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