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.BOOperation;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOOperationInputConstraintList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOOperationInputFieldList;
030: import com.metaboss.sdlctools.domains.enterprisemodel.BOOperationOutputFieldList;
031: import com.metaboss.sdlctools.domains.enterprisemodel.BOOperationOutputMessageList;
032: import com.metaboss.sdlctools.domains.enterprisemodel.BOService;
033: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSService;
034: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STOperation;
035: import com.metaboss.sdlctools.types.enterprisemodel.TransactionPolicy;
036: import com.oldboss.framework.bo.BOTransaction;
037: import com.oldboss.framework.bo.impl.BOObjectImpl;
038:
039: public class BOOperationImpl extends BOObjectImpl implements
040: BOOperation {
041: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
042: private String mOperationRef = null;
043: private BOService mOwnerService = null;
044: private STOperation mDetails = null;
045:
046: /* Instance creator */
047: public static BOOperation createInstanceForExisting(
048: BOMetaBossDomainImpl pMetaBossDomainImpl,
049: BOService pOwnerService, STOperation pDetails)
050: throws BOException {
051: if (pDetails == null)
052: throw new BOIllegalArgumentException(
053: "Empty details structure");
054: if (!pOwnerService.getRef().equals(pDetails.ServiceRef))
055: throw new BOIllegalArgumentException(
056: "Service Reference mismatch");
057: BOOperationImpl lImpl = new BOOperationImpl();
058: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
059: lImpl.mOperationRef = pDetails.ServiceRef + "." + pDetails.Name;
060: lImpl.mOwnerService = pOwnerService;
061: lImpl.mDetails = pDetails;
062: lImpl.setupForExisting();
063: return lImpl;
064: }
065:
066: /* Instance creator */
067: public static BOOperation createInstanceForExisting(
068: BOMetaBossDomainImpl pMetaBossDomainImpl,
069: String pOperationRef) throws BOException {
070: if (pOperationRef == null)
071: throw new BOIllegalArgumentException("Empty OperationRef");
072: BOOperationImpl lImpl = new BOOperationImpl();
073: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
074: lImpl.mOperationRef = pOperationRef;
075: lImpl.mOwnerService = null;
076: lImpl.mDetails = null;
077: lImpl.setupForExisting();
078: return lImpl;
079: }
080:
081: /* Instance creator */
082: public static BOOperation createInstanceForNew(
083: BOTransaction pTransaction,
084: BOMetaBossDomainImpl pMetaBossDomainImpl,
085: BOService pOwnerService, String pName) throws BOException {
086: if (pName == null || pName.length() == 0)
087: throw new BOException("Empty name");
088: BOOperationImpl lImpl = new BOOperationImpl();
089: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
090: lImpl.mOperationRef = pOwnerService.getRef() + "." + pName;
091: lImpl.mOwnerService = pOwnerService;
092: lImpl.mDetails = new STOperation();
093: lImpl.mDetails.Name = pName;
094: lImpl.setupForNew(pTransaction);
095: return lImpl;
096: }
097:
098: /* Private constructor restricts instance creation from outside */
099: private BOOperationImpl() throws BOException {
100: }
101:
102: /* Retrieves unique reference */
103: public String getRef() throws BOException {
104: return mOperationRef;
105: }
106:
107: /* Retrieves element's name. Name is only unique within parent entity */
108: public String getName() throws BOException {
109: int lLastDot = mOperationRef.lastIndexOf('.');
110: if (lLastDot <= 0)
111: throw new BOException("Invalid OperationRef: "
112: + mOperationRef);
113: return mOperationRef.substring(lLastDot + 1);
114: }
115:
116: /* Returns element's description */
117: public String getDescription() throws BOException {
118: loadDetailsIfNecessary();
119: return mDetails.Description;
120: }
121:
122: /* Sets description */
123: public void setDescription(String pDescription) throws BOException {
124: if (!isBeingEdited())
125: throw new BOInvalidOperationForReadOnlyObjectException();
126: mDetails.Description = pDescription;
127: }
128:
129: /* Retrieves transaction policy */
130: public TransactionPolicy getTransactionPolicy() throws BOException {
131: loadDetailsIfNecessary();
132: return mDetails.TransactionPolicy;
133: }
134:
135: /* Retrieves is query flag */
136: public boolean isQuery() throws BOException {
137: loadDetailsIfNecessary();
138: return mDetails.IsQuery;
139: }
140:
141: /* Sets new transaction policy */
142: public void setTransactionPolicy(
143: TransactionPolicy pTransactionPolicy) throws BOException {
144: if (!isBeingEdited())
145: throw new BOInvalidOperationForReadOnlyObjectException();
146: mDetails.TransactionPolicy = pTransactionPolicy;
147: }
148:
149: /* Retrieves the service this operation belongs to */
150: public BOService getService() throws BOException {
151: if (mOwnerService == null) {
152: int lLastDot = mOperationRef.lastIndexOf('.');
153: if (lLastDot <= 0)
154: throw new BOException("Invalid OperationRef: "
155: + mOperationRef);
156: String lServiceRef = mOperationRef.substring(0, lLastDot);
157: mOwnerService = BOServiceImpl.createInstanceForExisting(
158: mMetaBossDomainImpl, lServiceRef);
159: }
160: return mOwnerService;
161: }
162:
163: /* Retireves the list of input fields */
164: public BOOperationInputFieldList getInputFields()
165: throws BOException {
166: loadDetailsIfNecessary();
167: return BOOperationInputFieldListImpl.createInstanceForExisting(
168: mMetaBossDomainImpl, this );
169: }
170:
171: /** Retireves the list of input constraints */
172: public BOOperationInputConstraintList getInputConstraints()
173: throws BOException {
174: loadDetailsIfNecessary();
175: return BOOperationInputConstraintListImpl
176: .createInstanceForExisting(mMetaBossDomainImpl, this );
177: }
178:
179: /* Retireves the list of output fields */
180: public BOOperationOutputFieldList getOutputFields()
181: throws BOException {
182: loadDetailsIfNecessary();
183: return BOOperationOutputFieldListImpl
184: .createInstanceForExisting(mMetaBossDomainImpl, this );
185: }
186:
187: /* Retireves the list of output messages */
188: public BOOperationOutputMessageList getOutputMessages()
189: throws BOException {
190: loadDetailsIfNecessary();
191: return BOOperationOutputMessageListImpl
192: .createInstanceForExisting(mMetaBossDomainImpl, this );
193: }
194:
195: protected void onBeginEdit() throws BOException {
196: // Fully load the object
197: loadDetailsIfNecessary();
198: }
199:
200: /* Encapsulates commit action by this object */
201: protected void onCommitCreation() throws BOException {
202: try {
203: // Get the instance of the enterprise ps home via jndi
204: Context ctx = new InitialContext();
205: PSService lPs = (PSService) ctx
206: .lookup(PSService.COMPONENT_URL);
207: lPs.insertOperation(mOwnerService.getRef(), mDetails);
208: } catch (NamingException e) {
209: throw new BONamingAndDirectoryServiceInvocationException(
210: "", e);
211: } catch (PSException e) {
212: throw new BOPersistenceServiceInvocationException("", e);
213: }
214: }
215:
216: protected void loadDetailsIfNecessary() throws BOException {
217: if (mDetails == null) {
218: try {
219: // Get the instance of the enterprise ps home via jndi
220: Context ctx = new InitialContext();
221: PSService lPs = (PSService) ctx
222: .lookup(PSService.COMPONENT_URL);
223:
224: mDetails = lPs.getOperation(mOperationRef);
225: if (mDetails == null)
226: throw new BOException(
227: "Operation not found. OperationRef:"
228: + mOperationRef);
229: } catch (NamingException e) {
230: throw new BONamingAndDirectoryServiceInvocationException(
231: "", e);
232: } catch (PSException e) {
233: throw new BOPersistenceServiceInvocationException("", e);
234: }
235: }
236: }
237: }
|