commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1103507 - in /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder: LinkedRuleBuilder.java PluginCreateRuleBuilder.java
Date Sun, 15 May 2011 18:59:31 GMT
Author: simonetripodi
Date: Sun May 15 18:59:30 2011
New Revision: 1103507

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

Added:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/PluginCreateRuleBuilder.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=1103507&r1=1103506&r2=1103507&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 18:59:30 2011
@@ -228,6 +228,17 @@ public final class LinkedRuleBuilder
     }
 
     /**
+     * 
+     *
+     * NOTE: when using this rule, make sure {@link org.apache.commons.digester3.Digester}
instances
+     * will be created using {@link org.apache.commons.digester3.plugins.PluginRules} rules
strategy.
+     */
+    public PluginCreateRuleBuilder createPlugin()
+    {
+        return addProvider( new PluginCreateRuleBuilder( 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/PluginCreateRuleBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/PluginCreateRuleBuilder.java?rev=1103507&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/PluginCreateRuleBuilder.java
(added)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/binder/PluginCreateRuleBuilder.java
Sun May 15 18:59:30 2011
@@ -0,0 +1,224 @@
+/* $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.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.digester3.plugins.PluginCreateRule;
+import org.apache.commons.digester3.plugins.RuleLoader;
+
+/**
+ * Builder chained when invoking {@link LinkedRuleBuilder#createPlugin()}.
+ *
+ * @since 3.0
+ */
+public final class PluginCreateRuleBuilder
+    extends AbstractBackToLinkedRuleBuilder<PluginCreateRule>
+{
+
+    private final Map<String, String> pluginClassAttributes = new LinkedHashMap<String,
String>();
+
+    private final Map<String, String> pluginIdAttributes = new LinkedHashMap<String,
String>();
+
+    private Class<?> baseClass;
+
+    private Class<?> dfltPluginClass;
+
+    private RuleLoader dfltPluginRuleLoader;
+
+    PluginCreateRuleBuilder( String keyPattern, String namespaceURI, RulesBinder mainBinder,
+                                    LinkedRuleBuilder mainBuilder )
+    {
+        super( keyPattern, namespaceURI, mainBinder, mainBuilder );
+    }
+
+    /**
+     * 
+     * @param <T>
+     * @param type
+     * @return this builder instance
+     */
+    public <T> PluginCreateRuleBuilder ofType( Class<T> type )
+    {
+        if ( type == null )
+        {
+            reportError( "createPlugin().ofType( Class<?> )", "NULL Java type not allowed"
);
+            return this;
+        }
+
+        this.baseClass = type;
+
+        return this;
+    }
+
+    /**
+     * 
+     * @param <T>
+     * @param type
+     * @return this builder instance
+     */
+    public <T> PluginCreateRuleBuilder usingDefaultPluginClass( /* @Nullable */Class<T>
type )
+    {
+        this.dfltPluginClass = type;
+        return this;
+    }
+
+    /**
+     * 
+     * @param <RL>
+     * @param ruleLoader
+     * @return this builder instance
+     */
+    public <RL extends RuleLoader> PluginCreateRuleBuilder usingRuleLoader( /* @Nullable
*/RL ruleLoader )
+    {
+        this.dfltPluginRuleLoader = ruleLoader;
+        return this;
+    }
+
+    /**
+     * Sets the xml attribute which the input xml uses to indicate to a
+     * PluginCreateRule which class should be instantiated.
+     *
+     * @param attrName
+     * @return this builder instance
+     */
+    public PluginCreateRuleBuilder setPluginClassAttribute( String attrName )
+    {
+        if ( attrName == null )
+        {
+            reportError( "createPlugin().setPluginClassAttribute( String )", "NULL attribute
name not allowed" );
+            return this;
+        }
+
+        return this.setPluginClassAttribute( null, attrName );
+    }
+
+    /**
+     * Sets the xml attribute which the input xml uses to indicate to a
+     * PluginCreateRule which class should be instantiated.
+     *
+     * @param namespaceUri
+     * @param attrName
+     * @return this builder instance
+     */
+    public PluginCreateRuleBuilder setPluginClassAttribute( /* @Nullable */String namespaceUri,
String attrName )
+    {
+        if ( attrName == null )
+        {
+            reportError( "createPlugin().setPluginClassAttribute( String, String )", "NULL
attribute name not allowed" );
+            return this;
+        }
+
+        return addToMap( pluginClassAttributes, namespaceUri, attrName );
+    }
+
+    /**
+     * Sets the xml attribute which the input xml uses to indicate to a 
+     * PluginCreateRule which plugin declaration is being referenced.
+     *
+     * @param attrName
+     * @return this builder instance
+     */
+    public PluginCreateRuleBuilder setPluginIdAttribute( String attrName )
+    {
+        if ( attrName == null )
+        {
+            reportError( "createPlugin().setPluginIdAttribute( String )", "NULL attribute
name not allowed" );
+            return this;
+        }
+
+        return setPluginIdAttribute( null, attrName );
+    }
+
+    /**
+     * Sets the xml attribute which the input xml uses to indicate to a 
+     * PluginCreateRule which plugin declaration is being referenced.
+     *
+     * @param namespaceUri
+     * @param attrName
+     * @return this builder instance
+     */
+    public PluginCreateRuleBuilder setPluginIdAttribute( /* @Nullable */String namespaceUri,
String attrName )
+    {
+        if ( attrName == null )
+        {
+            reportError( "createPlugin().setPluginIdAttribute( String, String )", "NULL attribute
name not allowed" );
+            return this;
+        }
+
+        return addToMap( pluginIdAttributes, namespaceUri, attrName );
+    }
+
+    /**
+     * 
+     *
+     * @param map
+     * @param namespaceUri
+     * @param attrName
+     * @return this builder instance
+     */
+    private PluginCreateRuleBuilder addToMap( Map<String, String> map, String namespaceUri,
String attrName )
+    {
+        map.put( namespaceUri, attrName );
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected PluginCreateRule createRule()
+    {
+        if ( baseClass == null )
+        {
+            reportError( "createPlugin()", "'baseClass' has to be specified" );
+        }
+
+        PluginCreateRule rule;
+        if ( dfltPluginClass != null )
+        {
+            if ( dfltPluginRuleLoader != null )
+            {
+                rule = new PluginCreateRule( baseClass, dfltPluginClass, dfltPluginRuleLoader
);
+            }
+            else
+            {
+                rule = new PluginCreateRule( baseClass, dfltPluginClass );
+            }
+        }
+        else
+        {
+            rule = new PluginCreateRule( baseClass );
+        }
+
+        for ( Entry<String, String> entry : pluginClassAttributes.entrySet() )
+        {
+            rule.setPluginClassAttribute( entry.getKey(), entry.getValue() );
+        }
+
+        for ( Entry<String, String> entry : pluginIdAttributes.entrySet() )
+        {
+            rule.setPluginIdAttribute( entry.getKey(), entry.getValue() );
+        }
+
+        return rule;
+    }
+
+}

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

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

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



Mime
View raw message