2
Fork 0

[svn r382] hacked jsf frontend working

This commit is contained in:
willemc 2009-08-11 20:31:29 +02:00
parent 37fdf22282
commit 9a605f177a
123 changed files with 7035 additions and 2418 deletions

View file

@ -37,25 +37,6 @@ import java.lang.reflect.Method;
*/
public class VascAnnotationParser {
/** Determens if no when no annotation is found null will return or default key */
private Boolean noAnnotationNullReturn = null;
/**
* Creates an VascAnnotationParser
*/
public VascAnnotationParser() {
setNoAnnotationNullReturn(false);
}
/**
* Determens if no when no annotation is found null will return or default key
* default is false
* @param noAnnotationNullReturn
*/
public VascAnnotationParser(boolean noAnnotationNullReturn) {
setNoAnnotationNullReturn(noAnnotationNullReturn);
}
/**
* Gets the key of the VascToolTip key for the property of the class
* @param beanClass The class to search for the property
@ -137,6 +118,15 @@ public class VascAnnotationParser {
public Boolean getVascFieldOptional(Class<?> beanClass,String property) {
return (Boolean)getValue(beanClass,VascField.class,property,"optional");
}
public Boolean getVascFieldSortable(Class<?> beanClass,String property) {
return (Boolean)getValue(beanClass,VascField.class,property,"sortable");
}
public Boolean getVascFieldSumable(Class<?> beanClass,String property) {
return (Boolean)getValue(beanClass,VascField.class,property,"sumable");
}
public Boolean getVascFieldGraphable(Class<?> beanClass,String property) {
return (Boolean)getValue(beanClass,VascField.class,property,"graphable");
}
public String getVascFieldType(Class<?> beanClass,String property) {
@ -147,6 +137,13 @@ public class VascAnnotationParser {
}
public Class<?> getVascFieldTemplateClass(Class<?> beanClass,String property) {
return (Class<?>)getValue(beanClass,VascFieldTemplate.class,property,"templateClass");
}
public String getVascFieldTemplate(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascFieldTemplate.class,property,"template");
}
public String getVascRolesCreate(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascRoles.class,property,"rolesCreate");
}
@ -159,6 +156,15 @@ public class VascAnnotationParser {
public String getVascRolesList(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascRoles.class,property,"rolesList");
}
public VascChoices getVascChoices(Class<?> beanClass,String property) {
return (VascChoices)getValue(beanClass,VascChoices.class,property,null);
}
public VascEventListener getVascEventListener(Class<?> beanClass) {
return (VascEventListener)getValue(beanClass,VascEventListener.class,null,null);
}
/**
* TODO: change this, because we need differnce between key and value instance
@ -166,36 +172,67 @@ public class VascAnnotationParser {
* @param property
* @return
*/
public Object getVascDefaultValue(Class<?> beanClass,String property) {
return getValue(beanClass,VascDefaultValue.class,property,null);
public String getVascDefaultValue(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascDefaultValue.class,property,null);
}
public Object getVascDefaultValue(Class<?> beanClass) {
return getValue(beanClass,VascDefaultValue.class,null,null);
}
public String getVascDisplayName(Class<?> beanClass) {
//System.out.println("========== GetDisPlayName: "+beanClass);
for (Method method:beanClass.getMethods()) {
if(method.getName().startsWith("get")==false) { //a bit durty
if (method.getName().startsWith("get")==false) { //a bit durty
continue;
}
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template!=null) {
//System.out.println("Search template for: "+method.getName());
String tempProp = method.getName().substring(3);
if ("".equals(template.template())==false) {
tempProp = template.template();
}
for (Method method2:template.templateClass().getMethods()) {
if (method2.getName().equalsIgnoreCase("get"+tempProp)==false) { //a bit durty
continue;
}
Annotation anno = method2.getAnnotation(VascDisplayName.class);
//System.out.println("Template annot: "+anno+" prop: "+tempProp);
if (anno==null) {
break;
}
//System.out.println("Found template");
return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get
}
}
Annotation anno = method.getAnnotation(VascDisplayName.class);
if (anno==null) {
continue;
}
//System.out.println("Found normal");
return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get
}
return null;
//System.out.println("Defraulting to key");
return getVascPrimaryKey(beanClass); // fall back on primary key
}
public String getVascDisplayName(Class<?> beanClass,String property) {
for (Method method:beanClass.getMethods()) {
if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty
continue;
}
VascI18nModelReference mt = method.getAnnotation(VascI18nModelReference.class);
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template!=null) {
String tempProp = property;
if ("".equals(template.template())==false) {
tempProp = template.template();
}
String value = getVascDisplayName(template.templateClass(),tempProp);
if (value!=null) {
return value;
}
}
VascModelReference mt = method.getAnnotation(VascModelReference.class);
if (mt==null) {
String result = (String)getValue(beanClass,VascField.class,property,"displayName");
return result;
return null; // no display name
}
Class<?> typeClass = mt.type();
if (Object.class==mt.type()) {
@ -212,13 +249,20 @@ public class VascAnnotationParser {
if(method.getName().startsWith("get")==false) { //a bit durty
continue;
}
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template!=null) {
String value = getVascPrimaryKey(template.templateClass());
if (value!=null) {
return value;
}
}
Annotation anno = method.getAnnotation(VascPrimaryKey.class);
if (anno==null) {
continue;
}
return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get
}
return null;
return null; // maybe fallback on getId() ?
}
@ -242,25 +286,24 @@ public class VascAnnotationParser {
if (field!=null) {
def = def+"."+field;
}
Annotation anno = beanClass.getAnnotation(annotationType);
if (anno==null) {
// no annotation == no default
if (annotationType.equals(VascDefaultValue.class)) {
return null;
}
// no annotion avaible
if (noAnnotationNullReturn) {
return null;
}
if (annotationType.equals(VascEventListener.class)) {
return null;
}
} else {
if (annotationType.equals(VascEventListener.class)) {
return anno;
}
result = doAnnotation(anno,def,field);
if(result!=null) {
return result;
}
if (noAnnotationNullReturn) {
return null;
}
}
return def;
}
@ -281,16 +324,50 @@ public class VascAnnotationParser {
continue;
}
//logger.finer("Found property: "+property);
VascI18nModelReference mt = method.getAnnotation(VascI18nModelReference.class);
if (mt!=null && annotationType.equals(VascI18n.class)) {
VascModelReference mt = method.getAnnotation(VascModelReference.class);
if (mt!=null & (annotationType.equals(VascI18n.class) | annotationType.equals(VascField.class) | annotationType.equals(VascStyle.class) )) {
Class typeClass = mt.type();
if (Object.class==mt.type()) {
typeClass = method.getReturnType();
//return returnType.getName()+"."+annotationType.toString();
}
// recursif function:
return getValue(typeClass,annotationType,propRest,field);
if ( annotationType.equals(VascStyle.class) ) {
String disName = getVascDisplayName(typeClass);
return getValue(typeClass,annotationType,disName,field);
}
if ( annotationType.equals(VascField.class) ) {
if ("backendName".equals(field)) {
//return property+"."+getValue(typeClass,annotationType,propRest,field);
}
} else {
// recursif function:
return getValue(typeClass,annotationType,propRest,field);
}
}
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template!=null) {
if (annotationType.equals(VascFieldTemplate.class)) {
if ("templateClass".equals(field)) {
return template.templateClass();
}
if ("template".equals(field)) {
return template.template();
}
return null;
}
String tempProp = property;
if ("".equals(template.template())==false) {
tempProp = template.template();
}
Object value = getValue(template.templateClass(),annotationType,tempProp,field);
if (value!=null) {
return value;
}
}
Annotation anno = method.getAnnotation(annotationType);
@ -302,9 +379,6 @@ public class VascAnnotationParser {
if(result!=null) {
return result;
}
if (noAnnotationNullReturn) {
return null;
}
break; // return default
}
@ -337,6 +411,9 @@ public class VascAnnotationParser {
if ("optional".equals(field)) {
return VascField.class.getMethod("optional").getDefaultValue();
}
if ("sortable".equals(field)) {
return VascField.class.getMethod("sortable").getDefaultValue();
}
// This are the default value then....
return null;
} catch (Exception e) {
@ -344,6 +421,9 @@ public class VascAnnotationParser {
return false;
}
}
if (annotationType.equals(VascFieldTemplate.class)) {
return null;
}
if (annotationType.equals(VascFieldType.class)) {
return null;
}
@ -353,6 +433,12 @@ public class VascAnnotationParser {
if (annotationType.equals(VascRoles.class)) {
return null;
}
if (annotationType.equals(VascChoices.class)) {
return null;
}
if (annotationType.equals(VascEventListener.class)) {
return null;
}
if (annotationType.equals(VascFieldOrder.class)) {
int indexOrder = 0;
for (Method method:beanClass.getMethods()) {
@ -401,12 +487,16 @@ public class VascAnnotationParser {
VascFieldOrder v = (VascFieldOrder)b;
return v.orderIndex();
}
if (a.equals(VascChoices.class)) {
VascChoices v = (VascChoices)b;
return v;
}
if (a.equals(VascDefaultValue.class)) {
VascDefaultValue v = (VascDefaultValue)b;
if ("null".equals(v.defaultValue())) {
return "";
if ("null".equals(v.value())) {
return null;
}
return v.defaultValue();
return v.value();
}
if (a.equals(VascStyle.class)) {
VascStyle c = (VascStyle)b;
@ -460,6 +550,15 @@ public class VascAnnotationParser {
if ("optional".equals(field)) {
return c.optional();
}
if ("sortable".equals(field)) {
return c.sortable();
}
if ("sumable".equals(field)) {
return c.sumable();
}
if ("graphable".equals(field)) {
return c.graphable();
}
return null;
}
if (a.equals(VascFieldType.class)) {
@ -505,19 +604,4 @@ public class VascAnnotationParser {
return null;
}
/**
* default is false
* @return Returns the noAnnotationNullReturn.
*/
public Boolean getNoAnnotationNullReturn() {
return noAnnotationNullReturn;
}
/**
* @param noAnnotationNullReturn The noAnnotationNullReturn to set.
*/
public void setNoAnnotationNullReturn(Boolean noAnnotationNullReturn) {
this.noAnnotationNullReturn = noAnnotationNullReturn;
}
}

View file

@ -46,7 +46,13 @@ public @interface VascChoices {
String[] choisesKeys() default {};
String[] choisesNames();
String[] choisesValues() default {};
Class<?> choisesType() default String.class;
boolean choisesAsRadio() default false;
String nullLabel() default "null";
String nullKeyValue() default "null";
}

View file

@ -0,0 +1,110 @@
/**
*
*/
package com.idcanet.vasc.annotations;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascSelectItem;
import com.idcanet.vasc.core.ui.VascSelectItemModel;
/**
* Selected the vasc choices
*
*
* @author Willem Cazander
* @version 1.0 Apr 23, 2009
*/
@SuppressWarnings("serial")
public class VascChoicesSelectItemModel implements VascSelectItemModel,Serializable {
private VascChoices vascChoices = null;
private String nullLabel = null;
private String nullKeyValue = null;
public VascChoicesSelectItemModel(VascChoices vascChoices) {
this.vascChoices=vascChoices;
}
/**
* @see com.idcanet.vasc.core.ui.VascSelectItemModel#getVascSelectItems(com.idcanet.vasc.core.VascEntry)
*/
public List<VascSelectItem> getVascSelectItems(com.idcanet.vasc.core.VascEntry entry) throws VascException {
List<VascSelectItem> result = new ArrayList<VascSelectItem>(10);
if ("null".equals(vascChoices.nullLabel())==false) {
nullLabel = vascChoices.nullLabel();
nullKeyValue = vascChoices.nullKeyValue();
}
if (nullLabel!=null) {
if (nullKeyValue==null) {
nullKeyValue = "null";
}
String nullLabelText = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(nullLabel);
VascSelectItem item = new VascSelectItem(nullLabelText,null,nullKeyValue);
result.add(item);
}
int index = 0;
boolean val = false;
String[] a = vascChoices.choisesKeys();
if (a.length==0) {
a=vascChoices.choisesValues();
val = true;
} else if (vascChoices.choisesKeys().length!=vascChoices.choisesValues().length) {
throw new IllegalStateException("Can't have unequal sizes of array of keys and values of vascChoices annotation.");
}
for (String key:a) {
VascSelectItem item = new VascSelectItem();
String name = null;
if (val) {
name = key;
} else {
name = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key);
}
item.setLabel(name);
Object value = vascChoices.choisesValues()[index];
if (vascChoices.choisesType().equals(String.class)==false) {
try {
value = vascChoices.choisesType().getConstructor(String.class).newInstance(key);
} catch (Exception e) {
}
}
item.setValue(value);
item.setKeyValue(key);
result.add(item);
index++;
}
return result;
}
/**
* @return the nullLabel
*/
public String getNullLabel() {
return nullLabel;
}
/**
* @param nullLabel the nullLabel to set
*/
public void setNullLabel(String nullLabel) {
this.nullLabel = nullLabel;
}
/**
* @return the nullKeyValue
*/
public String getNullKeyValue() {
return nullKeyValue;
}
/**
* @param nullKeyValue the nullKeyValue to set
*/
public void setNullKeyValue(String nullKeyValue) {
this.nullKeyValue = nullKeyValue;
}
}

View file

@ -48,5 +48,5 @@ public @interface VascDefaultValue {
* Note: special value for default, because else we can not set empty.
* @return
*/
String defaultValue() default "null";
String value() default "null";
}

View file

@ -0,0 +1,50 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType;
/**
* Event listener annotation
*
* @author Willem Cazander
* @version 1.0 Apr 23, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface VascEventListener {
String[] listeners();
VascEventType[] types();
}

View file

@ -59,4 +59,10 @@ public @interface VascField {
boolean view() default true;
boolean optional() default false;
boolean sortable() default true;
boolean sumable() default false;
boolean graphable() default false;
}

View file

@ -0,0 +1,54 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Adds template support for the vasc annotations.
*
* @author Willem Cazander
* @version 1.0 May 12, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascFieldTemplate {
/**
* The choices template for this field.
*/
String template() default "";
/**
* The template class to get the templated property
*/
Class<?> templateClass();
}

View file

@ -40,7 +40,7 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascI18nModelReference {
public @interface VascModelReference {
Class<?> type() default Object.class;
}