01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.sdlctools.models.impl.metabossmodel.enterprisemodel.systemimplementationmodel;
16:
17: import java.util.Collection;
18: import java.util.List;
19:
20: import javax.jmi.reflect.ConstraintViolationException;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.netbeans.mdr.storagemodel.StorableObject;
25:
26: import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementImpl;
27: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationType;
28: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
29: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Association;
30: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
31:
32: public abstract class AssociationImpl extends ModelElementImpl
33: implements Association {
34: // Commons Logging instance.
35: private static final Log sLogger = LogFactory
36: .getLog(AssociationImpl.class);
37:
38: // Required constructor
39: protected AssociationImpl(StorableObject storable) {
40: super (storable);
41: }
42:
43: // Verify certain constraints
44: protected Collection _verify(Collection pViolations) {
45: // First call superclass
46: Collection lViolations = super ._verify(pViolations);
47:
48: // Constraint #1 - of the two association roles only one must have aggregation type COMPOSITION or AGGREGATION and the other must
49: // have NONE
50: {
51: List lRoles = getRoles();
52: // Cardinality constraint is checked elsewhere, just skip it
53: if (lRoles.size() == 2) {
54: AssociationRole lRoleA = (AssociationRole) lRoles
55: .get(0);
56: AggregationType lRoleAAggregationType = lRoleA
57: .getAggregationType();
58: AssociationRole lRoleB = (AssociationRole) lRoles
59: .get(1);
60: AggregationType lRoleBAggregationType = lRoleB
61: .getAggregationType();
62: if (lRoleAAggregationType != null
63: && lRoleBAggregationType != null) {
64: if (lRoleAAggregationType
65: .equals(AggregationTypeEnum.NONE)
66: && lRoleBAggregationType
67: .equals(AggregationTypeEnum.NONE))
68: lViolations
69: .add(new ConstraintViolationException(
70: this ,
71: refMetaObject(),
72: "One of two ends of the Association must have aggregation type of 'Composition' or 'Aggregation'."));
73: else if ((!lRoleAAggregationType
74: .equals(AggregationTypeEnum.NONE))
75: && (!lRoleBAggregationType
76: .equals(AggregationTypeEnum.NONE)))
77: lViolations
78: .add(new ConstraintViolationException(
79: this ,
80: refMetaObject(),
81: "Only one of the two ends of the Association can have aggregation type of 'Composition' or 'Aggregation'."));
82: }
83: }
84: }
85: return lViolations;
86: }
87: }
|