Author: tv
Date: Tue Apr 7 19:06:44 2015
New Revision: 1671923
URL: http://svn.apache.org/r1671923
Log:
Move to JAXB for parsing and object mapping.
Added:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/AppData.java
- copied, changed from r1658225,
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/AppData.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java
(with props)
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Rule.java
- copied, changed from r1658225,
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/Rule.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java
- copied, changed from r1658225,
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/package-info.java
(with props)
Removed:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldFactory.java
Modified:
turbine/fulcrum/trunk/intake/pom.xml
turbine/fulcrum/trunk/intake/src/changes/changes.xml
turbine/fulcrum/trunk/intake/src/dtd/intake.xsd
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DateStringField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Field.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FileItemField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/StringField.java
turbine/fulcrum/trunk/intake/src/test/intake1.xml
turbine/fulcrum/trunk/intake/src/test/intake2.xml
turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/MyField.java
Modified: turbine/fulcrum/trunk/intake/pom.xml
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/pom.xml?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/pom.xml (original)
+++ turbine/fulcrum/trunk/intake/pom.xml Tue Apr 7 19:06:44 2015
@@ -25,7 +25,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.fulcrum</groupId>
<artifactId>fulcrum-intake</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<name>Fulcrum Intake Service</name>
<inceptionYear>2005</inceptionYear>
<description>This Service provides rule-based input validation</description>
@@ -34,7 +34,7 @@
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/turbine/fulcrum/trunk/intake/</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/turbine/fulcrum/trunk/intake/</developerConnection>
- <url>http://svn.apache.org/viewcvs/turbine/fulcrum/trunk/intake/</url>
+ <url>http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/</url>
</scm>
<developers>
@@ -108,9 +108,9 @@
<version>1.1.3</version>
</dependency>
<dependency>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- <version>1.6</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-pool2</artifactId>
+ <version>2.0</version>
</dependency>
<!-- testing dependencies -->
Modified: turbine/fulcrum/trunk/intake/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/changes/changes.xml?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/changes/changes.xml (original)
+++ turbine/fulcrum/trunk/intake/src/changes/changes.xml Tue Apr 7 19:06:44
2015
@@ -25,7 +25,10 @@
</properties>
<body>
- <release version="1.1.1" date="in Subversion">
+ <release version="1.2.0" date="in Subversion">
+ <action dev="tv" type="update">
+ Move to JAXB for parsing and object mapping.
+ </action>
</release>
<release version="1.1.0" date="2013-12-??">
<action dev="tv" type="add">
@@ -44,7 +47,7 @@
Update dependency commons-logging to 1.1.3
</action>
<action dev="tv" type="update">
- Update dependency commons-pool to 1.6
+ Update dependency commons-pool to 2.0
</action>
<action dev="tv" type="update">
Update dependency fulcrum-parser to 1.0.3
Modified: turbine/fulcrum/trunk/intake/src/dtd/intake.xsd
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/dtd/intake.xsd?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/dtd/intake.xsd (original)
+++ turbine/fulcrum/trunk/intake/src/dtd/intake.xsd Tue Apr 7 19:06:44 2015
@@ -22,7 +22,7 @@
xmlns:tns="http://turbine.apache.org/schema/intake/4.0"
elementFormDefault="qualified">
- <element name="input-data" type="tns:input-dataComplexType">
+ <element name="input-data" type="tns:inputDataComplexType">
</element>
<complexType name="groupComplexType">
<sequence>
@@ -72,7 +72,7 @@
</annotation>
</attribute>
</complexType>
- <complexType name="input-dataComplexType">
+ <complexType name="inputDataComplexType">
<annotation>
<documentation>The input-data element is the root of the intake
XML definition file.</documentation>
Copied:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/AppData.java
(from r1658225,
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/AppData.java)
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/AppData.java?p2=turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/AppData.java&p1=turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/AppData.java&r1=1658225&r2=1671923&rev=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/AppData.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/AppData.java
Tue Apr 7 19:06:44 2015
@@ -1,4 +1,4 @@
-package org.apache.fulcrum.intake.xmlmodel;
+package org.apache.fulcrum.intake.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -20,11 +20,15 @@ package org.apache.fulcrum.intake.xmlmod
*/
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
import org.apache.fulcrum.intake.IntakeException;
-import org.xml.sax.Attributes;
/**
* A class for holding application data structures.
@@ -34,8 +38,9 @@ import org.xml.sax.Attributes;
* @author <a href="mailto:[email protected]">Thomas Vandahl</a>
* @version $Id$
*/
-public class AppData
- implements Serializable
+@XmlRootElement(name="input-data")
+@XmlAccessorType(XmlAccessType.NONE)
+public class AppData implements Serializable
{
/**
* Serial version id
@@ -43,48 +48,15 @@ public class AppData
private static final long serialVersionUID = -3953843038383617960L;
/** List of groups */
- private final List<XmlGroup> inputs;
+ private List<Group> groups;
/** Package that will be used for all mapTo objects */
- private String basePackage;
+ private String basePackage = "";
/** Prefix string that will be used to qualify
<prefix>:<intakegroup> names */
private String groupPrefix;
/**
- * Default Constructor
- */
- public AppData()
- {
- inputs = new ArrayList<XmlGroup>();
- }
-
- /**
- * Imports the top level element from an XML specification
- */
- public void loadFromXML(Attributes attrib)
- {
- String basePkg = attrib.getValue("basePackage");
- if (basePkg == null)
- {
- setBasePackage("");
- }
- else
- {
- if (basePkg.charAt(basePkg.length() - 1) != '.')
- {
- setBasePackage(basePkg + '.');
- }
- else
- {
- setBasePackage(basePkg);
- }
- }
-
- setGroupPrefix(attrib.getValue("groupPrefix"));
- }
-
- /**
* Return a collection of input sections (<group>).
* The names of the groups returned here are only unique
* to this AppData object and not qualified with the groupPrefix.
@@ -92,9 +64,20 @@ public class AppData
* groups with and without prefix in the service.
*
*/
- public List<XmlGroup> getGroups()
+ public List<Group> getGroups()
{
- return inputs;
+ return groups;
+ }
+
+ /**
+ * Set the collection of groups
+ *
+ * @param groups the groups to set
+ */
+ @XmlElement(name="group")
+ public void setGroups(List<Group> groups)
+ {
+ this.groups = groups;
}
/**
@@ -102,10 +85,10 @@ public class AppData
* qualified and unqualified names in this package.
*
* @param groupName a <code>String</code> value
- * @return a <code>XmlGroup</code> value
+ * @return a <code>Group</code> value
* @throws IntakeException indicates that the groupName was null
*/
- public XmlGroup getGroup(String groupName)
+ public Group getGroup(String groupName)
throws IntakeException
{
if (groupName == null)
@@ -116,9 +99,9 @@ public class AppData
String groupPrefix = getGroupPrefix();
- for (XmlGroup group : inputs)
+ for (Group group : groups)
{
- if (group.getName().equals(groupName))
+ if (group.getIntakeGroupName().equals(groupName))
{
return group;
}
@@ -128,7 +111,7 @@ public class AppData
qualifiedGroupName.append(groupPrefix)
.append(':')
- .append(group.getName());
+ .append(group.getIntakeGroupName());
if (qualifiedGroupName.toString().equals(groupName))
{
@@ -140,28 +123,6 @@ public class AppData
}
/**
- * An utility method to add a new input group from
- * an xml attribute.
- */
- public XmlGroup addGroup(Attributes attrib)
- {
- XmlGroup input = new XmlGroup();
- input.loadFromXML(attrib);
- addGroup(input);
- return input;
- }
-
- /**
- * Add an input group to the vector and sets the
- * AppData property to this AppData
- */
- public void addGroup(XmlGroup input)
- {
- input.setAppData(this);
- inputs.add(input);
- }
-
- /**
* Get the base package String that will be appended to
* any mapToObjects
*
@@ -178,9 +139,25 @@ public class AppData
*
* @param v Value to assign to basePackage.
*/
+ @XmlAttribute
public void setBasePackage(String v)
{
- this.basePackage = v;
+ if (v == null)
+ {
+ this.basePackage = "";
+ }
+ else
+ {
+ if (v.endsWith("."))
+ {
+ this.basePackage = v;
+ }
+ else
+ {
+ this.basePackage = v + ".";
+ }
+ }
+
}
/**
@@ -200,6 +177,7 @@ public class AppData
*
* @param groupPrefix Value to assign to basePackage.
*/
+ @XmlAttribute
public void setGroupPrefix(String groupPrefix)
{
this.groupPrefix = groupPrefix;
@@ -209,12 +187,13 @@ public class AppData
* Creates a string representation of this AppData.
* The representation is given in xml format.
*/
+ @Override
public String toString()
{
StringBuilder result = new StringBuilder();
result.append("<input-data>\n");
- for (XmlGroup group : inputs)
+ for (Group group : groups)
{
result.append(group);
}
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java
Tue Apr 7 19:06:44 2015
@@ -23,7 +23,6 @@ import java.math.BigDecimal;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.validator.BigDecimalValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
* @author <a href="mailto:[email protected]">John McNally</a>
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java
Tue Apr 7 19:06:44 2015
@@ -21,7 +21,6 @@ package org.apache.fulcrum.intake.model;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.validator.BooleanValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
* Processor for boolean fields.
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DateStringField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DateStringField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DateStringField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DateStringField.java
Tue Apr 7 19:06:44 2015
@@ -27,7 +27,6 @@ import org.apache.commons.lang.StringUti
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.IntakeRuntimeException;
import org.apache.fulcrum.intake.validator.DateStringValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java
Tue Apr 7 19:06:44 2015
@@ -21,7 +21,6 @@ package org.apache.fulcrum.intake.model;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.validator.DoubleValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
* Processor for double fields.
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Field.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Field.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Field.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Field.java
Tue Apr 7 19:06:44 2015
@@ -19,6 +19,10 @@ package org.apache.fulcrum.intake.model;
* under the License.
*/
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;
@@ -34,8 +38,6 @@ import org.apache.fulcrum.intake.validat
import org.apache.fulcrum.intake.validator.InitableByConstraintMap;
import org.apache.fulcrum.intake.validator.ValidationException;
import org.apache.fulcrum.intake.validator.Validator;
-import org.apache.fulcrum.intake.xmlmodel.Rule;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
import org.apache.fulcrum.parser.ValueParser;
/**
@@ -49,8 +51,11 @@ import org.apache.fulcrum.parser.ValuePa
* @author <a href="mailto:[email protected]">Thomas Vandahl</a>
* @version $Id$
*/
-public abstract class Field<T>
+public abstract class Field<T> implements Serializable
{
+ /** Serial version */
+ private static final long serialVersionUID = 6897267716698096895L;
+
/** Empty Value */
private static final String EMPTY = "";
@@ -75,16 +80,22 @@ public abstract class Field<T>
protected final String displaySize;
/** Class name of the object to which the field is mapped */
- protected final String mapToObject;
+ protected String mapToObject;
+
+ /** Optional property name of the object to which the field is mapped */
+ protected String mapToProperty;
+
+ /** Class name of the validator (for deserialization) */
+ protected String validatorClassName;
/** Used to validate the contents of the field */
- protected final Validator<T> validator;
+ protected transient Validator<T> validator;
/** Getter method in the mapped object used to populate the field */
- protected final Method getter;
+ protected Method getter;
/** Setter method in the mapped object used to store the value of field */
- protected final Method setter;
+ protected Method setter;
/** Error message set on the field if required and not set by parser */
protected String ifRequiredMessage;
@@ -208,7 +219,7 @@ public abstract class Field<T>
+ field.getEmptyValue(), e);
}
- String validatorClassName = field.getValidator();
+ this.validatorClassName = field.getValidator();
if (validatorClassName == null)
{
validatorClassName = getDefaultValidator();
@@ -220,41 +231,7 @@ public abstract class Field<T>
if (validatorClassName != null)
{
- try
- {
- validator = (Validator<T>)
- Class.forName(validatorClassName).newInstance();
- }
- catch (InstantiationException e)
- {
- throw new IntakeException(
- "Could not create new instance of Validator("
- + validatorClassName + ")", e);
- }
- catch (IllegalAccessException e)
- {
- throw new IntakeException(
- "Could not create new instance of Validator("
- + validatorClassName + ")", e);
- }
- catch (ClassNotFoundException e)
- {
- throw new IntakeException(
- "Could not load Validator class("
- + validatorClassName + ")", e);
- }
- // this should always be true for now
- // (until bean property initialization is implemented)
- if (validator instanceof InitableByConstraintMap)
- {
- ((InitableByConstraintMap) validator).init(field.getRuleMap());
- }
- else
- {
- throw new IntakeError(
- "All Validation objects must be subclasses of "
- + "InitableByConstraintMap");
- }
+ validator = createValidator(validatorClassName, field);
}
else
{
@@ -277,41 +254,47 @@ public abstract class Field<T>
// map the getter and setter methods
mapToObject = field.getMapToObject();
- String propName = field.getMapToProperty();
+ mapToProperty = field.getMapToProperty();
+ valArray = new Object[1];
+ }
+
+ /**
+ * Initialize getter and setter from properties
+ */
+ public void initGetterAndSetter()
+ {
Method tmpGetter = null;
Method tmpSetter = null;
if (StringUtils.isNotEmpty(mapToObject)
- && StringUtils.isNotEmpty(propName))
+ && StringUtils.isNotEmpty(mapToProperty))
{
try
{
- tmpGetter = IntakeServiceFacade.getFieldGetter(mapToObject,
propName);
+ tmpGetter = IntakeServiceFacade.getFieldGetter(mapToObject,
mapToProperty);
}
catch (Exception e)
{
log.error("IntakeService could not map the getter for field "
+ this.getDisplayName() + " in group "
+ this.group.getIntakeGroupName()
- + " to the property " + propName + " in object "
+ + " to the property " + mapToProperty + " in object "
+ mapToObject, e);
}
try
{
- tmpSetter = IntakeServiceFacade.getFieldSetter(mapToObject,
propName);
+ tmpSetter = IntakeServiceFacade.getFieldSetter(mapToObject,
mapToProperty);
}
catch (Exception e)
{
log.error("IntakeService could not map the setter for field "
+ this.getDisplayName() + " in group "
+ this.group.getIntakeGroupName()
- + " to the property " + propName + " in object "
+ + " to the property " + mapToProperty + " in object "
+ mapToObject, e);
}
}
getter = tmpGetter;
setter = tmpSetter;
-
- valArray = new Object[1];
}
/**
@@ -420,6 +403,14 @@ public abstract class Field<T>
}
/**
+ * Get the name of the object that takes this input
+ */
+ public String getMapToObject()
+ {
+ return mapToObject;
+ }
+
+ /**
* Flag to determine whether the field has been declared as multi-valued.
*
* @return value of isMultiValued.
@@ -601,6 +592,7 @@ public abstract class Field<T>
/**
* @deprecated Call validate() instead (with no parameters).
*/
+ @Deprecated
protected boolean validate(ValueParser pp)
{
return validate();
@@ -811,6 +803,7 @@ public abstract class Field<T>
*
* @return a <code>String</code> value
*/
+ @Override
public String toString()
{
String res = EMPTY;
@@ -1053,4 +1046,98 @@ public abstract class Field<T>
return this.toString();
}
+ /**
+ * Create a validator instance for the given class name
+ *
+ * @param validatorClassName the class name
+ * @param field the related xml field containing the rule map
+ * @return the validator instance
+ * @throws IntakeException if the instance could not be created
+ */
+ @SuppressWarnings("unchecked")
+ private Validator<T> createValidator(String validatorClassName, XmlField
field)
+ throws IntakeException
+ {
+ Validator<T> v;
+
+ try
+ {
+ v = (Validator<T>)
+ Class.forName(validatorClassName).newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new IntakeException(
+ "Could not create new instance of Validator("
+ + validatorClassName + ")", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new IntakeException(
+ "Could not create new instance of Validator("
+ + validatorClassName + ")", e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IntakeException(
+ "Could not load Validator class("
+ + validatorClassName + ")", e);
+ }
+
+ // this should always be true for now
+ // (until bean property initialization is implemented)
+ // FIXME: rulemap is not available when deserialized
+ if (field != null)
+ {
+ if (v instanceof InitableByConstraintMap)
+ {
+ ((InitableByConstraintMap) v).init(field.getRuleMap());
+ }
+ else
+ {
+ throw new IntakeError(
+ "All Validation objects must be subclasses of "
+ + "InitableByConstraintMap");
+ }
+ }
+
+ return v;
+ }
+ /**
+ * Serialize field to ObjectOutputStream
+ *
+ * @param oos the ObjectOutputStream
+ * @throws IOException
+ */
+ private void writeObject( ObjectOutputStream oos ) throws IOException
+ {
+ oos.defaultWriteObject();
+ }
+
+ /**
+ * De-serialize field from ObjectInputStream, recreate validator, getter
and setter
+ *
+ * @param ois the ObjectInputStream
+ * @throws IOException
+ */
+ private void readObject( ObjectInputStream ois ) throws IOException
+ {
+ try
+ {
+ ois.defaultReadObject();
+
+ if (validatorClassName != null)
+ {
+ validator = createValidator(validatorClassName, null);
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IOException("Could not create validator instance " +
validatorClassName, e);
+ }
+ catch (IntakeException e)
+ {
+ throw new IOException("Could not create validator instance " +
validatorClassName, e);
+ }
+ }
}
Added:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java?rev=1671923&view=auto
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java
(added)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java
Tue Apr 7 19:06:44 2015
@@ -0,0 +1,248 @@
+package org.apache.fulcrum.intake.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.apache.fulcrum.intake.IntakeException;
+
+/**
+ * Creates Field objects.
+ *
+ * @author <a href="mailto:[email protected]">Thomas Vandahl</a>
+ * @version $Id: FieldFactory.java 1200653 2011-11-11 00:05:28Z tv $
+ */
+public class FieldAdapter extends XmlAdapter<XmlField, Field<?>>
+{
+ private static Map<String, FieldAdapter.FieldCtor> fieldCtors =
initFieldCtors();
+
+ private static Map<String, FieldAdapter.FieldCtor> initFieldCtors()
+ {
+ fieldCtors = new HashMap<String, FieldAdapter.FieldCtor>();
+
+ fieldCtors.put("int", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new IntegerField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("boolean", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new BooleanField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("String", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new StringField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("BigDecimal", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new BigDecimalField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("FileItem", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new FileItemField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("DateString", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new DateStringField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("float", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new FloatField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("double", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new DoubleField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("short", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new ShortField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("long", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ return new LongField(f, g);
+ }
+ }
+ );
+ fieldCtors.put("custom", new FieldAdapter.FieldCtor()
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g)
+ throws IntakeException
+ {
+ String fieldClass = f.getFieldClass();
+
+ if (fieldClass != null
+ && fieldClass.indexOf('.') == -1)
+ {
+ fieldClass = Field.defaultFieldPackage + fieldClass;
+ }
+
+ if (fieldClass != null)
+ {
+ Class<?> field;
+
+ try
+ {
+ field = Class.forName(fieldClass);
+ Constructor<?> constructor =
+ field.getConstructor(XmlField.class, Group.class);
+
+ return (Field<?>)constructor.newInstance(f, g);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IntakeException(
+ "Could not load Field class("
+ + fieldClass + ")", e);
+ }
+ catch (Exception e)
+ {
+ throw new IntakeException(
+ "Could not create new instance of Field("
+ + fieldClass + ")", e);
+ }
+ }
+ else
+ {
+ throw new IntakeException(
+ "Custom field types must define a fieldClass");
+ }
+ }
+ }
+ );
+ return fieldCtors;
+ }
+
+ protected interface FieldCtor
+ {
+ public Field<?> getInstance(XmlField f, Group g) throws
IntakeException;
+ }
+
+ /**
+ * Creates a Field object appropriate for the type specified
+ * in the xml file.
+ *
+ * @param xmlField a <code>XmlField</code> value
+ * @return a <code>Field</code> value
+ * @throws IntakeException indicates that an unknown type was specified
for a field.
+ */
+ public static final Field<?> getInstance(XmlField xmlField, Group xmlGroup)
+ throws IntakeException
+ {
+ FieldCtor fieldCtor = null;
+ Field<?> field = null;
+ String type = xmlField.getType();
+
+ fieldCtor = fieldCtors.get(type);
+ if (fieldCtor == null)
+ {
+ throw new IntakeException("An Unsupported type has been specified
for " +
+ xmlField.getName() + " in group " +
xmlGroup.getIntakeGroupName() + " type = " + type);
+ }
+ else
+ {
+ field = fieldCtor.getInstance(xmlField, xmlGroup);
+ }
+
+ return field;
+ }
+
+ /**
+ * @see
javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
+ */
+ @Override
+ public Field<?> unmarshal(XmlField xmlField) throws Exception
+ {
+ return getInstance(xmlField, xmlField.getGroup());
+ }
+
+ /**
+ * @see
javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
+ */
+ @Override
+ public XmlField marshal(Field<?> field) throws Exception
+ {
+ // This is never used in this context
+ XmlField xml = new XmlField();
+ return xml;
+ }
+
+}
Propchange:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FileItemField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FileItemField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FileItemField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FileItemField.java
Tue Apr 7 19:06:44 2015
@@ -24,7 +24,6 @@ import org.apache.fulcrum.intake.IntakeE
import org.apache.fulcrum.intake.IntakeRuntimeException;
import org.apache.fulcrum.intake.validator.FileValidator;
import org.apache.fulcrum.intake.validator.ValidationException;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
import org.apache.fulcrum.parser.ParameterParser;
import org.apache.fulcrum.parser.ValueParser;
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java
Tue Apr 7 19:06:44 2015
@@ -21,7 +21,6 @@ package org.apache.fulcrum.intake.model;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.validator.FloatValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
* Processor for float fields.
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java
Tue Apr 7 19:06:44 2015
@@ -19,20 +19,30 @@ package org.apache.fulcrum.intake.model;
* under the License.
*/
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.commons.pool.BaseKeyedPoolableObjectFactory;
+import org.apache.commons.pool2.BaseKeyedPooledObjectFactory;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.IntakeServiceFacade;
import org.apache.fulcrum.intake.Retrievable;
-import org.apache.fulcrum.intake.xmlmodel.AppData;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
-import org.apache.fulcrum.intake.xmlmodel.XmlGroup;
import org.apache.fulcrum.parser.ValueParser;
/**
@@ -43,8 +53,13 @@ import org.apache.fulcrum.parser.ValuePa
* @author <a href="mailto:[email protected]">Quinton McCombs</a>
* @version $Id$
*/
-public class Group
+@XmlType(name="group")
+@XmlAccessorType(XmlAccessType.NONE)
+public class Group implements Serializable
{
+ /** Serial version */
+ private static final long serialVersionUID = -5452725641409669284L;
+
public static final String EMPTY = "";
/*
@@ -65,17 +80,31 @@ public class Group
* The key used to represent this group in a parameter.
* This key is usually a prefix as part of a field key.
*/
- protected final String gid;
+ @XmlAttribute(name="key", required=true)
+ private String gid;
/**
* The name used in templates and java code to refer to this group.
*/
- protected final String name;
+ @XmlAttribute(required=true)
+ private String name;
/**
* The number of Groups with the same name that will be pooled.
*/
- private final int poolCapacity;
+ @XmlAttribute
+ private int poolCapacity = 128;
+
+ /**
+ * The default map object for this group
+ */
+ @XmlAttribute(name="mapToObject")
+ private String defaultMapToObject;
+
+ /**
+ * The parent element in the XML tree
+ */
+ private AppData parent;
/**
* A map of the fields in this group mapped by field name.
@@ -109,55 +138,6 @@ public class Group
protected boolean isDeclared;
/**
- * Constructs a new Group based on the xml specification. Groups are
- * instantiated and pooled by the IntakeService and should not
- * be instantiated otherwise.
- *
- * @param group a <code>XmlGroup</code> value
- * @exception IntakeException if an error occurs in other classes
- */
- public Group(XmlGroup group) throws IntakeException
- {
- gid = group.getKey();
- name = group.getName();
- poolCapacity = Integer.parseInt(group.getPoolCapacity());
-
- List<XmlField> inputFields = group.getFields();
- int size = inputFields.size();
- fields = new HashMap<String, Field<?>>((int) (1.25 * size + 1));
- Map<String, List<Field<?>>> mapToObjectFieldLists =
- new HashMap<String, List<Field<?>>>((int) (1.25 * size + 1));
-
- fieldsArray = new Field[size];
- for (int i = size - 1; i >= 0; i--)
- {
- XmlField f = inputFields.get(i);
- Field<?> field = FieldFactory.getInstance(f, this);
- fieldsArray[i] = field;
- fields.put(f.getName(), field);
-
- // map fields by their mapToObject
- List<Field<?>> tmpFields =
mapToObjectFieldLists.get(f.getMapToObject());
- if (tmpFields == null)
- {
- tmpFields = new ArrayList<Field<?>>(size);
- mapToObjectFieldLists.put(f.getMapToObject(), tmpFields);
- }
-
- tmpFields.add(field);
- }
-
- // Change the mapToObjectFields values to Field[]
- mapToObjectFields = new HashMap<String, Field<?>[]>((int) (1.25 * size
+ 1));
-
- for (Map.Entry<String, List<Field<?>>> entry :
mapToObjectFieldLists.entrySet())
- {
- mapToObjectFields.put(entry.getKey(),
- entry.getValue().toArray(new Field[entry.getValue().size()]));
- }
- }
-
- /**
* Initializes the default Group using parameters.
*
* @param pp a <code>ValueParser</code> value
@@ -305,6 +285,16 @@ public class Group
}
/**
+ * Default object to map this group to.
+ *
+ * @return a <code>String</code> value
+ */
+ public String getDefaultMapToObject()
+ {
+ return defaultMapToObject;
+ }
+
+ /**
* Describe <code>getObjects</code> method here.
*
* @param pp a <code>ValueParser</code> value
@@ -346,6 +336,41 @@ public class Group
}
/**
+ * Get the list of Fields .
+ * @return list of Fields
+ */
+ public List<Field<?>> getFields()
+ {
+ if (fieldsArray == null)
+ {
+ return new ArrayList<Field<?>>();
+ }
+
+ return Arrays.asList(fieldsArray);
+ }
+
+ /**
+ * Set a collection of fields for this group
+ *
+ * @param fields the fields to set
+ */
+ @XmlElement(name="field")
+ @XmlJavaTypeAdapter(FieldAdapter.class)
+ protected void setFields(List<Field<?>> inputFields)
+ {
+ int size = inputFields.size();
+ fields = new HashMap<String, Field<?>>((int) (1.25 * size + 1));
+ fieldsArray = new Field[size];
+
+ for (int i = size - 1; i >= 0; i--)
+ {
+ Field<?> field = inputFields.get(i);
+ fieldsArray[i] = field;
+ fields.put(field.getName(), field);
+ }
+ }
+
+ /**
* Performs an AND between all the fields in this group.
*
* @return a <code>boolean</code> value
@@ -578,10 +603,87 @@ public class Group
}
}
+ /**
+ * Creates a string representation of this input group. This
+ * is an xml representation.
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder result = new StringBuilder();
+
+ result.append("<group
name=\"").append(getIntakeGroupName()).append("\"");
+ result.append(" key=\"").append(getGID()).append("\"");
+ result.append(">\n");
+
+ if (fieldsArray != null)
+ {
+ for (Field<?> field : fieldsArray)
+ {
+ result.append(field);
+ }
+ }
+
+ result.append("</group>\n");
+
+ return result.toString();
+ }
+
+ /**
+ * Get the parent AppData for this group
+ *
+ * @return the parent
+ */
+ public AppData getAppData()
+ {
+ return parent;
+ }
+
+ /**
+ * JAXB callback to set the parent object
+ *
+ * @param um the Unmarshaller
+ * @param parent the parent object (an AppData object)
+ */
+ public void afterUnmarshal(Unmarshaller um, Object parent)
+ {
+ this.parent = (AppData)parent;
+ Map<String, List<Field<?>>> mapToObjectFieldLists =
+ new HashMap<String, List<Field<?>>>((int) (1.25 *
fieldsArray.length + 1));
+
+ // Fix fields
+ for (Field<?> field : fieldsArray)
+ {
+ if (StringUtils.isNotEmpty(field.mapToObject))
+ {
+ field.mapToObject = this.parent.getBasePackage() +
field.mapToObject;
+ }
+
+ // map fields by their mapToObject
+ List<Field<?>> tmpFields =
mapToObjectFieldLists.get(field.getMapToObject());
+ if (tmpFields == null)
+ {
+ tmpFields = new ArrayList<Field<?>>(fieldsArray.length);
+ mapToObjectFieldLists.put(field.getMapToObject(), tmpFields);
+ }
+
+ tmpFields.add(field);
+ }
+
+ // Change the mapToObjectFields values to Field[]
+ mapToObjectFields = new HashMap<String, Field<?>[]>((int) (1.25 *
fieldsArray.length + 1));
+
+ for (Map.Entry<String, List<Field<?>>> entry :
mapToObjectFieldLists.entrySet())
+ {
+ mapToObjectFields.put(entry.getKey(),
+ entry.getValue().toArray(new Field[entry.getValue().size()]));
+ }
+ }
+
// ********** PoolableObjectFactory implementation ******************
public static class GroupFactory
- extends BaseKeyedPoolableObjectFactory<String, Group>
+ extends BaseKeyedPooledObjectFactory<String, Group>
{
private final AppData appData;
@@ -596,18 +698,30 @@ public class Group
* @return an instance that can be returned by the pool.
* @throws IntakeException indicates that the group could not be
retrieved
*/
- public Group makeObject(String key) throws IntakeException
+ @Override
+ public Group create(String key) throws IntakeException
+ {
+ return appData.getGroup(key);
+ }
+
+ /**
+ * @see
org.apache.commons.pool2.BaseKeyedPooledObjectFactory#wrap(java.lang.Object)
+ */
+ @Override
+ public PooledObject<Group> wrap(Group group)
{
- return new Group(appData.getGroup(key));
+ return new DefaultPooledObject<Group>(group);
}
/**
* Uninitialize an instance to be returned to the pool.
* @param key the name of the group
- * @param group the instance to be passivated
+ * @param pooledGroup the instance to be passivated
*/
- public void passivateObject(String key, Group group)
+ @Override
+ public void passivateObject(String key, PooledObject<Group>
pooledGroup)
{
+ Group group = pooledGroup.getObject();
group.oid = null;
group.pp = null;
for (int i = group.fieldsArray.length - 1; i >= 0; i--)
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java
Tue Apr 7 19:06:44 2015
@@ -21,7 +21,6 @@ package org.apache.fulcrum.intake.model;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.validator.IntegerValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
* Processor for int fields.
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java
Tue Apr 7 19:06:44 2015
@@ -21,7 +21,6 @@ package org.apache.fulcrum.intake.model;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.validator.LongValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
* Processor for long fields.
Copied:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Rule.java
(from r1658225,
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/Rule.java)
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Rule.java?p2=turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Rule.java&p1=turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/Rule.java&r1=1658225&r2=1671923&rev=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/Rule.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Rule.java
Tue Apr 7 19:06:44 2015
@@ -1,4 +1,4 @@
-package org.apache.fulcrum.intake.xmlmodel;
+package org.apache.fulcrum.intake.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -21,9 +21,13 @@ package org.apache.fulcrum.intake.xmlmod
import java.io.Serializable;
-import org.apache.fulcrum.intake.validator.Constraint;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
-import org.xml.sax.Attributes;
+import org.apache.fulcrum.intake.validator.Constraint;
/**
* A Class for holding data about a constraint on a property.
@@ -32,110 +36,62 @@ import org.xml.sax.Attributes;
* @author <a href="mailto:[email protected]">Thomas Vandahl</a>
* @version $Id$
*/
-public class Rule
- implements Constraint, Serializable
+@XmlType(name="rule")
+@XmlAccessorType(XmlAccessType.NONE)
+public class Rule implements Constraint, Serializable
{
/**
* Serial version id
*/
private static final long serialVersionUID = -4059931768288150848L;
+ @XmlAttribute(required=true)
private String name;
- private String value;
- private String message;
- private XmlField parent;
- /**
- * Default Constructor
- */
- public Rule()
- {
- //
- }
-
- /**
- * Imports a column from an XML specification
- */
- public void loadFromXML(Attributes attrib)
- {
- setName(attrib.getValue("name"));
- setValue(attrib.getValue("value"));
- }
+ @XmlAttribute(required=true)
+ private String value;
- /**
- * Set the name of the parameter
- */
- public void setName(String newName)
- {
- name = newName;
- }
+ @XmlValue
+ private String message;
/**
* Get the name of the parameter
*/
+ @Override
public String getName()
{
return name;
}
/**
- * Set the value of the parameter
- */
- public void setValue(String newValue)
- {
- value = newValue;
- }
-
- /**
* Get the value of the parameter
*/
+ @Override
public String getValue()
{
return value;
}
/**
- * Set the error message
- */
- public void setMessage(String newMessage)
- {
- message = newMessage;
- }
-
- /**
* Get the error message
*/
+ @Override
public String getMessage()
{
return message;
}
/**
- * Set the parent Field of the rule
- */
- public void setField(XmlField parent)
- {
- this.parent = parent;
- }
-
- /**
- * Get the parent Field of the rule
- */
- public XmlField getField()
- {
- return parent;
- }
-
- /**
* String representation of the column. This
* is an xml representation.
*/
+ @Override
public String toString()
{
StringBuilder result = new StringBuilder(100);
- result.append("<rule name=\"" + name + "\"")
- .append(" value=\"" + value + "\"");
+ result.append("<rule name=\"").append(name).append("\"")
+ .append(" value=\"").append(value).append("\"");
if (message == null)
{
@@ -150,8 +106,4 @@ public class Rule
return result.toString();
}
-
}
-
-
-
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java
Tue Apr 7 19:06:44 2015
@@ -21,7 +21,6 @@ package org.apache.fulcrum.intake.model;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.validator.ShortValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
* Processor for short fields.
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/StringField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/StringField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/StringField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/StringField.java
Tue Apr 7 19:06:44 2015
@@ -22,7 +22,6 @@ package org.apache.fulcrum.intake.model;
import org.apache.commons.lang.StringUtils;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.validator.StringValidator;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
/**
* Text field.
Copied:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java
(from r1658225,
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlField.java)
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java?p2=turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java&p1=turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlField.java&r1=1658225&r2=1671923&rev=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java
Tue Apr 7 19:06:44 2015
@@ -1,4 +1,4 @@
-package org.apache.fulcrum.intake.xmlmodel;
+package org.apache.fulcrum.intake.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -23,13 +23,18 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
import org.apache.commons.lang.StringUtils;
-import org.xml.sax.Attributes;
/**
* A Class for holding data about a property used in an Application.
@@ -40,6 +45,8 @@ import org.xml.sax.Attributes;
* @author <a href="mailto:[email protected]">Thomas Vandahl</a>
* @version $Id$
*/
+@XmlType(name="field")
+@XmlAccessorType(XmlAccessType.NONE)
public class XmlField
implements Serializable
{
@@ -48,67 +55,56 @@ public class XmlField
*/
private static final long serialVersionUID = -734309157828058007L;
- private String name;
+ @XmlAttribute(required=true)
private String key;
- private String type;
+
+ @XmlAttribute(required=true)
+ private String name;
+
+ @XmlAttribute
private String displayName;
- private String multiValued;
- private XmlGroup parent;
- private final List<Rule> rules;
- private final Map<String, Rule> ruleMap;
- private String ifRequiredMessage;
+
+ @XmlAttribute
+ private String displaySize;
+
+ @XmlAttribute
+ private String type = "String";
+
+ @XmlAttribute
+ private boolean multiValued = false;
+
+ @XmlAttribute
+ private String fieldClass;
+
+ @XmlAttribute
private String mapToObject;
+
+ @XmlAttribute
private String mapToProperty;
+
+ @XmlAttribute
private String validator;
+
+ @XmlAttribute
private String defaultValue;
+
+ @XmlAttribute
private String emptyValue;
- private String displaySize;
- private String fieldClass;
+
+ private List<Rule> rules;
+ private Map<String, Rule> ruleMap;
+
+ private Group parent;
/**
* Default Constructor
*/
public XmlField()
{
- rules = new ArrayList<Rule>();
ruleMap = new HashMap<String, Rule>();
}
/**
- * Creates a new column and set the name
- */
- public XmlField(String name)
- {
- this();
- this.name = name;
- }
-
- /**
- * Imports a column from an XML specification
- */
- public void loadFromXML(Attributes attrib)
- {
- setName(attrib.getValue("name"));
- setKey(attrib.getValue("key"));
- setType(attrib.getValue("type"));
- setDisplayName(attrib.getValue("displayName"));
- setDisplaySize(attrib.getValue("displaySize"));
- setMultiValued(attrib.getValue("multiValued"));
-
- String mapObj = attrib.getValue("mapToObject");
- if (mapObj != null && mapObj.length() != 0)
- {
- setMapToObject(mapObj);
- }
-
- setMapToProperty(attrib.getValue("mapToProperty"));
- setFieldClass(attrib.getValue("fieldClass"));
- setValidator(attrib.getValue("validator"));
- setDefaultValue(attrib.getValue("defaultValue"));
- setEmptyValue(attrib.getValue("emptyValue"));
- }
-
- /**
* Get the name of the property
*/
public String getRawName()
@@ -125,14 +121,6 @@ public class XmlField
}
/**
- * Set the name of the property
- */
- public void setName(String newName)
- {
- name = newName;
- }
-
- /**
* Get the display name of the property
*/
public String getDisplayName()
@@ -141,22 +129,6 @@ public class XmlField
}
/**
- * Set the display name of the property
- */
- public void setDisplayName(String newDisplayName)
- {
- displayName = newDisplayName;
- }
-
- /**
- * Sets the display size of the field.
- */
- private void setDisplaySize(String size)
- {
- this.displaySize = size;
- }
-
- /**
* Gets the display size of the field. This is
* useful for constructing the HTML input tag.
*/
@@ -166,14 +138,6 @@ public class XmlField
}
/**
- * Set the parameter key of the property
- */
- public void setKey(String newKey)
- {
- key = newKey;
- }
-
- /**
* Get the parameter key of the property
*/
public String getKey()
@@ -182,14 +146,6 @@ public class XmlField
}
/**
- * Set the type of the property
- */
- public void setType(String newType)
- {
- type = newType;
- }
-
- /**
* Get the type of the property
*/
public String getType()
@@ -198,33 +154,11 @@ public class XmlField
}
/**
- * Set whether this class can have multiple values
- */
- public void setMultiValued(String newMultiValued)
- {
- multiValued = newMultiValued;
- }
-
- /**
* can this field have several values?
*/
public boolean isMultiValued()
{
- if (multiValued != null && multiValued.equals("true"))
- {
- return true;
- }
- return false;
- }
-
- /**
- * Set the name of the object that takes this input
- *
- * @param objectName name of the class.
- */
- public void setMapToObject(String objectName)
- {
- mapToObject = objectName;
+ return multiValued;
}
/**
@@ -236,16 +170,6 @@ public class XmlField
}
/**
- * Set the property method that takes this input
- *
- * @param prop Name of the property to which the field will be mapped.
- */
- public void setMapToProperty(String prop)
- {
- mapToProperty = prop;
- }
-
- /**
* Get the property method that takes this input
*/
public String getMapToProperty()
@@ -261,14 +185,6 @@ public class XmlField
}
/**
- * Set the class name of the validator
- */
- public void setValidator(String prop)
- {
- validator = prop;
- }
-
- /**
* Get the className of the validator
*/
public String getValidator()
@@ -277,16 +193,6 @@ public class XmlField
}
/**
- * Set the default Value.
- *
- * @param prop The parameter to use as default value.
- */
- public void setDefaultValue(String prop)
- {
- defaultValue = prop;
- }
-
- /**
* Get the default Value.
*
* @return The default value for this field.
@@ -297,16 +203,6 @@ public class XmlField
}
/**
- * Set the empty Value.
- *
- * @param prop The parameter to use as empty value.
- */
- public void setEmptyValue(String prop)
- {
- emptyValue = prop;
- }
-
- /**
* Get the empty Value.
*
* @return The empty value for this field.
@@ -317,55 +213,11 @@ public class XmlField
}
/**
- * The name of the field making sure the first letter is lowercase.
- *
- * @return a <code>String</code> value
- * @deprecated No replacement
- */
- public String getVariable()
- {
- String firstChar = getName().substring(0, 1).toLowerCase();
- return firstChar + getName().substring(1);
- }
-
- /**
- * Set the parent XmlGroup of the property
- */
- public void setGroup(XmlGroup parent)
- {
- this.parent = parent;
- if (mapToObject != null && mapToObject.length() != 0)
- {
- mapToObject = parent.getAppData().getBasePackage() + mapToObject;
- }
- }
-
- /**
- * Get the parent XmlGroup of the property
- */
- public XmlGroup getGroup()
- {
- return parent;
- }
-
- /**
- * Get the value of ifRequiredMessage.
- *
- * @return value of ifRequiredMessage.
- */
- public String getIfRequiredMessage()
- {
- return ifRequiredMessage;
- }
-
- /**
- * Set the value of ifRequiredMessage.
- *
- * @param v Value to assign to ifRequiredMessage.
+ * Get the parent XmlGroup of the field
*/
- public void setIfRequiredMessage(String v)
+ public Group getGroup()
{
- this.ifRequiredMessage = v;
+ return this.parent;
}
/**
@@ -379,47 +231,29 @@ public class XmlField
}
/**
- * Set the value of fieldClass.
+ * The collection of rules for this field.
*
- * @param v Value to assign to fieldClass.
- */
- public void setFieldClass(String v)
- {
- this.fieldClass = v;
- }
-
- /**
- * A utility function to create a new input parameter
- * from attrib and add it to this property.
- */
- public Rule addRule(Attributes attrib)
- {
- Rule rule = new Rule();
- rule.loadFromXML(attrib);
- addRule(rule);
-
- return rule;
- }
-
- /**
- * Adds a new rule to the parameter Map and set the
- * parent property of the Rule to this property
+ * @return a <code>List</code> value
*/
- public void addRule(Rule rule)
+ public List<Rule> getRules()
{
- rule.setField(this);
- rules.add(rule);
- ruleMap.put(rule.getName(), rule);
+ return rules;
}
/**
- * The collection of rules for this field.
+ * Set the collection of rules for this field
*
- * @return a <code>List</code> value
+ * @param rules the rules to set
*/
- public List<Rule> getRules()
+ @XmlElement(name="rule")
+ public void setRules(List<Rule> rules)
{
- return rules;
+ this.rules = rules;
+ this.ruleMap.clear();
+ for (Rule rule : rules)
+ {
+ ruleMap.put(rule.getName(), rule);
+ }
}
/**
@@ -434,40 +268,62 @@ public class XmlField
}
/**
+ * JAXB callback to set the parent object
+ *
+ * @param um the Unmarshaller
+ * @param parent the parent object (an XmlGroup)
+ */
+ public void afterUnmarshal(Unmarshaller um, Object parent)
+ {
+ this.parent = (Group)parent;
+ if (mapToObject == null)
+ {
+ // if a mapToProperty exists, set the object to this group's
default
+ if (mapToProperty != null
+ && !"".equals(mapToProperty)
+ && this.parent.getDefaultMapToObject() != null)
+ {
+ mapToObject = this.parent.getDefaultMapToObject();
+ }
+ }
+ }
+
+ /**
* String representation of the column. This
* is an xml representation.
*/
+ @Override
public String toString()
{
StringBuilder result = new StringBuilder();
- result.append(" <field name=\"" + name + "\"");
- result.append(" key=\"" + key + "\"");
- result.append(" type=\"" + type + "\"");
+ result.append(" <field name=\"").append(name).append("\"")
+ .append(" key=\"").append(key).append("\"")
+ .append(" type=\"").append(type).append("\"");
if (displayName != null)
{
- result.append(" displayName=\"" + displayName + "\"");
+ result.append(" displayName=\"").append(displayName).append("\"");
}
if (mapToObject != null)
{
- result.append(" mapToObject=\"" + mapToObject + "\"");
+ result.append(" mapToObject=\"").append(mapToObject).append("\"");
}
if (mapToProperty != null)
{
- result.append(" mapToProperty=\"" + mapToProperty + "\"");
+ result.append("
mapToProperty=\"").append(mapToProperty).append("\"");
}
if (validator != null)
{
- result.append(" validator=\"" + validator + "\"");
+ result.append(" validator=\"").append(validator).append("\"");
}
if (defaultValue != null)
{
- result.append(" defaultValue=\"" + defaultValue + "\"");
+ result.append("
defaultValue=\"").append(defaultValue).append("\"");
}
if (emptyValue != null)
{
- result.append(" emptyValue=\"" + emptyValue + "\"");
+ result.append(" emptyValue=\"").append(emptyValue).append("\"");
}
if (rules.size() == 0)
Added:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/package-info.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/package-info.java?rev=1671923&view=auto
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/package-info.java
(added)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/package-info.java
Tue Apr 7 19:06:44 2015
@@ -0,0 +1,24 @@
[email protected](
+ namespace = "http://turbine.apache.org/schema/intake/4.0",
+ elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+
+package org.apache.fulcrum.intake.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
Propchange:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/package-info.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: turbine/fulcrum/trunk/intake/src/test/intake1.xml
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/intake1.xml?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/intake1.xml (original)
+++ turbine/fulcrum/trunk/intake/src/test/intake1.xml Tue Apr 7 19:06:44 2015
@@ -17,9 +17,8 @@
specific language governing permissions and limitations
under the License.
-->
-<!DOCTYPE input-data SYSTEM
- "http://turbine.apache.org/dtd/intake_2_4.dtd">
-<input-data basePackage="org.apache.fulcrum.intake.test.">
+<input-data xmlns="http://turbine.apache.org/schema/intake/4.0"
+ basePackage="org.apache.fulcrum.intake.test.">
<group name="LoginGroup" key="loginGroupKey" mapToObject="LoginForm">
<field name="Username" key="loginUsernameKey" type="String"
mapToProperty="Username">
@@ -53,7 +52,7 @@
<field name="EmptyDoubleTestField" key="edtf" type="double"/>
<field name="EmptyBigDecimalTestField" key="ebdtf" type="BigDecimal"/>
<field name="NumberTestField" key="ntf" type="int">
- <rule name="invalidNumber">Not a number</rule>
+ <rule name="invalidNumber" value="">Not a number</rule>
</field>
</group>
</input-data>
Modified: turbine/fulcrum/trunk/intake/src/test/intake2.xml
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/intake2.xml?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/intake2.xml (original)
+++ turbine/fulcrum/trunk/intake/src/test/intake2.xml Tue Apr 7 19:06:44 2015
@@ -17,14 +17,10 @@
specific language governing permissions and limitations
under the License.
-->
-<!DOCTYPE input-data SYSTEM
- "http://turbine.apache.org/dtd/intake_2_4.dtd">
-<input-data basePackage="org.apache.fulcrum.intake.test.">
-<group name="AnotherGroup" key="anotherGroupKey" mapToObject="AnotherForm">
-<field name="Username" key="loginUsernameKey" type="String"
- mapToProperty="Username">
-
-</field>
-</group>
-
+<input-data xmlns="http://turbine.apache.org/schema/intake/4.0"
+ basePackage="org.apache.fulcrum.intake.test.">
+ <group name="AnotherGroup" key="anotherGroupKey" mapToObject="AnotherForm">
+ <field name="Username" key="loginUsernameKey" type="String"
mapToProperty="Username">
+ </field>
+ </group>
</input-data>
Modified:
turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/MyField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/MyField.java?rev=1671923&r1=1671922&r2=1671923&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/MyField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/MyField.java
Tue Apr 7 19:06:44 2015
@@ -21,7 +21,7 @@ package org.apache.fulcrum.intake.test;
import org.apache.fulcrum.intake.IntakeException;
import org.apache.fulcrum.intake.model.Group;
import org.apache.fulcrum.intake.model.StringField;
-import org.apache.fulcrum.intake.xmlmodel.XmlField;
+import org.apache.fulcrum.intake.model.XmlField;
public class MyField extends StringField
{