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.reverseengineering.reframework;
043:
044: import org.dom4j.Element;
045: import org.dom4j.Node;
046:
047: import org.netbeans.modules.uml.core.metamodel.core.primitivetypes.IVisibilityKind;
048: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
049:
050: /**
051: */
052: public class REClassElement extends ParserData implements
053: IREClassElement {
054:
055: /* (non-Javadoc)
056: * @see org.netbeans.modules.uml.core.reverseengineering.reframework.IREClassElement#getName()
057: */
058: public String getName() {
059: return XMLManip.getAttributeValue(getEventData(), "name");
060: }
061:
062: /* (non-Javadoc)
063: * @see org.netbeans.modules.uml.core.reverseengineering.reframework.IREClassElement#getVisibility()
064: */
065: public int getVisibility() {
066: String vis = XMLManip.getAttributeValue(getEventData(),
067: "visibility");
068: if ("public".equals(vis))
069: return IVisibilityKind.VK_PUBLIC;
070: else if ("private".equals(vis))
071: return IVisibilityKind.VK_PRIVATE;
072: else if ("protected".equals(vis))
073: return IVisibilityKind.VK_PROTECTED;
074: return IVisibilityKind.VK_PACKAGE;
075: }
076:
077: /* (non-Javadoc)
078: * @see org.netbeans.modules.uml.core.reverseengineering.reframework.IREClassElement#getComment()
079: */
080: public String getComment() {
081: return getTokenDescriptorValue("Comment");
082: }
083:
084: /* (non-Javadoc)
085: * @see org.netbeans.modules.uml.core.reverseengineering.reframework.IREClassElement#getOwner()
086: */
087: public IREClass getOwner() {
088: Node parent = getOwningNamespace();
089: if (parent != null) {
090: // Make sure that the node is a UML:Class node.
091: // if the node is not a UML:Class (in other words
092: // it is a UML:Package node) then do nothing.
093: String name = ((Element) parent).getQualifiedName();
094:
095: if ("UML:Class".equals(name)) {
096: IREClass c = new REClass();
097: c.setEventData(parent);
098: return c;
099: }
100: }
101: return null;
102: }
103:
104: /**
105: * Retrieves the XML node that acts as a UML namespace to the specified
106: * XML node.
107: * <P>
108: * <B>Note:</B>The only XMI nodes that will be owners will be UML:Package
109: * and UML:Class.
110: *
111: * @param owner [out] The owner of the current class element.
112: */
113: private Node getOwningNamespace() {
114: return getOwningNamespace(getEventData());
115: }
116:
117: /**
118: * In XMI all elements that are contained inside of a namespace
119: * will be wrapped by a UML:Namespece.ownedElement tag.
120: *
121: * Attributes and operation will always be wrapped in a
122: * UML:Classifier.feature tag.
123: *
124: * Since I am only dealing with controlled XMI fragments I will
125: * take a short cut. I know that the only scoping elements will
126: * be Packages and classes. So, I will just go up the owners until
127: * I find a class tag or a package tag.
128: *
129: * In the future we may need to verify the structure of the tags.
130: *
131: * @param curNode [in] The node that will have its owning namespace retrieved.
132: * @param owner [out] The owner node or NULL if one was not found.
133: */
134: private Node getOwningNamespace(Node node) {
135: if (node == null)
136: return node;
137:
138: Node parent = node.getParent();
139: if (parent != null) {
140: String name = ((Element) parent).getQualifiedName();
141: return "UML:Package".equals(name)
142: || "UML:Class".equals(name) ? parent
143: : getOwningNamespace(parent);
144: }
145: return null;
146: }
147: }
|