commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1066068 - /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
Date Tue, 01 Feb 2011 15:30:38 GMT
Author: simonetripodi
Date: Tue Feb  1 15:30:37 2011
New Revision: 1066068

URL: http://svn.apache.org/viewvc?rev=1066068&view=rev
Log:
added objectParam() method implementation

Modified:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java?rev=1066068&r1=1066067&r2=1066068&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
Tue Feb  1 15:30:37 2011
@@ -37,6 +37,7 @@ import org.apache.commons.digester3.rule
 import org.apache.commons.digester3.rulesbinder.PathCallParamBuilder;
 import org.apache.commons.digester3.rulesbinder.SetPropertiesBuilder;
 import org.apache.commons.digester3.rulesbinder.SetPropertyBuilder;
+import org.apache.commons.digester3.spi.ObjectCreationFactory;
 import org.apache.commons.digester3.spi.RuleProvider;
 import org.apache.commons.digester3.spi.Rules;
 
@@ -356,12 +357,103 @@ final class RulesBinderImpl implements R
                 });
             }
 
-            public <T> ObjectParamBuilder objectParam(T paramObj) {
-                return null;
+            /**
+             * 
+             */
+            public <T> ObjectParamBuilder objectParam(/* @Nullable */final T paramObj)
{
+                return this.addProvider(new ObjectParamBuilder() {
+
+                    private int paramIndex = 0;
+
+                    private String attributeName;
+
+                    public ObjectParamRule get() {
+                        return setNamespaceAndReturn(new ObjectParamRule(paramIndex, attributeName,
paramObj));
+                    }
+
+                    public LinkedRuleBuilder then() {
+                        return mainBuilder;
+                    }
+
+                    public ObjectParamBuilder ofIndex(int paramIndex) {
+                        if (paramIndex < 0) {
+                            addError("{forPattern(\"%s\").objectParam(%s).ofIndex(int)} negative
index argument not allowed",
+                                    keyPattern,
+                                    String.valueOf(paramObj));
+                        }
+
+                        this.paramIndex = paramIndex;
+                        return this;
+                    }
+
+                    public ObjectParamBuilder matchingAttribute(/* @Nullable */String attributeName)
{
+                        this.attributeName = attributeName;
+                        return this;
+                    }
+
+                });
             }
 
+            /**
+             * 
+             */
             public FactoryCreateBuilder factoryCreate() {
-                return null;
+                return this.addProvider(new FactoryCreateBuilder() {
+
+                    private String className;
+
+                    private String attributeName;
+
+                    private boolean ignoreCreateExceptions;
+
+                    private ObjectCreationFactory<?> creationFactory;
+
+                    public FactoryCreateRule get() { // loading error, the rest are binding
errors
+                        if (className == null && attributeName == null &&
creationFactory == null) {
+                            addError("{forPattern(\"%s\").factoryCreate()} at least one between
'className' ar 'attributeName' or 'creationFactory' has to be specified",
+                                    keyPattern);
+                            return null;
+                        }
+
+                        return setNamespaceAndReturn(
+                                new FactoryCreateRule(keyPattern, attributeName, creationFactory,
ignoreCreateExceptions));
+                    }
+
+                    public LinkedRuleBuilder then() {
+                        return mainBuilder;
+                    }
+
+                    public <T> FactoryCreateBuilder usingFactory(/* @Nullable */ObjectCreationFactory<T>
creationFactory) {
+                        this.creationFactory = creationFactory;
+                        return this;
+                    }
+
+                    public FactoryCreateBuilder overriddenByAttribute(/* @Nullable */String
attributeName) {
+                        this.attributeName = attributeName;
+                        return this;
+                    }
+
+                    public FactoryCreateBuilder ofType(Class<?> type) {
+                        if (type == null) {
+                            addError("{forPattern(\"%s\").factoryCreate().ofType(Class<?>)}
NULL Java type not allowed",
+                                    keyPattern);
+                            return this;
+                        }
+
+                        return this.ofType(type.getName());
+                    }
+
+                    public FactoryCreateBuilder ofType(/* @Nullable */String className) {
+                        this.className = className;
+                        return this;
+                    }
+
+                    public FactoryCreateBuilder ignoreCreateExceptions(boolean ignoreCreateExceptions)
{
+                        this.ignoreCreateExceptions = ignoreCreateExceptions;
+                        return this;
+                    }
+
+                });
             }
 
             /**



Mime
View raw message