KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: Resource.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.entity.GenericDelegator;
28 import org.ofbiz.entity.GenericValue;
29 import org.ofbiz.entity.GenericEntityException;
30 import org.ofbiz.base.util.UtilMisc;
31 import org.ofbiz.base.util.Debug;
32 import org.ofbiz.shark.container.SharkContainer;
33
34 import org.enhydra.shark.api.internal.instancepersistence.*;
35
36 /**
37  * Persistance Object
38  *
39  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
40  * @version $Rev: 5462 $
41  * @since 3.1
42  */

43 public class Resource extends InstanceEntityObject implements ResourcePersistenceInterface {
44
45     public static final String JavaDoc module = Resource.class.getName();
46
47     protected GenericValue resource = null;
48     protected boolean newValue = false;
49
50     protected Resource(EntityPersistentMgr mgr, GenericDelegator delegator, String JavaDoc name) throws PersistenceException {
51         super(mgr, delegator);
52         if (this.delegator != null) {
53             try {
54                 this.resource = delegator.findByPrimaryKey("WfResource", UtilMisc.toMap("userName", name));
55             } catch (GenericEntityException e) {
56                 throw new PersistenceException(e);
57             }
58         } else {
59             Debug.logError("Invalid delegator object passed", module);
60         }
61     }
62
63     protected Resource(EntityPersistentMgr mgr, GenericValue resource) {
64         super(mgr, resource.getDelegator());
65         this.resource = resource;
66     }
67
68     public Resource(EntityPersistentMgr mgr, GenericDelegator delegator) {
69         super(mgr, delegator);
70         this.newValue = true;
71         this.resource = delegator.makeValue("WfResource", null);
72     }
73
74     public static Resource getInstance(EntityPersistentMgr mgr, GenericValue resource) {
75         Resource res = new Resource(mgr, resource);
76         if (res.isLoaded()) {
77             return res;
78         }
79         return null;
80     }
81
82     public static Resource getInstance(EntityPersistentMgr mgr, String JavaDoc name) throws PersistenceException {
83         Resource res = new Resource(mgr, SharkContainer.getDelegator(), name);
84         if (res.isLoaded()) {
85             return res;
86         }
87         return null;
88     }
89
90     public boolean isLoaded() {
91         if (resource == null) {
92             return false;
93         }
94         return true;
95     }
96
97     public void setUsername(String JavaDoc s) {
98         resource.set("userName", s);
99     }
100
101     public String JavaDoc getUsername() {
102         return resource.getString("userName");
103     }
104
105     public void setName(String JavaDoc s) {
106         resource.set("resourceName", s);
107     }
108
109     public String JavaDoc getName() {
110         return resource.getString("resourceName");
111     }
112
113     public void store() throws GenericEntityException {
114         if (newValue) {
115             delegator.createOrStore(resource);
116             newValue = false;
117         } else {
118             delegator.store(resource);
119         }
120     }
121
122     public void reload() throws GenericEntityException {
123         if (!newValue) {
124             resource.refresh();
125         }
126     }
127
128     public void remove() throws GenericEntityException {
129         if (!newValue) {
130             delegator.removeValue(resource);
131             Debug.log("**** REMOVED : " + this, module);
132         }
133     }
134 }
135
Popular Tags