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.BOEnterpriseSystemList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSEnterprise;
031: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STEnterprise;
032: import com.oldboss.framework.bo.BOTransaction;
033: import com.oldboss.framework.bo.impl.BOObjectImpl;
034:
035: public class BOEnterpriseImpl extends BOObjectImpl implements
036: BOEnterprise {
037: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
038: private String mEnterpriseRef = null;
039: private STEnterprise mDetailsBackup = null;
040: private STEnterprise mDetails = null;
041: private BOEnterpriseSystemList mSystemList = null;
042:
043: /* Instance creator */
044: public static BOEnterprise createInstanceForExisting(
045: BOMetaBossDomainImpl pMetaBossDomainImpl,
046: String pEnterpriseRef) throws BOException {
047: // See if we have this object in cache
048: BOEnterpriseImpl lImpl = (BOEnterpriseImpl) pMetaBossDomainImpl
049: .retrieveExistingBOInstance(BOEnterprise.class,
050: pEnterpriseRef);
051: if (lImpl != null)
052: return lImpl;
053: lImpl = new BOEnterpriseImpl();
054: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
055: lImpl.mEnterpriseRef = pEnterpriseRef;
056: lImpl.setupForExisting();
057: pMetaBossDomainImpl.saveNewBOInstance(BOEnterprise.class,
058: pEnterpriseRef, lImpl);
059: return lImpl;
060: }
061:
062: /* Instance creator */
063: public static BOEnterprise createInstanceForNew(
064: BOTransaction pTransaction,
065: BOMetaBossDomainImpl pMetaBossDomainImpl,
066: String pEnterpriseRef) throws BOException {
067: // See if we have this object in cache already
068: BOEnterpriseImpl lImpl = (BOEnterpriseImpl) pMetaBossDomainImpl
069: .retrieveExistingBOInstance(BOEnterprise.class,
070: pEnterpriseRef);
071: if (lImpl != null)
072: throw new BOIllegalArgumentException(
073: "Enterprise already exists. EnterpriseRef: "
074: + pEnterpriseRef);
075: lImpl = new BOEnterpriseImpl();
076: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
077: lImpl.mEnterpriseRef = pEnterpriseRef;
078: lImpl.mDetails = new STEnterprise();
079: lImpl.mDetails.EnterpriseRef = pEnterpriseRef;
080: lImpl.setupForNew(pTransaction);
081: pMetaBossDomainImpl.saveNewBOInstance(BOEnterprise.class,
082: pEnterpriseRef, lImpl);
083: return lImpl;
084: }
085:
086: /* Private constructor restricts instance creation from outside */
087: private BOEnterpriseImpl() throws BOException {
088: }
089:
090: /* Retrieves unique reference */
091: public String getRef() throws BOException {
092: return mEnterpriseRef;
093: }
094:
095: /* Retrieves enterprise name. */
096: public String getName() throws BOException {
097: return mEnterpriseRef;
098: }
099:
100: /* Retrieves description */
101: public String getDescription() throws BOException {
102: loadDetailsIfNecessary();
103: return mDetails.Description;
104: }
105:
106: /** Sets description */
107: public void setDescription(String pDescription) throws BOException {
108: if (!isBeingEdited())
109: throw new BOInvalidOperationForReadOnlyObjectException();
110: mDetails.Description = pDescription;
111: }
112:
113: /* Retrieves list of systems in this enteprise */
114: public BOEnterpriseSystemList getSystems() throws BOException {
115: if (mSystemList == null) {
116: loadDetailsIfNecessary();
117: mSystemList = BOEnterpriseSystemListImpl
118: .createInstanceForExisting(mMetaBossDomainImpl,
119: this );
120: }
121: return mSystemList;
122: }
123:
124: private void loadDetailsIfNecessary() throws BOException {
125: if (mDetails == null) {
126: try {
127: // Get the instance of the enterprise ps home via jndi
128: Context lCtx = new InitialContext();
129: PSEnterprise lPs = (PSEnterprise) lCtx
130: .lookup(PSEnterprise.COMPONENT_URL);
131:
132: mDetails = lPs.getEnterprise(mEnterpriseRef);
133: if (mDetails == null)
134: throw new BOException(
135: "Enterprise not found. EnterpriseRef:"
136: + mEnterpriseRef);
137: } catch (NamingException e) {
138: throw new BONamingAndDirectoryServiceInvocationException(
139: "", e);
140: } catch (PSException e) {
141: throw new BOPersistenceServiceInvocationException("", e);
142: }
143: }
144: }
145:
146: protected void onBeginEdit() throws BOException {
147: // Fully load the object
148: loadDetailsIfNecessary();
149: // Preserve old values
150: mDetailsBackup = mDetails;
151: }
152:
153: // Overriden to de-register from the owner and ensure that it is not referenced in any place
154: protected void onDelete() throws BOException {
155: BOEnterpriseListImpl lEnterpriseListImpl = (BOEnterpriseListImpl) mMetaBossDomainImpl
156: .getEnterprises();
157: lEnterpriseListImpl.beginEdit(fetchTransaction());
158: lEnterpriseListImpl.onDeleteEnterpise(this );
159: }
160:
161: // Overriden to de-register from the owner and ensure that it is not referenced in any place
162: protected void onDelete(BOObjectImpl pObjectImpl)
163: throws BOException {
164: // See if this is system
165: if (pObjectImpl instanceof BOSystem) {
166: BOEnterpriseSystemListImpl lEnterpriseSystemListImpl = (BOEnterpriseSystemListImpl) getSystems();
167: lEnterpriseSystemListImpl.beginEdit(fetchTransaction());
168: lEnterpriseSystemListImpl
169: .onDeleteSystem((BOSystem) pObjectImpl);
170: }
171: }
172:
173: /* Encapsulates commit action by this object */
174: protected void onCommitCreation() throws BOException {
175: try {
176: // Get the instance of the enterprise ps home via jndi
177: Context lCtx = new InitialContext();
178: PSEnterprise lPs = (PSEnterprise) lCtx
179: .lookup(PSEnterprise.COMPONENT_URL);
180: lPs.insertEnterprise(mDetails);
181: } catch (NamingException e) {
182: throw new BONamingAndDirectoryServiceInvocationException(
183: "", e);
184: } catch (PSException e) {
185: throw new BOPersistenceServiceInvocationException("", e);
186: }
187: }
188:
189: /* Encapsulates commit action by this object */
190: protected void onCommitUpdate() throws BOException {
191: try {
192: // Get the instance of the enterprise ps home via jndi
193: Context lCtx = new InitialContext();
194: PSEnterprise lPs = (PSEnterprise) lCtx
195: .lookup(PSEnterprise.COMPONENT_URL);
196: lPs.updateEnterprise(mDetails);
197: } catch (NamingException e) {
198: throw new BONamingAndDirectoryServiceInvocationException(
199: "", e);
200: } catch (PSException e) {
201: throw new BOPersistenceServiceInvocationException("", e);
202: }
203: }
204:
205: protected void onCommitDeletion() throws BOException {
206: try {
207: // Get the instance of the enterprise ps home via jndi
208: Context lCtx = new InitialContext();
209: PSEnterprise lPs = (PSEnterprise) lCtx
210: .lookup(PSEnterprise.COMPONENT_URL);
211: lPs.deleteEnterprise(mEnterpriseRef);
212: } catch (NamingException e) {
213: throw new BONamingAndDirectoryServiceInvocationException(
214: "", e);
215: } catch (PSException e) {
216: throw new BOPersistenceServiceInvocationException("", e);
217: }
218: }
219:
220: /* Encapsulates an action after successfull commit */
221: public void onCommitSucceeded() throws BOException {
222: mDetailsBackup = null;
223: if (isDeleted())
224: mMetaBossDomainImpl.removeExistingBOInstance(
225: BOEnterprise.class, mEnterpriseRef);
226: }
227:
228: // Overriddden to cleanup this object from cache
229: protected void onRollbackCreation() throws BOException {
230: mMetaBossDomainImpl.removeExistingBOInstance(
231: BOEnterprise.class, mEnterpriseRef);
232: }
233:
234: // Overriddden to restore this object's status to pre-begin edit state
235: protected void onRollbackUpdate() throws BOException {
236: mDetails = mDetailsBackup;
237: mDetailsBackup = null;
238: }
239: }
|