2
Fork 0

[svn r236] fixed swt test and added annotations

This commit is contained in:
willemc 2007-03-28 19:16:40 +02:00
parent 5e425bd032
commit 54ca574e58
18 changed files with 931 additions and 23 deletions

View file

@ -0,0 +1,204 @@
/*
* 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.Annotation;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Parses the Vasc annotations
*
* @author Willem Cazander
* @version 1.0 May 27, 2006
*/
public class VascAnnotationParser {
/** Determens if no when no annotation is found null will return or default key */
private Boolean noAnnotationNullReturn = null;
private Logger logger = null;
/**
* Creates an VascAnnotationParser
*/
public VascAnnotationParser() {
setNoAnnotationNullReturn(false);
logger = Logger.getLogger(VascAnnotationParser.class.getName());
}
/**
* 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
* @param property The property for the ToolTip
* @return The i18n key for an ToolTip
*/
public String getVascToolTipKey(Class beanClass,String property) {
return (String)getValue(beanClass,VascToolTip.class,property);
}
public String getVascToolTipKey(Class beanClass) {
return (String)getValue(beanClass,VascToolTip.class,null);
}
/**
* 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
*/
public String getVascNameKey(Class beanClass,String property) {
return (String)getValue(beanClass,VascName.class,property);
}
public String getVascLabelKey(Class beanClass) {
return (String)getValue(beanClass,VascName.class,null);
}
/**
* No oop code here...refactor at some point in time
*
*
* @param beanClass
* @param property
* @param annotationType
* @return
*/
private Object getValue(Class beanClass,Class annotationType,String property) {
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) {
result = doAnnotation(beanClass.getAnnotation(annotationType));
if(result!=null) {
return result;
}
if (noAnnotationNullReturn) {
return null;
}
return beanClass.getName()+"."+annotationType.getSimpleName();
}
String propRest = null;
int index = property.indexOf(".");
if(index>0) {
propRest = property.substring(index+1);
property = property.substring(0,index);
logger.finest("slit property into: '"+propRest+"' and '"+property+"'");
}
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) {
Class typeClass = mt.type();
if(Object.class==mt.type()) {
typeClass = method.getReturnType();
//return returnType.getName()+"."+annotationType.toString();
}
// recursif function:
return getValue(typeClass,annotationType,propRest);
}
result = doAnnotation(method.getAnnotation(annotationType));
if(result!=null) {
return result;
}
if (noAnnotationNullReturn) {
return null;
}
break; // return default
}
return beanClass.getName()+"."+property+"."+annotationType.getSimpleName();
}
private Object doAnnotation(Annotation a) {
if (a.equals(VascName.class)) {
VascName l = (VascName)a;
if("".equals(l.key()) | "null".equals(l.key())) {
return null;
}
return l.key();
}
if (a.equals(VascToolTip.class)) {
VascToolTip t = (VascToolTip)a;
if("".equals(t.key()) | "null".equals(t.key())) {
return null;
}
return t.key();
}
if (a.equals(VascHelpId.class)) {
VascHelpId h = (VascHelpId)a;
if("".equals(h.helpId()) | "null".equals(h.helpId())) {
return null;
}
return h.helpId();
}
if (a.equals(VascDefaultValue.class)) {
VascDefaultValue v = (VascDefaultValue)a;
if (v.defaultValue()==null) {
return null; // error ??
}
try {
return v.defaultValue().newInstance();
} catch (Exception e) {
logger.log(Level.WARNING,e.getMessage(),e);
}
}
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

@ -0,0 +1,49 @@
/*
* 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 defaultValue
*
* @author Willem Cazander
* @version 1.0 Mar 28, 2007
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascDefaultValue {
/**
* The defaultValue of the method
*/
Class defaultValue();
}

View file

@ -0,0 +1,49 @@
/*
* 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 helpId
*
* @author Willem Cazander
* @version 1.0 Mar 28, 2007
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascHelpId {
/**
* The defaultValue of the method
*/
String helpId() default "null";
}

View file

@ -0,0 +1,46 @@
/*
* 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;
/**
* When plased on a getter is will redirect the label and tooltip text to the type of the return type
*
* @author Willem Cazander
* @version 1.0 May 27, 2006
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascModelReference {
Class type() default Object.class;
}

View file

@ -0,0 +1,51 @@
/*
* 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 I18nLabel(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 VascName {
/**
* 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";
}

View file

@ -0,0 +1,51 @@
/*
* 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 VascToolTip {
/**
* 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";
}