[jbpm-commits] JBoss JBPM SVN: r6133 - in jbpm4/trunk: modules/pvm and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jan 26 11:33:44 EST 2010


Author: tom.baeyens at jboss.com
Date: 2010-01-26 11:33:43 -0500 (Tue, 26 Jan 2010)
New Revision: 6133

Added:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContext.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactory.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactoryImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmVariableElResolver.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JstlFunction.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/el/
Modified:
   jbpm4/trunk/modules/pvm/pom.xml
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/trunk/pom.xml
Log:
JBPM-2653 added first pieces of uel expression resolving infrastructure

Modified: jbpm4/trunk/modules/pvm/pom.xml
===================================================================
--- jbpm4/trunk/modules/pvm/pom.xml	2010-01-26 12:39:12 UTC (rev 6132)
+++ jbpm4/trunk/modules/pvm/pom.xml	2010-01-26 16:33:43 UTC (rev 6133)
@@ -171,6 +171,11 @@
       <artifactId>servlet-api</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>javax.enterprise</groupId>
+      <artifactId>cdi-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
   <!-- Plugins -->

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.el;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
+import org.jbpm.pvm.internal.task.TaskImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JbpmConstantsElResolver extends ELResolver {
+
+  private static final String NAME_EXECUTION = "execution";
+  private static final String NAME_PROCESSINSTANCE = "processInstance";
+  private static final String NAME_TASK = "task";
+
+  ExecutionImpl execution;
+  ExecutionImpl processInstance;
+  TaskImpl task;
+  
+  public JbpmConstantsElResolver(ScopeInstanceImpl scopeInstance) {
+    if (scopeInstance instanceof ExecutionImpl) {
+      this.execution = (ExecutionImpl) scopeInstance;
+      this.processInstance = execution.getProcessInstance();
+      
+    } else {
+      this.task = (TaskImpl) scopeInstance;
+      this.execution = task.getExecution();
+      if (this.execution!=null) {
+        this.processInstance = execution.getProcessInstance();
+      }
+    }
+  }
+  
+  public Object getValue(ELContext context, Object base, Object property) {
+    // this resolver only resolves top level variable names to execution variable names.
+    // only handle if this is a top level variable
+    if (base==null) {
+      // we assume a NPE-check for property is not needed
+      // i don't think the next cast can go wrong.  can it?
+      String name = (String) property;
+
+      if (execution!=null && NAME_EXECUTION.equals(name)) {
+        context.setPropertyResolved(true);
+        return execution;
+      }
+        
+      if (processInstance!=null && NAME_PROCESSINSTANCE.equals(name)) {
+        context.setPropertyResolved(true);
+        return processInstance;
+      }
+        
+      if (task!=null && NAME_TASK.equals(name)) {
+        context.setPropertyResolved(true);
+        return task;
+      }
+    }
+
+    return null;
+  }
+
+  public boolean isReadOnly(ELContext context, Object base, Object property) {
+    // this resolver only resolves top level variable names to execution variable names.
+    // only handle if this is a top level variable
+    if (base==null) {
+      // we assume a NPE-check for property is not needed
+      // i don't think the next cast can go wrong.  can it?
+      String name = (String) property;
+
+      if (NAME_EXECUTION.equals(name)
+          || NAME_PROCESSINSTANCE.equals(name)
+          || NAME_TASK.equals(name)) {
+        return true;
+      }
+    }
+
+    return true;
+  }
+
+  public void setValue(ELContext context, Object base, Object property, Object value) {
+  }
+
+  public Class< ? > getType(ELContext context, Object base, Object property) {
+    return Object.class;
+  }
+  public Class< ? > getCommonPropertyType(ELContext context, Object base) {
+    return Object.class;
+  }
+  public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
+    return null;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmConstantsElResolver.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContext.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContext.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContext.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.el;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JbpmElContext extends ELContext {
+  
+  ELResolver elResolver;
+  FunctionMapper functionMapper;
+  
+  public JbpmElContext(ELResolver elResolver, FunctionMapper functionMapper) {
+    this.elResolver = elResolver;
+    this.functionMapper = functionMapper;
+  }
+
+  public ELResolver getELResolver() {
+    return elResolver;
+  }
+
+  public FunctionMapper getFunctionMapper() {
+    return functionMapper;
+  }
+
+  public VariableMapper getVariableMapper() {
+    return null;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContext.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactory.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactory.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactory.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.el;
+
+import javax.el.ELContext;
+
+import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
+
+/**
+ * @author Tom Baeyens
+ */
+public interface JbpmElContextFactory {
+
+  ELContext createElContext();
+  ELContext createElContext(ScopeInstanceImpl scopeInstance);
+}
\ No newline at end of file


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactory.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactoryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactoryImpl.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactoryImpl.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.el;
+
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JbpmElContextFactoryImpl implements JbpmElContextFactory {
+  
+  private static Log log = Log.getLog(JbpmElContextFactoryImpl.class.getName());
+  
+  Class<?> functionClass = JstlFunction.class;
+  
+  /** create ElContext used during parsing time */
+  public ELContext createElContext() {
+    return createCompositeResolver(null);
+  }
+  
+  /** create ElContext used during evaluation time related to an execution */
+  public ELContext createElContext(ScopeInstanceImpl scopeInstance) {
+    return createCompositeResolver(scopeInstance);
+  }
+  
+  protected ELContext createCompositeResolver(ScopeInstanceImpl scopeInstance) {
+    CompositeELResolver compositeELResolver = new CompositeELResolver();
+    
+    if (scopeInstance!=null) {
+      compositeELResolver.add(new JbpmConstantsElResolver(scopeInstance));
+      compositeELResolver.add(new JbpmVariableElResolver(scopeInstance));
+    }
+
+    EnvironmentImpl environment = EnvironmentImpl.getCurrent();
+    if (environment!=null) {
+      compositeELResolver.add(new JbpmEnvironmentElResolver(environment));
+    }
+    
+    addCdiResolver(compositeELResolver);
+
+    addBasicResolvers(compositeELResolver);
+    
+    FunctionMapper functionMapper = createFunctionMapper();
+    
+    return createElContext(compositeELResolver, functionMapper);
+  }
+
+  protected void addCdiResolver(CompositeELResolver compositeELResolver) {
+    try {
+      InitialContext initialContext = new InitialContext();
+      Object object = initialContext.lookup("java:comp/BeanManager");
+      if (object!=null) {
+        BeanManager beanManager = (BeanManager) object;
+        ELResolver cdiResolver = beanManager.getELResolver();
+        if (cdiResolver!=null) {
+          compositeELResolver.add(cdiResolver);
+          log.debug("added cdi el resolver");
+        }
+      }
+    } catch (NamingException e) {
+      log.debug("no cdi bean manager available in jndi");
+    }
+  }
+
+  protected void addBasicResolvers(CompositeELResolver compositeELResolver) {
+    compositeELResolver.add(new BeanELResolver());
+    compositeELResolver.add(new MapELResolver());
+    compositeELResolver.add(new ListELResolver());
+    compositeELResolver.add(new ArrayELResolver());
+  }
+
+  protected FunctionMapper createFunctionMapper() {
+    return new JbpmFunctionMapper(functionClass);
+  }
+
+  protected JbpmElContext createElContext(CompositeELResolver compositeELResolver, FunctionMapper functionMapper) {
+    return new JbpmElContext(compositeELResolver, functionMapper);
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElContextFactoryImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.el;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JbpmEnvironmentElResolver extends ELResolver {
+  
+  EnvironmentImpl environment;
+  
+  public JbpmEnvironmentElResolver(EnvironmentImpl environment) {
+    this.environment = environment;
+  }
+
+  public Object getValue(ELContext context, Object base, Object property) {
+    // this resolver only resolves top level variable names to execution variable names.
+    // only handle if this is a top level variable
+    if (base==null) {
+      // we assume a NPE-check for property is not needed
+      // i don't think the next cast can go wrong.  can it?
+      String name = (String) property;
+
+      Object object = environment.get(name);
+      if (object!=null) {
+        context.setPropertyResolved(true);
+        return object;
+      }
+    }
+
+    return null;
+  }
+
+  public boolean isReadOnly(ELContext context, Object base, Object property) {
+    return true;
+  }
+
+  public void setValue(ELContext context, Object base, Object property, Object value) {
+  }
+
+  public Class< ? > getType(ELContext context, Object base, Object property) {
+    return Object.class;
+  }
+  public Class< ? > getCommonPropertyType(ELContext context, Object base) {
+    return Object.class;
+  }
+  public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
+    return null;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.el;
+
+import java.lang.reflect.Method;
+
+import javax.el.FunctionMapper;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JbpmFunctionMapper extends FunctionMapper {
+  
+  Class<?> functionClass;
+  
+  public JbpmFunctionMapper(Class< ? > funtionClass) {
+    this.functionClass = funtionClass;
+  }
+
+  public Method resolveFunction(String prefix, String localName) {
+    for (Method method: functionClass.getDeclaredMethods()) {
+      if (method.getName().equals(localName)) {
+        return method;
+      }
+    }
+    return null;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmVariableElResolver.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmVariableElResolver.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmVariableElResolver.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.el;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+
+import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JbpmVariableElResolver extends CompositeELResolver {
+
+  ScopeInstanceImpl scopeInstance;
+  
+  public JbpmVariableElResolver(ScopeInstanceImpl scopeInstance) {
+    this.scopeInstance = scopeInstance;
+  }
+
+  public Object getValue(ELContext context, Object base, Object property) {
+    // this resolver only resolves top level variable names to execution variable names.
+    // only handle if this is a top level variable
+    if (base==null) {
+      // we assume a NPE-check for property is not needed
+      // i don't think the next cast can go wrong.  can it?
+      String name = (String) property;
+
+      if (scopeInstance.hasVariable(name)) {
+        context.setPropertyResolved(true);
+        return scopeInstance.getVariable(name);
+      }
+    }
+
+    return null;
+  }
+
+  public boolean isReadOnly(ELContext context, Object base, Object property) {
+    // this resolver only resolves top level variable names to execution variable names.
+    // only handle if this is a top level variable
+    if (base==null) {
+      // we assume a NPE-check for property is not needed
+      // i don't think the next cast can go wrong.  can it?
+      String name = (String) property;
+
+      if (scopeInstance.hasVariable(name)) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  public void setValue(ELContext context, Object base, Object property, Object value) {
+    // this resolver only resolves top level variable names to execution variable names.
+    // only handle if this is a top level variable
+    if (base==null) {
+      // we assume a NPE-check for property is not needed
+      // i don't think the next cast can go wrong.  can it?
+      String variableName = (String) property;
+
+      if (scopeInstance.hasVariable(variableName)) {
+        scopeInstance.setVariable(variableName, value);
+      }
+    }
+  }
+
+  public Class< ? > getType(ELContext context, Object base, Object property) {
+    return Object.class;
+  }
+  public Class< ? > getCommonPropertyType(ELContext context, Object base) {
+    return Object.class;
+  }
+  public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
+    return null;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmVariableElResolver.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JstlFunction.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JstlFunction.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JstlFunction.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -0,0 +1,330 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License").  You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code.  If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license."  If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above.  However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Licensed 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.jbpm.pvm.internal.el;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+/**
+ * Implementations of JSTL Functions
+ * 
+ * @author Jacob Hookom
+ * @version $Id: JstlFunction.java 7265 2009-05-01 19:46:08Z rlubke $
+ */
+public final class JstlFunction {
+
+  private JstlFunction() {
+  }
+
+  public static boolean contains(String name, String searchString) {
+    if (name == null) {
+      name = "";
+    }
+    if (searchString == null) {
+      searchString = "";
+    }
+    return name.contains(searchString);
+  }
+
+  public static boolean containsIgnoreCase(String name, String searchString) {
+    if (name == null) {
+      name = "";
+    }
+    if (searchString == null) {
+      searchString = "";
+    }
+    return name.toLowerCase().contains(searchString.toLowerCase());
+  }
+
+  public static boolean endsWith(String name, String searchString) {
+    if (name == null) {
+      name = "";
+    }
+    if (searchString == null) {
+      searchString = "";
+    }
+    return name.endsWith(searchString);
+  }
+
+  public static String escapeXml(String value) {
+    if (value == null || value.length() == 0) {
+      value = "";
+    }
+    StringBuilder b = new StringBuilder(value.length());
+    final char[] lookahead = { 'a', 'm', 'p', ';' };
+    for (int i = 0, len = value.length(); i < len; i++) {
+      char c = value.charAt(i);
+      if (c == '<') {
+        b.append("&lt;");
+      } else if (c == '>') {
+        b.append("&gt;");
+      } else if (c == '\'') {
+        b.append("&#039;");
+      } else if (c == '"') {
+        b.append("&#034;");
+      } else if (c == '&') {
+        boolean matched = true;
+        for (int j = 0, jlen = lookahead.length; j < jlen; j++) {
+          if (lookahead[j] != value.charAt(i + (j + 1))) {
+            matched = false;
+            break;
+          }
+        }
+        if (matched) {
+          i += 4;
+        }
+        b.append("&amp;");
+      } else {
+        b.append(c);
+      }
+    }
+    return b.toString();
+  }
+
+  public static int indexOf(String name, String searchString) {
+    if (name == null) {
+      name = "";
+    }
+    if (searchString == null) {
+      searchString = "";
+    }
+    return name.indexOf(searchString);
+  }
+
+  public static String join(String[] a, String delim) {
+    if (a == null || a.length == 0) {
+      return "";
+    }
+    boolean skipDelim = false;
+    if (delim == null || delim.length() == 0) {
+      skipDelim = true;
+    }
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0, len = a.length, delimCount = (len - 1); i < len; i++) {
+      sb.append(a[i]);
+      if (!skipDelim && (i < delimCount)) {
+        sb.append(delim);
+      }
+    }
+    return sb.toString();
+  }
+
+  public static int length(Object obj) {
+    if (obj == null) {
+      return 0;
+    }
+    if (obj instanceof Collection) {
+      return ((Collection) obj).size();
+    }
+    if (obj.getClass().isArray()) {
+      return Array.getLength(obj);
+    }
+    if (obj instanceof String) {
+      return ((String) obj).length();
+    }
+    if (obj instanceof Map) {
+      return ((Map) obj).size();
+    }
+    if (obj instanceof Enumeration) {
+      Enumeration e = (Enumeration) obj;
+      int count = 0;
+      while (e.hasMoreElements()) {
+        e.nextElement();
+        count++;
+      }
+      return count;
+    }
+    if (obj instanceof Iterator) {
+      Iterator i = (Iterator) obj;
+      int count = 0;
+      while (i.hasNext()) {
+        i.next();
+        count++;
+      }
+      return count;
+    }
+    throw new IllegalArgumentException("Object type not supported: " + obj.getClass().getName());
+  }
+
+  public static String replace(String value, String before, String after) {
+    if (value == null) {
+      value = "";
+    }
+    if (before == null) {
+      before = "";
+    }
+    if (before.length() == 0) {
+      return value;
+    }
+    if (value.length() == 0) {
+      return "";
+    }
+    if (after == null) {
+      after = "";
+    }
+
+    return value.replaceAll(before, after);
+  }
+
+  public static String[] split(String value, String d) {
+    if (value == null) {
+      value = "";
+    }
+    if (value.length() == 0) {
+      return new String[] { "" };
+    }
+    if (d == null) {
+      d = "";
+    }
+    if (d.length() == 0) {
+      return new String[] { value };
+    }
+
+    List<String> tokens = new ArrayList<String>();
+    for (StringTokenizer st = new StringTokenizer(value, d); st.hasMoreTokens();) {
+      tokens.add(st.nextToken());
+    }
+
+    return tokens.toArray(new String[tokens.size()]);
+  }
+
+  public static boolean startsWith(String value, String p) {
+    if (value == null) {
+      value = "";
+    }
+    if (p == null) {
+      p = "";
+    }
+    return value.startsWith(p);
+  }
+
+  public static String substring(String v, int s, int e) {
+    if (v == null) {
+      v = "";
+    }
+    if (s >= v.length()) {
+      return "";
+    }
+    if (s < 0) {
+      s = 0;
+    }
+    if (e < 0 || e >= v.length()) {
+      e = v.length();
+    }
+    if (e < s) {
+      return "";
+    }
+    return v.substring(s, e);
+  }
+
+  public static String substringAfter(String v, String p) {
+    if (v == null) {
+      v = "";
+    }
+    if (v.length() == 0) {
+      return "";
+    }
+    if (p == null) {
+      p = "";
+    }
+    int i = v.indexOf(p);
+    if (i == -1) {
+      return "";
+    }
+    return v.substring(i + p.length());
+  }
+
+  public static String substringBefore(String v, String s) {
+    if (v == null) {
+      v = "";
+    }
+    if (v.length() == 0) {
+      return "";
+    }
+    if (s == null) {
+      s = "";
+    }
+    int i = v.indexOf(s);
+    if (i == -1) {
+      return "";
+    }
+    return v.substring(0, i);
+  }
+
+  public static String toLowerCase(String v) {
+    if (v == null || v.length() == 0) {
+      return "";
+    }
+    return v.toLowerCase();
+  }
+
+  public static String toUpperCase(String v) {
+    if (v == null || v.length() == 0) {
+      return "";
+    }
+    return v.toUpperCase();
+  }
+
+  public static String trim(String v) {
+    if (v == null || v.length() == 0) {
+      return "";
+    }
+    return v.trim();
+  }
+
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JstlFunction.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2010-01-26 12:39:12 UTC (rev 6132)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2010-01-26 16:33:43 UTC (rev 6133)
@@ -34,11 +34,14 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
-import org.hibernate.Session;
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+
 import org.jbpm.api.Execution;
 import org.jbpm.api.JbpmException;
 import org.jbpm.api.activity.ActivityExecution;
-import org.jbpm.api.cmd.Environment;
 import org.jbpm.api.job.Job;
 import org.jbpm.api.job.Timer;
 import org.jbpm.api.listener.EventListenerExecution;
@@ -51,6 +54,8 @@
 import org.jbpm.internal.log.Log;
 import org.jbpm.pvm.internal.client.ClientProcessDefinition;
 import org.jbpm.pvm.internal.client.ClientProcessInstance;
+import org.jbpm.pvm.internal.el.JbpmElContextFactory;
+import org.jbpm.pvm.internal.el.JbpmElContextFactoryImpl;
 import org.jbpm.pvm.internal.env.Context;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
 import org.jbpm.pvm.internal.env.ExecutionContext;
@@ -159,6 +164,8 @@
   protected int eventListenerIndex;
 
   protected ObservableElementImpl eventSource;
+  
+  protected Object cachedElContext = null;
 
   // cached named executions //////////////////////////////////////////////////
   
@@ -674,7 +681,34 @@
       atomicOperations.offer(operation);
     }
   }
-  
+
+  public Object resolveElValueExpressionGet(ValueExpression valueExpression) {
+    initCachedElContext();
+    return valueExpression.getValue((ELContext) cachedElContext);
+  }
+
+  public void resolveElValueExpressionSet(ValueExpression valueExpression, Object value) {
+    initCachedElContext();
+    valueExpression.setValue((ELContext) cachedElContext, value);
+  }
+
+  public void resolveElMethodExpressionInvoke(MethodExpression methodExpression) {
+    initCachedElContext();
+    Object[] params = new Object[]{};
+    // TODO figure out how to resolve the params
+    methodExpression.invoke((ELContext) cachedElContext, params);
+  }
+
+  protected void initCachedElContext() {
+    if (cachedElContext==null) {
+      JbpmElContextFactory contextFactory = EnvironmentImpl.getFromCurrent(JbpmElContextFactory.class, false);
+      if (contextFactory==null) {
+        contextFactory = new JbpmElContextFactoryImpl();
+      }
+      cachedElContext = contextFactory.createElContext(this);
+    }
+  }
+
   /** 
    * Important: Only use this if resolving an expression on another execution then the current execution
    * 

Modified: jbpm4/trunk/pom.xml
===================================================================
--- jbpm4/trunk/pom.xml	2010-01-26 12:39:12 UTC (rev 6132)
+++ jbpm4/trunk/pom.xml	2010-01-26 16:33:43 UTC (rev 6133)
@@ -77,6 +77,7 @@
     <postgresql.version>8.3-603.jdbc3</postgresql.version>
     <jtds.version>1.2.2</jtds.version>
     <oracle.version>10.2.0.4</oracle.version>
+    <cdi.version>1.0</cdi.version>
 	</properties>
 
   <!-- DependencyManagement -->
@@ -415,6 +416,11 @@
         <artifactId>jtds</artifactId>
         <version>${jtds.version}</version>
       </dependency>
+      <dependency>
+        <groupId>javax.enterprise</groupId>
+        <artifactId>cdi-api</artifactId>
+        <version>${cdi.version}</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 



More information about the jbpm-commits mailing list