KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > data > exe > VariableInstance


1 package org.jbpm.bpel.data.exe;
2
3 import javax.xml.namespace.QName JavaDoc;
4
5 import org.w3c.dom.Node JavaDoc;
6
7 import org.jbpm.bpel.data.def.VariableDefinition;
8 import org.jbpm.bpel.wsdl.def.PropertyAlias;
9 import org.jbpm.bpel.xml.util.NodeUtil;
10
11 /**
12  * @author Alejandro Guízar
13  * @version $Revision: 1.3 $ $Date: 2005/06/23 02:22:46 $
14  */

15 public abstract class VariableInstance {
16   
17   private VariableDefinition definition;
18   
19   protected VariableInstance() {
20   }
21   
22   public VariableDefinition getDefinition() {
23     return definition;
24   }
25   
26   public void setDefinition(VariableDefinition definition) {
27     this.definition = definition;
28   }
29   
30   public abstract Object JavaDoc getValue();
31   
32   public abstract void setValue(Object JavaDoc value);
33   
34   public abstract Object JavaDoc getOrCreateValue();
35   
36   public Object JavaDoc getProperty(QName JavaDoc propertyName) {
37     PropertyAlias alias = definition.getTypeInfo().getPropertyAlias(propertyName);
38     if (alias == null) {
39       throw new RuntimeException JavaDoc("Selection failure (property does not appear in variable's type):" +
40           " variable=" + definition.getName() + ", property=" + propertyName);
41     }
42     Object JavaDoc value = alias.getQuery().getScript().evaluate(getValue());
43     if (value instanceof Node JavaDoc) {
44       value = NodeUtil.getValue((Node JavaDoc) value);
45     }
46     return value;
47   }
48   
49   public void setProperty(QName JavaDoc propertyName, Object JavaDoc value) {
50     PropertyAlias alias = definition.getTypeInfo().getPropertyAlias(propertyName);
51     if (alias == null) {
52       throw new RuntimeException JavaDoc("Selection failure (property does not appear in variable's type):" +
53           " variable=" + definition.getName() + ", property=" + propertyName);
54     }
55     alias.getQuery().getScript().assign(getOrCreateValue(), value);
56   }
57 }
58
Popular Tags