package org.objectweb.speedo.generation.parser.ejb;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.speedo.generation.api.SpeedoXMLError;
import org.objectweb.speedo.generation.parser.AbstractParser;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.locale.LocaleHelper;
import org.objectweb.speedo.metadata.SpeedoClass;
import org.objectweb.speedo.metadata.SpeedoPackage;
import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
import org.objectweb.util.monolog.api.BasicLevel;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class EJBPersistenceParser
extends AbstractParser {
public EJBPersistenceParser() {
super(Personality.EJB);
}
public String getTitle() {
return LocaleHelper.getEJBParsingRB().getString("ejbperspar");
}
protected String getLoggerName() {
return "ejb";
}
protected Object treatDocument(Node node, Object o) throws SpeedoException {
//o is the descriptor of the root node
o = treatNode(node, o);
//list of child node
NodeList children = node.getChildNodes();
//if the node has a child
if (children != null) {
//for each child
for (int i = 0; i < children.getLength(); i++) {
//create a descriptor for the child
Object fils = treatDocument(children.item(i), o);
}
}
return o;
}
// PRIVATE METHODS //
//-----------------//
/**
* This methods creates the object descriptor for describing a tag of the
* XML file.
* It returns the descriptor for the root tag.
* It throws an exception if an attribute is missing.
* @param node node which will be described.
* @param o default descriptor to return.
* @return node descriptor.
* @exception SpeedoException if a compulsory attribute is missing for
* the current tag.
*/
private Object treatNode(Node node, Object o) throws SpeedoException {
// type of node
int type = node.getNodeType();
if (type != Node.ELEMENT_NODE)
return o;
//tag name
String tag = node.getNodeName();
logger.log(BasicLevel.DEBUG, "Parse tag: " + tag);
if (tag.equals("entity-manager")) { //tag entity-manager
//root: nothing to do
} else if (tag.equals("name")) { //tag name
} else if (tag.equals("provider")) { //tag provider
} else if (tag.equals("jta-data-source")) { //tag jta-data-source
} else if (tag.equals("non-jta-data-source")) { //tag non-jta-data-source
} else if (tag.equals("mapping-file")) { //tag mapping-file
} else if (tag.equals("jar-file")) { //tag jar-file
} else if (tag.equals("class")) { //tag class
String fullcn = node.getFirstChild().getNodeValue();
String pac = fullcn.substring(0, fullcn.lastIndexOf('.'));
String cn = fullcn.substring(fullcn.lastIndexOf('.') + 1,
fullcn.length());
SpeedoPackage sp = (SpeedoPackage) ((SpeedoXMLDescriptor) o).packages.get(pac);
if (sp == null) {
sp = new SpeedoPackage();
sp.name = pac;
sp.xmlDescriptor = (SpeedoXMLDescriptor) o;
((SpeedoXMLDescriptor) o).packages.put(pac, sp);
logger.log(BasicLevel.DEBUG, "New package: name= " + pac);
}
SpeedoClass sc = new SpeedoClass();
sc.name = sc.nameForQuery = cn;
sc.moPackage = sp;
sp.classes.put(cn, sc);
logger.log(BasicLevel.DEBUG, "New class: name= " + cn + " in the package=" + pac);
treatClassNode(sc);
} else if (tag.equals("properties")) { //tag properties
} else if (tag.equals("property")) { //tag property
Node n, v;
n = node.getAttributes().getNamedItem("name");
v = node.getAttributes().getNamedItem("value");
if ((n == null) || (v == null)) {
throw new SpeedoXMLError("Attribute name or value for tag property requested.");
}
n.getNodeValue();
v.getNodeValue();
}
return o;
}
private Object treatClassNode(SpeedoClass node) throws SpeedoException {
return node;
}
}