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.BOEntity;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOSelector;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOSelectorInputFieldList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSEntity;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STSelector;
031: import com.metaboss.sdlctools.types.enterprisemodel.SelectorCardinality;
032: import com.oldboss.framework.bo.BOTransaction;
033: import com.oldboss.framework.bo.impl.BOObjectImpl;
034:
035: public class BOSelectorImpl extends BOObjectImpl implements BOSelector {
036: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
037: private BOEntity mEntity = null;
038: private String mSelectorName = null;
039: private STSelector mDetails = null;
040:
041: /* Instance creator */
042: public static BOSelector createInstanceForExisting(
043: BOMetaBossDomainImpl pMetaBossDomainImpl, BOEntity pEntity,
044: STSelector pDetails) throws BOException {
045: BOSelectorImpl lImpl = new BOSelectorImpl();
046: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
047: lImpl.mEntity = pEntity;
048: lImpl.mSelectorName = pDetails.Name;
049: lImpl.mDetails = pDetails;
050: lImpl.setupForExisting();
051: return lImpl;
052: }
053:
054: /* Instance creator */
055: public static BOSelector createInstanceForExisting(
056: BOMetaBossDomainImpl pMetaBossDomainImpl, BOEntity pEntity,
057: String pSelectorName) throws BOException {
058: BOSelectorImpl lImpl = new BOSelectorImpl();
059: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
060: lImpl.mEntity = pEntity;
061: lImpl.mSelectorName = pSelectorName;
062: lImpl.mDetails = null;
063: lImpl.setupForExisting();
064: return lImpl;
065: }
066:
067: /* Instance creator */
068: public static BOSelector createInstanceForNew(
069: BOTransaction pTransaction,
070: BOMetaBossDomainImpl pMetaBossDomainImpl, BOEntity pEntity,
071: String pSelectorName) throws BOException {
072: BOSelectorImpl lImpl = new BOSelectorImpl();
073: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
074: lImpl.mEntity = pEntity;
075: lImpl.mSelectorName = pSelectorName;
076: lImpl.mDetails = new STSelector();
077: lImpl.mDetails.Name = pSelectorName;
078: lImpl.setupForNew(pTransaction);
079: return lImpl;
080: }
081:
082: /* Private constructor restricts instance creation from outside */
083: private BOSelectorImpl() throws BOException {
084: }
085:
086: /* Retrieves unique selector ref */
087: public String getRef() throws BOException {
088: return mEntity.getRef() + "." + mSelectorName;
089: }
090:
091: /* Retrieves entity which owns this selector. */
092: public BOEntity getEntity() throws BOException {
093: return mEntity;
094: }
095:
096: /* Retrieves selector name - used to name resulting collection.
097: * This name is always present */
098: public String getName() throws BOException {
099: return mSelectorName;
100: }
101:
102: /* Retrieves description */
103: public String getDescription() throws BOException {
104: loadDetailsIfNecessary();
105: return mDetails.Description;
106: }
107:
108: /* Sets description */
109: public void setDescription(String pDescription) throws BOException {
110: if (!isBeingEdited())
111: throw new BOInvalidOperationForReadOnlyObjectException();
112: mDetails.Description = pDescription;
113: }
114:
115: /* Retireves the list of input fields */
116: public BOSelectorInputFieldList getInputFields() throws BOException {
117: return BOSelectorInputFieldListImpl.createInstanceForExisting(
118: mMetaBossDomainImpl, this );
119: }
120:
121: /* Retrieves cardinality for the return from this selector. */
122: public SelectorCardinality getCardinality() throws BOException {
123: loadDetailsIfNecessary();
124: return mDetails.Cardinality;
125: }
126:
127: /* Sets cardinality for the return from this selector. */
128: public void setCardinality(SelectorCardinality pCardinality)
129: throws BOException {
130: if (!isBeingEdited())
131: throw new BOInvalidOperationForReadOnlyObjectException();
132: mDetails.Cardinality = pCardinality;
133: }
134:
135: /* Retrieves text of java implementation template of the selector */
136: public String getJavaSelector() throws BOException {
137: loadDetailsIfNecessary();
138: return mDetails.JavaSelector;
139: }
140:
141: /* Sets text of java implementation template of the selector */
142: public void setJavaSelector(String pJavaSelector)
143: throws BOException {
144: if (!isBeingEdited())
145: throw new BOInvalidOperationForReadOnlyObjectException();
146: mDetails.JavaSelector = pJavaSelector;
147: }
148:
149: /* Retrieves text of SQL implementation template of the selector */
150: public String getSQLSelector() throws BOException {
151: loadDetailsIfNecessary();
152: return mDetails.SQLSelector;
153: }
154:
155: /* Sets text of SQL implementation template of the selector */
156: public void setSQLSelector(String pSQLSelector) throws BOException {
157: if (!isBeingEdited())
158: throw new BOInvalidOperationForReadOnlyObjectException();
159: mDetails.SQLSelector = pSQLSelector;
160: }
161:
162: /* Returns boolean flag indicating if this selector is an implicit selector */
163: public boolean isImplicit() throws BOException {
164: loadDetailsIfNecessary();
165: return mDetails.IsImplicit;
166:
167: }
168:
169: /** Sets boolean flag indicating if this selector is an implicit selector */
170: public void setIsImplicit(boolean isImplicit) throws BOException {
171: if (!isBeingEdited())
172: throw new BOInvalidOperationForReadOnlyObjectException();
173: mDetails.IsImplicit = isImplicit;
174: }
175:
176: protected void loadDetailsIfNecessary() throws BOException {
177: if (mDetails == null) {
178: try {
179: // Get the instance of the enterprise ps home via jndi
180: Context ctx = new InitialContext();
181: PSEntity lPs = (PSEntity) ctx
182: .lookup(PSEntity.COMPONENT_URL);
183:
184: mDetails = lPs.getSelector(mEntity.getRef(),
185: mSelectorName);
186: if (mDetails == null)
187: throw new BOException(
188: "Selector not found. (EntityRef:"
189: + mEntity.getRef()
190: + ", SelectorName:" + mSelectorName);
191: } catch (NamingException e) {
192: throw new BONamingAndDirectoryServiceInvocationException(
193: "", e);
194: } catch (PSException e) {
195: throw new BOPersistenceServiceInvocationException(
196: "Exception caught during processing of Selector. EntityRef:"
197: + mEntity.getRef() + ", SelectorName:"
198: + mSelectorName, e);
199: }
200: }
201: }
202:
203: protected void onBeginEdit() throws BOException {
204: // Fully load the object
205: loadDetailsIfNecessary();
206: }
207:
208: /* Encapsulates commit action by this object */
209: protected void onCommitCreation() throws BOException {
210: try {
211: // Get the instance of the enterprise ps home via jndi
212: Context ctx = new InitialContext();
213: PSEntity lPs = (PSEntity) ctx
214: .lookup(PSEntity.COMPONENT_URL);
215: lPs.insertSelector(mEntity.getRef(), mDetails);
216: } catch (NamingException e) {
217: throw new BONamingAndDirectoryServiceInvocationException(
218: "", e);
219: } catch (PSException e) {
220: throw new BOPersistenceServiceInvocationException("", e);
221: }
222: }
223:
224: }
|