Author: gbailleul
Date: Sun Aug 19 10:50:54 2012
New Revision: 1374728

URL: http://svn.apache.org/viewvc?rev=1374728&view=rev
Log:
PDFBOX-1343: remove duplicated code in ComplexPropertyContainer

Added:
    
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java
Modified:
    
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java
    
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/AbstractStructuredType.java
    
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java
    
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java
    
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java

Modified: 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java?rev=1374728&r1=1374727&r2=1374728&view=diff
==============================================================================
--- 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java
 (original)
+++ 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java
 Sun Aug 19 10:50:54 2012
@@ -109,11 +109,10 @@ public class XmpSerializer {
                                // attributes
                                fillElementWithAttributes(asimple, 
array.getAllAttributes());
                                // the array definition
-                               ComplexPropertyContainer container = 
array.getContainer();
-                               Element econtainer = 
doc.createElement("rdf"+":"+"Bag"); // TODO 
+                               Element econtainer = 
doc.createElement("rdf"+":"+array.getArrayType()); 
                                asimple.appendChild(econtainer);
                                // for each element of the array
-                               List<AbstractField> innerFields = 
container.getAllProperties();
+                               List<AbstractField> innerFields = 
array.getAllProperties();
                                xxxxxxx(doc, econtainer, innerFields);
                        } else if (field instanceof AbstractStructuredType) {
                                AbstractStructuredType structured = 
(AbstractStructuredType)field;

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=1374728&r1=1374727&r2=1374728&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
 Sun Aug 19 10:50:54 2012
@@ -78,9 +78,7 @@ public class XMPSchema {
         */
        public XMPSchema(XMPMetadata metadata, String namespaceName, String 
namespaceURI) {
                this.metadata = metadata;
-               content = new ComplexPropertyContainer(metadata,
-                               XmpConstants.RDF_NAMESPACE, "rdf",
-                               "Description");
+               content = new ComplexPropertyContainer();
 
                localPrefix = namespaceName;
                localNSUri = namespaceURI;

Added: 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java?rev=1374728&view=auto
==============================================================================
--- 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java
 (added)
+++ 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java
 Sun Aug 19 10:50:54 2012
@@ -0,0 +1,96 @@
+/*****************************************************************************
+ * 
+ * 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.List;
+
+import org.apache.padaf.xmpbox.XMPMetadata;
+
+public abstract class AbstractComplexProperty extends AbstractField {
+
+       private ComplexPropertyContainer container;
+       
+       public AbstractComplexProperty(XMPMetadata metadata, String 
namespaceURI,
+                       String prefix, String propertyName) {
+               super(metadata, namespaceURI, prefix, propertyName);
+               container = new ComplexPropertyContainer();
+       }
+
+       /**
+        * Add a property to the current structure
+        * 
+        * @param obj the property to add
+        */
+       public final void addProperty(AbstractField obj) {
+               container.addProperty(obj);
+       }
+
+       /**
+        * Remove a property
+        * 
+        * @param property
+        *            The property to remove
+        */
+       public final void removeProperty(AbstractField property) {
+               container.removeProperty(property);
+       }
+
+//     /**
+//      * Return the container of this Array
+//      * 
+//      * @return The complex property container that represents content of 
this
+//      *         property
+//      */
+       public final ComplexPropertyContainer getContainer() {
+               return container;
+       }
+       
+       public final List<AbstractField> getAllProperties() {
+               return container.getAllProperties();
+       }
+
+       public final AbstractSimpleProperty getProperty (String fieldName) {
+               List<AbstractField> list = 
container.getPropertiesByLocalName(fieldName);
+               // return null if no property
+               if (list==null) {
+                       return null;
+               }
+               // return the first element of the list
+               return (AbstractSimpleProperty)list.get(0);
+       }
+
+       public final ArrayProperty getArrayProperty (String fieldName) {
+               List<AbstractField> list = 
container.getPropertiesByLocalName(fieldName);
+               // return null if no property
+               if (list==null) {
+                       return null;
+               }
+               // return the first element of the list
+               return (ArrayProperty)list.get(0);
+       }
+
+       protected final AbstractField getFirstEquivalentProperty(String 
localName,
+                       Class<? extends AbstractField> type) {
+               return container.getFirstEquivalentProperty(localName, type);
+       }
+
+}

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=1374728&r1=1374727&r2=1374728&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
 Sun Aug 19 10:50:54 2012
@@ -44,21 +44,6 @@ public abstract class AbstractField {
        private Map<String, Attribute> attributes;
 
        /**
-        * Constructor of a XMP field without namespaceURI
-        * 
-        * @param metadata
-        *            The metadata to attach to this field
-        * @param prefix
-        *            the prefix to set for this field
-        * @param propertyName
-        *            the local name to set for this field
-        */
-       public AbstractField(XMPMetadata metadata, String prefix,
-                       String propertyName) {
-               this(metadata,null,prefix,propertyName);
-       }
-
-       /**
         * Constructor of a XMP Field
         * 
         * @param metadata

Modified: 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java?rev=1374728&r1=1374727&r2=1374728&view=diff
==============================================================================
--- 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java
 (original)
+++ 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java
 Sun Aug 19 10:50:54 2012
@@ -26,15 +26,13 @@ import java.util.List;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
 
-public abstract class AbstractStructuredType extends AbstractField {
+public abstract class AbstractStructuredType extends AbstractComplexProperty {
 
        
        
        /** The prefix of the fields of the structure */
        private String fieldPrefix = null;
        
-       private ComplexPropertyContainer container = null;
-
        protected static final String STRUCTURE_ARRAY_PREFIX = "rdf";
 
        protected static final  String STRUCTURE_ARRAY_NAME = "li"; 
@@ -42,7 +40,6 @@ public abstract class AbstractStructured
        public AbstractStructuredType(XMPMetadata metadata, String namespaceURI,
                        String fieldPrefix) {
                super(metadata, namespaceURI, STRUCTURE_ARRAY_PREFIX, 
STRUCTURE_ARRAY_NAME);
-               this.container = new ComplexPropertyContainer(metadata, 
namespaceURI, STRUCTURE_ARRAY_PREFIX, "Description");
                this.fieldPrefix = fieldPrefix;
        }
 
@@ -53,19 +50,6 @@ public abstract class AbstractStructured
        }
 
 
-       public final void addProperty(AbstractField obj) {
-               container.addProperty(obj);
-       }
-       
-       protected final AbstractField getFirstEquivalentProperty(String 
localName,
-                       Class<? extends AbstractField> type) {
-               return container.getFirstEquivalentProperty(localName, type);
-       }
-
-       public final List<AbstractField> getAllProperties() {
-               return container.getAllProperties();
-       }
-
        
        protected void addSimpleProperty (String propertyName, Object value) {
                TypeMapping tm = getMetadata().getBuilder().getTypeMapping();
@@ -74,25 +58,7 @@ public abstract class AbstractStructured
        }
 
 
-       protected AbstractSimpleProperty getProperty (String fieldName) {
-               List<AbstractField> list = 
container.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 ArrayProperty getArrayProperty (String fieldName) {
-               List<AbstractField> list = 
container.getPropertiesByLocalName(fieldName);
-               // return null if no property
-               if (list==null) {
-                       return null;
-               }
-               // return the first element of the list
-               return (ArrayProperty)list.get(0);
-       }
 
        
        protected String getPropertyValueAsString (String fieldName) {
@@ -105,7 +71,7 @@ public abstract class AbstractStructured
        }
 
        protected Calendar getDatePropertyAsCalendar(String fieldName) {
-               DateType absProp = 
(DateType)container.getFirstEquivalentProperty(fieldName,DateType.class);
+               DateType absProp = 
(DateType)getFirstEquivalentProperty(fieldName,DateType.class);
                if (absProp != null) {
                        return absProp.getValue();
                } else {
@@ -113,8 +79,6 @@ public abstract class AbstractStructured
                }
        }
 
-       public ComplexPropertyContainer getContainer() {
-               return container;
-       }
+
 
 }

Modified: 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java?rev=1374728&r1=1374727&r2=1374728&view=diff
==============================================================================
--- 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java
 (original)
+++ 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java
 Sun Aug 19 10:50:54 2012
@@ -21,8 +21,6 @@
 
 package org.apache.padaf.xmpbox.type;
 
-import java.util.List;
-
 import org.apache.padaf.xmpbox.XMPMetadata;
 
 /**
@@ -32,15 +30,15 @@ import org.apache.padaf.xmpbox.XMPMetada
  * @author a183132
  * 
  */
-public class ArrayProperty extends AbstractField {
+public class ArrayProperty extends AbstractComplexProperty {
 
        public static final String UNORDERED_ARRAY = "Bag";
 
        public static final String ORDERED_ARRAY = "Seq";
        
        public static final String ALTERNATIVE_ARRAY = "Alt";
-
-       private ComplexPropertyContainer container;
+       
+       private String arrayType;
 
        /**
         * Contructor of a complex property
@@ -59,21 +57,11 @@ public class ArrayProperty extends Abstr
        public ArrayProperty(XMPMetadata metadata, String namespace,
                        String prefix, String propertyName, String type) {
                super(metadata, namespace, prefix, propertyName);
-               container = new ComplexPropertyContainer(metadata,null, "rdf", 
type);
-       }
-
-       /**
-        * Return the container of this Array
-        * 
-        * @return The complex property container that represents content of 
this
-        *         property
-        */
-       public ComplexPropertyContainer getContainer() {
-               return container;
+               this.arrayType = type;
        }
 
-       public List<AbstractField> getAllProperties() {
-               return container.getAllProperties();
+       public String getArrayType() {
+               return arrayType;
        }
 
        

Modified: 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java?rev=1374728&r1=1374727&r2=1374728&view=diff
==============================================================================
--- 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java
 (original)
+++ 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java
 Sun Aug 19 10:50:54 2012
@@ -27,8 +27,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.padaf.xmpbox.XMPMetadata;
-
 /**
  * Object representation for arrays content This Class could be used to define
  * directly a property with more than one field (structure) and also schemas
@@ -57,8 +55,7 @@ public class ComplexPropertyContainer /*
         * @param propertyName
         *            The local Name of this property
         */
-       public ComplexPropertyContainer(XMPMetadata metadata, String 
namespaceURI,
-                       String prefix, String propertyName) {
+       public ComplexPropertyContainer() {
                properties = new ArrayList<AbstractField>();
                attributes = new HashMap<String, Attribute>();
        }

Modified: 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java?rev=1374728&r1=1374727&r2=1374728&view=diff
==============================================================================
--- 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java
 (original)
+++ 
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceRefType.java
 Sun Aug 19 10:50:54 2012
@@ -302,7 +302,7 @@ public class ResourceRefType extends Abs
         }
                TypeMapping tm = getMetadata().getBuilder().getTypeMapping();
         TextType tt = (TextType)tm.instanciateSimpleProperty(getMetadata(), 
null, "rdf", "li", value, "Text");
-        seq.getContainer().addProperty(tt);
+        seq.addProperty(tt);
        }
 
        /**


Reply via email to