i am newbie in java...
keep in mind that every method is non-static.
all variables are also non-static.
here is my three classes....
My Aim --- to call toDom() from InvoiceNotes class to
addDocument() of InvoiceNotesController
1)
public class InvoiceNotesController {
public static void main(String args[]){
InvoiceNotesController inc = new InvoiceNotesController();
inc.init("a.xml");
}
private void init(String inFile){
try{
InvoiceNotesHandler handler = new InvoiceNotesHandler();
parseXmlFile(inFile, handler, false);
addDocument("aXmlId");
}catch (Exception e) {
e.printStackTrace();
}
}
public void parseXmlFile(String filename, DefaultHandler handler, boolean validating){
----------> Some parse code here <-----------------------------
}
public void addDocument(String xmlFileId) throws Exception {
Collection col = null;
String id;
************************************************************************************************************************************
How i call toDom() method from InvoiceNotes Class without creating new Instance of InvoiceNotes.....
Also all methods are instance Method and all variables are instance variables....Not used static any way ----
***********************************************************************************************************************************
try {
col = XmlDbManager.getCollectionInstance("aaa",4444,"ots","username","xxxx");
=========> Node finaldoc = (Node)toDom(); <=========
XMLResource document = (XMLResource)col.createResource(xmlFileId,"XMLResource");
document.setContentAsDOM(finaldoc);
col.storeResource(document);
String target = col.createId();
System.out.println("Document inserted with Id - " + xmlFileId);
}catch(XMLDBException e) {
System.err.println("XMLB Exception occured " + e.errorCode);
e.printStackTrace();
}catch(CouldNotConnectToXmlDbException ce) {
System.err.println("Could Not connect to XmlDb");
ce.printStackTrace();
}finally {
if (col != null) {
col.close();
}
}
}
2) Here InvoiceNotesHandler class.......
public class InvoiceNotesHandler extends DefaultHandler {
private String currentQname = null;
private StringBuffer thisText = new StringBuffer();
private String clientName = null;
private String dateString ;
private String descriptionString ;
private String minutesString ;
private float hours ;
private Date date ;
************ ***********
InvoiceNotes in = new InvoiceNotes();
*********** **********
public void startDocument() {
}
public void endDocument() {
}
public void startElement(String uri,
String localname,
String qname,
Attributes attributes)
throws SAXException {
if(qname.equals("CLIENT")) {
clientName = attributes.getValue(0);
in.chkContainsKey(clientName);
}
currentQname = qname;
}
public void endElement(String uri,
String localname,
String qname)
throws SAXException {
if(qname.equals("DATE")){
dateString = thisText.toString();
SimpleDateFormat sdf = new SimpleDateFormat("MMddyy");
try {
date = sdf.parse(dateString);
}catch(Exception e){
e.printStackTrace ();
}
}else if(qname.equals("DESCRIPTION")){
descriptionString = thisText.toString();
}else if(qname.equals("MINUTES")){
minutesString = thisText.toString();
hours = new Float(minutesString).floatValue();
}else if(qname.equals("REC")){
Record record = new Record(date, descriptionString, hours);
in.addRecord(record);
}else if(qname.equals("CLIENT")){
in.putMap(clientName);
}
}
}
3) here invoicenotes class.....
public class InvoiceNotes {
SortedLinkedList linkedRecordList = null;
TreeMap clientHistory = new TreeMap( new StringComparatorIgnoreCase( ) );
Document doc = null; // output DOM document
public void chkContainsKey(String clientName){
linkedRecordList = new SortedLinkedList();
if (clientHistory.containsKey(clientName)){
//--Here i am creating new SortedLinkedList and
// add each record to linkedRecordList
linkedRecordList = (SortedLinkedList)clientHistory.get(clientName);
}
}
public void addRecord(Record record){
linkedRecordList.add(record);
}
public void putMap(String clientName){
clientHistory.put(clientName,linkedRecordList);
}
public Document toDom(){
-----------> code for retrieve from treemap and create DOM document <-----------------------
doc.appendChild(documentElement);
return doc;
}
}
***** end ****
pl. give me the solution...
Thanks in advanced..
your help is appriciated.....
ketan
keep in mind that every method is non-static.
all variables are also non-static.
here is my three classes....
My Aim --- to call toDom() from InvoiceNotes class to
addDocument() of InvoiceNotesController
1)
public class InvoiceNotesController {
public static void main(String args[]){
InvoiceNotesController inc = new InvoiceNotesController();
inc.init("a.xml");
}
private void init(String inFile){
try{
InvoiceNotesHandler handler = new InvoiceNotesHandler();
parseXmlFile(inFile, handler, false);
addDocument("aXmlId");
}catch (Exception e) {
e.printStackTrace();
}
}
public void parseXmlFile(String filename, DefaultHandler handler, boolean validating){
----------> Some parse code here <-----------------------------
}
public void addDocument(String xmlFileId) throws Exception {
Collection col = null;
String id;
************************************************************************************************************************************
How i call toDom() method from InvoiceNotes Class without creating new Instance of InvoiceNotes.....
Also all methods are instance Method and all variables are instance variables....Not used static any way ----
***********************************************************************************************************************************
try {
col = XmlDbManager.getCollectionInstance("aaa",4444,"ots","username","xxxx");
=========> Node finaldoc = (Node)toDom(); <=========
XMLResource document = (XMLResource)col.createResource(xmlFileId,"XMLResource");
document.setContentAsDOM(finaldoc);
col.storeResource(document);
String target = col.createId();
System.out.println("Document inserted with Id - " + xmlFileId);
}catch(XMLDBException e) {
System.err.println("XMLB Exception occured " + e.errorCode);
e.printStackTrace();
}catch(CouldNotConnectToXmlDbException ce) {
System.err.println("Could Not connect to XmlDb");
ce.printStackTrace();
}finally {
if (col != null) {
col.close();
}
}
}
2) Here InvoiceNotesHandler class.......
public class InvoiceNotesHandler extends DefaultHandler {
private String currentQname = null;
private StringBuffer thisText = new StringBuffer();
private String clientName = null;
private String dateString ;
private String descriptionString ;
private String minutesString ;
private float hours ;
private Date date ;
************ ***********
InvoiceNotes in = new InvoiceNotes();
*********** **********
public void startDocument() {
}
public void endDocument() {
}
public void startElement(String uri,
String localname,
String qname,
Attributes attributes)
throws SAXException {
if(qname.equals("CLIENT")) {
clientName = attributes.getValue(0);
in.chkContainsKey(clientName);
}
currentQname = qname;
}
public void endElement(String uri,
String localname,
String qname)
throws SAXException {
if(qname.equals("DATE")){
dateString = thisText.toString();
SimpleDateFormat sdf = new SimpleDateFormat("MMddyy");
try {
date = sdf.parse(dateString);
}catch(Exception e){
e.printStackTrace ();
}
}else if(qname.equals("DESCRIPTION")){
descriptionString = thisText.toString();
}else if(qname.equals("MINUTES")){
minutesString = thisText.toString();
hours = new Float(minutesString).floatValue();
}else if(qname.equals("REC")){
Record record = new Record(date, descriptionString, hours);
in.addRecord(record);
}else if(qname.equals("CLIENT")){
in.putMap(clientName);
}
}
}
3) here invoicenotes class.....
public class InvoiceNotes {
SortedLinkedList linkedRecordList = null;
TreeMap clientHistory = new TreeMap( new StringComparatorIgnoreCase( ) );
Document doc = null; // output DOM document
public void chkContainsKey(String clientName){
linkedRecordList = new SortedLinkedList();
if (clientHistory.containsKey(clientName)){
//--Here i am creating new SortedLinkedList and
// add each record to linkedRecordList
linkedRecordList = (SortedLinkedList)clientHistory.get(clientName);
}
}
public void addRecord(Record record){
linkedRecordList.add(record);
}
public void putMap(String clientName){
clientHistory.put(clientName,linkedRecordList);
}
public Document toDom(){
-----------> code for retrieve from treemap and create DOM document <-----------------------
doc.appendChild(documentElement);
return doc;
}
}
***** end ****
pl. give me the solution...
Thanks in advanced..
your help is appriciated.....
ketan