[jboss-svn-commits] JBL Code SVN: r24903 - labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jan 23 14:46:52 EST 2009
Author: salaboy21
Date: 2009-01-23 14:46:52 -0500 (Fri, 23 Jan 2009)
New Revision: 24903
Added:
labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3PersistedVariable.java
labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3VariableConverter.java
labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3VariableTypeFinder.java
labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/PersistedVariable.java
labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariableConverter.java
labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariablePersistenceStrategy.java
labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariablePersistenceStrategyFactory.java
labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariableTypeFinder.java
Log:
new classes to store dinamically the process variables
Added: labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3PersistedVariable.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3PersistedVariable.java (rev 0)
+++ labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3PersistedVariable.java 2009-01-23 19:46:52 UTC (rev 24903)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2009 salaboy.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.drools.persistence.processinstance;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.Transient;
+import org.hibernate.annotations.Any;
+import org.hibernate.annotations.AnyMetaDef;
+import org.hibernate.annotations.Cascade;
+import org.hibernate.annotations.CascadeType;
+import org.hibernate.annotations.MetaValue;
+
+
+
+/**
+ *
+ * @author salaboy
+ */
+
+ at Entity
+public class EJB3PersistedVariable extends PersistedVariable {
+
+
+ @Transient
+ private Object realVariable;
+
+ /**
+ * @return the realVariable
+ */
+
+ public Object getRealVariable() {
+ return realVariable;
+ }
+
+ /**
+ * @param realVariable the realVariable to set
+ */
+
+ public void setRealVariable(Object realVariable) {
+ this.realVariable = realVariable;
+ }
+
+
+ public EJB3PersistedVariable(){
+ setConverter(this.getClass().toString());
+ }
+
+ @Override
+ public String getConverter() {
+ return getConverter();
+ }
+
+
+
+
+}
Added: labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3VariableConverter.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3VariableConverter.java (rev 0)
+++ labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3VariableConverter.java 2009-01-23 19:46:52 UTC (rev 24903)
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2009 salaboy.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.drools.persistence.processinstance;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ *
+ * @author salaboy
+ */
+public class EJB3VariableConverter implements VariableConverter {
+
+ @PersistenceContext EntityManager em;
+
+ public PersistedVariable convertToPersistedVariable(String name, Object o) {
+ PersistedVariable variable = new EJB3PersistedVariable();
+ try {
+
+ variable.setName(name);
+ Field id = o.getClass().getDeclaredField("id");
+ //((EJB3PersistedVariable)variable).setRealVariable(o);
+
+ } catch (NoSuchFieldException ex) {
+ Logger.getLogger(EJB3VariableConverter.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (SecurityException ex) {
+ Logger.getLogger(EJB3VariableConverter.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return variable;
+ }
+
+ public Object convertFromPersistedVariable(PersistedVariable variable) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+}
Added: labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3VariableTypeFinder.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3VariableTypeFinder.java (rev 0)
+++ labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/EJB3VariableTypeFinder.java 2009-01-23 19:46:52 UTC (rev 24903)
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2009 salaboy.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.drools.persistence.processinstance;
+
+/**
+ *
+ * @author salaboy
+ */
+public class EJB3VariableTypeFinder implements VariableTypeFinder{
+
+ public boolean accept(Object o) {
+ return true;
+ }
+
+ public String getType() {
+ return "org.drools.persistence.processinstance.EJB3PersistedVariable";
+ }
+
+}
Added: labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/PersistedVariable.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/PersistedVariable.java (rev 0)
+++ labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/PersistedVariable.java 2009-01-23 19:46:52 UTC (rev 24903)
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2009 salaboy.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.drools.persistence.processinstance;
+
+import java.io.Serializable;
+
+
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+import javax.persistence.JoinColumn;
+import org.hibernate.annotations.Any;
+import org.hibernate.annotations.AnyMetaDef;
+import org.hibernate.annotations.MetaValue;
+
+
+/**
+ *
+ * @author salaboy
+ */
+ at Entity
+ at Inheritance(strategy=InheritanceType.SINGLE_TABLE)
+ at DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.STRING,length=50)
+ at DiscriminatorValue("GEN")
+public class PersistedVariable implements Serializable {
+ @Id @GeneratedValue(strategy=GenerationType.AUTO)
+ private Long id;
+ private String name;
+ private String converter;
+
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ /**
+ * @return the converter
+ */
+ public String getConverter() {
+ return converter;
+ }
+
+ /**
+ * @param converter the converter to set
+ */
+ public void setConverter(String converter) {
+ this.converter = converter;
+ }
+
+
+
+
+}
Added: labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariableConverter.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariableConverter.java (rev 0)
+++ labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariableConverter.java 2009-01-23 19:46:52 UTC (rev 24903)
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2009 salaboy.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.drools.persistence.processinstance;
+
+/**
+ *
+ * @author salaboy
+ */
+
+public interface VariableConverter {
+ public PersistedVariable convertToPersistedVariable(String name, Object o);
+
+ public Object convertFromPersistedVariable(PersistedVariable variable);
+
+
+
+}
Added: labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariablePersistenceStrategy.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariablePersistenceStrategy.java (rev 0)
+++ labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariablePersistenceStrategy.java 2009-01-23 19:46:52 UTC (rev 24903)
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2009 salaboy.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.drools.persistence.processinstance;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author salaboy
+ */
+public class VariablePersistenceStrategy {
+ private Map<String, String> types = new HashMap<String, String>();
+ private List<VariableTypeFinder> finders = new ArrayList<VariableTypeFinder>();
+
+
+
+ @SuppressWarnings("unchecked")
+ public PersistedVariable persistVariable(String name, Object o){
+ PersistedVariable variable = null;
+ VariableConverter converter = null;
+ String converterFQN = resolveVariableTypeConverter(o);
+ if(converterFQN != null && !converterFQN.equals("")){
+ Class converterClass = null;
+ try {
+ converterClass = Class.forName(converterFQN);
+ Constructor constructor;
+ constructor = converterClass.getConstructor(null);
+ converter = (VariableConverter) constructor.newInstance(null);
+
+ } catch (ClassNotFoundException ex) {
+ Logger.getLogger(VariablePersistenceStrategy.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (NoSuchMethodException ex) {
+ Logger.getLogger(VariablePersistenceStrategy.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (SecurityException ex) {
+ Logger.getLogger(VariablePersistenceStrategy.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ Logger.getLogger(VariablePersistenceStrategy.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ Logger.getLogger(VariablePersistenceStrategy.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IllegalArgumentException ex) {
+ Logger.getLogger(VariablePersistenceStrategy.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (InvocationTargetException ex) {
+ Logger.getLogger(VariablePersistenceStrategy.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+
+ variable = converter.convertToPersistedVariable(name, o);
+
+ }
+ return variable;
+ }
+
+ public Object read(){
+ return new Object();
+ }
+
+ private String resolveVariableTypeConverter(Object o) {
+
+ for( VariableTypeFinder finder: getFinders()){
+ if(finder.accept(o)){
+ return (String) getTypes().get(finder.getType());
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the types
+ */
+ public Map<String, String> getTypes() {
+ return types;
+ }
+
+ /**
+ * @param types the types to set
+ */
+ public void setTypes(Map<String, String> types) {
+ this.types = types;
+ }
+
+ /**
+ * @return the finders
+ */
+ public List<VariableTypeFinder> getFinders() {
+ return finders;
+ }
+
+ /**
+ * @param finders the finders to set
+ */
+ public void setFinders(List<VariableTypeFinder> finders) {
+ this.finders = finders;
+ }
+
+
+
+}
Added: labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariablePersistenceStrategyFactory.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariablePersistenceStrategyFactory.java (rev 0)
+++ labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariablePersistenceStrategyFactory.java 2009-01-23 19:46:52 UTC (rev 24903)
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2009 salaboy.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.drools.persistence.processinstance;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ * @author salaboy
+ */
+public class VariablePersistenceStrategyFactory {
+ public VariablePersistenceStrategyFactory(){
+
+ }
+ public static VariablePersistenceStrategy getVariablePersistenceStrategyFactory(){
+ VariablePersistenceStrategy vPRS = new VariablePersistenceStrategy();
+ List<VariableTypeFinder> finders= new ArrayList<VariableTypeFinder>();
+ finders.add(new EJB3VariableTypeFinder());
+ vPRS.setFinders(finders);
+
+ Map<String, String> types = new HashMap<String, String>();
+ types.put("org.drools.persistence.processinstance.EJB3PersistedVariable", "org.drools.persistence.processinstance.EJB3VariableConverter");
+ vPRS.setTypes(types);
+ return vPRS;
+ }
+}
Added: labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariableTypeFinder.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariableTypeFinder.java (rev 0)
+++ labs/jbossrules/branches/salaboy_VariablePersistenceStrategy/drools-process/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/VariableTypeFinder.java 2009-01-23 19:46:52 UTC (rev 24903)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 salaboy.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.drools.persistence.processinstance;
+
+/**
+ *
+ * @author salaboy
+ */
+public interface VariableTypeFinder {
+
+ public boolean accept(Object o);
+ public String getType();
+
+}
More information about the jboss-svn-commits
mailing list