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.BOMessageFieldList;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOServicemodule;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSMessage;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STMessage;
031: import com.metaboss.sdlctools.types.enterprisemodel.MessageType;
032: import com.oldboss.framework.bo.BOTransaction;
033: import com.oldboss.framework.bo.impl.BOObjectImpl;
034:
035: public class BOMessageImpl extends BOObjectImpl implements BOMessage {
036: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
037: private BOServicemodule mServicemodule = null;
038: private String mMessageRef = null;
039: private STMessage mDetails = null;
040:
041: /* Instance creator */
042: public static BOMessage createInstanceForExisting(
043: BOMetaBossDomainImpl pMetaBossDomainImpl, String pMessageRef)
044: throws BOException {
045: BOMessageImpl lImpl = new BOMessageImpl();
046: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
047: lImpl.mMessageRef = pMessageRef;
048: lImpl.setupForExisting();
049: return lImpl;
050: }
051:
052: /* Instance creator */
053: public static BOMessage createInstanceForNew(
054: BOTransaction pTransaction,
055: BOMetaBossDomainImpl pMetaBossDomainImpl, String pMessageRef)
056: throws BOException {
057: BOMessageImpl lImpl = new BOMessageImpl();
058: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
059: lImpl.mMessageRef = pMessageRef;
060: lImpl.mDetails = new STMessage();
061: lImpl.mDetails.MessageRef = pMessageRef;
062: lImpl.setupForNew(pTransaction);
063: return lImpl;
064: }
065:
066: /* Private constructor restricts instance creation from outside */
067: private BOMessageImpl() throws BOException {
068: }
069:
070: /* Retrieves unique reference */
071: public String getRef() throws BOException {
072: return mMessageRef;
073: }
074:
075: /* Retrieves entity name */
076: public String getName() throws BOException {
077: String lMessageRef = getRef();
078: if (lMessageRef.lastIndexOf(".") < 0)
079: throw new BOException("Invalid BOMessage reference : "
080: + getRef());
081: return lMessageRef.substring(lMessageRef.lastIndexOf(".") + 1);
082: }
083:
084: /* Retrieves description */
085: public String getDescription() throws BOException {
086: loadDetailsIfNecessary();
087: return mDetails.Description;
088: }
089:
090: /* Sets description */
091: public void setDescription(String pDescription) throws BOException {
092: if (!isBeingEdited())
093: throw new BOInvalidOperationForReadOnlyObjectException();
094: mDetails.Description = pDescription;
095: }
096:
097: /* Retrieves message type */
098: public MessageType getType() throws BOException {
099: loadDetailsIfNecessary();
100: return mDetails.Type;
101: }
102:
103: /** Sets message type */
104: public void setType(MessageType pType) throws BOException {
105: if (!isBeingEdited())
106: throw new BOInvalidOperationForReadOnlyObjectException();
107: mDetails.Type = pType;
108: }
109:
110: /* Retrieves default text */
111: public String getDefaultText() throws BOException {
112: loadDetailsIfNecessary();
113: return mDetails.DefaultText;
114: }
115:
116: /** Sets default text */
117: public void setDefaultText(String pDefaultText) throws BOException {
118: if (!isBeingEdited())
119: throw new BOInvalidOperationForReadOnlyObjectException();
120: mDetails.DefaultText = pDefaultText;
121: }
122:
123: /* Retrieves parent servicemodule */
124: public BOServicemodule getServicemodule() throws BOException {
125: if (mServicemodule == null) {
126: String lMessageRef = getRef();
127: if (lMessageRef.lastIndexOf(".") < 0)
128: throw new BOException("Invalid MessageRef: " + getRef());
129: mServicemodule = BOServicemoduleImpl
130: .createInstanceForExisting(mMetaBossDomainImpl,
131: lMessageRef.substring(0, lMessageRef
132: .lastIndexOf(".")));
133: }
134: return mServicemodule;
135: }
136:
137: /* Retireves the list of input fields */
138: public BOMessageFieldList getFields() throws BOException {
139: loadDetailsIfNecessary();
140: return BOMessageFieldListImpl.createInstanceForExisting(
141: mMetaBossDomainImpl, this );
142: }
143:
144: protected void loadDetailsIfNecessary() throws BOException {
145: if (mDetails == null) {
146: try {
147: // Get the instance of the enterprise ps home via jndi
148: Context ctx = new InitialContext();
149: PSMessage lPs = (PSMessage) ctx
150: .lookup(PSMessage.COMPONENT_URL);
151:
152: mDetails = lPs.getMessage(mMessageRef);
153: if (mDetails == null)
154: throw new BOException(
155: "Message not found. MessageRef:"
156: + mMessageRef);
157: } catch (NamingException e) {
158: throw new BONamingAndDirectoryServiceInvocationException(
159: "", e);
160: } catch (PSException e) {
161: throw new BOPersistenceServiceInvocationException("", e);
162: }
163: }
164: }
165:
166: protected void onBeginEdit() throws BOException {
167: // Fully load the object
168: loadDetailsIfNecessary();
169: }
170:
171: /* Encapsulates commit action by this object */
172: protected void onCommitCreation() throws BOException {
173: try {
174: // Get the instance of the enterprise ps home via jndi
175: Context ctx = new InitialContext();
176: PSMessage lPs = (PSMessage) ctx
177: .lookup(PSMessage.COMPONENT_URL);
178: lPs.insert(new STMessage[] { mDetails });
179: } catch (NamingException e) {
180: throw new BONamingAndDirectoryServiceInvocationException(
181: "", e);
182: } catch (PSException e) {
183: throw new BOPersistenceServiceInvocationException("", e);
184: }
185: }
186: }
|