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.BOEnterprise;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystemApplicationList;
030: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystemDatatypeList;
031: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystemDomainList;
032: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystemServicemoduleList;
033: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystemTypetemplateList;
034: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSSystem;
035: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STSystem;
036: import com.oldboss.framework.bo.BOTransaction;
037: import com.oldboss.framework.bo.impl.BOObjectImpl;
038:
039: public class BOSystemImpl extends BOObjectImpl implements BOSystem {
040: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
041: private String mSystemRef = null;
042: private STSystem mDetailsBackup = null;
043: private STSystem mDetails = null;
044:
045: /* Instance creator */
046: public static BOSystem createInstanceForExisting(
047: BOMetaBossDomainImpl pMetaBossDomainImpl, String pSystemRef)
048: throws BOException {
049: if (pSystemRef == null)
050: throw new BOIllegalArgumentException(
051: "SystemRef is not expected to be null");
052: if (pSystemRef.lastIndexOf(".") < 0)
053: throw new BOIllegalArgumentException("Invalid SystemRef: "
054: + pSystemRef);
055: // See if we have this object in cache
056: BOSystemImpl lImpl = (BOSystemImpl) pMetaBossDomainImpl
057: .retrieveExistingBOInstance(BOSystem.class, pSystemRef);
058: if (lImpl != null)
059: return lImpl;
060: lImpl = new BOSystemImpl();
061: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
062: lImpl.mSystemRef = pSystemRef;
063: lImpl.setupForExisting((BOObjectImpl) BOEnterpriseImpl
064: .createInstanceForExisting(pMetaBossDomainImpl,
065: pSystemRef.substring(0, pSystemRef
066: .lastIndexOf("."))));
067: pMetaBossDomainImpl.saveNewBOInstance(BOSystem.class,
068: pSystemRef, lImpl);
069: return lImpl;
070: }
071:
072: /* Instance creator */
073: public static BOSystem createInstanceForNew(
074: BOTransaction pTransaction,
075: BOMetaBossDomainImpl pMetaBossDomainImpl, String pSystemRef)
076: throws BOException {
077: if (pSystemRef == null)
078: throw new BOIllegalArgumentException(
079: "SystemRef is not expected to be null");
080: if (pSystemRef.lastIndexOf(".") < 0)
081: throw new BOIllegalArgumentException("Invalid SystemRef: "
082: + pSystemRef);
083: // See if we have this object in cache already
084: BOSystemImpl lImpl = (BOSystemImpl) pMetaBossDomainImpl
085: .retrieveExistingBOInstance(BOSystem.class, pSystemRef);
086: if (lImpl != null)
087: throw new BOIllegalArgumentException(
088: "System already exists. SystemRef: " + pSystemRef);
089: lImpl = new BOSystemImpl();
090: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
091: lImpl.mSystemRef = pSystemRef;
092: lImpl.mDetails = new STSystem();
093: lImpl.mDetails.SystemRef = pSystemRef;
094: lImpl.setupForNew(pTransaction, (BOObjectImpl) BOEnterpriseImpl
095: .createInstanceForExisting(pMetaBossDomainImpl,
096: pSystemRef.substring(0, pSystemRef
097: .lastIndexOf("."))));
098: pMetaBossDomainImpl.saveNewBOInstance(BOSystem.class,
099: pSystemRef, lImpl);
100: return lImpl;
101: }
102:
103: /* Private constructor restricts instance creation from outside */
104: private BOSystemImpl() throws BOException {
105: }
106:
107: /* Retrieves unique reference */
108: public String getRef() throws BOException {
109: return mSystemRef;
110: }
111:
112: /* Retrieves system name. */
113: public String getName() throws BOException {
114: return mSystemRef.substring(mSystemRef.indexOf(".") + 1);
115: }
116:
117: /* Retrieves description */
118: public String getDescription() throws BOException {
119: loadDetailsIfNecessary();
120: return mDetails.Description;
121: }
122:
123: /** Sets description */
124: public void setDescription(String pDescription) throws BOException {
125: if (!isBeingEdited())
126: throw new BOInvalidOperationForReadOnlyObjectException();
127: mDetails.Description = pDescription;
128: }
129:
130: /* Retrieves enterprise, which owns this system */
131: public BOEnterprise getEnterprise() throws BOException {
132: return (BOEnterprise) getOwnerObject();
133: }
134:
135: /* Retrieves list of datatypes in this enteprise */
136: public BOSystemDatatypeList getDatatypes() throws BOException {
137: loadDetailsIfNecessary();
138: return BOSystemDatatypeListImpl.createInstanceForExisting(
139: mMetaBossDomainImpl, this );
140: }
141:
142: /* Retrieves list of typetemplates in this enteprise */
143: public BOSystemTypetemplateList getTypetemplates()
144: throws BOException {
145: loadDetailsIfNecessary();
146: return BOSystemTypetemplateListImpl.createInstanceForExisting(
147: mMetaBossDomainImpl, this );
148: }
149:
150: /* Retrieves list of domains within this system */
151: public BOSystemDomainList getDomains() throws BOException {
152: loadDetailsIfNecessary();
153: return BOSystemDomainListImpl.createInstanceForExisting(
154: mMetaBossDomainImpl, this );
155: }
156:
157: /* Retrieves list of servicemodules within this system */
158: public BOSystemServicemoduleList getServicemodules()
159: throws BOException {
160: loadDetailsIfNecessary();
161: return BOSystemServicemoduleListImpl.createInstanceForExisting(
162: mMetaBossDomainImpl, this );
163: }
164:
165: /* Retrieves list of applications within this system */
166: public BOSystemApplicationList getApplications() throws BOException {
167: loadDetailsIfNecessary();
168: return BOSystemApplicationListImpl.createInstanceForExisting(
169: mMetaBossDomainImpl, this );
170: }
171:
172: private void loadDetailsIfNecessary() throws BOException {
173: if (mDetails == null) {
174: try {
175: // Get the instance of the enterprise ps home via jndi
176: Context ctx = new InitialContext();
177: PSSystem lPs = (PSSystem) ctx
178: .lookup(PSSystem.COMPONENT_URL);
179: mDetails = lPs.getSystem(mSystemRef);
180: if (mDetails == null)
181: throw new BOException(
182: "System not found. SystemRef:" + mSystemRef);
183: } catch (NamingException e) {
184: throw new BONamingAndDirectoryServiceInvocationException(
185: "Error while loading system details. SystemRef:"
186: + mSystemRef, e);
187: } catch (PSException e) {
188: throw new BOPersistenceServiceInvocationException(
189: "Error while loading system details. SystemRef:"
190: + mSystemRef, e);
191: }
192: }
193: }
194:
195: protected void onBeginEdit() throws BOException {
196: // Fully load the object
197: loadDetailsIfNecessary();
198: // Preserve old values
199: mDetailsBackup = mDetails;
200: }
201:
202: /* Encapsulates commit action by this object */
203: protected void onCommitCreation() throws BOException {
204: try {
205: // Get the instance of the enterprise ps home via jndi
206: Context ctx = new InitialContext();
207: PSSystem lPs = (PSSystem) ctx
208: .lookup(PSSystem.COMPONENT_URL);
209: lPs.insertSystem(mDetails);
210: } catch (NamingException e) {
211: throw new BONamingAndDirectoryServiceInvocationException(
212: "", e);
213: } catch (PSException e) {
214: throw new BOPersistenceServiceInvocationException("", e);
215: }
216: }
217:
218: /* Encapsulates commit action by this object */
219: protected void onCommitUpdate() throws BOException {
220: try {
221: // Get the instance of the enterprise ps home via jndi
222: Context ctx = new InitialContext();
223: PSSystem lPs = (PSSystem) ctx
224: .lookup(PSSystem.COMPONENT_URL);
225: lPs.updateSystem(mDetails);
226: } catch (NamingException e) {
227: throw new BONamingAndDirectoryServiceInvocationException(
228: "", e);
229: } catch (PSException e) {
230: throw new BOPersistenceServiceInvocationException("", e);
231: }
232: }
233:
234: protected void onCommitDeletion() throws BOException {
235: try {
236: // Get the instance of the enterprise ps home via jndi
237: Context ctx = new InitialContext();
238: PSSystem lPs = (PSSystem) ctx
239: .lookup(PSSystem.COMPONENT_URL);
240: lPs.deleteSystem(mSystemRef);
241: } catch (NamingException e) {
242: throw new BONamingAndDirectoryServiceInvocationException(
243: "", e);
244: } catch (PSException e) {
245: throw new BOPersistenceServiceInvocationException("", e);
246: }
247: }
248:
249: /* Encapsulates an action after successfull commit */
250: public void onCommitSucceeded() throws BOException {
251: mDetailsBackup = null;
252: if (isDeleted())
253: mMetaBossDomainImpl.removeExistingBOInstance(
254: BOSystem.class, mSystemRef);
255: }
256:
257: // Overriddden to cleanup this object from cache
258: protected void onRollbackCreation() throws BOException {
259: mMetaBossDomainImpl.removeExistingBOInstance(BOSystem.class,
260: mSystemRef);
261: }
262:
263: // Overriddden to restore this object's status to pre-begin edit state
264: protected void onRollbackUpdate() throws BOException {
265: mDetails = mDetailsBackup;
266: mDetailsBackup = null;
267: }
268: }
|