[svn r380] added all kinds of objects
This commit is contained in:
parent
a9520b3804
commit
37fdf22282
140 changed files with 7679 additions and 901 deletions
|
|
@ -62,61 +62,165 @@ public class VascAnnotationParser {
|
|||
* @param property The property for the ToolTip
|
||||
* @return The i18n key for an ToolTip
|
||||
*/
|
||||
public String getVascDescriptionKey(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascDescription.class,property);
|
||||
public String getVascI18nDescription(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascI18n.class,property,"description");
|
||||
}
|
||||
|
||||
public String getVascDescriptionKey(Class<?> beanClass) {
|
||||
return (String)getValue(beanClass,VascDescription.class,null);
|
||||
public String getVascI18nDescription(Class<?> beanClass) {
|
||||
return (String)getValue(beanClass,VascI18n.class,null,"description");
|
||||
}
|
||||
|
||||
public String getVascI18nName(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascI18n.class,property,"name");
|
||||
}
|
||||
|
||||
public String getVascI18nName(Class<?> beanClass) {
|
||||
return (String)getValue(beanClass,VascI18n.class,null,"name");
|
||||
}
|
||||
|
||||
public String getVascI18nHelpId(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascI18n.class,property,"helpId");
|
||||
}
|
||||
|
||||
public String getVascI18nHelpId(Class<?> beanClass) {
|
||||
return (String)getValue(beanClass,VascI18n.class,null,"helpId");
|
||||
}
|
||||
|
||||
public String getVascI18nImage(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascI18n.class,property,"image");
|
||||
}
|
||||
|
||||
public String getVascI18nImage(Class<?> beanClass) {
|
||||
return (String)getValue(beanClass,VascI18n.class,null,"image");
|
||||
}
|
||||
|
||||
public Integer getVascOrderIndex(Class<?> beanClass,String property) {
|
||||
return (Integer)getValue(beanClass,VascFieldOrder.class,property,"orderIndex");
|
||||
}
|
||||
|
||||
|
||||
public Integer getVascStyleSizeList(Class<?> beanClass,String property) {
|
||||
return (Integer)getValue(beanClass,VascStyle.class,property,"sizeList");
|
||||
}
|
||||
public Integer getVascStyleSizeEdit(Class<?> beanClass,String property) {
|
||||
return (Integer)getValue(beanClass,VascStyle.class,property,"sizeEdit");
|
||||
}
|
||||
public String getVascStyleStyleList(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascStyle.class,property,"styleList");
|
||||
}
|
||||
public String getVascStyleStyleEdit(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascStyle.class,property,"styleEdit");
|
||||
}
|
||||
|
||||
|
||||
public String getVascFieldBackendName(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascField.class,property,"backendName");
|
||||
}
|
||||
public Boolean getVascFieldCreate(Class<?> beanClass,String property) {
|
||||
return (Boolean)getValue(beanClass,VascField.class,property,"create");
|
||||
}
|
||||
public Boolean getVascFieldEdit(Class<?> beanClass,String property) {
|
||||
return (Boolean)getValue(beanClass,VascField.class,property,"edit");
|
||||
}
|
||||
public Boolean getVascFieldEditReadOnly(Class<?> beanClass,String property) {
|
||||
return (Boolean)getValue(beanClass,VascField.class,property,"editReadOnly");
|
||||
}
|
||||
public Boolean getVascFieldEditBlank(Class<?> beanClass,String property) {
|
||||
return (Boolean)getValue(beanClass,VascField.class,property,"editBlank");
|
||||
}
|
||||
public Boolean getVascFieldList(Class<?> beanClass,String property) {
|
||||
return (Boolean)getValue(beanClass,VascField.class,property,"list");
|
||||
}
|
||||
public Boolean getVascFieldView(Class<?> beanClass,String property) {
|
||||
return (Boolean)getValue(beanClass,VascField.class,property,"view");
|
||||
}
|
||||
public Boolean getVascFieldOptional(Class<?> beanClass,String property) {
|
||||
return (Boolean)getValue(beanClass,VascField.class,property,"optional");
|
||||
}
|
||||
|
||||
|
||||
public String getVascFieldType(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascFieldType.class,property,"type");
|
||||
}
|
||||
public String[] getVascFieldTypeProperties(Class<?> beanClass,String property) {
|
||||
return (String[])getValue(beanClass,VascFieldType.class,property,"properties");
|
||||
}
|
||||
|
||||
|
||||
public String getVascRolesCreate(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascRoles.class,property,"rolesCreate");
|
||||
}
|
||||
public String getVascRolesEdit(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascRoles.class,property,"rolesEdit");
|
||||
}
|
||||
public String getVascRolesEditReadOnly(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascRoles.class,property,"rolesEditReadOnly");
|
||||
}
|
||||
public String getVascRolesList(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascRoles.class,property,"rolesList");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key of the VascName key for the property of the class
|
||||
* @param beanClass The class to search for the property
|
||||
* @param property The property for the Labe
|
||||
* @return The i18n key for an Label
|
||||
* TODO: change this, because we need differnce between key and value instance
|
||||
* @param beanClass
|
||||
* @param property
|
||||
* @return
|
||||
*/
|
||||
public String getVascNameKey(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascName.class,property);
|
||||
}
|
||||
|
||||
public String getVascNameKey(Class<?> beanClass) {
|
||||
return (String)getValue(beanClass,VascName.class,null);
|
||||
}
|
||||
|
||||
|
||||
public Object getVascColumnWidth(Class<?> beanClass,String property) {
|
||||
return getValue(beanClass,VascColumnWidth.class,property);
|
||||
}
|
||||
|
||||
public Object getVascColumnWidth(Class<?> beanClass) {
|
||||
return getValue(beanClass,VascColumnWidth.class,null);
|
||||
}
|
||||
|
||||
public String getVascHelpId(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascHelpId.class,property);
|
||||
}
|
||||
|
||||
public String getVascHelpId(Class<?> beanClass) {
|
||||
return (String)getValue(beanClass,VascHelpId.class,null);
|
||||
}
|
||||
|
||||
public Object getVascDefaultValue(Class<?> beanClass,String property) {
|
||||
return getValue(beanClass,VascDefaultValue.class,property);
|
||||
return getValue(beanClass,VascDefaultValue.class,property,null);
|
||||
}
|
||||
|
||||
public Object getVascDefaultValue(Class<?> beanClass) {
|
||||
return getValue(beanClass,VascDefaultValue.class,null);
|
||||
}
|
||||
|
||||
public String getVascImage(Class<?> beanClass,String property) {
|
||||
return (String)getValue(beanClass,VascImage.class,property);
|
||||
}
|
||||
|
||||
public String getVascImage(Class<?> beanClass) {
|
||||
return (String)getValue(beanClass,VascImage.class,null);
|
||||
return getValue(beanClass,VascDefaultValue.class,null,null);
|
||||
}
|
||||
|
||||
public String getVascDisplayName(Class<?> beanClass) {
|
||||
for (Method method:beanClass.getMethods()) {
|
||||
if(method.getName().startsWith("get")==false) { //a bit durty
|
||||
continue;
|
||||
}
|
||||
Annotation anno = method.getAnnotation(VascDisplayName.class);
|
||||
if (anno==null) {
|
||||
continue;
|
||||
}
|
||||
return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get
|
||||
}
|
||||
return null;
|
||||
}
|
||||
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);
|
||||
if (mt==null) {
|
||||
String result = (String)getValue(beanClass,VascField.class,property,"displayName");
|
||||
return result;
|
||||
}
|
||||
Class<?> typeClass = mt.type();
|
||||
if (Object.class==mt.type()) {
|
||||
typeClass = method.getReturnType();
|
||||
}
|
||||
String name = getVascDisplayName(typeClass);
|
||||
return name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getVascPrimaryKey(Class<?> beanClass) {
|
||||
for (Method method:beanClass.getMethods()) {
|
||||
if(method.getName().startsWith("get")==false) { //a bit durty
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* No oop code here...refactor at some point in time
|
||||
|
|
@ -128,12 +232,16 @@ public class VascAnnotationParser {
|
|||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object getValue(Class<?> beanClass,Class annotationType,String property) {
|
||||
private Object getValue(Class<?> beanClass,Class annotationType,String property,String field) {
|
||||
if(beanClass==null) { throw new NullPointerException("beanClass may not be null"); }
|
||||
if(annotationType==null){ throw new NullPointerException("annotationType may not be null"); }
|
||||
|
||||
Object result = null;
|
||||
if(property==null) {
|
||||
if (property==null) {
|
||||
String def = beanClass.getName()+"."+annotationType.getSimpleName();
|
||||
if (field!=null) {
|
||||
def = def+"."+field;
|
||||
}
|
||||
Annotation anno = beanClass.getAnnotation(annotationType);
|
||||
if (anno==null) {
|
||||
// no annotation == no default
|
||||
|
|
@ -146,7 +254,7 @@ public class VascAnnotationParser {
|
|||
return null;
|
||||
}
|
||||
} else {
|
||||
result = doAnnotation(anno);
|
||||
result = doAnnotation(anno,def,field);
|
||||
if(result!=null) {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -154,31 +262,35 @@ public class VascAnnotationParser {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
return beanClass.getName()+"."+annotationType.getSimpleName();
|
||||
return def;
|
||||
}
|
||||
|
||||
String propRest = null;
|
||||
int index = property.indexOf(".");
|
||||
if(index>0) {
|
||||
if (index>0) {
|
||||
propRest = property.substring(index+1);
|
||||
property = property.substring(0,index);
|
||||
}
|
||||
|
||||
for(Method method:beanClass.getMethods()) {
|
||||
if(method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty
|
||||
String def = beanClass.getName()+"."+property+"."+annotationType.getSimpleName();
|
||||
if (field!=null) {
|
||||
def = def+"."+field;
|
||||
}
|
||||
for (Method method:beanClass.getMethods()) {
|
||||
if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty
|
||||
continue;
|
||||
}
|
||||
//logger.finer("Found property: "+property);
|
||||
VascModelReference mt = method.getAnnotation(VascModelReference.class);
|
||||
if(mt!=null) {
|
||||
VascI18nModelReference mt = method.getAnnotation(VascI18nModelReference.class);
|
||||
if (mt!=null && annotationType.equals(VascI18n.class)) {
|
||||
Class typeClass = mt.type();
|
||||
if(Object.class==mt.type()) {
|
||||
if (Object.class==mt.type()) {
|
||||
typeClass = method.getReturnType();
|
||||
//return returnType.getName()+"."+annotationType.toString();
|
||||
}
|
||||
|
||||
// recursif function:
|
||||
return getValue(typeClass,annotationType,propRest);
|
||||
return getValue(typeClass,annotationType,propRest,field);
|
||||
}
|
||||
|
||||
Annotation anno = method.getAnnotation(annotationType);
|
||||
|
|
@ -186,7 +298,7 @@ public class VascAnnotationParser {
|
|||
if (anno==null && annotationType.equals(VascDefaultValue.class)) {
|
||||
return null;
|
||||
}
|
||||
result = doAnnotation(anno);
|
||||
result = doAnnotation(anno,def,field);
|
||||
if(result!=null) {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -195,62 +307,202 @@ public class VascAnnotationParser {
|
|||
}
|
||||
break; // return default
|
||||
}
|
||||
return beanClass.getName()+"."+property+"."+annotationType.getSimpleName();
|
||||
|
||||
if (annotationType.equals(VascField.class)) {
|
||||
try {
|
||||
if ("backendName".equals(field)) {
|
||||
return VascField.class.getMethod("backendName").getDefaultValue();
|
||||
}
|
||||
if ("displayName".equals(field)) {
|
||||
return VascField.class.getMethod("displayName").getDefaultValue();
|
||||
}
|
||||
if ("create".equals(field)) {
|
||||
return VascField.class.getMethod("create").getDefaultValue();
|
||||
}
|
||||
if ("edit".equals(field)) {
|
||||
return VascField.class.getMethod("edit").getDefaultValue();
|
||||
}
|
||||
if ("editReadOnly".equals(field)) {
|
||||
return VascField.class.getMethod("editReadOnly").getDefaultValue();
|
||||
}
|
||||
if ("editBlank".equals(field)) {
|
||||
return VascField.class.getMethod("editBlank").getDefaultValue();
|
||||
}
|
||||
if ("list".equals(field)) {
|
||||
return VascField.class.getMethod("list").getDefaultValue();
|
||||
}
|
||||
if ("view".equals(field)) {
|
||||
return VascField.class.getMethod("view").getDefaultValue();
|
||||
}
|
||||
if ("optional".equals(field)) {
|
||||
return VascField.class.getMethod("optional").getDefaultValue();
|
||||
}
|
||||
// This are the default value then....
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (annotationType.equals(VascFieldType.class)) {
|
||||
return null;
|
||||
}
|
||||
if (annotationType.equals(VascStyle.class)) {
|
||||
return null;
|
||||
}
|
||||
if (annotationType.equals(VascRoles.class)) {
|
||||
return null;
|
||||
}
|
||||
if (annotationType.equals(VascFieldOrder.class)) {
|
||||
int indexOrder = 0;
|
||||
for (Method method:beanClass.getMethods()) {
|
||||
if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty
|
||||
indexOrder = indexOrder + 100;
|
||||
continue;
|
||||
}
|
||||
return indexOrder;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
private Object doAnnotation(Annotation b) {
|
||||
private Object doAnnotation(Annotation b,String def,String field) {
|
||||
if (b==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Class<?> a = b.annotationType();
|
||||
if (a.equals(VascName.class)) {
|
||||
VascName l = (VascName)b;
|
||||
if("".equals(l.key()) | "null".equals(l.key())) {
|
||||
return null;
|
||||
}
|
||||
return l.key();
|
||||
if (a.equals(VascI18n.class)) {
|
||||
VascI18n l = (VascI18n)b;
|
||||
String val = null;
|
||||
|
||||
if ("name".equals(field)) {
|
||||
val = l.name();
|
||||
}
|
||||
if ("description".equals(field)) {
|
||||
val = l.description();
|
||||
}
|
||||
if ("image".equals(field)) {
|
||||
val = l.image();
|
||||
}
|
||||
if ("helpId".equals(field)) {
|
||||
val = l.helpId();
|
||||
}
|
||||
if (val==null) {
|
||||
val = "";
|
||||
}
|
||||
if ("".equals(val)) {
|
||||
return def;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
if (a.equals(VascDescription.class)) {
|
||||
VascDescription t = (VascDescription)b;
|
||||
if("".equals(t.key()) | "null".equals(t.key())) {
|
||||
return null;
|
||||
}
|
||||
return t.key();
|
||||
}
|
||||
if (a.equals(VascHelpId.class)) {
|
||||
VascHelpId h = (VascHelpId)b;
|
||||
if("".equals(h.helpId()) | "null".equals(h.helpId())) {
|
||||
return null;
|
||||
}
|
||||
return h.helpId();
|
||||
if (a.equals(VascFieldOrder.class)) {
|
||||
VascFieldOrder v = (VascFieldOrder)b;
|
||||
return v.orderIndex();
|
||||
}
|
||||
if (a.equals(VascDefaultValue.class)) {
|
||||
VascDefaultValue v = (VascDefaultValue)b;
|
||||
|
||||
if(v.defaultValue().equals(Object.class)==false) {
|
||||
try {
|
||||
//return v.defaultValue().newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new NullPointerException("Could not init defaultValueClass error: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
if ("null".equals(v.defaultValue())) {
|
||||
return "";
|
||||
}
|
||||
return v.defaultValue();
|
||||
}
|
||||
if (a.equals(VascColumnWidth.class)) {
|
||||
VascColumnWidth c = (VascColumnWidth)b;
|
||||
return c.width();
|
||||
}
|
||||
if (a.equals(VascImage.class)) {
|
||||
VascImage c = (VascImage)b;
|
||||
if("".equals(c.image()) | "null".equals(c.image())) {
|
||||
return null;
|
||||
if (a.equals(VascStyle.class)) {
|
||||
VascStyle c = (VascStyle)b;
|
||||
if ("sizeList".equals(field)) {
|
||||
return c.sizeList();
|
||||
}
|
||||
return c.image();
|
||||
if ("sizeEdit".equals(field)) {
|
||||
return c.sizeEdit();
|
||||
}
|
||||
if ("styleList".equals(field)) {
|
||||
return c.styleList();
|
||||
}
|
||||
if ("styleEdit".equals(field)) {
|
||||
return c.styleEdit();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (a.equals(VascField.class)) {
|
||||
VascField c = (VascField)b;
|
||||
if ("backendName".equals(field)) {
|
||||
if ("".equals(c.backendName())) {
|
||||
return null;
|
||||
}
|
||||
return c.backendName();
|
||||
}
|
||||
if ("displayName".equals(field)) {
|
||||
if ("".equals(c.displayName())) {
|
||||
return null;
|
||||
}
|
||||
return c.displayName();
|
||||
}
|
||||
if ("create".equals(field)) {
|
||||
return c.create();
|
||||
}
|
||||
if ("edit".equals(field)) {
|
||||
return c.edit();
|
||||
}
|
||||
if ("editReadOnly".equals(field)) {
|
||||
return c.editReadOnly();
|
||||
}
|
||||
if ("editBlank".equals(field)) {
|
||||
return c.editBlank();
|
||||
}
|
||||
if ("list".equals(field)) {
|
||||
return c.list();
|
||||
}
|
||||
if ("view".equals(field)) {
|
||||
return c.view();
|
||||
}
|
||||
if ("optional".equals(field)) {
|
||||
return c.optional();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (a.equals(VascFieldType.class)) {
|
||||
VascFieldType c = (VascFieldType)b;
|
||||
if ("type".equals(field)) {
|
||||
if ("".equals(c.type())) {
|
||||
return null;
|
||||
}
|
||||
return c.type();
|
||||
}
|
||||
if ("properties".equals(field)) {
|
||||
return c.properties();
|
||||
}
|
||||
}
|
||||
if (a.equals(VascRoles.class)) {
|
||||
VascRoles c = (VascRoles)b;
|
||||
if ("rolesCreate".equals(field)) {
|
||||
if ("".equals(c.rolesCreate())) {
|
||||
return null;
|
||||
}
|
||||
return c.rolesCreate();
|
||||
}
|
||||
if ("rolesEdit".equals(field)) {
|
||||
if ("".equals(c.rolesEdit())) {
|
||||
return null;
|
||||
}
|
||||
return c.rolesEdit();
|
||||
}
|
||||
if ("rolesEditReadOnly".equals(field)) {
|
||||
if ("".equals(c.rolesEditReadOnly())) {
|
||||
return null;
|
||||
}
|
||||
return c.rolesEditReadOnly();
|
||||
}
|
||||
if ("rolesList".equals(field)) {
|
||||
if ("".equals(c.rolesList())) {
|
||||
return null;
|
||||
}
|
||||
return c.rolesList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* 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.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Parses the Vasc annotations and generates all i18n keys for you.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 23, 2009
|
||||
*/
|
||||
public class VascBundleKeyGenerator {
|
||||
|
||||
private List<Class<?>> models = null;
|
||||
private Map<String,String> keys = null;
|
||||
private boolean generateName = true;
|
||||
private boolean generateDescription = true;
|
||||
private boolean generateImage = true;
|
||||
private boolean generateHelpId = true;
|
||||
|
||||
public VascBundleKeyGenerator() {
|
||||
models = new ArrayList<Class<?>>(30);
|
||||
keys = new HashMap<String,String>(300);
|
||||
}
|
||||
|
||||
public void addModelClass(Class<?> model) {
|
||||
models.add(model);
|
||||
}
|
||||
|
||||
public List<Class<?>> getModelClasses() {
|
||||
return models;
|
||||
}
|
||||
|
||||
|
||||
public void generateMissingKeys(StringBuffer buffer,ResourceBundle bundle) {
|
||||
if (keys.isEmpty()==false) {
|
||||
keys.clear();
|
||||
}
|
||||
for (Class<?> modelClass:models) {
|
||||
generatorI18nKeys(modelClass);
|
||||
}
|
||||
|
||||
List<String> keys2 = new ArrayList<String>(keys.keySet());
|
||||
keys2.removeAll(bundle.keySet());
|
||||
Collections.sort(keys2);
|
||||
for (String key:keys2) {
|
||||
String value = keys.get(key);
|
||||
buffer.append(key);
|
||||
buffer.append(" = ");
|
||||
buffer.append(value);
|
||||
buffer.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
public void generateRemoveKeys(StringBuffer buffer,ResourceBundle bundle,String excludeRegex) {
|
||||
if (keys.isEmpty()==false) {
|
||||
keys.clear();
|
||||
}
|
||||
for (Class<?> modelClass:models) {
|
||||
generatorI18nKeys(modelClass);
|
||||
}
|
||||
|
||||
List<String> keys2 = new ArrayList<String>(bundle.keySet());
|
||||
keys2.removeAll(keys.keySet());
|
||||
Collections.sort(keys2);
|
||||
for (String key:keys2) {
|
||||
// exlude code and user keys
|
||||
if (excludeRegex!=null && key.matches(excludeRegex)) {
|
||||
continue;
|
||||
}
|
||||
buffer.append(key);
|
||||
buffer.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
public void generateKeys(StringBuffer buffer) {
|
||||
if (keys.isEmpty()==false) {
|
||||
keys.clear();
|
||||
}
|
||||
for (Class<?> modelClass:models) {
|
||||
generatorI18nKeys(modelClass);
|
||||
}
|
||||
List<String> keys2 = new ArrayList<String>(keys.keySet());
|
||||
Collections.sort(keys2);
|
||||
for (String key:keys2) {
|
||||
String value = keys.get(key);
|
||||
buffer.append(key);
|
||||
buffer.append(" = ");
|
||||
buffer.append(value);
|
||||
buffer.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
private void generatorI18nKeys(Class<?> bean) {
|
||||
VascAnnotationParser vap = new VascAnnotationParser();
|
||||
|
||||
String prop1 = bean.getName().substring(bean.getName().lastIndexOf('.')+1);
|
||||
if (isGenerateName()) {
|
||||
appendKey(vap.getVascI18nName(bean),prop1);
|
||||
}
|
||||
if (isGenerateDescription()) {
|
||||
appendKey(vap.getVascI18nDescription(bean),prop1);
|
||||
}
|
||||
if (isGenerateImage()) {
|
||||
appendKey(vap.getVascI18nImage(bean),"resources/images/models/"+prop1+".png");
|
||||
}
|
||||
if (isGenerateHelpId()) {
|
||||
appendKey(vap.getVascI18nHelpId(bean),prop1);
|
||||
}
|
||||
|
||||
|
||||
for (Method method:bean.getMethods()) {
|
||||
if (method.getName().startsWith("get")==false) { //a bit durty
|
||||
continue;
|
||||
}
|
||||
if (method.getName().equals("getClass")==true) {
|
||||
continue;
|
||||
}
|
||||
String prop = method.getName().substring(3);
|
||||
prop = prop.substring(0,1).toLowerCase()+prop.substring(1);
|
||||
|
||||
|
||||
if (isGenerateName()) {
|
||||
appendKey(vap.getVascI18nName(bean, prop),prop);
|
||||
}
|
||||
if (isGenerateDescription()) {
|
||||
appendKey(vap.getVascI18nDescription(bean, prop),prop);
|
||||
}
|
||||
if (isGenerateImage()) {
|
||||
appendKey(vap.getVascI18nImage(bean, prop),"resources/images/models/"+prop1+"-"+prop+".png");
|
||||
}
|
||||
if (isGenerateHelpId()) {
|
||||
appendKey(vap.getVascI18nHelpId(bean),prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void appendKey(String key,String value) {
|
||||
if (keys.containsKey(key)) {
|
||||
return;
|
||||
}
|
||||
keys.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateName
|
||||
*/
|
||||
public boolean isGenerateName() {
|
||||
return generateName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateName the generateName to set
|
||||
*/
|
||||
public void setGenerateName(boolean generateName) {
|
||||
this.generateName = generateName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateDescription
|
||||
*/
|
||||
public boolean isGenerateDescription() {
|
||||
return generateDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateDescription the generateDescription to set
|
||||
*/
|
||||
public void setGenerateDescription(boolean generateDescription) {
|
||||
this.generateDescription = generateDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateImage
|
||||
*/
|
||||
public boolean isGenerateImage() {
|
||||
return generateImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateImage the generateImage to set
|
||||
*/
|
||||
public void setGenerateImage(boolean generateImage) {
|
||||
this.generateImage = generateImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateHelpId
|
||||
*/
|
||||
public boolean isGenerateHelpId() {
|
||||
return generateHelpId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateHelpId the generateHelpId to set
|
||||
*/
|
||||
public void setGenerateHelpId(boolean generateHelpId) {
|
||||
this.generateHelpId = generateHelpId;
|
||||
}
|
||||
}
|
||||
|
|
@ -35,6 +35,8 @@ import java.lang.annotation.Target;
|
|||
/**
|
||||
* Some choises options
|
||||
*
|
||||
* make also the field type to list
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 19, 2008
|
||||
*/
|
||||
|
|
@ -42,9 +44,9 @@ import java.lang.annotation.Target;
|
|||
@Target(ElementType.METHOD)
|
||||
public @interface VascChoices {
|
||||
|
||||
String[] choisesKeys();
|
||||
String[] choisesKeys() default {};
|
||||
|
||||
String[] choisesNames();
|
||||
|
||||
boolean editAsRadio() default true;
|
||||
boolean choisesAsRadio() default false;
|
||||
}
|
||||
|
|
@ -42,12 +42,11 @@ import java.lang.annotation.Target;
|
|||
@Target(ElementType.METHOD)
|
||||
public @interface VascDefaultValue {
|
||||
|
||||
String key() default "null";
|
||||
//String key() default "";
|
||||
|
||||
/**
|
||||
* Note: special value for default, because else we can not set empty.
|
||||
* @return
|
||||
*/
|
||||
String defaultValue() default "null";
|
||||
|
||||
/**
|
||||
* The defaultValue of the method
|
||||
*/
|
||||
//Class<?> defaultValueClass() default Object.class;
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the I18nToolTip(non default) an a Class property
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2006
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||
public @interface VascDescription {
|
||||
|
||||
/**
|
||||
* The key of the ToolTip default to "null"
|
||||
* @see com.idcanet.i18n.I18nAnnotationParser#getI18nToolTipKey(Class, String)
|
||||
* @return The key of the ToolTip
|
||||
*/
|
||||
String key() default "null";
|
||||
}
|
||||
|
|
@ -41,13 +41,5 @@ import java.lang.annotation.Target;
|
|||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface VascDisplayName {
|
||||
|
||||
/**
|
||||
* The field or fields which are the display name.
|
||||
* If used on method then field may be left out.
|
||||
*
|
||||
*/
|
||||
String fields() default "null";
|
||||
|
||||
String format() default "null";
|
||||
|
||||
}
|
||||
|
|
@ -40,13 +40,24 @@ import java.lang.annotation.Target;
|
|||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface VascAdmin {
|
||||
public @interface VascEntry {
|
||||
|
||||
boolean list() default true;
|
||||
String id() default "";
|
||||
|
||||
String headerName() default "";
|
||||
|
||||
String headerDescription() default "";
|
||||
|
||||
String headerImage() default "";
|
||||
|
||||
String helpId() default "";
|
||||
|
||||
|
||||
boolean vascAdminList() default true;
|
||||
|
||||
boolean create() default true;
|
||||
boolean vascAdminCreate() default true;
|
||||
|
||||
boolean update() default true;
|
||||
boolean vascAdminEdit() default true;
|
||||
|
||||
boolean delete() default true;
|
||||
boolean vascAdminDelete() default true;
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ import java.lang.annotation.Target;
|
|||
* @version 1.0 Aug 15, 2008
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface VascEventChannel {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -40,17 +40,23 @@ import java.lang.annotation.Target;
|
|||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface VascFieldOptions {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
boolean blank() default false;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String choises() default "null"; // + radio admin
|
||||
|
||||
boolean editable() default true;
|
||||
public @interface VascField {
|
||||
|
||||
String backendName() default "";
|
||||
|
||||
String displayName() default "";
|
||||
|
||||
boolean create() default true;
|
||||
|
||||
boolean edit() default true;
|
||||
|
||||
boolean editReadOnly() default false;
|
||||
|
||||
boolean editBlank() default false;
|
||||
|
||||
boolean list() default true;
|
||||
|
||||
boolean view() default true;
|
||||
|
||||
boolean optional() default false;
|
||||
}
|
||||
|
|
@ -33,17 +33,18 @@ import java.lang.annotation.Target;
|
|||
|
||||
|
||||
/**
|
||||
* Sets the helpId
|
||||
* Lets you order the fields to better UI bahaivur.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 28, 2007
|
||||
* @version 1.0 Apr 6, 2009
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||
public @interface VascHelpId {
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface VascFieldOrder {
|
||||
|
||||
/**
|
||||
* The defaultValue of the method
|
||||
* The editor of the method/field
|
||||
*/
|
||||
String helpId() default "null";
|
||||
int orderIndex() default 0;
|
||||
|
||||
}
|
||||
|
|
@ -40,15 +40,15 @@ import java.lang.annotation.Target;
|
|||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface VascEditorType {
|
||||
public @interface VascFieldType {
|
||||
|
||||
/**
|
||||
* The editor of the method/field
|
||||
*/
|
||||
String type() default "null";
|
||||
String type() default "";
|
||||
|
||||
/**
|
||||
* Hints for the choosen editor
|
||||
*/
|
||||
String hints() default "null";
|
||||
String[] properties() default {};
|
||||
}
|
||||
|
|
@ -40,12 +40,18 @@ import java.lang.annotation.Target;
|
|||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||
public @interface VascName {
|
||||
public @interface VascI18n {
|
||||
|
||||
/**
|
||||
* The key of the Label default to "null"
|
||||
* @see com.idcanet.i18n.I18nAnnotationParser#getI18nLabelKey(Class, String)
|
||||
* @return The key of the ToolTip
|
||||
*/
|
||||
String key() default "null";
|
||||
String name() default "";
|
||||
|
||||
String description() default "";
|
||||
|
||||
String image() default "";
|
||||
|
||||
String helpId() default "";
|
||||
}
|
||||
|
|
@ -40,9 +40,7 @@ import java.lang.annotation.Target;
|
|||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface VascModelReference {
|
||||
|
||||
boolean editAsRadio() default true;
|
||||
|
||||
public @interface VascI18nModelReference {
|
||||
|
||||
Class<?> type() default Object.class;
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the VascImage property
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2006
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||
public @interface VascImage {
|
||||
|
||||
/**
|
||||
* The resource or key of the Image, default to "null"
|
||||
* @see com.idcanet.i18n.I18nAnnotationParser#getI18nLabelKey(Class, String)
|
||||
* @return The key of the ToolTip
|
||||
*/
|
||||
String image() default "null";
|
||||
}
|
||||
|
|
@ -40,20 +40,23 @@ import java.lang.annotation.Target;
|
|||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface VascUserRoles {
|
||||
public @interface VascRoles {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String list() default "null";
|
||||
String rolesCreate() default "";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String edit() default "null";
|
||||
String rolesEdit() default "";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String editViewOnly() default "null";
|
||||
String rolesEditReadOnly() default "";
|
||||
|
||||
|
||||
String rolesList() default "";
|
||||
}
|
||||
|
|
@ -40,7 +40,10 @@ import java.lang.annotation.Target;
|
|||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface VascColumnWidth {
|
||||
public @interface VascStyle {
|
||||
|
||||
int width() default 150;
|
||||
int sizeList() default 0;
|
||||
int sizeEdit() default 0;
|
||||
String styleList() default "";
|
||||
String styleEdit() default "";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue