Discussion:
[jade-develop] Error getting XML tags contents
alhusain taher
2014-08-17 23:01:02 UTC
Permalink
Hello,
I am facing a problem reading XML files, specifically when using the
getTextContent()
method.
and this is the code that I uses to read the file:



import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.w3c.dom.Node;
import org.w3c.dom.Element;

public class XMLTools_2 {
public static String GetValueFromXMLFile(String fileName, int taskNumber,
String rootTagName , String targetTagName ) {
String tagValue = null;
File fXmlFile = new File(fileName);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
try {
System.out.println("within GetValueFromXMLFile ");
dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList taskList = doc.getElementsByTagName(rootTagName);
for (int temp = 0; temp < taskList.getLength(); temp++) {
Node node = taskList.item(temp);
System.out.println("\n Element Name :" + node.getNodeName());
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
System.out.println("TaskType : "+
element.getElementsByTagName(targetTagName).item(0).getTextContent());
tagValue =
element.getElementsByTagName(targetTagName).item(0).getTextContent();
}

}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tagValue;
}

}

when I call this function from the JADE platform using eclipse i got
the following error:
java.lang.AbstractMethodError:
org.apache.crimson.tree.ElementNode.getTextContent()Ljava/lang/String;


Please note that when I call the same function from a simple program it
work fine.
actually the call is done from this class



import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.OneShotBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;

import java.util.Hashtable;

public class Designer extends Agent {
private boolean taskExist = true; // for future use
private String taskFileName= "d:\\task.txt";
// Put agent initializations here
protected void setup() {
// Register the designer service in the yellow pages
DFAgentDescription dfd = new DFAgentDescription();
dfd.setName(getAID());
ServiceDescription sd = new ServiceDescription();
sd.setType("Digging-Designer");
sd.setName("JADE-Digging-Monitoring");
dfd.addServices(sd);
try {
DFService.register(this, dfd);
}
catch (FIPAException fe) {
fe.printStackTrace();
}

// Add the behaviour serving task queries from coordinator agent
addBehaviour(new TaskServer());

// Add the behaviour serving notification from coordinator agent
addBehaviour(new NotificationServer());
}

// Put agent clean-up operations here
protected void takeDown() {
// Deregister from the yellow pages
try {
DFService.deregister(this);
}
catch (FIPAException fe) {
fe.printStackTrace();
}
// Printout a dismissal message
System.out.println("Designer "+getAID().getName()+" is terminating.");
}
/**
Inner class TaskServer.
This is the behaviour used designer agents to serve incoming task
requests from coordinator agent.
the designer replys by the task to performs
*/
private class TaskServer extends CyclicBehaviour {
public void action() {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CFP);
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
System.out.println("we got a request from the coordinator 1");
// CFP Message received. Process it
String requestContent = msg.getContent();
ACLMessage reply = msg.createReply();
if(taskExist){
reply.setPerformative(ACLMessage.PROPOSE);
String replyContent = null;
System.out.println("befote XMLTools_2 ");
replyContent = XMLTools_2.GetValueFromXMLFile("d:\\Jade\\JavaWS\\task.xml",
0, "task", "TaskNumber");
reply.setContent(replyContent);
}
else {
// The requested book is NOT available for sale.
reply.setPerformative(ACLMessage.REFUSE);
reply.setContent("not-available");
}
myAgent.send(reply);
System.out.println("A response is sent to the coordinator");
}
else {
block();
}
}
} // End of inner class OfferRequestsServer

/**
Inner class PurchaseOrdersServer.
This is the behaviour used by Book-seller agents to serve incoming
offer acceptances (i.e. purchase orders) from buyer agents.
The seller agent removes the purchased book from its catalogue
and replies with an INFORM message to notify the buyer that the
purchase has been sucesfully completed.
*/
private class NotificationServer extends CyclicBehaviour {
public void action() {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
// ACCEPT_PROPOSAL Message received. Process it
String messageContent = msg.getContent();
ACLMessage reply = msg.createReply();
reply.setPerformative(ACLMessage.AGREE);
reply.setContent("Updated");
myAgent.send(reply);
System.out.println("The designer gots the message:"+messageContent);
}
else {
block();
}
}
} // End of inner class NotificationServer
}


Best regards.
--
*Mr. Alhusain Taher*


* Montreal - Canada*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140817/25f55058/attachment-0001.html>
Caire Giovanni
2014-08-18 21:08:28 UTC
Permalink
Hi,

Such error typically occurs when you are mixing different versions of libraries. My suggestion is to double-check all the libraries you are using. Be sure you are using the latest versions and recompile the whole.

Bye,

Giovanni

Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di alhusain taher
Inviato: lunedì 18 agosto 2014 01:01
A: jade-develop at avalon.tilab.com
Oggetto: [jade-develop] Error getting XML tags contents


Hello,
I am facing a problem reading XML files, specifically when using the getTextContent() method.
and this is the code that I uses to read the file:



import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.w3c.dom.Node;
import org.w3c.dom.Element;

public class XMLTools_2 {
public static String GetValueFromXMLFile(String fileName, int taskNumber, String rootTagName , String targetTagName ) {
String tagValue = null;
File fXmlFile = new File(fileName);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
try {
System.out.println("within GetValueFromXMLFile ");
dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList taskList = doc.getElementsByTagName(rootTagName);
for (int temp = 0; temp < taskList.getLength(); temp++) {
Node node = taskList.item(temp);
System.out.println("\n Element Name :" + node.getNodeName());
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
System.out.println("TaskType : "+ element.getElementsByTagName(targetTagName).item(0).getTextContent());
tagValue = element.getElementsByTagName(targetTagName).item(0).getTextContent();
}

}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tagValue;
}

}

when I call this function from the JADE platform using eclipse i got the following error:
java.lang.AbstractMethodError: org.apache.crimson.tree.ElementNode.getTextContent()Ljava/lang/String;


Please note that when I call the same function from a simple program it work fine.
actually the call is done from this class



import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.OneShotBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;

import java.util.Hashtable;

public class Designer extends Agent {
private boolean taskExist = true; // for future use
private String taskFileName= "d:\\task.txt";
// Put agent initializations here
protected void setup() {
// Register the designer service in the yellow pages
DFAgentDescription dfd = new DFAgentDescription();
dfd.setName(getAID());
ServiceDescription sd = new ServiceDescription();
sd.setType("Digging-Designer");
sd.setName("JADE-Digging-Monitoring");
dfd.addServices(sd);
try {
DFService.register(this, dfd);
}
catch (FIPAException fe) {
fe.printStackTrace();
}

// Add the behaviour serving task queries from coordinator agent
addBehaviour(new TaskServer());

// Add the behaviour serving notification from coordinator agent
addBehaviour(new NotificationServer());
}

// Put agent clean-up operations here
protected void takeDown() {
// Deregister from the yellow pages
try {
DFService.deregister(this);
}
catch (FIPAException fe) {
fe.printStackTrace();
}
// Printout a dismissal message
System.out.println("Designer "+getAID().getName()+" is terminating.");
}
/**
Inner class TaskServer.
This is the behaviour used designer agents to serve incoming task requests from coordinator agent.
the designer replys by the task to performs
*/
private class TaskServer extends CyclicBehaviour {
public void action() {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CFP);
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
System.out.println("we got a request from the coordinator 1");
// CFP Message received. Process it
String requestContent = msg.getContent();
ACLMessage reply = msg.createReply();
if(taskExist){
reply.setPerformative(ACLMessage.PROPOSE);
String replyContent = null;
System.out.println("befote XMLTools_2 ");
replyContent = XMLTools_2.GetValueFromXMLFile("d:\\Jade\\JavaWS\\task.xml", 0, "task", "TaskNumber");
reply.setContent(replyContent);
}
else {
// The requested book is NOT available for sale.
reply.setPerformative(ACLMessage.REFUSE);
reply.setContent("not-available");
}
myAgent.send(reply);
System.out.println("A response is sent to the coordinator");
}
else {
block();
}
}
} // End of inner class OfferRequestsServer

/**
Inner class PurchaseOrdersServer.
This is the behaviour used by Book-seller agents to serve incoming
offer acceptances (i.e. purchase orders) from buyer agents.
The seller agent removes the purchased book from its catalogue
and replies with an INFORM message to notify the buyer that the
purchase has been sucesfully completed.
*/
private class NotificationServer extends CyclicBehaviour {
public void action() {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
// ACCEPT_PROPOSAL Message received. Process it
String messageContent = msg.getContent();
ACLMessage reply = msg.createReply();
reply.setPerformative(ACLMessage.AGREE);
reply.setContent("Updated");
myAgent.send(reply);
System.out.println("The designer gots the message:"+messageContent);
}
else {
block();
}
}
} // End of inner class NotificationServer
}


Best regards.

--
Mr. Alhusain Taher

Montreal - Canada


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140818/7c1c7342/attachment-0001.html>
Loading...