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.BOInvalidOperationForReadOnlyObjectException;
023: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
024: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
025: import com.metaboss.enterprise.ps.PSException;
026: import com.metaboss.sdlctools.domains.enterprisemodel.BOMessage;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOOperation;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOOutputMessage;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSService;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STOutputMessage;
031: import com.oldboss.framework.bo.BOTransaction;
032: import com.oldboss.framework.bo.impl.BOObjectImpl;
033:
034: public class BOOutputMessageImpl extends BOObjectImpl implements
035: BOOutputMessage {
036: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
037: protected BOMessage mMessage = null;
038: protected BOOperation mOwnerOperation = null;
039: protected STOutputMessage mDetails = null;
040:
041: public static BOOutputMessage createInstanceForExistingOperationOutputMessage(
042: BOMetaBossDomainImpl pMetaBossDomainImpl,
043: BOOperation pOwnerOperation, STOutputMessage pDetails)
044: throws BOException {
045: if (pDetails == null)
046: throw new BOException("Empty details structure.");
047: BOOutputMessageImpl lImpl = new BOOutputMessageImpl();
048: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
049: lImpl.mOwnerOperation = pOwnerOperation;
050: lImpl.mDetails = pDetails;
051: lImpl.setupForExisting();
052: return lImpl;
053: }
054:
055: public static BOOutputMessage createInstanceForNewOperationOutputMessage(
056: BOTransaction pTransaction,
057: BOMetaBossDomainImpl pMetaBossDomainImpl,
058: BOOperation pOwnerOperation, BOMessage pMessage,
059: String pOutputMessageName) throws BOException {
060: BOOutputMessageImpl lImpl = new BOOutputMessageImpl();
061: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
062: lImpl.mOwnerOperation = pOwnerOperation;
063: lImpl.mMessage = pMessage;
064: lImpl.mDetails = new STOutputMessage();
065: lImpl.mDetails.MessageRef = pMessage.getRef();
066: lImpl.mDetails.Name = pOutputMessageName;
067: lImpl.setupForNew(pTransaction);
068: return lImpl;
069: }
070:
071: // Restict outside access
072: private BOOutputMessageImpl() {
073: }
074:
075: /** This method returns globally unique object id. To make it globally unique it has to
076: * incorporate type identifier and instance identifier */
077: public String getObjectId() throws BOException {
078: return "BOOutputMessage:" + getOperation().getRef() + "."
079: + getName();
080: }
081:
082: /** Retrieves name of the output message. Unique within operation
083: * and shares namespace with output fields */
084: public String getName() throws BOException {
085: return mDetails.Name;
086: }
087:
088: /* Returns the message this output message references */
089: public BOMessage getMessage() throws BOException {
090: if (mMessage == null)
091: mMessage = BOMessageImpl.createInstanceForExisting(
092: mMetaBossDomainImpl, mDetails.MessageRef);
093: return mMessage;
094: }
095:
096: /* Returns the operation this output message belongs to. */
097: public BOOperation getOperation() throws BOException {
098: return mOwnerOperation;
099: }
100:
101: /* Returns element's description */
102: public String getDescription() throws BOException {
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: /* Returns boolean if this field is an array */
114: public boolean isArray() throws BOException {
115: return mDetails.IsArray;
116: }
117:
118: /* Sets is array flag */
119: public void setIsArray(boolean isArray) throws BOException {
120: if (!isBeingEdited())
121: throw new BOInvalidOperationForReadOnlyObjectException();
122: mDetails.IsArray = isArray;
123: }
124:
125: /* Encapsulates commit action by this object */
126: protected void onCommitCreation() throws BOException {
127: try {
128: // Get the instance of the enterprise ps home via jndi
129: Context ctx = new InitialContext();
130: if (mOwnerOperation != null) {
131: PSService lPs = (PSService) ctx
132: .lookup(PSService.COMPONENT_URL);
133: lPs.insertOutputMessage(mOwnerOperation.getService()
134: .getRef(), mOwnerOperation.getName(), mDetails);
135: } else
136: throw new PSException("Operation not supported");
137: } catch (NamingException e) {
138: throw new BONamingAndDirectoryServiceInvocationException(
139: "", e);
140: } catch (PSException e) {
141: throw new BOPersistenceServiceInvocationException("", e);
142: }
143: }
144: }
|