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.BODatatype;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOMessage;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOMessageField;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSMessage;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STMessageField;
031: import com.oldboss.framework.bo.BOTransaction;
032: import com.oldboss.framework.bo.impl.BOObjectImpl;
033:
034: public class BOMessageFieldImpl extends BOObjectImpl implements
035: BOMessageField {
036: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
037: protected BOMessage mOwnerMessage = null;
038: protected STMessageField mDetails = null;
039:
040: /* Instance creator */
041: public static BOMessageField createInstanceForExisting(
042: BOMetaBossDomainImpl pMetaBossDomainImpl,
043: BOMessage pOwnerMessage, STMessageField pDetails)
044: throws BOException {
045: if (pDetails == null)
046: throw new BOException("Empty details structure");
047: BOMessageFieldImpl lImpl = new BOMessageFieldImpl();
048: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
049: lImpl.mOwnerMessage = pOwnerMessage;
050: lImpl.mDetails = pDetails;
051: lImpl.setupForExisting();
052: return lImpl;
053: }
054:
055: /* Instance creator */
056: public static BOMessageField createInstanceForNew(
057: BOTransaction pTransaction,
058: BOMetaBossDomainImpl pMetaBossDomainImpl,
059: BOMessage pOwnerMessage, String pName) throws BOException {
060: if (pName == null || pName.length() == 0)
061: throw new BOException("Empty name");
062: BOMessageFieldImpl lImpl = new BOMessageFieldImpl();
063: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
064: lImpl.mOwnerMessage = pOwnerMessage;
065: lImpl.mDetails = new STMessageField();
066: lImpl.mDetails.Name = pName;
067: lImpl.setupForNew(pTransaction);
068: return lImpl;
069: }
070:
071: /** Retrieves message this field list belongs to */
072: public BOMessage getMessage() throws BOException {
073: return mOwnerMessage;
074: }
075:
076: /* Retrieves element's name. Name is only unique within parent entity */
077: public String getName() throws BOException {
078: return mDetails.Name;
079: }
080:
081: /* Returns element's description */
082: public String getDescription() throws BOException {
083: return mDetails.Description;
084: }
085:
086: /** Sets description */
087: public void setDescription(String pDescription) throws BOException {
088: if (!isBeingEdited())
089: throw new BOInvalidOperationForReadOnlyObjectException();
090: mDetails.Description = pDescription;
091: }
092:
093: /** Returns type object It may be of type BODataType or BOStructure */
094: public BODatatype getType() throws BOException {
095: return BODatatypeImpl.createInstanceForExisting(
096: mMetaBossDomainImpl, mDetails.DataTypeRef);
097: }
098:
099: /* Sets type to the given datatype */
100: public void setType(BODatatype pDatatype) throws BOException {
101: if (!isBeingEdited())
102: throw new BOInvalidOperationForReadOnlyObjectException();
103: mDetails.DataTypeRef = pDatatype.getRef();
104: }
105:
106: /* Encapsulates commit action by this object */
107: protected void onCommitCreation() throws BOException {
108: try {
109: // Get the instance of the enterprise ps home via jndi
110: Context ctx = new InitialContext();
111: PSMessage lPs = (PSMessage) ctx
112: .lookup(PSMessage.COMPONENT_URL);
113: lPs.insertField(mOwnerMessage.getRef(), mDetails);
114: } catch (NamingException e) {
115: throw new BONamingAndDirectoryServiceInvocationException(
116: "", e);
117: } catch (PSException e) {
118: throw new BOPersistenceServiceInvocationException("", e);
119: }
120: }
121: }
|