commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1103400 - in /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder: LinkedRuleBuilder.java ObjectCreateBuilder.java
Date Sun, 15 May 2011 14:38:18 GMT
Author: simonetripodi
Date: Sun May 15 14:38:17 2011
New Revision: 1103400

URL: http://svn.apache.org/viewvc?rev=1103400&view=rev
Log:
restored the ObjectCreateBuilder class
ObjectCreateBuilder plugged in the Digester EDSL

Added:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
  (with props)
Modified:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/LinkedRuleBuilder.java

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/LinkedRuleBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/LinkedRuleBuilder.java?rev=1103400&r1=1103399&r2=1103400&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/LinkedRuleBuilder.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/LinkedRuleBuilder.java
Sun May 15 14:38:17 2011
@@ -100,6 +100,15 @@ public final class LinkedRuleBuilder
     }
 
     /**
+     * Construct an object.
+     */
+    public ObjectCreateBuilder createObject()
+    {
+        return this.addProvider(
+                                new ObjectCreateBuilder(keyPattern, namespaceURI, mainBinder,
this, classLoader));
+    }
+
+    /**
      * Add a custom user rule in the specified pattern built by the given provider.
      *
      * @param <R>

Added: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java?rev=1103400&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
(added)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
Sun May 15 14:38:17 2011
@@ -0,0 +1,87 @@
+package org.apache.commons.digester3.binder;
+
+import org.apache.commons.digester3.ObjectCreateRule;
+
+public final class ObjectCreateBuilder
+    extends AbstractBackToLinkedRuleBuilder<ObjectCreateRule>
+{
+
+    private final ClassLoader classLoader;
+
+    private Class<?> type;
+
+    private String attributeName;
+
+    ObjectCreateBuilder( String keyPattern, String namespaceURI, RulesBinder mainBinder,
LinkedRuleBuilder mainBuilder,
+                         ClassLoader classLoader )
+    {
+        super( keyPattern, namespaceURI, mainBinder, mainBuilder );
+        this.classLoader = classLoader;
+    }
+
+    /**
+     * Construct an object with the specified class name.
+     *
+     * @param className Java class name of the object to be created
+     * @return this builder instance
+     */
+    public ObjectCreateBuilder ofType( String className )
+    {
+        if ( className == null )
+        {
+            reportError( "createObject().ofType( String )", "NULL Java type not allowed"
);
+            return this;
+        }
+
+        try
+        {
+            return ofType( this.classLoader.loadClass( className ) );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            reportError( "createObject().ofType( String )", String.format( "class '%s' cannot
be load", className ) );
+            return this;
+        }
+    }
+
+    /**
+     * Construct an object with the specified class.
+     *
+     * @param type Java class of the object to be created
+     * @return this builder instance
+     */
+    public <T> ObjectCreateBuilder ofType( Class<T> type )
+    {
+        if ( type == null )
+        {
+            reportError( "createObject().ofType( Class<?> )", "NULL Java type not allowed"
);
+            return this;
+        }
+
+        this.type = type;
+
+        return this;
+    }
+
+    /**
+     * Allows specify the attribute containing an override class name if it is present.
+     *
+     * @param attributeName The attribute containing an override class name if it is present
+     * @return this builder instance
+     */
+    public ObjectCreateBuilder ofTypeSpecifiedByAttribute( /* @Nullable */String attributeName
)
+    {
+        this.attributeName = attributeName;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected ObjectCreateRule createRule()
+    {
+        return new ObjectCreateRule( attributeName, type );
+    }
+
+}

Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message