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/10/26 23:25:26 UTC

svn commit: r1402668 - in /pdfbox/branches/xmpbox-refactoring/xmpbox/src: main/java/org/apache/padaf/xmpbox/ main/java/org/apache/padaf/xmpbox/schema/ main/java/org/apache/padaf/xmpbox/type/ main/java/org/apache/padaf/xmpbox/xml/ test/java/org/apache/p...

Author: gbailleul
Date: Fri Oct 26 21:25:25 2012
New Revision: 1402668

URL: http://svn.apache.org/viewvc?rev=1402668&view=rev
Log:
PDFBOX-1388: 
remove typedescription
reduce type mapping complexity

Removed:
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/BuildPDFAExtensionSchemaDescriptionException.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropertyDescription.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java
Modified:
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Cardinality.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Types.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractSchemaTester.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/DublinCoreTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/PhotoshopSchemaTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/AbstractStructuredTypeTester.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TypeTestingHelper.java

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java Fri Oct 26 21:25:25 2012
@@ -44,6 +44,7 @@ import org.apache.padaf.xmpbox.type.Date
 import org.apache.padaf.xmpbox.type.IntegerType;
 import org.apache.padaf.xmpbox.type.TextType;
 import org.apache.padaf.xmpbox.type.TypeMapping;
+import org.apache.padaf.xmpbox.type.Types;
 
 /**
  * This class represents a metadata schema that can be stored in an XMP
@@ -161,18 +162,8 @@ public class XMPSchema extends AbstractS
 		}
 	}
 
-	/**
-	 * Set a simple specified type property on the schema.
-	 * 
-	 * @param type
-	 *            the property type
-	 * @param qualifiedName
-	 *            the qualified name to specify for the new property
-	 * @param propertyValue
-	 *            The value (must be an object understandable by specified type)
-	 */
 	private void setSpecifiedSimpleTypeProperty(
-			Class<? extends AbstractSimpleProperty> type, String qualifiedName,
+			Types type, String qualifiedName,
 			Object propertyValue) {
 		if (propertyValue == null) {
 			// Search in properties to erase
@@ -191,7 +182,7 @@ public class XMPSchema extends AbstractS
 				TypeMapping tm = getMetadata().getTypeMapping();
 				specifiedTypeProperty = tm.instanciateSimpleProperty(
 						null, getPrefix(), qualifiedName,
-						propertyValue, tm.getType(type));
+						propertyValue, type);
 			} catch (Exception e) {
 				throw new IllegalArgumentException(
 						"Failed to create property with the specified type given in parameters",
@@ -213,6 +204,7 @@ public class XMPSchema extends AbstractS
 		}
 	}
 
+	
 	/**
 	 * Add a SimpleProperty to this schema
 	 * 
@@ -256,7 +248,7 @@ public class XMPSchema extends AbstractS
 	 *            will remove the property.
 	 */
 	public void setTextPropertyValue(String qualifiedName, String propertyValue) {
-		setSpecifiedSimpleTypeProperty(TextType.class, qualifiedName,
+		setSpecifiedSimpleTypeProperty(Types.Text, qualifiedName,
 				propertyValue);
 	}
 
@@ -400,7 +392,7 @@ public class XMPSchema extends AbstractS
 	 *            The date to set, or null to clear.
 	 */
 	public void setDatePropertyValue(String qualifiedName, Calendar date) {
-		setSpecifiedSimpleTypeProperty(DateType.class, qualifiedName, date);
+		setSpecifiedSimpleTypeProperty(Types.Date, qualifiedName, date);
 
 	}
 
@@ -494,7 +486,7 @@ public class XMPSchema extends AbstractS
 	 *            The boolean to set, or null to clear.
 	 */
 	public void setBooleanPropertyValue(String qualifiedName, Boolean bool) {
-		setSpecifiedSimpleTypeProperty(BooleanType.class, qualifiedName, bool);
+		setSpecifiedSimpleTypeProperty(Types.Boolean, qualifiedName, bool);
 	}
 
 	/**
@@ -583,7 +575,7 @@ public class XMPSchema extends AbstractS
 	 *            The int to set, or null to clear.
 	 */
 	public void setIntegerPropertyValue(String qualifiedName, Integer intValue) {
-		setSpecifiedSimpleTypeProperty(IntegerType.class, qualifiedName,
+		setSpecifiedSimpleTypeProperty(Types.Integer, qualifiedName,
 				intValue);
 	}
 

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java Fri Oct 26 21:25:25 2012
@@ -41,10 +41,6 @@ public abstract class AbstractField {
 
 	private XMPMetadata metadata;
 
-//	private String namespaceURI;
-	
-//	private String prefix;
-	
 	private String propertyName;
 	
 	private Map<String, Attribute> attributes;

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Cardinality.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Cardinality.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Cardinality.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Cardinality.java Fri Oct 26 21:25:25 2012
@@ -2,6 +2,19 @@ package org.apache.padaf.xmpbox.type;
 
 public enum Cardinality {
 
-	Simple,Bag,Seq,Alt
+	Simple(false),
+	Bag(true),
+	Seq(true),
+	Alt(true);
+	
+	private boolean array;
+	
+	private Cardinality (boolean a) {
+		this.array = a;
+	}
+	
+	public boolean isArray () {
+		return this.array;
+	}
 	
 }

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java Fri Oct 26 21:25:25 2012
@@ -43,33 +43,18 @@ import org.apache.padaf.xmpbox.schema.XM
 import org.apache.padaf.xmpbox.schema.XMPSchema;
 import org.apache.padaf.xmpbox.schema.XMPSchemaFactory;
 import org.apache.padaf.xmpbox.schema.XmpSchemaException;
-import org.apache.padaf.xmpbox.type.TypeDescription.BasicType;
-import org.apache.padaf.xmpbox.xml.XmpParsingException;
-import org.apache.padaf.xmpbox.xml.XmpParsingException.ErrorType;
 
 public final class TypeMapping {
 
+	private Map<Types, PropMapping> structuredMappings;
 
+	// ns -> type
+	private Map<String, Types> structuredNamespaces;
 
-	private Map<Types,TypeDescription<AbstractSimpleProperty>> basicTypes;
-
-	private Map<Class<? extends AbstractField>,TypeDescription<AbstractSimpleProperty>> basicClasses;
-
-	private Map<Types,TypeDescription<AbstractSimpleProperty>> derivedTypes;
-
-	private Map<Class<? extends AbstractField>,TypeDescription<AbstractSimpleProperty>> derivedClasses;
-
-	private Map<Types, TypeDescription<AbstractStructuredType>> structuredTypes;
-
-	private Map<Class<? extends AbstractField>,TypeDescription<AbstractStructuredType>> structuredClasses;
-
-	private Map<String,TypeDescription<AbstractStructuredType>> structuredNamespaces;
-
-	private Map<String, String> schemaUriToPrefered;
+	// ns -> type
+	private Map<String, String> definedStructuredNamespaces;
 	
-	private Map<String, TypeDescription<AbstractStructuredType>> definedStructuredTypes;
-	
-	private Map<String, TypeDescription<AbstractStructuredType>> definedStructuredNamespaces;
+	private Map<String, PropMapping> definedStructuredMappings;
 
 	private XMPMetadata metadata;
 
@@ -91,53 +76,25 @@ public final class TypeMapping {
 	};
 
 	private void initialize () {
-		// basic
-		basicTypes = new HashMap<Types,TypeDescription<AbstractSimpleProperty>>();
-		basicClasses = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractSimpleProperty>>();
-		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>(Types.Text,BasicType.Text,TextType.class));
-		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>(Types.Date,BasicType.Date,DateType.class));
-		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>(Types.Boolean,BasicType.Boolean,BooleanType.class));
-		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>(Types.Integer,BasicType.Integer,IntegerType.class));
-		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>(Types.Real,BasicType.Real,RealType.class));
-
-		// derived
-		derivedTypes = new HashMap<Types,TypeDescription<AbstractSimpleProperty>>();
-		derivedClasses = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractSimpleProperty>>();
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.AgentName,BasicType.Text,AgentNameType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.Choice,BasicType.Text,ChoiceType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.GUID,BasicType.Text,GUIDType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.LangAlt,BasicType.Text,TextType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.Locale,BasicType.Text,LocaleType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.MIMEType,BasicType.Text,MIMEType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.ProperName,BasicType.Text,ProperNameType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.RenditionClass,BasicType.Text,RenditionClassType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.URL,BasicType.Text,URLType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.URI,BasicType.Text,URIType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.XPath,BasicType.Text,XPathType.class));
-		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>(Types.Part,BasicType.Text,PartType.class));
-
 		// structured types
-		structuredTypes = new HashMap<Types, TypeDescription<AbstractStructuredType>>();
-		structuredClasses = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractStructuredType>>();
-		structuredNamespaces = new HashMap<String, TypeDescription<AbstractStructuredType>>();
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.Thumbnail,null,ThumbnailType.class));
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.Layer,null,LayerType.class));
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.ResourceEvent,null,ResourceEventType.class));
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.Job,null,JobType.class));
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.ResourceRef,null,ResourceRefType.class));
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.Version,null,VersionType.class));
-		// PDF/A structured types
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.PDFAField,null,PDFAFieldType.class));
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.PDFAProperty,null,PDFAPropertyType.class));
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.PDFAType,null,PDFATypeType.class));
-		addToStructuredMaps(new TypeDescription<AbstractStructuredType>(Types.PDFASchema,null,PDFASchemaType.class));
-
+		structuredMappings = new HashMap<Types, PropMapping>();
+		structuredNamespaces = new HashMap<String, Types>();
+		for (Types type : Types.values()) {
+			if (type.isStructured()) {
+				Class<?> clz = type.getImplementingClass();
+				StructuredType st = clz.getAnnotation(StructuredType.class);
+				String ns = st.namespace();
+				PropMapping pm = ReflectHelper.initializePropMapping(ns, clz);
+				structuredNamespaces.put(ns, type);
+				structuredMappings.put(type, pm);
+			}
+		}
+		
 		// define structured types
-		definedStructuredTypes = new HashMap<String, TypeDescription<AbstractStructuredType>>();
-		definedStructuredNamespaces = new HashMap<String, TypeDescription<AbstractStructuredType>>();
+		definedStructuredNamespaces = new HashMap<String, String>();
+		definedStructuredMappings = new HashMap<String, PropMapping>();
 		
 		// schema
-		schemaUriToPrefered = new HashMap<String, String>();
 		schemaMap = new HashMap<String, XMPSchemaFactory>();
 		addNameSpace(XMPBasicSchema.class);
 		addNameSpace(DublinCoreSchema.class);
@@ -151,83 +108,26 @@ public final class TypeMapping {
 
 	}
 
-	private void addToBasicMaps (TypeDescription<AbstractSimpleProperty> td) {
-		basicTypes.put(td.getType(),td);
-		basicClasses.put(td.getTypeClass(), td);
-	}
-
-	public void addToDerivedMaps (TypeDescription<AbstractSimpleProperty> td) {
-		derivedTypes.put(td.getType(),td);
-		derivedClasses.put(td.getTypeClass(), td);
-	}
-
-	private void addToStructuredMaps (TypeDescription<AbstractStructuredType> td) {
-		Class<? extends AbstractStructuredType> clz = td.getTypeClass();
-		StructuredType st = clz.getAnnotation(StructuredType.class);
-		String ns = st.namespace();
-		PropMapping pm = ReflectHelper.initializePropMapping(ns, clz);
-		td.setProperties(pm);
-		addToStructuredMaps(td, ns);
-	}
-
-	public void addToStructuredMaps (TypeDescription<AbstractStructuredType> td, String ns) {
-		structuredTypes.put(td.getType(),td);
-		structuredClasses.put(td.getTypeClass(), td);
-		structuredNamespaces.put(ns, td);
-	}
-
-	public void addToDefinedStructuredTypes (String typeName, TypeDescription<AbstractStructuredType> td, String ns) {
-		definedStructuredTypes.put(typeName, td);
-		definedStructuredNamespaces.put(ns, td);
-	}
-
-	public Types getType (Class<?> clz) {
-		// search in basic
-		TypeDescription<AbstractSimpleProperty> td = basicClasses.get(clz);
-		// search in derived
-		if (td==null) {
-			td = derivedClasses.get(clz);
-		}
-		// return simple
-		if (td!=null) {
-			return td.getType();
-		} else {
-			// search in structured
-			TypeDescription<AbstractStructuredType> td2 = structuredClasses.get(clz);
-			// return type if exists
-			return (td2!=null)?td2.getType():null;
-		}
+	public void addToDefinedStructuredTypes (String typeName, String ns, PropMapping pm) {
+		definedStructuredNamespaces.put(ns, typeName);
+		definedStructuredMappings.put(typeName, pm);
 	}
 
-	public TypeDescription<AbstractSimpleProperty> getSimpleDescription (Types type) {
-		if (basicTypes.containsKey(type)) {
-			return basicTypes.get(type);
-		} else if (derivedTypes.containsKey(type)) {
-			return derivedTypes.get(type);
-		} else {
-			return null;
-		}
-	}
-
-	public TypeDescription<AbstractStructuredType> getStructuredDescription (Types type) {
-		return structuredTypes.get(type);
-	}
-
-	public TypeDescription<AbstractStructuredType> getDefinedDescription (String name) {
-		return this.definedStructuredTypes.get(name);
-	}
-
-	public TypeDescription<AbstractStructuredType> getDefinedDescriptionByNamespace (String namespace) {
+	public String getDefinedDescriptionByNamespace (String namespace) {
 		return this.definedStructuredNamespaces.get(namespace);
 	}
 
-	public AbstractStructuredType instanciateStructuredType (TypeDescription<AbstractStructuredType> td, String propertyName) throws BadFieldValueException {
+	public PropMapping getDefinedPropMapping (String name) {
+		return this.definedStructuredMappings.get(name);
+	}
+	
+	public AbstractStructuredType instanciateStructuredType (Types type, String typeName, String propertyName) throws BadFieldValueException {
 		try {
-			Class<? extends AbstractStructuredType> propertyTypeClass = td.getTypeClass();
-			if (propertyTypeClass.equals(DefinedStructuredType.class)) {
-				PropMapping pm = td.getProperties();
+			if (type==Types.DefinedType) {
+				PropMapping pm = definedStructuredMappings.get(typeName);
 				return new DefinedStructuredType(metadata, pm.getConcernedNamespace(), null, propertyName);
 			} else {
+				Class<? extends AbstractStructuredType> propertyTypeClass = type.getImplementingClass().asSubclass(AbstractStructuredType.class);
 				Constructor<? extends AbstractStructuredType> construct = propertyTypeClass.getConstructor(new Class<?> [] {
 						XMPMetadata.class});
 				AbstractStructuredType tmp = construct.newInstance(metadata);
@@ -235,17 +135,17 @@ public final class TypeMapping {
 				return tmp;
 			}
 		} catch (InvocationTargetException e) {
-			throw new BadFieldValueException("Failed to instanciate structured type : "+td.getType(),e);
+			throw new BadFieldValueException("Failed to instanciate structured type : "+type,e);
 		} catch (IllegalArgumentException e) {
-			throw new BadFieldValueException("Failed to instanciate structured type : "+td.getType(),e);
+			throw new BadFieldValueException("Failed to instanciate structured type : "+type,e);
 		} catch (InstantiationException e) {
-			throw new BadFieldValueException("Failed to instanciate structured type : "+td.getType(),e);
+			throw new BadFieldValueException("Failed to instanciate structured type : "+type,e);
 		} catch (IllegalAccessException e) {
-			throw new BadFieldValueException("Failed to instanciate structured type : "+td.getType(),e);
+			throw new BadFieldValueException("Failed to instanciate structured type : "+type,e);
 		} catch (SecurityException e) {
-			throw new BadFieldValueException("Failed to instanciate structured type : "+td.getType(),e);
+			throw new BadFieldValueException("Failed to instanciate structured type : "+type,e);
 		} catch (NoSuchMethodException e) {
-			throw new BadFieldValueException("Failed to instanciate structured type : "+td.getType(),e);
+			throw new BadFieldValueException("Failed to instanciate structured type : "+type,e);
 		} 
 	}
 
@@ -260,8 +160,7 @@ public final class TypeMapping {
 		};
 		// type 
 		try {
-			TypeDescription<AbstractSimpleProperty> description = getSimpleDescription(type);
-			Class<? extends AbstractSimpleProperty> clz = (Class<? extends AbstractSimpleProperty>)description.getTypeClass();
+			Class<? extends AbstractSimpleProperty> clz = type.getImplementingClass().asSubclass(AbstractSimpleProperty.class);
 			Constructor<? extends AbstractSimpleProperty> cons = clz.getConstructor(simplePropertyConstParams);
 			return cons.newInstance(params);
 		} catch (NoSuchMethodError e) {
@@ -288,10 +187,6 @@ public final class TypeMapping {
 		return instanciateSimpleProperty(nsuri, prefix, propertyName, value, type);
 	}
 
-	public TypeDescription<AbstractStructuredType> getStructuredTypeName (String namespace) {
-		return structuredNamespaces.get(namespace);
-	}
-
 	/**
 	 * Check if a namespace used reference a complex basic types (like
 	 * Thumbnails)
@@ -308,50 +203,35 @@ public final class TypeMapping {
 		return definedStructuredNamespaces.containsKey(namespace);
 	}
 
-	public boolean isArrayOfSimpleType (PropertyType type) {
-		if (type.card()==Cardinality.Simple) {
-			return false;
-		}
-		// else is Alt/Bag/Seq
-		return type.type().isSimple();
-	}
-
-	public boolean isArrayType (PropertyType type) {
-		return type.card()!=Cardinality.Simple;
-	}
-
-	public String getTypeInArray (String type) {
-		int pos = type.indexOf(' ');
-		if (pos<0) {
-			// not array
-			return null;
-		} else {
-			return type.substring(pos+1);
-		}
-	}
-
-	public boolean isStructuredType(Types type) {
-		return structuredTypes.containsKey(type);
-	}
+//	public String getTypeInArray (String type) {
+//		int pos = type.indexOf(' ');
+//		if (pos<0) {
+//			// not array
+//			return null;
+//		} else {
+//			return type.substring(pos+1);
+//		}
+//	}
 
 	public boolean isDefinedType (String name) {
-		return this.definedStructuredTypes.containsKey(name);
+		return this.definedStructuredMappings.containsKey(name);
 	}
 
 	private void addNameSpace(Class<? extends XMPSchema> classSchem) {
 		StructuredType st = classSchem.getAnnotation(StructuredType.class);
 		String ns = st.namespace();
-		String pp = st.preferedPrefix();
 		schemaMap.put(ns, new XMPSchemaFactory(ns, classSchem,	ReflectHelper.initializePropMapping(ns, classSchem)));
-		schemaUriToPrefered.put(ns, pp);
 	}
 
 	public void addNewNameSpace(String ns,String prefered) {
 		PropMapping mapping = new PropMapping(ns);
 		schemaMap.put(ns, new XMPSchemaFactory(ns, XMPSchema.class, mapping));
-		schemaUriToPrefered.put(ns, prefered);
 	}
 
+	public PropMapping getStructuredPropMapping (Types type) {
+		return structuredMappings.get(type);
+	}
+	
 	/**
 	 * Return the specialized schema class representation if it's known (create
 	 * and add it to metadata). In other cases, return null
@@ -404,19 +284,18 @@ public final class TypeMapping {
 			return  factory.getPropertyType(name.getLocalPart());
 		} else {
 			// try in structured
-			TypeDescription<AbstractStructuredType> td = getStructuredTypeName(name.getNamespaceURI());
-			if (td==null) {
+			Types st = structuredNamespaces.get(name.getNamespaceURI());
+			if (st!=null) {
+				return  createPropertyType(st,Cardinality.Simple);
+			} else {
 				// try in defined
-				TypeDescription<AbstractStructuredType> td2 = definedStructuredNamespaces.get(name.getNamespaceURI());
-				if (td2==null) {
+				String dt = definedStructuredNamespaces.get(name.getNamespaceURI());
+				if (dt==null) {
 					// not found
-//					return null;
 					throw new BadFieldValueException("No descriptor found for "+name);
 				} else {
-					return createPropertyType(td2.getType(),Cardinality.Simple);
+					return createPropertyType(Types.DefinedType,Cardinality.Simple);
 				}
-			} else {
-				return  createPropertyType(td.getType(),Cardinality.Simple);
 			}
 		}
 	}
@@ -509,7 +388,7 @@ public final class TypeMapping {
 		return new PropertyType() {
 
 			public Class<? extends Annotation> annotationType() {
-				return PropertyType.class;
+				return null;
 			}
 
 			public Types type() {

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Types.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Types.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Types.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Types.java Fri Oct 26 21:25:25 2012
@@ -1,50 +1,73 @@
 package org.apache.padaf.xmpbox.type;
 
 public enum Types {
+
+	Structured(false,null,null),
+	DefinedType(false,null,null),
+
 	// basic
-	Text(true),
-	Date(true),
-	Boolean(true),
-	Integer(true),
-	Real(true),
-	
-	ProperName(true),
-	Locale(true),
-	AgentName(true),
-	GUID(true),
-	XPath(true),
-	Part(true),
-	URL(true),
-	URI(true),
-	Choice(true),
-	MIMEType(true),
-	LangAlt(true),
-	RenditionClass(true),
-	
-	Layer(false),
-	Thumbnail(false),
-	ResourceEvent(false),
-	ResourceRef(false),
-	Version(false),
-	PDFASchema(false),
-	PDFAField(false),
-	PDFAProperty(false),
-	PDFAType(false),
-	Job(false),
-	
+	Text(true,null,TextType.class),
+	Date(true,null,DateType.class),
+	Boolean(true,null,BooleanType.class),
+	Integer(true,null,IntegerType.class),
+	Real(true,null,RealType.class),
+	
+	ProperName(true,Text,ProperNameType.class),
+	Locale(true,Text,LocaleType.class),
+	AgentName(true,Text,AgentNameType.class),
+	GUID(true,Text,GUIDType.class),
+	XPath(true,Text,XPathType.class),
+	Part(true,Text,PartType.class),
+	URL(true,Text,URLType.class),
+	URI(true,Text,URIType.class),
+	Choice(true,Text,ChoiceType.class),
+	MIMEType(true,Text,MIMEType.class),
+	LangAlt(true,Text,TextType.class),
+	RenditionClass(true,Text,RenditionClassType.class),
+
+	Layer(false,Structured,LayerType.class),
+	Thumbnail(false,Structured,ThumbnailType.class),
+	ResourceEvent(false,Structured,ResourceEventType.class),
+	ResourceRef(false,Structured,ResourceRefType.class),
+	Version(false,Structured,VersionType.class),
+	PDFASchema(false,Structured,PDFASchemaType.class),
+	PDFAField(false,Structured,PDFAFieldType.class),
+	PDFAProperty(false,Structured,PDFAPropertyType.class),
+	PDFAType(false,Structured,PDFATypeType.class),
+	Job(false,Structured,JobType.class);
+
 	// For defined types
-	DefinedType(false);
 
 	private boolean simple;
 	
-	private Types (boolean s) {
+	private Types basic;
+	
+	private Class<? extends AbstractField> clz;
+	
+	private Types (boolean s, Types b, Class<? extends AbstractField> c) {
 		this.simple = s;
+		this.basic = b;
+		this.clz = c;
 	}
 
 	public boolean isSimple() {
 		return simple;
 	}
 	
+	public boolean isBasic () {
+		return basic==null;
+	}
+	
+	public boolean isStructured () {
+		return basic==Structured;
+	}
 	
+	public Types getBasic () {
+		return basic;
+	}
+	
+	public Class<? extends AbstractField> getImplementingClass () {
+		return clz;
+	}
 	
 }

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java Fri Oct 26 21:25:25 2012
@@ -30,7 +30,6 @@ import org.apache.padaf.xmpbox.type.Card
 import org.apache.padaf.xmpbox.type.ComplexPropertyContainer;
 import org.apache.padaf.xmpbox.type.PropMapping;
 import org.apache.padaf.xmpbox.type.PropertyType;
-import org.apache.padaf.xmpbox.type.TypeDescription;
 import org.apache.padaf.xmpbox.type.TypeMapping;
 import org.apache.padaf.xmpbox.type.Types;
 import org.apache.padaf.xmpbox.xml.XmpParsingException.ErrorType;
@@ -180,11 +179,11 @@ public class DomXmpParser {
 						}
 					} else if (type.type()==Types.LangAlt) {
 						manageLangAlt (xmp, property, container);
-					} else if (tm.isArrayType(type)) {
+					} else if (type.card().isArray()) {
 						manageArray(xmp,property,type,container);
 					} else if (type.type().isSimple()) {
 						manageSimpleType (xmp, property, type.type(), container);
-					} else if (tm.isStructuredType(type.type())) {
+					} else if (type.type().isStructured()) {
 						if (DomHelper.isParseTypeResource(property)) {
 							AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), property);
 							ast.setPrefix(prefix);
@@ -236,38 +235,32 @@ public class DomXmpParser {
 	}
 
 	private void manageArray (XMPMetadata xmp, Element property, PropertyType type, ComplexPropertyContainer container) throws XmpParsingException, BadFieldValueException {
-		//		nsFinder.push(property);
-		try {
-			TypeMapping tm = xmp.getTypeMapping();
-			String prefix = property.getPrefix();
-			String name = property.getLocalName();
-			String namespace = property.getNamespaceURI();
-//			Cardinality at = tm.getArrayType(type);
-			Element bagOrSeq = DomHelper.getUniqueElementChild(property);
-			// ensure this is the good type of array
-			if (bagOrSeq==null) {
-				// not an array
-				throw new XmpParsingException(ErrorType.Format,"Invalid array definition, expecting "+type.card()+" and found nothing");
-			}
-			if (!bagOrSeq.getLocalName().equals(type.card().name())) {
-				// not the good array type
-				throw new XmpParsingException(ErrorType.Format,"Invalid array type, expecting "+type.card()+" and found "+bagOrSeq.getLocalName());
-			}
-			ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
-			container.addProperty(array);
-			List<Element> lis=  DomHelper.getElementChildren(bagOrSeq);
-
-			for (Element element : lis) {
-				QName propertyQName = DomHelper.getQName(property);
-				AbstractField ast = parseLiElement(xmp, propertyQName, element);
-				if (ast!=null) {
-					array.addProperty(ast);
-				}
+		TypeMapping tm = xmp.getTypeMapping();
+		String prefix = property.getPrefix();
+		String name = property.getLocalName();
+		String namespace = property.getNamespaceURI();
+		//			Cardinality at = tm.getArrayType(type);
+		Element bagOrSeq = DomHelper.getUniqueElementChild(property);
+		// ensure this is the good type of array
+		if (bagOrSeq==null) {
+			// not an array
+			throw new XmpParsingException(ErrorType.Format,"Invalid array definition, expecting "+type.card()+" and found nothing");
+		}
+		if (!bagOrSeq.getLocalName().equals(type.card().name())) {
+			// not the good array type
+			throw new XmpParsingException(ErrorType.Format,"Invalid array type, expecting "+type.card()+" and found "+bagOrSeq.getLocalName());
+		}
+		ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
+		container.addProperty(array);
+		List<Element> lis=  DomHelper.getElementChildren(bagOrSeq);
+
+		for (Element element : lis) {
+			QName propertyQName = DomHelper.getQName(property);
+			AbstractField ast = parseLiElement(xmp, propertyQName, element);
+			if (ast!=null) {
+				array.addProperty(ast);
 			}
-		} finally {
-			//			nsFinder.pop();
 		}
-
 	}
 
 	private void manageLangAlt (XMPMetadata xmp, Element property, ComplexPropertyContainer container) throws XmpParsingException, BadFieldValueException {
@@ -285,8 +278,7 @@ public class DomXmpParser {
 				String name = property.getLocalName();
 				String namespace = property.getNamespaceURI();
 				PropertyType dtype = checkPropertyDefinition(xmp, DomHelper.getQName(property));
-				TypeDescription<AbstractStructuredType> td = tm.getStructuredDescription(dtype.type());
-				PropertyType ptype = td.getProperties().getPropertyType(name);
+				PropertyType ptype = tm.getStructuredPropMapping(dtype.type()).getPropertyType(name);
 				// create property
 				nsFinder.push(property);
 				try {
@@ -299,11 +291,11 @@ public class DomXmpParser {
 						}
 					} else if (ptype.type()==Types.LangAlt) {
 						manageLangAlt (xmp, property, parentContainer);
-					} else if (tm.isArrayType(ptype)) {
+					} else if (ptype.card().isArray()) {
 						manageArray(xmp,property,ptype,parentContainer);
 					} else if (ptype.type().isSimple()) {
 						manageSimpleType (xmp, property, ptype.type(), parentContainer);
-					} else if (tm.isStructuredType(ptype.type())) {
+					} else if (ptype.type().isStructured()) {
 						if (DomHelper.isParseTypeResource(property)) {
 							AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), property);
 							ast.setPrefix(prefix);
@@ -329,30 +321,25 @@ public class DomXmpParser {
 
 
 	private AbstractField parseLiElement (XMPMetadata xmp, QName descriptor, Element liElement) throws XmpParsingException, BadFieldValueException {
-		//		nsFinder.push(liElement);
-		try {
-			if (DomHelper.isParseTypeResource(liElement)) {
-				return parseLiDescription(xmp, descriptor,liElement);
-			} 
-			// will find rdf:Description
-			Element liChild = DomHelper.getUniqueElementChild(liElement);
-			if (liChild!=null) {
-				return parseLiDescription(xmp, descriptor, liChild);
-			} else {
-				// no child, so consider as simple text
-				String text = liElement.getTextContent();
-				TypeMapping tm = xmp.getTypeMapping();
-				AbstractSimpleProperty sp = tm.instanciateSimpleProperty(
-						descriptor.getNamespaceURI(), 
-						descriptor.getPrefix(), 
-						descriptor.getLocalPart(), 
-						text,
-						Types.Text);
-				loadAttributes(sp, liElement);
-				return sp;
-			}
-		} finally {
-			//			nsFinder.pop();
+		if (DomHelper.isParseTypeResource(liElement)) {
+			return parseLiDescription(xmp, descriptor,liElement);
+		} 
+		// will find rdf:Description
+		Element liChild = DomHelper.getUniqueElementChild(liElement);
+		if (liChild!=null) {
+			return parseLiDescription(xmp, descriptor, liChild);
+		} else {
+			// no child, so consider as simple text
+			String text = liElement.getTextContent();
+			TypeMapping tm = xmp.getTypeMapping();
+			AbstractSimpleProperty sp = tm.instanciateSimpleProperty(
+					descriptor.getNamespaceURI(), 
+					descriptor.getPrefix(), 
+					descriptor.getLocalPart(), 
+					text,
+					Types.Text);
+			loadAttributes(sp, liElement);
+			return sp;
 		}
 	}
 
@@ -366,77 +353,80 @@ public class DomXmpParser {
 			}
 		}
 	}
-	
+
 	private AbstractStructuredType parseLiDescription (XMPMetadata xmp, QName descriptor, Element liElement) throws XmpParsingException, BadFieldValueException {
-		//		nsFinder.push(liElement);
-		try {
-			TypeMapping tm = xmp.getTypeMapping();
-			List<Element> elements = DomHelper.getElementChildren(liElement);
-			if (elements.size()==0) {
-				// The list is empty
-				return null;
-			}
-			// Instantiate abstract structured type with hint from first element
-			Element first = elements.get(0);
-			PropertyType ctype = checkPropertyDefinition(xmp, DomHelper.getQName(first));
-			AbstractStructuredType ast = instanciateStructured(tm, ctype.type(), descriptor.getLocalPart(),first.getNamespaceURI());
-			ast.setNamespace(descriptor.getNamespaceURI());
-			ast.setPrefix(descriptor.getPrefix());
-
-			TypeDescription<AbstractStructuredType> td = tm.getStructuredDescription(ctype.type());
-			if (td==null) {
-				td = tm.getDefinedDescriptionByNamespace(first.getNamespaceURI());
-			}
-			PropMapping pm = td.getProperties();
-			for (Element element : elements) {
-				String prefix = element.getPrefix();
-				String name = element.getLocalName();
-				String namespace = element.getNamespaceURI();
-				PropertyType type = pm.getPropertyType(name);
-				if (type.type().isSimple()) {
-					AbstractSimpleProperty sp = tm.instanciateSimpleProperty(
-							namespace, 
-							prefix, 
-							name, 
-							element.getTextContent(),
-							type.type());
-					loadAttributes(sp,element);
-					ast.getContainer().addProperty(sp);
-				} else if (tm.isArrayType(type)) {
-					ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
-					ast.getContainer().addProperty(array);
-
-
-					Element bagOrSeq = DomHelper.getUniqueElementChild(element);
-					List<Element> lis=  DomHelper.getElementChildren(bagOrSeq);
-					for (Element element2 : lis) {
-						AbstractField ast2 = parseLiElement(xmp, descriptor, element2);
-						if (ast2!=null) {
-							array.addProperty(ast2);
-						}
-					}
-				} else if (tm.isStructuredType(type.type())) {
-					// create a new structured type
-					AbstractStructuredType inner = instanciateStructured(tm, type.type(), name,null);
-					inner.setNamespace(namespace);
-					inner.setPrefix(prefix);
-					ast.getContainer().addProperty(inner);
-					ComplexPropertyContainer cpc = inner.getContainer();
-					if (DomHelper.isParseTypeResource(element)) {
-						parseDescriptionInner(xmp, element, cpc);
-					} else {
-						Element descElement = DomHelper.getFirstChildElement(element);
-						parseDescriptionInner(xmp,descElement,cpc);
+		TypeMapping tm = xmp.getTypeMapping();
+		List<Element> elements = DomHelper.getElementChildren(liElement);
+		if (elements.size()==0) {
+			// The list is empty
+			return null;
+		}
+		// Instantiate abstract structured type with hint from first element
+		Element first = elements.get(0);
+		PropertyType ctype = checkPropertyDefinition(xmp, DomHelper.getQName(first));
+		AbstractStructuredType ast = instanciateStructured(tm, ctype.type(), descriptor.getLocalPart(),first.getNamespaceURI());
+		ast.setNamespace(descriptor.getNamespaceURI());
+		ast.setPrefix(descriptor.getPrefix());
+
+//		TypeDescription<AbstractStructuredType> td = tm.getStructuredDescription(ctype.type());
+//		if (td==null) {
+//			td = tm.getDefinedDescriptionByNamespace(first.getNamespaceURI());
+//		}
+		Types tt = ctype.type();
+		PropMapping pm;
+		if (tt.isStructured()) {
+			pm = tm.getStructuredPropMapping(tt);
+		} else {
+			String dt =tm.getDefinedDescriptionByNamespace(first.getNamespaceURI());
+//			pm = tm.getDefinedDescription(dt).getProperties();
+			pm = tm.getDefinedPropMapping(dt);
+		}
+		for (Element element : elements) {
+			String prefix = element.getPrefix();
+			String name = element.getLocalName();
+			String namespace = element.getNamespaceURI();
+			PropertyType type = pm.getPropertyType(name);
+			if (type.type().isSimple()) {
+				AbstractSimpleProperty sp = tm.instanciateSimpleProperty(
+						namespace, 
+						prefix, 
+						name, 
+						element.getTextContent(),
+						type.type());
+				loadAttributes(sp,element);
+				ast.getContainer().addProperty(sp);
+			} else if (type.card().isArray()) {
+				ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
+				ast.getContainer().addProperty(array);
+
+
+				Element bagOrSeq = DomHelper.getUniqueElementChild(element);
+				List<Element> lis=  DomHelper.getElementChildren(bagOrSeq);
+				for (Element element2 : lis) {
+					AbstractField ast2 = parseLiElement(xmp, descriptor, element2);
+					if (ast2!=null) {
+						array.addProperty(ast2);
 					}
+				}
+			} else if (type.type().isStructured()) {
+				// create a new structured type
+				AbstractStructuredType inner = instanciateStructured(tm, type.type(), name,null);
+				inner.setNamespace(namespace);
+				inner.setPrefix(prefix);
+				ast.getContainer().addProperty(inner);
+				ComplexPropertyContainer cpc = inner.getContainer();
+				if (DomHelper.isParseTypeResource(element)) {
+					parseDescriptionInner(xmp, element, cpc);
 				} else {
-					throw new XmpParsingException(ErrorType.NoType, "Unidentified element to parse "+element+" (type="+type+")");
+					Element descElement = DomHelper.getFirstChildElement(element);
+					parseDescriptionInner(xmp,descElement,cpc);
 				}
-
+			} else {
+				throw new XmpParsingException(ErrorType.NoType, "Unidentified element to parse "+element+" (type="+type+")");
 			}
-			return ast;
-		} finally {
-			//			nsFinder.pop();
+
 		}
+		return ast;
 	}
 
 
@@ -561,12 +551,12 @@ public class DomXmpParser {
 	}
 
 	private AbstractStructuredType instanciateStructured (TypeMapping tm, Types type, String name, String structuredNamespace) throws BadFieldValueException {
-		TypeDescription<AbstractStructuredType> td = null;
-		td = tm.getStructuredDescription(type);
-		if (td==null) {
-			td = tm.getDefinedDescriptionByNamespace(structuredNamespace);
+		if (type.isStructured()) {
+			return tm.instanciateStructuredType(type,null,name);
+		} else {
+			String dt = tm.getDefinedDescriptionByNamespace(structuredNamespace);
+			return tm.instanciateStructuredType(Types.DefinedType, dt, name);
 		}
-		return tm.instanciateStructuredType(td,name);
 	}
 
 	private PropertyType checkPropertyDefinition (XMPMetadata xmp, QName prop) throws XmpParsingException {
@@ -576,13 +566,14 @@ public class DomXmpParser {
 			throw new XmpParsingException(ErrorType.NoSchema, "Schema is not set in this document : "+prop.getNamespaceURI());
 		}
 		// test if namespace is defined
-		if (!tm.isDefinedSchema(prop.getNamespaceURI())) {
-			if (tm.isStructuredTypeNamespace(prop.getNamespaceURI())) {
-				// structured exists
-			} else if (tm.isDefinedTypeNamespace(prop.getNamespaceURI())) {
-				// defined
-			} else { 
-				// not existing
+		String nsuri = prop.getNamespaceURI();
+		if (!tm.isDefinedSchema(nsuri)) {
+			if (!tm.isStructuredTypeNamespace(nsuri) && !tm.isDefinedTypeNamespace(nsuri)) {
+//				// structured exists
+//			} else if () {
+//				// defined
+//			} else { 
+				// not structured and not defind
 				throw new XmpParsingException(ErrorType.NoSchema, "Cannot find a definition for the namespace "+prop.getNamespaceURI());
 			} 
 		}

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java Fri Oct 26 21:25:25 2012
@@ -8,7 +8,6 @@ import org.apache.padaf.xmpbox.schema.PD
 import org.apache.padaf.xmpbox.schema.XMPSchema;
 import org.apache.padaf.xmpbox.schema.XMPSchemaFactory;
 import org.apache.padaf.xmpbox.type.AbstractField;
-import org.apache.padaf.xmpbox.type.AbstractSimpleProperty;
 import org.apache.padaf.xmpbox.type.AbstractStructuredType;
 import org.apache.padaf.xmpbox.type.ArrayProperty;
 import org.apache.padaf.xmpbox.type.Cardinality;
@@ -20,7 +19,6 @@ import org.apache.padaf.xmpbox.type.PDFA
 import org.apache.padaf.xmpbox.type.PropMapping;
 import org.apache.padaf.xmpbox.type.PropertyType;
 import org.apache.padaf.xmpbox.type.StructuredType;
-import org.apache.padaf.xmpbox.type.TypeDescription;
 import org.apache.padaf.xmpbox.type.TypeMapping;
 import org.apache.padaf.xmpbox.type.Types;
 import org.apache.padaf.xmpbox.xml.XmpParsingException.ErrorType;
@@ -118,32 +116,24 @@ public final class PdfaExtensionHelper {
 												if (fName==null || fDescription==null || fValueType==null) {
 													throw new XmpParsingException(ErrorType.RequiredProperty,"Missing field in field definition");
 												}
-												TypeDescription<AbstractSimpleProperty> vtd  = null;
 												try {
 													Types fValue = Types.valueOf(fValueType);
-													vtd = tm.getSimpleDescription(fValue);
-													if (vtd!=null) {
-														// a type is found
-														Types ftype = vtd.getType();
-														structuredType.addProperty(fName, TypeMapping.createPropertyType(ftype,Cardinality.Simple));
-													} else {
-														throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : "+fValueType);
-													}
+													structuredType.addProperty(fName, TypeMapping.createPropertyType(fValue,Cardinality.Simple));
 												} catch (IllegalArgumentException e) {
-													throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : "+fValueType);
+													throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : "+fValueType,e);
 													// TODO could fValueType be a structured type ?
 												}
 											} // else TODO
 										}
 									}
 									// add the structured type to list
-									TypeDescription<AbstractStructuredType> td = new TypeDescription<AbstractStructuredType>(Types.DefinedType, null, DefinedStructuredType.class);
+//									TypeDescription<AbstractStructuredType> td = new TypeDescription<AbstractStructuredType>(tm,Types.DefinedType);
 									PropMapping pm = new PropMapping(structuredType.getNamespace());
 									for (Map.Entry<String, PropertyType> entry : structuredType.getDefinedProperties().entrySet()) {
 										pm.addNewProperty(entry.getKey(), entry.getValue());
 									}
-									td.setProperties(pm);
-									tm.addToDefinedStructuredTypes(ttype, td,tns);
+//									td.setProperties(pm);
+									tm.addToDefinedStructuredTypes(ttype, tns,pm);
 								}
 							}	
 						}
@@ -164,7 +154,7 @@ public final class PdfaExtensionHelper {
 								PropertyType pt = transformValueType(tm,ptype);
 								if (pt.type()==null) {
 									throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : "+ptype);
-								} else if (pt.type().isSimple() || tm.isStructuredType(pt.type()) || pt.type()==Types.DefinedType) {
+								} else if (pt.type().isSimple() || pt.type().isStructured() || pt.type()==Types.DefinedType) {
 									xsf.getPropertyDefinition().addNewProperty(pname, pt);
 								} else {
 									throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : "+ptype);
@@ -204,7 +194,8 @@ public final class PdfaExtensionHelper {
 			type = pos<0?Types.valueOf(valueType):Types.valueOf(vt);
 		} catch (IllegalArgumentException e) {
 			if (tm.isDefinedType(vt)) {
-				type = tm.getDefinedDescription(vt).getType();
+//				type = tm.getDefinedDescription(vt).getType();
+				type = Types.DefinedType;
 			}
 		}
 		return TypeMapping.createPropertyType(type, card);

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractSchemaTester.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractSchemaTester.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractSchemaTester.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractSchemaTester.java Fri Oct 26 21:25:25 2012
@@ -29,7 +29,7 @@ import junit.framework.Assert;
 import org.apache.padaf.xmpbox.XMPMetadata;
 import org.apache.padaf.xmpbox.type.AbstractSimpleProperty;
 import org.apache.padaf.xmpbox.type.ArrayProperty;
-import org.apache.padaf.xmpbox.type.TypeDescription;
+import org.apache.padaf.xmpbox.type.Cardinality;
 import org.apache.padaf.xmpbox.type.TypeMapping;
 import org.apache.padaf.xmpbox.type.TypeTestingHelper;
 import org.apache.padaf.xmpbox.type.Types;
@@ -51,9 +51,6 @@ public abstract class AbstractSchemaTest
 	
 	protected DomXmpParser builder;
 	
-	// TODO supprimer
-	protected enum Cardinality {Simple, Bag, Seq, Alt}
-	
 	public void before () throws Exception {
 		builder = new DomXmpParser();
 		xmp = XMPMetadata.createXMPMetadata();
@@ -96,8 +93,7 @@ public abstract class AbstractSchemaTest
 	public void testSettingValue() throws Exception {
 		if (cardinality!=Cardinality.Simple) return;
 		// only test simple properties
-		TypeDescription<AbstractSimpleProperty> td =typeMapping.getSimpleDescription(type);
-		Object value = TypeTestingHelper.getJavaValue(td);
+		Object value = TypeTestingHelper.getJavaValue(type);
 		AbstractSimpleProperty property = getSchema().instanciateSimple(fieldName, value);
 		getSchema().addProperty(property);
 		String qn = getPropertyQualifiedName(fieldName);
@@ -117,8 +113,7 @@ public abstract class AbstractSchemaTest
 	public void testSettingValueInArray() throws Exception {
 		if (cardinality==Cardinality.Simple) return;
 		// only test array properties
-		TypeDescription<AbstractSimpleProperty> td =typeMapping.getSimpleDescription(type);
-		Object value = TypeTestingHelper.getJavaValue(td);
+		Object value = TypeTestingHelper.getJavaValue(type);
 		AbstractSimpleProperty property = getSchema().instanciateSimple(fieldName, value);
 		switch (cardinality) {
 		case Seq:
@@ -148,12 +143,11 @@ public abstract class AbstractSchemaTest
     public void testPropertySetterSimple () throws Exception {
 		if (cardinality!=Cardinality.Simple) return;
     	String setter = TypeTestingHelper.calculateSimpleSetter(fieldName)+"Property";
-    	TypeDescription<AbstractSimpleProperty> td = typeMapping.getSimpleDescription(type);
-    	Object value = TypeTestingHelper.getJavaValue(td);
+    	Object value = TypeTestingHelper.getJavaValue(type);
     	AbstractSimpleProperty asp = typeMapping.instanciateSimpleProperty(
     			getSchema().getNamespace(), 
     			getSchema().getPrefix(), fieldName, value, type);
-    	Method set = getSchemaClass().getMethod(setter, new Class<?>[] {td.getTypeClass()} );
+    	Method set = getSchemaClass().getMethod(setter, new Class<?>[] {type.getImplementingClass()} );
     	set.invoke(getSchema(), new Object [] {asp});
     	// check property set
     	AbstractSimpleProperty stored = (AbstractSimpleProperty)getSchema().getProperty(fieldName);
@@ -162,7 +156,7 @@ public abstract class AbstractSchemaTest
     	String getter = TypeTestingHelper.calculateSimpleGetter(fieldName)+"Property";
     	Method get = getSchemaClass().getMethod(getter, new Class[0]);
     	Object result = get.invoke(getSchema(), new Object [0]);
-    	Assert.assertTrue(td.getTypeClass().isAssignableFrom(result.getClass()));
+    	Assert.assertTrue(type.getImplementingClass().isAssignableFrom(result.getClass()));
     	Assert.assertEquals(asp, result);
     }
 
@@ -171,9 +165,9 @@ public abstract class AbstractSchemaTest
 		if (cardinality==Cardinality.Simple) return;
 		// add value
     	String setter = "add"+TypeTestingHelper.calculateFieldNameForMethod(fieldName);
-    	TypeDescription<AbstractSimpleProperty> td = typeMapping.getSimpleDescription(type);
-    	Object value1 = TypeTestingHelper.getJavaValue(td);
-    	Method set = getSchemaClass().getMethod(setter, new Class<?>[] {TypeTestingHelper.getJavaType(td)} );
+//    	TypeDescription<AbstractSimpleProperty> td = typeMapping.getSimpleDescription(type);
+    	Object value1 = TypeTestingHelper.getJavaValue(type);
+    	Method set = getSchemaClass().getMethod(setter, new Class<?>[] {TypeTestingHelper.getJavaType(type)} );
     	set.invoke(getSchema(), new Object [] {value1});
     	// retrieve complex property
     	String getter = TypeTestingHelper.calculateArrayGetter(fieldName)+"Property";
@@ -184,12 +178,12 @@ public abstract class AbstractSchemaTest
     	// check size is ok (1)
     	Assert.assertEquals(1,cp.getContainer().getAllProperties().size());
     	// add a new one
-    	Object value2 = TypeTestingHelper.getJavaValue(td);
+    	Object value2 = TypeTestingHelper.getJavaValue(type);
     	set.invoke(getSchema(), new Object [] {value2});
     	Assert.assertEquals(2,cp.getContainer().getAllProperties().size());
     	// remove the first
     	String remover = "remove"+TypeTestingHelper.calculateFieldNameForMethod(fieldName);
-    	Method remove = getSchemaClass().getMethod(remover, new Class<?>[] {TypeTestingHelper.getJavaType(td)});
+    	Method remove = getSchemaClass().getMethod(remover, new Class<?>[] {TypeTestingHelper.getJavaType(type)});
     	remove.invoke(getSchema(), value1);
     	Assert.assertEquals(1,cp.getContainer().getAllProperties().size());
     	

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/DublinCoreTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/DublinCoreTest.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/DublinCoreTest.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/DublinCoreTest.java Fri Oct 26 21:25:25 2012
@@ -23,6 +23,7 @@ package org.apache.padaf.xmpbox.schema;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.apache.padaf.xmpbox.type.Cardinality;
 import org.apache.padaf.xmpbox.type.Types;
 import org.junit.Before;
 import org.junit.runner.RunWith;

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/PhotoshopSchemaTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/PhotoshopSchemaTest.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/PhotoshopSchemaTest.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/PhotoshopSchemaTest.java Fri Oct 26 21:25:25 2012
@@ -23,6 +23,7 @@ package org.apache.padaf.xmpbox.schema;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.apache.padaf.xmpbox.type.Cardinality;
 import org.apache.padaf.xmpbox.type.Types;
 import org.junit.Before;
 import org.junit.runner.RunWith;

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/AbstractStructuredTypeTester.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/AbstractStructuredTypeTester.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/AbstractStructuredTypeTester.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/AbstractStructuredTypeTester.java Fri Oct 26 21:25:25 2012
@@ -72,8 +72,7 @@ public abstract class AbstractStructured
 	
 	@Test
 	public void testSettingValue() throws Exception {
-		TypeDescription<AbstractSimpleProperty> td = typeMapping.getSimpleDescription(type);
-		Object value = TypeTestingHelper.getJavaValue(td);
+		Object value = TypeTestingHelper.getJavaValue(type);
 		getStructured().addSimpleProperty(fieldName, value);
 		Assert.assertNotNull(getStructured().getProperty(fieldName));
 		// check other properties not modified
@@ -89,21 +88,19 @@ public abstract class AbstractStructured
 
 	@Test
 	public void testPropertyType() throws Exception {
-		TypeDescription<AbstractSimpleProperty> td = typeMapping.getSimpleDescription(type);
-		Object value = TypeTestingHelper.getJavaValue(td);
+		Object value = TypeTestingHelper.getJavaValue(type);
 		getStructured().addSimpleProperty(fieldName, value);
 		Assert.assertNotNull(getStructured().getProperty(fieldName));
 		// check property type
 		AbstractSimpleProperty asp = (AbstractSimpleProperty) getStructured().getProperty(fieldName);
-		Assert.assertEquals(td.getTypeClass(),asp.getClass());
+		Assert.assertEquals(type.getImplementingClass(),asp.getClass());
 	}
 
     @Test
     public void testSetter () throws Exception {
     	String setter = TypeTestingHelper.calculateSimpleSetter(fieldName);
-    	TypeDescription<AbstractSimpleProperty> td = typeMapping.getSimpleDescription(type);
-    	Object value = TypeTestingHelper.getJavaValue(td);
-    	Method set = clz.getMethod(setter, new Class<?>[] {TypeTestingHelper.getJavaType(td)} );
+    	Object value = TypeTestingHelper.getJavaValue(type);
+    	Method set = clz.getMethod(setter, new Class<?>[] {TypeTestingHelper.getJavaType(type)} );
     	set.invoke(getStructured(), new Object [] {value});
     	// check property set
     	Assert.assertEquals(value, ((AbstractSimpleProperty)getStructured().getProperty(fieldName)).getValue());
@@ -111,7 +108,7 @@ public abstract class AbstractStructured
     	Method get = clz.getMethod(TypeTestingHelper.calculateSimpleGetter(fieldName), new Class[0]);
     	Object result = get.invoke(getStructured(), new Object [0]);
 //    	Assert.assertEquals(getJavaType(td),result.getClass());
-    	Assert.assertTrue(TypeTestingHelper.getJavaType(td).isAssignableFrom(result.getClass()));
+    	Assert.assertTrue(TypeTestingHelper.getJavaType(type).isAssignableFrom(result.getClass()));
     	Assert.assertEquals(value, result);
     	
     }

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TypeTestingHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TypeTestingHelper.java?rev=1402668&r1=1402667&r2=1402668&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TypeTestingHelper.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TypeTestingHelper.java Fri Oct 26 21:25:25 2012
@@ -60,36 +60,36 @@ public final class TypeTestingHelper {
     }
 
     
-    public static Class<?> getJavaType (TypeDescription td) {
-    	if (td.getTypeClass()==TextType.class) {
+    public static Class<?> getJavaType (Types type) {
+    	if (type.getImplementingClass()==TextType.class) {
     		return String.class;
-    	} else if (td.getTypeClass()==DateType.class) {
+    	} else if (type.getImplementingClass()==DateType.class) {
     		return Calendar.class;
-    	} else if (td.getTypeClass()==IntegerType.class) {
+    	} else if (type.getImplementingClass()==IntegerType.class) {
     		return Integer.class;
-    	} else if (TextType.class.isAssignableFrom(td.getTypeClass())) {
+    	} else if (TextType.class.isAssignableFrom(type.getImplementingClass())) {
     		return String.class;
     	} else {
-    		throw new IllegalArgumentException("TODO : type not expected in test : "+td.getTypeClass());
+    		throw new IllegalArgumentException("TODO : type not expected in test : "+type.getImplementingClass());
     	}
     }
     
-    public static Object getJavaValue (TypeDescription td) {
-    	if (td.getTypeClass()==TextType.class) {
+    public static Object getJavaValue (Types type) {
+    	if (type.getImplementingClass()==TextType.class) {
     		return UUID.randomUUID().toString();
-    	} else if (td.getTypeClass()==DateType.class) {
+    	} else if (type.getImplementingClass()==DateType.class) {
     		// use random because test are too fast (generate same calendar twice)
     		Calendar calendar = Calendar.getInstance();
     		Random rand = new Random();
     		calendar.setTimeInMillis(rand.nextLong());
     		return calendar;
-    	} else if (td.getTypeClass()==IntegerType.class) {
+    	} else if (type.getImplementingClass()==IntegerType.class) {
     		return new Integer(14);
-    	} else if (TextType.class.isAssignableFrom(td.getTypeClass())) {
+    	} else if (TextType.class.isAssignableFrom(type.getImplementingClass())) {
     		// all derived from TextType
     		return UUID.randomUUID().toString();
     	} else {
-    		throw new IllegalArgumentException("TODO : type not expected in test : "+td.getTypeClass());
+    		throw new IllegalArgumentException("TODO : type not expected in test : "+type.getImplementingClass());
     	}
     }