rdonkin 2004/02/21 09:20:06
Modified: betwixt/src/java/org/apache/commons/betwixt/io Tag:
REFACTORING-BRANCH_2004-01-13 BeanRuleSet.java
betwixt/src/java/org/apache/commons/betwixt/io/read Tag:
REFACTORING-BRANCH_2004-01-13 MappingAction.java
ReadConfiguration.java ReadContext.java
Log:
Factored out the operation of deciding which action should be performed next into a
pluggable strategy and delegated decision to last action.
Revision Changes Path
No revision
No revision
1.16.2.7 +8 -23
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanRuleSet.java
Index: BeanRuleSet.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanRuleSet.java,v
retrieving revision 1.16.2.6
retrieving revision 1.16.2.7
diff -u -r1.16.2.6 -r1.16.2.7
--- BeanRuleSet.java 21 Feb 2004 16:58:58 -0000 1.16.2.6
+++ BeanRuleSet.java 21 Feb 2004 17:20:06 -0000 1.16.2.7
@@ -287,33 +287,18 @@
throws Exception {
MappingAction result = null;
- if (context.currentMappingAction() == null)
+ MappingAction lastAction = context.currentMappingAction();
+ if (lastAction == null)
{
result = BeanBindAction.INSTANCE;
} else {
- result = createAction(name, context);
+ result = lastAction.next(namespace, name, attributes, context);
}
return result.begin(namespace, name, attributes, context);
}
- private MappingAction createAction(String name, ReadContext context)
- throws Exception, IntrospectionException {
- MappingAction result = MappingAction.EMPTY;
-
- ElementDescriptor activeDescriptor = context.getCurrentDescriptor();
- if (activeDescriptor != null) {
- if (activeDescriptor.isHollow())
- {
- result = BeanBindAction.INSTANCE;
- }
- else if (activeDescriptor.isSimple())
- {
- result = SimpleTypeBindAction.INSTANCE;
- }
- }
- return result;
- }
+
/**
* @see Rule#body(String, String, String)
No revision
No revision
1.1.2.3 +25 -7
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/Attic/MappingAction.java
Index: MappingAction.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/Attic/MappingAction.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- MappingAction.java 15 Jan 2004 20:21:21 -0000 1.1.2.2
+++ MappingAction.java 21 Feb 2004 17:20:06 -0000 1.1.2.3
@@ -74,6 +74,14 @@
*/
public abstract class MappingAction {
+
+ public abstract MappingAction next(
+ String namespace,
+ String name,
+ Attributes attributes,
+ ReadContext context)
+ throws Exception;
+
/**
* Executes mapping action on new element.
* @param namespace
@@ -116,7 +124,17 @@
* @version $Revision$
*/
public static class Base extends MappingAction {
-
+
+ public MappingAction next(
+ String namespace,
+ String name,
+ Attributes attributes,
+ ReadContext context)
+ throws Exception {
+
+ return context.getActionMappingStrategy().getMappingAction(namespace,
name, attributes, context);
+ }
+
/* (non-Javadoc)
* @see
org.apache.commons.betwixt.io.read.MappingAction#begin(java.lang.String,
java.lang.String, org.xml.sax.Attributes,
org.apache.commons.betwixt.io.read.ReadContext,
org.apache.commons.betwixt.XMLIntrospector)
*/
1.3.2.1 +17 -4
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/ReadConfiguration.java
Index: ReadConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/ReadConfiguration.java,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -r1.3 -r1.3.2.1
--- ReadConfiguration.java 9 Oct 2003 20:52:06 -0000 1.3
+++ ReadConfiguration.java 21 Feb 2004 17:20:06 -0000 1.3.2.1
@@ -60,6 +60,8 @@
*/
package org.apache.commons.betwixt.io.read;
+import org.apache.commons.betwixt.strategy.ActionMappingStrategy;
+
/**
* Stores mapping phase configuration settings that apply only for bean reading.
*
@@ -71,6 +73,8 @@
/** Chain used to create beans defaults to
BeanCreationChain.createDefaultChain() */
private BeanCreationChain beanCreationChain =
BeanCreationChain.createDefaultChain();
+ private ActionMappingStrategy actionMappingStrategy = new
ActionMappingStrategy();
+
/**
* Gets the BeanCreationChain that should be used to construct beans.
* @return the BeanCreationChain to use, not null
@@ -87,4 +91,13 @@
this.beanCreationChain = beanCreationChain;
}
+
+ public ActionMappingStrategy getActionMappingStrategy() {
+ return actionMappingStrategy;
+ }
+
+ public void setActionMappingStrategy(ActionMappingStrategy
actionMappingStrategy) {
+ this.actionMappingStrategy = actionMappingStrategy;
+ }
+
}
1.4.2.4 +9 -5
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/ReadContext.java
Index: ReadContext.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/ReadContext.java,v
retrieving revision 1.4.2.3
retrieving revision 1.4.2.4
diff -u -r1.4.2.3 -r1.4.2.4
--- ReadContext.java 21 Feb 2004 16:34:57 -0000 1.4.2.3
+++ ReadContext.java 21 Feb 2004 17:20:06 -0000 1.4.2.4
@@ -72,6 +72,7 @@
import org.apache.commons.betwixt.XMLIntrospector;
import org.apache.commons.betwixt.expression.Context;
import org.apache.commons.betwixt.expression.Updater;
+import org.apache.commons.betwixt.strategy.ActionMappingStrategy;
import org.apache.commons.collections.ArrayStack;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -205,6 +206,10 @@
return readConfiguration.getBeanCreationChain();
}
+ public ActionMappingStrategy getActionMappingStrategy() {
+ return readConfiguration.getActionMappingStrategy();
+ }
+
/**
* Pops the top element from the element mapping stack.
* Also removes any mapped class marks below the top element.
@@ -617,6 +622,5 @@
}
}
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]