You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/05/15 17:31:17 UTC

svn commit: r1103431 - in /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder: LinkedRuleBuilder.java NestedPropertiesBuilder.java

Author: simonetripodi
Date: Sun May 15 15:31:17 2011
New Revision: 1103431

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

Added:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/NestedPropertiesBuilder.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=1103431&r1=1103430&r2=1103431&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 15:31:17 2011
@@ -119,6 +119,23 @@ public final class LinkedRuleBuilder
     }
 
     /**
+     * Sets properties on the object at the top of the stack,
+     * based on child elements with names matching properties on that  object.
+     */
+    public NestedPropertiesBuilder setNestedProperties()
+    {
+        // that would be useful when adding rules via automatically generated rules binding (such annotations)
+        NestedPropertiesBuilder nestedPropertiesBuilder =
+            fromBinderRuleSet.getProvider( keyPattern, namespaceURI, NestedPropertiesBuilder.class );
+        if ( nestedPropertiesBuilder != null )
+        {
+            return nestedPropertiesBuilder;
+        }
+
+        return addProvider( new NestedPropertiesBuilder( keyPattern, namespaceURI, mainBinder, this ) );
+    }
+
+    /**
      * 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/NestedPropertiesBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/NestedPropertiesBuilder.java?rev=1103431&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/NestedPropertiesBuilder.java (added)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/NestedPropertiesBuilder.java Sun May 15 15:31:17 2011
@@ -0,0 +1,130 @@
+/* $Id$
+ *
+ * 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.commons.digester3.binder;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.digester3.SetNestedPropertiesRule;
+
+/**
+ * Builder chained when invoking {@link LinkedRuleBuilderImpl#setNestedProperties()}.
+ *
+ * @since 3.0
+ */
+public final class NestedPropertiesBuilder
+    extends AbstractBackToLinkedRuleBuilder<SetNestedPropertiesRule>
+{
+
+    private final Map<String, String> elementNames = new HashMap<String, String>();
+
+    private boolean trimData = true;
+
+    private boolean allowUnknownChildElements = false;
+
+    NestedPropertiesBuilder( String keyPattern, String namespaceURI, RulesBinder mainBinder,
+                                    LinkedRuleBuilder mainBuilder )
+    {
+        super( keyPattern, namespaceURI, mainBinder, mainBuilder );
+    }
+
+    /**
+     * Allows ignore a matching element.
+     *
+     * @param elementName The child xml element to be ignored
+     * @return this builder instance
+     */
+    public NestedPropertiesBuilder ignoreElement( String elementName )
+    {
+        if ( elementName == null )
+        {
+            reportError( "setNestedProperties().ignoreElement( String )", "empty 'elementName' not allowed" );
+        }
+        else
+        {
+            elementNames.put( elementName, null );
+        }
+        return this;
+    }
+
+    /**
+     * Allows element2property mapping to be overridden.
+     *
+     * @param elementName The child xml element to match
+     * @param propertyName The java bean property to be assigned the value
+     * @return this builder instance
+     */
+    public NestedPropertiesBuilder addAlias( String elementName, String propertyName )
+    {
+        if ( elementName == null )
+        {
+            reportError( "setNestedProperties().addAlias( String,String )", "empty 'elementName' not allowed" );
+        }
+        else
+        {
+            if ( propertyName == null )
+            {
+                reportError( "setNestedProperties().addAlias( String,String )", "empty 'propertyName' not allowed" );
+            }
+            else
+            {
+                elementNames.put( elementName, propertyName );
+            }
+        }
+        return this;
+    }
+
+    /**
+     * When set to true, any text within child elements will have leading
+     * and trailing whitespace removed before assignment to the target
+     * object.
+     *
+     * @param trimData
+     * @return this builder instance
+     */
+    public NestedPropertiesBuilder trimData( boolean trimData )
+    {
+        this.trimData = trimData;
+        return this;
+    }
+
+    /**
+     * 
+     *
+     * @param allowUnknownChildElements
+     * @return
+     */
+    public NestedPropertiesBuilder allowUnknownChildElements( boolean allowUnknownChildElements )
+    {
+        this.allowUnknownChildElements = allowUnknownChildElements;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected SetNestedPropertiesRule createRule()
+    {
+        SetNestedPropertiesRule rule = new SetNestedPropertiesRule( elementNames );
+        rule.setTrimData( trimData );
+        rule.setAllowUnknownChildElements( allowUnknownChildElements );
+        return rule;
+    }
+
+}

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

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

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