org.sparx.Collection - java examples

Here are the examples of the java api org.sparx.Collection taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

68 Examples 7

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * @param e      Element to which the new constraint shall be added.
 * @param name   Name of the new constraint
 * @param type   Type of the new constraint
 * @param text   Text of the new constraint
 * @param status Status of the new constraint
 * @return The new constraint
 * @throws EAException tbd
 */
public static org.sparx.Constraint addConstraint(Element e, String name, String type, String text, String status) throws EAException {
    Collection<org.sparx.Constraint> cons = e.GetConstraints();
    org.sparx.Constraint con = cons.AddNew(name, type);
    cons.Refresh();
    con.SetNotes(text);
    if (StringUtils.isNotBlank(status)) {
        con.SetStatus(status);
    }
    if (!con.Update()) {
        throw new EAException(createMessage(message(1006), name, e.GetName(), con.GetLastError()));
    } else {
        return con;
    }
}

19 View Complete Implementation : EARepositoryUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Identify the child package with given stereotype. NOTE: Additional such
 * packages are ignored.
 *
 * @param rep           the repository to query
 * @param eaParentPkgId EA ID of the parent package
 * @param stereotype    Stereotype of the child package to look up
 * @return the EA ID of the package if it was found, else <code>null</code>
 */
public static Integer getEAChildPackageByStereotype(Repository rep, int eaParentPkgId, String stereotype) {
    Package eaParentPkg = rep.GetPackageByID(eaParentPkgId);
    Collection<Package> pkgs = eaParentPkg.GetPackages();
    for (short i = 0; i < pkgs.GetCount(); i++) {
        Package p = pkgs.GetAt(i);
        if (p.GetStereotypeEx().contains(stereotype)) {
            return p.GetPackageID();
        }
    }
    return null;
}

19 View Complete Implementation : EAConnectorEndUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public static void deleteTaggedValue(ConnectorEnd ce, String nameOfTVToDelete) {
    Collection<RoleTag> cTV = ce.GetTaggedValues();
    cTV.Refresh();
    for (short i = 0; i < cTV.GetCount(); i++) {
        RoleTag tv = cTV.GetAt(i);
        if (tv.GetTag().equalsIgnoreCase(nameOfTVToDelete)) {
            cTV.Delete(i);
        }
    }
    cTV.Refresh();
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * @param elmt    EA element in which to look for the attribute
 * @param attName name of the attribute to look up
 * @return the EA attribute that belongs to the EA element and has the given
 *         attribute name; can be <code>null</code> if no such attribute was
 *         found
 */
public static Attribute getAttributeByName(Element elmt, String attName) {
    Attribute result = null;
    Collection<Attribute> atts = elmt.GetAttributes();
    for (short i = 0; i < atts.GetCount(); i++) {
        Attribute att = atts.GetAt(i);
        if (att.GetName().equals(attName)) {
            result = att;
            break;
        }
    }
    return result;
}

19 View Complete Implementation : EAConnectorUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given collection of tagged values to the given connector, NOT
 * checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a model element that adheres to a specific UML profile. In that case,
 * adding the same tagged values would lead to duplicates. If duplicates
 * shall be prevented, set the tagged value instead of adding it.
 *
 * @param con
 *                the connector to which the tagged values shall be added
 * @param tvs
 *                collection of tagged values to add
 * @throws EAException  tbd
 */
public static void addTaggedValues(Connector con, TaggedValues tvs) throws EAException {
    if (tvs == null || tvs.isEmpty()) {
    // nothing to do
    } else {
        Collection<ConnectorTag> cTV = con.GetTaggedValues();
        for (Entry<String, List<String>> e : tvs.asMap().entrySet()) {
            String name = e.getKey();
            List<String> values = e.getValue();
            if (values != null) {
                for (String v : values) {
                    ConnectorTag eaTv = cTV.AddNew(name, "");
                    cTV.Refresh();
                    if (v.length() > 255) {
                        eaTv.SetValue("<memo>");
                        eaTv.SetNotes(v);
                    } else {
                        eaTv.SetValue(v);
                        eaTv.SetNotes("");
                    }
                    if (!eaTv.Update()) {
                        throw new EAException(createMessage(message(101), name, con.GetName(), v, eaTv.GetLastError()));
                    }
                }
            }
        }
    }
}

19 View Complete Implementation : EAAttributeUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Updates the tagged values with given name (which can be a fully qualified
 * name) in the tagged values of the given attribute. Does NOT delete those
 * tagged values. NOTE: This method is especially useful when setting tagged
 * values that are defined by an MDG / UML Profile, since these tagged
 * values cannot be created programmatically (they are created by EA - for
 * further details, see
 * http://sparxsystems.com/forums/smf/index.php?topic=3859.0).
 *
 * @param att
 *            the attribute in which the tagged values shall be updated
 * @param name
 *            (fully qualified or unqualified) name of the tagged value to
 *            update, must not be <code>null</code>
 * @param value
 *            value of the tagged value to update, can be <code>null</code>
 * @param createAsMemoField
 *            If set to <code>true</code>, the value shall be encoded using a
 *            <memo> field, regardless of the actual length of the
 *            value.
 * @throws EAException
 *             If updating the attribute did not succeed, this exception
 *             contains the error message.
 */
public static void updateTaggedValue(Attribute att, String name, String value, boolean createAsMemoField) throws EAException {
    boolean isQualifiedName = name.contains("::");
    Collection<AttributeTag> cTV = att.GetTaggedValues();
    cTV.Refresh();
    for (short i = 0; i < cTV.GetCount(); i++) {
        AttributeTag tv = cTV.GetAt(i);
        if ((isQualifiedName && tv.GetFQName().equalsIgnoreCase(name)) || tv.GetName().equalsIgnoreCase(name)) {
            if (createAsMemoField || value.length() > 255) {
                tv.SetValue("<memo>");
                tv.SetNotes(value);
            } else {
                tv.SetValue(value);
                tv.SetNotes("");
            }
            if (!tv.Update()) {
                throw new EAException(createMessage(message(102), name, att.GetName(), value, tv.GetLastError()));
            }
        }
    }
    cTV.Refresh();
}

19 View Complete Implementation : EAMethodUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given list of tagged values to the collection of (EA) tagged
 * values of the given method, NOT checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a method that adheres to a specific UML profile. In that case, adding
 * the same tagged values would lead to duplicates. If duplicates shall be
 * prevented, set the tagged value instead of adding it.
 *
 * @param m tbd
 * @param tvs
 *            collection of tagged values to add
 * @throws EAException  tbd
 */
public static void addTaggedValues(Method m, List<EATaggedValue> tvs) throws EAException {
    if (tvs == null || tvs.isEmpty()) {
    // nothing to do
    } else {
        Collection<MethodTag> cTV = m.GetTaggedValues();
        for (EATaggedValue tv : tvs) {
            String name = tv.getName();
            List<String> values = tv.getValues();
            if (values != null) {
                for (String v : values) {
                    MethodTag eaTv = cTV.AddNew(name, "");
                    cTV.Refresh();
                    if (tv.createAsMemoField() || v.length() > 255) {
                        eaTv.SetValue("<memo>");
                        eaTv.SetNotes(v);
                    } else {
                        eaTv.SetValue(v);
                        eaTv.SetNotes("");
                    }
                    if (!eaTv.Update()) {
                        throw new EAException(createMessage(message(105), name, m.GetName(), v, eaTv.GetLastError()));
                    }
                }
            }
        }
    }
}

19 View Complete Implementation : PackageInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public clreplaced PackageInfoEA extends PackageInfoImpl implements PackageInfo {

    /**
     * Flag used to prevent duplicate retrieval/computation of the alias of this
     * package.
     */
    protected boolean aliasAccessed = false;

    /**
     * Flag used to prevent duplicate retrieval/computation of the connectors of
     * this package.
     */
    protected boolean connectorsAccessed = false;

    /**
     * Flag used to prevent duplicate retrieval/computation of the doreplacedentation
     * of this package.
     */
    protected boolean doreplacedentationAccessed = false;

    /**
     * Flag used to prevent duplicate retrieval/computation of the
     * globalIdentifier of this clreplaced.
     */
    protected boolean globalIdentifierAccessed = false;

    /**
     * Access to the connectors of this package in the EA model
     */
    protected Collection<Connector> conns = null;

    /**
     * The Model object
     */
    protected EADoreplacedent doreplacedent = null;

    /**
     * The parent package object
     */
    protected PackageInfoEA parentPI = null;

    /**
     * Set of child package objects
     */
    protected TreeSet<PackageInfoEA> childPI = new TreeSet<PackageInfoEA>();

    /**
     * Set of child clreplacedes
     */
    protected TreeSet<ClreplacedInfoEA> childCI = new TreeSet<ClreplacedInfoEA>();

    /**
     * The EA package object
     */
    protected org.sparx.Package eaPackage = null;

    /**
     * The EA object id of the package object
     */
    protected int eaPackageId = 0;

    protected String packageId = null;

    /**
     * The EA element object possibly replacedociated to the package
     */
    protected Element eaPackageElmt = null;

    /**
     * The EA object id of the replacedociated element object
     */
    protected int eaPackageElmtId = 0;

    /**
     * Name of the Package
     */
    protected String eaName = null;

    public org.sparx.Package getEaPackageObj() {
        return eaPackage;
    }

    public int getEaPackageId() {
        return eaPackageId;
    }

    /**
     * Cache for the IDs of the suppliers of this clreplaced
     */
    protected TreeSet<String> supplierIds = null;

    public PackageInfoEA(EADoreplacedent doc, PackageInfoEA ppi, org.sparx.Package pack, Element packelmt) {
        // Memorize doreplacedent object
        doreplacedent = doc;
        // Store EA package object and inquire its id and name.
        eaPackage = pack;
        eaPackageId = eaPackage.GetPackageID();
        // augment integer id to achieve model-wide unique IDs required by
        // Info.id()
        packageId = "P" + Integer.valueOf(eaPackageId).toString();
        eaName = eaPackage.GetName().trim();
        // Store the possibly replacedociated EA element (describing the package) and
        // its id.
        eaPackageElmt = packelmt;
        if (eaPackageElmt != null)
            eaPackageElmtId = eaPackageElmt.GetElementID();
        // Memorize parent PackageInfo and establish this package as a child
        // of its parent.
        parentPI = ppi;
        if (ppi != null)
            ppi.childPI.add(this);
    }

    // PackageInfoEA Ctor
    /**
     * Return EA model object.
     */
    public Model model() {
        return doreplacedent;
    }

    /**
     * Return options and configuration object.
     */
    public Options options() {
        return doreplacedent.options;
    }

    /**
     * Return result object for error reporting.
     */
    public ShapeChangeResult result() {
        return doreplacedent.result;
    }

    /**
     * @see de.interactive_instruments.ShapeChange.Model.PackageInfo#containedPackages()
     */
    @SuppressWarnings("unchecked")
    public SortedSet<PackageInfo> containedPackages() {
        // Return a shallow copy of the stored child relation.
        return (TreeSet<PackageInfo>) childPI.clone();
    }

    // containedPackages()
    /**
     * The stereotypes added to the cache are the well-known equivalents of the
     * stereotypes defined in the EA model, if mapped in the configuration.
     *
     * @see de.interactive_instruments.ShapeChange.Model.Info#validateStereotypesCache()
     */
    public void validateStereotypesCache() {
        if (stereotypesCache == null) {
            // Fetch stereotypes 'collection' ...
            String sts = eaPackage.GetStereotypeEx();
            String[] stereotypes = sts.split("\\,");
            // Allocate cache
            stereotypesCache = StereotypeNormalizer.normalizeAndMapToWellKnownStereotype(stereotypes, this);
        }
    }

    // validateStereotypesCache()
    /**
     * Return the parent package if present, null otherwise.
     */
    public PackageInfo owner() {
        return parentPI;
    }

    // owner()
    @Override
    public SortedSet<String> supplierIds() {
        // Only retrieve/compute supplierIds once
        // Cache the results for subsequent use
        if (supplierIds == null) {
            // Prepare set to return
            supplierIds = new TreeSet<String>();
            // Ask EA for the connectors attached to the package object and loop
            // over the connectors returned
            // Only compute them once for the whole clreplaced
            if (!connectorsAccessed) {
                conns = eaPackage.GetConnectors();
                connectorsAccessed = true;
            }
            // Ensure that there are connectors before continuing
            if (conns != null) {
                for (Connector conn : conns) {
                    // Single out dependency connectors
                    String type = conn.GetType();
                    if (type.equals("Dependency") || type.equals("Package")) {
                        // From the dependency grab the id of the supplier
                        int suppId = conn.GetSupplierID();
                        String suppIdS = Integer.toString(suppId);
                        // Since all connectors are delivered from both objects
                        // at the
                        // connector ends, we have to make sure it is not
                        // accidently us,
                        // which we found.
                        if (suppId == eaPackageElmtId)
                            continue;
                        // Now, this is an element id, not a package id. So we
                        // have to
                        // identify the package, which owns the element
                        // addressed.
                        PackageInfoEA suppPack = (PackageInfoEA) doreplacedent.fPackageByElmtId.get(suppIdS);
                        // From this only the id is required
                        if (suppPack != null) {
                            String suppPackId = suppPack.id();
                            if (suppPackId != null)
                                supplierIds.add(suppPackId);
                        }
                    }
                }
            }
        }
        return supplierIds;
    }

    // supplierIds()
    // /**
    // * Return the doreplacedentation attached to the property object. This is
    // fetched
    // * from tagged values and - if this is absent - from the 'notes' specific
    // to
    // * the EA objects model.
    // */
    // @Override
    // public Descriptors doreplacedentationAll() {
    // 
    // // Retrieve/compute the doreplacedentation only once
    // // Cache the result for subsequent use
    // if (!doreplacedentationAccessed) {
    // 
    // doreplacedentationAccessed = true;
    // 
    // // Fetch from tagged values
    // Descriptors ls = super.doreplacedentationAll();
    // 
    // // Try EA notes, if both tagged values fail
    // if (ls.isEmpty()
    // && descriptorSource(Descriptor.DOreplacedENTATION)
    // .equals("ea:notes")) {
    // String s = eaPackage.GetNotes();
    // // Handle EA formatting
    // if (s != null) {
    // s = doreplacedent.applyEAFormatting(s);
    // }
    // 
    // if (s == null) {
    // super.doreplacedentation = new Descriptors();
    // } else {
    // super.doreplacedentation = new Descriptors(
    // new LangString(options().internalize(s)));
    // }
    // }
    // }
    // return super.doreplacedentation;
    // }
    /**
     * Return model-unique id of package.
     */
    public String id() {
        return packageId;
    }

    /**
     * Obtain the name of the package.
     */
    public String name() {
        if (eaName == null || eaName.equals("")) {
            eaName = id();
            MessageContext mc = doreplacedent.result.addWarning(null, 100, "package", eaName);
            if (mc != null)
                mc.addDetail(null, 400, "Package", owner().fullName());
        }
        return eaName;
    }

    // name();
    // @Override
    // public Descriptors aliasNameAll() {
    // 
    // // Retrieve/compute the alias only once
    // // Cache the result for subsequent use
    // if (!aliasAccessed) {
    // 
    // aliasAccessed = true;
    // 
    // // Obtain alias name from default implementation
    // Descriptors ls = super.aliasNameAll();
    // // If not present, obtain from EA model directly
    // if (ls.isEmpty() && descriptorSource(Descriptor.ALIAS)
    // .equals("ea:alias")) {
    // 
    // String a = eaPackage.GetAlias();
    // 
    // if (a != null && !a.isEmpty()) {
    // 
    // super.aliasName = new Descriptors(
    // new LangString(options().internalize(a)));
    // } else {
    // super.aliasName = new Descriptors();
    // }
    // }
    // }
    // return super.aliasName;
    // }
    // Validate tagged values cache, filtering on tagged values defined within
    // ShapeChange ...
    public void validateTaggedValuesCache() {
        if (taggedValuesCache == null) {
            // Fetch tagged values collection
            Collection<TaggedValue> tvs = null;
            int ntvs = 0;
            if (eaPackageElmt != null) {
                tvs = eaPackageElmt.GetTaggedValues();
                // ensure that there are tagged values
                if (tvs != null) {
                    ntvs = tvs.GetCount();
                }
            }
            // Allocate cache
            taggedValuesCache = options().taggedValueFactory(ntvs);
            // Copy tag-value-pairs, leave out non-ShapeChange stuff and
            // normalize deprecated tags.
            if (tvs != null)
                for (TaggedValue tv : tvs) {
                    String t = tv.GetName();
                    t = options().taggedValueNormalizer().normalizeTaggedValue(t);
                    if (t != null) {
                        String v = tv.GetValue();
                        if (v.equals("<memo>"))
                            v = tv.GetNotes();
                        taggedValuesCache.add(t, v);
                    }
                }
        }
    }

    // loadTaggedValuesCache()
    public void taggedValue(String tag, String value) {
        Collection<TaggedValue> cTV = eaPackageElmt.GetTaggedValues();
        TaggedValue tv = cTV.GetByName(tag);
        if (tv == null && value != null) {
            tv = cTV.AddNew(tag, value);
            tv.Update();
        } else if (tv != null) {
            if (value == null)
                value = "";
            if (!tv.GetValue().equals(value)) {
                tv.SetValue(value);
                tv.Update();
            }
        }
        // invalidate cache
        taggedValuesCache = null;
    }

    // taggedValue()
    // @Override
    // public Descriptors globalIdentifierAll() {
    // 
    // // Obtain global identifier from default implementation
    // Descriptors ls = super.globalIdentifierAll();
    // 
    // // If not present, obtain from EA model directly
    // if (ls.isEmpty()
    // && descriptorSource(Descriptor.GLOBALIDENTIFIER)
    // .equals("ea:guidtoxml")) {
    // 
    // String gi = doreplacedent.repository.GetProjectInterface()
    // .GUIDtoXML(eaPackage.GetPackageGUID());
    // 
    // super.globalIdentifier = new Descriptors(
    // new LangString(options().internalize(gi)));
    // }
    // 
    // return super.globalIdentifier;
    // }
    @Override
    protected List<LangString> descriptorValues(Descriptor descriptor) {
        // get default first
        List<LangString> ls = super.descriptorValues(descriptor);
        if (ls.isEmpty()) {
            if (!doreplacedentationAccessed && descriptor == Descriptor.DOreplacedENTATION) {
                doreplacedentationAccessed = true;
                String s = eaPackage.GetNotes();
                // Handle EA formatting
                if (s != null) {
                    s = doreplacedent.applyEAFormatting(s);
                }
                if (s != null) {
                    ls.add(new LangString(options().internalize(s)));
                    this.descriptors().put(descriptor, ls);
                }
            } else if (!globalIdentifierAccessed && descriptor == Descriptor.GLOBALIDENTIFIER) {
                globalIdentifierAccessed = true;
                // obtain from EA model directly
                if (model().descriptorSource(Descriptor.GLOBALIDENTIFIER).equals("ea:guidtoxml")) {
                    String gi = doreplacedent.repository.GetProjectInterface().GUIDtoXML(eaPackage.GetPackageGUID());
                    if (gi != null && !gi.isEmpty()) {
                        ls.add(new LangString(options().internalize(gi)));
                        this.descriptors().put(descriptor, ls);
                    }
                }
            } else if (!aliasAccessed && descriptor == Descriptor.ALIAS) {
                aliasAccessed = true;
                /*
				 * obtain from EA model directly if ea:alias is identified as
				 * the source
				 */
                if (model().descriptorSource(Descriptor.ALIAS).equals("ea:alias")) {
                    String a = eaPackage.GetAlias();
                    if (a != null && !a.isEmpty()) {
                        ls.add(new LangString(options().internalize(a)));
                        this.descriptors().put(descriptor, ls);
                    }
                }
            }
        }
        return ls;
    }
}

19 View Complete Implementation : EARepositoryUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * @param rep  the repository to query
 * @param name Name of the package to look up
 * @return the EA package with given name, if it was found, else
 *         <code>null</code>
 */
public static Package findPackage(Repository rep, String name) {
    Collection<org.sparx.Package> models = rep.GetModels();
    for (short i = 0; i < models.GetCount(); i++) {
        Package pkg = EAPackageUtil.findPackage(models.GetAt(i), name);
        if (pkg != null) {
            return pkg;
        }
    }
    return null;
}

19 View Complete Implementation : DatabaseModelVisitor.java
Copyright GNU General Public License v3.0
Author : ShapeChange
@Override
public void postprocess() {
    /*
	 * Sort table operations/methods to facilitate comparison with database models
	 * that were imported from actual databases.
	 */
    for (Integer eaElmtID : this.eaElementIDByTable.values()) {
        Element element = repository.GetElementByID(eaElmtID);
        Collection<Method> eaMethods = element.GetMethods();
        List<Method> methods = new ArrayList<Method>();
        for (short i = 0; i < eaMethods.GetCount(); i++) {
            Method method = eaMethods.GetAt(i);
            methods.add(method);
        }
        Collections.sort(methods, new Comparator<Method>() {

            @Override
            public int compare(Method m1, Method m2) {
                String m1Stereo = m1.GetStereotype();
                String m2Stereo = m2.GetStereotype();
                String m1Name = m1.GetName();
                String m2Name = m2.GetName();
                if (m1Stereo.equalsIgnoreCase(m2Stereo)) {
                    return m1Name.compareTo(m2Name);
                } else if (m1Stereo.endsWith("PK")) {
                    return -1;
                } else if (m2Stereo.endsWith("PK")) {
                    return 1;
                } else if (m1Stereo.endsWith("check")) {
                    return -1;
                } else if (m2Stereo.endsWith("check")) {
                    return 1;
                } else if (m1Stereo.endsWith("index")) {
                    return -1;
                } else if (m2Stereo.endsWith("index")) {
                    return 1;
                } else if (m1Stereo.endsWith("unique")) {
                    return -1;
                } else if (m2Stereo.endsWith("unique")) {
                    return 1;
                } else {
                    return m1Name.compareTo(m2Name);
                }
            }
        });
        /*
	     * now set the positions of the methods according to their order in the sorted
	     * list
	     */
        try {
            for (int i = 0; i < methods.size(); i++) {
                Method method = methods.get(i);
                EAMethodUtil.setEAPos(method, i);
            }
        } catch (EAException e) {
            result.addError(this, 107, element.GetName(), e.getMessage());
        }
    }
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * @param e tbd
 * @param stereotype tbd
 * @return the (first encountered) method whose 'StereotypeEx' contains the
 *         given stereotype, or <code>null</code> if no such method was found
 */
public static Method getEAMethodWithStereotypeEx(Element e, String stereotype) {
    Collection<Method> methods = e.GetMethods();
    methods.Refresh();
    for (short i = 0; i < methods.GetCount(); i++) {
        Method m = methods.GetAt(i);
        if (m.GetStereotypeEx().contains(stereotype)) {
            return m;
        }
    }
    return null;
}

19 View Complete Implementation : EAConnectorUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given collection of tagged values to the given connector, NOT
 * checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a model element that adheres to a specific UML profile. In that case,
 * adding the same tagged values would lead to duplicates. If duplicates
 * shall be prevented, set the tagged value instead of adding it.
 *
 * @param con
 *                the connector to which the tagged values shall be added
 * @param tvs
 *                collection of tagged values to add
 * @throws EAException  tbd
 */
public static void addTaggedValues(Connector con, List<EATaggedValue> tvs) throws EAException {
    if (tvs == null || tvs.isEmpty()) {
    // nothing to do
    } else {
        Collection<ConnectorTag> cTV = con.GetTaggedValues();
        for (EATaggedValue tv : tvs) {
            String name = tv.getName();
            List<String> values = tv.getValues();
            if (values != null) {
                for (String v : values) {
                    ConnectorTag eaTv = cTV.AddNew(name, "");
                    cTV.Refresh();
                    if (tv.createAsMemoField() || v.length() > 255) {
                        eaTv.SetValue("<memo>");
                        eaTv.SetNotes(v);
                    } else {
                        eaTv.SetValue(v);
                        eaTv.SetNotes("");
                    }
                    if (!eaTv.Update()) {
                        throw new EAException(createMessage(message(101), name, con.GetName(), v, eaTv.GetLastError()));
                    }
                }
            }
        }
    }
}

19 View Complete Implementation : EAAttributeUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Retrieves the first tagged value with given name of the given attribute.
 * Does not apply normalization of tags, i.e. comparison is performed using
 * string equality. With UML 2, there may be multiple values per tag. This
 * method does NOT issue a warning if more than one value exists for the
 * tag. I.e., use this method only for cases, where only one value per tag
 * may be provided.
 *
 * @param att
 *            attribute that contains the tagged values to search
 * @param tvName
 *            name of the tagged value to retrieve
 * @return The tagged value for the tag with given name or <code>null</code>
 *         if the tagged value was not found. If there are multiple values
 *         with the tag only the first is provided.
 */
public static String taggedValue(Attribute att, String tvName) {
    org.sparx.Collection<org.sparx.AttributeTag> tvs = att.GetTaggedValues();
    for (org.sparx.AttributeTag tv : tvs) {
        if (tvName.equals(tv.GetName())) {
            String v = tv.GetValue();
            if (v.equals("<memo>")) {
                v = tv.GetNotes();
            }
            return v;
        }
    }
    return null;
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given collection of tagged values to the tagged values of the given
 * element, NOT checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values for
 * a model element that adheres to a specific UML profile. In that case, adding
 * the same tagged values would lead to duplicates. If duplicates shall be
 * prevented, set the tagged value instead of adding it.
 *
 * @param e   the element to which the tagged values shall be added
 * @param tvs collection of tagged values to add
 * @throws EAException  tbd
 */
public static void addTaggedValues(Element e, TaggedValues tvs) throws EAException {
    if (tvs == null || tvs.isEmpty()) {
    // nothing to do
    } else {
        Collection<TaggedValue> cTV = e.GetTaggedValues();
        for (String tag : tvs.keySet()) {
            String[] values = tvs.get(tag);
            for (String v : values) {
                TaggedValue tv = cTV.AddNew(tag, "");
                cTV.Refresh();
                if (v.length() > 255) {
                    tv.SetValue("<memo>");
                    tv.SetNotes(v);
                } else {
                    tv.SetValue(v);
                    tv.SetNotes("");
                }
                if (!tv.Update()) {
                    throw new EAException(createMessage(message(106), tag, e.GetName(), v, tv.GetLastError()));
                }
            }
        }
    }
}

19 View Complete Implementation : OperationInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public clreplaced OperationInfoEA extends OperationInfoImpl implements OperationInfo {

    /**
     * Flag used to prevent duplicate retrieval/computation of the alias of this
     * property.
     */
    protected boolean aliasAccessed = false;

    /**
     * Flag used to prevent duplicate retrieval/computation of the
     * globalIdentifier of this clreplaced.
     */
    protected boolean globalIdentifierAccessed = false;

    /**
     * Access to the doreplacedent object
     */
    protected EADoreplacedent doreplacedent = null;

    /**
     * Clreplaced the operation belongs to
     */
    protected ClreplacedInfoEA clreplacedInfo = null;

    /**
     * Model-unique id. This is the ID from EA Methods, prefixed by the clreplaced
     * ID.
     */
    protected String eaOperationId = null;

    /**
     * Name of the operation
     */
    protected String eaName = null;

    /**
     * Type information
     */
    protected Type typeInfo = new Type();

    protected ClreplacedInfoEA typeClreplacedInfo = null;

    /**
     * EA method object
     */
    protected Method eaMethod = null;

    /**
     * Cache set for stereotypes
     */
    // this map is already defined in InfoImpl
    /**
     * Cache map for tagged values
     */
    // this map is already defined in InfoImpl
    /**
     * Cache map for Parameters
     */
    protected Collection<Parameter> eaParametersCache = null;

    public OperationInfoEA(EADoreplacedent doc, ClreplacedInfoEA ci, Method meth) {
        // Record references ...
        doreplacedent = doc;
        clreplacedInfo = ci;
        eaMethod = meth;
        // The Id
        eaOperationId = ci.id();
        eaOperationId += "_M";
        eaOperationId += String.valueOf(eaMethod.GetMethodID());
        // Property name
        eaName = eaMethod.GetName();
        if (eaName != null)
            eaName = eaName.trim();
    }

    // OperationInfoEA()
    // Validate parameter cache of the operation.
    private void validateParametersCache() {
        if (eaParametersCache == null) {
            eaParametersCache = eaMethod.GetParameters();
        }
    }

    // validateParametersCache()
    /**
     * Return the total number of parameters including __RETURN__
     */
    public int parameterCount() {
        validateParametersCache();
        if (eaParametersCache == null)
            return 0;
        else
            return eaParametersCache.GetCount() + 1;
    }

    // parameterCount()
    /**
     * Obtain the names all parameters of the operation. They will appear
     * ordered as in the method definition. The return value (if any) appears in
     * the last position and the receives the name __RETURN__.
     */
    public TreeMap<Integer, String> parameterNames() {
        validateParametersCache();
        int count = 0;
        TreeMap<Integer, String> parms = new TreeMap<Integer, String>();
        if (eaParametersCache != null) {
            for (Parameter p : eaParametersCache) {
                String name = p.GetName();
                // "return" not observed ...
                // String kind = p.GetKind();
                // if(kind.equals("return"))
                // name = "__RETURN__";
                parms.put(++count, name);
            }
            parms.put(++count, "__RETURN__");
        }
        return parms;
    }

    /**
     * Obtain the types of all parameters of the operation. Types will appear
     * ordered as in the method definition. The type of the return value (if
     * any) appears in the last position.
     */
    public TreeMap<Integer, String> parameterTypes() {
        validateParametersCache();
        int count = 0;
        TreeMap<Integer, String> parms = new TreeMap<Integer, String>();
        if (eaParametersCache != null) {
            for (Parameter p : eaParametersCache) {
                String type = p.GetType();
                parms.put(++count, type);
            }
            String ret = eaMethod.GetReturnType();
            parms.put(++count, ret);
        }
        return parms;
    }

    /**
     * Return model-unique id of operation.
     */
    public String id() {
        return eaOperationId;
    }

    // id()
    /**
     * Return EA model object.
     */
    public Model model() {
        return doreplacedent;
    }

    // model()
    /**
     * Obtain the name of the property.
     */
    public String name() {
        // Get the name obtained from the model
        return eaName;
    }

    // name()
    // @Override
    // public Descriptors aliasNameAll() {
    // 
    // // Retrieve/compute the alias only once
    // // Cache the result for subsequent use
    // if (!aliasAccessed) {
    // 
    // aliasAccessed = true;
    // 
    // // Obtain alias name from default implementation
    // Descriptors ls = super.aliasNameAll();
    // 
    // // If not present, obtain from EA model directly
    // if (ls.isEmpty()) {
    // 
    // String a = eaMethod.GetStyle();
    // 
    // if (a != null && !a.isEmpty()) {
    // 
    // super.aliasName = new Descriptors(
    // new LangString(options().internalize(a)));
    // } else {
    // super.aliasName = new Descriptors();
    // }
    // }
    // }
    // return super.aliasName;
    // }
    /**
     * Return options and configuration object.
     */
    public Options options() {
        return doreplacedent.options;
    }

    // options()
    /**
     * Return result object for error reporting.
     */
    public ShapeChangeResult result() {
        return doreplacedent.result;
    }

    // result()
    /**
     * The stereotypes added to the cache are the well-known equivalents of the
     * stereotypes defined in the EA model, if mapped in the configuration.
     *
     * @see de.interactive_instruments.ShapeChange.Model.Info#validateStereotypesCache()
     */
    public void validateStereotypesCache() {
        if (stereotypesCache == null) {
            // Fetch stereotypes 'collection' ...
            String sts;
            sts = eaMethod.GetStereotypeEx();
            String[] stereotypes = sts.split("\\,");
            // Allocate cache
            stereotypesCache = StereotypeNormalizer.normalizeAndMapToWellKnownStereotype(stereotypes, this);
        }
    }

    // validateStereotypesCache()
    // Validate tagged values cache, filtering on tagged values defined within
    // ShapeChange ...
    public void validateTaggedValuesCache() {
        if (taggedValuesCache == null) {
            // Fetch tagged values collection
            Collection<MethodTag> tvs = eaMethod.GetTaggedValues();
            // ensure that there are tagged values
            if (tvs != null) {
                // Allocate cache
                int ntvs = tvs.GetCount();
                taggedValuesCache = options().taggedValueFactory(ntvs);
                // Copy tag-value-pairs, leave out non-ShapeChange stuff and
                // normalize deprecated tags.
                for (MethodTag tv : tvs) {
                    String t = tv.GetName();
                    t = options().taggedValueNormalizer().normalizeTaggedValue(t);
                    if (t != null) {
                        String v = tv.GetValue();
                        if (v.equals("<memo>"))
                            v = tv.GetNotes();
                        taggedValuesCache.add(t, v);
                    }
                }
            } else {
                taggedValuesCache = options().taggedValueFactory(0);
            }
        }
    }

    // validateTaggedValuesCache()
    // @Override
    // public Descriptors globalIdentifierAll() {
    // 
    // // Obtain global identifier from default implementation
    // Descriptors ls = super.globalIdentifierAll();
    // 
    // // If not present, obtain from EA model directly
    // if (ls.isEmpty()
    // && descriptorSource(Descriptor.GLOBALIDENTIFIER)
    // .equals("ea:guidtoxml")) {
    // 
    // String gi = doreplacedent.repository.GetProjectInterface()
    // .GUIDtoXML(eaMethod.GetMethodGUID());
    // 
    // super.globalIdentifier = new Descriptors(
    // new LangString(options().internalize(gi)));
    // }
    // return super.globalIdentifier;
    // }
    @Override
    protected List<LangString> descriptorValues(Descriptor descriptor) {
        // get default first
        List<LangString> ls = super.descriptorValues(descriptor);
        if (ls.isEmpty()) {
            if (!globalIdentifierAccessed && descriptor == Descriptor.GLOBALIDENTIFIER) {
                globalIdentifierAccessed = true;
                // obtain from EA model directly
                if (model().descriptorSource(Descriptor.GLOBALIDENTIFIER).equals("ea:guidtoxml")) {
                    String gi = doreplacedent.repository.GetProjectInterface().GUIDtoXML(eaMethod.GetMethodGUID());
                    if (gi != null && !gi.isEmpty()) {
                        ls.add(new LangString(options().internalize(gi)));
                        this.descriptors().put(descriptor, ls);
                    }
                }
            } else if (!aliasAccessed && descriptor == Descriptor.ALIAS) {
                aliasAccessed = true;
                /*
				 * obtain from EA model directly if ea:alias is identified as
				 * the source
				 */
                if (model().descriptorSource(Descriptor.ALIAS).equals("ea:alias")) {
                    String a = eaMethod.GetStyle();
                    if (a != null && !a.isEmpty()) {
                        ls.add(new LangString(options().internalize(a)));
                        this.descriptors().put(descriptor, ls);
                    }
                }
            }
        }
        return ls;
    }
}

19 View Complete Implementation : EAMethodUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public static Parameter createEAParameter(Method m, String name) throws EAException {
    Collection<Parameter> parameters = m.GetParameters();
    Parameter param = parameters.AddNew(name, "");
    if (!param.Update()) {
        throw new EAException(createMessage(message(107), name, m.GetName(), m.GetLastError()));
    }
    parameters.Refresh();
    return param;
}

19 View Complete Implementation : EAConnectorEndUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given collection of tagged values to the given connector end,
 * NOT checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a model element that adheres to a specific UML profile. In that case,
 * adding the same tagged values would lead to duplicates. If duplicates
 * shall be prevented, set the tagged value instead of adding it.
 *
 * @param end
 *            the connector end to which the tagged values shall be added
 * @param tvs
 *            collection of tagged values to add
 * @throws EAException  tbd
 */
public static void addTaggedValues(ConnectorEnd end, TaggedValues tvs) throws EAException {
    if (tvs == null || tvs.isEmpty()) {
    // nothing to do
    } else {
        Collection<RoleTag> cTV = end.GetTaggedValues();
        for (Entry<String, List<String>> e : tvs.asMap().entrySet()) {
            String name = e.getKey();
            List<String> values = e.getValue();
            if (values != null) {
                for (String v : values) {
                    RoleTag eaTv = cTV.AddNew(name, "");
                    cTV.Refresh();
                    /*
						 * An EA memo-field is used to provide convenient
						 * support (via a dialog in EA) for entering a tagged
						 * value with very long text. Such fields always start
						 * with the string '<memo>' (six characters long).
						 * 
						 * If a tagged value with a memo-field has an actual
						 * textual value then the value starts with
						 * '<memo>$ea_notes=' (16 characters long). So if a tag
						 * with memo-field does not have an actual value, we
						 * will only find '<memo>', but not followed by
						 * '$ea_notes='.
						 * 
						 * Otherwise (no memo field) we can use the value as is.
						 */
                    if (v.length() > 255) {
                        eaTv.SetValue("<memo>$ea_notes=" + v);
                    } else {
                        eaTv.SetValue(v);
                    }
                    if (!eaTv.Update()) {
                        throw new EAException(createMessage(message(101), name, end.GetRole(), v, eaTv.GetLastError()));
                    }
                }
            }
        }
    }
}

19 View Complete Implementation : EAPackageUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Searches in the package hierarchy with the given package at the top.
 * First checks if the given package has the given name. Otherwise,
 * recursively searches in child packages.
 *
 * @param pkgIn
 *            Package to search in
 * @param name
 *            Name of package to find
 * @return the package with equal to the given name; can be
 *         <code>null</code> if no such package was found
 */
public static Package findPackage(Package pkgIn, String name) {
    if (pkgIn.GetName().equals(name)) {
        return pkgIn;
    } else {
        Collection<org.sparx.Package> pkgs = pkgIn.GetPackages();
        for (short i = 0; i < pkgs.GetCount(); i++) {
            Package resPkg = EAPackageUtil.findPackage(pkgs.GetAt(i), name);
            if (resPkg != null) {
                return resPkg;
            }
        }
        return null;
    }
}

19 View Complete Implementation : ClassInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
// validatePropertiesCache()
// Validate operations cache. This makes sure the operations cache contains
// all Operations ordered by their appearance in the clreplaced.
private void validateOperationsCache() {
    if (operationsCache == null) {
        // Allocate the cache
        operationsCache = new TreeMap<Integer, OperationInfo>();
        // Load methods ...
        Collection<Method> meths = eaClreplacedElement.GetMethods();
        int i = 0;
        // Ensure that there are methods before continuing
        if (meths != null) {
            for (Method meth : meths) {
                // Create the operation object.
                OperationInfoEA oi = new OperationInfoEA(doreplacedent, this, meth);
                // Drop in cache
                // operationsCache.put(oi.eaMethod.GetPos(), oi); <-- does
                // not work!
                operationsCache.put(++i, oi);
            }
        }
    }
}

19 View Complete Implementation : EARepositoryUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Creates an EA package for the given PackageInfo. The new EA package will be a
 * child of the given EA parent package. Properties such as stereotype and
 * tagged values are not set by this method and thus need to be added later on.
 *
 * @param rep tbd
 * @param pi            package to create in EA
 * @param eaParentPkgId The PackageID of the EA Package element that is the
 *                      parent of the EA Package to create for pi
 * @return The PackageID of the new package
 * @throws EAException If an EA error was encountered while updating the package
 */
public static int createEAPackage(Repository rep, PackageInfo pi, int eaParentPkgId) throws EAException {
    Package eaParentPkg = rep.GetPackageByID(eaParentPkgId);
    Collection<Package> eaParentPkgs = eaParentPkg.GetPackages();
    Package eaPkg = eaParentPkgs.AddNew(pi.name(), "Package");
    if (!eaPkg.Update()) {
        throw new EAException(createMessage(message(103), pi.name(), eaPkg.GetLastError()));
    }
    eaParentPkgs.Refresh();
    return eaPkg.GetPackageID();
}

19 View Complete Implementation : EAConnectorUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public static void deleteTaggedValue(Connector con, String nameOfTVToDelete) {
    Collection<ConnectorTag> cTV = con.GetTaggedValues();
    cTV.Refresh();
    for (short i = 0; i < cTV.GetCount(); i++) {
        ConnectorTag tv = cTV.GetAt(i);
        if (tv.GetName().equalsIgnoreCase(nameOfTVToDelete)) {
            cTV.Delete(i);
        }
    }
    cTV.Refresh();
}

19 View Complete Implementation : EAConnectorUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Updates the tagged values with given name (which can be a fully qualified
 * name) in the tagged values of the given connector. Does NOT delete those
 * tagged values. NOTE: This method is especially useful when setting tagged
 * values that are defined by an MDG / UML Profile, since these tagged
 * values cannot be created programmatically (they are created by EA - for
 * further details, see
 * http://sparxsystems.com/forums/smf/index.php?topic=3859.0).
 *
 * @param con
 *                              the connector in which the tagged values
 *                              shall be updated
 * @param name
 *                              (fully qualified or unqualified) name of the
 *                              tagged value to update, must not be
 *                              <code>null</code>
 * @param value
 *                              value of the tagged value to update, can be
 *                              <code>null</code>
 * @param createAsMemoField
 *                              If set to <code>true</code>, the values
 *                              shall be encoded using <memo> fields,
 *                              regardless of the actual length of each
 *                              value.
 * @throws EAException
 *                         If updating the connector did not succeed, this
 *                         exception contains the error message.
 */
public static void updateTaggedValue(Connector con, String name, String value, boolean createAsMemoField) throws EAException {
    boolean isQualifiedName = name.contains("::");
    Collection<ConnectorTag> cTV = con.GetTaggedValues();
    cTV.Refresh();
    for (short i = 0; i < cTV.GetCount(); i++) {
        ConnectorTag tv = cTV.GetAt(i);
        if ((isQualifiedName && tv.GetFQName().equalsIgnoreCase(name)) || tv.GetName().equalsIgnoreCase(name)) {
            if (createAsMemoField || value.length() > 255) {
                tv.SetValue("<memo>");
                tv.SetNotes(value);
            } else {
                tv.SetValue(value);
                tv.SetNotes("");
            }
            if (!tv.Update()) {
                throw new EAException(createMessage(message(101), name, con.GetName(), value, tv.GetLastError()));
            }
        }
    }
    cTV.Refresh();
}

19 View Complete Implementation : ClassInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
// Validate properties cache. This makes sure the property cache contains
// all properties ordered by their appearance in the clreplaced.
private void validatePropertiesCache() {
    if (propertiesCache == null) {
        // Allocate the cache
        propertiesCache = new TreeMap<StructuredNumber, PropertyInfo>();
        // Load attributes ...
        Collection<Attribute> attrs = eaClreplacedElement.GetAttributes();
        // Ensure that there are attributes before continuing
        if (attrs != null) {
            for (Attribute attr : attrs) {
                // Pick public attributes if this has been requested
                if (doreplacedent.options.parameter("publicOnly").equals("true")) {
                    String vis = attr.GetVisibility();
                    if (!vis.equalsIgnoreCase("Public")) {
                        continue;
                    }
                }
                // Create the property object.
                PropertyInfoEA pi = new PropertyInfoEA(doreplacedent, this, attr);
                // Check sequence number on duplicates
                PropertyInfo piTemp = propertiesCache.get(pi.sequenceNumber());
                if (piTemp != null) {
                    int cat = category();
                    if (cat != Options.ENUMERATION && cat != Options.CODELIST && !pi.sequenceNumber.equals(new StructuredNumber(Integer.MIN_VALUE))) {
                        MessageContext mc = doreplacedent.result.addError(null, 107, pi.name(), name(), piTemp.name());
                        if (mc != null)
                            mc.addDetail(null, 400, "Package", pkg().fullName());
                    }
                }
                // Add to properties cache
                propertiesCache.put(pi.sequenceNumber(), pi);
            }
        }
        // Load roles ...
        for (PropertyInfoEA pi : registeredRoles) {
            // Check sequence number on duplicates
            PropertyInfo piTemp = propertiesCache.get(pi.sequenceNumber());
            if (piTemp != null) {
                MessageContext mc = doreplacedent.result.addError(null, 107, pi.name(), name(), piTemp.name());
                if (mc != null)
                    mc.addDetail(null, 400, "Package", pkg().fullName());
            }
            // Add to properties cache
            propertiesCache.put(pi.sequenceNumber(), pi);
        }
    }
}

19 View Complete Implementation : EAConnectorUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given tagged value to the tagged values of the given connector,
 * NOT checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a model element that adheres to a specific UML profile. In that case,
 * adding the same tagged values would lead to duplicates. If duplicates
 * shall be prevented, set the tagged value instead of adding it.
 *
 * @param con
 *                the connector to which the tagged value shall be added
 * @param tv
 *                tagged value to add
 * @throws EAException  tbd
 */
public static void addTaggedValue(Connector con, EATaggedValue tv) throws EAException {
    Collection<ConnectorTag> cTV = con.GetTaggedValues();
    String name = tv.getName();
    String type = "";
    List<String> values = tv.getValues();
    if (values != null) {
        for (String v : values) {
            ConnectorTag eaTv = cTV.AddNew(name, type);
            cTV.Refresh();
            if (tv.createAsMemoField() || v.length() > 255) {
                eaTv.SetValue("<memo>");
                eaTv.SetNotes(v);
            } else {
                eaTv.SetValue(v);
                eaTv.SetNotes("");
            }
            if (!eaTv.Update()) {
                throw new EAException(createMessage(message(101), name, con.GetName(), v, eaTv.GetLastError()));
            }
        }
    }
}

19 View Complete Implementation : EAAttributeUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given collection of tagged values to the tagged values of the
 * given attribute, NOT checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a model element that adheres to a specific UML profile. In that case,
 * adding the same tagged values would lead to duplicates. If duplicates
 * shall be prevented, set the tagged value instead of adding it.
 *
 * @param att
 *            the attribute to which the tagged values shall be added
 * @param tvs
 *            collection of tagged values to add
 * @throws EAException  tbd
 */
public static void addTaggedValues(Attribute att, List<EATaggedValue> tvs) throws EAException {
    if (tvs == null || tvs.isEmpty()) {
    // nothing to do
    } else {
        Collection<AttributeTag> cTV = att.GetTaggedValues();
        String attName = att.GetName();
        for (EATaggedValue tv : tvs) {
            String name = tv.getName();
            List<String> values = tv.getValues();
            if (values != null) {
                for (String v : values) {
                    AttributeTag eaTv = cTV.AddNew(name, "");
                    cTV.Refresh();
                    if (tv.createAsMemoField() || v.length() > 255) {
                        eaTv.SetValue("<memo>");
                        eaTv.SetNotes(v);
                    } else {
                        eaTv.SetValue(v);
                        eaTv.SetNotes("");
                    }
                    if (!eaTv.Update()) {
                        throw new EAException(createMessage(message(102), name, attName, v, eaTv.GetLastError()));
                    }
                }
            }
        }
    }
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given tagged value to the tagged values of the given element, NOT
 * checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values for
 * a model element that adheres to a specific UML profile. In that case, adding
 * the same tagged values would lead to duplicates. If duplicates shall be
 * prevented, set the tagged value instead of adding it.
 *
 * @param e  the element to which the tagged value shall be added
 * @param tv tagged value to add
 * @throws EAException  tbd
 */
public static void addTaggedValue(Element e, EATaggedValue tv) throws EAException {
    Collection<TaggedValue> cTV = e.GetTaggedValues();
    String name = tv.getName();
    String type = "";
    List<String> values = tv.getValues();
    if (values != null) {
        for (String v : values) {
            TaggedValue eaTv = cTV.AddNew(name, type);
            cTV.Refresh();
            if (tv.createAsMemoField() || v.length() > 255) {
                eaTv.SetValue("<memo>");
                eaTv.SetNotes(v);
            } else {
                eaTv.SetValue(v);
                eaTv.SetNotes("");
            }
            if (!eaTv.Update()) {
                throw new EAException(createMessage(message(106), name, e.GetName(), v, eaTv.GetLastError()));
            }
        }
    }
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Retrieves the first tagged value with given name of the given element. Does
 * not apply normalization of tags, i.e. comparison is performed using string
 * equality. With UML 2, there may be multiple values per tag. This method does
 * NOT issue a warning if more than one value exists for the tag. I.e., use this
 * method only for cases, where only one value per tag may be provided.
 *
 * @param elmt   element that contains the tagged values to search
 * @param tvName name of the tagged value to retrieve
 * @return The tagged value for the tag with given name or <code>null</code> if
 *         the tagged value was not found. If there are multiple values with the
 *         tag only the first is provided.
 */
public static String taggedValue(Element elmt, String tvName) {
    org.sparx.Collection<org.sparx.TaggedValue> tvs = elmt.GetTaggedValues();
    for (org.sparx.TaggedValue tv : tvs) {
        if (tvName.equals(tv.GetName())) {
            String value = tv.GetValue();
            if (value.equals("<memo>")) {
                value = tv.GetNotes();
            }
            return value;
        }
    }
    return null;
}

19 View Complete Implementation : EAAttributeUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given collection of tagged values to the tagged values of the
 * given attribute, NOT checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a model element that adheres to a specific UML profile. In that case,
 * adding the same tagged values would lead to duplicates. If duplicates
 * shall be prevented, set the tagged value instead of adding it.
 *
 * @param att
 *            the attribute to which the tagged values shall be added
 * @param tv
 *            collection of tagged values to add
 * @throws EAException  tbd
 */
public static void addTaggedValue(Attribute att, EATaggedValue tv) throws EAException {
    if (tv == null) {
    // nothing to do
    } else {
        Collection<AttributeTag> cTV = att.GetTaggedValues();
        String tag = tv.getName();
        List<String> values = tv.getValues();
        if (values != null) {
            for (String v : values) {
                AttributeTag at = cTV.AddNew(tag, "");
                cTV.Refresh();
                if (v.length() > 255) {
                    at.SetValue("<memo>");
                    at.SetNotes(v);
                } else {
                    at.SetValue(v);
                    at.SetNotes("");
                }
                if (!at.Update()) {
                    throw new EAException(createMessage(message(102), tag, att.GetName(), v, at.GetLastError()));
                }
            }
        }
    }
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Updates the tagged values with given name (which can be a fully qualified
 * name) in the tagged values of the given element. Does NOT delete those tagged
 * values. NOTE: This method is especially useful when setting tagged values
 * that are defined by an MDG / UML Profile, since these tagged values cannot be
 * created programmatically (they are created by EA - for further details, see
 * http://sparxsystems.com/forums/smf/index.php?topic=3859.0).
 *
 * @param e                 the element in which the tagged values shall be
 *                          updated
 * @param name              (fully qualified or unqualified) name of the tagged
 *                          value to update, must not be <code>null</code>
 * @param value             value of the tagged value to update, can be
 *                          <code>null</code>
 * @param createAsMemoField If set to <code>true</code>, the values shall be
 *                          encoded using <memo> fields, regardless of the
 *                          actual length of each value.
 * @throws EAException If updating the element did not succeed, this exception
 *                     contains the error message.
 */
public static void updateTaggedValue(Element e, String name, String value, boolean createAsMemoField) throws EAException {
    boolean isQualifiedName = name.contains("::");
    Collection<TaggedValue> cTV = e.GetTaggedValues();
    cTV.Refresh();
    for (short i = 0; i < cTV.GetCount(); i++) {
        TaggedValue tv = cTV.GetAt(i);
        if ((isQualifiedName && tv.GetFQName().equalsIgnoreCase(name)) || tv.GetName().equalsIgnoreCase(name)) {
            if (createAsMemoField || value.length() > 255) {
                tv.SetValue("<memo>");
                tv.SetNotes(value);
            } else {
                tv.SetValue(value);
                tv.SetNotes("");
            }
            if (!tv.Update()) {
                throw new EAException(createMessage(message(106), name, e.GetName(), value, tv.GetLastError()));
            }
        }
    }
    cTV.Refresh();
}

19 View Complete Implementation : EADocument.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * @return list of diagrams of the given package. The list is sorted by name if
 *         parameter sortDiagramsByName is set to true (default), or by the
 *         order in the EA model if set to false.
 */
private List<Diagram> getDiagramsOfPackage(PackageInfoEA piEa) {
    // note that this is an org.sparx.Collection
    Collection<Diagram> diagrams = piEa.eaPackage.GetDiagrams();
    List<Diagram> diagramList = new ArrayList<Diagram>();
    for (Diagram d : diagrams) {
        diagramList.add(d);
    }
    boolean sortDiagramsByName = options.parameterAsBoolean(null, "sortDiagramsByName", true);
    if (sortDiagramsByName) {
        Collections.sort(diagramList, new Comparator<Diagram>() {

            @Override
            public int compare(Diagram o1, Diagram o2) {
                return o1.GetName().compareTo(o2.GetName());
            }
        });
    }
    return diagramList;
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public static Method createEAMethod(Element elmt, String name) throws EAException {
    Collection<Method> methods = elmt.GetMethods();
    Method m = methods.AddNew(name, "");
    if (!m.Update()) {
        throw new EAException(createMessage(message(107), name, elmt.GetName(), m.GetLastError()));
    }
    methods.Refresh();
    return m;
}

19 View Complete Implementation : EAAttributeUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public static void deleteTaggedValue(Attribute a, String nameOfTVToDelete) {
    Collection<AttributeTag> cTV = a.GetTaggedValues();
    cTV.Refresh();
    for (short i = 0; i < cTV.GetCount(); i++) {
        AttributeTag tv = cTV.GetAt(i);
        if (tv.GetName().equalsIgnoreCase(nameOfTVToDelete)) {
            cTV.Delete(i);
        }
    }
    cTV.Refresh();
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public static Connector createEAreplacedociation(Element client, Element supplier) throws EAException {
    Collection<Connector> clientCons = client.GetConnectors();
    Connector con = clientCons.AddNew("", "replacedociation");
    con.SetSupplierID(supplier.GetElementID());
    if (!con.Update()) {
        throw new EAException(createMessage(message(1005), client.GetName(), supplier.GetName(), con.GetLastError()));
    }
    clientCons.Refresh();
    return con;
}

19 View Complete Implementation : ClassInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
// isLeaf()
// Validate constraints cache. This makes sure the constraints cache
// contains all constraints ordered by their appearance in the clreplaced.
// If constraints are disabled the cache is empty.
private void validateConstraintsCache() {
    if (constraintsCache == null) {
        // Allocate cache
        constraintsCache = new Vector<Constraint>();
        // Constraints disabled?
        if (!doreplacedent.options.constraintLoadingEnabled())
            return;
        // Constraints for this clreplaced category irrelevant?
        if (!doreplacedent.options.isClreplacedTypeToCreateConstraintsFor(category()))
            return;
        // Constraints from selected schemas only?
        if (doreplacedent.options.isLoadConstraintsForSelectedSchemasOnly() && !doreplacedent.isInSelectedSchemas(this)) {
            return;
        }
        // Filter map for inheritance and overriding by name
        HashMap<String, Constraint> namefilter = new HashMap<String, Constraint>();
        // Access EA constraints data
        Collection<org.sparx.Constraint> constrs = eaClreplacedElement.GetConstraints();
        // Determine constraint types to be parsed as OCL
        String oclTypes = doreplacedent.options.parameter("oclConstraintTypeRegex");
        // Determine constraint types to be parsed as FOL
        String folTypes = doreplacedent.options.parameter("folConstraintTypeRegex");
        // Enumerate all constraints found
        // Ensure that there are constraints before continuing
        if (constrs != null) {
            for (org.sparx.Constraint constr : constrs) {
                // Wrap into constraint object
                String type = constr.GetType();
                Constraint oc;
                if (oclTypes.length() > 0 && type.matches(oclTypes)) {
                    // 100422/re removed: &&
                    // !encodingRule("xsd").equals(Options.ISO19136_2007_INSPIRE)
                    OclConstraintEA ocl = new OclConstraintEA(doreplacedent, this, constr);
                    if (ocl.syntaxTree() == null)
                        // Text constraint is a fallback in case of parsing
                        // issues
                        oc = new TextConstraintEA(doreplacedent, this, constr);
                    else
                        oc = ocl;
                } else if (folTypes != null && folTypes.length() > 0 && type.matches(folTypes)) {
                    /*
			 * only sets up the textual information; parsing is done during model
			 * postprocessing - see ModelImpl.postprocessFolConstraints()
			 */
                    oc = new FolConstraintEA(doreplacedent, this, constr);
                } else {
                    oc = new TextConstraintEA(doreplacedent, this, constr);
                }
                // Collect in cache
                constraintsCache.add(oc);
                // If the constraint has a name, add it to the filter which
                // blocks inheritance of constraints
                String conam = oc.name();
                if (conam != null && conam.length() > 0)
                    namefilter.put(conam, oc);
            }
        }
        /*
	     * Fetch constraints from super-clreplacedes. Override by name.
	     */
        /*
	     * JE: replaced this code with code (see below) that directly accesses the
	     * supertype objects, instead of first getting all their IDs and then looking
	     * the objects up in the model.
	     */
        // HashSet<String> stids = supertypes();
        // if (stids != null) {
        // for (String stid : stids) {
        // ClreplacedInfo stci = model().clreplacedById(stid);
        // Vector<Constraint> stcos = null;
        // if (stci != null)
        // stcos = stci.constraints();
        // if (stcos != null) {
        // for (Constraint stco : stcos) {
        // String nam = stco == null ? null : stco.name();
        // if(nam!=null && nam.length()>0 && namefilter.containsKey(nam))
        // continue;
        // constraintsCache.add(stco);
        // }
        // }
        // }
        // }
        HashSet<ClreplacedInfoEA> sts = supertypesAsClreplacedInfoEA();
        if (sts != null) {
            for (ClreplacedInfoEA stci : sts) {
                Vector<Constraint> stcos = null;
                if (stci != null)
                    stcos = stci.constraints();
                if (stcos != null) {
                    for (Constraint stco : stcos) {
                        String nam = stco == null ? null : stco.name();
                        if (nam != null && nam.length() > 0 && namefilter.containsKey(nam))
                            continue;
                        // Is the context of stco still the supertype, or
                        // should it not be this (ClreplacedInfoEA)?
                        constraintsCache.add(stco);
                    }
                }
            }
        }
    }
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Deletes all tagged values whose name equals (ignoring case) the given name in
 * the given element.
 *
 * @param e tbd
 * @param nameOfTVToDelete tbd
 */
public static void deleteTaggedValue(Element e, String nameOfTVToDelete) {
    Collection<TaggedValue> cTV = e.GetTaggedValues();
    cTV.Refresh();
    for (short i = 0; i < cTV.GetCount(); i++) {
        TaggedValue tv = cTV.GetAt(i);
        if (tv.GetName().equalsIgnoreCase(nameOfTVToDelete)) {
            cTV.Delete(i);
        }
    }
    cTV.Refresh();
}

19 View Complete Implementation : EAAttributeUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given collection of tagged values to the tagged values of the
 * given attribute, NOT checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a model element that adheres to a specific UML profile. In that case,
 * adding the same tagged values would lead to duplicates. If duplicates
 * shall be prevented, set the tagged value instead of adding it.
 *
 * @param att
 *            the attribute to which the tagged values shall be added
 * @param tvs
 *            collection of tagged values to add
 * @throws EAException  tbd
 */
public static void addTaggedValues(Attribute att, TaggedValues tvs) throws EAException {
    if (tvs == null || tvs.isEmpty()) {
    // nothing to do
    } else {
        Collection<AttributeTag> cTV = att.GetTaggedValues();
        String attName = att.GetName();
        for (String tag : tvs.keySet()) {
            String[] values = tvs.get(tag);
            for (String v : values) {
                AttributeTag tv = cTV.AddNew(tag, "");
                cTV.Refresh();
                if (v.length() > 255) {
                    tv.SetValue("<memo>");
                    tv.SetNotes(v);
                } else {
                    tv.SetValue(v);
                    tv.SetNotes("");
                }
                if (!tv.Update()) {
                    throw new EAException(createMessage(message(102), tag, attName, v, tv.GetLastError()));
                }
            }
        }
    }
}

19 View Complete Implementation : EAMethodUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * @param m tbd
 * @return the first parameter defined for this method, or <code>null</code>
 *         if no such parameter exists
 */
public static Parameter getFirstParameter(Method m) {
    Collection<Parameter> params = m.GetParameters();
    params.Refresh();
    if (params.GetCount() > 0) {
        return params.GetAt((short) 0);
    } else {
        return null;
    }
}

19 View Complete Implementation : PackageInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
// name();
// @Override
// public Descriptors aliasNameAll() {
// 
// // Retrieve/compute the alias only once
// // Cache the result for subsequent use
// if (!aliasAccessed) {
// 
// aliasAccessed = true;
// 
// // Obtain alias name from default implementation
// Descriptors ls = super.aliasNameAll();
// // If not present, obtain from EA model directly
// if (ls.isEmpty() && descriptorSource(Descriptor.ALIAS)
// .equals("ea:alias")) {
// 
// String a = eaPackage.GetAlias();
// 
// if (a != null && !a.isEmpty()) {
// 
// super.aliasName = new Descriptors(
// new LangString(options().internalize(a)));
// } else {
// super.aliasName = new Descriptors();
// }
// }
// }
// return super.aliasName;
// }
// Validate tagged values cache, filtering on tagged values defined within
// ShapeChange ...
public void validateTaggedValuesCache() {
    if (taggedValuesCache == null) {
        // Fetch tagged values collection
        Collection<TaggedValue> tvs = null;
        int ntvs = 0;
        if (eaPackageElmt != null) {
            tvs = eaPackageElmt.GetTaggedValues();
            // ensure that there are tagged values
            if (tvs != null) {
                ntvs = tvs.GetCount();
            }
        }
        // Allocate cache
        taggedValuesCache = options().taggedValueFactory(ntvs);
        // Copy tag-value-pairs, leave out non-ShapeChange stuff and
        // normalize deprecated tags.
        if (tvs != null)
            for (TaggedValue tv : tvs) {
                String t = tv.GetName();
                t = options().taggedValueNormalizer().normalizeTaggedValue(t);
                if (t != null) {
                    String v = tv.GetValue();
                    if (v.equals("<memo>"))
                        v = tv.GetNotes();
                    taggedValuesCache.add(t, v);
                }
            }
    }
}

19 View Complete Implementation : EAPackageUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Looks up the elements contained in the given package as well as the
 * direct and indirect child packages whose type equals one of the given
 * types. Results are stored in the given map.
 *
 * @param pkg
 *            EA package in which to search for elements; must not be
 *            <code>null</code>
 * @param elementTypes
 *            element types to look up, must not be <code>null</code>; see
 *            the EA API on Element.Type for the list of possible types
 * @param resultMap
 *            storage for found elements (key: element name, value: EA
 *            element ID); must not be <code>null</code>
 */
public static void lookUpElements(Package pkg, Set<String> elementTypes, SortedMap<String, Integer> resultMap) {
    Collection<Element> elmts = pkg.GetElements();
    // process elements contained in the package
    for (short i = 0; i < elmts.GetCount(); i++) {
        Element elmt = elmts.GetAt(i);
        if (elementTypes.contains(elmt.GetType())) {
            resultMap.put(elmt.GetName(), elmt.GetElementID());
        }
    }
    // process child packages
    Collection<org.sparx.Package> pkgs = pkg.GetPackages();
    for (short i = 0; i < pkgs.GetCount(); i++) {
        lookUpElements(pkgs.GetAt(i), elementTypes, resultMap);
    }
}

19 View Complete Implementation : EAConnectorEndUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Retrieves the first tagged value with given name of the given connector end.
 * Does not apply normalization of tags, i.e. comparison is performed using
 * string equality. With UML 2, there may be multiple values per tag. This
 * method does NOT issue a warning if more than one value exists for the
 * tag. I.e., use this method only for cases, where only one value per tag
 * may be provided.
 *
 * @param end
 *            connector end that contains the tagged values to search
 * @param tvName
 *            name of the tagged value to retrieve
 * @return The tagged value for the tag with given name or <code>null</code>
 *         if the tagged value was not found. If there are multiple values
 *         with the tag only the first is provided.
 */
public static String taggedValue(ConnectorEnd end, String tvName) {
    org.sparx.Collection<org.sparx.RoleTag> tvs = end.GetTaggedValues();
    for (org.sparx.RoleTag tv : tvs) {
        if (tvName.equals(tv.GetTag())) {
            String v = tv.GetValue();
            /*
				 * An EA memo-field is used to provide convenient support (via a
				 * dialog in EA) for entering a tagged value with very long
				 * text. Such fields always start with the string '<memo>' (six
				 * characters long).
				 * 
				 * If a tagged value with a memo-field has an actual textual
				 * value then the value starts with '<memo>$ea_notes=' (16
				 * characters long). So if a tag with memo-field does not have
				 * an actual value, we will only find '<memo>', but not followed
				 * by '$ea_notes='.
				 * 
				 * If the tagged value does not use a memo-field, then it may
				 * still contain or start with '$ea_notes='. In that case, the
				 * part after '$ea_notes=' provides the doreplacedentation of the tag
				 * (e.g. from the MDG Technology - UnitTests showed that the
				 * doreplacedentation can be empty) and the part before provides the
				 * actual value.
				 * 
				 * Otherwise (does not start with '<memo>' and does not contain
				 * '$ea_notes=') we can use the value as is.
				 */
            if (v.startsWith("<memo>$ea_notes=")) {
                v = v.substring(16);
            } else if (v.startsWith("<memo>")) {
                // no actual value in the memo-field
                v = "";
            } else if (v.contains("$ea_notes=")) {
                // retrieve the value
                v = v.substring(0, v.indexOf("$ea_notes="));
            } else {
            // fine - use the value as is
            }
            return v;
        }
    }
    return null;
}

19 View Complete Implementation : EAPackageUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public static void deleteElement(Package pkg, int elementId) {
    Collection<Element> elmts = pkg.GetElements();
    for (short i = 0; i < elmts.GetCount(); i++) {
        Element e = elmts.GetAt(i);
        if (e.GetElementID() == elementId) {
            elmts.Delete(i);
            break;
        }
    }
    elmts.Refresh();
}

19 View Complete Implementation : ClassInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
// validateTaggedValuesCache()
/**
 * Set the tagged value for the tag given.
 *
 * @param tag   tbd
 * @param value tbd
 */
public void taggedValue(String tag, String value) {
    Collection<TaggedValue> cTV = eaClreplacedElement.GetTaggedValues();
    TaggedValue tv = cTV.GetByName(tag);
    if (tv == null && value != null) {
        tv = cTV.AddNew(tag, value);
        tv.Update();
    } else if (tv != null) {
        if (value == null)
            value = "";
        if (!tv.GetValue().equals(value)) {
            tv.SetValue(value);
            tv.Update();
        }
    }
    // invalidate cache
    taggedValuesCache = null;
}

19 View Complete Implementation : EARepositoryUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Create a generalization relationship between clreplaced 1 (subtype) and clreplaced 2
 * (supertype).
 *
 * @param rep tbd
 * @param c1 tbd
 * @param c2 tbd
 * @return  tbd
 * @throws EAException tbd
 */
public static Connector createEAGeneralization(Repository rep, Element c1, Element c2) throws EAException {
    Collection<Connector> c1Cons = c1.GetConnectors();
    Connector con = c1Cons.AddNew("", "Generalization");
    con.SetSupplierID(c2.GetElementID());
    if (!con.Update()) {
        throw new EAException(createMessage(message(102), c1.GetName(), c2.GetName(), con.GetLastError()));
    }
    c1Cons.Refresh();
    return con;
}

19 View Complete Implementation : EAConnectorEndUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given tagged value to the given connector end, NOT checking for
 * duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values
 * for a model element that adheres to a specific UML profile. In that case,
 * adding the same tagged values would lead to duplicates. If duplicates
 * shall be prevented, set the tagged value instead of adding it.
 *
 * @param end
 *            the connector end to which the tagged value shall be added
 * @param tv
 *            tagged value to add, must not be <code>null</code>
 * @throws EAException  tbd
 */
public static void addTaggedValue(ConnectorEnd end, EATaggedValue tv) throws EAException {
    Collection<RoleTag> cTV = end.GetTaggedValues();
    String name = tv.getName();
    List<String> values = tv.getValues();
    if (values != null) {
        for (String v : values) {
            RoleTag eaTv = cTV.AddNew(name, "");
            cTV.Refresh();
            /*
				 * An EA memo-field is used to provide convenient support (via a
				 * dialog in EA) for entering a tagged value with very long
				 * text. Such fields always start with the string '<memo>' (six
				 * characters long).
				 * 
				 * If a tagged value with a memo-field has an actual textual
				 * value then the value starts with '<memo>$ea_notes=' (16
				 * characters long). So if a tag with memo-field does not have
				 * an actual value, we will only find '<memo>', but not followed
				 * by '$ea_notes='.
				 * 
				 * Otherwise (no memo field) we can use the value as is.
				 */
            if (tv.createAsMemoField() || v.length() > 255) {
                if (v.length() == 0) {
                    eaTv.SetValue("<memo>");
                } else {
                    eaTv.SetValue("<memo>$ea_notes=" + v);
                }
            } else {
                eaTv.SetValue(v);
            }
            if (!eaTv.Update()) {
                throw new EAException(createMessage(message(101), name, end.GetRole(), v, eaTv.GetLastError()));
            }
        }
    }
}

19 View Complete Implementation : PropertyInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
// validateStereotypesCache()
// Validate tagged values cache, filtering on tagged values defined within
// ShapeChange ...
public void validateTaggedValuesCache() {
    if (taggedValuesCache == null) {
        taggedValuesCache = options().taggedValueFactory(0);
        if (isAttribute()) {
            // Attribute case:
            // Fetch tagged values collection
            Collection<AttributeTag> tvs = eaAttribute.GetTaggedValues();
            // ensure that there are tagged values
            if (tvs != null) {
                // Allocate cache
                int ntvs = tvs.GetCount();
                taggedValuesCache = options().taggedValueFactory(ntvs);
                // Copy tag-value-pairs, leave out non-ShapeChange stuff and
                // normalize deprecated tags.
                for (AttributeTag tv : tvs) {
                    String t = tv.GetName();
                    t = options().taggedValueNormalizer().normalizeTaggedValue(t);
                    if (t != null) {
                        String v = tv.GetValue();
                        if (v.equals("<memo>"))
                            v = tv.GetNotes();
                        taggedValuesCache.add(t, v);
                    }
                }
            }
        } else {
            // Role case:
            // Fetch tagged values collection
            Collection<RoleTag> tvs = eaConnectorEnd.GetTaggedValues();
            // ensure that there are tagged values
            if (tvs != null) {
                // Allocate cache
                int ntvs = tvs.GetCount();
                taggedValuesCache = options().taggedValueFactory(ntvs);
                // Copy tag-value-pairs, leave out non-ShapeChange stuff and
                // normalize deprecated tags.
                for (RoleTag tv : tvs) {
                    String t = tv.GetTag();
                    t = options().taggedValueNormalizer().normalizeTaggedValue(t);
                    if (t != null) {
                        String v = tv.GetValue();
                        /*
							 * An EA memo-field is used to provide convenient
							 * support (via a dialog in EA) for entering a
							 * tagged value with very long text. Such fields
							 * always start with the string '<memo>' (six
							 * characters long).
							 * 
							 * If a tagged value with a memo-field has an actual
							 * textual value then the value starts with
							 * '<memo>$ea_notes=' (16 characters long). So if a
							 * tag with memo-field does not have an actual
							 * value, we will only find '<memo>', but not
							 * followed by '$ea_notes='.
							 * 
							 * If the tagged value does not use a memo-field,
							 * then it may still contain or start with
							 * '$ea_notes='. In that case, the part after
							 * '$ea_notes=' provides the doreplacedentation of the
							 * tag (e.g. from the MDG Technology - UnitTests
							 * showed that the doreplacedentation can be empty) and
							 * the part before provides the actual value.
							 * 
							 * Otherwise (does not start with '<memo>' and does
							 * not contain '$ea_notes=') we can use the value as
							 * is.
							 */
                        if (v.startsWith("<memo>$ea_notes=")) {
                            v = v.substring(16);
                        } else if (v.startsWith("<memo>")) {
                            // no actual value in the memo-field
                            v = "";
                        } else if (v.contains("$ea_notes=")) {
                            // retrieve the value
                            v = v.substring(0, v.indexOf("$ea_notes="));
                        } else {
                        // fine - use the value as is
                        }
                        taggedValuesCache.add(t, v);
                    }
                }
            }
        }
    }
}

19 View Complete Implementation : AssociationInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
// public int getEAConnectorId() {
// return this.eaConnectorId;
// }
// Validate tagged values cache, filtering on tagged values defined within
// ShapeChange ...
public void validateTaggedValuesCache() {
    if (taggedValuesCache == null) {
        // Fetch tagged values collection
        Collection<ConnectorTag> tvs = eaConnector.GetTaggedValues();
        // ensure that there are tagged values
        if (tvs != null) {
            // Allocate cache
            int ntvs = tvs.GetCount();
            taggedValuesCache = options().taggedValueFactory(ntvs);
            // Copy tag-value-pairs, leave out non-ShapeChange stuff and
            // normalize deprecated tags.
            for (ConnectorTag tv : tvs) {
                String t = tv.GetName();
                t = options().taggedValueNormalizer().normalizeTaggedValue(t);
                if (t != null) {
                    String v = tv.GetValue();
                    if (v.equals("<memo>"))
                        v = tv.GetNotes();
                    taggedValuesCache.add(t, v);
                }
            }
        } else {
            taggedValuesCache = options().taggedValueFactory(0);
        }
    }
}

19 View Complete Implementation : ClassInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
// name()
// @Override
// public Descriptors aliasNameAll() {
// 
// // Only retrieve/compute the alias once
// // Cache the result for subsequent use
// if (!aliasAccessed) {
// 
// aliasAccessed = true;
// 
// // Obtain alias name from default implementation
// Descriptors ls = super.aliasNameAll();
// 
// // If not present, obtain from EA model directly, if ea:alias is
// // identified as the source
// if (ls.isEmpty()
// && descriptorSource(Descriptor.ALIAS).equals("ea:alias")) {
// 
// String a = eaClreplacedElement.GetAlias();
// 
// if (a != null && !a.isEmpty()) {
// 
// super.aliasName = new Descriptors(
// new LangString(options().internalize(a)));
// } else {
// super.aliasName = new Descriptors();
// }
// }
// }
// return super.aliasName;
// }
// Validate tagged values cache, filtering on tagged values defined within
// ShapeChange ...
public void validateTaggedValuesCache() {
    if (taggedValuesCache == null) {
        // Fetch tagged values collection
        Collection<TaggedValue> tvs = eaClreplacedElement.GetTaggedValues();
        // ensure that there are tagged values
        if (tvs != null) {
            // Allocate cache
            int ntvs = tvs.GetCount();
            taggedValuesCache = options().taggedValueFactory(ntvs);
            // Copy tag-value-pairs, leave out non-ShapeChange stuff and
            // normalize deprecated tags.
            for (TaggedValue tv : tvs) {
                String t = tv.GetName();
                t = options().taggedValueNormalizer().normalizeTaggedValue(t);
                if (t != null) {
                    String v = tv.GetValue();
                    if (v.equals("<memo>"))
                        v = tv.GetNotes();
                    taggedValuesCache.add(t, v);
                }
            }
        } else {
            taggedValuesCache = options().taggedValueFactory(0);
        }
    }
}

19 View Complete Implementation : ClassInfoEA.java
Copyright GNU General Public License v3.0
Author : ShapeChange
public clreplaced ClreplacedInfoEA extends ClreplacedInfoImpl implements ClreplacedInfo {

    /**
     * Flag used to prevent duplicate retrieval/computation of the alias of this
     * clreplaced.
     */
    protected boolean aliasAccessed = false;

    /**
     * Flag used to prevent duplicate retrieval/computation of the connectors of
     * this clreplaced.
     */
    protected boolean connectorsAccessed = false;

    /**
     * Flag used to prevent duplicate retrieval/computation of the doreplacedentation of
     * this clreplaced.
     */
    protected boolean doreplacedentationAccessed = false;

    /**
     * Flag used to prevent duplicate retrieval/computation of the globalIdentifier
     * of this clreplaced.
     */
    protected boolean globalIdentifierAccessed = false;

    /**
     * Flag used to prevent duplicate retrieval/computation of the replacedociation of
     * this clreplaced.
     */
    protected boolean isreplacedocClreplacedAccessed = false;

    /**
     * Cache for the replacedociation this clreplaced belongs to if it is an replacedociation
     * clreplaced.
     */
    protected replacedociationInfo replacedoc = null;

    /**
     * Access to the connectors of this clreplaced in the EA model
     */
    protected Collection<Connector> conns = null;

    /**
     * Cache for the IDs of the suppliers of this clreplaced
     */
    protected TreeSet<String> supplierIds = null;

    /**
     * Access to the doreplacedent object
     */
    protected EADoreplacedent doreplacedent;

    /**
     * The package the clreplaced belongs to
     */
    protected PackageInfoEA packageInfo;

    /**
     * Baseclreplacedes
     */
    protected TreeSet<ClreplacedInfoEA> baseclreplacedInfoSet = null;

    /**
     * Subclreplacedes
     */
    protected TreeSet<ClreplacedInfoEA> subclreplacedInfoSet = new TreeSet<ClreplacedInfoEA>();

    /**
     * The EA element addressed by this ClreplacedInfo
     */
    protected org.sparx.Element eaClreplacedElement = null;

    /**
     * The EA object id of the clreplaced element object
     */
    protected int eaClreplacedId = 0;

    /**
     * Name of the clreplaced
     */
    protected String eaName = null;

    /**
     * Some clreplaced flags.
     */
    protected boolean isAbstract = false;

    protected boolean isLeaf = false;

    /**
     * Roles registered as properties of the clreplaced
     */
    protected Vector<PropertyInfoEA> registeredRoles = new Vector<PropertyInfoEA>();

    /**
     * Cache map for tagged values
     */
    // this map is already defined in InfoImpl
    /**
     * Cache set for stereotypes
     */
    // this map is already defined in InfoImpl
    /**
     * Cache (ordered) set for properties
     */
    protected TreeMap<StructuredNumber, PropertyInfo> propertiesCache = null;

    /**
     * Cache (ordered) set for operations
     */
    protected TreeMap<Integer, OperationInfo> operationsCache = null;

    /**
     * Cache set of constraints
     */
    protected Vector<Constraint> constraintsCache = null;

    private Boolean realization = null;

    public ClreplacedInfoEA(EADoreplacedent doc, PackageInfoEA pi, org.sparx.Element elmt) throws ShapeChangeAbortException {
        // Memorize doreplacedent and parent package.
        doreplacedent = doc;
        packageInfo = pi;
        // EA object reference. Fetch id and name.
        eaClreplacedElement = elmt;
        eaClreplacedId = eaClreplacedElement.GetElementID();
        eaName = eaClreplacedElement.GetName().trim();
        // Register as child of parent package.
        pi.childCI.add(this);
        // Determine some clreplaced flags
        isAbstract = eaClreplacedElement.GetAbstract().equals("1");
        isLeaf = eaClreplacedElement.GetIsLeaf();
        // Determine clreplaced category
        establishCategory();
        if (category == Options.UNKNOWN && elmt.GetType().equalsIgnoreCase("enumeration")) {
            category = Options.ENUMERATION;
        }
        // Cache if realisations should not be treated as generalisations
        /*
	 * 2015-04-16 JE TBD: 'realisationLikeGeneralisation' should become a general
	 * input parameter. Loading of the input model should not depend on a specific
	 * target.
	 */
        String realization = doreplacedent.options.parameter(Options.TargetXmlSchemaClreplaced, "realisationLikeGeneralisation");
        if (realization != null && realization.equalsIgnoreCase("false")) {
            this.realization = Boolean.FALSE;
        }
    }

    // ClreplacedInfoEA Ctor
    // Establish clreplaced derivation hierarchy. This auxiliary initializing
    // method sets the base clreplaced relation ship obtained from the model and
    // also enters this clreplaced as subclreplaced of all its base clreplacedes.
    // Note that invocation of this method requires that all clreplacedes in
    // the model are already cached.
    // Note: ISO19107 makes use of realization instead of generalization in some
    // cases to inherit from interfaces. Therefore realization of interfaces is
    // also considered a base clreplaced relationship as a default unless overruled
    // by
    // a parameter.
    public void establishClreplacedDerivationHierarchy() {
        // Find out about all connectors attached to the clreplaced
        // Only do this once; cache the results for subsequent use
        if (!connectorsAccessed) {
            conns = eaClreplacedElement.GetConnectors();
            connectorsAccessed = true;
        }
        // check that this clreplaced has connectors
        if (conns != null) {
            /*
	     * Enumerate connectors selecting those where this clreplaced is the client, from
	     * these select "Generalization" and "Realisation". Retrieve the supplier clreplaced
	     * wrappers. For "Realisation" type suppliers also make sure the clreplaced is an
	     * interface. The clreplacedes found are registered as base clreplacedes. In the base
	     * clreplacedes register this clreplaced as subclreplaced.
	     */
            int clientid, bclid, cat;
            String conntype;
            boolean gen, rea;
            for (Connector conn : conns) {
                // Skip all other connector types
                conntype = conn.GetType();
                gen = conntype.equals("Generalization");
                rea = conntype.equals("Realisation");
                // this.realization is determined from configuration parameters
                // if it is not null then it is false
                if (this.realization != null && !this.realization.booleanValue())
                    rea = false;
                if (!gen && !rea)
                    continue;
                // Make sure we are the client of this connector
                clientid = conn.GetClientID();
                if (clientid != this.eaClreplacedId)
                    continue;
                // Find out about the id of the base clreplaced (=supplier)
                bclid = conn.GetSupplierID();
                // From this determine the ClreplacedInfo wrapper object
                ClreplacedInfoEA baseCI = doreplacedent.fClreplacedById.get(String.valueOf(bclid));
                // If such an object exists establish it as base clreplaced.
                if (baseCI != null) {
                    // If we know this via a Realization we additionally check
                    // we are seeing an interface.
                    if (rea) {
                        cat = baseCI.category();
                        if (cat != Options.MIXIN)
                            continue;
                    }
                    if (baseclreplacedInfoSet == null) {
                        baseclreplacedInfoSet = new TreeSet<ClreplacedInfoEA>();
                    }
                    baseclreplacedInfoSet.add(baseCI);
                    // Register with the subclreplacedes of the base clreplaced.
                    baseCI.subclreplacedInfoSet.add(this);
                }
            }
        }
    }

    // establishClreplacedDerivationHierarchy()
    /*
     * Old version as of 2009-05-27 preserved. Required change was the additional
     * consideration of realisations instead of generalisations. public void
     * establishClreplacedDerivationHierarchy() { // Find out about base clreplacedes
     * Collection<Element> baseclreplacedes = eaClreplacedElement.GetBaseClreplacedes(); short nbcl
     * = baseclreplacedes.GetCount(); // Enumerate base clreplacedes and retrieve their
     * corresponding wrappers. // Register these as base clreplacedes. In the base
     * clreplacedes register this // clreplaced as subclreplaced. for(Element baseclreplaced :
     * baseclreplacedes) { // Find out about the id of the base clreplaced int bclid =
     * baseclreplaced.GetElementID(); // From this determine the ClreplacedInfo wrapper object
     * ClreplacedInfoEA baseCI = doreplacedent.fClreplacedById.get(new Integer(bclid).toString());
     * // If such an object exists establish it as base clreplaced. if(baseCI!=null) { //
     * Establish as base clreplaced. Since most clreplacedes indeed possess // at most one
     * base clreplaced, this case will be treated somewhat // storage-optimized.
     * if(nbcl==1) { baseclreplacedInfo = baseCI; } else { if(baseclreplacedInfoSet==null)
     * baseclreplacedInfoSet = new HashSet<ClreplacedInfoEA>(nbcl);
     * baseclreplacedInfoSet.add(baseCI); } // Register with the subclreplacedes of the base
     * clreplaced. baseCI.subclreplacedInfoSet.add(this); } } } //
     * establishClreplacedDerivationHierarchy()
     */
    // Establish all clreplaced replacedociations. This is an auxiliary initializing
    // method, which retrieves all replacedociations (EA: Connectors) known to
    // the clreplaced and creates wrapper objects for them in case they have not
    // already been encountered from the other clreplaced end. All created
    // replacedociation objects are registered. Object creation established the
    // necessary links to source and target objects and properties.
    // Note that invocation of this method requires that all clreplacedes of the
    // model are already cached.
    public void establishreplacedociations() {
        // Find out about replacedociations connected to the clreplaced
        // Only do this once; cache the results for subsequent use
        if (!connectorsAccessed) {
            conns = eaClreplacedElement.GetConnectors();
            connectorsAccessed = true;
        }
        // check that this clreplaced has connectors
        if (conns != null) {
            // Enumerate connectors
            boolean known;
            int id;
            String connid;
            for (Connector conn : conns) {
                // only process "replacedociation" connectors
                String type = conn.GetType();
                if (!type.equalsIgnoreCase("replacedociation") && !type.equalsIgnoreCase("Aggregation")) {
                    continue;
                }
                // First find out whether the replacedociation has already been
                // processed from its other end. If so, discard.
                id = conn.GetConnectorID();
                connid = createreplacedociationId(Integer.valueOf(id).toString());
                known = doreplacedent.freplacedociationById.containsKey(connid);
                if (known)
                    continue;
                // First encounter: Create replacedociationInfo wrapper and
                // properties linkage.
                replacedociationInfoEA ai = new replacedociationInfoEA(doreplacedent, conn, connid);
                // Register with global replacedociations map, if relevant clreplaced
                // replacedociation
                if (ai.relevant)
                    doreplacedent.freplacedociationById.put(connid, ai);
            }
        }
    }

    /**
     * In EA, the replacedociation and the clreplaced of an replacedociation clreplaced construct may
     * have the same ID. That is not allowed by ShapeChange. See {@link Info#id()}.
     * Therefore, this method augments the base ID of an replacedociation connector.
     *
     * @param baseId
     */
    private String createreplacedociationId(String baseId) {
        return "as" + baseId;
    }

    // Establish the roles attached to the clreplaced. This auxiliary initializing
    // method is called from the replacedociationInfoEA Ctor to register a list of
    // roles as properties of the clreplaced.
    public void establishRoles(PropertyInfoEA pi) {
        registeredRoles.add(pi);
    }

    /**
     * Inquire wrapped EA object
     *
     * @return tbd
     */
    public org.sparx.Element getEaClreplacedElement() {
        return eaClreplacedElement;
    }

    public int getEaElementId() {
        return eaClreplacedId;
    }

    /**
     * Return EA model object.
     */
    public Model model() {
        return doreplacedent;
    }

    // model()
    /**
     * Return options and configuration object.
     */
    public Options options() {
        return doreplacedent.options;
    }

    // options()
    /**
     * Return result object for error reporting.
     */
    public ShapeChangeResult result() {
        return doreplacedent.result;
    }

    // result()
    /**
     * This is supposed to find out, whether the given category 'cat' applied in
     * 'this' clreplaced complies to the categories of all its base clreplacedes. If at least
     * one base clreplaced does not comply, 'false' is returned. Overloaded from
     * supertype, because we here have more comfortable data structures available.
     */
    @Override
    public boolean checkSupertypes(int cat) {
        // Prepare set of base clreplacedes
        TreeSet<ClreplacedInfoEA> bcis = new TreeSet<ClreplacedInfoEA>();
        if (baseclreplacedInfoSet != null)
            bcis = baseclreplacedInfoSet;
        // Consider all baseclreplacedes in turn, break as soon as a first non-
        // compliancy is detected.
        boolean res = true;
        for (ClreplacedInfoEA bci : bcis) {
            // Get category of base clreplaced
            int bcicat = bci.category();
            // Find out about category compliance
            if (bcicat == Options.UNKNOWN) {
                // If base clreplaced category unknown, obtain from its base clreplacedes
                res = bci.checkSupertypes(cat);
            } else if (bcicat == Options.MIXIN) {
                // Ignore mixin base clreplaced
                continue;
            } else if (bcicat != cat) {
                // Not compliant: Reject
                res = false;
            }
            // We no longer need to look, if the result is non-compliant ...
            if (!res)
                break;
        }
        // Trace for debugging
        if (res)
            doreplacedent.result.addDebug(null, 10003, name(), "" + cat, "TRUE");
        else
            doreplacedent.result.addDebug(null, 10003, name(), "" + cat, "FALSE");
        // Return, what we found out
        return res;
    }

    // checkSupertypes()
    @Override
    public PackageInfo pkg() {
        return packageInfo;
    }

    /**
     * @see de.interactive_instruments.ShapeChange.Model.ClreplacedInfo#properties()
     */
    @SuppressWarnings("unchecked")
    public SortedMap<StructuredNumber, PropertyInfo> properties() {
        validatePropertiesCache();
        return (TreeMap<StructuredNumber, PropertyInfo>) propertiesCache.clone();
    }

    // properties()
    /**
     * @see de.interactive_instruments.ShapeChange.Model.ClreplacedInfo#property(java.lang.String)
     */
    public PropertyInfo property(String name) {
        // Search in own properties
        validatePropertiesCache();
        for (PropertyInfo pi : propertiesCache.values()) {
            if (pi.name().equals(name))
                return pi;
        }
        // Go and search in base clreplacedes
        TreeSet<ClreplacedInfoEA> bcis = new TreeSet<ClreplacedInfoEA>();
        if (baseclreplacedInfoSet != null)
            bcis = baseclreplacedInfoSet;
        for (ClreplacedInfoEA bci : bcis) {
            PropertyInfo pi = bci.property(name);
            if (pi != null)
                return pi;
        }
        return null;
    }

    // property()
    /**
     * The stereotypes added to the cache are the well-known equivalents of the
     * stereotypes defined in the EA model, if mapped in the configuration.
     *
     * @see de.interactive_instruments.ShapeChange.Model.Info#validateStereotypesCache()
     */
    public void validateStereotypesCache() {
        if (stereotypesCache == null) {
            // Fetch stereotypes 'collection' ...
            String sts = eaClreplacedElement.GetStereotypeEx();
            String[] stereotypes = sts.split("\\,");
            // Allocate cache
            stereotypesCache = StereotypeNormalizer.normalizeAndMapToWellKnownStereotype(stereotypes, this);
            /*
	     * 2017-03-23 JE: Apparently when calling eaClreplacedElement.GetStereotypeEx() the
	     * EA API does not return the stereotype of a clreplaced that has been created in EA
	     * as an element with type enumeration (which is different than a normal clreplaced).
	     * We explicitly add the stereotype "enumeration" for such elements. That will
	     * also help in case that the UML profile of an application schema did not
	     * define a stereotype for enumerations but still used EA elements of type
	     * enumeration (with the intent to treat them as enumerations). The
	     * "enumeration" stereotype is necessary when exporting a model without also
	     * exporting the category of a clreplaced, since then the clreplaced category must be
	     * established based upon the stereotype (and potentially existing XML Schema
	     * conversion rules) when importing an SCXML model.
	     */
            if (stereotypesCache.isEmpty() && eaClreplacedElement.GetType().equalsIgnoreCase("enumeration")) {
                stereotypesCache.add("enumeration");
                doreplacedent.result.addDebug(null, 52, this.name(), "enumeration");
            }
            /*
	     * The same reasoning applies for data types, which are not clreplacedes according to
	     * the UML spec, but another type of clreplacedifier.
	     */
            if (stereotypesCache.isEmpty() && eaClreplacedElement.GetType().equalsIgnoreCase("datatype")) {
                stereotypesCache.add("datatype");
                doreplacedent.result.addDebug(null, 52, this.name(), "datatype");
            }
            doreplacedent.result.addDebug(null, 55, this.name(), Integer.toString(stereotypesCache.size()), stereotypesCache.toString());
        }
    }

    // validateStereotypesCache()
    /**
     * Provide the ids of all subclreplacedes of this clreplaced.
     */
    public SortedSet<String> subtypes() {
        // Convert subclreplaced object set to subclreplaced id set.
        SortedSet<String> subids = new TreeSet<String>();
        for (ClreplacedInfoEA sci : subclreplacedInfoSet) subids.add(sci.id());
        return subids;
    }

    // subtypes()
    /**
     * @see de.interactive_instruments.ShapeChange.Model.ClreplacedInfo#supertypes()
     */
    public SortedSet<String> supertypes() {
        // Convert base clreplaced object set to base clreplaced id set.
        SortedSet<String> baseids = new TreeSet<String>();
        if (baseclreplacedInfoSet != null)
            for (ClreplacedInfoEA bci : baseclreplacedInfoSet) baseids.add(bci.id());
        return baseids;
    }

    // supertypes()
    @Override
    protected List<LangString> descriptorValues(Descriptor descriptor) {
        // get default first
        List<LangString> ls = super.descriptorValues(descriptor);
        if (ls.isEmpty()) {
            if (!doreplacedentationAccessed && descriptor == Descriptor.DOreplacedENTATION) {
                doreplacedentationAccessed = true;
                String s = null;
                // Try EA notes if ea:notes is the source
                if (model().descriptorSource(Descriptor.DOreplacedENTATION).equals("ea:notes")) {
                    s = eaClreplacedElement.GetNotes();
                    // Handle EA formatting
                    if (s != null) {
                        s = doreplacedent.applyEAFormatting(s);
                    }
                }
                /*
		 * If result is empty, check if we can get the doreplacedentation from a dependency
		 */
                if (s == null || s.isEmpty()) {
                    for (String cid : this.supplierIds()) {
                        ClreplacedInfoEA cix = doreplacedent.fClreplacedById.get(cid);
                        if (cix != null) {
                            if (cix.name().equalsIgnoreCase(this.name()) && cix.stereotype("featureconcept")) {
                                s = cix.doreplacedentation();
                                break;
                            }
                        }
                    }
                }
                // If result is empty, check if we can get the doreplacedentation
                // from a
                // supertype with the same name (added for ELF/INSPIRE)
                if (s == null || s.isEmpty()) {
                    HashSet<ClreplacedInfoEA> sts = supertypesAsClreplacedInfoEA();
                    if (sts != null) {
                        for (ClreplacedInfoEA stci : sts) {
                            if (stci.name().equals(this.name())) {
                                s = stci.doreplacedentation();
                                break;
                            }
                        }
                    }
                }
                if (s != null) {
                    ls.add(new LangString(options().internalize(s)));
                    this.descriptors().put(descriptor, ls);
                }
            } else if (!globalIdentifierAccessed && descriptor == Descriptor.GLOBALIDENTIFIER) {
                globalIdentifierAccessed = true;
                // obtain from EA model directly
                if (model().descriptorSource(Descriptor.GLOBALIDENTIFIER).equals("ea:guidtoxml")) {
                    String gi = doreplacedent.repository.GetProjectInterface().GUIDtoXML(eaClreplacedElement.GetElementGUID());
                    if (gi != null && !gi.isEmpty()) {
                        ls.add(new LangString(options().internalize(gi)));
                        this.descriptors().put(descriptor, ls);
                    }
                }
            } else if (!aliasAccessed && descriptor == Descriptor.ALIAS) {
                aliasAccessed = true;
                /*
		 * obtain from EA model directly if ea:alias is identified as the source
		 */
                if (model().descriptorSource(Descriptor.ALIAS).equals("ea:alias")) {
                    String a = eaClreplacedElement.GetAlias();
                    if (a != null && !a.isEmpty()) {
                        ls.add(new LangString(options().internalize(a)));
                        this.descriptors().put(descriptor, ls);
                    }
                }
            }
        }
        return ls;
    }

    // /**
    // * Return the doreplacedentation attached to the property object. This is
    // fetched
    // * from tagged values and - if this is absent - from the 'notes' specific
    // to
    // * the EA objects model.
    // */
    // @Override
    // public Descriptors doreplacedentationAll() {
    // 
    // // Retrieve/compute the doreplacedentation only once
    // // Cache the result for subsequent use
    // if (!doreplacedentationAccessed) {
    // 
    // doreplacedentationAccessed = true;
    // 
    // // Try default first
    // Descriptors ls = super.doreplacedentationAll();
    // 
    // if (ls.isEmpty()) {
    // 
    // String s = null;
    // 
    // // Try EA notes if ea:notes is the source
    // if (descriptorSource(Descriptor.DOreplacedENTATION)
    // .equals("ea:notes")) {
    // s = eaClreplacedElement.GetNotes();
    // // Handle EA formatting
    // if (s != null) {
    // s = doreplacedent.applyEAFormatting(s);
    // }
    // }
    // 
    // // If result is empty, check if we can get the doreplacedentation
    // // from a
    // // dependency
    // if (s == null || s.isEmpty()) {
    // 
    // for (Iterator<String> i = this.supplierIds().iterator(); i
    // .hasNext();) {
    // 
    // String cid = i.next();
    // 
    // ClreplacedInfoEA cix = doreplacedent.fClreplacedById.get(cid);
    // 
    // if (cix != null) {
    // if (cix.name().equalsIgnoreCase(this.name())
    // && cix.stereotype("featureconcept")) {
    // s = cix.doreplacedentation();
    // break;
    // }
    // }
    // }
    // }
    // 
    // // If result is empty, check if we can get the doreplacedentation
    // // from a
    // // supertype with the same name (added for ELF/INSPIRE)
    // if (s == null || s.isEmpty()) {
    // 
    // HashSet<ClreplacedInfoEA> sts = supertypesAsClreplacedInfoEA();
    // 
    // if (sts != null) {
    // for (ClreplacedInfoEA stci : sts) {
    // if (stci.name().equals(this.name())) {
    // s = stci.doreplacedentation();
    // break;
    // }
    // }
    // }
    // }
    // 
    // // replacedign what we got or "" ...
    // if (s == null) {
    // super.doreplacedentation = new Descriptors();
    // } else {
    // super.doreplacedentation = new Descriptors(
    // new LangString(options().internalize(s)));
    // }
    // }
    // }
    // return super.doreplacedentation;
    // }
    /**
     * Return model-unique id of clreplaced.
     */
    public String id() {
        return Integer.valueOf(eaClreplacedId).toString();
    }

    // id()
    /**
     * Obtain the name of the clreplaced.
     */
    public String name() {
        // Get the name obtained from the model
        if (eaName == null || eaName.equals("")) {
            // TBD: this can also be checked in the ctor
            eaName = id();
            MessageContext mc = doreplacedent.result.addWarning(null, 100, "clreplaced", eaName);
            if (mc != null)
                mc.addDetail(null, 400, "Package", pkg().fullName());
        }
        return eaName;
    }

    // name()
    // @Override
    // public Descriptors aliasNameAll() {
    // 
    // // Only retrieve/compute the alias once
    // // Cache the result for subsequent use
    // if (!aliasAccessed) {
    // 
    // aliasAccessed = true;
    // 
    // // Obtain alias name from default implementation
    // Descriptors ls = super.aliasNameAll();
    // 
    // // If not present, obtain from EA model directly, if ea:alias is
    // // identified as the source
    // if (ls.isEmpty()
    // && descriptorSource(Descriptor.ALIAS).equals("ea:alias")) {
    // 
    // String a = eaClreplacedElement.GetAlias();
    // 
    // if (a != null && !a.isEmpty()) {
    // 
    // super.aliasName = new Descriptors(
    // new LangString(options().internalize(a)));
    // } else {
    // super.aliasName = new Descriptors();
    // }
    // }
    // }
    // return super.aliasName;
    // }
    // Validate tagged values cache, filtering on tagged values defined within
    // ShapeChange ...
    public void validateTaggedValuesCache() {
        if (taggedValuesCache == null) {
            // Fetch tagged values collection
            Collection<TaggedValue> tvs = eaClreplacedElement.GetTaggedValues();
            // ensure that there are tagged values
            if (tvs != null) {
                // Allocate cache
                int ntvs = tvs.GetCount();
                taggedValuesCache = options().taggedValueFactory(ntvs);
                // Copy tag-value-pairs, leave out non-ShapeChange stuff and
                // normalize deprecated tags.
                for (TaggedValue tv : tvs) {
                    String t = tv.GetName();
                    t = options().taggedValueNormalizer().normalizeTaggedValue(t);
                    if (t != null) {
                        String v = tv.GetValue();
                        if (v.equals("<memo>"))
                            v = tv.GetNotes();
                        taggedValuesCache.add(t, v);
                    }
                }
            } else {
                taggedValuesCache = options().taggedValueFactory(0);
            }
        }
    }

    // validateTaggedValuesCache()
    /**
     * Set the tagged value for the tag given.
     *
     * @param tag   tbd
     * @param value tbd
     */
    public void taggedValue(String tag, String value) {
        Collection<TaggedValue> cTV = eaClreplacedElement.GetTaggedValues();
        TaggedValue tv = cTV.GetByName(tag);
        if (tv == null && value != null) {
            tv = cTV.AddNew(tag, value);
            tv.Update();
        } else if (tv != null) {
            if (value == null)
                value = "";
            if (!tv.GetValue().equals(value)) {
                tv.SetValue(value);
                tv.Update();
            }
        }
        // invalidate cache
        taggedValuesCache = null;
    }

    // taggedValue()
    /**
     * Determine whether the clreplaced is tagged as being an abstract clreplaced
     */
    public boolean isAbstract() {
        return isAbstract;
    }

    // isAbstract()
    @Override
    public boolean isLeaf() {
        return isLeaf;
    }

    // isLeaf()
    // Validate constraints cache. This makes sure the constraints cache
    // contains all constraints ordered by their appearance in the clreplaced.
    // If constraints are disabled the cache is empty.
    private void validateConstraintsCache() {
        if (constraintsCache == null) {
            // Allocate cache
            constraintsCache = new Vector<Constraint>();
            // Constraints disabled?
            if (!doreplacedent.options.constraintLoadingEnabled())
                return;
            // Constraints for this clreplaced category irrelevant?
            if (!doreplacedent.options.isClreplacedTypeToCreateConstraintsFor(category()))
                return;
            // Constraints from selected schemas only?
            if (doreplacedent.options.isLoadConstraintsForSelectedSchemasOnly() && !doreplacedent.isInSelectedSchemas(this)) {
                return;
            }
            // Filter map for inheritance and overriding by name
            HashMap<String, Constraint> namefilter = new HashMap<String, Constraint>();
            // Access EA constraints data
            Collection<org.sparx.Constraint> constrs = eaClreplacedElement.GetConstraints();
            // Determine constraint types to be parsed as OCL
            String oclTypes = doreplacedent.options.parameter("oclConstraintTypeRegex");
            // Determine constraint types to be parsed as FOL
            String folTypes = doreplacedent.options.parameter("folConstraintTypeRegex");
            // Enumerate all constraints found
            // Ensure that there are constraints before continuing
            if (constrs != null) {
                for (org.sparx.Constraint constr : constrs) {
                    // Wrap into constraint object
                    String type = constr.GetType();
                    Constraint oc;
                    if (oclTypes.length() > 0 && type.matches(oclTypes)) {
                        // 100422/re removed: &&
                        // !encodingRule("xsd").equals(Options.ISO19136_2007_INSPIRE)
                        OclConstraintEA ocl = new OclConstraintEA(doreplacedent, this, constr);
                        if (ocl.syntaxTree() == null)
                            // Text constraint is a fallback in case of parsing
                            // issues
                            oc = new TextConstraintEA(doreplacedent, this, constr);
                        else
                            oc = ocl;
                    } else if (folTypes != null && folTypes.length() > 0 && type.matches(folTypes)) {
                        /*
			 * only sets up the textual information; parsing is done during model
			 * postprocessing - see ModelImpl.postprocessFolConstraints()
			 */
                        oc = new FolConstraintEA(doreplacedent, this, constr);
                    } else {
                        oc = new TextConstraintEA(doreplacedent, this, constr);
                    }
                    // Collect in cache
                    constraintsCache.add(oc);
                    // If the constraint has a name, add it to the filter which
                    // blocks inheritance of constraints
                    String conam = oc.name();
                    if (conam != null && conam.length() > 0)
                        namefilter.put(conam, oc);
                }
            }
            /*
	     * Fetch constraints from super-clreplacedes. Override by name.
	     */
            /*
	     * JE: replaced this code with code (see below) that directly accesses the
	     * supertype objects, instead of first getting all their IDs and then looking
	     * the objects up in the model.
	     */
            // HashSet<String> stids = supertypes();
            // if (stids != null) {
            // for (String stid : stids) {
            // ClreplacedInfo stci = model().clreplacedById(stid);
            // Vector<Constraint> stcos = null;
            // if (stci != null)
            // stcos = stci.constraints();
            // if (stcos != null) {
            // for (Constraint stco : stcos) {
            // String nam = stco == null ? null : stco.name();
            // if(nam!=null && nam.length()>0 && namefilter.containsKey(nam))
            // continue;
            // constraintsCache.add(stco);
            // }
            // }
            // }
            // }
            HashSet<ClreplacedInfoEA> sts = supertypesAsClreplacedInfoEA();
            if (sts != null) {
                for (ClreplacedInfoEA stci : sts) {
                    Vector<Constraint> stcos = null;
                    if (stci != null)
                        stcos = stci.constraints();
                    if (stcos != null) {
                        for (Constraint stco : stcos) {
                            String nam = stco == null ? null : stco.name();
                            if (nam != null && nam.length() > 0 && namefilter.containsKey(nam))
                                continue;
                            // Is the context of stco still the supertype, or
                            // should it not be this (ClreplacedInfoEA)?
                            constraintsCache.add(stco);
                        }
                    }
                }
            }
        }
    }

    private HashSet<ClreplacedInfoEA> supertypesAsClreplacedInfoEA() {
        // Create base clreplaced object set
        HashSet<ClreplacedInfoEA> baseClreplacedes = new HashSet<ClreplacedInfoEA>(1);
        if (baseclreplacedInfoSet != null)
            for (ClreplacedInfoEA bci : baseclreplacedInfoSet) baseClreplacedes.add(bci);
        return baseClreplacedes;
    }

    /**
     * @see de.interactive_instruments.ShapeChange.Model.ClreplacedInfo#constraints()
     */
    public Vector<Constraint> constraints() {
        validateConstraintsCache();
        return constraintsCache;
    }

    // Validate properties cache. This makes sure the property cache contains
    // all properties ordered by their appearance in the clreplaced.
    private void validatePropertiesCache() {
        if (propertiesCache == null) {
            // Allocate the cache
            propertiesCache = new TreeMap<StructuredNumber, PropertyInfo>();
            // Load attributes ...
            Collection<Attribute> attrs = eaClreplacedElement.GetAttributes();
            // Ensure that there are attributes before continuing
            if (attrs != null) {
                for (Attribute attr : attrs) {
                    // Pick public attributes if this has been requested
                    if (doreplacedent.options.parameter("publicOnly").equals("true")) {
                        String vis = attr.GetVisibility();
                        if (!vis.equalsIgnoreCase("Public")) {
                            continue;
                        }
                    }
                    // Create the property object.
                    PropertyInfoEA pi = new PropertyInfoEA(doreplacedent, this, attr);
                    // Check sequence number on duplicates
                    PropertyInfo piTemp = propertiesCache.get(pi.sequenceNumber());
                    if (piTemp != null) {
                        int cat = category();
                        if (cat != Options.ENUMERATION && cat != Options.CODELIST && !pi.sequenceNumber.equals(new StructuredNumber(Integer.MIN_VALUE))) {
                            MessageContext mc = doreplacedent.result.addError(null, 107, pi.name(), name(), piTemp.name());
                            if (mc != null)
                                mc.addDetail(null, 400, "Package", pkg().fullName());
                        }
                    }
                    // Add to properties cache
                    propertiesCache.put(pi.sequenceNumber(), pi);
                }
            }
            // Load roles ...
            for (PropertyInfoEA pi : registeredRoles) {
                // Check sequence number on duplicates
                PropertyInfo piTemp = propertiesCache.get(pi.sequenceNumber());
                if (piTemp != null) {
                    MessageContext mc = doreplacedent.result.addError(null, 107, pi.name(), name(), piTemp.name());
                    if (mc != null)
                        mc.addDetail(null, 400, "Package", pkg().fullName());
                }
                // Add to properties cache
                propertiesCache.put(pi.sequenceNumber(), pi);
            }
        }
    }

    // validatePropertiesCache()
    // Validate operations cache. This makes sure the operations cache contains
    // all Operations ordered by their appearance in the clreplaced.
    private void validateOperationsCache() {
        if (operationsCache == null) {
            // Allocate the cache
            operationsCache = new TreeMap<Integer, OperationInfo>();
            // Load methods ...
            Collection<Method> meths = eaClreplacedElement.GetMethods();
            int i = 0;
            // Ensure that there are methods before continuing
            if (meths != null) {
                for (Method meth : meths) {
                    // Create the operation object.
                    OperationInfoEA oi = new OperationInfoEA(doreplacedent, this, meth);
                    // Drop in cache
                    // operationsCache.put(oi.eaMethod.GetPos(), oi); <-- does
                    // not work!
                    operationsCache.put(++i, oi);
                }
            }
        }
    }

    // validateOperationsCache()
    /**
     * Find the operation identified by its name and the types of its parameters in
     * this clreplaced or (if not present there) recursively in its base clreplacedes.
     */
    public OperationInfo operation(String name, String[] types) {
        // Make sure operations are loaded
        validateOperationsCache();
        // Search in the clreplaced itself
        search_operation: for (OperationInfo oi : operationsCache.values()) {
            if (oi.name().equals(name)) {
                // Success if types shall not be compared
                if (types == null)
                    return oi;
                // Check number of parameters
                if (types.length != oi.parameterCount())
                    continue;
                // Check type strings
                SortedMap<Integer, String> ptypes = oi.parameterTypes();
                for (int i = 0; i < types.length; i++) {
                    if (types[i].equals("*"))
                        continue;
                    if (!ptypes.get(i + 1).equals(types[i]))
                        continue search_operation;
                }
                // All types found matching
                return oi;
            }
        }
        // Go and search in base clreplacedes
        TreeSet<ClreplacedInfoEA> bcis = new TreeSet<ClreplacedInfoEA>();
        if (baseclreplacedInfoSet != null)
            bcis = baseclreplacedInfoSet;
        for (ClreplacedInfoEA bci : bcis) {
            OperationInfo oi = bci.operation(name, types);
            if (oi != null)
                return oi;
        }
        return null;
    }

    public replacedociationInfo isreplacedocClreplaced() {
        // Only retrieve/compute the replacedociation once
        // Cache the result for subsequent use
        if (!isreplacedocClreplacedAccessed) {
            isreplacedocClreplacedAccessed = true;
            if (eaClreplacedElement.GetSubtype() == 17 && !eaClreplacedElement.MiscData(3).isEmpty()) {
                replacedoc = doreplacedent.freplacedociationById.get(createreplacedociationId(eaClreplacedElement.MiscData(3)));
            }
        }
        return replacedoc;
    }

    /**
     * @return set of ids of clreplacedes this clreplaced depends on; can be empty but not
     *         <code>null</code>
     */
    protected TreeSet<String> supplierIds() {
        // Only retrieve/compute supplierIds once
        // Cache the results for subsequent use
        if (supplierIds == null) {
            // Prepare set to return
            supplierIds = new TreeSet<String>();
            // Ask EA for the connectors attached to the package object and loop
            // over the connectors returned
            // Only compute them once for the whole clreplaced
            if (!connectorsAccessed) {
                conns = eaClreplacedElement.GetConnectors();
                connectorsAccessed = true;
            }
            // Ensure that there are connectors before continuing
            if (conns != null) {
                for (Connector conn : conns) {
                    // Single out dependency connectors
                    String type = conn.GetType();
                    if (type.equals("Dependency")) {
                        // From the dependency grab the id of the supplier
                        int suppId = conn.GetSupplierID();
                        String suppIdS = Integer.toString(suppId);
                        /*
			 * Since all connectors are delivered from both objects at the connector ends,
			 * we have to make sure it is not accidently us, which we found.
			 */
                        if (suppId == eaClreplacedId)
                            continue;
                        /*
			 * Now, this is an element id, not a package id. So we have to identify the
			 * package, which owns the element addressed.
			 */
                        ClreplacedInfoEA suppClreplaced = (ClreplacedInfoEA) doreplacedent.fClreplacedById.get(suppIdS);
                        if (suppClreplaced != null) {
                            // From this only the id is required
                            String suppPackId = suppClreplaced.id();
                            if (suppPackId != null)
                                supplierIds.add(suppPackId);
                        } else {
                        // package of supplier clreplaced has not been loaded,
                        // dismiss the supplier
                        }
                    }
                }
            }
        }
        return supplierIds;
    }
    // supplierIds()
    // 
    // @Override
    // public Descriptors descriptors() {
    // 
    // // Obtain descriptors from default implementation
    // Descriptors ls = super.descriptors();
    // // If not present, obtain from EA model directly
    // if (ls.isEmpty() && descriptorSource(Descriptor.GLOBALIDENTIFIER)
    // .equals("ea:guidtoxml")) {
    // 
    // String gi = doreplacedent.repository.GetProjectInterface()
    // .GUIDtoXML(eaClreplacedElement.GetElementGUID());
    // 
    // super.globalIdentifier = new Descriptors(
    // new LangString(options().internalize(gi)));
    // }
    // return super.globalIdentifier;
    // }
}

19 View Complete Implementation : EAAttributeUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * @param att
 *            Attribute to which the new constraint shall be added.
 * @param name
 *            Name of the new constraint
 * @param type
 *            Type of the new constraint
 * @param text
 *            Text of the new constraint
 * @return The new constraint
 * @throws EAException tbd
 */
public static org.sparx.AttributeConstraint addConstraint(Attribute att, String name, String type, String text) throws EAException {
    Collection<org.sparx.AttributeConstraint> cons = att.GetConstraints();
    org.sparx.AttributeConstraint con = cons.AddNew(name, type);
    cons.Refresh();
    con.SetNotes(text);
    if (!con.Update()) {
        throw new EAException(createMessage(message(108), name, att.GetName(), con.GetLastError()));
    } else {
        return con;
    }
}

19 View Complete Implementation : EAElementUtil.java
Copyright GNU General Public License v3.0
Author : ShapeChange
/**
 * Adds the given list of tagged values to the collection of (EA) tagged values
 * of the given element, NOT checking for duplicate tags.
 * <p>
 * <b>WARNING:</b> Enterprise Architect may initialize default tagged values for
 * a model element that adheres to a specific UML profile. In that case, adding
 * the same tagged values would lead to duplicates. If duplicates shall be
 * prevented, set the tagged value instead of adding it.
 *
 * @param e tbd
 * @param tvs collection of tagged values to set
 * @throws EAException  tbd
 */
public static void addTaggedValues(Element e, List<EATaggedValue> tvs) throws EAException {
    if (tvs == null || tvs.isEmpty()) {
    // nothing to do
    } else {
        Collection<TaggedValue> cTV = e.GetTaggedValues();
        for (EATaggedValue tv : tvs) {
            String name = tv.getName();
            List<String> values = tv.getValues();
            if (values != null) {
                for (String v : values) {
                    TaggedValue eaTv = cTV.AddNew(name, "");
                    cTV.Refresh();
                    if (tv.createAsMemoField() || v.length() > 255) {
                        eaTv.SetValue("<memo>");
                        eaTv.SetNotes(v);
                    } else {
                        eaTv.SetValue(v);
                        eaTv.SetNotes("");
                    }
                    if (!eaTv.Update()) {
                        throw new EAException(createMessage(message(106), name, e.GetName(), v, eaTv.GetLastError()));
                    }
                }
            }
        }
    }
}