001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.core.metamodel.profiles;
043:
044: import org.dom4j.Document;
045: import org.dom4j.Node;
046:
047: import org.netbeans.modules.uml.core.metamodel.core.constructs.Class;
048: import org.netbeans.modules.uml.core.metamodel.core.foundation.IVersionableElement;
049: import org.netbeans.modules.uml.core.metamodel.core.foundation.UMLXMLManip;
050: import org.netbeans.modules.uml.core.support.umlsupport.StringUtilities;
051: import org.netbeans.modules.uml.core.support.umlutils.ETList;
052:
053: /**
054: * Stereotype is the implementation of the UML Stereotype meta type.
055: * A stereotype defines how an existing metaclass (or stereotype) may be
056: * extended, and enables the use of platform or domain specific
057: * terminology or notation in addition to the ones used for the extended
058: * metaclass.
059: */
060: public class Stereotype extends Class implements IStereotype {
061:
062: /**
063: *
064: * Retrieves the names of the Meta types that this Stereotype can be applied to.
065: */
066: public ETList<String> appliesTo() {
067: String values = UMLXMLManip.getAttributeValue(m_Node,
068: "appliesTo");
069: ETList<String> strs = null;
070: if (values != null && values.length() > 0) {
071: strs = StringUtilities.splitOnDelimiter(values, " ");
072: }
073: return strs;
074: }
075:
076: /**
077: *
078: * Adds a meta type that this Stereotype will now be able to be applied to.
079: *
080: * @param sType[in] The name of the meta type, e.g. "Class"
081: */
082: public void addApplicableMetaType(String sType) {
083: String curValue = UMLXMLManip.getAttributeValue(m_Node,
084: "appliesTo");
085: if (curValue != null && curValue.length() > 0) {
086: curValue += " ";
087: curValue += sType;
088: } else {
089: curValue = sType;
090: }
091:
092: UMLXMLManip.setAttributeValue(this , "appliesTo", curValue);
093: }
094:
095: /**
096: *
097: * Removes the passed-in meta type from this Stereotype's list of applicable
098: * types. Essentially, this now prevents this Stereotype from being applied
099: * to an instance of that meta type.
100: *
101: * @param sType[in] The meta type to remove
102: */
103: public void removeApplicableMetaType(String sType) {
104: if (sType != null && sType.length() > 0) {
105: String curValue = UMLXMLManip.getAttributeValue(m_Node,
106: "appliesTo");
107: if (curValue != null && curValue.length() > 0) {
108: String newValue = UMLXMLManip.removeElementFromString(
109: sType, curValue);
110: UMLXMLManip.setAttributeValue(this , "appliesTo",
111: newValue);
112: }
113: }
114: }
115:
116: /**
117: * Establishes the appropriate XML elements for this UML type.
118: *
119: * [in] The document where this element will reside
120: * [in] The element's parent node.
121: */
122: public void establishNodePresence(Document doc, Node parent) {
123: buildNodePresence("UML:Stereotype", doc, parent);
124: }
125:
126: }
|