KickJava   Java API By Example, From Geeks To Geeks.

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


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

14 public class ElementVariableInstance extends VariableInstance {
15
16   private Element JavaDoc element;
17   
18   public Object JavaDoc getValue() {
19     return getElement();
20   }
21
22   public void setValue(Object JavaDoc value) {
23     NodeUtil.setValue(getOrCreateElement(), value);
24   }
25   
26   public Object JavaDoc getOrCreateValue() {
27     return getOrCreateElement();
28   }
29
30   public Element JavaDoc getElement() {
31     if (element == null) {
32       throw new RuntimeException JavaDoc("Uninitialized variable: variable=" + getDefinition().getName());
33     }
34     return element;
35   }
36   
37   public Element JavaDoc getOrCreateElement() {
38     if (element == null) {
39       QName JavaDoc type = getDefinition().getTypeInfo().getName();
40       Document JavaDoc doc = NodeUtil.createDocument();
41       element = doc.createElementNS(type.getNamespaceURI(), type.getLocalPart());
42       doc.appendChild(element);
43     }
44     return element;
45   }
46   
47   public void setElement(Element JavaDoc element) {
48     this.element = element;
49   }
50 }
51
Popular Tags