Here is my problem.

1.  When I try to import xerces.jar into VisualAge, import just stops in
between, it wont import all the classes, also whatever is imported into VA I
can just see the name of the packages I    cannot expand them and cannot see
anything with in.

2. Then I tried to import the source, which I am able to import properly,
then I imported xalan becouse I have to use XPATHapi etc.  this is fine as
well.
    I have created a class for xml messaging purposes (show below) which
import many of the package from these products.  So far So good, In my class
I am reading xml file and then using
        
        // strRequest is my xml message    
         StringReader sr = new StringReader(strRequest);
         InputSource in = new InputSource(sr); 

        but right at the second line above VA Debugger comes up and
complaines that noclassdefinationfound for InputSource, but InputSource
class in present in org.xml.sax package.

3.   So I decide to export all my classes any complie under dos prompt,
using javac and suprise I am able to run it and getting the response back.
I am so confused.

My source code


import java.io.*;
import java.util.*;

import org.apache.xerces.parsers.*;

import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xml.serialize.*;


import org.apache.xpath.*;

public class BrokerEngine { 
        private static BrokerEngine instance = null; 
        private Map serviceMap; 

        private BrokerEngine() { 
          serviceMap = new HashMap(); 
          serviceMap.put("saveInvoice", new SaveInvoiceInvoker()); 
        }
        public static synchronized BrokerEngine getInstance() 
        { 
          if(instance == null) 
                   instance = new BrokerEngine(); 
                return instance; 
        }
   private Document invoke(Document doc) { 
          String type = null; 
          try { 
                   Node node = XPathAPI.selectSingleNode(doc,
"/message/header/type/text()"); 
                   type = node.getNodeValue(); 
          } 
          catch (Exception e) { 
                 e.printStackTrace(); 
          } 
          Invoker invoker = (Invoker) serviceMap.get(type); 
          Document response = invoker.invoke(doc); 

          return response;

   }                  
   //test case 
        public static void main (String[] args) { 
          if (args.length < 1) { 
                 System.out.println("Usage: BrokerEngine <message>"); 
                 System.exit(-1); 
          } 

          StringBuffer sb = new StringBuffer(); 
          try { 
                 RandomAccessFile randFile = new RandomAccessFile(args[0],
"r"); 
                 String line = randFile.readLine(); 
                 while (line != null) { 
                        sb.append(line); 
                        line = randFile.readLine(); 
                 } 
                 randFile.close(); 
          } 
          catch (Exception e) { 
                 e.printStackTrace(); 
          } 

          BrokerEngine brokerEngine = BrokerEngine.getInstance(); 
          System.out.println("result: \n" +
brokerEngine.serviceSync(sb.toString())); 
   }      
        public void serviceAsync (String request) { 
          InputSource in = new InputSource(new StringReader(request)); 
          DOMParser parser = new DOMParser(); 
          try { 
                 parser.parse(in); 
          } 
          catch (Exception e) { 
                 e.printStackTrace(); 
          } 

          Document doc = parser.getDocument(); 

          //invoke a method/procedure 
          invoke(doc); 
   }      
        public String serviceSync (String strRequest) {

          StringReader sr = new StringReader(strRequest);
          System.out.println("Entering Danger Jone");
          
        
          InputSource in = new InputSource(sr); 
          DOMParser parser = new DOMParser(); 
          try { 
                 parser.parse(in); 
          } 
          catch (Exception e) { 
                 e.printStackTrace(); 
          } 
          Document request = parser.getDocument(); 

          //invoke a method/procedure 
          Document response = invoke(request); 

          StringWriter strResponse = null; 
          try { 
                 OutputFormat format = new OutputFormat(response); 
                 strResponse = new StringWriter(); 
                 XMLSerializer serial = new XMLSerializer( strResponse,
format ); 
                 serial.asDOMSerializer(); 
                 serial.serialize(response.getDocumentElement()); 
          } 
          catch (Exception e) { 
                 e.printStackTrace(); 
          } 
          return strResponse.toString(); 
   }                                 
}



public interface Invoker {
        Document invoke (Document doc);
}

import java.io.*;
import org.apache.xerces.dom.*;
import org.apache.xml.serialize.*;
import org.w3c.dom.*;
/**
 * Insert the type's description here.
 * Creation date: (3/8/2001 10:41:56 AM)
 * @author: Administrator
 */
public class MessageFactory {
/**
 * MessageFactory constructor comment.
 */
public MessageFactory() {
        super();
}
/**
 * Insert the method's description here.
 * Creation date: (3/8/2001 11:01:05 AM)
 * @return org.w3c.dom.Document
 * @param strTo java.lang.String
 * @param strFrom java.lang.String
 * @param strType java.lang.String
 * @param strResult java.lang.String
 */
public Document createReturnMessage(String strTo, String strFrom, String
strType, String strResult) {

        
        Document doc = new DocumentImpl();
        Element message = doc.createElement("message");
        Element header  = doc.createElement("header");

        Element to = doc.createElement("to");
        header.appendChild(to);
        to.appendChild(doc.createTextNode(strTo));
        
        Element from = doc.createElement("from");
        header.appendChild(from);
        from.appendChild(doc.createTextNode(strFrom));

        Element type = doc.createElement("type");
        header.appendChild(type);
        type.appendChild(doc.createTextNode(strType));

        message.appendChild(header);

        Element body = doc.createElement("body");

        Element result  = doc.createElement("result");
        body.appendChild(result);
        result.appendChild(doc.createTextNode(strResult));

        message.appendChild(body);

        doc.appendChild(message);
        
        
        return doc;
}
}


import java.io.*;
import org.apache.xpath.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xml.serialize.*;

public class SaveInvoiceInvoker implements Invoker {
/**
 * SaveInvoiceInvoker constructor comment.
 */
public SaveInvoiceInvoker() {
        super();
}
/**
 * Insert the method's description here.
 * Creation date: (3/8/2001 10:15:41 AM)
 * @return org.w3c.dom.Document
 * @param doc org.w3c.dom.Document
 */
public Document invoke(Document doc) {

        String strTo = null, strFrom = null, strType = null;
        
        MessageFactory mf = new MessageFactory();
        
        try {



                Node toNode =
XPathAPI.selectSingleNode(doc,"/message/header/to/text()");
                strTo = toNode.getNodeValue();

                Node fromNode =
XPathAPI.selectSingleNode(doc,"/message/header/from/text()");
                strFrom         = fromNode.getNodeValue();

                Node typeNode =
XPathAPI.selectSingleNode(doc,"/message/header/type/text()");
                strType         =       typeNode.getNodeValue();

                Node numberNode =
XPathAPI.selectSingleNode(doc,"/message/body/saveInvoice/invoice/@number");
                String  invoiceNumber = numberNode.getNodeValue();

                Node invoiceNode =
XPathAPI.selectSingleNode(doc,"/message/body/saveInvoice/invoice");

                OutputFormat format = new OutputFormat(doc);

                StringWriter strInvoice = new StringWriter();
                XMLSerializer serial = new XMLSerializer
(strInvoice,format);
                serial.asDOMSerializer();
                serial.serialize((Element) invoiceNode);

                String filename = invoiceNumber + ".xml";
                File file = new File(filename);

                if (!file.exists()) {
                        RandomAccessFile randFile = new
RandomAccessFile(file,"rw");
                        randFile.writeBytes(strInvoice.toString());
                        randFile.close();
                }
                
                
        
        }
        catch (Exception e) {
                e.printStackTrace();
                return mf.createReturnMessage(strFrom,strTo,strType,"Error
Processing");
        }
                return
mf.createReturnMessage(strFrom,strTo,strType,"Success");
        

}
}

<?xml version="1.0" ?> 
- <message>
- <header>
  <to>companyReceiver</to> 
  <from>companySender</from> 
  <type>saveInvoice</type> 
  </header>
- <body>
- <saveInvoice>
- <invoice date="01-20-2000" number="123">
- <address country="US">
  <name>John Smith</name> 
  <street>123 George St.</street> 
  <city>Mountain View</city> 
  <state>CA</state> 
  <zip>94041</zip> 
  </address>
- <billTo country="US">
  <name>Company A</name> 
  <street>100 Main St.</street> 
  <city>Washington</city> 
  <state>DC</state> 
  <zip>20015</zip> 
  </billTo>
- <items>
- <item number="1">
  <name>IBM A20 Laptop</name> 
  <quantity>1</quantity> 
  <USPrice>2000.00</USPrice> 
  </item>
  </items>
  </invoice>
  </saveInvoice>
  </body>
  </message>


Thanks
Munish Talwar
Tel:(514)866-0001 ext.:4319
[EMAIL PROTECTED]


-----Original Message-----
From: Steve Graham [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 08, 2001 4:05 PM
To: [email protected]
Subject: Re: Xerces in Visualage


Munish:
Yes, I use Xerces in VisualAge 3.5.

What problems are you seeing when you try to import Xerces 1.3.0?

++++++++
Steve Graham
[EMAIL PROTECTED]
(919)254-0615 (T/L 444)
Web Services Architect
Emerging Internet Technologies
++++++++


Munish Talwar <[EMAIL PROTECTED]> on 03/08/2001 03:05:21 PM

Please respond to [email protected]

To:   "'[email protected]'" <[email protected]>
cc:
Subject:  Xerces in Visualage






Hi,

Can anybody help me setting up my Visual age environment. I am using Visual
Age 3.5. I am not able to import Xerces 1.3.0 at all I have tried so many
times.  Is their anybody using xerces in visualage

thanks in advance

MT

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to