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.BOIllegalArgumentException;
023: import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
024: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
025: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
026: import com.metaboss.enterprise.bo.BOUnexpectedProgramConditionException;
027: import com.metaboss.enterprise.ps.PSException;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BODatatype;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOField;
030: import com.metaboss.sdlctools.domains.enterprisemodel.BOOperation;
031: import com.metaboss.sdlctools.domains.enterprisemodel.BOReport;
032: import com.metaboss.sdlctools.domains.enterprisemodel.BOSelector;
033: import com.metaboss.sdlctools.domains.enterprisemodel.BOStructure;
034: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSEntity;
035: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSService;
036: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSStructure;
037: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STField;
038: import com.oldboss.framework.bo.BOObject;
039: import com.oldboss.framework.bo.BOTransaction;
040: import com.oldboss.framework.bo.impl.BOObjectImpl;
041:
042: public class BOFieldImpl extends BOObjectImpl implements BOField {
043: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
044: protected BOStructure mOwnerStructure = null;
045: protected BOOperation mOwnerOperation = null;
046: protected BOReport mOwnerReport = null;
047: protected BOSelector mOwnerSelector = null;
048: private boolean mIsOperationInputField = false; // Only true if this is an operation input field
049: private boolean mIsOperationOutputField = false; // Only true if this is an operation output field
050: private boolean mIsReportInputField = false; // Only true if this is report input field
051: private boolean mIsReportOutputField = false; // Only true if this is report output field
052: private boolean mIsSelectorInputField = false; // Only true if this is selector input field
053: private boolean mIsStructureField = false; // Only true if this is selector input field
054: private int mReportOutputFieldLevel = -1; // Only true if this is report element output field
055: protected STField mDetails = null;
056: private String mObjectId = null;
057:
058: /* Instance creator */
059: public static BOField createInstanceForExistingStructureField(
060: BOMetaBossDomainImpl pMetaBossDomainImpl,
061: BOStructure pOwnerStructure, STField pDetails)
062: throws BOException {
063: if (pDetails == null)
064: throw new BOIllegalArgumentException(
065: "Empty details structure");
066: if (pDetails.Name == null || pDetails.Name.length() == 0)
067: throw new BOIllegalArgumentException(
068: "Empty name field inside details structure");
069: BOFieldImpl lImpl = new BOFieldImpl();
070: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
071: lImpl.mOwnerStructure = pOwnerStructure;
072: lImpl.mDetails = pDetails;
073: lImpl.mIsStructureField = true;
074: lImpl.mObjectId = generateObjectId(pDetails.Name,
075: pOwnerStructure, null, null, null, false, false, false,
076: false, false, true, -1);
077: lImpl.setupForExisting();
078: return lImpl;
079: }
080:
081: public static BOField createInstanceForExistingOperationOutputField(
082: BOMetaBossDomainImpl pMetaBossDomainImpl,
083: BOOperation pOwnerOperation, STField pDetails)
084: throws BOException {
085: if (pDetails == null)
086: throw new BOIllegalArgumentException(
087: "Empty details structure");
088: if (pDetails.Name == null || pDetails.Name.length() == 0)
089: throw new BOIllegalArgumentException(
090: "Empty name field inside details structure");
091: BOFieldImpl lImpl = new BOFieldImpl();
092: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
093: lImpl.mOwnerOperation = pOwnerOperation;
094: lImpl.mDetails = pDetails;
095: lImpl.mIsOperationOutputField = true;
096: lImpl.mObjectId = generateObjectId(pDetails.Name, null,
097: pOwnerOperation, null, null, false, true, false, false,
098: false, false, -1);
099: lImpl.setupForExisting();
100: return lImpl;
101: }
102:
103: public static BOField createInstanceForExistingReportInputField(
104: BOMetaBossDomainImpl pMetaBossDomainImpl,
105: BOReport pOwnerReport, STField pDetails) throws BOException {
106: if (pDetails == null)
107: throw new BOIllegalArgumentException(
108: "Empty details structure");
109: if (pDetails.Name == null || pDetails.Name.length() == 0)
110: throw new BOIllegalArgumentException(
111: "Empty name field inside details structure");
112: BOFieldImpl lImpl = new BOFieldImpl();
113: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
114: lImpl.mOwnerReport = pOwnerReport;
115: lImpl.mDetails = pDetails;
116: lImpl.mIsReportInputField = true;
117: lImpl.mObjectId = generateObjectId(pDetails.Name, null, null,
118: pOwnerReport, null, false, false, true, false, false,
119: false, -1);
120: lImpl.setupForExisting();
121: return lImpl;
122: }
123:
124: public static BOField createInstanceForExistingReportOutputField(
125: BOMetaBossDomainImpl pMetaBossDomainImpl,
126: BOReport pOwnerReport, int pLevel, STField pDetails)
127: throws BOException {
128: if (pDetails == null)
129: throw new BOIllegalArgumentException(
130: "Empty details structure");
131: if (pDetails.Name == null || pDetails.Name.length() == 0)
132: throw new BOIllegalArgumentException(
133: "Empty name field inside details structure");
134: BOFieldImpl lImpl = new BOFieldImpl();
135: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
136: lImpl.mOwnerReport = pOwnerReport;
137: lImpl.mDetails = pDetails;
138: lImpl.mIsReportOutputField = true;
139: lImpl.mReportOutputFieldLevel = pLevel;
140: lImpl.mObjectId = generateObjectId(pDetails.Name, null, null,
141: pOwnerReport, null, false, false, false, true, false,
142: false, pLevel);
143: lImpl.setupForExisting();
144: return lImpl;
145: }
146:
147: public static BOField createInstanceForExistingOperationInputField(
148: BOMetaBossDomainImpl pMetaBossDomainImpl,
149: BOOperation pOwnerOperation, STField pDetails)
150: throws BOException {
151: if (pDetails == null)
152: throw new BOIllegalArgumentException(
153: "Empty details structure");
154: if (pDetails.Name == null || pDetails.Name.length() == 0)
155: throw new BOIllegalArgumentException(
156: "Empty name field inside details structure");
157: BOFieldImpl lImpl = new BOFieldImpl();
158: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
159: lImpl.mOwnerOperation = pOwnerOperation;
160: lImpl.mIsOperationInputField = true;
161: lImpl.mDetails = pDetails;
162: lImpl.mObjectId = generateObjectId(pDetails.Name, null,
163: pOwnerOperation, null, null, true, false, false, false,
164: false, false, -1);
165: lImpl.setupForExisting();
166: return lImpl;
167: }
168:
169: public static BOField createInstanceForExistingSelectorInputField(
170: BOMetaBossDomainImpl pMetaBossDomainImpl,
171: BOSelector pOwnerSelector, STField pDetails)
172: throws BOException {
173: if (pDetails == null)
174: throw new BOIllegalArgumentException(
175: "Empty details structure");
176: if (pDetails.Name == null || pDetails.Name.length() == 0)
177: throw new BOIllegalArgumentException(
178: "Empty name field inside details structure");
179: // Selector field may not contain reference to structure
180: if (pDetails.StructRef != null
181: && pDetails.StructRef.length() > 0)
182: throw new BOIllegalArgumentException(
183: "Selector may not have Structure as an input field. EntityRef: "
184: + pOwnerSelector.getEntity().getRef()
185: + " SelectorName: "
186: + pOwnerSelector.getName() + " FieldName: "
187: + pDetails.Name);
188: BOFieldImpl lImpl = new BOFieldImpl();
189: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
190: lImpl.mOwnerSelector = pOwnerSelector;
191: lImpl.mDetails = pDetails;
192: lImpl.mIsSelectorInputField = true;
193: lImpl.mObjectId = generateObjectId(pDetails.Name, null, null,
194: null, pOwnerSelector, false, false, false, false, true,
195: false, -1);
196: lImpl.setupForExisting();
197: return lImpl;
198: }
199:
200: public static BOField createInstanceForNewSelectorInputField(
201: BOTransaction pTransaction,
202: BOMetaBossDomainImpl pMetaBossDomainImpl,
203: BOSelector pOwnerSelector, String pName) throws BOException {
204: if (pName == null || pName.length() == 0)
205: throw new BOIllegalArgumentException(
206: "Name of the field must not be empty");
207: BOFieldImpl lImpl = new BOFieldImpl();
208: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
209: lImpl.mOwnerSelector = pOwnerSelector;
210: lImpl.mDetails = new STField();
211: lImpl.mDetails.Name = pName;
212: lImpl.mIsSelectorInputField = true;
213: lImpl.mObjectId = generateObjectId(pName, null, null, null,
214: pOwnerSelector, false, false, false, false, true,
215: false, -1);
216: lImpl.setupForNew(pTransaction);
217: return lImpl;
218: }
219:
220: /* Instance creator */
221: public static BOField createInstanceForNewStructureField(
222: BOTransaction pTransaction,
223: BOMetaBossDomainImpl pMetaBossDomainImpl,
224: BOStructure pOwnerStructure, String pName)
225: throws BOException {
226: if (pName == null || pName.length() == 0)
227: throw new BOIllegalArgumentException(
228: "Name of the field must not be empty");
229: BOFieldImpl lImpl = new BOFieldImpl();
230: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
231: lImpl.mOwnerStructure = pOwnerStructure;
232: lImpl.mDetails = new STField();
233: lImpl.mDetails.Name = pName;
234: lImpl.mIsStructureField = true;
235: lImpl.mObjectId = generateObjectId(pName, pOwnerStructure,
236: null, null, null, false, false, false, false, false,
237: true, -1);
238: lImpl.setupForNew(pTransaction);
239: return lImpl;
240: }
241:
242: public static BOField createInstanceForNewOperationOutputField(
243: BOTransaction pTransaction,
244: BOMetaBossDomainImpl pMetaBossDomainImpl,
245: BOOperation pOwnerOperation, String pName)
246: throws BOException {
247: if (pName == null || pName.length() == 0)
248: throw new BOIllegalArgumentException(
249: "Name of the field must not be empty");
250: BOFieldImpl lImpl = new BOFieldImpl();
251: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
252: lImpl.mOwnerOperation = pOwnerOperation;
253: lImpl.mDetails = new STField();
254: lImpl.mDetails.Name = pName;
255: lImpl.mIsOperationOutputField = true;
256: lImpl.mObjectId = generateObjectId(pName, null,
257: pOwnerOperation, null, null, false, true, false, false,
258: false, false, -1);
259: lImpl.setupForNew(pTransaction);
260: return lImpl;
261: }
262:
263: public static BOField createInstanceForNewOperationInputField(
264: BOTransaction pTransaction,
265: BOMetaBossDomainImpl pMetaBossDomainImpl,
266: BOOperation pOwnerOperation, String pName)
267: throws BOException {
268: if (pName == null || pName.length() == 0)
269: throw new BOIllegalArgumentException(
270: "Name of the field must not be empty");
271: BOFieldImpl lImpl = new BOFieldImpl();
272: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
273: lImpl.mOwnerOperation = pOwnerOperation;
274: lImpl.mIsOperationInputField = true;
275: lImpl.mDetails = new STField();
276: lImpl.mDetails.Name = pName;
277: lImpl.mObjectId = generateObjectId(pName, null,
278: pOwnerOperation, null, null, true, false, false, false,
279: false, false, -1);
280: lImpl.setupForNew(pTransaction);
281: return lImpl;
282: }
283:
284: // Hidden constructor
285: private BOFieldImpl() {
286: }
287:
288: // Return unique string representing the object
289: public String getObjectId() throws BOException {
290: return mObjectId;
291: }
292:
293: /* Retrieves element's name. Name is only unique within parent entity */
294: public String getName() throws BOException {
295: return mDetails.Name;
296: }
297:
298: /* Returns element's description */
299: public String getDescription() throws BOException {
300: return mDetails.Description;
301: }
302:
303: /* Returns structure which owns this field or null if this field is not owned by structure */
304: public BOStructure getOwnerStructure() {
305: return mOwnerStructure;
306: }
307:
308: /* Returns operation which owns this field or null if this field is not owned by operation */
309: public BOOperation getOwnerOperation() {
310: return mOwnerOperation;
311: }
312:
313: /* Returns report which owns this field or null if this field is not owned by report */
314: public BOReport getOwnerReport() {
315: return mOwnerReport;
316: }
317:
318: /* Returns selector which owns this field or null if this field is not owned by selector */
319: public BOSelector getOwnerSelector() {
320: return mOwnerSelector;
321: }
322:
323: /* Sets description */
324: public void setDescription(String pDescription) throws BOException {
325: if (!isBeingEdited())
326: throw new BOInvalidOperationForReadOnlyObjectException();
327: mDetails.Description = pDescription;
328: }
329:
330: /* Returns boolean if this field is an array */
331: public boolean isArray() throws BOException {
332: return mDetails.IsArray;
333: }
334:
335: /* Sets is array flag */
336: public void setIsArray(boolean isArray) throws BOException {
337: if (!isBeingEdited())
338: throw new BOInvalidOperationForReadOnlyObjectException();
339: mDetails.IsArray = isArray;
340: }
341:
342: /** Returns type object It may be of type BODataType or BOStructure */
343: public BOObject getType() throws BOException {
344: if (mDetails.DataTypeRef != null
345: && mDetails.DataTypeRef.length() > 0)
346: return BODatatypeImpl.createInstanceForExisting(
347: mMetaBossDomainImpl, mDetails.DataTypeRef);
348: else if (mDetails.StructRef != null
349: && mDetails.StructRef.length() > 0)
350: return BOStructureImpl.createInstanceForExisting(
351: mMetaBossDomainImpl, mDetails.StructRef);
352: else
353: throw new BOException("Undefined field type");
354: }
355:
356: /* Sets type to the given datatype */
357: public void setType(BODatatype pDatatype) throws BOException {
358: if (!isBeingEdited())
359: throw new BOInvalidOperationForReadOnlyObjectException();
360: mDetails.DataTypeRef = pDatatype.getRef();
361: mDetails.StructRef = null;
362: }
363:
364: /* Sets type to the given structure type */
365: public void setType(BOStructure pStructure) throws BOException {
366: if (!isBeingEdited())
367: throw new BOInvalidOperationForReadOnlyObjectException();
368: if (!isBeingEdited())
369: throw new BOInvalidOperationForReadOnlyObjectException();
370: mDetails.DataTypeRef = null;
371: mDetails.StructRef = pStructure.getRef();
372: }
373:
374: /* Encapsulates commit action by this object */
375: protected void onCommitCreation() throws BOException {
376: try {
377: // Get the instance of the enterprise ps home via jndi
378: Context ctx = new InitialContext();
379: if (mOwnerStructure != null) {
380: PSStructure lPs = (PSStructure) ctx
381: .lookup(PSStructure.COMPONENT_URL);
382: lPs.insertField(mOwnerStructure.getRef(), mDetails);
383: } else if (mOwnerOperation != null) {
384: PSService lPs = (PSService) ctx
385: .lookup(PSService.COMPONENT_URL);
386: if (mIsOperationInputField)
387: lPs.insertInputField(mOwnerOperation.getService()
388: .getRef(), mOwnerOperation.getName(),
389: mDetails);
390: else
391: lPs.insertOutputField(mOwnerOperation.getService()
392: .getRef(), mOwnerOperation.getName(),
393: mDetails);
394: } else if (mOwnerSelector != null) {
395: PSEntity lPs = (PSEntity) ctx
396: .lookup(PSEntity.COMPONENT_URL);
397: lPs.insertSelectorInputField(mOwnerSelector.getEntity()
398: .getRef(), mOwnerSelector.getName(), mDetails);
399: } else
400: throw new PSException("Operation not supported");
401: } catch (NamingException e) {
402: throw new BONamingAndDirectoryServiceInvocationException(
403: "", e);
404: } catch (PSException e) {
405: throw new BOPersistenceServiceInvocationException("", e);
406: }
407: }
408:
409: private static String generateObjectId(String pName,
410: BOStructure pOwnerStructure, BOOperation pOwnerOperation,
411: BOReport pOwnerReport, BOSelector pOwnerSelector,
412: boolean pIsOperationInputField,
413: boolean pIsOperationOutputField,
414: boolean pIsReportInputField, boolean pIsReportOutputField,
415: boolean pIsSelectorInputField, boolean pIsStructureField,
416: int pReportOutputFieldLevel) throws BOException {
417: if (pIsOperationInputField)
418: return BOField.class.getName() + "operation:"
419: + pOwnerOperation.getRef() + ":inp:" + pName;
420: if (pIsOperationOutputField)
421: return BOField.class.getName() + "operation:"
422: + pOwnerOperation.getRef() + ":out:" + pName;
423: if (pIsReportInputField)
424: return BOField.class.getName() + "report:"
425: + pOwnerReport.getRef() + ":inp:" + pName;
426: if (pIsReportOutputField)
427: return BOField.class.getName() + "report:"
428: + pOwnerReport.getRef() + ":out:"
429: + pReportOutputFieldLevel + ":" + pName;
430: if (pIsSelectorInputField)
431: return BOField.class.getName() + "selector:"
432: + pOwnerSelector.getRef() + ":inp:" + pName;
433: if (pIsStructureField)
434: return BOField.class.getName() + "structure:"
435: + pOwnerStructure.getRef() + ":" + pName;
436: throw new BOUnexpectedProgramConditionException(
437: "Unknown field type. Unable to generate ObjectId for it");
438: }
439: }
|