db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1464334 - in /db/torque/torque4/trunk/torque-generator/src/main: java/org/apache/torque/generator/configuration/ java/org/apache/torque/generator/configuration/source/ java/org/apache/torque/generator/control/ java/org/apache/torque/genera...
Date Thu, 04 Apr 2013 07:44:53 GMT
Author: tfischer
Date: Thu Apr  4 07:44:52 2013
New Revision: 1464334

URL: http://svn.apache.org/r1464334
Log:
TORQUE-273 implement loading the model from the source graph

Modified:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceSaxHandler.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerHelper.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/NoSuchPropertyException.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyAccess.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotReadableException.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotWriteableException.java
    db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
Thu Apr  4 07:44:52 2013
@@ -85,6 +85,13 @@ public class UnitConfiguration
     private String defaultOutputEncoding = null;
 
     /**
+     * The class loader to use by the generator when accessing the templates
+     * or classes defined within the templates.
+     * If null, the class loader of the torque generator classes is used.
+     */
+    private ClassLoader classLoader;
+
+    /**
      * Returns the configuration of the outlets in this generation unit.
      *
      * @return the outlet configuration, not null.
@@ -476,6 +483,31 @@ public class UnitConfiguration
     }
 
     /**
+     * Returns the class loader to use by the generator when accessing
+     * the templates or classes defined within the templates.
+     *
+     * @return the class loader for the templates, or null if the standard
+     *         class loader of the torque generator classes is used.
+     */
+    public ClassLoader getClassLoader()
+    {
+        return classLoader;
+    }
+
+    /**
+     * Sets the class loader to use by the generator when accessing
+     * the templates or classes defined within the templates.
+     *
+     * @param classLoader the class loader for the templates,
+     *        or null if the standard class loader
+     *        of the torque generator classes should be used.
+     */
+    public void setClassLoader(ClassLoader classLoader)
+    {
+        this.classLoader = classLoader;
+    }
+
+    /**
      * Checks whether the unit configuration is fully initialized.
      *
      * @return true if the unit configuration is fully initialized,

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java
Thu Apr  4 07:44:52 2013
@@ -95,6 +95,7 @@ class UnitConfigurationReader
                 unitDescriptor.getProjectPaths().getWorkDirectory());
         unitConfiguration.setOverrideSourceProvider(
                 unitDescriptor.getOverrideSourceProvider());
+        unitConfiguration.setClassLoader(unitDescriptor.getClassLoader());
 
         ConfigurationProvider configurationProvider
             = createConfigurationProvider(unitDescriptor);

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java
Thu Apr  4 07:44:52 2013
@@ -40,6 +40,9 @@ public final class SourceConfigurationTa
     /** Attribute name for the "skipDecider" attribute. */
     public static final String SKIP_DECIDER_ARRTIBUTE = "skipDecider";
 
+    /** Attribute name for the "modelRootClass" attribute. */
+    public static final String MODEL_ROOT_CLASS_ATTRIBUTE = "modelRootClass";
+
     /** Attribute name for the "format" attribute. */
     public static final String FORMAT_ATTRIBUTE = "format";
 

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceSaxHandler.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceSaxHandler.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceSaxHandler.java
Thu Apr  4 07:44:52 2013
@@ -20,6 +20,7 @@ package org.apache.torque.generator.conf
  */
 
 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.ELEMENTS_ATTRIBUTE;
+import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.MODEL_ROOT_CLASS_ATTRIBUTE;
 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.SKIP_DECIDER_ARRTIBUTE;
 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.SOURCE_TAG;
 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.TRANSFORMER_TAG;
@@ -53,7 +54,10 @@ public abstract class SourceSaxHandler e
     /** The known configuration handlers. */
     private ConfigurationHandlers configurationHandlers;
 
-    /** The source process configuration. */
+    /**
+     * How a source should be processed between obtaining the original source
+     * and feeding it to the outlets.
+     */
     private SourceProcessConfiguration sourceProcessConfiguration;
 
     /**
@@ -134,6 +138,9 @@ public abstract class SourceSaxHandler e
                 sourceProcessConfiguration.setSkipDecider(
                         attributes.getValue(SKIP_DECIDER_ARRTIBUTE),
                         unitDescriptor);
+                sourceProcessConfiguration.setModelRootClass(
+                        attributes.getValue(MODEL_ROOT_CLASS_ATTRIBUTE),
+                        unitDescriptor);
             }
             catch (ConfigurationException e)
             {

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
Thu Apr  4 07:44:52 2013
@@ -24,8 +24,11 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import org.apache.commons.logging.Log;
@@ -53,6 +56,7 @@ import org.apache.torque.generator.sourc
 import org.apache.torque.generator.source.SourceProcessConfiguration;
 import org.apache.torque.generator.source.SourceProvider;
 import org.apache.torque.generator.source.SourceTransformerDefinition;
+import org.apache.torque.generator.source.model.PropertyAccess;
 import org.apache.torque.generator.source.skipDecider.SkipDecider;
 import org.apache.torque.generator.source.transform.SourceTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
@@ -66,6 +70,12 @@ public class Controller
     private static Log log = LogFactory.getLog(Controller.class);
 
     /**
+     * The field name in the model which is filled if tthe sttribute name
+     * <code>null</code> appears in the source graph.
+     */
+    public static final String NULL_ATTRIBUTE_FIELD_NAME = "value";
+
+    /**
      * All known ExistingTargetStrategies.
      * TODO: move to a better place.
      */
@@ -257,6 +267,8 @@ public class Controller
         controllerState.setSourceFile(source.getSourceFile());
         SourceProcessConfiguration sourceProcessConfiguration
                 = output.getSourceProcessConfiguration();
+        Object modelRoot = sourceProcessConfiguration.getModelRoot();
+        fillModelRoot(modelRoot, rootElement, unitConfiguration);
         rootElement = transformSource(
                 rootElement,
                 sourceProcessConfiguration.getTransformerDefinitions(),
@@ -286,6 +298,111 @@ public class Controller
     }
 
     /**
+     * Constructs the model from the source graph. This is done by recursively
+     * walking through the source graph and setting the fields corresponding
+     * to the names of the attributes resp. child elements.
+     *
+     * @param modelRoot the root object to fill, not null.
+     * @param rootSourceElement the root source element to traverse, not null.
+     * @param unitConfiguration the unit configuration, not null.
+     *
+     * @throws SourceException if filling the source graph fails, e.g. if
+     *         an attribute name or element name has no corresponding
+     *         field in a model element.
+     */
+    private void fillModelRoot(
+                Object modelRoot,
+                SourceElement rootSourceElement,
+                UnitConfiguration unitConfiguration)
+            throws SourceException
+    {
+        if (modelRoot == null) {
+            return;
+        }
+        fillModelElement(
+                modelRoot,
+                rootSourceElement,
+                unitConfiguration,
+                new HashMap<SourceElement, Object>());
+
+    }
+
+    /**
+     * Constructs a part of the model from a part of the source graph.
+     * This is done by recursively walking through the source graph
+     * and setting the fields corresponding to the names of the attributes
+     * resp. child elements.
+     *
+     * @param modelElement the model object to fill, not null.
+     * @param sourceElement the source element corresponding to the
+     *        model object, not null.
+     * @param unitConfiguration the unit configuration, not null.
+     * @param alreadyMapped a map of already mapped source elements,
+     *        mapped to the corresponding model elements.
+     *
+     * @throws SourceException if filling the source graph fails, e.g. if
+     *         an attribute name or element name has no corresponding
+     *         field in a model element.
+     */
+    private void fillModelElement(
+                Object modelElement,
+                SourceElement sourceElement,
+                UnitConfiguration unitConfiguration,
+                Map<SourceElement, Object> alreadyMapped)
+            throws SourceException
+    {
+        for (String attributeName : sourceElement.getAttributeNames())
+        {
+            if (attributeName == null)
+            {
+                attributeName = NULL_ATTRIBUTE_FIELD_NAME;
+            }
+            Object attributeValue = sourceElement.getAttribute(attributeName);
+            PropertyAccess propertyAccess = new PropertyAccess(
+                    modelElement,
+                    attributeName);
+            propertyAccess.setProperty(attributeValue);
+        }
+        for (SourceElement child : sourceElement.getChildren()) {
+            String propertyName = sourceElement.getName();
+            PropertyAccess propertyAccess = new PropertyAccess(
+                    modelElement,
+                    propertyName);
+            Object childModelElement = alreadyMapped.get(child);
+            if (childModelElement != null) {
+                propertyAccess.setProperty(childModelElement);
+                continue;
+            }
+            if (Collection.class.isAssignableFrom(
+                    propertyAccess.getPropertyType()))
+            {
+                childModelElement = ControllerHelper.getInstance(
+                        propertyAccess.getFirstGenericTypeArgument().getName(),
+                        unitConfiguration);
+            }
+            else if (propertyAccess.getPropertyType().isArray())
+            {
+                childModelElement = ControllerHelper.getInstance(
+                        propertyAccess.getPropertyType().getComponentType().getName(),
+                        unitConfiguration);
+            }
+            else
+            {
+                childModelElement = ControllerHelper.getInstance(
+                        propertyAccess.getPropertyType().getName(),
+                        unitConfiguration);
+            }
+            propertyAccess.setProperty(childModelElement);
+            alreadyMapped.put(child, childModelElement);
+            fillModelElement(
+                    childModelElement,
+                    child,
+                    unitConfiguration,
+                    alreadyMapped);
+        }
+    }
+
+    /**
      * Creates the output file name and sets it in the output.
      * The filename is calculated either by the filenameConfigurator in
      * <code>output</code> or is given explicitly (in the latter case

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerHelper.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerHelper.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerHelper.java
Thu Apr  4 07:44:52 2013
@@ -21,7 +21,9 @@ package org.apache.torque.generator.cont
 
 import java.io.File;
 
+import org.apache.torque.generator.configuration.ClassHelper;
 import org.apache.torque.generator.configuration.UnitConfiguration;
+import org.apache.torque.generator.source.SourceException;
 
 /**
  * Helper methods for the controller.
@@ -60,5 +62,55 @@ public final class ControllerHelper
         return outputFile;
     }
 
-
+    /**
+     * Creates an instance of a class.
+     *
+     * @param className the fully qualified name of the class to instantiate.
+     * @param unitDescriptor The description of the generation unit, not null.
+     *
+     * @throws SourceException if the class cannot be instantiated.
+     */
+    public static Object getInstance(
+                    String className,
+                    UnitConfiguration unitConfiguration)
+            throws SourceException
+    {
+        if (className == null)
+        {
+            return null;
+        }
+        Object result;
+        try
+        {
+            ClassLoader classLoader = unitConfiguration.getClassLoader();
+            if (classLoader == null)
+            {
+                classLoader = ClassHelper.class.getClassLoader();
+            }
+            Class<?> clazz = Class.forName(className, true, classLoader);
+            result = clazz.newInstance();
+        }
+        catch (ClassNotFoundException e)
+        {
+            throw new SourceException("The class "
+                         + className
+                         + " could not be found.",
+                    e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new SourceException("Instantiating "
+                        + className
+                        + " is not allowed",
+                    e);
+        }
+        catch (InstantiationException e)
+        {
+            throw new SourceException("The class "
+                        + className
+                        + " has no standard constructor.",
+                    e);
+        }
+        return result;
+    }
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java
Thu Apr  4 07:44:52 2013
@@ -30,7 +30,7 @@ import org.apache.torque.generator.confi
 import org.apache.torque.generator.source.skipDecider.SkipDecider;
 
 /**
- * Contains the configuration how a source should be processed between
+ * Contains the information how a source should be processed between
  * obtaining the original source and feeding it to the outlets.
  *
  * @version $Id$
@@ -49,6 +49,12 @@ public class SourceProcessConfiguration
     private SkipDecider skipDecider;
 
     /**
+     * The model class instance attached to the root of the source,
+     * or null if none exists.
+     */
+    private Object modelRoot;
+
+    /**
      * Sets the start element path.
      *
      * @param startElementsPath the path to the elements which are used
@@ -91,6 +97,33 @@ public class SourceProcessConfiguration
     }
 
     /**
+     * Sets and instantiates the model root class instance.
+     *
+     * @param modelRootClass the fully qualified name of a class
+     *        which contains the root class of the source model.
+     * @param unitDescriptor The description of the generation unit, not null.
+     *
+     * @throws SourceException if the class cannot be instantiated.
+     */
+    public void setModelRootClass(
+                String modelRootClass,
+                UnitDescriptor unitDescriptor)
+            throws ConfigurationException
+    {
+        if (modelRootClass != null)
+        {
+            this.modelRoot = ClassHelper.getInstance(
+                    modelRootClass,
+                    null,
+                    unitDescriptor);
+        }
+        else
+        {
+            this.modelRoot = null;
+        }
+    }
+
+    /**
      * Sets the transformer definitions.
      *
      * @param transformerDefinitions the transformer definitions, or null
@@ -144,4 +177,17 @@ public class SourceProcessConfiguration
     {
         return skipDecider;
     }
+
+    /**
+     * Returns the model root instance.
+     * This is the instance of the class equivalent to the root node of
+     * the source graph. The instance is not yet filled.
+     *
+     * @return the model root instance, or null if no model root class is
+     *         defined.
+     */
+    public Object getModelRoot()
+    {
+       return modelRoot;
+    }
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/NoSuchPropertyException.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/NoSuchPropertyException.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/NoSuchPropertyException.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/NoSuchPropertyException.java
Thu Apr  4 07:44:52 2013
@@ -21,8 +21,23 @@ package org.apache.torque.generator.sour
 
 import org.apache.torque.generator.source.SourceException;
 
+/**
+ * Indicates that an attempt was made to access a property which does not exist.
+ *
+ * @version $Id: $
+ */
 public class NoSuchPropertyException extends SourceException
 {
+    /** Serial Version UID. */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Constructor.
+     *
+     * @param target the object on which the property was unsuccessfully
+     *        accessed.
+     * @param name the name of the property which was unsuccessfully accessed.
+     */
     public NoSuchPropertyException(Object target, String name)
     {
         super("Neither public field nor public getter/setter"
@@ -32,6 +47,11 @@ public class NoSuchPropertyException ext
                 + target.getClass().getName());
     }
 
+    /**
+     * Constructor.
+     *
+     * @param message The exception message.
+     */
     protected NoSuchPropertyException(String message)
     {
         super(message);

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyAccess.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyAccess.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyAccess.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyAccess.java
Thu Apr  4 07:44:52 2013
@@ -45,21 +45,44 @@ import org.apache.torque.generator.sourc
  */
 public class PropertyAccess
 {
+    /** The object on which the property should be accessed, not null. */
     private Object target;
 
+    /** The name of the property to access, not null. */
     private String propertyName;
 
+    /**
+     * The public field corresponding to the property name,
+     * or null if no such field exists.
+     */
     private Field field;
 
+    /**
+     * The public write method corresponding to the property name,
+     * or null if a field with the property name exists
+     * or if no such write method exists.
+     */
     private Method writeMethod;
 
+    /**
+     * The public read method corresponding to the property name,
+     * or null if a field with the property name exists
+     * or if no such read method exists.
+     */
     private Method readMethod;
 
     /**
+     * Constructs a reflection access to a property of an object.
+     * The property is assumed to be a public field, or if no such field exists
+     * on the target object, by getters and setters using the java beans
+     * naming conventions.
+     * It is not an error to call this constructor on fields which do not exist.
+     *
+     * @param target the target object, not null.
+     * @param propertyName the name of the property, not null.
      *
-     * @param target
-     * @param propertyName
-     * @throws SourceException
+     * @throws SourceException if reflection access to fields or methods fails.
+     * @throws NullPointerException if target or propertyName are null.
      */
     public PropertyAccess(Object target, String propertyName)
             throws SourceException
@@ -77,7 +100,8 @@ public class PropertyAccess
         this.field = determinePublicField(target, propertyName);
         if (this.field == null)
         {
-            PropertyDescriptor propertyDescriptor = determinePropertyDescriptor(target, propertyName);
+            PropertyDescriptor propertyDescriptor
+                    = determinePropertyDescriptor(target, propertyName);
             if (propertyDescriptor != null)
             {
                 this.readMethod = propertyDescriptor.getReadMethod();
@@ -93,7 +117,7 @@ public class PropertyAccess
      * @param target the target object, not null.
      * @param name the name of the field, not null.
      * @return the field if a public field with the given name exists,
-     *         or null if no public filed with the given name exists.
+     *         or null if no public field with the given name exists.
      *
      * @throws SourceException if security settings prevent reading the field
      *         of the object.
@@ -125,6 +149,19 @@ public class PropertyAccess
         return null;
     }
 
+    /**
+     * Returns the property descriptor of the class of the object
+     * <code>target</code> with name <code>name</code>.
+     *
+     * @param target the target object, not null.
+     * @param name the name of the field, not null.
+     * @return the field if a public getter or setter corresponding to
+     *         the property name exists, or null if no such getter
+     *         and setter exists.
+     *
+     * @throws SourceException if security settings prevent reading the field
+     *         of the object.
+     */
     private static PropertyDescriptor determinePropertyDescriptor(
                 Object target,
                 String name)
@@ -150,6 +187,21 @@ public class PropertyAccess
         }
     }
 
+    /**
+     * Sets the property on the target object to a given value.
+     * If the property is an array and value is not an array, value is set
+     * as a member of the array.
+     * If the property is a collection and value is not a collection,
+     * value is added to the collection.
+     * In all other cases, the field is set to the value.
+     *
+     * @param value the value to set the property to.
+     *
+     * @throws SourceException if the property cannot be set.
+     *         Common reasons for such an exception are that the property
+     *         does not exist at all, or is not writeable, or value has the
+     *         wrong class.
+     */
     public void setProperty(Object value)
             throws SourceException
     {
@@ -164,7 +216,7 @@ public class PropertyAccess
                     && (value == null
                         || !Collection.class.isAssignableFrom(value.getClass())))
             {
-                setMemberinCollectionField(value);
+                setMemberinCollectionProperty(value);
             }
             else
             {
@@ -184,7 +236,7 @@ public class PropertyAccess
                     && (value == null
                         || !Collection.class.isAssignableFrom(value.getClass())))
             {
-                setMemberinCollectionField(value);
+                setMemberinCollectionProperty(value);
             }
             else
             {
@@ -199,7 +251,7 @@ public class PropertyAccess
                 && (value == null
                     || !Collection.class.isAssignableFrom(value.getClass())))
             {
-                setMemberinCollectionField(value);
+                setMemberinCollectionProperty(value);
                 return;
             }
             throw new PropertyNotWriteableException(target, propertyName);
@@ -210,6 +262,17 @@ public class PropertyAccess
         }
     }
 
+    /**
+     * Sets the property on the target object to a given value.
+     * Arrays and Lists are not treated specially.
+     *
+     * @param value the value to set the property to.
+     *
+     * @throws SourceException if the property cannot be set.
+     *         Common reasons for such an exception are that the property
+     *         does not exist at all, or is not writeable, or value has the
+     *         wrong class.
+     */
     public void setPropertyStrict(Object value)
             throws SourceException
     {
@@ -233,6 +296,16 @@ public class PropertyAccess
         }
     }
 
+    /**
+     * Sets the field on the target object to a given value.
+     * Arrays and Lists are not treated specially.
+     * This method should only be called if the member field is not null.
+     *
+     * @param value the value to set the property to.
+     *
+     * @throws SourceException if the property cannot be set.
+     *         A common reason is that value has the wrong class.
+     */
     private void setPropertyStrictUsingField(Object value)
             throws SourceException
     {
@@ -264,6 +337,17 @@ public class PropertyAccess
         }
     }
 
+    /**
+     * Sets the property on the target object to a given value using the setter
+     * method.
+     * Arrays and Lists are not treated specially.
+     * This method should only be called if the writeMethod field is not null.
+     *
+     * @param value the value to set the property to.
+     *
+     * @throws SourceException if the property cannot be set.
+     *         A common reason is that value has the wrong class.
+     */
     private void setPropertyStrictUsingSetter(Object value)
             throws SourceException
     {
@@ -297,6 +381,15 @@ public class PropertyAccess
         }
     }
 
+    /**
+     * Returns the value of the property.
+     *
+     * @return the value of the property.
+     *
+     * @throws SourceException if the property is not readable.
+     *         A common reason for this is that no public field and no getter
+     *         exists with the given name.
+     */
     public Object getProperty() throws SourceException {
         if (field != null) {
             return getPropertyUsingField();
@@ -307,6 +400,15 @@ public class PropertyAccess
         }
     }
 
+    /**
+     * Returns the value of the property by accessing the field of the target.
+     *
+     * @return the value of the property.
+     *
+     * @throws SourceException if the property is not readable.
+     *         A common reason for this is that no public field exists
+     *         with the given name.
+     */
     private Object getPropertyUsingField() throws SourceException
     {
         try
@@ -323,6 +425,16 @@ public class PropertyAccess
         }
     }
 
+    /**
+     * Returns the value of the property by accessing the getter method
+     * of the property.
+     *
+     * @return the value of the property.
+     *
+     * @throws SourceException if the property is not readable.
+     *         A common reason for this is that no public getter exists
+     *         with the corresponding name.
+     */
     private Object getPropertyUsingGetter() throws SourceException
     {
         try
@@ -366,9 +478,9 @@ public class PropertyAccess
     }
 
     /**
-     * Returns the class of the generic type property.
+     * Returns the generic type of the property.
      *
-     * @return the class of the generic type of the property,
+     * @return the generic type of the property,
      *         or null if the property does not exist.
      */
     public Type getPropertyGenericType()
@@ -388,6 +500,14 @@ public class PropertyAccess
         return null;
     }
 
+    /**
+     * Gets the class of the first generic argument of the property.
+     * E.g. if the property is a collection, this method will return
+     * the class of the members of the collection.
+     *
+     * @return the class of the first generic argument of the property,
+     *         or null if the property is not generified.
+     */
     public Class<?> getFirstGenericTypeArgument()
     {
         Type type = getPropertyGenericType();
@@ -403,17 +523,30 @@ public class PropertyAccess
         return null;
     }
 
+    /**
+     * Adds value as a member of an array to the property of the target object.
+     * This method should only be called ifthe property is an array.
+     *
+     * @param value the value to add to the array.
+     *
+     * @throws SourceException if adding the value fails.
+     *         A common reason is that value has the wrong class.
+     */
     private void setMemberinArrayField(Object value) throws SourceException
     {
         Object[] oldContent = (Object[]) getProperty();
         int newIndex;
         Object newContent;
         if (oldContent == null) {
-            newContent = Array.newInstance(getPropertyType().getComponentType(), 1);
+            newContent = Array.newInstance(
+                    getPropertyType().getComponentType(),
+                    1);
             newIndex = 0;
         }
         else {
-            newContent = Array.newInstance(getPropertyType().getComponentType(), oldContent.length
+ 1);
+            newContent = Array.newInstance(
+                    getPropertyType().getComponentType(),
+                    oldContent.length + 1);
             System.arraycopy(oldContent, 0, newContent, 0, oldContent.length);
             newIndex = oldContent.length;
         }
@@ -421,7 +554,18 @@ public class PropertyAccess
         setPropertyStrict(newContent);
     }
 
-    private void setMemberinCollectionField(Object value) throws SourceException
+    /**
+     * Adds value as a member of an collection to the property of the target
+     * object.
+     * This method should only be called if the property is a collection.
+     *
+     * @param value the value to add to the array.
+     *
+     * @throws SourceException if adding the value fails.
+     *         A common reason is that value has the wrong class.
+     */
+    private void setMemberinCollectionProperty(Object value)
+            throws SourceException
     {
         @SuppressWarnings("unchecked")
         Collection<Object> content = (Collection<Object>) getProperty();
@@ -432,6 +576,21 @@ public class PropertyAccess
         content.add(value);
     }
 
+    /**
+     * Returns the collection instance to use if a member is added
+     * to a collection property which is still null.
+     * If the property is of type Collection or List, an instance of ArrayList
+     * will be returned.
+     * If the property is of type Set, an instance of HashSet will be returned.
+     * If the property is of type Queue, an instance of LinkedList will be
+     * returned.
+     * In all other cases the class of the collection will be instantiated.
+     *
+     * @return the collection instance to use, not null.
+     *
+     * @throws SourceException if instantiation fails, e.g. if the collection
+     *         is an unknown abstract collection.
+     */
     private Collection<Object> getCollectionInstance() throws SourceException
     {
         Class<?> type = getPropertyType();
@@ -464,6 +623,15 @@ public class PropertyAccess
         }
     }
 
+    /**
+     * Constructs a source exception when setting a field fails.
+     *
+     * @param value the value to which the field was set.
+     * @param reason the reason why setting the field failed.
+     * @param cause the root cause of the exception.
+     *
+     * @return An appropriate SourceException to throw.
+     */
     private SourceException createSetFieldException(
             Object value,
             String reason,
@@ -477,6 +645,17 @@ public class PropertyAccess
                 cause);
     }
 
+    /**
+     * Constructs a source exception when setting a field fails.
+     *
+     * @param target the target object on which the property was set.
+     * @param propertyName the name of the property which was set.
+     * @param value the value to which the field was set.
+     * @param reason the reason why setting the field failed.
+     * @param cause the root cause of the exception.
+     *
+     * @return An appropriate SourceException to throw.
+     */
     private static SourceException createSetFieldException(
             Object target,
             String propertyName,

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotReadableException.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotReadableException.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotReadableException.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotReadableException.java
Thu Apr  4 07:44:52 2013
@@ -21,14 +21,38 @@ package org.apache.torque.generator.sour
 
 import org.apache.torque.generator.source.SourceException;
 
+/**
+ * Indicates that an attempt was made to read a property which is not readable.
+ *
+ * @version $Id: $
+ */
 public class PropertyNotReadableException extends SourceException
 {
+    /** Serial Version UID. */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Constructor.
+     *
+     * @param target the object on which the property was unsuccessfully read.
+     * @param name the name of the property which was unsuccessfully read.
+     */
     public PropertyNotReadableException(Object target, String name)
     {
         this(target, name, null);
     }
 
-    public PropertyNotReadableException(Object target, String name, String detail)
+    /**
+     * Constructor.
+     *
+     * @param target the object on which the property was unsuccessfully read.
+     * @param name the name of the property which was unsuccessfully read.
+     * @param detail a detail cause which is appended to the error message.
+     */
+    public PropertyNotReadableException(
+            Object target,
+            String name,
+            String detail)
     {
         super("The property "
                 + name

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotWriteableException.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotWriteableException.java?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotWriteableException.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/model/PropertyNotWriteableException.java
Thu Apr  4 07:44:52 2013
@@ -21,14 +21,41 @@ package org.apache.torque.generator.sour
 
 import org.apache.torque.generator.source.SourceException;
 
+/**
+ * Indicates that an attempt was made to write a property which is not
+ * writeable.
+ *
+ * @version $Id: $
+ */
 public class PropertyNotWriteableException extends SourceException
 {
+    /** Serial Version UID. */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Constructor.
+     *
+     * @param target the object on which the property was unsuccessfully
+     *        written.
+     * @param name the name of the property which was unsuccessfully written.
+     */
     public PropertyNotWriteableException(Object target, String name)
     {
         this(target, name, null);
     }
 
-    public PropertyNotWriteableException(Object target, String name, String detail)
+    /**
+     * Constructor.
+     *
+     * @param target the object on which the property was unsuccessfully
+     *        written.
+     * @param name the name of the property which was unsuccessfully written.
+     * @param detail a detail cause which is appended to the error message.
+     */
+    public PropertyNotWriteableException(
+            Object target,
+            String name,
+            String detail)
     {
         super("The property "
                 + name

Modified: db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd?rev=1464334&r1=1464333&r2=1464334&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd
Thu Apr  4 07:44:52 2013
@@ -198,6 +198,14 @@
         </documentation>
       </annotation>
     </attribute>
+    <attribute name="modelRootClass" type="string" use="optional">
+      <annotation>
+        <documentation>
+          The fully qualified name of the class to construct from the root
+          element.
+        </documentation>
+      </annotation>
+    </attribute>
     <attribute name="skipDecider" type="string" use="optional">
       <annotation>
         <documentation>



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message