001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.domains.enterprisemodel.impl;
016:
017: import javax.naming.Context;
018: import javax.naming.InitialContext;
019: import javax.naming.NamingException;
020:
021: import com.metaboss.enterprise.bo.BOException;
022: import com.metaboss.enterprise.bo.BOIllegalArgumentException;
023: import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
024: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
025: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
026: import com.metaboss.enterprise.ps.PSException;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOServicemodule;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOServicemoduleMessageList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOServicemoduleServiceList;
030: import com.metaboss.sdlctools.domains.enterprisemodel.BOServicemoduleStructureList;
031: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
032: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSServicemodule;
033: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STServicemodule;
034: import com.oldboss.framework.bo.BOTransaction;
035: import com.oldboss.framework.bo.impl.BOObjectImpl;
036:
037: public class BOServicemoduleImpl extends BOObjectImpl implements
038: BOServicemodule {
039: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
040: private BOSystem mSystem = null;
041: private String mServicemoduleRef = null;
042: private STServicemodule mDetails = null;
043:
044: /* Instance creator */
045: public static BOServicemodule createInstanceForExisting(
046: BOMetaBossDomainImpl pMetaBossDomainImpl,
047: String pServicemoduleRef) throws BOException {
048: // Servicemodule Ref must consist of three parts: enteprise name . system name . servicemodule name
049: int lFirstDot = pServicemoduleRef.indexOf(".");
050: int lLastDot = pServicemoduleRef.lastIndexOf(".");
051: if (lFirstDot < 0 || lFirstDot == lLastDot)
052: throw new BOException("Invalid ServicemoduleRef "
053: + pServicemoduleRef);
054: // See if we have this object in cache
055: BOServicemoduleImpl lImpl = (BOServicemoduleImpl) pMetaBossDomainImpl
056: .retrieveExistingBOInstance(BOServicemodule.class,
057: pServicemoduleRef);
058: if (lImpl != null)
059: return lImpl;
060: lImpl = new BOServicemoduleImpl();
061: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
062: lImpl.mServicemoduleRef = pServicemoduleRef;
063: lImpl.setupForExisting();
064: pMetaBossDomainImpl.saveNewBOInstance(BOServicemodule.class,
065: pServicemoduleRef, lImpl);
066: return lImpl;
067: }
068:
069: /* Instance creator */
070: public static BOServicemodule loadInstanceForExisting(
071: BOMetaBossDomainImpl pMetaBossDomainImpl,
072: String pServicemoduleRef) throws BOException {
073: try {
074: // See if we have this object in cache
075: BOServicemoduleImpl lImpl = (BOServicemoduleImpl) pMetaBossDomainImpl
076: .retrieveExistingBOInstance(BOServicemodule.class,
077: pServicemoduleRef);
078: if (lImpl != null)
079: return lImpl;
080: // Get the instance of the enterprise ps home via jndi
081: Context ctx = new InitialContext();
082: PSServicemodule lPs = (PSServicemodule) ctx
083: .lookup(PSServicemodule.COMPONENT_URL);
084: STServicemodule lDetails = lPs
085: .getServicemodule(pServicemoduleRef);
086: if (lDetails == null)
087: return null;
088: lImpl = new BOServicemoduleImpl();
089: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
090: lImpl.mServicemoduleRef = lDetails.ServicemoduleRef;
091: lImpl.mDetails = lDetails;
092: lImpl.setupForExisting();
093: pMetaBossDomainImpl.saveNewBOInstance(
094: BOServicemodule.class, pServicemoduleRef, lImpl);
095: return lImpl;
096: } catch (NamingException e) {
097: throw new BONamingAndDirectoryServiceInvocationException(
098: "", e);
099: } catch (PSException e) {
100: throw new BOPersistenceServiceInvocationException("", e);
101: }
102: }
103:
104: /* Instance creator */
105: public static BOServicemodule createInstanceForNew(
106: BOTransaction pTransaction,
107: BOMetaBossDomainImpl pMetaBossDomainImpl,
108: String pServicemoduleRef) throws BOException {
109: // See if we have this object in cache
110: BOServicemoduleImpl lImpl = (BOServicemoduleImpl) pMetaBossDomainImpl
111: .retrieveExistingBOInstance(BOServicemodule.class,
112: pServicemoduleRef);
113: if (lImpl != null)
114: throw new BOIllegalArgumentException(
115: "Service already exists. ServicemoduleRef: "
116: + pServicemoduleRef);
117: lImpl = new BOServicemoduleImpl();
118: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
119: lImpl.mServicemoduleRef = pServicemoduleRef;
120: lImpl.mDetails = new STServicemodule();
121: lImpl.mDetails.ServicemoduleRef = pServicemoduleRef;
122: lImpl.setupForNew(pTransaction);
123: pMetaBossDomainImpl.saveNewBOInstance(BOServicemodule.class,
124: pServicemoduleRef, lImpl);
125: return lImpl;
126: }
127:
128: /* Retrieves unique reference */
129: public String getRef() throws BOException {
130: return mServicemoduleRef;
131: }
132:
133: /* Retrieves servicemodule name. Usually last part of the reference.
134: * name is only unique within type, within enteprise */
135: public String getName() throws BOException {
136: String lRef = getRef();
137: return lRef.substring(lRef.lastIndexOf(".") + 1);
138: }
139:
140: /* Retrieves system which owns this servicemodule */
141: public BOSystem getSystem() throws BOException {
142: if (mSystem == null) {
143: String lRef = getRef();
144: if (lRef.lastIndexOf(".") < 0)
145: throw new BOException("Invalid ServicemoduleRef: "
146: + lRef);
147: mSystem = BOSystemImpl.createInstanceForExisting(
148: mMetaBossDomainImpl, lRef.substring(0, lRef
149: .lastIndexOf(".")));
150: }
151: return mSystem;
152: }
153:
154: /* Retrieves description */
155: public String getDescription() throws BOException {
156: loadDetailsIfNecessary();
157: return mDetails.Description;
158: }
159:
160: /** Sets description */
161: public void setDescription(String pDescription) throws BOException {
162: if (!isBeingEdited())
163: throw new BOInvalidOperationForReadOnlyObjectException();
164: mDetails.Description = pDescription;
165: }
166:
167: /* Retrieves list of services defined in this servicemodule */
168: public BOServicemoduleServiceList getServices() throws BOException {
169: return BOServicemoduleServiceListImpl
170: .createInstanceForExisting(mMetaBossDomainImpl, this );
171: }
172:
173: /* Retrieves list of structures defined in this servicemodule */
174: public BOServicemoduleStructureList getStructures()
175: throws BOException {
176: return BOServicemoduleStructureListImpl
177: .createInstanceForExisting(mMetaBossDomainImpl, this );
178: }
179:
180: /* Retrieves list of messages defined in this servicemodule */
181: public BOServicemoduleMessageList getMessages() throws BOException {
182: return BOServicemoduleMessageListImpl
183: .createInstanceForExisting(mMetaBossDomainImpl, this );
184: }
185:
186: /* Overriden to provide check reference equality */
187: public boolean equals(Object pOther) {
188: if (pOther == null)
189: return false;
190: if (!(pOther instanceof BOServicemoduleImpl))
191: return false;
192: return ((BOServicemoduleImpl) pOther).mServicemoduleRef
193: .equals(mServicemoduleRef);
194: }
195:
196: protected void loadDetailsIfNecessary() throws BOException {
197: if (mDetails == null) {
198: try {
199: // Get the instance of the enterprise ps home via jndi
200: Context ctx = new InitialContext();
201: PSServicemodule lPs = (PSServicemodule) ctx
202: .lookup(PSServicemodule.COMPONENT_URL);
203:
204: mDetails = lPs.getServicemodule(mServicemoduleRef);
205: if (mDetails == null)
206: throw new BOException(
207: "Servicemodule not found. ServicemoduleRef: "
208: + mServicemoduleRef);
209: } catch (NamingException e) {
210: throw new BONamingAndDirectoryServiceInvocationException(
211: "", e);
212: } catch (PSException e) {
213: throw new BOPersistenceServiceInvocationException("", e);
214: }
215: }
216: }
217:
218: protected void onBeginEdit() throws BOException {
219: // Fully load the object
220: loadDetailsIfNecessary();
221: }
222:
223: /* Encapsulates commit action by this object */
224: protected void onCommitCreation() throws BOException {
225: try {
226: // Get the instance of the enterprise ps home via jndi
227: Context ctx = new InitialContext();
228: PSServicemodule lPs = (PSServicemodule) ctx
229: .lookup(PSServicemodule.COMPONENT_URL);
230: lPs.insertServicemodule(mDetails);
231: } catch (NamingException e) {
232: throw new BONamingAndDirectoryServiceInvocationException(
233: "", e);
234: } catch (PSException e) {
235: throw new BOPersistenceServiceInvocationException("", e);
236: }
237: }
238:
239: /* Encapsulates commit action by this object */
240: protected void onCommitUpdate() throws BOException {
241: try {
242: // Get the instance of the enterprise ps home via jndi
243: Context ctx = new InitialContext();
244: PSServicemodule lPs = (PSServicemodule) ctx
245: .lookup(PSServicemodule.COMPONENT_URL);
246: lPs.updateServicemodule(mDetails);
247: } catch (NamingException e) {
248: throw new BONamingAndDirectoryServiceInvocationException(
249: "", e);
250: } catch (PSException e) {
251: throw new BOPersistenceServiceInvocationException("", e);
252: }
253: }
254:
255: protected void onCommitDeletion() throws BOException {
256: try {
257: // Get the instance of the enterprise ps home via jndi
258: Context ctx = new InitialContext();
259: PSServicemodule lPs = (PSServicemodule) ctx
260: .lookup(PSServicemodule.COMPONENT_URL);
261: lPs.deleteServicemodule(mServicemoduleRef);
262: mMetaBossDomainImpl.removeExistingBOInstance(
263: BOServicemodule.class, mServicemoduleRef);
264:
265: } catch (NamingException e) {
266: throw new BONamingAndDirectoryServiceInvocationException(
267: "", e);
268: } catch (PSException e) {
269: throw new BOPersistenceServiceInvocationException("", e);
270: }
271: }
272: }
|