[jboss-svn-commits] JBL Code SVN: r12055 - in labs/jbossrules/trunk/drools-core: src/main/java/org/drools/base/mvel and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue May 22 03:04:06 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-05-22 03:04:06 -0400 (Tue, 22 May 2007)
New Revision: 12055
Modified:
labs/jbossrules/trunk/drools-core/.classpath
labs/jbossrules/trunk/drools-core/.project
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java
Log:
JBRULES-713 Make Dialects Pluggeable
JBRULES-708 Full MVEL integration
Modified: labs/jbossrules/trunk/drools-core/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-core/.classpath 2007-05-22 06:17:39 UTC (rev 12054)
+++ labs/jbossrules/trunk/drools-core/.classpath 2007-05-22 07:04:06 UTC (rev 12055)
@@ -1,12 +1,12 @@
<classpath>
<classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
<classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
- <classpathentry kind="src" path="src/test/resources" output="target/test-classes"/>
+ <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta16/mvel14-1.2beta16.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
<classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta18/mvel14-1.2beta18.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
</classpath>
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/.project
===================================================================
--- labs/jbossrules/trunk/drools-core/.project 2007-05-22 06:17:39 UTC (rev 12054)
+++ labs/jbossrules/trunk/drools-core/.project 2007-05-22 07:04:06 UTC (rev 12055)
@@ -5,7 +5,6 @@
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
- <arguments/>
</buildCommand>
</buildSpec>
<natures>
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java 2007-05-22 06:17:39 UTC (rev 12054)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java 2007-05-22 07:04:06 UTC (rev 12055)
@@ -1,50 +1,51 @@
package org.drools.base.mvel;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
import org.drools.WorkingMemory;
import org.drools.rule.Declaration;
import org.drools.spi.Tuple;
+import org.mvel.CompileException;
import org.mvel.integration.VariableResolver;
import org.mvel.integration.VariableResolverFactory;
+import org.mvel.integration.impl.BaseVariableResolverFactory;
+import org.mvel.integration.impl.MapVariableResolver;
-public class DroolsMVELFactory
- implements
- VariableResolverFactory {
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class DroolsMVELFactory extends BaseVariableResolverFactory {
+ /**
+ * Holds the instance of the variables.
+ */
+ private Map variables;
+
+ // public DroolsMVELFactory(Map variables) {
+ // this.variables = variables;
+ // }
+
private Tuple tuple;
private Object object;
private Map localDeclarations;
private Map previousDeclarations;
private Map globals;
-
- private Map resolvers;
+
+ //private Map resolvers;
//private
private WorkingMemory workingMemory;
public DroolsMVELFactory() {
- this.resolvers = Collections.EMPTY_MAP;
+ // this.resolvers = Collections.EMPTY_MAP;
}
public DroolsMVELFactory(final Map previousDeclarations,
final Map localDeclarations,
final Map globals) {
-
- }
-
- public void setPreviousDeclarationMap(final Map declarations) {
- this.previousDeclarations = declarations;
- }
-
- public void setLocalDeclarationMap(final Map declarations) {
- this.localDeclarations = declarations;
- }
-
- public void setGlobalsMap(final Map globals) {
+ this.previousDeclarations = previousDeclarations;
+ this.localDeclarations = localDeclarations;
this.globals = globals;
+ this.variables = new HashMap();
}
-
+
public Object getObject() {
return this.object;
}
@@ -63,90 +64,88 @@
public Object getValue(final String identifier) {
return this.workingMemory.getGlobal( identifier );
- }
+ }
- public VariableResolver createVariable(final String name,
- final Object value) {
- throw new UnsupportedOperationException( "Variables cannot be created here" );
+ public VariableResolver createVariable(String name,
+ Object value) {
+ VariableResolver vr = getVariableResolver( name );
+ if ( vr != null ) {
+ vr.setValue( value );
+ return vr;
+ } else {
+ addResolver( name,
+ vr = new MapVariableResolver( variables,
+ name ) );
+ vr.setValue( value );
+ return vr;
+ }
}
- public VariableResolverFactory getNextFactory() {
- return null;
+ public VariableResolver createVariable(String name,
+ Object value,
+ Class type) {
+ VariableResolver vr = getVariableResolver( name );
+ if ( vr != null && vr.getType() != null ) {
+ throw new CompileException( "variable already defined within scope: " + vr.getType() + " " + name );
+ } else {
+ addResolver( name,
+ vr = new MapVariableResolver( variables,
+ name,
+ type ) );
+ vr.setValue( value );
+ return vr;
+ }
}
- public VariableResolverFactory setNextFactory(final VariableResolverFactory resolverFactory) {
- throw new UnsupportedOperationException( "Chained factories are not support for DroolsMVELFactory" );
- }
-
- public VariableResolver getVariableResolver(final String name) {
- return (VariableResolver) this.resolvers.get( name );
- }
-
- public boolean isResolveable(final String name) {
- //return this.declarations.containsKey( name ) || this.globals.containsKey( name );
- if ( this.resolvers == Collections.EMPTY_MAP ) {
- this.resolvers = new HashMap();
- }
-
- VariableResolver resolver = (VariableResolver) this.resolvers.get( name );
-
- if ( resolver != null ) {
+ public boolean isResolveable(String name) {
+ if ( variableResolvers != null && variableResolvers.containsKey( name ) ) {
return true;
- }
-
- if ( this.previousDeclarations != null && this.previousDeclarations.containsKey( name ) ) {
- resolver = new DroolsMVELPreviousDeclarationVariable( (Declaration) this.previousDeclarations.get( name ),
- this );
+ } else if ( this.previousDeclarations != null && this.previousDeclarations.containsKey( name ) ) {
+ addResolver(name, new DroolsMVELPreviousDeclarationVariable( (Declaration) this.previousDeclarations.get( name ),
+ this ) );
+ return true;
} else if ( this.localDeclarations != null && this.localDeclarations.containsKey( name ) ) {
- resolver = new DroolsMVELLocalDeclarationVariable( (Declaration) this.localDeclarations.get( name ),
- this );
- } else {
- resolver = new DroolsMVELGlobalVariable( name,
+ addResolver(name, new DroolsMVELLocalDeclarationVariable( (Declaration) this.localDeclarations.get( name ),
+ this ) );
+ return true;
+ } else if ( this.globals.containsKey( name ) ) {
+ addResolver(name, new DroolsMVELGlobalVariable( name,
(Class) this.globals.get( name ),
- this );
- }
-
- if ( resolver != null ) {
- this.resolvers.put( name,
- resolver );
+ this ) );
return true;
- } else {
- return false;
+ } else if ( variables != null && variables.containsKey( name ) ) {
+ addResolver( name,
+ new MapVariableResolver( variables,
+ name ) );
+ return true;
+ } else if ( nextFactory != null ) {
+ return nextFactory.isResolveable( name );
}
+
+ return false;
}
- public boolean isTarget(final String name) {
- return this.resolvers.containsKey( name );
+ public void pack() {
+ if ( variables != null ) {
+ if ( variableResolvers == null ) variableResolvers = new HashMap();
+ for ( Iterator it = variables.keySet().iterator(); it.hasNext(); ) {
+ String s = (String) it.next();
+ //for (String s : variables.keySet()) {
+ variableResolvers.put( s,
+ new MapVariableResolver( variables,
+ s ) );
+ }
+ }
}
- /**
- * This is not used in drools.
- */
- public VariableResolver createVariable(String arg0, Object arg1, Class arg2) {
- return null;
+ private void addResolver(String name,
+ VariableResolver vr) {
+ if (variableResolvers == null) variableResolvers = new HashMap();
+ variableResolvers.put( name,
+ vr );
}
- // public ValueHandler createExternalVariable(String identifier) {
- // registerExternalVariable( identifier );
- // ValueHandler variable;
- // if ( this.declarations.containsKey( identifier )) {
- // variable = new DroolsMVELDeclarationVariable( (Declaration) this.declarations.get( identifier ), this );
- // } else {
- // variable = new DroolsMVELGlobalVariable( identifier, (Class) this.globals.get( identifier ), this );
- // }
- // return variable;
- // return null;
- // }
- //
- // public boolean isValidVariable(String identifier) {
- // return this.declarations.containsKey( identifier );
- // }
- //
- // public Declaration[] getRequiredDeclarations() {
- // List list = new ArrayList();
- // for (int i = 0, length = this.requiredVariables.length; i < length; i++) {
- // list.add( this.declarations.get( this.requiredVariables[i] ) );
- // }
- // return (Declaration[]) list.toArray( new Declaration[list.size() ] );
- // }
+ public boolean isTarget(String name) {
+ return variableResolvers.containsKey( name );
+ }
}
More information about the jboss-svn-commits
mailing list