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.requirementsframework;
043:
044: import java.util.Iterator;
045: import java.util.List;
046:
047: import org.dom4j.Element;
048: import org.dom4j.Node;
049:
050: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
051: import org.netbeans.modules.uml.core.support.umlutils.ETList;
052:
053: /**
054: * @author brettb
055: *
056: * To change the template for this generated type comment go to
057: * Window>Preferences>Java>Code Generation>Code and Comments
058: */
059: public class RequirementUtility {
060:
061: /**
062: *
063: * Recursively process child XML elements from the requirements file
064: * looking for requirements to display in the requirements tree.
065: *
066: * @param node[in] Current XML node.
067: * @param class[in] ClassID of the component to be created.
068: * @param ppRequirements[out,retval] Requirements Collection
069: *
070: * @return void
071: *
072: */
073: public static ETList<IRequirement> processChildElements(Node node,
074: Class c, ETList<IRequirement> requirements)
075:
076: {
077: if (null == node)
078: throw new IllegalArgumentException();
079:
080: String strProjectName = "";
081: if (node instanceof Element) {
082: Element projectElement = (Element) node;
083:
084: strProjectName = projectElement.attributeValue("name");
085: }
086:
087: List children = node.selectNodes("Requirement");
088:
089: // Get all Requirement Nodes from XMLDOM representation of file and add to
090: // an IRequirements collection.
091: for (Iterator iter = children.iterator(); iter.hasNext();) {
092: Node childNode = (Node) iter.next();
093:
094: if (childNode instanceof Element) {
095: Element childElement = (Element) childNode;
096:
097: String strNodeName = childElement.getName();
098: String strName = childElement.attributeValue("name");
099: String strModName = childElement
100: .attributeValue("modname");
101: String strType = childElement.attributeValue("type");
102:
103: if (strType.equals("Requirement")
104: || strType.equals("Category")) {
105: String strID = childElement.attributeValue("id");
106:
107: // Create a new Requirement instance.
108: IRequirement requirement = null;
109: try {
110: requirement = (IRequirement) c.newInstance();
111: } catch (Exception e) {
112: e.printStackTrace();
113: }
114:
115: // Get the Node's description for display in treeItem later.
116: Node descriptionNode = childElement
117: .selectSingleNode("Description");
118:
119: if ((descriptionNode != null)
120: && (requirement != null))
121:
122: {
123: // Populate the Requirement's id and name properties.
124: requirement.setType(strType);
125: requirement.setID(strID);
126: requirement.setName(strName);
127: requirement.setModName(strModName);
128: requirement.setProjectName(strProjectName);
129:
130: // Populate the Requirement's description prop.
131: String strDescription = descriptionNode
132: .getText();
133: requirement.setDescription(strDescription);
134:
135: // Create or add to the return collection parameter.
136: if (requirements != null) {
137: requirements.add(requirement);
138: } else {
139: requirements = new ETArrayList<IRequirement>();
140:
141: requirements.add(requirement);
142: }
143: }
144: } else {
145: requirements = processChildElements(childElement,
146: c, requirements);
147: }
148: }
149: }
150:
151: return requirements;
152: }
153: }
|