001: /*
002: * $Id: SRAPNode.java,v 1.2 2002/07/22 08:47:29 mm132998 Exp $
003: * $Source: /m/portal/ps/srap/src/migration/modules/srap/erproxy/Attic/SRAPNode.java,v $
004: * $Log: SRAPNode.java,v $
005: * Revision 1.2 2002/07/22 08:47:29 mm132998
006: * Bug ID - 4718198 , Desc - Initial code changes
007: *
008: *
009: */
010: /**
011: * $Id: SRAPNode.java,v 1.2 2002/07/22 08:47:29 mm132998 Exp $
012: * Copyright 2002 Sun Microsystems, Inc. All
013: * rights reserved. Use of this product is subject
014: * to license terms. Federal Acquisitions:
015: * Commercial Software -- Government Users
016: * Subject to Standard License Terms and
017: * Conditions.
018: *
019: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
020: * are trademarks or registered trademarks of Sun Microsystems,
021: * Inc. in the United States and other countries.
022: */package migration.modules.srap.erproxy;
023:
024: import javax.xml.parsers.*;
025: import org.xml.sax.*;
026: import org.xml.sax.helpers.*;
027: import org.w3c.dom.*;
028:
029: import java.util.Vector;
030:
031: public final class SRAPNode {
032: private NamedNodeMap nodeMap = null;
033: private String name = "";
034: private String value = "";
035: private Node node;
036: private Document source = null;
037:
038: public SRAPNode(Node node) {
039: if (node != null) {
040: this .node = node;
041: source = node.getOwnerDocument();
042: name = node.getNodeName();
043: nodeMap = node.getAttributes();
044: Node childNode = node.getFirstChild();
045: if (childNode != null) {
046: value = childNode.getNodeValue();
047: if (value == null) {
048: value = "";
049: }
050: }
051: }
052: }//constructor
053:
054: public String[] getAttributes() {
055: int len = nodeMap.getLength();
056: String[] attribs = new String[len];
057:
058: for (int i = 0; i < len; i++) {
059: Node anode = nodeMap.item(i);
060: attribs[i] = anode.getNodeName();
061: }
062: return attribs;
063: }
064:
065: public String getAttributeValue(String aAtt) {
066: if (nodeMap != null) {
067: try {
068: return nodeMap.getNamedItem(aAtt).getNodeValue();
069: } catch (Exception e) {
070: System.out.println("Error: NodeName:"
071: + node.getNodeName() + " Attribute Absent: "
072: + aAtt);
073: //Log the info..
074: return null;
075: }
076: }
077: return null;
078: }
079:
080: /**
081: Returns the Value of the String present beween the start and end Tags
082: */
083: public String getValue() {
084: return value;
085: }
086:
087: /**
088: * Returns the Name of the Tag, this node represents
089: */
090: public String getName() {
091: return name;
092: }
093:
094: public SRAPNode[] getChildNodes() {
095: return getChildNodes(node);
096: }
097:
098: public SRAPNode[] getChildNodes(Node node) {
099: Vector v = new Vector();
100: NodeList list = node.getChildNodes();
101: for (int i = 0; i < list.getLength(); i++) {
102: Node lNode = list.item(i);
103: v.add(new SRAPNode(lNode));
104: }
105: return (SRAPNode[]) v.toArray(new SRAPNode[0]);
106: }
107:
108: public SRAPNode[] getChildNodes(String nodeName) {
109: return getChildNodes(node, nodeName);
110: }
111:
112: public SRAPNode[] getChildNodes(Node node, String nodeName) {
113: Vector v = new Vector();
114: NodeList list = node.getChildNodes();
115: for (int i = 0; i < list.getLength(); i++) {
116: Node lNode = list.item(i);
117: if (lNode.getNodeName().equals(nodeName)) {
118: v.add(new SRAPNode(lNode));
119: }
120: }
121: return (SRAPNode[]) v.toArray(new SRAPNode[0]);
122: }
123:
124: }//class SRAPNode
|