You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by gb...@apache.org on 2012/07/28 10:36:33 UTC

svn commit: r1366609 [5/5] - in /pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox: parser/ schema/ type/

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java Sat Jul 28 08:36:32 2012
@@ -47,10 +47,14 @@ public abstract class AbstractField impl
 	 * the element associated will not appear)
 	 */
 
-	protected Element element;
-	protected Document parent;
+	private Element element;
+	
+	private Document parent;
+	
+	private XMPMetadata metadata;
 
 	private String namespaceURI, prefix, propertyName;
+	
 	private Map<String, Attribute> attributes;
 
 	/**
@@ -65,13 +69,7 @@ public abstract class AbstractField impl
 	 */
 	public AbstractField(XMPMetadata metadata, String prefix,
 			String propertyName) {
-		String qualifiedName;
-		this.prefix = prefix;
-		qualifiedName = prefix + ":" + propertyName;
-		this.parent = metadata.getFuturOwner();
-		this.propertyName = propertyName;
-		element = parent.createElement(qualifiedName);
-		attributes = new HashMap<String, Attribute>();
+		this(metadata,null,prefix,propertyName);
 	}
 
 	/**
@@ -91,10 +89,15 @@ public abstract class AbstractField impl
 		String qualifiedName;
 		this.prefix = prefix;
 		qualifiedName = prefix + ":" + propertyName;
+		this.metadata = metadata;
 		this.parent = metadata.getFuturOwner();
 		this.namespaceURI = namespaceURI;
 		this.propertyName = propertyName;
-		element = parent.createElementNS(namespaceURI, qualifiedName);
+		if (this.namespaceURI!=null) {
+			element = parent.createElementNS(namespaceURI, qualifiedName);
+		} else {
+			element = parent.createElement(qualifiedName);
+		}
 		attributes = new HashMap<String, Attribute>();
 	}
 
@@ -112,7 +115,7 @@ public abstract class AbstractField impl
 	 * 
 	 * @return the namespace URI
 	 */
-	public String getNamespace() {
+	public final String getNamespace() {
 		return namespaceURI;
 	}
 
@@ -210,4 +213,9 @@ public abstract class AbstractField impl
 
 	}
 
+	public XMPMetadata getMetadata() {
+		return metadata;
+	}
+
+	
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractSimpleProperty.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractSimpleProperty.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractSimpleProperty.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractSimpleProperty.java Sat Jul 28 08:36:32 2012
@@ -31,26 +31,7 @@ import org.apache.padaf.xmpbox.XMPMetada
  */
 public abstract class AbstractSimpleProperty extends AbstractField {
 
-	protected Object objValue;
-
-	/**
-	 * Property specific type constructor (namespaceURI is not given)
-	 * 
-	 * @param metadata
-	 *            The metadata to attach to this property
-	 * @param prefix
-	 *            The prefix to set for this property
-	 * @param propertyName
-	 *            The local Name of this property
-	 * @param value
-	 *            the value to give
-	 * 
-	 */
-	public AbstractSimpleProperty(XMPMetadata metadata, String prefix,
-			String propertyName, Object value) {
-		super(metadata, prefix, propertyName);
-		setValue(value);
-	}
+	private Object objValue;
 
 	/**
 	 * Property specific type constructor (namespaceURI is given)
@@ -74,16 +55,6 @@ public abstract class AbstractSimpleProp
 	}
 
 	/**
-	 * Must be rewritten in each special XMP type Class to check if the value
-	 * type corresponding to the XMP Type
-	 * 
-	 * @param value
-	 *            Object to analyze
-	 * @return true if object type can be treat by the property type
-	 */
-	public abstract boolean isGoodType(Object value);
-
-	/**
 	 * Check and set new property value (in Element and in its Object
 	 * Representation)
 	 * 
@@ -91,6 +62,10 @@ public abstract class AbstractSimpleProp
 	 *            Object value to set
 	 */
 	public abstract void setValue(Object value);
+	
+	protected void setObjectValue (Object value) {
+		this.objValue = value;
+	}
 
 	/**
 	 * Return the property value
@@ -98,7 +73,18 @@ public abstract class AbstractSimpleProp
 	 * @return a string
 	 */
 	public String getStringValue() {
-		return element.getTextContent();
+		return getElement().getTextContent();
 	}
 
+	public Object getObjectValue () {
+		return objValue;
+	}
+	
+	public String toString () {
+		StringBuilder sb = new StringBuilder ();
+		sb.append("[").append(this.getClass().getSimpleName()).append(":");
+		sb.append(objValue).append("]");
+		return sb.toString();
+	}
+	
 }

Added: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java?rev=1366609&view=auto
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java (added)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java Sat Jul 28 08:36:32 2012
@@ -0,0 +1,88 @@
+/*****************************************************************************
+ * 
+ * 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.
+ * 
+ ****************************************************************************/
+
+package org.apache.padaf.xmpbox.type;
+
+import java.util.Calendar;
+import java.util.List;
+
+import org.apache.padaf.xmpbox.XMPMetadata;
+
+public abstract class AbstractStructuredType extends ComplexPropertyContainer {
+
+	
+	
+	/** The prefix of the fields of the structure */
+	private String fieldPrefix = null;
+
+	protected static final String STRUCTURE_ARRAY_PREFIX = "rdf";
+
+	protected static final  String STRUCTURE_ARRAY_NAME = "li"; 
+
+	public AbstractStructuredType(XMPMetadata metadata, String namespaceURI,
+			String fieldPrefix) {
+		super(metadata, namespaceURI, STRUCTURE_ARRAY_PREFIX, STRUCTURE_ARRAY_NAME);
+		this.fieldPrefix = fieldPrefix;
+	}
+
+	public abstract String getFieldsNamespace();
+	
+	public String getFieldPrefix () {
+		return this.fieldPrefix;
+	}
+
+	
+	protected void addSimpleProperty (String propertyName, Object value) {
+		AbstractSimpleProperty asp = TypeMapping.instanciateSimpleField(getClass(), getMetadata(),null,fieldPrefix,propertyName, value);
+		addProperty(asp);
+	}
+
+
+	protected AbstractSimpleProperty getProperty (String fieldName) {
+		List<AbstractField> list = getPropertiesByLocalName(fieldName);
+		// return null if no property
+		if (list==null) {
+			return null;
+		}
+		// return the first element of the list
+		return (AbstractSimpleProperty)list.get(0);
+	}
+
+	
+	protected String getPropertyValueAsString (String fieldName) {
+		AbstractSimpleProperty absProp = getProperty(fieldName);
+		if (absProp == null) {
+			return null;
+		} else {
+			return absProp.getStringValue();
+		}
+	}
+
+	protected Calendar getDatePropertyAsCalendar(String fieldName) {
+		DateType absProp = (DateType)getFirstEquivalentProperty(fieldName,DateType.class);
+		if (absProp != null) {
+			return absProp.getValue();
+		} else {
+			return null;
+		}
+	}
+
+}

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.java Sat Jul 28 08:36:32 2012
@@ -31,25 +31,8 @@ import org.apache.padaf.xmpbox.XMPMetada
  */
 public class BooleanType extends AbstractSimpleProperty {
 
-	private static final String TRUE = "True";
-	private static final String FALSE = "False";
-
-	/**
-	 * Property Boolean type constructor (namespaceURI is not given)
-	 * 
-	 * @param metadata
-	 *            The metadata to attach to this property
-	 * @param prefix
-	 *            The prefix to set for this property
-	 * @param propertyName
-	 *            The local Name of this property
-	 * @param value
-	 *            the value to give
-	 */
-	public BooleanType(XMPMetadata metadata, String prefix,
-			String propertyName, Object value) {
-		super(metadata, prefix, propertyName, value);
-	}
+	public static final String TRUE = "True";
+	public static final String FALSE = "False";
 
 	/**
 	 * Property Boolean type constructor (namespaceURI is given)
@@ -70,21 +53,6 @@ public class BooleanType extends Abstrac
 		super(metadata, namespaceURI, prefix, propertyName, value);
 	}
 
-	/**
-	 * Check if object value type is compatible with this property type
-	 * 
-	 * @param value
-	 *            Object value to check
-	 * @return true if types are compatibles
-	 */
-	public boolean isGoodType(Object value) {
-		if (value instanceof Boolean) {
-			return true;
-		} else if (value instanceof String) {
-			return value.equals(TRUE) || value.equals(FALSE);
-		}
-		return false;
-	}
 
 	/**
 	 * return the property value
@@ -92,7 +60,7 @@ public class BooleanType extends Abstrac
 	 * @return boolean the property value
 	 */
 	public boolean getValue() {
-		return (Boolean) objValue;
+		return (Boolean) getObjectValue();
 	}
 
 	/**
@@ -104,48 +72,27 @@ public class BooleanType extends Abstrac
 	 * 
 	 */
 	public void setValue(Object value) {
-		if (!isGoodType(value)) {
-			throw new IllegalArgumentException(
-					"Value given is not allowed for the boolean type.");
-		} else {
-			// if string object
-			if (value instanceof String) {
-				setValueFromString((String) value);
+		if (value instanceof Boolean) {
+			setObjectValue(value);
+		} else if (value instanceof String) {
+			// NumberFormatException is thrown (sub of InvalidArgumentException)
+			String s = value.toString().trim().toUpperCase();
+			if ("TRUE".equals(s)) {
+				setObjectValue(Boolean.TRUE);
+				getElement().setTextContent(TRUE);
+			} else if ("FALSE".equals(s)) {
+				setObjectValue(Boolean.FALSE);
+				getElement().setTextContent(FALSE);
 			} else {
-				// if boolean
-				setValueFromBool((Boolean) value);
+				// unknown value
+				throw new IllegalArgumentException("Not a valid boolean value : '"+value+"'");
 			}
-
-		}
-	}
-
-	/**
-	 * Set property value
-	 * 
-	 * @param value
-	 *            the new boolean element value
-	 */
-	private void setValueFromBool(boolean value) {
-		objValue = value;
-		if (value) {
-			element.setTextContent(TRUE);
 		} else {
-			element.setTextContent(FALSE);
+			// invalid type of value
+			throw new IllegalArgumentException("Value given is not allowed for the Boolean type.");
 		}
 	}
 
-	/**
-	 * Set the value of this property
-	 * 
-	 * @param value
-	 *            The String value to set
-	 */
-	private void setValueFromString(String value) {
-		if (value.equals(TRUE)) {
-			setValueFromBool(true);
-		} else {
-			setValueFromBool(false);
-		}
-	}
+
 
 }

Copied: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexProperty.java (from r1355678, pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexProperty.java)
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexProperty.java?p2=pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexProperty.java&p1=pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexProperty.java&r1=1355678&r2=1366609&rev=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexProperty.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexProperty.java Sat Jul 28 08:36:32 2012
@@ -33,29 +33,12 @@ import org.apache.padaf.xmpbox.XMPMetada
 public class ComplexProperty extends AbstractField {
 
 	public static final String UNORDERED_ARRAY = "Bag";
+
 	public static final String ORDERED_ARRAY = "Seq";
+	
 	public static final String ALTERNATIVE_ARRAY = "Alt";
 
-	protected ComplexPropertyContainer container;
-
-	/**
-	 * Contructor of a complex property
-	 * 
-	 * @param metadata
-	 *            The metadata to attach to this property
-	 * @param prefix
-	 *            The prefix to set for this property
-	 * @param propertyName
-	 *            The local Name of this property
-	 * @param type
-	 *            type of complexProperty (Bag, Seq, Alt)
-	 */
-	public ComplexProperty(XMPMetadata metadata, String prefix,
-			String propertyName, String type) {
-		super(metadata, prefix, propertyName);
-		container = new ComplexPropertyContainer(metadata, "rdf", type);
-		element.appendChild(container.getElement());
-	}
+	private ComplexPropertyContainer container;
 
 	/**
 	 * Contructor of a complex property
@@ -74,8 +57,8 @@ public class ComplexProperty extends Abs
 	public ComplexProperty(XMPMetadata metadata, String namespace,
 			String prefix, String propertyName, String type) {
 		super(metadata, namespace, prefix, propertyName);
-		container = new ComplexPropertyContainer(metadata, "rdf", type);
-		element.appendChild(container.getElement());
+		container = new ComplexPropertyContainer(metadata,null, "rdf", type);
+		getElement().appendChild(container.getElement());
 	}
 
 	/**

Copied: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java (from r1355678, pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java)
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java?p2=pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java&p1=pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java&r1=1355678&r2=1366609&rev=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java Sat Jul 28 08:36:32 2012
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
+import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
 
@@ -38,25 +39,9 @@ import org.w3c.dom.NodeList;
  */
 public class ComplexPropertyContainer extends AbstractField {
 
-	protected List<AbstractField> properties;
-
-	/**
-	 * Complex Property type constructor (namespaceURI is not given)
-	 * 
-	 * @param metadata
-	 *            The metadata to attach to this property
-	 * @param prefix
-	 *            The prefix to set for this property
-	 * @param propertyName
-	 *            The local Name of this property
-	 */
-	public ComplexPropertyContainer(XMPMetadata metadata, String prefix,
-			String propertyName) {
-		super(metadata, prefix, propertyName);
-		properties = new ArrayList<AbstractField>();
-
-	}
-
+	
+	private List<AbstractField> properties;
+	
 	/**
 	 * Complex Property type constructor (namespaceURI is given)
 	 * 
@@ -90,7 +75,6 @@ public class ComplexPropertyContainer ex
 		List<AbstractField> list = getPropertiesByLocalName(localName);
 		if (list != null) {
 			for (AbstractField abstractField : list) {
-				// System.out.println(abstractField.getQualifiedName());
 				if (abstractField.getClass().equals(type)) {
 					return abstractField;
 				}
@@ -113,7 +97,7 @@ public class ComplexPropertyContainer ex
 		// BUT IT CREATE PROBLEM TO FIND AND ERASE CLONED ELEMENT
 		// Node cloned = obj.getElement().cloneNode(true);
 		// parent.adoptNode(cloned);
-		element.appendChild(obj.getElement());
+		getElement().appendChild(obj.getElement());
 		// element.appendChild(cloned);
 	}
 
@@ -142,7 +126,11 @@ public class ComplexPropertyContainer ex
 					list.add(abstractField);
 				}
 			}
-			return list;
+			if (list.size()==0) {
+				return null;
+			} else {
+				return list;
+			}
 		}
 		return null;
 
@@ -196,6 +184,7 @@ public class ComplexPropertyContainer ex
 	public void removeProperty(AbstractField property) {
 		if (containsProperty(property)) {
 			properties.remove(property);
+			Element element = getElement();
 			if (element.hasChildNodes()) {
 				NodeList nodes = element.getChildNodes();
 				boolean canRemove = false;
@@ -205,7 +194,9 @@ public class ComplexPropertyContainer ex
 					}
 				}
 				// remove out of the loop to avoid concurrent exception
-				if (canRemove)element.removeChild(property.getElement());
+				if (canRemove) {
+					element.removeChild(property.getElement());
+				}
 			}
 		}
 	}

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DateType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DateType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DateType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DateType.java Sat Jul 28 08:36:32 2012
@@ -36,23 +36,6 @@ import org.apache.padaf.xmpbox.parser.Da
  */
 public class DateType extends AbstractSimpleProperty {
 
-    /**
-     * Property Date type constructor (namespaceURI is not given)
-     * 
-     * @param metadata
-     *            The metadata to attach to this property
-     * @param prefix
-     *            The prefix to set for this property
-     * @param propertyName
-     *            The local Name of this property
-     * @param value
-     *            The value to set for this property
-     */
-    public DateType(XMPMetadata metadata, String prefix, String propertyName,
-            Object value) {
-        super(metadata, prefix, propertyName, value);
-
-    }
 
     /**
      * Property Date type constructor (namespaceURI is given)
@@ -81,8 +64,8 @@ public class DateType extends AbstractSi
      * @throws InappropriateTypeException
      */
     private void setValueFromCalendar(Calendar value) {
-        objValue = value;
-        element.setTextContent(DateConverter.toISO8601(value));
+        setObjectValue(value);
+        getElement().setTextContent(DateConverter.toISO8601(value));
 
     }
 
@@ -92,7 +75,7 @@ public class DateType extends AbstractSi
      * @return boolean
      */
     public Calendar getValue() {
-        return (Calendar) objValue;
+        return (Calendar) getObjectValue();
     }
 
     /**
@@ -102,7 +85,7 @@ public class DateType extends AbstractSi
      *            Object value to check
      * @return True if types are compatibles
      */
-    public boolean isGoodType(Object value) {
+    private boolean isGoodType(Object value) {
         if (value instanceof Calendar) {
             return true;
         } else if (value instanceof String) {

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Elementable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Elementable.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Elementable.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Elementable.java Sat Jul 28 08:36:32 2012
@@ -36,5 +36,5 @@ public interface Elementable {
 	 * 
 	 * @return The xml element.
 	 */
-	public Element getElement();
+	Element getElement();
 }

Copied: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/FieldDescription.java (from r1355678, pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/FieldDescription.java)
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/FieldDescription.java?p2=pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/FieldDescription.java&p1=pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/FieldDescription.java&r1=1355678&r2=1366609&rev=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/FieldDescription.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/FieldDescription.java Sat Jul 28 08:36:32 2012
@@ -32,9 +32,12 @@ import org.apache.padaf.xmpbox.schema.PD
  * 
  */
 public class FieldDescription {
-	protected String name;
-	protected String valueType;
-	protected String description;
+	
+	private String name;
+	
+	private String valueType;
+	
+	private String description;
 
 	/**
 	 * Constructor of a FieldDescription in order to be use in automatic

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java Sat Jul 28 08:36:32 2012
@@ -31,23 +31,6 @@ import org.apache.padaf.xmpbox.XMPMetada
  */
 public class IntegerType extends AbstractSimpleProperty {
 
-	/**
-	 * Property Integer type constructor (namespaceURI is not given)
-	 * 
-	 * @param metadata
-	 *            The metadata to attach to this property
-	 * @param prefix
-	 *            The prefix to set for this property
-	 * @param propertyName
-	 *            The local Name of this property
-	 * @param value
-	 *            The value to set
-	 */
-	public IntegerType(XMPMetadata metadata, String prefix,
-			String propertyName, Object value) {
-		super(metadata, prefix, propertyName, value);
-
-	}
 
 	/**
 	 * Property Integer type constructor (namespaceURI is given)
@@ -75,39 +58,7 @@ public class IntegerType extends Abstrac
 	 * @return the property value
 	 */
 	public int getValue() {
-		return (Integer) objValue;
-	}
-
-	/**
-	 * Set property value
-	 * 
-	 * @param value
-	 *            the value to set
-	 */
-	private void setValueFromInt(int value) {
-		objValue = value;
-		element.setTextContent("" + value);
-	}
-
-	/**
-	 * Check if the value can be treated
-	 * 
-	 * @param value
-	 *            The object to check
-	 * @return True if types are compatibles
-	 */
-	public boolean isGoodType(Object value) {
-		if (value instanceof Integer) {
-			return true;
-		} else if (value instanceof String) {
-			try {
-				Integer.parseInt((String) value);
-				return true;
-			} catch (NumberFormatException e) {
-				return false;
-			}
-		}
-		return false;
+		return (Integer) getObjectValue();
 	}
 
 	/**
@@ -117,30 +68,35 @@ public class IntegerType extends Abstrac
 	 *            The value to set
 	 */
 	public void setValue(Object value) {
-		if (!isGoodType(value)) {
-			throw new IllegalArgumentException(
-					"Value given is not allowed for the Integer type.");
+		if (value instanceof Integer) {
+			setObjectValue(value);
+		} else if (value instanceof String) {
+			// NumberFormatException is thrown (sub of InvalidArgumentException)
+			setObjectValue(Integer.valueOf((String)value));
 		} else {
-			// if string object
-			if (value instanceof String) {
-				setValueFromString((String) value);
-			} else {
-				// if Integer
-				setValueFromInt((Integer) value);
-			}
-
+			// invalid type of value
+			throw new IllegalArgumentException("Value given is not allowed for the Integer type.");
 		}
-
+		// set value
+		getElement().setTextContent(getObjectValue().toString());
 	}
+//
+//	public void setValue(Object value) {
+//		if (!isGoodType(value)) {
+//			throw new IllegalArgumentException(
+//					"Value given is not allowed for the Integer type.");
+//		} else {
+//			// if string object
+//			if (value instanceof String) {
+//				setValueFromString((String) value);
+//			} else {
+//				// if Integer
+//				setValueFromInt((Integer) value);
+//			}
+//
+//		}
+//
+//	}
 
-	/**
-	 * Set the value from a String
-	 * 
-	 * @param value
-	 *            the String value to set
-	 */
-	private void setValueFromString(String value) {
-		setValueFromInt(Integer.parseInt(value));
-	}
 
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/JobType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/JobType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/JobType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/JobType.java Sat Jul 28 08:36:32 2012
@@ -22,71 +22,63 @@
 package org.apache.padaf.xmpbox.type;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.XmpConstants;
+import org.apache.padaf.xmpbox.schema.PropertyType;
+import org.apache.padaf.xmpbox.schema.XMPSchema;
 
-public class JobType extends ComplexPropertyContainer {
+public class JobType extends AbstractStructuredType {
 
     public static final String ELEMENT_NS = "http://ns.adobe.com/xap/1.0/sType/Job#";
 
     public static final String PREFERED_PREFIX = "stJob";
     
+    @PropertyType(propertyType="Text")
     public static final String ID = "id";
 
+    @PropertyType(propertyType="Text")
     public static final String NAME = "name";
 
+    @PropertyType(propertyType="URL")
     public static final String URL = "url";
 
-    protected XMPMetadata metadata;
 
-
-    public JobType(XMPMetadata metadata, String namespace, String prefix,
-            String propertyName) {
-        super(metadata, namespace, prefix, propertyName);
-        this.metadata = metadata;
-        setAttribute(new Attribute(null, "rdf", "parseType", "Resource"));
+    public JobType(XMPMetadata metadata) {
+        this(metadata, PREFERED_PREFIX);
     }
 
-    
-    
-    public JobType(XMPMetadata metadata, String prefix, String propertyName) {
-        super(metadata, prefix, propertyName);
-        this.metadata = metadata;
-        setAttribute(new Attribute(null, "rdf", "parseType", "Resource"));
+    public JobType(XMPMetadata metadata, String fieldPrefix) {
+        super(metadata, XmpConstants.RDF_NAMESPACE, fieldPrefix);
+		setAttribute(new Attribute(XMPSchema.NS_NAMESPACE, "xmlns", fieldPrefix, ELEMENT_NS));
     }
 
-    public void setId(String prefix, String id) {
-        this.addProperty(new TextType(metadata, prefix, ID, id));
+    public void setId(String id) {
+    	addSimpleProperty(ID, id);
     }
 
-    public void setName(String prefix, String name) {
-        this.addProperty(new TextType(metadata, prefix, NAME, name));
+    public void setName( String name) {
+    	addSimpleProperty(NAME, name);
     }
 
-    public void setUrl(String prefix, String name) {
-        this.addProperty(new TextType(metadata, prefix, URL, name));
+    public void setUrl(String name) {
+    	addSimpleProperty(URL, name);
     }
 
     public String getId() {
-        AbstractField absProp = getFirstEquivalentProperty(ID,TextType.class);
-        if (absProp != null) {
-            return ((TextType) absProp).getStringValue();
-        }
-        return null;
+    	return getPropertyValueAsString(ID);
     }
 
     public String getName() {
-        AbstractField absProp = getFirstEquivalentProperty(NAME,TextType.class);
-        if (absProp != null) {
-            return ((TextType) absProp).getStringValue();
-        }
-        return null;
+    	return getPropertyValueAsString(NAME);
     }
 
     public String getUrl() {
-        AbstractField absProp = getFirstEquivalentProperty(URL,TextType.class);
-        if (absProp != null) {
-            return ((TextType) absProp).getStringValue();
-        }
-        return null;
+    	return getPropertyValueAsString(URL);
     }
 
+	@Override
+	public String getFieldsNamespace() {
+		return ELEMENT_NS;
+	}
+
+    
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/LayerType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/LayerType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/LayerType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/LayerType.java Sat Jul 28 08:36:32 2012
@@ -22,19 +22,24 @@
 package org.apache.padaf.xmpbox.type;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.XmpConstants;
+import org.apache.padaf.xmpbox.schema.PropertyType;
 
-public class LayerType extends ComplexPropertyContainer {
-	protected XMPMetadata metadata;
+public class LayerType extends AbstractStructuredType {
+
+	public static final String PREFERED_PREFIX = "photoshop";
 	
-	public LayerType(XMPMetadata metadata, String namespaceURI, String prefix, String propertyName) {
-		super(metadata, namespaceURI, prefix, propertyName);
-		this.metadata = metadata;
-		setAttribute(new Attribute(null, "rdf", "parseType", "Resource"));
-	}
+	public static final String ELEMENT_NS = "http://ns.adobe.com/photoshop/1.0/";
 	
-	public LayerType(XMPMetadata metadata, String prefix, String propertyName) {
-		super(metadata, prefix, propertyName);
-		this.metadata = metadata;
+	@PropertyType(propertyType="Text")
+	public static final String LAYER_NAME = "LayerName";
+
+	@PropertyType(propertyType="Text")
+	public static final String LAYER_TEXT = "LayerText";
+
+	
+	public LayerType(XMPMetadata metadata) {
+		super(metadata, XmpConstants.RDF_NAMESPACE, PREFERED_PREFIX);
 		setAttribute(new Attribute(null, "rdf", "parseType", "Resource"));
 	}
 	
@@ -44,7 +49,7 @@ public class LayerType extends ComplexPr
 	 * @return the LayerName
 	 */
 	public String getLayerName() {
-		AbstractField absProp = getFirstEquivalentProperty("LayerName",
+		AbstractField absProp = getFirstEquivalentProperty(LAYER_NAME,
 				TextType.class);
 		if (absProp != null) {
 			return ((TextType) absProp).getStringValue();
@@ -62,8 +67,8 @@ public class LayerType extends ComplexPr
 	 * @param image
 	 *            the value of LayerName property to set
 	 */
-	public void setLayerName(String prefix, String name, String image) {
-		this.addProperty(new TextType(metadata, prefix, name, image));
+	public void setLayerName(String image) {
+		this.addProperty(new TextType(getMetadata(), null,getFieldPrefix(), LAYER_NAME, image));
 	}
 	
 	/**
@@ -72,7 +77,7 @@ public class LayerType extends ComplexPr
 	 * @return the LayerText
 	 */
 	public String getLayerText() {
-		AbstractField absProp = getFirstEquivalentProperty("LayerText",
+		AbstractField absProp = getFirstEquivalentProperty(LAYER_TEXT,
 				TextType.class);
 		if (absProp != null) {
 			return ((TextType) absProp).getStringValue();
@@ -90,8 +95,14 @@ public class LayerType extends ComplexPr
 	 * @param image
 	 *            the value of LayerText property to set
 	 */
-	public void setLayerText(String prefix, String name, String image) {
-		this.addProperty(new TextType(metadata, prefix, name, image));
+	public void setLayerText(String image) {
+		this.addProperty(new TextType(getMetadata(), null,getFieldPrefix(), LAYER_TEXT, image));
+	}
+
+	@Override
+	public String getFieldsNamespace() {
+		return ELEMENT_NS;
 	}
 
+
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropertyDescription.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropertyDescription.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropertyDescription.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropertyDescription.java Sat Jul 28 08:36:32 2012
@@ -29,8 +29,10 @@ package org.apache.padaf.xmpbox.type;
  * 
  */
 public class PropertyDescription {
-	protected String propName;
-	protected String propDesc;
+
+	private String propName;
+	
+	private String propDesc;
 
 	/**
 	 * Constructor of a propertyDescription in order to be use in automatic

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java Sat Jul 28 08:36:32 2012
@@ -31,23 +31,6 @@ import org.apache.padaf.xmpbox.XMPMetada
  */
 public class RealType extends AbstractSimpleProperty {
 
-	/**
-	 * Property Real type constructor (namespaceURI is not given)
-	 * 
-	 * @param metadata
-	 *            The metadata to attach to this property
-	 * @param prefix
-	 *            The prefix to set for this property
-	 * @param propertyName
-	 *            The local Name of this property
-	 * @param value
-	 *            The value to set
-	 */
-	public RealType(XMPMetadata metadata, String prefix, String propertyName,
-			Object value) {
-		super(metadata, prefix, propertyName, value);
-
-	}
 
 	/**
 	 * Property Real type constructor (namespaceURI is given)
@@ -75,39 +58,7 @@ public class RealType extends AbstractSi
 	 * @return float the property value
 	 */
 	public float getValue() {
-		return (Float) objValue;
-	}
-
-	/**
-	 * Set property value
-	 * 
-	 * @param value
-	 *            the value to set
-	 */
-	private void setValueFromFloat(float value) {
-		objValue = value;
-		element.setTextContent("" + value);
-	}
-
-	/**
-	 * Check if the value can be treated
-	 * 
-	 * @param value
-	 *            The object to check
-	 * @return True if types are compatibles
-	 */
-	public boolean isGoodType(Object value) {
-		if (value instanceof Float) {
-			return true;
-		} else if (value instanceof String) {
-			try {
-				Float.parseFloat((String) value);
-				return true;
-			} catch (NumberFormatException e) {
-				return false;
-			}
-		}
-		return false;
+		return (Float) getObjectValue();
 	}
 
 	/**
@@ -117,30 +68,19 @@ public class RealType extends AbstractSi
 	 *            The value to set
 	 */
 	public void setValue(Object value) {
-		if (!isGoodType(value)) {
-			throw new IllegalArgumentException(
-					"Value given is not allowed for the Real type.");
+		if (value instanceof Float) {
+			setObjectValue(value);
+		} else if (value instanceof String) {
+			// NumberFormatException is thrown (sub of InvalidArgumentException)
+			setObjectValue(Float.valueOf((String)value));
 		} else {
-			// if string object
-			if (value instanceof String) {
-				setValueFromString((String) value);
-			} else {
-				// if Real (float)
-				setValueFromFloat((Float) value);
-			}
-
+			// invalid type of value
+			throw new IllegalArgumentException("Value given is not allowed for the Real type.");
 		}
-
+		// set value
+		getElement().setTextContent(getObjectValue().toString());
 	}
 
-	/**
-	 * Set the value from a String
-	 * 
-	 * @param value
-	 *            the String value to set
-	 */
-	private void setValueFromString(String value) {
-		setValueFromFloat(Float.parseFloat(value));
-	}
+
 
 }

Added: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RenditionClassType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RenditionClassType.java?rev=1366609&view=auto
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RenditionClassType.java (added)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RenditionClassType.java Sat Jul 28 08:36:32 2012
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * 
+ * 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.
+ * 
+ ****************************************************************************/
+
+package org.apache.padaf.xmpbox.type;
+
+import org.apache.padaf.xmpbox.XMPMetadata;
+
+public class RenditionClassType extends TextType {
+
+	public RenditionClassType(XMPMetadata metadata, String namespaceURI,
+			String prefix, String propertyName, Object value) {
+		super(metadata, namespaceURI, prefix, propertyName, value);
+	}
+
+}

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java Sat Jul 28 08:36:32 2012
@@ -24,26 +24,32 @@ package org.apache.padaf.xmpbox.type;
 import java.util.Calendar;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.XmpConstants;
+import org.apache.padaf.xmpbox.schema.PropertyType;
 import org.apache.padaf.xmpbox.schema.XMPSchema;
 
-public class ResourceEventType extends ComplexPropertyContainer {
+public class ResourceEventType extends AbstractStructuredType {
 
 	public static final String ELEMENT_NS = "http://ns.adobe.com/xap/1.0/sType/ResourceEvent#";
 
 	public static final String PREFERRED_PREFIX = "stEvt";
 	
-	protected XMPMetadata metadata;
-	
+	@PropertyType(propertyType="Choice")
 	public static final String ACTION = "action";
 
+	@PropertyType(propertyType="Text")
 	public static final String CHANGED = "changed";
 
+	@PropertyType(propertyType="GUID")
 	public static final String INSTANCE_ID = "instanceID";
 	
+	@PropertyType(propertyType="Text")
 	public static final String PARAMETERS = "parameters";
 	
+	@PropertyType(propertyType="AgentName")
 	public static final String SOFTWARE_AGENT = "softwareAgent";
 
+	@PropertyType(propertyType="Date")
 	public static final String WHEN = "when";
 	
 
@@ -58,94 +64,65 @@ public class ResourceEventType extends C
 	 * @param propertyName
 	 *            The local Name of this thumbnail type
 	 */
-	public ResourceEventType(XMPMetadata metadata, String namespace, String prefix,
-			String propertyName) {
-		super(metadata, namespace, prefix, propertyName);
-		this.metadata = metadata;
+	public ResourceEventType(XMPMetadata metadata) {
+		super(metadata, XmpConstants.RDF_NAMESPACE, PREFERRED_PREFIX);
 		setAttribute(new Attribute(XMPSchema.NS_NAMESPACE, "xmlns", PREFERRED_PREFIX, ELEMENT_NS));
 	}
 	
 	
 	public String getInstanceID () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(INSTANCE_ID,TextType.class);
-		if (absProp != null) {
-			return absProp.getStringValue();
-		} else {
-			return null;
-		}
+		return getPropertyValueAsString(INSTANCE_ID);
 	}
 
 	public void setInstanceID (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, INSTANCE_ID, value));
+		addSimpleProperty(INSTANCE_ID, value);
 	}
 
 	public String getSoftwareAgent () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(SOFTWARE_AGENT,TextType.class);
-		if (absProp != null) {
-			return absProp.getStringValue();
-		} else {
-			return null;
-		}
+		return getPropertyValueAsString(SOFTWARE_AGENT);
 	}
 
 	public void setSoftwareAgent (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, SOFTWARE_AGENT, value));
+		addSimpleProperty(SOFTWARE_AGENT, value);
 	}
 
 	public Calendar getWhen () {
-		DateType absProp = (DateType)getFirstEquivalentProperty(WHEN,DateType.class);
-		if (absProp != null) {
-			return absProp.getValue();
-		} else {
-			return null;
-		}
+		return getDatePropertyAsCalendar(WHEN);
 	}
 
 	public void setWhen (Calendar value) {
-		this.addProperty(new DateType(metadata, PREFERRED_PREFIX, WHEN, value));
+		addSimpleProperty(WHEN, value);
 	}
 
 	public String getAction () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(ACTION,TextType.class);
-		if (absProp != null) {
-			return absProp.getStringValue();
-		} else {
-			return null;
-		}
+		return getPropertyValueAsString(ACTION);
 	}
 
 	public void setAction (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, ACTION, value));
+		addSimpleProperty(ACTION, value);
 	}
 
 	
 	public String getChanged () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(CHANGED,TextType.class);
-		if (absProp != null) {
-			return absProp.getStringValue();
-		} else {
-			return null;
-		}
+		return getPropertyValueAsString(CHANGED);
 	}
 
 	public void setChanged (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, CHANGED, value));
+		addSimpleProperty(CHANGED, value);
 	}
 
 	public String getParameters () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(PARAMETERS,TextType.class);
-		if (absProp != null) {
-			return absProp.getStringValue();
-		} else {
-			return null;
-		}
+		return getPropertyValueAsString(PARAMETERS);
 	}
 
 	public void setParameters (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, PARAMETERS, value));
+		addSimpleProperty(PARAMETERS, value);
 	}
 
-
+	@Override
+	public String getFieldsNamespace() {
+		return ELEMENT_NS;
+	}
 
 	
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java Sat Jul 28 08:36:32 2012
@@ -21,52 +21,63 @@
 
 package org.apache.padaf.xmpbox.type;
 
-import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.XmpConstants;
 import org.apache.padaf.xmpbox.schema.PropertyType;
 import org.apache.padaf.xmpbox.schema.XMPSchema;
 
-public class ResourceRefType extends ComplexPropertyContainer {
+public class ResourceRefType extends AbstractStructuredType {
 
 	public static final String ELEMENT_NS = "http://ns.adobe.com/xap/1.0/sType/ResourceRef#";
 
 	public static final String PREFERRED_PREFIX = "stRef";
 	
-	protected XMPMetadata metadata;
-	
+	@PropertyType(propertyType = "URI")
 	public static final String DOCUMENT_ID = "documentID";
 
+	@PropertyType(propertyType = "URI")
 	public static final String FILE_PATH = "filePath";
 
+	@PropertyType(propertyType = "URI")
 	public static final String INSTANCE_ID = "instanceID";
 	
-	public static final String LAS_MODIFY_DATE = "lastModifyDate";
+	@PropertyType(propertyType = "Date")
+	public static final String LAST_MODIFY_DATE = "lastModifyDate";
 	
+	@PropertyType(propertyType = "URI")
 	public static final String MANAGE_TO = "manageTo";
 
+	@PropertyType(propertyType = "URI")
 	public static final String MANAGE_UI = "manageUI";
 	
+	@PropertyType(propertyType = "AgentName")
 	public static final String MANAGER = "manager";
 
+	@PropertyType(propertyType = "Text")
 	public static final String MANAGER_VARIANT = "managerVariant";
 
+	@PropertyType(propertyType = "Text")
 	public static final String PART_MAPPING = "partMapping";
 	
+	@PropertyType(propertyType = "Text")
 	public static final String RENDITION_PARAMS = "renditionParams";
-	
+
+	@PropertyType(propertyType = "Text")
 	public static final String VERSION_ID = "versionID";
 
+	@PropertyType(propertyType = "Choice")
 	public static final String MASK_MARKERS = "maskMarkers";
 	
+	@PropertyType(propertyType = "RenditionClass")
 	public static final String RENDITION_CLASS = "renditionClass";
 	
+	@PropertyType(propertyType = "Part")
 	public static final String FROM_PART = "fromPart";
 	
+	@PropertyType(propertyType = "Part")
 	public static final String TO_PART = "toPart";
 	
 	public static final String ALTERNATE_PATHS = "alternatePaths";
@@ -82,15 +93,13 @@ public class ResourceRefType extends Com
 	 * @param propertyName
 	 *            The local Name of this thumbnail type
 	 */
-	public ResourceRefType(XMPMetadata metadata, String namespace, String prefix,
-			String propertyName) {
-		super(metadata, namespace, prefix, propertyName);
-		this.metadata = metadata;
+	public ResourceRefType(XMPMetadata metadata) {
+		super(metadata, XmpConstants.RDF_NAMESPACE, PREFERRED_PREFIX);
 		setAttribute(new Attribute(XMPSchema.NS_NAMESPACE, "xmlns", PREFERRED_PREFIX, ELEMENT_NS));
 	}
 	
-	public String getDocumentId () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(DOCUMENT_ID,TextType.class);
+	public String getDocumentID () {
+		TextType absProp = (TextType)getFirstEquivalentProperty(DOCUMENT_ID,URIType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -98,12 +107,12 @@ public class ResourceRefType extends Com
 		}
 	}
 	
-	public void setDocumentId (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, DOCUMENT_ID, value));
+	public void setDocumentID (String value) {
+		addSimpleProperty(DOCUMENT_ID, value);
 	}
 	
 	public String getFilePath () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(FILE_PATH,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(FILE_PATH,URIType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -112,11 +121,11 @@ public class ResourceRefType extends Com
 	}
 
 	public void setFilePath (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, FILE_PATH, value));
+		addSimpleProperty(FILE_PATH, value);
 	}
 
 	public String getInstanceID () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(INSTANCE_ID,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(INSTANCE_ID,URIType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -125,11 +134,11 @@ public class ResourceRefType extends Com
 	}
 
 	public void setInstanceID (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, INSTANCE_ID, value));
+		addSimpleProperty(INSTANCE_ID, value);
 	}
 
 	public Calendar getLastModifyDate () {
-		DateType absProp = (DateType)getFirstEquivalentProperty(INSTANCE_ID,DateType.class);
+		DateType absProp = (DateType)getFirstEquivalentProperty(LAST_MODIFY_DATE,DateType.class);
 		if (absProp != null) {
 			return absProp.getValue();
 		} else {
@@ -138,11 +147,11 @@ public class ResourceRefType extends Com
 	}
 
 	public void setLastModifyDate (Calendar value) {
-		this.addProperty(new DateType(metadata, PREFERRED_PREFIX, INSTANCE_ID, value));
+		addSimpleProperty(LAST_MODIFY_DATE, value);
 	}
 
 	public String getManageUI () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(MANAGE_UI,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(MANAGE_UI,URIType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -151,11 +160,11 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setManageUI (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, MANAGE_UI, value));
+		addSimpleProperty(MANAGE_UI, value);
 	}
 	
 	public String getManageTo () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(MANAGE_TO,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(MANAGE_TO,URIType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -164,11 +173,11 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setManageTo (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, MANAGE_TO, value));
+		addSimpleProperty(MANAGE_TO, value);
 	}
 	
 	public String getManager () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(MANAGER,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(MANAGER,AgentNameType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -177,7 +186,7 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setManager (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, MANAGER, value));
+		addSimpleProperty(MANAGER, value);
 	}
 	
 	public String getManagerVariant () {
@@ -190,7 +199,7 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setManagerVariant (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, MANAGER_VARIANT, value));
+		addSimpleProperty(MANAGER_VARIANT, value);
 	}
 	
 	public String getPartMapping () {
@@ -203,7 +212,7 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setPartMapping (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, PART_MAPPING, value));
+		addSimpleProperty(PART_MAPPING, value);
 	}
 	
 	public String getRenditionParams () {
@@ -216,7 +225,7 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setRenditionParams (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, RENDITION_PARAMS, value));
+		addSimpleProperty(RENDITION_PARAMS, value);
 	}
 	
 	public String getVersionID () {
@@ -229,11 +238,11 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setVersionID (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, VERSION_ID, value));
+		addSimpleProperty(VERSION_ID, value);
 	}
 	
 	public String getMaskMarkers () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(MASK_MARKERS,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(MASK_MARKERS,ChoiceType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -242,11 +251,11 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setMaskMarkers (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, MASK_MARKERS, value));
+		addSimpleProperty(MASK_MARKERS, value);
 	}
 	
 	public String getRenditionClass () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(RENDITION_CLASS,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(RENDITION_CLASS,RenditionClassType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -255,11 +264,11 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setRenditionClass (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, RENDITION_CLASS, value));
+		addSimpleProperty(RENDITION_CLASS, value);
 	}
 	
 	public String getFromPart () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(FROM_PART,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(FROM_PART,PartType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -268,11 +277,11 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setFromPart (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, FROM_PART, value));
+		addSimpleProperty(FROM_PART, value);
 	}
 	
 	public String getToPart () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(TO_PART,TextType.class);
+		TextType absProp = (TextType)getFirstEquivalentProperty(TO_PART,PartType.class);
 		if (absProp != null) {
 			return absProp.getStringValue();
 		} else {
@@ -281,18 +290,19 @@ public class ResourceRefType extends Com
 	}
 	
 	public void setToPart (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, TO_PART, value));
+		addSimpleProperty(TO_PART, value);
 	}
 	
 	public void addAlternatePath(String value) {
         ComplexProperty seq = (ComplexProperty) getFirstEquivalentProperty(ALTERNATE_PATHS, ComplexProperty.class);
         if (seq==null) {
-        	seq = new ComplexProperty(metadata,
+        	seq = new ComplexProperty(getMetadata(), null,
                     PREFERRED_PREFIX, ALTERNATE_PATHS,
                     ComplexProperty.ORDERED_ARRAY);
         	addProperty(seq);
         }
-        seq.getContainer().addProperty(new TextType(metadata, "rdf", "li", value) );
+        TextType tt = (TextType)TypeMapping.instanciateSimpleProperty(getMetadata(), null, "rdf", "li", value, "Text");
+        seq.getContainer().addProperty(tt);
 	}
 
 	/**
@@ -301,8 +311,7 @@ public class ResourceRefType extends Com
 	 * @return version property to set
 	 */
 	public ComplexProperty getAlternatePathsProperty() {
-        ComplexProperty seq = (ComplexProperty) getFirstEquivalentProperty(ALTERNATE_PATHS, ComplexProperty.class);
-		return seq;
+        return (ComplexProperty) getFirstEquivalentProperty(ALTERNATE_PATHS, ComplexProperty.class);
 	}
 
 	/**
@@ -313,28 +322,16 @@ public class ResourceRefType extends Com
 	public List<String> getAlternatePaths() {
         ComplexProperty seq = (ComplexProperty) getFirstEquivalentProperty(ALTERNATE_PATHS, ComplexProperty.class);
         if (seq!=null) {
-        	return getArrayListToString(seq);
+        	return TypeUtil.getArrayListToString(seq);
         } else {
         	return null;
         }
 	}
 
-	// TODO should factorize in helper (exists in XMPSchema)
-    private List<String> getArrayListToString(ComplexProperty array) {
-        List<String> retval = null;
-        if (array != null) {
-            retval = new ArrayList<String>();
-            Iterator<AbstractField> it = array.getContainer()
-            .getAllProperties().iterator();
-            AbstractSimpleProperty tmp;
-            while (it.hasNext()) {
-                tmp = (AbstractSimpleProperty) it.next();
-                retval.add(tmp.getStringValue());
-            }
-            retval = Collections.unmodifiableList(retval);
-        }
-        return retval;
-    }
+	@Override
+	public String getFieldsNamespace() {
+		return ELEMENT_NS;
+	}
+
 
-	
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.java Sat Jul 28 08:36:32 2012
@@ -31,23 +31,6 @@ import org.apache.padaf.xmpbox.XMPMetada
  */
 public class TextType extends AbstractSimpleProperty {
 
-	/**
-	 * Property Text type constructor (namespaceURI is not given)
-	 * 
-	 * @param metadata
-	 *            The metadata to attach to this property
-	 * @param prefix
-	 *            The prefix to set for this property
-	 * @param propertyName
-	 *            The local Name of this property
-	 * @param value
-	 *            The value to set
-	 */
-	public TextType(XMPMetadata metadata, String prefix, String propertyName,
-			Object value) {
-		super(metadata, prefix, propertyName, value);
-
-	}
 
 	/**
 	 * Property Text type constructor (namespaceURI is given)
@@ -70,30 +53,19 @@ public class TextType extends AbstractSi
 	}
 
 	/**
-	 * Check if the value can be treated
-	 * 
-	 * @param value
-	 *            The object to check
-	 * @return True if types are compatibles
-	 */
-	public boolean isGoodType(Object value) {
-		return value instanceof String;
-	}
-
-	/**
 	 * Set the property value
 	 * 
 	 * @param value
 	 *            The value to set
 	 */
 	public void setValue(Object value) {
-		if (!isGoodType(value)) {
+		if (!(value instanceof String)) {
 			throw new IllegalArgumentException(
 					"Value given is not allowed for the Text type : '" + value
 							+ "'");
 		} else {
-			objValue = (String) value;
-			element.setTextContent((String) value);
+			setObjectValue((String) value);
+			getElement().setTextContent((String) value);
 		}
 
 	}

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ThumbnailType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ThumbnailType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ThumbnailType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ThumbnailType.java Sat Jul 28 08:36:32 2012
@@ -22,6 +22,8 @@
 package org.apache.padaf.xmpbox.type;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.XmpConstants;
+import org.apache.padaf.xmpbox.schema.PropertyType;
 
 
 /**
@@ -29,9 +31,23 @@ import org.apache.padaf.xmpbox.XMPMetada
  * 
  * @author eric
  */
-public class ThumbnailType extends ComplexPropertyContainer {
-	protected static final String ELEMENT_NS = "http://ns.adobe.com/xap/1.0/g/img/";
-	protected XMPMetadata metadata;
+public class ThumbnailType extends AbstractStructuredType {
+	
+	public static final String ELEMENT_NS = "http://ns.adobe.com/xap/1.0/g/img/";
+	
+	public static final String PREFERRED_PREFIX = "xmpGImg";
+	
+	@PropertyType(propertyType = "Choice")
+	public static final String FORMAT = "format";
+
+	@PropertyType(propertyType = "Integer")
+	public static final String HEIGHT = "height";
+	
+	@PropertyType(propertyType = "Integer")
+	public static final String WIDTH = "width";
+
+	@PropertyType(propertyType = "Text")
+	public static final String IMAGE = "image";
 
 	/**
 	 * 
@@ -44,37 +60,18 @@ public class ThumbnailType extends Compl
 	 * @param propertyName
 	 *            The local Name of this thumbnail type
 	 */
-	public ThumbnailType(XMPMetadata metadata, String namespace, String prefix,
-			String propertyName) {
-		super(metadata, namespace, prefix, propertyName);
-		this.metadata = metadata;
+	public ThumbnailType(XMPMetadata metadata) {
+		super(metadata, XmpConstants.RDF_NAMESPACE, PREFERRED_PREFIX);
 		setAttribute(new Attribute(null, "rdf", "parseType", "Resource"));
 	}
 
 	/**
-	 * 
-	 * @param metadata
-	 *            The metadata to attach to this property
-	 * @param prefix
-	 *            The prefix to set for this property
-	 * @param propertyName
-	 *            The local Name of this thumbnail type
-	 */
-	public ThumbnailType(XMPMetadata metadata, String prefix,
-			String propertyName) {
-		super(metadata, prefix, propertyName);
-		this.metadata = metadata;
-		setAttribute(new Attribute(null, "rdf", "parseType", "Resource"));
-	}
-
-
-	/**
 	 * Get Height
 	 * 
 	 * @return the height
 	 */
 	public Integer getHeight() {
-		AbstractField absProp = getFirstEquivalentProperty("height",
+		AbstractField absProp = getFirstEquivalentProperty(HEIGHT,
 				IntegerType.class);
 		if (absProp != null) {
 			return ((IntegerType) absProp).getValue();
@@ -92,8 +89,8 @@ public class ThumbnailType extends Compl
 	 * @param height
 	 *            the value of Height property to set
 	 */
-	public void setHeight(String prefix, String name, Integer height) {
-		this.addProperty(new IntegerType(metadata, prefix, name, height));
+	public void setHeight(Integer height) {
+		addSimpleProperty(HEIGHT, height);
 	}
 
 	/**
@@ -102,7 +99,7 @@ public class ThumbnailType extends Compl
 	 * @return the width
 	 */
 	public Integer getWidth() {
-		AbstractField absProp = getFirstEquivalentProperty("width",
+		AbstractField absProp = getFirstEquivalentProperty(WIDTH,
 				IntegerType.class);
 		if (absProp != null) {
 
@@ -121,8 +118,8 @@ public class ThumbnailType extends Compl
 	 * @param width
 	 *            the value of width property to set
 	 */
-	public void setWidth(String prefix, String name, Integer width) {
-		this.addProperty(new IntegerType(metadata, prefix, name, width));
+	public void setWidth(Integer width) {
+		addSimpleProperty(WIDTH, width);
 	}
 
 	/**
@@ -130,8 +127,8 @@ public class ThumbnailType extends Compl
 	 * 
 	 * @return the img
 	 */
-	public String getImg() {
-		AbstractField absProp = getFirstEquivalentProperty("image",
+	public String getImage() {
+		AbstractField absProp = getFirstEquivalentProperty(IMAGE,
 				TextType.class);
 		if (absProp != null) {
 			return ((TextType) absProp).getStringValue();
@@ -149,8 +146,8 @@ public class ThumbnailType extends Compl
 	 * @param image
 	 *            the value of image property to set
 	 */
-	public void setImg(String prefix, String name, String image) {
-		this.addProperty(new TextType(metadata, prefix, name, image));
+	public void setImage(String image) {
+		addSimpleProperty(IMAGE, image);
 	}
 
 	/**
@@ -159,8 +156,7 @@ public class ThumbnailType extends Compl
 	 * @return the format
 	 */
 	public String getFormat() {
-		AbstractField absProp = getFirstEquivalentProperty("format",
-				TextType.class);
+		AbstractField absProp = getFirstEquivalentProperty(FORMAT,ChoiceType.class);
 		if (absProp != null) {
 			return ((TextType) absProp).getStringValue();
 		}
@@ -177,8 +173,14 @@ public class ThumbnailType extends Compl
 	 * @param format
 	 *            the value of format property to set
 	 */
-	public void setFormat(String prefix, String name, String format) {
-		this.addProperty(new TextType(metadata, prefix, name, format));
+	public void setFormat(String format) {
+		addSimpleProperty(FORMAT, format);
+	}
+
+	@Override
+	public String getFieldsNamespace() {
+		return ELEMENT_NS;
 	}
 
+	
 }

Added: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java?rev=1366609&view=auto
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java (added)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java Sat Jul 28 08:36:32 2012
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * 
+ * 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.
+ * 
+ ****************************************************************************/
+
+package org.apache.padaf.xmpbox.type;
+
+
+public class TypeDescription {
+
+	public enum BasicType {	Text, Date, Integer, Boolean, Real}
+
+	private String type;
+	
+	private BasicType basic;
+	
+	private Class<? extends AbstractField> clz;
+
+	public TypeDescription(String type, BasicType basic,Class<? extends AbstractField> clz) {
+		super();
+		this.type = type;
+		this.basic = basic;
+		this.clz = clz;
+	}
+	
+
+	public TypeDescription(String type, BasicType basic) {
+		this(type, basic,TextType.class);
+	}
+
+	public TypeDescription(String type) {
+		this(type,BasicType.Text,TextType.class);
+	}
+
+	
+	public String getType() {
+		return type;
+	}
+
+	public Class<? extends AbstractField> getTypeClass() {
+		return clz;
+	}
+
+	public BasicType getBasic() {
+		return basic;
+	}
+
+	
+	
+	
+	
+}

Added: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java?rev=1366609&view=auto
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java (added)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java Sat Jul 28 08:36:32 2012
@@ -0,0 +1,307 @@
+/*****************************************************************************
+ * 
+ * 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.
+ * 
+ ****************************************************************************/
+
+package org.apache.padaf.xmpbox.type;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.schema.PropertyType;
+import org.apache.padaf.xmpbox.type.TypeDescription.BasicType;
+
+public final class TypeMapping {
+
+
+	
+    private static final Map<String,TypeDescription> BASIC_TYPES;
+
+    private static final Map<Class<? extends AbstractField>,TypeDescription> BASIC_CLASSES;
+
+    private static final Map<String,TypeDescription> DERIVED_TYPES;
+  
+    private static final Map<Class<? extends AbstractField>,TypeDescription> DERIVED_CLASSES;
+
+    private static final Map<String, TypeDescription> STRUCTURED_TYPES;
+
+    private static final Map<Class<? extends AbstractField>,TypeDescription> STRUCTURED_CLASSES;
+
+    private static final Map<String,TypeDescription> STRUCTURED_NAMESPACES;
+    
+	private static Map<Class<?>, Map<String,String>> structuredTypes = new HashMap<Class<?>, Map<String,String>>();
+
+    
+	// no public constructor
+	private TypeMapping() {
+		
+	}
+    
+
+    private static Class<?> [] simplePropertyConstParams = new Class<?> [] {
+    	XMPMetadata.class,
+    	String.class,
+		String.class,
+		String.class,
+		Object.class
+    };
+
+    static {
+    	// basic
+        BASIC_TYPES = new HashMap<String,TypeDescription>();
+        BASIC_CLASSES = new HashMap<Class<? extends AbstractField>, TypeDescription>();
+        addToBasicMaps(new TypeDescription("Text",BasicType.Text,TextType.class));
+        addToBasicMaps(new TypeDescription("Date",BasicType.Date,DateType.class));
+        addToBasicMaps(new TypeDescription("Boolean",BasicType.Boolean,BooleanType.class));
+        addToBasicMaps(new TypeDescription("Integer",BasicType.Integer,IntegerType.class));
+        addToBasicMaps(new TypeDescription("Real",BasicType.Real,RealType.class));
+
+        // derived
+        DERIVED_TYPES = new HashMap<String,TypeDescription>();
+        DERIVED_CLASSES = new HashMap<Class<? extends AbstractField>, TypeDescription>();
+        addToDerivedMaps(new TypeDescription("AgentName",BasicType.Text,AgentNameType.class));
+        addToDerivedMaps(new TypeDescription("Choice",BasicType.Text,ChoiceType.class));
+        addToDerivedMaps(new TypeDescription("GUID",BasicType.Text,GUIDType.class));
+        addToDerivedMaps(new TypeDescription("Lang Alt",BasicType.Text,TextType.class));
+        addToDerivedMaps(new TypeDescription("Locale",BasicType.Text,LocaleType.class));
+        addToDerivedMaps(new TypeDescription("MIMEType",BasicType.Text,MIMEType.class));
+        addToDerivedMaps(new TypeDescription("ProperName",BasicType.Text,ProperNameType.class));
+        addToDerivedMaps(new TypeDescription("RenditionClass",BasicType.Text,RenditionClassType.class));
+        addToDerivedMaps(new TypeDescription("URL",BasicType.Text,URLType.class));
+        addToDerivedMaps(new TypeDescription("URI",BasicType.Text,URIType.class));
+        addToDerivedMaps(new TypeDescription("XPath",BasicType.Text,XPathType.class));
+        addToDerivedMaps(new TypeDescription("Part",BasicType.Text,PartType.class));
+
+        // structured types
+        STRUCTURED_TYPES = new HashMap<String, TypeDescription>();
+        STRUCTURED_CLASSES = new HashMap<Class<? extends AbstractField>, TypeDescription>();
+        STRUCTURED_NAMESPACES = new HashMap<String, TypeDescription>();
+        addToStructuredMaps(new TypeDescription("Thumbnail",null,ThumbnailType.class));
+        addToStructuredMaps(new TypeDescription("Layer",null,LayerType.class));
+        addToStructuredMaps(new TypeDescription("ResourceEvent",null,ResourceEventType.class));
+        addToStructuredMaps(new TypeDescription("Job",null,JobType.class));
+        addToStructuredMaps(new TypeDescription("ResourceRef",null,ResourceRefType.class));
+        addToStructuredMaps(new TypeDescription("Version",null,VersionType.class));
+    }
+
+    private static void addToBasicMaps (TypeDescription td) {
+        BASIC_TYPES.put(td.getType(),td);
+        BASIC_CLASSES.put(td.getTypeClass(), td);
+    }
+
+    private static void addToDerivedMaps (TypeDescription td) {
+        DERIVED_TYPES.put(td.getType(),td);
+        DERIVED_CLASSES.put(td.getTypeClass(), td);
+    }
+
+    private static void addToStructuredMaps (TypeDescription td) {
+        STRUCTURED_TYPES.put(td.getType(),td);
+        STRUCTURED_CLASSES.put(td.getTypeClass(), td);
+        try {
+			STRUCTURED_NAMESPACES.put((String)td.getTypeClass().getField("ELEMENT_NS").get(null), td);
+		} catch (IllegalArgumentException e) {
+			throw new IllegalArgumentException("Failed to init structured maps for "+td.getTypeClass(), e);
+		} catch (SecurityException e) {
+			throw new IllegalArgumentException("Failed to init structured maps for "+td.getTypeClass(), e);
+		} catch (IllegalAccessException e) {
+			throw new IllegalArgumentException("Failed to init structured maps for "+td.getTypeClass(), e);
+		} catch (NoSuchFieldException e) {
+			throw new IllegalArgumentException("Failed to init structured maps for "+td.getTypeClass(), e);
+		}  
+    }
+
+    public static String getType (Class<?> clz) {
+    	// search in basic
+    	TypeDescription td = BASIC_CLASSES.get(clz);
+    	// search in derived
+    	if (td==null) {
+    		td = DERIVED_CLASSES.get(clz);
+    	}
+    	// search in structured
+    	if (td==null) {
+    		td = STRUCTURED_CLASSES.get(clz);
+    	}
+    	// return type if exists
+    	return (td!=null)?td.getType():null;
+    }
+    
+    /**
+     * Return the type description linked the specified paramater. If the type
+     * parameter is an array, the TypeDescription of the elements of the array
+     * will be returned
+     * 
+     * @param type
+     * @return
+     */
+    public static TypeDescription getTypeDescription (String type) {
+    	if (BASIC_TYPES.containsKey(type)) {
+    		return BASIC_TYPES.get(type);
+    	} else if (DERIVED_TYPES.containsKey(type)) {
+    		return DERIVED_TYPES.get(type);
+    	} else if (STRUCTURED_TYPES.containsKey(type)) { 
+    		return STRUCTURED_TYPES.get(type);
+    	} else {
+    		int pos = type.indexOf(' ');
+    		if (pos>0) {
+    			return getTypeDescription(type.substring(pos+1));
+    		} else {
+    			// unknown type
+    			return null;
+    		}
+    	}
+    }
+    
+    public static AbstractSimpleProperty instanciateSimpleProperty (XMPMetadata xmp,String nsuri, String prefix, String name, Object value, String type) {
+    	// constructor parameters
+    	Object [] params = new Object [] {
+    		xmp,	
+    		nsuri,
+    		prefix,
+    		name,
+    		value
+    	};
+    	// type 
+    	try {
+			TypeDescription description = getTypeDescription(type);
+			Class<? extends AbstractSimpleProperty> clz = (Class<? extends AbstractSimpleProperty>)description.getTypeClass();
+			Constructor<? extends AbstractSimpleProperty> cons = clz.getConstructor(simplePropertyConstParams);
+			return cons.newInstance(params);
+    	} catch (NoSuchMethodError e) {
+    		throw new IllegalArgumentException("Failed to instanciate property", e);
+    	} catch (IllegalArgumentException e) {
+    		throw new IllegalArgumentException("Failed to instanciate property", e);
+		} catch (InstantiationException e) {
+    		throw new IllegalArgumentException("Failed to instanciate property", e);
+		} catch (IllegalAccessException e) {
+    		throw new IllegalArgumentException("Failed to instanciate property", e);
+		} catch (InvocationTargetException e) {
+    		throw new IllegalArgumentException("Failed to instanciate property", e);
+		} catch (SecurityException e) {
+    		throw new IllegalArgumentException("Failed to instanciate property", e);
+		} catch (NoSuchMethodException e) {
+    		throw new IllegalArgumentException("Failed to instanciate property", e);
+		}
+    }
+   
+	public static AbstractSimpleProperty instanciateSimpleField (Class<?> clz, XMPMetadata xmp, String nsuri, String prefix,String propertyName, Object value) {
+		Map<String, String> fields = getStructuredTypeFields(clz);
+		String fieldName = fields.get(propertyName);
+		try {
+			Field f= clz.getField(fieldName);
+			PropertyType pt = f.getAnnotation(PropertyType.class);
+			String simpleType = pt.propertyType();
+			return TypeMapping.instanciateSimpleProperty(xmp, nsuri, prefix, propertyName, value, simpleType);
+		} catch (SecurityException e) {
+			throw new IllegalArgumentException("Failed to instanciate",e);
+		} catch (NoSuchFieldException e) {
+			throw new IllegalArgumentException("Failed to instanciate",e);
+		}
+	}
+
+    
+    
+	private static Map<String,String> getStructuredTypeFields (Class<?> clz) throws IllegalArgumentException {
+		Map<String,String> result = structuredTypes.get(clz);
+		if (result==null) {
+			result = new HashMap<String, String>();
+			Field [] fields = clz.getFields();
+			for (Field field : fields) {
+				PropertyType pt = field.getAnnotation(PropertyType.class);
+				if (pt!=null) {
+					String name = field.getName();
+					String value;
+					try {
+						value = field.get(null).toString();
+						result.put(value, name);
+					} catch (IllegalAccessException e) {
+						throw new IllegalArgumentException("Cannot parse this class", e);
+					}
+				}
+			}
+			structuredTypes.put(clz, result);
+		}
+		return result;
+	}
+
+    
+
+    
+    public static TypeDescription getStructuredTypeName (String namespace) {
+    	return STRUCTURED_NAMESPACES.get(namespace);
+    }
+  
+    /**
+     * Check if a namespace used reference a complex basic types (like
+     * Thumbnails)
+     * 
+     * @param namespace
+     *            The namespace URI to check
+     * @return True if namespace URI is a reference for a complex basic type
+     */
+    public static boolean isStructuredTypeNamespace(String namespace) {
+        return STRUCTURED_TYPES.containsKey(namespace);
+    }
+
+
+    public static boolean isArrayOfSimpleType (String type) {
+    	int pos = type.indexOf(' ');
+    	if (pos<0) {
+    		// not array
+    		return false;
+    	} else {
+    		String second = type.substring(pos+1);
+    		return isSimpleType(second);
+    	}
+    	
+    }
+    
+    public static String  getArrayType (String type) {
+    	int pos = type.indexOf(' ');
+    	if (pos<0) {
+    		// not array
+    		return null;
+    	} else {
+    		String first = type.substring(0,pos);
+    		if (first.equalsIgnoreCase(ComplexProperty.UNORDERED_ARRAY)) {
+    			return ComplexProperty.UNORDERED_ARRAY;
+    		} else if (first.equalsIgnoreCase(ComplexProperty.ORDERED_ARRAY)) {
+    			return ComplexProperty.ORDERED_ARRAY;
+    		} else if (first.equalsIgnoreCase(ComplexProperty.ALTERNATIVE_ARRAY)) {
+    			return ComplexProperty.ALTERNATIVE_ARRAY;
+    		} else {
+	    		// else not an array
+	    		return null;
+    		}
+    	}
+    }
+    
+    public static boolean isSimpleType(String type) {
+    	return (BASIC_TYPES.containsKey(type) || DERIVED_TYPES.containsKey(type));
+    }
+
+    public static boolean isStructuredType(String type) {
+    	return STRUCTURED_TYPES.containsKey(type);
+    }
+
+    
+}

Copied: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ValueTypeDescription.java (from r1355678, pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ValueTypeDescription.java)
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ValueTypeDescription.java?p2=pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ValueTypeDescription.java&p1=pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ValueTypeDescription.java&r1=1355678&r2=1366609&rev=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ValueTypeDescription.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ValueTypeDescription.java Sat Jul 28 08:36:32 2012
@@ -36,11 +36,16 @@ import org.apache.padaf.xmpbox.schema.PD
  * 
  */
 public class ValueTypeDescription {
-	protected String type;
-	protected String namespaceURI;
-	protected String prefix;
-	protected String description;
-	protected List<FieldDescription> fields;
+	
+	private String type;
+	
+	private String namespaceURI;
+	
+	private String prefix;
+	
+	private String description;
+	
+	private List<FieldDescription> fields;
 
 	/**
 	 * Constructor of ValueType Description with fields associated in order to

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java?rev=1366609&r1=1366608&r2=1366609&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java Sat Jul 28 08:36:32 2012
@@ -24,24 +24,29 @@ package org.apache.padaf.xmpbox.type;
 import java.util.Calendar;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.XmpConstants;
+import org.apache.padaf.xmpbox.schema.PropertyType;
 import org.apache.padaf.xmpbox.schema.XMPSchema;
 
-public class VersionType extends ComplexPropertyContainer {
+public class VersionType extends AbstractStructuredType {
 
 	public static final String ELEMENT_NS = "http://ns.adobe.com/xap/1.0/sType/Version#";
 
 	public static final String PREFERRED_PREFIX = "stVer";
 	
-	protected XMPMetadata metadata;
-	
+	@PropertyType(propertyType="Text")
 	public static final String COMMENTS = "comments";
 
+	@PropertyType(propertyType="ResourceEvent")
 	public static final String EVENT = "event";
 
+	@PropertyType(propertyType="ProperName") 
 	public static final String MODIFIER = "modifier";
 	
+	@PropertyType(propertyType="Date")
 	public static final String MODIFY_DATE = "modifyDate";
 	
+	@PropertyType(propertyType="Text")
 	public static final String VERSION = "version";
 
 
@@ -56,29 +61,21 @@ public class VersionType extends Complex
 	 * @param propertyName
 	 *            The local Name of this thumbnail type
 	 */
-	public VersionType(XMPMetadata metadata, String namespace, String prefix,
-			String propertyName) {
-		super(metadata, namespace, prefix, propertyName);
-		this.metadata = metadata;
+	public VersionType(XMPMetadata metadata) {
+		super(metadata, XmpConstants.RDF_NAMESPACE, PREFERRED_PREFIX);
 		setAttribute(new Attribute(XMPSchema.NS_NAMESPACE, "xmlns", PREFERRED_PREFIX, ELEMENT_NS));
 	}
 	
 	
 	public String getComments() {
-		TextType absProp = (TextType)getFirstEquivalentProperty(COMMENTS,TextType.class);
-		if (absProp != null) {
-			return absProp.getStringValue();
-		} else {
-			return null;
-		}
+		return getPropertyValueAsString(COMMENTS);
 	}
 
 	public void setComments (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, COMMENTS, value));
+		addSimpleProperty(COMMENTS, value);
 	}
 
 	public ResourceEventType getEvent () {
-//		ResourceEventType event = (ResourceEventType)getPropertiesByLocalName(EVENT);
 		return (ResourceEventType)getFirstEquivalentProperty(EVENT,ResourceEventType.class);
 	}
 
@@ -87,44 +84,33 @@ public class VersionType extends Complex
 	}
 
 	public Calendar getModifyDate () {
-		DateType absProp = (DateType)getFirstEquivalentProperty(MODIFY_DATE,DateType.class);
-		if (absProp != null) {
-			return absProp.getValue();
-		} else {
-			return null;
-		}
+		return getDatePropertyAsCalendar(MODIFY_DATE);
 	}
 
 	public void setModifyDate (Calendar value) {
-		this.addProperty(new DateType(metadata, PREFERRED_PREFIX, MODIFY_DATE, value));
+		addSimpleProperty(MODIFY_DATE, value);
 	}
 
 	public String getVersion () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(VERSION,TextType.class);
-		if (absProp != null) {
-			return absProp.getStringValue();
-		} else {
-			return null;
-		}
+		return getPropertyValueAsString(VERSION);
 	}
 
 	public void setVersion (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, VERSION, value));
+		addSimpleProperty(VERSION, value);
 	}
 
 	public String getModifier () {
-		TextType absProp = (TextType)getFirstEquivalentProperty(MODIFIER,TextType.class);
-		if (absProp != null) {
-			return absProp.getStringValue();
-		} else {
-			return null;
-		}
+		return getPropertyValueAsString(MODIFIER);
 	}
 
 	public void setModifier (String value) {
-		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, MODIFIER, value));
+		addSimpleProperty(MODIFIER, value);
+	}
+
+	@Override
+	public String getFieldsNamespace() {
+		return ELEMENT_NS;
 	}
 
 
-	
 }