automatical synchronization of references with association ends (by implementing BLD200210040100
authormmatula@netbeans.org
Thu, 03 Oct 2002 16:48:59 +0000
changeset 106540e2f8a1a13c
parent 1064 152f122b1662
child 1066 3c9726f96386
automatical synchronization of references with association ends (by implementing
post processing on RefersTo association)
mdr/src/org/netbeans/jmiimpl/mof/model/RefersToImpl.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mdr/src/org/netbeans/jmiimpl/mof/model/RefersToImpl.java	Thu Oct 03 16:48:59 2002 +0000
     1.3 @@ -0,0 +1,60 @@
     1.4 +/*
     1.5 + *                 Sun Public License Notice
     1.6 + *
     1.7 + * The contents of this file are subject to the Sun Public License
     1.8 + * Version 1.0 (the "License"). You may not use this file except in
     1.9 + * compliance with the License. A copy of the License is available at
    1.10 + * http://www.sun.com/
    1.11 + *
    1.12 + * The Original Code is NetBeans. The Initial Developer of the Original
    1.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
    1.14 + * Microsystems, Inc. All Rights Reserved.
    1.15 + */
    1.16 +package org.netbeans.jmiimpl.mof.model;
    1.17 +
    1.18 +import java.util.Collection;
    1.19 +import javax.jmi.model.AssociationEnd;
    1.20 +import javax.jmi.model.Classifier;
    1.21 +import javax.jmi.model.MultiplicityType;
    1.22 +import javax.jmi.model.Reference;
    1.23 +import javax.jmi.model.RefersTo;
    1.24 +import org.netbeans.mdr.handlers.AssociationHandler;
    1.25 +import org.netbeans.mdr.storagemodel.StorableAssociation;
    1.26 +import org.netbeans.mdr.util.Logger;
    1.27 +
    1.28 +/**
    1.29 + *
    1.30 + * @author  mm109185
    1.31 + */
    1.32 +public abstract class RefersToImpl extends AssociationHandler implements RefersTo {
    1.33 +    
    1.34 +    /** Creates a new instance of RefersToImpl */
    1.35 +    public RefersToImpl(StorableAssociation s) {
    1.36 +        super(s);
    1.37 +    }
    1.38 +    
    1.39 +    public boolean add(Reference reference, AssociationEnd associationEnd) {
    1.40 +        boolean result = super_add(reference, associationEnd);
    1.41 +        if (result) {
    1.42 +            boolean isChangeable = associationEnd.isChangeable();
    1.43 +            MultiplicityType multiplicity = associationEnd.getMultiplicity();
    1.44 +            
    1.45 +            if (reference.isChangeable() != isChangeable) {
    1.46 +                Logger.getDefault().log(Logger.WARNING, "Reference<->AssociationEnd inconsistency: \n    " +
    1.47 +                    reference.getName() + "[Reference].isChangeable = " + reference.isChangeable() +
    1.48 +                    "\n    " + associationEnd.getName() + "[AssociationEnd].isChangeable = " + isChangeable);
    1.49 +                reference.setChangeable(isChangeable);
    1.50 +                Logger.getDefault().log(Logger.WARNING, "Value of isChangeable attribute of the reference was updated to " + isChangeable);
    1.51 +            } else if (!reference.getMultiplicity().equals(multiplicity)) {
    1.52 +                Logger.getDefault().log(Logger.WARNING, "Reference<->AssociationEnd inconsistency: \n    " +
    1.53 +                    reference.getName() + "[Reference].multiplicity = " + reference.getMultiplicity() +
    1.54 +                    "\n    " + associationEnd.getName() + "[AssociationEnd].multiplicity = " + multiplicity);
    1.55 +                reference.setMultiplicity(multiplicity);
    1.56 +                Logger.getDefault().log(Logger.WARNING, "Value of multiplicity attribute of the reference was updated to " + multiplicity);
    1.57 +            }
    1.58 +        }
    1.59 +        return result;
    1.60 +    }
    1.61 +        
    1.62 +    protected abstract boolean super_add(Reference reference, AssociationEnd associationEnd);
    1.63 +}