KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > shark > mapping > EntityApplicationMap


1 /*
2  * $Id: EntityApplicationMap.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.mapping;
26
27 import org.ofbiz.entity.GenericEntityException;
28 import org.ofbiz.entity.GenericDelegator;
29 import org.ofbiz.entity.GenericValue;
30 import org.ofbiz.base.util.UtilMisc;
31 import org.ofbiz.shark.container.SharkContainer;
32
33 import org.enhydra.shark.api.internal.appmappersistence.ApplicationMap;
34 import org.enhydra.shark.api.RootException;
35
36 /**
37  * Shark Application Map Implementation
38  *
39  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
40  * @version $Rev: 5462 $
41  * @since 3.1
42  */

43 public class EntityApplicationMap implements ApplicationMap {
44
45     protected GenericDelegator delegator = null;
46     protected GenericValue application = null;
47     protected boolean isNew = false;
48     
49     protected EntityApplicationMap(GenericDelegator delegator, String JavaDoc packageId, String JavaDoc processDefId, String JavaDoc applicationDefId) throws RootException {
50         this.delegator = delegator;
51         try {
52             this.application = delegator.findByPrimaryKey("WfApplicationMap", UtilMisc.toMap("packageId", packageId, "processDefId", processDefId, "applicationDefId", applicationDefId));
53         } catch (GenericEntityException e) {
54             throw new RootException(e);
55         }
56     }
57
58     protected EntityApplicationMap(GenericValue application) {
59         this.application = application;
60         this.delegator = application.getDelegator();
61     }
62
63     public EntityApplicationMap(GenericDelegator delegator) {
64         this.isNew = true;
65         this.delegator = delegator;
66         this.application = delegator.makeValue("SharkApplicationMap", null);
67     }
68
69     public static EntityApplicationMap getInstance(GenericValue application) {
70         EntityApplicationMap app = new EntityApplicationMap(application);
71         if (app.isLoaded()) {
72             return app;
73         }
74         return null;
75     }
76
77     public static EntityApplicationMap getInstance(String JavaDoc packageId, String JavaDoc processDefId, String JavaDoc applicationDefId) throws RootException {
78         EntityApplicationMap act = new EntityApplicationMap(SharkContainer.getDelegator(), packageId, processDefId, applicationDefId);
79         if (act.isLoaded()) {
80             return act;
81         }
82         return null;
83     }
84
85     public boolean isLoaded() {
86         if (application == null) {
87             return false;
88         }
89         return true;
90     }
91
92     public void setApplicationDefinitionId(String JavaDoc applicationDefId) {
93         application.set("applicationDefId", applicationDefId);
94     }
95
96     public String JavaDoc getApplicationDefinitionId() {
97         return application.getString("applicationDefId");
98     }
99
100     public void setPackageId(String JavaDoc packageId) {
101         application.set("packageId", packageId);
102     }
103
104     public String JavaDoc getPackageId() {
105         return application.getString("applicationName");
106     }
107
108     public void setProcessDefinitionId(String JavaDoc processDefId) {
109         application.set("processDefId", processDefId);
110     }
111
112     public String JavaDoc getProcessDefinitionId() {
113         return application.getString("processDefId");
114     }
115
116     public void setToolAgentClassName(String JavaDoc toolAgentName) {
117         application.set("toolAgentName", toolAgentName);
118     }
119
120     public String JavaDoc getToolAgentClassName() {
121         return application.getString("toolAgentName");
122     }
123
124     public void setUsername(String JavaDoc userName) {
125         application.set("userName", userName);
126     }
127
128     public String JavaDoc getUsername() {
129         return application.getString("userName");
130     }
131
132     public void setPassword(String JavaDoc password) {
133         application.set("password", password);
134     }
135
136     public String JavaDoc getPassword() {
137         return application.getString("password");
138     }
139
140     public void setApplicationName(String JavaDoc name) {
141         application.set("applicationName", name);
142     }
143
144     public String JavaDoc getApplicationName() {
145         return application.getString("applicationName");
146     }
147
148     public void setApplicationMode(Integer JavaDoc mode) {
149         application.set("applicationMode", mode);
150     }
151
152     public Integer JavaDoc getApplicationMode() {
153         return application.getInteger("applicationMode");
154     }
155
156     public boolean equalsByKeys(ApplicationMap applicationMap) {
157         if (applicationMap == null ) return false;
158
159         if ((applicationMap.getPackageId() != null && this.getPackageId() != null))
160             if (!(applicationMap.getPackageId().equals(this.getPackageId())))
161                 return false;
162
163         if ((applicationMap.getProcessDefinitionId() != null && this.getProcessDefinitionId() != null))
164             if( !(applicationMap.getProcessDefinitionId().equals(this.getProcessDefinitionId())))
165                 return false;
166
167         if ((applicationMap.getApplicationDefinitionId() != null && this.getApplicationDefinitionId() != null))
168             if (!(applicationMap.getApplicationDefinitionId().equals(this.getApplicationDefinitionId())))
169                 return false;
170
171         if ((applicationMap.getToolAgentClassName() != null && this.getToolAgentClassName() != null))
172             if (!(applicationMap.getToolAgentClassName().equals(this.getToolAgentClassName())))
173                 return false;
174
175         return true;
176     }
177
178     public void store() throws RootException {
179         if (isNew) {
180             try {
181                 delegator.create(application);
182             } catch (GenericEntityException e) {
183                 throw new RootException(e);
184             }
185         } else {
186             try {
187                 delegator.store(application);
188             } catch (GenericEntityException e) {
189                 throw new RootException(e);
190             }
191         }
192     }
193
194     public void reload() throws RootException {
195         if (!isNew) {
196             try {
197                 delegator.refresh(application);
198             } catch (GenericEntityException e) {
199                 throw new RootException(e);
200             }
201         }
202     }
203
204     public void remove() throws RootException {
205         if (!isNew) {
206             try {
207                 delegator.removeValue(application);
208             } catch (GenericEntityException e) {
209                 throw new RootException(e);
210             }
211         }
212     }
213 }
214
Popular Tags