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.Node;
045:
046: import org.netbeans.modules.uml.core.support.umlsupport.StringUtilities;
047: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
048: import org.netbeans.modules.uml.core.support.umlutils.ETList;
049:
050: /**
051: */
052: public class ReferenceEvent extends MethodDetailParserData implements
053: IReferenceEvent {
054:
055: /* (non-Javadoc)
056: * @see org.netbeans.modules.uml.core.reverseengineering.reframework.IReferenceEvent#getParentReference()
057: */
058: public IReferenceEvent getParentReference() {
059: Node n = getXMLNode("ReferenceVariable");
060: if (n != null) {
061: IReferenceEvent e = new ReferenceEvent();
062: e.setEventData(n);
063: return e;
064: }
065: return null;
066: }
067:
068: /* (non-Javadoc)
069: * @see org.netbeans.modules.uml.core.reverseengineering.reframework.IReferenceEvent#getFullName()
070: */
071: public String getFullName() {
072: IReferenceEvent par = getParentReference();
073: String ret = null;
074: if (par != null) {
075: ret = par.getFullName() + "::";
076: }
077:
078: String myName = getName();
079: if ((myName == null) || (myName.length() <= 0)) {
080: // We have a static instance. So, get the name
081: // of the type instead.
082: myName = getShortTypeName();
083: }
084:
085: if (myName != null)
086: ret = ret != null ? ret + myName : myName;
087: return ret;
088: }
089:
090: /**
091: * @return
092: */
093: private String getShortTypeName() {
094: String myName = getType();
095: if (myName == null)
096: return null;
097:
098: ETList<String> tokens = StringUtilities.splitOnDelimiter(
099: myName, "::");
100: if (tokens.size() > 0)
101: return tokens.get(tokens.size() - 1);
102: return null;
103: }
104:
105: /* (non-Javadoc)
106: * @see org.netbeans.modules.uml.core.reverseengineering.reframework.IReferenceEvent#getREClass()
107: */
108: public IREClass getREClass() {
109: Node node = getXMLNode("UML:Class|UML:Interface|UML:Enumeration");
110: if (node != null) {
111: IREClass cl = new REClass();
112: cl.setEventData(node);
113: return cl;
114: }
115: return null;
116: }
117:
118: /**
119: * Retrieves the name of the classifier that declares the variable.
120: *
121: * @param pVal [out] The declaring class name.
122: */
123: public String getDeclaringClassifier() {
124: String cl = XMLManip.getAttributeValue(getEventData(),
125: "declaringClassifier");
126: if (cl == null || cl.length() == 0)
127: cl = XMLManip.getAttributeValue(getEventData(), "type");
128: return cl;
129: }
130:
131: /**
132: * Retrieves the variables declared type.
133: *
134: * @param pVal [out] The variables type.
135: */
136: public String getType() {
137: return XMLManip.getAttributeValue(getEventData(), "type");
138: }
139:
140: /**
141: * Retrieves the name of the variable.
142: *
143: * @param pVal [out] The name of the variable.
144: */
145: public String getName() {
146: return XMLManip.getAttributeValue(getEventData(), "name");
147: }
148:
149: }
|