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/02/19 15:52:56 UTC
svn commit: r1072354 - in
/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3:
internal/rulesbinder/ plugins/ rulesbinder/
Author: simonetripodi
Date: Sat Feb 19 14:52:55 2011
New Revision: 1072354
URL: http://svn.apache.org/viewvc?rev=1072354&view=rev
Log:
added the PluginCreateRule directly into the RulesBinder EDSL
Added:
commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/PluginCreateRuleBuilderImpl.java (with props)
commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/PluginCreateRuleBuilder.java (with props)
Modified:
commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/LinkedRuleBuilderImpl.java
commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/plugins/PluginContext.java
commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/LinkedRuleBuilder.java
Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/LinkedRuleBuilderImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/LinkedRuleBuilderImpl.java?rev=1072354&r1=1072353&r2=1072354&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/LinkedRuleBuilderImpl.java (original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/LinkedRuleBuilderImpl.java Sat Feb 19 14:52:55 2011
@@ -30,6 +30,7 @@ import org.apache.commons.digester3.rule
import org.apache.commons.digester3.rulesbinder.ObjectCreateBuilder;
import org.apache.commons.digester3.rulesbinder.ObjectParamBuilder;
import org.apache.commons.digester3.rulesbinder.PathCallParamBuilder;
+import org.apache.commons.digester3.rulesbinder.PluginCreateRuleBuilder;
import org.apache.commons.digester3.rulesbinder.PluginDeclarationRuleBuilder;
import org.apache.commons.digester3.rulesbinder.SetNextBuilder;
import org.apache.commons.digester3.rulesbinder.SetPropertiesBuilder;
@@ -266,4 +267,12 @@ final class LinkedRuleBuilderImpl implem
new PluginDeclarationRuleBuilderImpl(this.keyPattern, this.namespaceURI, this.mainBinder, this));
}
+ /**
+ * {@inheritDoc}
+ */
+ public PluginCreateRuleBuilder createPlugin() {
+ return this.addProvider(
+ new PluginCreateRuleBuilderImpl(this.keyPattern, this.namespaceURI, this.mainBinder, this));
+ }
+
}
Added: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/PluginCreateRuleBuilderImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/PluginCreateRuleBuilderImpl.java?rev=1072354&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/PluginCreateRuleBuilderImpl.java (added)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/PluginCreateRuleBuilderImpl.java Sat Feb 19 14:52:55 2011
@@ -0,0 +1,186 @@
+/* $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.internal.rulesbinder;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map.Entry;
+
+import org.apache.commons.digester3.RulesBinder;
+import org.apache.commons.digester3.plugins.PluginCreateRule;
+import org.apache.commons.digester3.plugins.RuleLoader;
+import org.apache.commons.digester3.rulesbinder.LinkedRuleBuilder;
+import org.apache.commons.digester3.rulesbinder.PluginCreateRuleBuilder;
+
+/**
+ * Builder chained when invoking {@link LinkedRuleBuilder#createPlugin()}.
+ */
+final class PluginCreateRuleBuilderImpl
+ extends AbstractBackToLinkedRuleBuilder<PluginCreateRule>
+ implements PluginCreateRuleBuilder {
+
+ private final Collection<Entry<String, String>> pluginClassAttributes = new ArrayList<Entry<String, String>>();
+
+ private final Collection<Entry<String, String>> pluginIdAttributes = new ArrayList<Entry<String, String>>();
+
+ private Class<?> baseClass;
+
+ private Class<?> dfltPluginClass;
+
+ private RuleLoader dfltPluginRuleLoader;
+
+ public PluginCreateRuleBuilderImpl(String keyPattern,
+ String namespaceURI,
+ RulesBinder mainBinder,
+ LinkedRuleBuilderImpl mainBuilder) {
+ super(keyPattern, namespaceURI, mainBinder, mainBuilder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> PluginCreateRuleBuilder ofType(Class<T> type) {
+ if (type == null) {
+ this.reportError("createPlugin().ofType(Class<?>)", "NULL Java type not allowed");
+ return this;
+ }
+
+ this.baseClass = type;
+
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> PluginCreateRuleBuilder usingDefaultPluginClass(/* @Nullable */ Class<T> type) {
+ this.dfltPluginClass = type;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <RL extends RuleLoader> PluginCreateRuleBuilder usingRuleLoader(/* @Nullable */ RL ruleLoader) {
+ this.dfltPluginRuleLoader = ruleLoader;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PluginCreateRuleBuilder setPluginClassAttribute(String attrName) {
+ if (attrName == null) {
+ this.reportError("createPlugin().setPluginClassAttribute(String)", "NULL attribute name not allowed");
+ return this;
+ }
+
+ return this.setPluginClassAttribute(null, attrName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PluginCreateRuleBuilder setPluginClassAttribute(/* @Nullable */ String namespaceUri, String attrName) {
+ if (attrName == null) {
+ this.reportError("createPlugin().setPluginClassAttribute(String,String)", "NULL attribute name not allowed");
+ return this;
+ }
+
+ return this.addToCollection(this.pluginClassAttributes, namespaceUri, attrName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PluginCreateRuleBuilder setPluginIdAttribute(String attrName) {
+ if (attrName == null) {
+ this.reportError("createPlugin().setPluginIdAttribute(String)", "NULL attribute name not allowed");
+ return this;
+ }
+
+ return this.setPluginIdAttribute(null, attrName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PluginCreateRuleBuilder setPluginIdAttribute(/* @Nullable */ String namespaceUri, String attrName) {
+ if (attrName == null) {
+ this.reportError("createPlugin().setPluginIdAttribute(String,String)", "NULL attribute name not allowed");
+ return this;
+ }
+
+ return this.addToCollection(this.pluginIdAttributes, namespaceUri, attrName);
+ }
+
+ public PluginCreateRuleBuilder addToCollection(Collection<Entry<String, String>> collection,
+ final String namespaceUri,
+ final String attrName) {
+ collection.add(new Entry<String, String>() {
+
+ public String setValue(String value) {
+ // not needed
+ return null;
+ }
+
+ public String getValue() {
+ return attrName;
+ }
+
+ public String getKey() {
+ return namespaceUri;
+ }
+
+ });
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected PluginCreateRule createRule() {
+ if (this.baseClass == null) {
+ this.reportError("createPlugin()",
+ "'baseClass' has to be specified");
+ }
+
+ PluginCreateRule rule;
+ if (this.dfltPluginClass != null) {
+ if (this.dfltPluginRuleLoader != null) {
+ rule = new PluginCreateRule(this.baseClass, this.dfltPluginClass, this.dfltPluginRuleLoader);
+ } else {
+ rule = new PluginCreateRule(this.baseClass, this.dfltPluginClass);
+ }
+ } else {
+ rule = new PluginCreateRule(this.baseClass);
+ }
+
+ for (Entry<String, String> entry : this.pluginClassAttributes) {
+ rule.setPluginClassAttribute(entry.getKey(), entry.getValue());
+ }
+
+ for (Entry<String, String> entry : this.pluginIdAttributes) {
+ rule.setPluginIdAttribute(entry.getKey(), entry.getValue());
+ }
+
+ return rule;
+ }
+
+}
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/PluginCreateRuleBuilderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/PluginCreateRuleBuilderImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/PluginCreateRuleBuilderImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/plugins/PluginContext.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/plugins/PluginContext.java?rev=1072354&r1=1072353&r2=1072354&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/plugins/PluginContext.java (original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/plugins/PluginContext.java Sat Feb 19 14:52:55 2011
@@ -152,8 +152,7 @@ public class PluginContext {
* @param attrName is the attribute whose value contains the name of the
* class to be instantiated.
*/
- public void setPluginClassAttribute(String namespaceUri,
- String attrName) {
+ public void setPluginClassAttribute(String namespaceUri, String attrName) {
pluginClassAttrNs = namespaceUri;
pluginClassAttr = attrName;
}
@@ -191,8 +190,7 @@ public class PluginContext {
* @param attrName is the attribute whose value contains the id of the
* plugin declaration to be used when instantiating an object.
*/
- public void setPluginIdAttribute(String namespaceUri,
- String attrName) {
+ public void setPluginIdAttribute(String namespaceUri, String attrName) {
pluginIdAttrNs = namespaceUri;
pluginIdAttr = attrName;
}
@@ -206,7 +204,7 @@ public class PluginContext {
public String getPluginClassAttrNs() {
return pluginClassAttrNs;
}
-
+
/**
* Get the namespace for the xml attribute which indicates to a
* PluginCreateRule which class is to be plugged in.
@@ -216,7 +214,7 @@ public class PluginContext {
public String getPluginClassAttr() {
return pluginClassAttr;
}
-
+
/**
* Get the namespace for the xml attribute which indicates to a
* PluginCreateRule which previous plugin declaration should be used.
@@ -226,7 +224,7 @@ public class PluginContext {
public String getPluginIdAttrNs() {
return pluginIdAttrNs;
}
-
+
/**
* Get the namespace for the xml attribute which indicates to a
* PluginCreateRule which previous plugin declaration should be used.
@@ -236,4 +234,5 @@ public class PluginContext {
public String getPluginIdAttr() {
return pluginIdAttr;
}
+
}
Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/LinkedRuleBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/LinkedRuleBuilder.java?rev=1072354&r1=1072353&r2=1072354&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/LinkedRuleBuilder.java (original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/LinkedRuleBuilder.java Sat Feb 19 14:52:55 2011
@@ -150,4 +150,14 @@ public interface LinkedRuleBuilder {
*/
PluginDeclarationRuleBuilder declarePlugin();
+ /**
+ *
+ *
+ * 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.
+ *
+ * @return
+ */
+ PluginCreateRuleBuilder createPlugin();
+
}
Added: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/PluginCreateRuleBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/PluginCreateRuleBuilder.java?rev=1072354&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/PluginCreateRuleBuilder.java (added)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/PluginCreateRuleBuilder.java Sat Feb 19 14:52:55 2011
@@ -0,0 +1,92 @@
+/* $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.rulesbinder;
+
+import org.apache.commons.digester3.plugins.PluginCreateRule;
+import org.apache.commons.digester3.plugins.RuleLoader;
+
+/**
+ * Builder chained when invoking {@link LinkedRuleBuilder#createPlugin()}.
+ */
+public interface PluginCreateRuleBuilder extends BackToLinkedRuleBuilder<PluginCreateRule> {
+
+ /**
+ *
+ *
+ * @param <T>
+ * @param type The class which any specified plugin <i>must</i> be descended from
+ * @return this builder instance
+ */
+ <T> PluginCreateRuleBuilder ofType(Class<T> type);
+
+ /**
+ *
+ *
+ * @param <T>
+ * @return this builder instance
+ */
+ <T> PluginCreateRuleBuilder usingDefaultPluginClass(Class<T> type);
+
+ /**
+ *
+ *
+ * @param <RL>
+ * @param ruleLoader
+ * @return this builder instance
+ */
+ <RL extends RuleLoader> PluginCreateRuleBuilder usingRuleLoader(RL ruleLoader);
+
+ /**
+ * Sets the xml attribute which the input xml uses to indicate to a
+ * PluginCreateRule which class should be instantiated.
+ *
+ * @param attrName
+ * @return
+ */
+ PluginCreateRuleBuilder setPluginClassAttribute(String 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
+ */
+ PluginCreateRuleBuilder setPluginClassAttribute(String namespaceUri, String 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
+ */
+ PluginCreateRuleBuilder setPluginIdAttribute(String attrName);
+
+ /**
+ * Sets the xml attribute which the input xml uses to indicate to a
+ * PluginCreateRule which plugin declaration is being referenced.
+ *
+ * @param attrName
+ * @return
+ */
+ PluginCreateRuleBuilder setPluginIdAttribute(String namespaceUri, String attrName);
+
+}
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/PluginCreateRuleBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/PluginCreateRuleBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/PluginCreateRuleBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain