KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > shark > instance > ActivityVariable


1 /*
2  * $Id: ActivityVariable.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.shark.instance;
26
27 import org.ofbiz.base.util.Debug;
28 import org.ofbiz.base.util.UtilMisc;
29 import org.ofbiz.base.util.UtilObject;
30 import org.ofbiz.entity.GenericDelegator;
31 import org.ofbiz.entity.GenericEntityException;
32 import org.ofbiz.entity.GenericValue;
33 import org.ofbiz.shark.container.SharkContainer;
34
35 import org.enhydra.shark.api.internal.instancepersistence.ActivityVariablePersistenceInterface;
36 import org.enhydra.shark.api.internal.instancepersistence.PersistenceException;
37
38 /**
39  * Persistance Object
40  *
41  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
42  * @version $Rev: 5462 $
43  * @since 3.1
44  */

45 public class ActivityVariable extends InstanceEntityObject implements ActivityVariablePersistenceInterface {
46
47     public static final String JavaDoc module = ActivityVariable.class.getName();
48
49     protected GenericValue activityVariable = null;
50     protected boolean newValue = false;
51
52     protected ActivityVariable(EntityPersistentMgr mgr, GenericDelegator delegator, String JavaDoc activityVariableId) throws PersistenceException {
53         super(mgr, delegator);
54         this.delegator = delegator;
55         if (this.delegator != null) {
56             try {
57                 this.activityVariable = delegator.findByPrimaryKey("WfActivityVariable", UtilMisc.toMap("activityVariableId", activityVariableId));
58             } catch (GenericEntityException e) {
59                 throw new PersistenceException(e);
60             }
61         } else {
62             Debug.logError("Invalid delegator object passed", module);
63         }
64     }
65
66     protected ActivityVariable(EntityPersistentMgr mgr, GenericValue activityVariable) {
67         super(mgr, activityVariable.getDelegator());
68         this.activityVariable = activityVariable;
69     }
70
71     public ActivityVariable(EntityPersistentMgr mgr, GenericDelegator delegator) {
72         super(mgr, delegator);
73         this.newValue = true;
74         this.activityVariable = delegator.makeValue("WfActivityVariable", UtilMisc.toMap("activityVariableId", delegator.getNextSeqId("WfActivityVariable")));
75         Debug.log("******* New activity variable created", module);
76     }
77
78     public static ActivityVariable getInstance(EntityPersistentMgr mgr, GenericValue activityVariable) {
79         ActivityVariable var = new ActivityVariable(mgr, activityVariable);
80         if (var.isLoaded()) {
81             return var;
82         }
83         return null;
84     }
85
86     public static ActivityVariable getInstance(EntityPersistentMgr mgr, String JavaDoc activityVariableId) throws PersistenceException {
87         ActivityVariable var = new ActivityVariable(mgr, SharkContainer.getDelegator(), activityVariableId);
88         if (var.isLoaded()) {
89             return var;
90         }
91         return null;
92     }
93
94     public boolean isLoaded() {
95         if (activityVariable == null) {
96             return false;
97         }
98         return true;
99     }
100
101     public void setActivityId(String JavaDoc aId) {
102         activityVariable.set("activityId", aId);
103     }
104
105     public String JavaDoc getActivityId() {
106         return activityVariable.getString("activityId");
107     }
108
109     public void setDefinitionId(String JavaDoc defId) {
110         activityVariable.set("definitionId", defId);
111     }
112
113     public String JavaDoc getDefinitionId() {
114         return activityVariable.getString("definitionId");
115     }
116
117     public void setValue(Object JavaDoc val) {
118         if (val instanceof String JavaDoc) {
119             activityVariable.set("valueField", "strValue");
120             activityVariable.set("strValue", val);
121         } else if (val instanceof Number JavaDoc) {
122             if (val instanceof Double JavaDoc) {
123                 activityVariable.set("valueField", "dblValue");
124                 activityVariable.set("dblValue", val);
125             } else {
126                 activityVariable.set("valueField", "numValue");
127                 activityVariable.set("numValue", val);
128             }
129         } else {
130             byte[] value = UtilObject.getBytes(val);
131             activityVariable.setBytes("objValue", (value != null ? value : null));
132         }
133     }
134
135     public Object JavaDoc getValue() {
136         String JavaDoc fieldName = activityVariable.getString("valueField");
137         if ("objValue".equals(fieldName)) {
138             byte[] value = activityVariable.getBytes(fieldName);
139             return UtilObject.getObject(value);
140         } else {
141             return activityVariable.get(fieldName);
142         }
143     }
144
145     public void setResultVariable(boolean modified) {
146         activityVariable.set("isModified", (modified ? "Y" : "N"));
147     }
148
149     public boolean isResultVariable() {
150         return (activityVariable.get("isModified") != null ?
151                 ("Y".equals(activityVariable.getString("isModified")) ? true : false) : false);
152     }
153
154     public void store() throws GenericEntityException {
155         if (newValue) {
156             delegator.createOrStore(activityVariable);
157             newValue = false;
158         } else {
159             delegator.store(activityVariable);
160         }
161     }
162
163     public void reload() throws GenericEntityException {
164         if (!newValue) {
165             activityVariable.refresh();
166         }
167     }
168
169     public void remove() throws GenericEntityException {
170         if (!newValue) {
171             delegator.removeValue(activityVariable);
172         }
173     }
174 }
175
Popular Tags