2
0
Fork 0

basic slit in multi module project

This commit is contained in:
willem.cazander 2010-09-19 22:02:05 +02:00
parent 029ad96a10
commit f79378dacb
239 changed files with 46 additions and 25213 deletions

View file

@ -0,0 +1,625 @@
/*
* 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;
/**
* Parses the Vasc annotations
*
* @author Willem Cazander
* @version 1.0 May 27, 2006
*/
public class VascAnnotationParser {
/**
* 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 getVascI18nDescription(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascI18n.class,property,"description");
}
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 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) {
return (String)getValue(beanClass,VascFieldType.class,property,"type");
}
public String[] getVascFieldTypeProperties(Class<?> beanClass,String property) {
return (String[])getValue(beanClass,VascFieldType.class,property,"properties");
}
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");
}
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");
}
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
* @param beanClass
* @param property
* @return
*/
public String getVascDefaultValue(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascDefaultValue.class,property,null);
}
public String getVascDisplayName(Class<?> beanClass) {
//System.out.println("========== GetDisPlayName: "+beanClass);
// first search in class for display name
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
}
// then search in class for display name on templated fields.
for (Method method:beanClass.getMethods()) {
if (method.getName().startsWith("get")==false) { //a bit durty
continue;
}
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template==null) {
continue; // no template anno
}
//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
}
}
//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;
}
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) {
return null; // no display name
}
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) {
// first search Key anno
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
}
for (Method method:beanClass.getMethods()) {
if(method.getName().startsWith("get")==false) { //a bit durty
continue;
}
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template==null) {
continue; // no template
}
String value = getVascPrimaryKey(template.templateClass()); // note templateing the templated class is possible
if (value!=null) {
return value;
}
}
return null; // maybe fallback on getId() ?
}
/**
* No oop code here...refactor at some point in time
*
*
* @param beanClass
* @param property
* @param annotationType
* @return
*/
@SuppressWarnings("unchecked")
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) {
String def = beanClass.getName()+"."+annotationType.getSimpleName();
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;
}
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;
}
}
return def;
}
String propRest = null;
int index = property.indexOf(".");
if (index>0) {
propRest = property.substring(index+1);
property = property.substring(0,index);
}
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;
}
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();
}
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);
// no annotation == no default
if (anno==null && annotationType.equals(VascDefaultValue.class)) {
return null;
}
result = doAnnotation(anno,def,field);
if(result!=null) {
return result;
}
break; // return default
}
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();
}
if ("sortable".equals(field)) {
return VascField.class.getMethod("sortable").getDefaultValue();
}
// This are the default value then....
return null;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
if (annotationType.equals(VascFieldTemplate.class)) {
return null;
}
if (annotationType.equals(VascFieldType.class)) {
return null;
}
if (annotationType.equals(VascStyle.class)) {
return null;
}
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()) {
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,String def,String field) {
if (b==null) {
return null;
}
Class<?> a = b.annotationType();
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(VascFieldOrder.class)) {
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.value())) {
return null;
}
return v.value();
}
if (a.equals(VascStyle.class)) {
VascStyle c = (VascStyle)b;
if ("sizeList".equals(field)) {
return c.sizeList();
}
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();
}
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)) {
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;
}
}

View file

@ -0,0 +1,245 @@
/*
* 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;
private List<String> dubId = null;
public VascBundleKeyGenerator() {
models = new ArrayList<Class<?>>(30);
keys = new HashMap<String,String>(300);
dubId = new ArrayList<String>(30);
}
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();
dubId.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();
dubId.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();
dubId.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);
}
String idKey = vap.getVascPrimaryKey(bean);
String nameKey = vap.getVascDisplayName(bean);
if (idKey!=null && idKey.equals(nameKey)) {
dubId.add("idKey and nameKey is the same: "+bean.getName());
}
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;
}
public List<String> getDubIdNameKeys() {
return dubId;
}
}

View file

@ -0,0 +1,58 @@
/*
* 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;
/**
* Some choises options
*
* make also the field type to list
*
* @author Willem Cazander
* @version 1.0 Aug 19, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascChoices {
String[] choisesKeys() default {};
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

@ -0,0 +1,52 @@
/*
* 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)
public @interface VascDefaultValue {
//String key() default "";
/**
* Note: special value for default, because else we can not set empty.
* @return
*/
String value() default "null";
}

View file

@ -0,0 +1,45 @@
/*
* 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;
/**
* The field(s)/method used for displaying the display name in lists/etc.
*
* @author Willem Cazander
* @version 1.0 Aug 18, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascDisplayName {
}

View file

@ -0,0 +1,63 @@
/*
* 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;
/**
* Defines the admin interface settings
*
* @author Willem Cazander
* @version 1.0 Aug 18, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface VascEntry {
String id() default "";
String headerName() default "";
String headerDescription() default "";
String headerImage() default "";
String helpId() default "";
boolean vascAdminList() default true;
boolean vascAdminCreate() default true;
boolean vascAdminEdit() default true;
boolean vascAdminDelete() default true;
}

View file

@ -0,0 +1,57 @@
/*
* 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;
/**
* Specefiecs the type of events we want to get from vasc.
*
* @author Willem Cazander
* @version 1.0 Aug 15, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface VascEventChannel {
/**
* The channel to send to.
*/
String channel() default "null";
boolean create() default false;
boolean update() default false;
boolean delete() default false;
boolean listed() default false;
}

View file

@ -0,0 +1,45 @@
/*
* 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;
/**
* Event listener annotation
*
* @author Willem Cazander
* @version 1.0 Apr 23, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface VascEventListener {
Class<?>[] listeners();
}

View file

@ -0,0 +1,68 @@
/*
* 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;
/**
* Some generic field options
*
* @author Willem Cazander
* @version 1.0 Aug 15, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
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;
boolean sortable() default true;
boolean sumable() default false;
boolean graphable() default false;
}

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;
/**
* Lets you order the fields to better UI bahaivur.
*
* @author Willem Cazander
* @version 1.0 Apr 6, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascFieldOrder {
/**
* The editor of the method/field
*/
int orderIndex() default 0;
}

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

@ -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;
/**
* Specefiecs the editor needed for a field
*
* @author Willem Cazander
* @version 1.0 Aug 15, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascFieldType {
/**
* The editor of the method/field
*/
String type() default "";
/**
* Hints for the choosen editor
*/
String[] properties() default {};
}

View file

@ -0,0 +1,57 @@
/*
* 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 VascI18n {
/**
* The key of the Label default to "null"
* @see com.idcanet.i18n.I18nAnnotationParser#getI18nLabelKey(Class, String)
* @return The key of the ToolTip
*/
String name() default "";
String description() default "";
String image() default "";
String helpId() default "";
}

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,45 @@
/*
* 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;
/**
* The field(s)/method used for letting vasc know what the PrimaryKey is so we can load it.
*
* @author Willem Cazander
* @version 1.0 Aug 18, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascPrimaryKey {
}

View file

@ -0,0 +1,62 @@
/*
* 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;
/**
* Specefiecs the roles to view/edit or edit-view only modes
*
* @author Willem Cazander
* @version 1.0 Aug 18, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascRoles {
/**
*
*/
String rolesCreate() default "";
/**
*
*/
String rolesEdit() default "";
/**
*
*/
String rolesEditReadOnly() default "";
String rolesList() default "";
}

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;
/**
* The default column width
*
* @author Willem Cazander
* @version 1.0 Apr 28, 2007
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascStyle {
int sizeList() default 0;
int sizeEdit() default 0;
String styleList() default "";
String styleEdit() default "";
}

View file

@ -0,0 +1,109 @@
/*
* Copyright 2004-2010 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.backends;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValue;
import com.idcanet.x4o.impl.DefaultElementObjectPropertyValue;
/**
*
* @author Willem Cazander
* @version 1.0 Dec 05, 2009
*/
public class BeanVascEntryFieldValue implements VascEntryFieldValue {
private static final long serialVersionUID = 1L;
private DefaultElementObjectPropertyValue bean = new DefaultElementObjectPropertyValue();
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
public Object getValue(VascEntryField field, Object record) throws VascException {
if (field==null) {
throw new NullPointerException("Can't get value of null field.");
}
if (field.getBackendName()==null) {
throw new NullPointerException("Can't get value of null backendName field.");
}
if (record==null) {
throw new NullPointerException("Can't get value of null object.");
}
try {
Object o = bean.getProperty(record,field.getBackendName());
return o;
} catch (Exception e) {
throw new VascException(e);
}
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
public String getDisplayValue(VascEntryField field, Object record) throws VascException {
Object value = getValue(field,record);
if (value==null) {
return "";
}
if (field.getDisplayName()==null) {
if (value instanceof String) {
return (String)value;
}
return ""+value;
}
try {
Object result = bean.getProperty(value, field.getDisplayName());
if (result instanceof String) {
return (String)result;
}
return ""+result;
} catch (Exception e) {
throw new VascException(e);
}
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
*/
public void setValue(VascEntryField field, Object record,Object value) throws VascException {
if (field==null) {
throw new NullPointerException("Can't set value of null field.");
}
if (field.getBackendName()==null) {
throw new NullPointerException("Can't set value of null backendName field.");
}
if (record==null) {
throw new NullPointerException("Can't set value of null object.");
}
try {
bean.setProperty(record, field.getBackendName(), value);
} catch (Exception e) {
throw new VascException(e);
}
}
}

View file

@ -0,0 +1,32 @@
/**
*
*/
package com.idcanet.vasc.backends;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
/**
* @author willemc
*
*/
public class BeanVascEntryRecordCreator implements VascEntryRecordCreator {
private static final long serialVersionUID = 1L;
private Class<?> resultClass = null;
public BeanVascEntryRecordCreator(Class<?> resultClass) {
if (resultClass==null) {
throw new NullPointerException("Can't provide creator service with null class object.");
}
this.resultClass=resultClass;
}
public Class<?> getObjectClass() {
return resultClass;
}
public Object newRecord(VascEntry entry) throws Exception {
return resultClass.newInstance();
}
}

View file

@ -0,0 +1,49 @@
/**
*
*/
package com.idcanet.vasc.backends;
import java.util.Map;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValue;
/**
* @author willemc
*
*/
public class MapVascEntryFieldValue implements VascEntryFieldValue {
private static final long serialVersionUID = 1L;
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public Object getValue(VascEntryField field, Object record) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
Object r = map.get(field.getBackendName());
if (r==null) {
return ""; // create new value, ldap does not return data for field that an user does not have, but other do,...
}
return r;
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
public String getDisplayValue(VascEntryField field, Object record) throws VascException {
return ""+getValue(field,record); // not supported (this)ldap is already fully string based.
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public void setValue(VascEntryField field, Object record,Object value) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
map.put(field.getBackendName(), value);
}
}

View file

@ -0,0 +1,27 @@
/**
*
*/
package com.idcanet.vasc.backends;
import java.util.HashMap;
import java.util.Map;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
/**
* @author willemc
*
*/
public class MapVascEntryRecordCreator implements VascEntryRecordCreator {
private static final long serialVersionUID = 1L;
public Class<?> getObjectClass() {
return Map.class;
}
public Object newRecord(VascEntry entry) throws Exception {
return new HashMap<String,Object>(10);
}
}

View file

@ -0,0 +1,41 @@
/*
* Copyright 2004-2007 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.backends.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public interface JdbcConnectionProvider {
public Connection getJdbcConnection() throws SQLException;
}

View file

@ -0,0 +1,159 @@
/*
* Copyright 2004-2007 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.backends.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.idcanet.vasc.backends.MapVascEntryFieldValue;
import com.idcanet.vasc.backends.MapVascEntryRecordCreator;
import com.idcanet.vasc.core.AbstractVascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValue;
import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class JdbcVascBackend extends AbstractVascBackend {
private JdbcConnectionProvider jdbcConnectionProvider = null;
private String sqlList = null;
private String idColumn = null;
private String sqlDelete = null;
private String sqlUpdate = null;
private String sqlInsert = null;
/**
* @return the JdbcConnectionProvider
*/
public JdbcConnectionProvider getJdbcConnectionProvider() {
return jdbcConnectionProvider;
}
/**
* @param JdbcConnectionProvider the JdbcConnectionProvider to set
*/
public void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) {
this.jdbcConnectionProvider = jdbcConnectionProvider;
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
public List<Object> execute(VascBackendState state) throws VascException {
JdbcConnectionProvider prov = getJdbcConnectionProvider();
List<Object> result = new ArrayList<Object>(50);
Connection connection = null;
try {
connection = prov.getJdbcConnection();
Statement s = connection.createStatement();
s.execute(getSqlList());
ResultSet rs = s.getResultSet();
int cols = rs.getMetaData().getColumnCount();
while (rs.next()) {
Map<String,Object> map = new HashMap<String,Object>(cols);
for (int i=1;i<=cols;i++) {
String columnName = rs.getMetaData().getColumnName(i);
Object columnObject = rs.getObject(i);
map.put(columnName, columnObject);
}
result.add(map);
}
} catch (Exception e) {
throw new VascException(e);
} finally {
if (connection!=null) {
try {
connection.close();
} catch (Exception e) {
}
}
}
return result;
}
/**
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws VascException {
return object;
}
/**
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws VascException {
}
/**
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws VascException {
}
/**
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return new MapVascEntryFieldValue();
}
/**
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new MapVascEntryRecordCreator();
}
/**
* @return the sqlList
*/
public String getSqlList() {
return sqlList;
}
/**
* @param sqlList the sqlList to set
*/
public void setSqlList(String sqlList) {
this.sqlList = sqlList;
}
}

View file

@ -0,0 +1,199 @@
/*
* Copyright 2004-2007 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.backends.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.AbstractVascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValue;
import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
import com.idcanet.xtes.xpql.query.QueryParameterValue;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class JdbcXpqlVascBackend extends AbstractVascBackend {
private JdbcConnectionProvider jdbcConnectionProvider = null;
private com.idcanet.xtes.xpql.query.Query query = null;
/**
* @return the JdbcConnectionProvider
*/
public JdbcConnectionProvider getJdbcConnectionProvider() {
return jdbcConnectionProvider;
}
/**
* @param JdbcConnectionProvider the JdbcConnectionProvider to set
*/
public void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) {
this.jdbcConnectionProvider = jdbcConnectionProvider;
}
/**
* @return the query
*/
public com.idcanet.xtes.xpql.query.Query getQuery() {
return query;
}
/**
* @param query the query to set
*/
public void setQuery(com.idcanet.xtes.xpql.query.Query query) {
this.query = query;
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
public List<Object> execute(VascBackendState state) throws VascException {
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
query.setQueryParameter(key, value);
}
Connection c = null;
try {
c = getJdbcConnectionProvider().getJdbcConnection();;
PreparedStatement q = c.prepareStatement(query.toPreparedSQL(query));
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
int ii = 1;
for (QueryParameterValue value:values) {
q.setObject(ii,value.getValue());
ii++;
}
q.execute();
ResultSet rs = q.getResultSet();
int cols = rs.getMetaData().getColumnCount();
List<Object> result = new ArrayList<Object>(50);
while (rs.next()) {
Map<String,Object> map = new HashMap<String,Object>(cols);
for (int i=1;i<=cols;i++) {
String columnName = rs.getMetaData().getColumnName(i);
Object columnObject = rs.getObject(i);
map.put(columnName, columnObject);
}
result.add(map);
}
return result;
} catch (Exception e) {
throw new VascException(e);
} finally {
if (c!=null) {
try {
c.close();
} catch (Exception e) {
}
}
}
}
/**
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws VascException {
return object;
}
/**
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws VascException {
}
/**
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws VascException {
}
/**
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
VascEntryFieldValue result = new VascEntryFieldValue() {
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public Object getValue(VascEntryField field, Object record) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
Object o = map.get(field.getBackendName());
return o;
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
public String getDisplayValue(VascEntryField field, Object record) throws VascException {
return ""+getValue(field,record); // not supported
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public void setValue(VascEntryField field, Object record,Object value) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
map.put(field.getBackendName(), value);
}
};
return result;
}
/**
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new VascEntryRecordCreator() {
public Class<?> getObjectClass() {
return Map.class;
}
public Object newRecord(VascEntry entry) throws Exception {
return new HashMap<String,Object>(10);
}
};
}
}

View file

@ -0,0 +1,112 @@
/*
* Copyright 2004-2007 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.backends.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 15, 2009
*/
public class JdniDataSourceJdbcConnectionProvider implements JdbcConnectionProvider {
/** The context in which database data sources are found. */
private String dataSourceContext = "java:/";
private String dataSourceName = null;
/**
* @see com.idcanet.vasc.backends.jdbc.JdbcConnectionProvider#getJdbcConnection()
*/
public Connection getJdbcConnection() throws SQLException {
Connection connection = getDataSource(dataSourceName).getConnection();
return connection;
}
/**
* Gets a DataSource out of the JNDI context.
* <p>
* @param name The name of the data source in the JDNI context.
* @return The data source.
*/
private DataSource getDataSource(String name) throws SQLException {
try {
Context initialContext = new InitialContext();
if ( initialContext == null ) {
throw new SQLException("Cannot get Initial Context");
}
DataSource datasource = (DataSource)initialContext.lookup(dataSourceContext+name);
if ( datasource == null ) {
throw new SQLException("Cannot lookup datasource: "+name);
}
return datasource;
} catch ( NamingException e ) {
throw new SQLException("Cannot get connection " + e,e);
}
}
/**
* @return the dataSourceContext
*/
public String getDataSourceContext() {
return dataSourceContext;
}
/**
* @param dataSourceContext the dataSourceContext to set
*/
public void setDataSourceContext(String dataSourceContext) {
this.dataSourceContext = dataSourceContext;
}
/**
* @return the dataSourceName
*/
public String getDataSourceName() {
return dataSourceName;
}
/**
* @param dataSourceName the dataSourceName to set
*/
public void setDataSourceName(String dataSourceName) {
this.dataSourceName = dataSourceName;
}
}

View file

@ -0,0 +1,121 @@
/*
* Copyright 2004-2007 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.backends.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 15, 2009
*/
public class SimpleJdbcConnectionProvider implements JdbcConnectionProvider {
private String driverClassName = null;
private String dbUrl = null;
private String dbUser = null;
private String dbPassword = null;
private boolean loadedDriver = false;
/**
* @see com.idcanet.vasc.backends.jdbc.JdbcConnectionProvider#getJdbcConnection()
*/
public Connection getJdbcConnection() throws SQLException {
if (loadedDriver==false) {
try {
Class.forName(driverClassName);
loadedDriver = true;
} catch (ClassNotFoundException e) {
throw new SQLException("Could not load driver: "+driverClassName+" error: "+e.getMessage(),e);
}
}
Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
return connection;
}
/**
* @return the driverClassName
*/
public String getDriverClassName() {
return driverClassName;
}
/**
* @param driverClassName the driverClassName to set
*/
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
/**
* @return the dbUrl
*/
public String getDbUrl() {
return dbUrl;
}
/**
* @param dbUrl the dbUrl to set
*/
public void setDbUrl(String dbUrl) {
this.dbUrl = dbUrl;
}
/**
* @return the dbUser
*/
public String getDbUser() {
return dbUser;
}
/**
* @param dbUser the dbUser to set
*/
public void setDbUser(String dbUser) {
this.dbUser = dbUser;
}
/**
* @return the dbPassword
*/
public String getDbPassword() {
return dbPassword;
}
/**
* @param dbPassword the dbPassword to set
*/
public void setDbPassword(String dbPassword) {
this.dbPassword = dbPassword;
}
}

View file

@ -0,0 +1,45 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascDateFuture {
}

View file

@ -0,0 +1,69 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
import java.util.Date;
/**
* Validates
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascDateFutureValidator implements VascValidator {
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
if ((object instanceof Date)==false) {
return false;
}
Date dateCheck = (Date)object;
Date dateNow = new Date();
return dateCheck.after(dateNow);
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascDateFuture.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
}
public VascValidator clone() throws CloneNotSupportedException {
VascDateFutureValidator result = new VascDateFutureValidator();
return result;
}
}

View file

@ -0,0 +1,46 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascDatePast {
}

View file

@ -0,0 +1,69 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
import java.util.Date;
/**
* Validates
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascDatePastValidator implements VascValidator {
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
if ((object instanceof Date)==false) {
return false;
}
Date dateCheck = (Date)object;
Date dateNow = new Date();
return dateCheck.after(dateNow);
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascDatePast.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
}
public VascValidator clone() throws CloneNotSupportedException {
VascDateFutureValidator result = new VascDateFutureValidator();
return result;
}
}

View file

@ -0,0 +1,56 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascIntSize {
/**
* The minimal size
* @return
*/
int min() default 0;
/**
* The maximum size
* @return
*/
int max() default 0;
}

View file

@ -0,0 +1,109 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
/**
* Validates
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascIntSizeValidator implements VascValidator {
private int max = Integer.MAX_VALUE;
private int min = Integer.MIN_VALUE;
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
if ((object instanceof Integer)==false) {
return false; // only Integer can be matched.
}
Integer value = (Integer)object;
if (value > max) {
return false;
}
if (value < min) {
return false;
}
return true;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascIntSizeValidator.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
VascIntSize a = VascIntSize.class.cast(annotation);
setMin(a.min());
setMax(a.max());
}
/**
* @return the max
*/
public int getMax() {
return max;
}
/**
* @param max the max to set
*/
public void setMax(int max) {
this.max = max;
}
/**
* @return the min
*/
public int getMin() {
return min;
}
/**
* @param min the min to set
*/
public void setMin(int min) {
this.min = min;
}
public VascValidator clone() throws CloneNotSupportedException {
VascIntSizeValidator result = new VascIntSizeValidator();
result.min=min;
result.max=max;
return result;
}
}

View file

@ -0,0 +1,56 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascLongSize {
/**
* The minimal size
* @return
*/
long min() default 0;
/**
* The maximum size
* @return
*/
long max() default 0;
}

View file

@ -0,0 +1,109 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
/**
* Validates
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascLongSizeValidator implements VascValidator {
private long max = Long.MAX_VALUE;
private long min = Long.MIN_VALUE;
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
if ((object instanceof Long)==false) {
return false; // only string can be matched.
}
Long value = (Long)object;
if (value > max) {
return false;
}
if (value < min) {
return false;
}
return true;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascLongSize.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
VascLongSize a = VascLongSize.class.cast(annotation);
setMin(a.min());
setMax(a.max());
}
/**
* @return the max
*/
public long getMax() {
return max;
}
/**
* @param max the max to set
*/
public void setMax(long max) {
this.max = max;
}
/**
* @return the min
*/
public long getMin() {
return min;
}
/**
* @param min the min to set
*/
public void setMin(long min) {
this.min = min;
}
public VascValidator clone() throws CloneNotSupportedException {
VascLongSizeValidator result = new VascLongSizeValidator();
result.min=min;
result.max=max;
return result;
}
}

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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascObjectNotNull {
}

View file

@ -0,0 +1,63 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
/**
* Validates
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascObjectNotNullValidator implements VascValidator {
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
return object!=null;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascObjectNotNull.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
}
public VascValidator clone() throws CloneNotSupportedException {
VascObjectNotNullValidator result = new VascObjectNotNullValidator();
return result;
}
}

View file

@ -0,0 +1,46 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascObjectNull {
}

View file

@ -0,0 +1,63 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
/**
* Validates
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascObjectNullValidator implements VascValidator {
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
return object==null;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascObjectNull.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
}
public VascValidator clone() throws CloneNotSupportedException {
VascObjectNullValidator result = new VascObjectNullValidator();
return result;
}
}

View file

@ -0,0 +1,51 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an url field of a bean.
* Also works on String types
*
* @author Willem Cazander
* @version 1.0 Dec 15, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascObjectUrl {
/**
* The regex to match on the url to forbid some urls.
* @return
*/
String forbidRegex();
}

View file

@ -0,0 +1,117 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Validates the url annotations
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascObjectUrlValidator implements VascValidator {
private Pattern pattern = null;
/**
* Sets the regulare expression on which this object filters an String.<br>
* <br>
* When set to <code>Null</code> matching is disabled.<br>
*
* @param regex The regulare expression to match to.
*/
public void setForbidRegEx(String regex) {
pattern = Pattern.compile(regex);
}
/**
* Returns the current regulare expression.
* @return The regulare expression.
*/
public String getForbidRegEx() {
if(pattern==null) {
return null;
}
return pattern.pattern();
}
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
if (object==null) {
return true;
}
URL url = null;
if (object instanceof URL) {
url = (URL)object;
}
if (object instanceof String) {
try {
url = new URL((String)object);
} catch (MalformedURLException e) {
throw new VascValidatorException("Url not valid: "+(String)object,e);
}
}
if (url==null) {
throw new VascValidatorException("Object could not be translated into url: "+object);
}
if (pattern==null) {
return true;
}
String urlString = url.toExternalForm();
// test if regex matches
Matcher m = pattern.matcher(urlString);
return !m.find(); // if found then url it NOT valid
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascObjectNull.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
VascObjectUrl a = VascObjectUrl.class.cast(annotation);
setForbidRegEx(a.forbidRegex());
}
public VascValidator clone() throws CloneNotSupportedException {
VascObjectUrlValidator result = new VascObjectUrlValidator();
result.pattern=pattern;
return result;
}
}

View file

@ -0,0 +1,46 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascStringEmail {
}

View file

@ -0,0 +1,68 @@
/*
* Copyright 2004-2008 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.validators;
/**
* Validates emails addresses.
*
* based on the following regex:
* <pre>
* EMAIL_REGEX = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*";
* </pre>
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascStringEmailValidator extends VascStringRegexValidator {
static private final String EMAIL_REGEX = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*";
/**
* The constructor which sets the regex for email validation
*/
public VascStringEmailValidator() {
setRegEx(EMAIL_REGEX);
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascStringEmail.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.Class)
*/
public void initAnnotation(Class<?> annotationType) {
}
public VascValidator clone() throws CloneNotSupportedException {
VascStringEmailValidator result = new VascStringEmailValidator();
return result;
}
}

View file

@ -0,0 +1,61 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascStringLength {
/**
* The minimal length
* @return
*/
int min() default 0;
/**
* The maximum length
* @return
*/
int max() default 0;
/**
* Is null a valid value
*/
boolean nullable() default false;
}

View file

@ -0,0 +1,131 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
/**
* Validates
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascStringLengthValidator implements VascValidator {
private Integer minLenght = 0;
private Integer maxLenght = Integer.MAX_VALUE;
private boolean nullable = false;
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
if (nullable && object==null) {
return true;
}
if ((object instanceof String)==false) {
return false; // only string can be matched.
}
String result = (String)object;
if (getMinLenght()!=null && result.length()<getMinLenght()) {
return false;
}
if (getMaxLenght()!=null && result.length()>getMaxLenght()) {
return false;
}
return true;
}
/**
* @return the minLenght
*/
public Integer getMinLenght() {
return minLenght;
}
/**
* @param minLenght the minLenght to set
*/
public void setMinLenght(Integer minLenght) {
this.minLenght = minLenght;
}
/**
* @return the maxLenght
*/
public Integer getMaxLenght() {
return maxLenght;
}
/**
* @param maxLenght the maxLenght to set
*/
public void setMaxLenght(Integer maxLenght) {
this.maxLenght = maxLenght;
}
/**
* @return the nullable
*/
public boolean isNullable() {
return nullable;
}
/**
* @param nullable the nullable to set
*/
public void setNullable(boolean nullable) {
this.nullable = nullable;
}
public Class<?> getAnnotationType() {
return VascStringLength.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
VascStringLength a = VascStringLength.class.cast(annotation);
if (a.min()!=0) {
setMinLenght(a.min());
}
if (a.max()!=0) {
setMaxLenght(a.max());
}
setNullable(a.nullable());
}
public VascValidator clone() throws CloneNotSupportedException {
VascStringLengthValidator result = new VascStringLengthValidator();
result.minLenght=minLenght;
result.maxLenght=maxLenght;
result.nullable=nullable;
return result;
}
}

View file

@ -0,0 +1,50 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Mar 14, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascStringRegex {
/**
* The regex to match on the String field
* @return
*/
String regex();
}

View file

@ -0,0 +1,96 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Validates with custum regex.
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascStringRegexValidator implements VascValidator {
private Pattern pattern = null;
/**
* Sets the regulare expression on which this object filters an String.<br>
* <br>
* When set to <code>Null</code> matching is disabled.<br>
*
* @param regex The regulare expression to match to.
*/
public void setRegEx(String regex) {
pattern = Pattern.compile(regex);
}
/**
* Returns the current regulare expression.
* @return The regulare expression.
*/
public String getRegEx() {
if(pattern==null) {
return null;
}
return pattern.pattern();
}
/**
* @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object)
*/
public boolean isObjectValid(Object object) throws VascValidatorException {
if ((object instanceof String)==false) {
return false; // only string can be matched.
}
// test if regex matches
Matcher m = pattern.matcher((String)object);
return m.find();
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascStringRegex.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation)
*/
public void initAnnotation(Annotation annotation) {
VascStringRegex a = VascStringRegex.class.cast(annotation);
setRegEx(a.regex());
}
public VascValidator clone() throws CloneNotSupportedException {
VascStringRegexValidator result = new VascStringRegexValidator();
result.pattern=pattern;
return result;
}
}

View file

@ -0,0 +1,46 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to validate an field of a bean.
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascStringZipCode {
}

View file

@ -0,0 +1,79 @@
/*
* Copyright 2004-2008 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.validators;
/**
* Validates
*
* TODO:
* #Japanese postal codes
* zipJP=^\d{3}-\d{4}$
* #US postal codes
* zipUS=^\d{5}\p{Punct}?\s?(?:\d{4})?$
* #Dutch postal code
* zipNL=^[0-9]{4}\s*[a-zA-Z]{2}$
* #Argentinean postal code
* zipAR=^\d{3}-\d{4}$
* #Swedish postal code
* zipSE=^(s-|S-){0,1}[0-9]{3}\s?[0-9]{2}$
* #Canadian postal code
* zipCA=^([A-Z]\d[A-Z]\s\d[A-Z]\d)$
* #UK postal code
* zipUK=^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascStringZipCodeValidator extends VascStringRegexValidator {
static private final String ZIP_REGEX = "^[0-9]{4}\\s*[a-zA-Z]{2}$";
/**
* The constructor which sets the regex for email validation
*/
public VascStringZipCodeValidator() {
setRegEx(ZIP_REGEX);
}
/**
* @see com.idcanet.vasc.validators.VascValidator#getAnnotationType()
*/
public Class<?> getAnnotationType() {
return VascStringZipCode.class;
}
/**
* @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.Class)
*/
public void initAnnotation(Class<?> annotationType) {
VascStringRegex a = VascStringRegex.class.cast(annotationType);
if (a.regex().equals("null")) {
return;
}
setRegEx(a.regex());
}
}

View file

@ -0,0 +1,56 @@
/*
* Copyright 2004-2008 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.validators;
import java.io.Serializable;
import java.lang.annotation.Annotation;
/**
* The VascValidator interface
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public interface VascValidator extends Cloneable,Serializable {
public boolean isObjectValid(Object object) throws VascValidatorException;
/**
* May return null for no annotation support
* @return
*/
public Class<?> getAnnotationType();
public void initAnnotation(Annotation annotation);
/**
* Force impl to have public clone methode
* @return
* @throws CloneNotSupportedException
*/
public VascValidator clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,83 @@
/*
* Copyright 2004-2008 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.validators;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* The VascValidator interface
*
* @author Willem Cazander
* @version 1.0 Sep 14, 2008
*/
public class VascValidatorClassParser {
private List<VascValidator> validators = null;
public VascValidatorClassParser() {
validators = new ArrayList<VascValidator>(20);
validators.add(new VascDateFutureValidator());
validators.add(new VascDatePastValidator());
validators.add(new VascIntSizeValidator());
validators.add(new VascLongSizeValidator());
validators.add(new VascObjectNotNullValidator());
validators.add(new VascObjectNullValidator());
validators.add(new VascObjectUrlValidator());
validators.add(new VascStringEmailValidator());
validators.add(new VascStringLengthValidator());
validators.add(new VascStringRegexValidator());
validators.add(new VascStringZipCodeValidator());
}
public List<VascValidator> getValidatorsByPropertyName(Class<?> parseClass,String propertyName) {
List<VascValidator> result = new ArrayList<VascValidator>(4);
for(Method method:parseClass.getMethods()) {
if (method.getName().equalsIgnoreCase("get"+propertyName)==false) { //a bit dirty
continue;
}
for (VascValidator v:validators) {
for (Annotation a:method.getAnnotations()) {
if (a.annotationType().equals(v.getAnnotationType())) {
try {
VascValidator val = v.clone();
val.initAnnotation(a);
result.add(val);
} catch (CloneNotSupportedException e) {
}
}
}
}
break;
}
return result;
}
}

View file

@ -0,0 +1,50 @@
/*
* Copyright 2004-2008 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.validators;
/**
* The VascValidatorException
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class VascValidatorException extends Exception {
private static final long serialVersionUID = 510901125063551186L;
public VascValidatorException() {
}
public VascValidatorException(String message) {
super(message);
}
public VascValidatorException(String message,Exception exception) {
super(message,exception);
}
}

View file

@ -0,0 +1,69 @@
/*
* Copyright 2004-2008 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.validators;
import com.idcanet.vasc.core.VascEntry;
/**
* The VascValidator interface
*
* @author Willem Cazander
* @version 1.0 May 14, 2009
*/
public class VascValidatorMessages {
public String getErrorI18nKey(VascValidator val) {
return "vasc.validator."+val.getClass().getSimpleName();
}
public String getErrorMessage(VascEntry entry,VascValidator val) {
String key = getErrorI18nKey(val);
String message = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key);
if (val instanceof VascIntSizeValidator) {
VascIntSizeValidator v = (VascIntSizeValidator)val;
message = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,v.getMin(),v.getMax());
return message;
}
if (val instanceof VascLongSizeValidator) {
VascLongSizeValidator v = (VascLongSizeValidator)val;
message = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,v.getMin(),v.getMax());
return message;
}
if (val instanceof VascStringLengthValidator) {
VascStringLengthValidator v = (VascStringLengthValidator)val;
message = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,v.getMinLenght(),v.getMaxLenght());
return message;
}
if (val instanceof VascStringRegexValidator) {
VascStringRegexValidator v = (VascStringRegexValidator)val;
message = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,v.getRegEx());
return message;
}
return message;
}
}

View file

@ -0,0 +1,69 @@
/*
* 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;
import java.io.InputStream;
import java.util.logging.LogManager;
import com.idcanet.vasc.core.VascEntryFieldType;
import com.idcanet.vasc.impl.type.FieldTypeParser;
import junit.framework.TestCase;
/**
* Tests a simple x4o xml language.
*
* @author Willem Cazander
* @version 1.0 Jul 24, 2006
*/
public class FieldTypesTest extends TestCase {
public void setUp() throws Exception {
// enable all logs
// //InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties");
// LogManager.getLogManager().readConfiguration( loggingProperties );
// loggingProperties.close();
}
public void tearDown() throws Exception {
}
public void testNull() throws Exception {
assertEquals(true, true);
}
/*
public void testParse() throws Exception {
FieldTypeParser p = new FieldTypeParser();
p.parseVascFieldTypes();
System.out.println("Got types;");
for (VascEntryFieldType t:p.getTypes()) {
System.out.println("t= "+t.getId());
}
}
*/
}