commons-commits mailing list archives

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

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

Added:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/SetPropertiesBuilder.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=1103470&r1=1103469&r2=1103470&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 17:33:06 2011
@@ -153,6 +153,22 @@ public final class LinkedRuleBuilder
     }
 
     /**
+     * {@inheritDoc}
+     */
+    public SetPropertiesBuilder setProperties()
+    {
+        // that would be useful when adding rules via automatically generated rules binding
(such annotations)
+        SetPropertiesBuilder setPropertiesBuilder =
+            fromBinderRuleSet.getProvider( this.keyPattern, this.namespaceURI, SetPropertiesBuilder.class
);
+        if ( setPropertiesBuilder != null )
+        {
+            return setPropertiesBuilder;
+        }
+
+        return this.addProvider( new SetPropertiesBuilder( 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/SetPropertiesBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/SetPropertiesBuilder.java?rev=1103470&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/SetPropertiesBuilder.java
(added)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/SetPropertiesBuilder.java
Sun May 15 17:33:06 2011
@@ -0,0 +1,95 @@
+/* $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.SetPropertiesRule;
+
+/**
+ * Builder chained when invoking {@link LinkedRuleBuilder#setProperties()}.
+ */
+public final class SetPropertiesBuilder
+    extends AbstractBackToLinkedRuleBuilder<SetPropertiesRule>
+{
+
+    private final Map<String, String> aliases = new HashMap<String, String>();
+
+    private boolean ignoreMissingProperty = true;
+
+    SetPropertiesBuilder( String keyPattern, String namespaceURI, RulesBinder mainBinder,
LinkedRuleBuilder mainBuilder )
+    {
+        super( keyPattern, namespaceURI, mainBinder, mainBuilder );
+    }
+
+    /**
+     * Add an additional attribute name to property name mapping.
+     *
+     * @param attributeName The attribute to match
+     * @param propertyName The java bean property to be assigned the value
+     * @return this builder instance
+     */
+    public SetPropertiesBuilder addAlias( String attributeName, String propertyName )
+    {
+        if ( attributeName == null )
+        {
+            reportError( "setProperties().addAlias( String,String ) }", "empty 'attributeName'
not allowed" );
+        }
+        else
+        {
+            if ( propertyName == null )
+            {
+                reportError( "setProperties().addAlias( String,String ) }", "empty 'propertyName'
not allowed" );
+            }
+            else
+            {
+                aliases.put( attributeName, propertyName );
+            }
+        }
+        return this;
+    }
+
+    /**
+     * Sets whether attributes found in the XML without matching properties should be ignored.
+     * 
+     * If set to false, the parsing will throw an {@code NoSuchMethodException}
+     * if an unmatched attribute is found.
+     * This allows to trap misspellings in the XML file.
+     *
+     * @param ignoreMissingProperty false to stop the parsing on unmatched attributes
+     * @return this builder instance
+     */
+    public SetPropertiesBuilder ignoreMissingProperty( boolean ignoreMissingProperty )
+    {
+        this.ignoreMissingProperty = ignoreMissingProperty;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected SetPropertiesRule createRule()
+    {
+        SetPropertiesRule rule = new SetPropertiesRule( aliases );
+        rule.setIgnoreMissingProperty( ignoreMissingProperty );
+        return rule;
+    }
+
+}

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

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

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



Mime
View raw message