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 com.metaboss.enterprise.bo.BOException;
018: import com.metaboss.enterprise.bo.BOIllegalArgumentException;
019: import com.metaboss.enterprise.bo.BOUnexpectedProgramConditionException;
020: import com.metaboss.sdlctools.domains.enterprisemodel.BOConstraint;
021: import com.metaboss.sdlctools.domains.enterprisemodel.BOEntity;
022: import com.metaboss.sdlctools.domains.enterprisemodel.BOField;
023: import com.metaboss.sdlctools.domains.enterprisemodel.BOOperation;
024: import com.metaboss.sdlctools.domains.enterprisemodel.BOReport;
025: import com.metaboss.sdlctools.domains.enterprisemodel.BOSelector;
026: import com.metaboss.sdlctools.domains.enterprisemodel.BOStructure;
027: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STConstraint;
028: import com.oldboss.framework.bo.impl.BOObjectImpl;
029:
030: public class BOConstraintImpl extends BOObjectImpl implements
031: BOConstraint {
032: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
033: protected BOStructure mOwnerStructure = null;
034: protected BOOperation mOwnerOperation = null;
035: protected BOEntity mOwnerEntity = null;
036: private boolean mIsOperationInputConstraint = false; // Only true if this is an operation input constraint
037: private boolean mIsEntityConstraint = false; // Only true if this is an entity constraint
038: private boolean mIsStructureConstraint = false; // Only true if this is structure constraint
039: protected STConstraint mDetails = null;
040:
041: /* Instance creator */
042: public static BOConstraint createInstanceForExistingStructureConstraint(
043: BOMetaBossDomainImpl pMetaBossDomainImpl,
044: BOStructure pOwnerStructure, STConstraint pDetails)
045: throws BOException {
046: if (pDetails == null)
047: throw new BOIllegalArgumentException(
048: "Empty details structure");
049: if (pDetails.Name == null || pDetails.Name.length() == 0)
050: throw new BOIllegalArgumentException(
051: "Empty name field inside details structure");
052: BOConstraintImpl lImpl = new BOConstraintImpl();
053: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
054: lImpl.mOwnerStructure = pOwnerStructure;
055: lImpl.mDetails = pDetails;
056: lImpl.mIsStructureConstraint = true;
057: lImpl.setupForExisting();
058: return lImpl;
059: }
060:
061: public static BOConstraint createInstanceForExistingOperationInputConstraint(
062: BOMetaBossDomainImpl pMetaBossDomainImpl,
063: BOOperation pOwnerOperation, STConstraint pDetails)
064: throws BOException {
065: if (pDetails == null)
066: throw new BOIllegalArgumentException(
067: "Empty details structure");
068: if (pDetails.Name == null || pDetails.Name.length() == 0)
069: throw new BOIllegalArgumentException(
070: "Empty name field inside details structure");
071: BOConstraintImpl lImpl = new BOConstraintImpl();
072: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
073: lImpl.mOwnerOperation = pOwnerOperation;
074: lImpl.mDetails = pDetails;
075: lImpl.mIsOperationInputConstraint = true;
076: lImpl.setupForExisting();
077: return lImpl;
078: }
079:
080: public static BOConstraint createInstanceForExistingEntityConstraint(
081: BOMetaBossDomainImpl pMetaBossDomainImpl,
082: BOEntity pOwnerEntity, STConstraint pDetails)
083: throws BOException {
084: if (pDetails == null)
085: throw new BOIllegalArgumentException(
086: "Empty details structure");
087: if (pDetails.Name == null || pDetails.Name.length() == 0)
088: throw new BOIllegalArgumentException(
089: "Empty name field inside details structure");
090: BOConstraintImpl lImpl = new BOConstraintImpl();
091: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
092: lImpl.mOwnerEntity = pOwnerEntity;
093: lImpl.mDetails = pDetails;
094: lImpl.mIsEntityConstraint = true;
095: lImpl.setupForExisting();
096: return lImpl;
097: }
098:
099: // Hidden constructor
100: private BOConstraintImpl() {
101: }
102:
103: /* Retrieves element's name. Name is only unique within parent entity */
104: public String getName() throws BOException {
105: return mDetails.Name;
106: }
107:
108: /* Returns element's description */
109: public String getDescription() throws BOException {
110: return mDetails.Description;
111: }
112:
113: /* Returns element's OCLExpression */
114: public String getOCLExpression() throws BOException {
115: return mDetails.OCLExpression;
116: }
117:
118: /* Returns element's OCLExpression */
119: public String getDefaultErrorText() throws BOException {
120: return mDetails.DefaultErrorText;
121: }
122:
123: /* Returns structure which owns this constraint or null if this constraint is not owned by structure */
124: public BOStructure getOwnerStructure() {
125: return mOwnerStructure;
126: }
127:
128: /* Returns operation which owns this constraint or null if this constraint is not owned by operation */
129: public BOOperation getOwnerOperation() {
130: return mOwnerOperation;
131: }
132:
133: /* Returns entity which owns this constraint or null if this constraint is not owned by report */
134: public BOEntity getOwnerEntity() {
135: return mOwnerEntity;
136: }
137:
138: private static String generateObjectId(String pName,
139: BOStructure pOwnerStructure, BOOperation pOwnerOperation,
140: BOReport pOwnerReport, BOSelector pOwnerSelector,
141: boolean pIsOperationInputField,
142: boolean pIsOperationOutputField,
143: boolean pIsReportInputField, boolean pIsReportOutputField,
144: boolean pIsSelectorInputField, boolean pIsStructureField,
145: int pReportOutputFieldLevel) throws BOException {
146: if (pIsOperationInputField)
147: return BOField.class.getName() + "operation:"
148: + pOwnerOperation.getRef() + ":inp:" + pName;
149: if (pIsOperationOutputField)
150: return BOField.class.getName() + "operation:"
151: + pOwnerOperation.getRef() + ":out:" + pName;
152: if (pIsReportInputField)
153: return BOField.class.getName() + "report:"
154: + pOwnerReport.getRef() + ":inp:" + pName;
155: if (pIsReportOutputField)
156: return BOField.class.getName() + "report:"
157: + pOwnerReport.getRef() + ":out:"
158: + pReportOutputFieldLevel + ":" + pName;
159: if (pIsSelectorInputField)
160: return BOField.class.getName() + "selector:"
161: + pOwnerSelector.getRef() + ":inp:" + pName;
162: if (pIsStructureField)
163: return BOField.class.getName() + "structure:"
164: + pOwnerStructure.getRef() + ":" + pName;
165: throw new BOUnexpectedProgramConditionException(
166: "Unknown field type. Unable to generate ObjectId for it");
167: }
168: }
|