Author: tv
Date: Wed Aug 1 12:25:20 2018
New Revision: 1837231
URL: http://svn.apache.org/viewvc?rev=1837231&view=rev
Log:
Move Field creation to typesafe enum
Added:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldType.java
(with props)
Modified:
turbine/fulcrum/trunk/intake/src/changes/changes.xml
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java
Modified: turbine/fulcrum/trunk/intake/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/changes/changes.xml?rev=1837231&r1=1837230&r2=1837231&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/changes/changes.xml (original)
+++ turbine/fulcrum/trunk/intake/src/changes/changes.xml Wed Aug 1 12:25:20
2018
@@ -25,7 +25,25 @@
</properties>
<body>
- <release version="1.2.4" date="in Subversion">
+ <release version="2.0.0" date="in Subversion">
+ <action dev="tv" type="update">
+ Move Field creation to typesafe enum
+ </action>
+ <action dev="tv" type="update">
+ Deprecate field type FileItem
+ </action>
+ <action dev="tv" type="add">
+ Add new field type UploadPart to support Servlet 3.1 upload handling
+ </action>
+ <action dev="tv" type="remove">
+ Remove dependency on fulcrum-upload
+ </action>
+ <action dev="tv" type="update">
+ INCOMPATIBLE: Update dependency servlet-api to 3.1.0
+ </action>
+ <action dev="tv" type="update">
+ Update dependencies commons-lang3 3.7, fulcrum-parser 2.0.0
+ </action>
</release>
<release version="1.2.3" date="2018-02-11">
<action type="fix" dev="tv" issue="TRB-94" due-to="Tilo Villwock">
Modified:
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=1837231&r1=1837230&r2=1837231&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldAdapter.java
Wed Aug 1 12:25:20 2018
@@ -1,28 +1,5 @@
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;
@@ -35,215 +12,38 @@ import org.apache.fulcrum.intake.IntakeE
*/
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
- {
- 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
- * @param xmlGroup the group this field belongs to
- * @return a <code>Field</code> value
- * @throws IntakeException indicates that an unknown type was specified
for a field.
+ * @see
javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
*/
- public static final Field<?> getInstance(XmlField xmlField, Group xmlGroup)
- throws IntakeException
+ @Override
+ public Field<?> unmarshal(XmlField xmlField) throws Exception
{
- FieldCtor fieldCtor = null;
Field<?> field = null;
- String type = xmlField.getType();
+ FieldType type = xmlField.getType();
- fieldCtor = fieldCtors.get(type);
- if (fieldCtor == null)
+ if (type == null)
{
- throw new IntakeException("An Unsupported type has been specified
for " +
- xmlField.getName() + " in group " +
xmlGroup.getIntakeGroupName() + " type = " + type);
+ throw new IntakeException("An unsupported type has been specified
for " +
+ xmlField.getName() + " in group " +
xmlField.getGroup().getIntakeGroupName());
}
else
{
- field = fieldCtor.getInstance(xmlField, xmlGroup);
+ field = type.getInstance(xmlField, xmlField.getGroup());
}
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;
+ return new XmlField();
}
-
}
Added:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldType.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldType.java?rev=1837231&view=auto
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldType.java
(added)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldType.java
Wed Aug 1 12:25:20 2018
@@ -0,0 +1,220 @@
+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.io.Serializable;
+import java.lang.reflect.Constructor;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlEnumValue;
+
+import org.apache.fulcrum.intake.IntakeException;
+
+/**
+ * Enum for valid field types.
+ *
+ * @author <a href="mailto:[email protected]">Thomas Vandahl</a>
+ */
+@XmlEnum(String.class)
+public enum FieldType implements Serializable
+{
+ @XmlEnumValue("boolean") FIELD_BOOLEAN("boolean")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new BooleanField(f, g);
+ }
+ },
+ @XmlEnumValue("BigDecimal") FIELD_BIGDECIMAL("BigDecimal")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new BigDecimalField(f, g);
+ }
+ },
+ @XmlEnumValue("int") FIELD_INT("int")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new IntegerField(f, g);
+ }
+ },
+ @XmlEnumValue("float") FIELD_FLOAT("float")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new FloatField(f, g);
+ }
+ },
+ @Deprecated
+ @XmlEnumValue("FileItem") FIELD_FILEITEM("FileItem")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new UploadPartField(f, g);
+ }
+ },
+ @XmlEnumValue("UploadPart") FIELD_UPLOADPART("UploadPart")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new UploadPartField(f, g);
+ }
+ },
+ @XmlEnumValue("String") FIELD_STRING("String")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new StringField(f, g);
+ }
+ },
+ @XmlEnumValue("DateString") FIELD_DATESTRING("DateString")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new DateStringField(f, g);
+ }
+ },
+ @XmlEnumValue("ComboKey") FIELD_COMBOKEY("ComboKey")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ throw new IntakeException("An unsupported type has been specified
for " +
+ f.getName() + " in group " + g.getIntakeGroupName() + "
type = " + value());
+ }
+ },
+ @XmlEnumValue("double") FIELD_DOUBLE("double")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new DoubleField(f, g);
+ }
+ },
+ @XmlEnumValue("short") FIELD_SHORT("short")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new ShortField(f, g);
+ }
+ },
+ @XmlEnumValue("long") FIELD_LONG("long")
+ {
+ @Override
+ public Field<?> getInstance(XmlField f, Group g) throws IntakeException
+ {
+ return new LongField(f, g);
+ }
+ },
+ @XmlEnumValue("custom") FIELD_CUSTOM("custom")
+ {
+ @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");
+ }
+ }
+ };
+
+ /** Serial version */
+ private static final long serialVersionUID = -8563326491799622016L;
+
+ /** String value of the field type */
+ private String stringValue;
+
+ /**
+ * Constructor
+ *
+ * @param stringValue
+ */
+ FieldType(String stringValue)
+ {
+ this.stringValue = stringValue;
+ }
+
+ /**
+ * Return the string value
+ *
+ * @return a <code>String</code> value
+ */
+ public String value()
+ {
+ return stringValue;
+ }
+
+ /**
+ * Create a specific field instance from its XML representation
+ *
+ * @param f the XML object
+ * @param g the group this field belongs to
+ * @return a Field<?> instance
+ *
+ * @throws IntakeException
+ * if the field could not be created
+ */
+ public abstract Field<?> getInstance(XmlField f, Group g) throws
IntakeException;
+}
Propchange:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FieldType.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java?rev=1837231&r1=1837230&r2=1837231&view=diff
==============================================================================
---
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java
(original)
+++
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/XmlField.java
Wed Aug 1 12:25:20 2018
@@ -71,7 +71,7 @@ public class XmlField
private String displaySize;
@XmlAttribute
- private String type = "String";
+ private FieldType type = FieldType.FIELD_STRING;
@XmlAttribute
private boolean multiValued = false;
@@ -185,7 +185,7 @@ public class XmlField
*
* @return the type of the field
*/
- public String getType()
+ public FieldType getType()
{
return type;
}
@@ -350,7 +350,7 @@ public class XmlField
StringBuilder result = new StringBuilder();
result.append(" <field name=\"").append(name).append("\"")
.append(" key=\"").append(key).append("\"")
- .append(" type=\"").append(type).append("\"");
+ .append(" type=\"").append(type.value()).append("\"");
if (displayName != null)
{