001: package org.objectweb.speedo.generation.parser.ejb;
002:
003: import org.objectweb.speedo.api.SpeedoException;
004: import org.objectweb.speedo.generation.api.SpeedoXMLError;
005: import org.objectweb.speedo.generation.parser.AbstractParser;
006: import org.objectweb.speedo.lib.Personality;
007: import org.objectweb.speedo.locale.LocaleHelper;
008: import org.objectweb.speedo.metadata.SpeedoClass;
009: import org.objectweb.speedo.metadata.SpeedoPackage;
010: import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
011: import org.objectweb.util.monolog.api.BasicLevel;
012: import org.w3c.dom.Node;
013: import org.w3c.dom.NodeList;
014:
015: public class EJBPersistenceParser extends AbstractParser {
016:
017: public EJBPersistenceParser() {
018: super (Personality.EJB);
019: }
020:
021: public String getTitle() {
022: return LocaleHelper.getEJBParsingRB().getString("ejbperspar");
023: }
024:
025: protected String getLoggerName() {
026: return "ejb";
027: }
028:
029: protected Object treatDocument(Node node, Object o)
030: throws SpeedoException {
031: //o is the descriptor of the root node
032: o = treatNode(node, o);
033: //list of child node
034: NodeList children = node.getChildNodes();
035: //if the node has a child
036: if (children != null) {
037: //for each child
038: for (int i = 0; i < children.getLength(); i++) {
039: //create a descriptor for the child
040: Object fils = treatDocument(children.item(i), o);
041: }
042: }
043: return o;
044: }
045:
046: // PRIVATE METHODS //
047: //-----------------//
048:
049: /**
050: * This methods creates the object descriptor for describing a tag of the
051: * XML file.
052: * It returns the descriptor for the root tag.
053: * It throws an exception if an attribute is missing.
054: * @param node node which will be described.
055: * @param o default descriptor to return.
056: * @return node descriptor.
057: * @exception SpeedoException if a compulsory attribute is missing for
058: * the current tag.
059: */
060: private Object treatNode(Node node, Object o)
061: throws SpeedoException {
062: // type of node
063: int type = node.getNodeType();
064: if (type != Node.ELEMENT_NODE)
065: return o;
066: //tag name
067: String tag = node.getNodeName();
068: logger.log(BasicLevel.DEBUG, "Parse tag: " + tag);
069: if (tag.equals("entity-manager")) { //tag entity-manager
070: //root: nothing to do
071: } else if (tag.equals("name")) { //tag name
072: } else if (tag.equals("provider")) { //tag provider
073: } else if (tag.equals("jta-data-source")) { //tag jta-data-source
074: } else if (tag.equals("non-jta-data-source")) { //tag non-jta-data-source
075: } else if (tag.equals("mapping-file")) { //tag mapping-file
076: } else if (tag.equals("jar-file")) { //tag jar-file
077: } else if (tag.equals("class")) { //tag class
078: String fullcn = node.getFirstChild().getNodeValue();
079: String pac = fullcn.substring(0, fullcn.lastIndexOf('.'));
080: String cn = fullcn.substring(fullcn.lastIndexOf('.') + 1,
081: fullcn.length());
082: SpeedoPackage sp = (SpeedoPackage) ((SpeedoXMLDescriptor) o).packages
083: .get(pac);
084: if (sp == null) {
085: sp = new SpeedoPackage();
086: sp.name = pac;
087: sp.xmlDescriptor = (SpeedoXMLDescriptor) o;
088: ((SpeedoXMLDescriptor) o).packages.put(pac, sp);
089: logger.log(BasicLevel.DEBUG, "New package: name= "
090: + pac);
091: }
092: SpeedoClass sc = new SpeedoClass();
093: sc.name = sc.nameForQuery = cn;
094: sc.moPackage = sp;
095: sp.classes.put(cn, sc);
096: logger.log(BasicLevel.DEBUG, "New class: name= " + cn
097: + " in the package=" + pac);
098: treatClassNode(sc);
099: } else if (tag.equals("properties")) { //tag properties
100: } else if (tag.equals("property")) { //tag property
101: Node n, v;
102: n = node.getAttributes().getNamedItem("name");
103: v = node.getAttributes().getNamedItem("value");
104: if ((n == null) || (v == null)) {
105: throw new SpeedoXMLError(
106: "Attribute name or value for tag property requested.");
107: }
108: n.getNodeValue();
109: v.getNodeValue();
110: }
111: return o;
112: }
113:
114: private Object treatClassNode(SpeedoClass node)
115: throws SpeedoException {
116: return node;
117: }
118: }
|