commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1065585 - /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
Date Mon, 31 Jan 2011 12:55:31 GMT
Author: simonetripodi
Date: Mon Jan 31 12:55:31 2011
New Revision: 1065585

URL: http://svn.apache.org/viewvc?rev=1065585&view=rev
Log:
first attempt of createObject() rule 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=1065585&r1=1065584&r2=1065585&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
Mon Jan 31 12:55:31 2011
@@ -110,16 +110,9 @@ final class RulesBinderImpl implements R
 
         return new LinkedRuleBuilder() {
 
-            private String namespaceURI;
+            private final LinkedRuleBuilder mainBuilder = this;
 
-            private LinkedRuleBuilder reportNotNull(String parameterName) {
-                String methodName = new Exception().getStackTrace()[1].getMethodName();
-                RulesBinderImpl.this.addError("{%s} Parameter \"%s\" for pattern \"%s\" must
be NOT null",
-                        methodName,
-                        parameterName,
-                        keyPattern);
-                return this;
-            }
+            private String namespaceURI;
 
             public LinkedRuleBuilder withNamespaceURI(/* @Nullable */ String namespaceURI)
{
                 this.namespaceURI = namespaceURI;
@@ -162,8 +155,51 @@ final class RulesBinderImpl implements R
                 return null;
             }
 
+            /**
+             * 
+             */
             public ObjectCreateBuilder createObject() {
-                return null;
+                return new ObjectCreateBuilder() {
+
+                    private String className;
+
+                    private String attributeName;
+
+                    public ObjectCreateRule get() {
+                        if (this.className == null && this.attributeName == null)
{
+                            addError("{forPattern(\"%s\").createObject()} At least one between
'className' or 'attributeName' has to be specified",
+                                    keyPattern);
+                            return null;
+                        }
+
+                        return new ObjectCreateRule(this.className, this.attributeName);
+                    }
+
+                    public LinkedRuleBuilder then() {
+                        return mainBuilder;
+                    }
+
+                    public ObjectCreateBuilder ofTypeSpecifiedByAttribute(String attributeName)
{
+                        this.attributeName = attributeName;
+                        return this;
+                    }
+
+                    public ObjectCreateBuilder ofType(Class<?> type) {
+                        if (type == null) {
+                            addError("{forPattern(\"%s\").createObject().ofType(Class<?>)}
When specifying 'className', NULL Java type is not admitted",
+                                    keyPattern);
+                            return this;
+                        }
+
+                        return this.ofType(type.getName());
+                    }
+
+                    public ObjectCreateBuilder ofType(String className) {
+                        this.className = className;
+                        return this;
+                    }
+
+                };
             }
 
             public PathCallParamBuilder callParamPath() {



Mime
View raw message