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 java.util.List;
045:
046: import org.dom4j.Node;
047:
048: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
049:
050: //import com.sun.corba.se.internal.orbutil.Condition;
051:
052: /**
053: */
054: public class TestEvent extends MethodDetailParserData implements
055: ITestEvent {
056:
057: /* (non-Javadoc)
058: * @see org.netbeans.modules.uml.core.reverseengineering.reframework.ITestEvent#getStringRepresentation()
059: */
060: public String getStringRepresentation() {
061: Node n = getEventData();
062: String ret = "";
063: if (n != null) {
064: // NOTE: It would be better to use a XSLT script to generate
065: // this value.
066: Node clauseParent = n.getParent();
067: if (clauseParent != null) {
068: // We will always want the conditional Node. For normal conditionals
069: // that is the prefect place to look for the test condition. For switch
070: // statments the conditional node has the jump condition.
071: Node conditionalParent = clauseParent.getParent();
072: if (conditionalParent != null) {
073: String name = "";
074: if (clauseParent instanceof org.dom4j.Element)
075: name = ((org.dom4j.Element) clauseParent)
076: .getQualifiedName();
077: else
078: name = clauseParent.getName();
079:
080: if ("UML:ConditionalAction.switchClause"
081: .equals(name)) {
082: ret = getTestExpression(conditionalParent, ret);
083:
084: // If we have a switch statement then then the representing string
085: // should be <Jump Expression> = <Case Expression> (, <Case Expression>)
086: //
087: // So, first get the jump condition.
088: if (ret != null && ret.length() > 0)
089: ret += " = ";
090: }
091: }
092:
093: ret += getTestExpression(n, "");
094: }
095: }
096: return ret;
097: }
098:
099: /**
100: * @param n
101: * @return
102: */
103: private String getTestExpression(Node n, String val) {
104: val = getTestExpression(n, "./UML:Clause.test", val);
105: // There are two different test node name (That is UML for you, not able
106: // to standardize on anything.
107: if (val == null || val.length() == 0)
108: val = getTestExpression(n, "./UML:LoopAction.test", val);
109: return val;
110: }
111:
112: /**
113: * @param n
114: * @param string
115: * @return
116: */
117: private String getTestExpression(Node n, String query, String curval) {
118: List nodes = XMLManip.selectNodeList(n, query);
119: String ret = curval != null ? curval : "";
120: int added = 0;
121: if (nodes != null) {
122: for (int i = 0, count = nodes.size(); i < count; ++i) {
123: Node cur = (Node) nodes.get(i);
124: if (cur != null) {
125: String val = XMLManip.getAttributeValue(cur,
126: "representation");
127: if (val == null || val.length() == 0)
128: continue;
129: if (added++ > 0)
130: ret += ", ";
131: ret += val;
132: }
133: }
134: }
135: return ret;
136: }
137: }
|