pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1760962 - in /pdfbox/branches/2.0: debugger/src/main/java/org/apache/pdfbox/debugger/ui/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/ pdfbox/src/test/java/org/apache/pdfbox/pdmodel/ xmpbox/src/main/java/org/apache/xmpbox/type/ xm...
Date Thu, 15 Sep 2016 16:54:35 GMT
Author: tilman
Date: Thu Sep 15 16:54:35 2016
New Revision: 1760962

URL: http://svn.apache.org/viewvc?rev=1760962&view=rev
Log:
PDFBOX-2852: remove explicit array creation for calling varargs method, as suggested by Lorenz Pahl

Modified:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDNumberTreeNode.java
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java
    pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java
    pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java
    pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java
    pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/TestDerivedType.java

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java?rev=1760962&r1=1760961&r2=1760962&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java Thu Sep 15 16:54:35 2016
@@ -104,8 +104,8 @@ public class OSXAdapter implements Invoc
         // If we're setting a handler, enable the About menu item by calling
         // com.apple.eawt.Application reflectively
         try {
-            Method enableAboutMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledAboutMenu", new Class[] { boolean.class });
-            enableAboutMethod.invoke(macOSXApplication, new Object[] { Boolean.valueOf(enableAboutMenu) });
+            Method enableAboutMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledAboutMenu", boolean.class);
+            enableAboutMethod.invoke(macOSXApplication, Boolean.valueOf(enableAboutMenu));
         } catch (Exception ex) {
             System.err.println("OSXAdapter could not access the About Menu");
             throw new RuntimeException(ex);
@@ -122,8 +122,8 @@ public class OSXAdapter implements Invoc
         // If we're setting a handler, enable the Preferences menu item by calling
         // com.apple.eawt.Application reflectively
         try {
-            Method enablePrefsMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledPreferencesMenu", new Class[] { boolean.class });
-            enablePrefsMethod.invoke(macOSXApplication, new Object[] { enablePrefsMenu });
+            Method enablePrefsMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledPreferencesMenu", boolean.class);
+            enablePrefsMethod.invoke(macOSXApplication, enablePrefsMenu);
         } catch (Exception ex) {
             System.err.println("OSXAdapter could not access the About Menu");
             throw new RuntimeException(ex);
@@ -142,7 +142,7 @@ public class OSXAdapter implements Invoc
                     try {
                         Method getFilenameMethod = appleEvent.getClass().getDeclaredMethod("getFilename", (Class[])null);
                         String filename = (String) getFilenameMethod.invoke(appleEvent, (Object[])null);
-                        this.targetMethod.invoke(this.targetObject, new Object[] { filename });
+                        this.targetMethod.invoke(this.targetObject, filename);
                     } catch (Exception ex) {
                         throw new RuntimeException(ex);
                     }
@@ -160,10 +160,10 @@ public class OSXAdapter implements Invoc
                 macOSXApplication = applicationClass.getConstructor((Class[])null).newInstance((Object[])null);
             }
             Class<?> applicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
-            Method addListenerMethod = applicationClass.getDeclaredMethod("addApplicationListener", new Class[] { applicationListenerClass });
+            Method addListenerMethod = applicationClass.getDeclaredMethod("addApplicationListener", applicationListenerClass);
             // Create a proxy object around this handler that can be reflectively added as an Apple ApplicationListener
             Object osxAdapterProxy = Proxy.newProxyInstance(OSXAdapter.class.getClassLoader(), new Class[]{applicationListenerClass}, adapter);
-            addListenerMethod.invoke(macOSXApplication, new Object[] { osxAdapterProxy });
+            addListenerMethod.invoke(macOSXApplication, osxAdapterProxy);
         } catch (ClassNotFoundException cnfe) {
             System.err.println("This version of Mac OS X does not support the Apple EAWT.  ApplicationEvent handling has been disabled (" + cnfe + ")");
         } catch (Exception ex) {  // Likely a NoSuchMethodException or an IllegalAccessException loading/invoking eawt.Application methods
@@ -213,9 +213,9 @@ public class OSXAdapter implements Invoc
     protected void setApplicationEventHandled(Object event, boolean handled) {
         if (event != null) {
             try {
-                Method setHandledMethod = event.getClass().getDeclaredMethod("setHandled", new Class[] { boolean.class });
+                Method setHandledMethod = event.getClass().getDeclaredMethod("setHandled", boolean.class);
                 // If the target method returns a boolean, use that as a hint
-                setHandledMethod.invoke(event, new Object[] { Boolean.valueOf(handled) });
+                setHandledMethod.invoke(event, Boolean.valueOf(handled));
             } catch (Exception ex) {
                 System.err.println("OSXAdapter was unable to handle an ApplicationEvent: " + event);
                 throw new RuntimeException(ex);

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDNumberTreeNode.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDNumberTreeNode.java?rev=1760962&r1=1760961&r2=1760962&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDNumberTreeNode.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDNumberTreeNode.java Thu Sep 15 16:54:35 2016
@@ -208,8 +208,8 @@ public class PDNumberTreeNode implements
         COSObjectable retval = null;
         try
         {
-            Constructor<? extends COSObjectable> ctor = valueType.getConstructor( new Class[] { base.getClass() } );
-            retval = ctor.newInstance( new Object[] { base } );
+            Constructor<? extends COSObjectable> ctor = valueType.getConstructor(base.getClass());
+            retval = ctor.newInstance(base);
         }
         catch( Throwable t )
         {

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java?rev=1760962&r1=1760961&r2=1760962&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java Thu Sep 15 16:54:35 2016
@@ -48,9 +48,9 @@ public class TestPDDocumentInformation e
            assertNull("Wrong subject", info.getSubject());
            assertNull("Wrong trapped", info.getTrapped());
 
-           List<String> expectedMetadataKeys = Arrays.asList(new String[] {"CreationDate", "Author", "Creator",
-                                                                           "Producer", "ModDate", "Company",
-                                                                           "SourceModified", "Title"});
+           List<String> expectedMetadataKeys = Arrays.asList("CreationDate", "Author", "Creator",
+                                                             "Producer", "ModDate", "Company",
+                                                             "SourceModified", "Title");
            assertEquals("Wrong metadata key count", expectedMetadataKeys.size(),
                                                     info.getMetadataKeys().size());
            for (String key : expectedMetadataKeys)

Modified: pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java?rev=1760962&r1=1760961&r2=1760962&view=diff
==============================================================================
--- pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java (original)
+++ pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java Thu Sep 15 16:54:35 2016
@@ -1,491 +1,491 @@
-/*****************************************************************************
- * 
- * 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.xmpbox.type;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Calendar;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
-import org.apache.xmpbox.XMPMetadata;
-import org.apache.xmpbox.schema.AdobePDFSchema;
-import org.apache.xmpbox.schema.DublinCoreSchema;
-import org.apache.xmpbox.schema.ExifSchema;
-import org.apache.xmpbox.schema.PDFAExtensionSchema;
-import org.apache.xmpbox.schema.PDFAIdentificationSchema;
-import org.apache.xmpbox.schema.PhotoshopSchema;
-import org.apache.xmpbox.schema.TiffSchema;
-import org.apache.xmpbox.schema.XMPBasicJobTicketSchema;
-import org.apache.xmpbox.schema.XMPBasicSchema;
-import org.apache.xmpbox.schema.XMPMediaManagementSchema;
-import org.apache.xmpbox.schema.XMPRightsManagementSchema;
-import org.apache.xmpbox.schema.XMPSchema;
-import org.apache.xmpbox.schema.XMPSchemaFactory;
-import org.apache.xmpbox.schema.XMPageTextSchema;
-import org.apache.xmpbox.schema.XmpSchemaException;
-
-public final class TypeMapping
-{
-
-    private Map<Types, PropertiesDescription> structuredMappings;
-
-    // ns -> type
-    private Map<String, Types> structuredNamespaces;
-
-    // ns -> type
-    private Map<String, String> definedStructuredNamespaces;
-
-    private Map<String, PropertiesDescription> definedStructuredMappings;
-
-    private final XMPMetadata metadata;
-
-    private Map<String, XMPSchemaFactory> schemaMap;
-
-    public TypeMapping(XMPMetadata metadata)
-    {
-        this.metadata = metadata;
-        initialize();
-    }
-
-    private static final Class<?>[] SIMPLEPROPERTYCONSTPARAMS = new Class<?>[] { XMPMetadata.class, String.class,
-            String.class, String.class, Object.class };
-
-    private void initialize()
-    {
-        // structured types
-        structuredMappings = new EnumMap<Types, PropertiesDescription>(Types.class);
-        structuredNamespaces = new HashMap<String, Types>();
-        for (Types type : Types.values())
-        {
-            if (type.isStructured())
-            {
-                Class<? extends AbstractStructuredType> clz = type.getImplementingClass().asSubclass(
-                        AbstractStructuredType.class);
-                StructuredType st = clz.getAnnotation(StructuredType.class);
-                String ns = st.namespace();
-                PropertiesDescription pm = initializePropMapping(clz);
-                structuredNamespaces.put(ns, type);
-                structuredMappings.put(type, pm);
-            }
-        }
-
-        // define structured types
-        definedStructuredNamespaces = new HashMap<String, String>();
-        definedStructuredMappings = new HashMap<String, PropertiesDescription>();
-
-        // schema
-        schemaMap = new HashMap<String, XMPSchemaFactory>();
-        addNameSpace(XMPBasicSchema.class);
-        addNameSpace(DublinCoreSchema.class);
-        addNameSpace(PDFAExtensionSchema.class);
-        addNameSpace(XMPMediaManagementSchema.class);
-        addNameSpace(AdobePDFSchema.class);
-        addNameSpace(PDFAIdentificationSchema.class);
-        addNameSpace(XMPRightsManagementSchema.class);
-        addNameSpace(PhotoshopSchema.class);
-        addNameSpace(XMPBasicJobTicketSchema.class);
-        addNameSpace(ExifSchema.class);
-        addNameSpace(TiffSchema.class);
-        addNameSpace(XMPageTextSchema.class);
-    }
-
-    public void addToDefinedStructuredTypes(String typeName, String ns, PropertiesDescription pm)
-    {
-        definedStructuredNamespaces.put(ns, typeName);
-        definedStructuredMappings.put(typeName, pm);
-    }
-
-    public PropertiesDescription getDefinedDescriptionByNamespace(String namespace)
-    {
-        String dt = definedStructuredNamespaces.get(namespace);
-        return this.definedStructuredMappings.get(dt);
-    }
-
-    public AbstractStructuredType instanciateStructuredType(Types type, String propertyName)
-            throws BadFieldValueException
-    {
-        try
-        {
-            Class<? extends AbstractStructuredType> propertyTypeClass = type.getImplementingClass().asSubclass(
-                    AbstractStructuredType.class);
-            Constructor<? extends AbstractStructuredType> construct = propertyTypeClass
-                    .getConstructor(new Class<?>[] { XMPMetadata.class });
-            AbstractStructuredType tmp = construct.newInstance(metadata);
-            tmp.setPropertyName(propertyName);
-            return tmp;
-        }
-        catch (InvocationTargetException e)
-        {
-            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
-        }
-        catch (IllegalArgumentException e)
-        {
-            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
-        }
-        catch (InstantiationException e)
-        {
-            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
-        }
-        catch (IllegalAccessException e)
-        {
-            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
-        }
-        catch (SecurityException e)
-        {
-            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
-        }
-        catch (NoSuchMethodException e)
-        {
-            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
-        }
-    }
-
-    public AbstractStructuredType instanciateDefinedType(String propertyName, String namespace)
-    {
-        return new DefinedStructuredType(metadata, namespace, null, propertyName);
-    }
-
-    public AbstractSimpleProperty instanciateSimpleProperty(String nsuri, String prefix, String name, Object value,
-            Types type)
-    {
-        // constructor parameters
-        Object[] params = new Object[] { metadata, nsuri, prefix, name, value };
-        // type
-        Class<? extends AbstractSimpleProperty> clz =
-                type.getImplementingClass().asSubclass(AbstractSimpleProperty.class);
-        try
-        {
-            Constructor<? extends AbstractSimpleProperty> cons = clz.getConstructor(SIMPLEPROPERTYCONSTPARAMS);
-            return cons.newInstance(params);
-        }
-        catch (NoSuchMethodError e)
-        {
-            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
-        }
-        catch (IllegalArgumentException e)
-        {
-            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
-        }
-        catch (InstantiationException e)
-        {
-            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
-        }
-        catch (IllegalAccessException e)
-        {
-            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
-        }
-        catch (InvocationTargetException e)
-        {
-            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
-        }
-        catch (SecurityException e)
-        {
-            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
-        }
-        catch (NoSuchMethodException e)
-        {
-            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
-        }
-    }
-
-    public AbstractSimpleProperty instanciateSimpleField(Class<?> clz, String nsuri, String prefix,
-            String propertyName, Object value)
-    {
-        PropertiesDescription pm = initializePropMapping(clz);
-        PropertyType simpleType = pm.getPropertyType(propertyName);
-        Types type = simpleType.type();
-        return instanciateSimpleProperty(nsuri, prefix, propertyName, value, type);
-    }
-
-    /**
-     * 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 boolean isStructuredTypeNamespace(String namespace)
-    {
-        return structuredNamespaces.containsKey(namespace);
-    }
-
-    public boolean isDefinedTypeNamespace(String namespace)
-    {
-        return definedStructuredNamespaces.containsKey(namespace);
-    }
-
-    public boolean isDefinedType(String name)
-    {
-        return this.definedStructuredMappings.containsKey(name);
-    }
-
-    private void addNameSpace(Class<? extends XMPSchema> classSchem)
-    {
-        StructuredType st = classSchem.getAnnotation(StructuredType.class);
-        String ns = st.namespace();
-        schemaMap.put(ns, new XMPSchemaFactory(ns, classSchem, initializePropMapping(classSchem)));
-    }
-
-    public void addNewNameSpace(String ns, String prefered)
-    {
-        PropertiesDescription mapping = new PropertiesDescription();
-        schemaMap.put(ns, new XMPSchemaFactory(ns, XMPSchema.class, mapping));
-    }
-
-    public PropertiesDescription 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
-     * 
-     * @param metadata
-     *            Metadata to link the new schema
-     * @param namespace
-     *            The namespace URI
-     * @param prefix The namespace prefix
-     * @return Schema representation
-     * @throws XmpSchemaException
-     *             When Instancing specified Object Schema failed
-     */
-    public XMPSchema getAssociatedSchemaObject(XMPMetadata metadata, String namespace, String prefix)
-            throws XmpSchemaException
-    {
-        if (schemaMap.containsKey(namespace))
-        {
-            XMPSchemaFactory factory = schemaMap.get(namespace);
-            return factory.createXMPSchema(metadata, prefix);
-        }
-        else
-        {
-            XMPSchemaFactory factory = getSchemaFactory(namespace);
-            return factory != null ? factory.createXMPSchema(metadata, prefix) : null;
-        }
-    }
-
-    public XMPSchemaFactory getSchemaFactory(String namespace)
-    {
-        return schemaMap.get(namespace);
-    }
-
-    /**
-     * Say if a specific namespace is known
-     * 
-     * @param namespace
-     *            The namespace URI checked
-     * @return True if namespace URI is known
-     */
-    public boolean isDefinedSchema(String namespace)
-    {
-        return schemaMap.containsKey(namespace);
-    }
-
-    public boolean isDefinedNamespace(String namespace)
-    {
-        return isDefinedSchema(namespace) || isStructuredTypeNamespace(namespace) || isDefinedTypeNamespace(namespace);
-    }
-
-    /**
-     * Give type of specified property in specified schema (given by its namespaceURI)
-     * 
-     * @param name
-     *            the property Qualified Name
-     * @return Property type declared for namespace specified, null if unknown
-     * @throws org.apache.xmpbox.type.BadFieldValueException if the name was not found.
-     */
-    public PropertyType getSpecifiedPropertyType(QName name) throws BadFieldValueException
-    {
-        XMPSchemaFactory factory = getSchemaFactory(name.getNamespaceURI());
-        if (factory != null)
-        {
-            // found in schema
-            return factory.getPropertyType(name.getLocalPart());
-        }
-        else
-        {
-            // try in structured
-            Types st = structuredNamespaces.get(name.getNamespaceURI());
-            if (st != null)
-            {
-                return createPropertyType(st, Cardinality.Simple);
-            }
-            else
-            {
-                // try in defined
-                String dt = definedStructuredNamespaces.get(name.getNamespaceURI());
-                if (dt == null)
-                {
-                    // not found
-                    throw new BadFieldValueException("No descriptor found for " + name);
-                }
-                else
-                {
-                    return createPropertyType(Types.DefinedType, Cardinality.Simple);
-                }
-            }
-        }
-    }
-
-    public PropertiesDescription initializePropMapping(Class<?> classSchem)
-    {
-        PropertiesDescription propMap = new PropertiesDescription();
-        Field[] fields = classSchem.getFields();
-        String propName = null;
-        for (Field field : fields)
-        {
-            if (field.isAnnotationPresent(PropertyType.class))
-            {
-                try
-                {
-                    propName = (String) field.get(propName);
-                }
-                catch (Exception e)
-                {
-                    throw new IllegalArgumentException(
-                            "couldn't read one type declaration, please check accessibility and declaration of fields annoted in "
-                                    + classSchem.getName(), e);
-                }
-                PropertyType propType = field.getAnnotation(PropertyType.class);
-                propMap.addNewProperty(propName, propType);
-            }
-        }
-        return propMap;
-    }
-
-    public BooleanType createBoolean(String namespaceURI, String prefix, String propertyName, boolean value)
-    {
-        return new BooleanType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public DateType createDate(String namespaceURI, String prefix, String propertyName, Calendar value)
-    {
-        return new DateType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public IntegerType createInteger(String namespaceURI, String prefix, String propertyName, int value)
-    {
-        return new IntegerType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public RealType createReal(String namespaceURI, String prefix, String propertyName, float value)
-    {
-        return new RealType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public TextType createText(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new TextType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public ProperNameType createProperName(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new ProperNameType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public URIType createURI(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new URIType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public URLType createURL(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new URLType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public RenditionClassType createRenditionClass(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new RenditionClassType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public PartType createPart(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new PartType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public MIMEType createMIMEType(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new MIMEType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public LocaleType createLocale(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new LocaleType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public GUIDType createGUID(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new GUIDType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public ChoiceType createChoice(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new ChoiceType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public AgentNameType createAgentName(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new AgentNameType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public XPathType createXPath(String namespaceURI, String prefix, String propertyName, String value)
-    {
-        return new XPathType(metadata, namespaceURI, prefix, propertyName, value);
-    }
-
-    public ArrayProperty createArrayProperty(String namespace, String prefix, String propertyName, Cardinality type)
-    {
-        return new ArrayProperty(metadata, namespace, prefix, propertyName, type);
-    }
-
-    public static PropertyType createPropertyType(final Types type, final Cardinality card)
-    {
-        return new PropertyType()
-        {
-
-            @Override
-            public Class<? extends Annotation> annotationType()
-            {
-                return null;
-            }
-
-            @Override
-            public Types type()
-            {
-                return type;
-            }
-
-            @Override
-            public Cardinality card()
-            {
-                return card;
-            }
-        };
-    }
-}
+/*****************************************************************************
+ * 
+ * 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.xmpbox.type;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Calendar;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.xmpbox.XMPMetadata;
+import org.apache.xmpbox.schema.AdobePDFSchema;
+import org.apache.xmpbox.schema.DublinCoreSchema;
+import org.apache.xmpbox.schema.ExifSchema;
+import org.apache.xmpbox.schema.PDFAExtensionSchema;
+import org.apache.xmpbox.schema.PDFAIdentificationSchema;
+import org.apache.xmpbox.schema.PhotoshopSchema;
+import org.apache.xmpbox.schema.TiffSchema;
+import org.apache.xmpbox.schema.XMPBasicJobTicketSchema;
+import org.apache.xmpbox.schema.XMPBasicSchema;
+import org.apache.xmpbox.schema.XMPMediaManagementSchema;
+import org.apache.xmpbox.schema.XMPRightsManagementSchema;
+import org.apache.xmpbox.schema.XMPSchema;
+import org.apache.xmpbox.schema.XMPSchemaFactory;
+import org.apache.xmpbox.schema.XMPageTextSchema;
+import org.apache.xmpbox.schema.XmpSchemaException;
+
+public final class TypeMapping
+{
+
+    private Map<Types, PropertiesDescription> structuredMappings;
+
+    // ns -> type
+    private Map<String, Types> structuredNamespaces;
+
+    // ns -> type
+    private Map<String, String> definedStructuredNamespaces;
+
+    private Map<String, PropertiesDescription> definedStructuredMappings;
+
+    private final XMPMetadata metadata;
+
+    private Map<String, XMPSchemaFactory> schemaMap;
+
+    public TypeMapping(XMPMetadata metadata)
+    {
+        this.metadata = metadata;
+        initialize();
+    }
+
+    private static final Class<?>[] SIMPLEPROPERTYCONSTPARAMS = new Class<?>[] { XMPMetadata.class, String.class,
+            String.class, String.class, Object.class };
+
+    private void initialize()
+    {
+        // structured types
+        structuredMappings = new EnumMap<Types, PropertiesDescription>(Types.class);
+        structuredNamespaces = new HashMap<String, Types>();
+        for (Types type : Types.values())
+        {
+            if (type.isStructured())
+            {
+                Class<? extends AbstractStructuredType> clz = type.getImplementingClass().asSubclass(
+                        AbstractStructuredType.class);
+                StructuredType st = clz.getAnnotation(StructuredType.class);
+                String ns = st.namespace();
+                PropertiesDescription pm = initializePropMapping(clz);
+                structuredNamespaces.put(ns, type);
+                structuredMappings.put(type, pm);
+            }
+        }
+
+        // define structured types
+        definedStructuredNamespaces = new HashMap<String, String>();
+        definedStructuredMappings = new HashMap<String, PropertiesDescription>();
+
+        // schema
+        schemaMap = new HashMap<String, XMPSchemaFactory>();
+        addNameSpace(XMPBasicSchema.class);
+        addNameSpace(DublinCoreSchema.class);
+        addNameSpace(PDFAExtensionSchema.class);
+        addNameSpace(XMPMediaManagementSchema.class);
+        addNameSpace(AdobePDFSchema.class);
+        addNameSpace(PDFAIdentificationSchema.class);
+        addNameSpace(XMPRightsManagementSchema.class);
+        addNameSpace(PhotoshopSchema.class);
+        addNameSpace(XMPBasicJobTicketSchema.class);
+        addNameSpace(ExifSchema.class);
+        addNameSpace(TiffSchema.class);
+        addNameSpace(XMPageTextSchema.class);
+    }
+
+    public void addToDefinedStructuredTypes(String typeName, String ns, PropertiesDescription pm)
+    {
+        definedStructuredNamespaces.put(ns, typeName);
+        definedStructuredMappings.put(typeName, pm);
+    }
+
+    public PropertiesDescription getDefinedDescriptionByNamespace(String namespace)
+    {
+        String dt = definedStructuredNamespaces.get(namespace);
+        return this.definedStructuredMappings.get(dt);
+    }
+
+    public AbstractStructuredType instanciateStructuredType(Types type, String propertyName)
+            throws BadFieldValueException
+    {
+        try
+        {
+            Class<? extends AbstractStructuredType> propertyTypeClass = type.getImplementingClass().asSubclass(
+                    AbstractStructuredType.class);
+            Constructor<? extends AbstractStructuredType> construct = propertyTypeClass
+                    .getConstructor(XMPMetadata.class);
+            AbstractStructuredType tmp = construct.newInstance(metadata);
+            tmp.setPropertyName(propertyName);
+            return tmp;
+        }
+        catch (InvocationTargetException e)
+        {
+            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
+        }
+        catch (IllegalArgumentException e)
+        {
+            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
+        }
+        catch (InstantiationException e)
+        {
+            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
+        }
+        catch (SecurityException e)
+        {
+            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
+        }
+        catch (NoSuchMethodException e)
+        {
+            throw new BadFieldValueException("Failed to instanciate structured type : " + type, e);
+        }
+    }
+
+    public AbstractStructuredType instanciateDefinedType(String propertyName, String namespace)
+    {
+        return new DefinedStructuredType(metadata, namespace, null, propertyName);
+    }
+
+    public AbstractSimpleProperty instanciateSimpleProperty(String nsuri, String prefix, String name, Object value,
+            Types type)
+    {
+        // constructor parameters
+        Object[] params = new Object[] { metadata, nsuri, prefix, name, value };
+        // type
+        Class<? extends AbstractSimpleProperty> clz =
+                type.getImplementingClass().asSubclass(AbstractSimpleProperty.class);
+        try
+        {
+            Constructor<? extends AbstractSimpleProperty> cons = clz.getConstructor(SIMPLEPROPERTYCONSTPARAMS);
+            return cons.newInstance(params);
+        }
+        catch (NoSuchMethodError e)
+        {
+            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
+        }
+        catch (IllegalArgumentException e)
+        {
+            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
+        }
+        catch (InstantiationException e)
+        {
+            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
+        }
+        catch (InvocationTargetException e)
+        {
+            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
+        }
+        catch (SecurityException e)
+        {
+            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
+        }
+        catch (NoSuchMethodException e)
+        {
+            throw new IllegalArgumentException("Failed to instanciate " + clz.getSimpleName() + " property with value " + value, e);
+        }
+    }
+
+    public AbstractSimpleProperty instanciateSimpleField(Class<?> clz, String nsuri, String prefix,
+            String propertyName, Object value)
+    {
+        PropertiesDescription pm = initializePropMapping(clz);
+        PropertyType simpleType = pm.getPropertyType(propertyName);
+        Types type = simpleType.type();
+        return instanciateSimpleProperty(nsuri, prefix, propertyName, value, type);
+    }
+
+    /**
+     * 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 boolean isStructuredTypeNamespace(String namespace)
+    {
+        return structuredNamespaces.containsKey(namespace);
+    }
+
+    public boolean isDefinedTypeNamespace(String namespace)
+    {
+        return definedStructuredNamespaces.containsKey(namespace);
+    }
+
+    public boolean isDefinedType(String name)
+    {
+        return this.definedStructuredMappings.containsKey(name);
+    }
+
+    private void addNameSpace(Class<? extends XMPSchema> classSchem)
+    {
+        StructuredType st = classSchem.getAnnotation(StructuredType.class);
+        String ns = st.namespace();
+        schemaMap.put(ns, new XMPSchemaFactory(ns, classSchem, initializePropMapping(classSchem)));
+    }
+
+    public void addNewNameSpace(String ns, String prefered)
+    {
+        PropertiesDescription mapping = new PropertiesDescription();
+        schemaMap.put(ns, new XMPSchemaFactory(ns, XMPSchema.class, mapping));
+    }
+
+    public PropertiesDescription 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
+     * 
+     * @param metadata
+     *            Metadata to link the new schema
+     * @param namespace
+     *            The namespace URI
+     * @param prefix The namespace prefix
+     * @return Schema representation
+     * @throws XmpSchemaException
+     *             When Instancing specified Object Schema failed
+     */
+    public XMPSchema getAssociatedSchemaObject(XMPMetadata metadata, String namespace, String prefix)
+            throws XmpSchemaException
+    {
+        if (schemaMap.containsKey(namespace))
+        {
+            XMPSchemaFactory factory = schemaMap.get(namespace);
+            return factory.createXMPSchema(metadata, prefix);
+        }
+        else
+        {
+            XMPSchemaFactory factory = getSchemaFactory(namespace);
+            return factory != null ? factory.createXMPSchema(metadata, prefix) : null;
+        }
+    }
+
+    public XMPSchemaFactory getSchemaFactory(String namespace)
+    {
+        return schemaMap.get(namespace);
+    }
+
+    /**
+     * Say if a specific namespace is known
+     * 
+     * @param namespace
+     *            The namespace URI checked
+     * @return True if namespace URI is known
+     */
+    public boolean isDefinedSchema(String namespace)
+    {
+        return schemaMap.containsKey(namespace);
+    }
+
+    public boolean isDefinedNamespace(String namespace)
+    {
+        return isDefinedSchema(namespace) || isStructuredTypeNamespace(namespace) || isDefinedTypeNamespace(namespace);
+    }
+
+    /**
+     * Give type of specified property in specified schema (given by its namespaceURI)
+     * 
+     * @param name
+     *            the property Qualified Name
+     * @return Property type declared for namespace specified, null if unknown
+     * @throws org.apache.xmpbox.type.BadFieldValueException if the name was not found.
+     */
+    public PropertyType getSpecifiedPropertyType(QName name) throws BadFieldValueException
+    {
+        XMPSchemaFactory factory = getSchemaFactory(name.getNamespaceURI());
+        if (factory != null)
+        {
+            // found in schema
+            return factory.getPropertyType(name.getLocalPart());
+        }
+        else
+        {
+            // try in structured
+            Types st = structuredNamespaces.get(name.getNamespaceURI());
+            if (st != null)
+            {
+                return createPropertyType(st, Cardinality.Simple);
+            }
+            else
+            {
+                // try in defined
+                String dt = definedStructuredNamespaces.get(name.getNamespaceURI());
+                if (dt == null)
+                {
+                    // not found
+                    throw new BadFieldValueException("No descriptor found for " + name);
+                }
+                else
+                {
+                    return createPropertyType(Types.DefinedType, Cardinality.Simple);
+                }
+            }
+        }
+    }
+
+    public PropertiesDescription initializePropMapping(Class<?> classSchem)
+    {
+        PropertiesDescription propMap = new PropertiesDescription();
+        Field[] fields = classSchem.getFields();
+        String propName = null;
+        for (Field field : fields)
+        {
+            if (field.isAnnotationPresent(PropertyType.class))
+            {
+                try
+                {
+                    propName = (String) field.get(propName);
+                }
+                catch (Exception e)
+                {
+                    throw new IllegalArgumentException(
+                            "couldn't read one type declaration, please check accessibility and declaration of fields annoted in "
+                                    + classSchem.getName(), e);
+                }
+                PropertyType propType = field.getAnnotation(PropertyType.class);
+                propMap.addNewProperty(propName, propType);
+            }
+        }
+        return propMap;
+    }
+
+    public BooleanType createBoolean(String namespaceURI, String prefix, String propertyName, boolean value)
+    {
+        return new BooleanType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public DateType createDate(String namespaceURI, String prefix, String propertyName, Calendar value)
+    {
+        return new DateType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public IntegerType createInteger(String namespaceURI, String prefix, String propertyName, int value)
+    {
+        return new IntegerType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public RealType createReal(String namespaceURI, String prefix, String propertyName, float value)
+    {
+        return new RealType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public TextType createText(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new TextType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public ProperNameType createProperName(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new ProperNameType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public URIType createURI(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new URIType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public URLType createURL(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new URLType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public RenditionClassType createRenditionClass(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new RenditionClassType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public PartType createPart(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new PartType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public MIMEType createMIMEType(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new MIMEType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public LocaleType createLocale(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new LocaleType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public GUIDType createGUID(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new GUIDType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public ChoiceType createChoice(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new ChoiceType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public AgentNameType createAgentName(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new AgentNameType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public XPathType createXPath(String namespaceURI, String prefix, String propertyName, String value)
+    {
+        return new XPathType(metadata, namespaceURI, prefix, propertyName, value);
+    }
+
+    public ArrayProperty createArrayProperty(String namespace, String prefix, String propertyName, Cardinality type)
+    {
+        return new ArrayProperty(metadata, namespace, prefix, propertyName, type);
+    }
+
+    public static PropertyType createPropertyType(final Types type, final Cardinality card)
+    {
+        return new PropertyType()
+        {
+
+            @Override
+            public Class<? extends Annotation> annotationType()
+            {
+                return null;
+            }
+
+            @Override
+            public Types type()
+            {
+                return type;
+            }
+
+            @Override
+            public Cardinality card()
+            {
+                return card;
+            }
+        };
+    }
+}

Modified: pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java?rev=1760962&r1=1760961&r2=1760962&view=diff
==============================================================================
--- pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java (original)
+++ pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/schema/AbstractSchemaTester.java Thu Sep 15 16:54:35 2016
@@ -82,16 +82,16 @@ public abstract class AbstractSchemaTest
         if (cardinality == Cardinality.Simple)
         {
             String getter = calculateSimpleGetter(fieldName);
-            Method get = getSchemaClass().getMethod(getter, new Class[0]);
-            Object result = get.invoke(schema, new Object[0]);
+            Method get = getSchemaClass().getMethod(getter);
+            Object result = get.invoke(schema);
             Assert.assertNull(result);
         }
         else
         {
             // arrays
             String getter = calculateArrayGetter(fieldName);
-            Method get = getSchemaClass().getMethod(getter, new Class[0]);
-            Object result = get.invoke(schema, new Object[0]);
+            Method get = getSchemaClass().getMethod(getter);
+            Object result = get.invoke(schema);
             Assert.assertNull(result);
         }
 
@@ -218,15 +218,15 @@ public abstract class AbstractSchemaTest
         Object value = getJavaValue(type);
         AbstractSimpleProperty asp = typeMapping.instanciateSimpleProperty(schema.getNamespace(), schema
                 .getPrefix(), fieldName, value, type);
-        Method set = getSchemaClass().getMethod(setter, new Class<?>[] { type.getImplementingClass() });
-        set.invoke(schema, new Object[] { asp });
+        Method set = getSchemaClass().getMethod(setter, type.getImplementingClass());
+        set.invoke(schema, asp);
         // check property set
         AbstractSimpleProperty stored = (AbstractSimpleProperty) schema.getProperty(fieldName);
         Assert.assertEquals(value, stored.getValue());
         // check getter
         String getter = calculateSimpleGetter(fieldName) + "Property";
-        Method get = getSchemaClass().getMethod(getter, new Class[0]);
-        Object result = get.invoke(schema, new Object[0]);
+        Method get = getSchemaClass().getMethod(getter);
+        Object result = get.invoke(schema);
         Assert.assertTrue(type.getImplementingClass().isAssignableFrom(result.getClass()));
         Assert.assertEquals(asp, result);
     }
@@ -259,23 +259,23 @@ public abstract class AbstractSchemaTest
         // TypeDescription<AbstractSimpleProperty> td =
         // typeMapping.getSimpleDescription(type);
         Object value1 = getJavaValue(type);
-        Method set = getSchemaClass().getMethod(setter, new Class<?>[] { getJavaType(type) });
-        set.invoke(schema, new Object[] { value1 });
+        Method set = getSchemaClass().getMethod(setter, getJavaType(type));
+        set.invoke(schema, value1);
         // retrieve complex property
         String getter = calculateArrayGetter(fieldName) + "Property";
-        Method getcp = getSchemaClass().getMethod(getter, new Class[0]);
-        Object ocp = getcp.invoke(schema, new Object[0]);
+        Method getcp = getSchemaClass().getMethod(getter);
+        Object ocp = getcp.invoke(schema);
         Assert.assertTrue(ocp instanceof ArrayProperty);
         ArrayProperty cp = (ArrayProperty) ocp;
         // check size is ok (1)
         Assert.assertEquals(1, cp.getContainer().getAllProperties().size());
         // add a new one
         Object value2 = getJavaValue(type);
-        set.invoke(schema, new Object[] { value2 });
+        set.invoke(schema, value2);
         Assert.assertEquals(2, cp.getContainer().getAllProperties().size());
         // remove the first
         String remover = "remove" + calculateFieldNameForMethod(fieldName);
-        Method remove = getSchemaClass().getMethod(remover, new Class<?>[] { getJavaType(type) });
+        Method remove = getSchemaClass().getMethod(remover, getJavaType(type));
         remove.invoke(schema, value1);
         Assert.assertEquals(1, cp.getContainer().getAllProperties().size());
 

Modified: pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java?rev=1760962&r1=1760961&r2=1760962&view=diff
==============================================================================
--- pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java (original)
+++ pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/AbstractStructuredTypeTester.java Thu Sep 15 16:54:35 2016
@@ -69,8 +69,8 @@ public abstract class AbstractStructured
         // default method
         Assert.assertNull(structured.getProperty(fieldName));
         // accessor
-        Method get = clz.getMethod(calculateSimpleGetter(fieldName), new Class[0]);
-        Object result = get.invoke(structured, new Object[0]);
+        Method get = clz.getMethod(calculateSimpleGetter(fieldName));
+        Object result = get.invoke(structured);
         Assert.assertNull(result);
 
     }
@@ -161,13 +161,13 @@ public abstract class AbstractStructured
         AbstractStructuredType structured = getStructured();
         String setter = calculateSimpleSetter(fieldName);
         Object value = getJavaValue(type);
-        Method set = clz.getMethod(setter, new Class<?>[] { getJavaType(type) });
-        set.invoke(structured, new Object[] { value });
+        Method set = clz.getMethod(setter, getJavaType(type));
+        set.invoke(structured, value);
         // check property set
         Assert.assertEquals(value, ((AbstractSimpleProperty) structured.getProperty(fieldName)).getValue());
         // check getter
-        Method get = clz.getMethod(calculateSimpleGetter(fieldName), new Class[0]);
-        Object result = get.invoke(structured, new Object[0]);
+        Method get = clz.getMethod(calculateSimpleGetter(fieldName));
+        Object result = get.invoke(structured);
         Assert.assertTrue(getJavaType(type).isAssignableFrom(result.getClass()));
         Assert.assertEquals(value, result);
     }

Modified: pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/TestDerivedType.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/TestDerivedType.java?rev=1760962&r1=1760961&r2=1760962&view=diff
==============================================================================
--- pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/TestDerivedType.java (original)
+++ pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/type/TestDerivedType.java Thu Sep 15 16:54:35 2016
@@ -1,106 +1,106 @@
-/*****************************************************************************
- * 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.xmpbox.type;
-
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.xmpbox.XMPMetadata;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-@RunWith(Parameterized.class)
-public class TestDerivedType
-{
-
-    public static final String PREFIX = "myprefix";
-
-    public static final String NAME = "myname";
-
-    public static final String VALUE = "myvalue";
-
-    protected XMPMetadata xmp;
-
-    protected String type = null;
-
-    protected Class<? extends TextType> clz = null;
-
-    protected Constructor<? extends TextType> constructor = null;
-
-    public TestDerivedType(Class<? extends TextType> clz, String type)
-    {
-        super();
-        this.clz = clz;
-        this.type = type;
-    }
-
-    @Parameters
-    public static Collection<Object[]> initializeParameters() throws Exception
-    {
-        Collection<Object[]> result = new ArrayList<Object[]>();
-
-        result.add(new Object[] { AgentNameType.class, "AgentName" });
-        result.add(new Object[] { ChoiceType.class, "Choice" });
-        result.add(new Object[] { GUIDType.class, "GUID" });
-        result.add(new Object[] { LocaleType.class, "Locale" });
-        result.add(new Object[] { MIMEType.class, "MIME" });
-        result.add(new Object[] { PartType.class, "Part" });
-        result.add(new Object[] { ProperNameType.class, "ProperName" });
-        result.add(new Object[] { RenditionClassType.class, "RenditionClass" });
-        result.add(new Object[] { URIType.class, "URI" });
-        result.add(new Object[] { URLType.class, "URL" });
-        result.add(new Object[] { XPathType.class, "XPath" });
-
-        return result;
-
-    }
-
-    @Before
-    public void before() throws Exception
-    {
-        xmp = XMPMetadata.createXMPMetadata();
-        constructor = clz.getConstructor(new Class[] { XMPMetadata.class, String.class, String.class, String.class,
-                Object.class });
-    }
-
-    protected TextType instanciate(XMPMetadata metadata, String namespaceURI, String prefix, String propertyName,
-            Object value) throws Exception
-    {
-        Object[] initargs = new Object[] { metadata, namespaceURI, prefix, propertyName, value };
-        return constructor.newInstance(initargs);
-    }
-
-    @Test
-    public void test1() throws Exception
-    {
-        TextType element = instanciate(xmp, null, PREFIX, NAME, VALUE);
-        Assert.assertNull(element.getNamespace());
-        Assert.assertTrue(element.getValue() instanceof String);
-        Assert.assertEquals(VALUE, element.getValue());
-
-    }
-
-}
+/*****************************************************************************
+ * 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.xmpbox.type;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.xmpbox.XMPMetadata;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class TestDerivedType
+{
+
+    public static final String PREFIX = "myprefix";
+
+    public static final String NAME = "myname";
+
+    public static final String VALUE = "myvalue";
+
+    protected XMPMetadata xmp;
+
+    protected String type = null;
+
+    protected Class<? extends TextType> clz = null;
+
+    protected Constructor<? extends TextType> constructor = null;
+
+    public TestDerivedType(Class<? extends TextType> clz, String type)
+    {
+        super();
+        this.clz = clz;
+        this.type = type;
+    }
+
+    @Parameters
+    public static Collection<Object[]> initializeParameters() throws Exception
+    {
+        Collection<Object[]> result = new ArrayList<Object[]>();
+
+        result.add(new Object[] { AgentNameType.class, "AgentName" });
+        result.add(new Object[] { ChoiceType.class, "Choice" });
+        result.add(new Object[] { GUIDType.class, "GUID" });
+        result.add(new Object[] { LocaleType.class, "Locale" });
+        result.add(new Object[] { MIMEType.class, "MIME" });
+        result.add(new Object[] { PartType.class, "Part" });
+        result.add(new Object[] { ProperNameType.class, "ProperName" });
+        result.add(new Object[] { RenditionClassType.class, "RenditionClass" });
+        result.add(new Object[] { URIType.class, "URI" });
+        result.add(new Object[] { URLType.class, "URL" });
+        result.add(new Object[] { XPathType.class, "XPath" });
+
+        return result;
+
+    }
+
+    @Before
+    public void before() throws Exception
+    {
+        xmp = XMPMetadata.createXMPMetadata();
+        constructor = clz.getConstructor(XMPMetadata.class, String.class, String.class, String.class,
+                Object.class);
+    }
+
+    protected TextType instanciate(XMPMetadata metadata, String namespaceURI, String prefix, String propertyName,
+            Object value) throws Exception
+    {
+        Object[] initargs = new Object[] { metadata, namespaceURI, prefix, propertyName, value };
+        return constructor.newInstance(initargs);
+    }
+
+    @Test
+    public void test1() throws Exception
+    {
+        TextType element = instanciate(xmp, null, PREFIX, NAME, VALUE);
+        Assert.assertNull(element.getNamespace());
+        Assert.assertTrue(element.getValue() instanceof String);
+        Assert.assertEquals(VALUE, element.getValue());
+
+    }
+
+}



Mime
View raw message