package com.primaca.cs.osytem.xml;
import org.xml.sax.*;
import java.io.*;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;
import com.primaca.cs.osytem.common.*;
public class ParserDOM {
//Create an instance of Activation object to be available during XML processing, so the values can be set
Activation activation = new Activation();
private
String activity_id = "";
private final static String ORDER_HEADER = "primaca:orderHeader";
private final static String ORDER_ID ="primaca:orderHeaderOrderID";
private final static String CREATE_DATE ="primaca:orderHeaderCreateDate";
private final static String CUSTOMER_NAME= "primaca:orderHeaderCustomerName";
private final static String COMMENTS ="primaca:orderHeaderComments";
private final staticString MAJOR_ACCOUNT= "primaca:CorpInfoSWNumber";
private final static String LEVEL_NUMBER = "primaca:CorpInfoHierarchyLevel";
private final static String LEVEL_ID = "primaca:CorpInfoHierarchyLevel";
* ParserDOM constructor comment.
*/
public ParserDOM() {
super();
}
/**
* Insert the method's description here.
* Creation date: (6/10/2001 12:14:34 PM)
*/
public void buildRequest(Node node) throws CBSException {
String name = null;
switch (node.getNodeType())
{
case Node.DOCUMENT_NODE :
// recurse on first child after the root of the Document
NodeList nodes = node.getChildNodes();
if (nodes != null)
{
for (int i = 0; i < nodes.getLength(); i++)
{
buildRequest(nodes.item(i));
}
}
break;
case Node.ELEMENT_NODE :
int length = (node.getAttributes() != null) ?
node.getAttributes().getLength() : 0;
//System.out.println("*************length of Attributes******" + length);
Attr attributes[] = new Attr[length];
for (int loopIndex = 0; loopIndex < length; loopIndex++) {
attributes[loopIndex] =
(Attr)node.getAttributes().item(loopIndex);
String n = attributes[loopIndex].getName();
//System.out.println("***********value of n*************" + n + "********************");
if (n.equals("Level")){
//getting the next attribute value from the primaca:CorpInfoSWNumber ELEMENT NODE
attributes[1] = (Attr)node.getAttributes().item(1);
String m = attributes[1].getName();
String u = attributes[1].getValue();
//System.out.println("***************value of u*******" + u + "***************");
String v = attributes[loopIndex].getValue();
name = node.getNodeName();
if (v.equals("1")) {
activation.setClient_level1desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setLevel_id(levelvalue);
}
}
else if (v.equals("2")) {
activation.setClient_level2desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setLevel_id(levelvalue);
}
}
else if (v.equals("3")) {
activation.setClient_level3desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setCharge_code(levelvalue);
}
}
else if (v.equals("4")) {
activation.setClient_level4desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setLocation_id(levelvalue);
}
}
else if (v.equals("5")) {
activation.setClient_level5desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setLevel_five(levelvalue);
}
}
else if (v.equals("6")) {
activation.setClient_level6desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setLevel_six(levelvalue);
}
}
else if (v.equals("7")) {
activation.setClient_level7desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setLevel_seven(levelvalue);
}
}
else if (v.equals("8")) {
activation.setClient_level8desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setLevel_eight(levelvalue);
}
}
else if (v.equals("9")) {
activation.setClient_level9desc(u);
if (name.equals("primaca:CorpInfoHierarchyLevel")) {
String levelvalue = node.getNodeValue();
System.out.println("****goldcbslevelvalue" + levelvalue + "**********");
activation.setLevel_nine(levelvalue);
}
}
}
else if (n.equals("requestType")|| n.equals("requesttype")) {
String v = attributes[loopIndex].getValue();
if (v.equals("Activation")||v.equals("Transfer of Liability")||
v.equals("Activation - Add to Existing Account")||
v.equals("Switch from Existing Carrier")) {
System.out.println("This an Activation request");
activity_id = "01";
}
else if (v.equals("Deactivation")) {
System.out.println("This a Disconnect request");
activity_id = "03";
}
else if (v.equals("Hardware Purchase")||
v.equals("Hardware Upgrade")||v.equals("Accessory Only")||
v.equals("Existing Equipment Upgrade")||v.equals("New Equipment Upgrade")) {
System.out.println("This an Equipment request");
activity_id = "11";
}
else if (v.equals("Suspension")) {
System.out.println("This a Suspension request");
activity_id = "05";
}
else if (v.equals("Rate Plan Change")) {
System.out.println("This a Rate Plan Change request");
activity_id = "13";
}
else if (v.equals("User Information Change")) {
System.out.println("This a Name Change request");
activity_id = "10";
}
else {
System.out.println("This an Unknown request");
activity_id = "00";
}
}
}
/*
Switch from Existing Carrier
Add Discount*/
name = node.getNodeName();
System.out.println("********************" + name + "***********************");
// recurse on each grandchild of the root of the Document
NodeList children = node.getChildNodes();
if (children != null)
{
for (int i = 0; i < children.getLength(); i++)
{
buildRequest(children.item(i));
}
}
break;
case Node.TEXT_NODE :
//Sets the object to be returned with the value of the grandchild node
//createSARObject(node);
//System.out.println("*************node**********" + node);
createOrderObject(node);
break;
case Node.CDATA_SECTION_NODE :
break;
case Node.PROCESSING_INSTRUCTION_NODE :
break;
case Node.ENTITY_REFERENCE_NODE :
break;
}
}
private void createOrderObject(Node node) throws CBSException
{
System.out.println("Start createOrderObject");
activation.setActivity_id(activity_id);
if (node.getParentNode().getNodeName().equals(ORDER_ID)){
activation.setCaller_name(node.getNodeValue());
activation.set_order_id(node.getNodeValue());
System.out.println("Order Id/Caller Name " + activation.getCaller_name());
activation.set_order_id(node.getNodeValue());
}
//Open Date
if (node.getParentNode().getNodeName().equals(CREATE_DATE)) {
activation.setOpen_date(node.getNodeValue());
System.out.println("Open Date " + activation.getOpen_date());
}
if (node.getParentNode().getNodeName().equals(MAJOR_ACCOUNT)) {
activation.setClient_id(node.getNodeValue());
System.out.println("********MAJOR ACCOUNT NUM******************" + activation.getClient_id());
}
if (node.getParentNode().getNodeName().equals(COMMENTS))
{
if (node.getParentNode().getParentNode().getNodeName().equals(ORDER_HEADER));
activation.setSpecial_instructions(node.getNodeValue());
System.out.println("Special Instructions " + activation.getSpecial_instructions());
}
}
System.out.println("End createOrderObject");
}
/**
* Code to perform when this object is garbage collected.
*
* Any exception thrown by a finalize method causes the finalization to
* halt. But otherwise, it is ignored.
*/
protected void finalize() throws Throwable {
.
super.finalize();
}
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args) {
// Insert code to start the application here.
try {
DOMParser parser = new DOMParser();
parser.parse(args[0]);
Document document = parser.getDocument();
ParserDOM goldparserdom = new ParserDOM();
goldparserdom.buildRequest(document);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
/**
* Insert the method's description here.
* Creation date: (6/10/2001 12:14:34 PM)
*/
public Activation returnActivationObject() {
return activation;
}
public ServiceOrder xmlString(String xmlString) throws CBSException
{
DOMParser parser = new DOMParser();
Document myDoc = null;
try {
//add for read xml string directly
StringReader myReader = new StringReader(xmlString);
InputSource myInputSource = new InputSource(myReader);
parser.parse(myInputSource);
myDoc = parser.getDocument();
buildRequest(myDoc);
} catch (IOException e) {
System.out.println("Error reading Input String: " + e.getMessage());
} catch (SAXException e) {
System.out.println("Error during compass XML parsing of Order: " + e.getMessage());
}
return activation;
}
}
[Map tried to add code tags, but it only became worse]
[ September 06, 2002: Message edited by: Mapraputa Is ]