001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package migration.modules.srap.erproxy;
006:
007: import javax.xml.parsers.*;
008: import org.xml.sax.*;
009: import org.xml.sax.helpers.*;
010: import org.w3c.dom.*;
011: import java.io.*;
012: import java.util.ArrayList;
013: import java.util.HashMap;
014:
015: public abstract class ConvertSRAP {
016: String idsameBasedir = null;
017: String reportfile = null;
018: String infile = null;
019: String outfile = null;
020: String component = null;
021: Document srcDocument = null;
022: Document destDocument = null;
023: HashMap ips3AttributeMappings = null;
024: HashMap ips6InstAttributes = null;
025: ArrayList ips6NewInstAttributes = null;
026:
027: private ConvertSRAP() {
028: }
029:
030: public ConvertSRAP(String infile, String outfile,
031: String idsameBasedir, String reportfile, String component) {
032: this .infile = infile;
033: this .outfile = outfile;
034: this .idsameBasedir = idsameBasedir;
035: this .reportfile = reportfile;
036: this .component = component;
037: }
038:
039: protected void init() throws SRAPInitException {
040:
041: try {
042: SRAPUtil.getReportLogHandle(reportfile);
043: } catch (Exception ex) {
044: throw new SRAPInitException(
045: "Error!, could not create the report file, "
046: + reportfile + "\n\tException : "
047: + ex.toString());
048: }
049:
050: try {
051: srcDocument = SRAPUtil.create(infile, false, false);
052: } catch (SRAPDOMException ex) {
053: throw new SRAPInitException(
054: "Error!, could not parse the input file, " + infile
055: + "\n\tException : " + ex.toString());
056: }
057:
058: try {
059: destDocument = SRAPUtil.create(false, false);
060: } catch (SRAPDOMException ex) {
061: throw new SRAPInitException(
062: "Error!, could not initialize the output file, "
063: + outfile + "\n\tException : "
064: + ex.toString());
065: }
066:
067: }
068:
069: abstract protected void convert() throws SRAPConvertException;
070:
071: protected SRAPNode[] getAllNodes(Document w3cDocument, String attrib) {
072: SRAPNode[] lNodes = null;
073: if (w3cDocument != null) {
074: NodeList nodeList = w3cDocument
075: .getElementsByTagName(attrib);
076: int len = nodeList.getLength();
077: lNodes = new SRAPNode[len];
078: for (int i = 0; i < len; i++) {
079: lNodes[i] = new SRAPNode(nodeList.item(i));
080: }
081: }
082: return lNodes;
083: }//selectNodes()
084:
085: protected void createCommentNode() {
086: Node comment = destDocument.createComment(getDocComment());
087: destDocument.appendChild(comment);
088: }
089:
090: protected String getDocComment() {
091: return ("\n PROPRIETARY/CONFIDENTIAL/ Use of this product is subject\n"
092: + " to license terms. Copyright 2001 Sun Microsystems Inc.\n"
093: + " Some preexisting portions Copyright 2001 Netscape\n"
094: + " Communications Corp. All rights reserved.\n");
095: }
096:
097: protected void createDocTypeNode() {
098: DOMImplementation domImpl = destDocument.getImplementation();
099: Node doc = domImpl
100: .createDocumentType(
101: "ServicesConfiguration",
102: "=//iPlanet//Service Management Services (SMS) 1.0 DTD//EN",
103: "file:" + idsameBasedir + "/SUNWam/dtd/sms.dtd");
104: destDocument.appendChild(doc);
105: }
106:
107: protected Node createRootNode() {
108: return createRootNode("ServiceConfiguration");
109: }
110:
111: protected Node createRootNode(String nodename) {
112: Node root = (Node) destDocument.createElement(nodename);
113: destDocument.appendChild(root);
114: return root;
115: }
116:
117: protected Node createChildNode(String nodename, ArrayList attrList) {
118: Element node = destDocument.createElement(nodename);
119: if (attrList != null) {
120: int len = attrList.size();
121: for (int i = 0; i < len; i++) {
122: Attribute attr = (Attribute) attrList.get(i);
123: node.setAttribute(attr.getKey(), attr.getValue());
124: }
125: }
126: return (Node) node;
127: }
128:
129: protected Node createServiceNode(Node parent, ArrayList attribList) {
130: //Create child
131: Node Service = createChildNode("Service", attribList);
132: parent.appendChild(Service);
133: return Service;
134: }
135: }
|