Fields Summary |
---|
private static final int | DEFAULT_HASH_TABLE_SIZE |
private static final int | STATE_LOOKING_EJBJAR |
private static final int | STATE_IN_EJBJAR |
private static final int | STATE_IN_BEANS |
private static final int | STATE_IN_SESSION |
private static final int | STATE_IN_ENTITY |
private static final int | STATE_IN_MESSAGE |
private org.apache.tools.ant.Task | owningTask |
private String | publicId |
private static final String | EJB_REFBunch of constants used for storing entries in a hashtable, and for
constructing the filenames of various parts of the ejb jar. |
private static final String | EJB_LOCAL_REF |
private static final String | HOME_INTERFACE |
private static final String | REMOTE_INTERFACE |
private static final String | LOCAL_HOME_INTERFACE |
private static final String | LOCAL_INTERFACE |
private static final String | BEAN_CLASS |
private static final String | PK_CLASS |
private static final String | EJB_NAME |
private static final String | EJB_JAR |
private static final String | ENTERPRISE_BEANS |
private static final String | ENTITY_BEAN |
private static final String | SESSION_BEAN |
private static final String | MESSAGE_BEAN |
private int | parseStateThe state of the parsing |
protected String | currentElementInstance variable used to store the name of the current element being
processed by the SAX parser. Accessed by the SAX parser call-back methods
startElement() and endElement(). |
protected String | currentTextThe text of the current element |
protected Hashtable | ejbFilesInstance variable that stores the names of the files as they will be
put into the jar file, mapped to File objects Accessed by the SAX
parser call-back method characters(). |
protected String | ejbNameInstance variable that stores the value found in the <ejb-name> element |
private Hashtable | fileDTDs |
private Hashtable | resourceDTDs |
private boolean | inEJBRef |
private Hashtable | urlDTDs |
private File | srcDirThe directory containing the bean classes and interfaces. This is
used for performing dependency file lookups. |
Methods Summary |
---|
public void | characters(char[] ch, int start, int length)SAX parser call-back method invoked whenever characters are located within
an element. currentAttribute (modified by startElement and endElement)
tells us whether we are in an interesting element (one of the up to four
classes of an EJB). If so then converts the classname from the format
org.apache.tools.ant.Parser to the convention for storing such a class,
org/apache/tools/ant/Parser.class. This is then resolved into a file
object under the srcdir which is stored in a Hashtable.
currentText += new String(ch, start, length);
|
public void | endElement(java.lang.String name)SAX parser call-back method that is invoked when an element is exited.
Used to blank out (set to the empty string, not nullify) the name of
the currentAttribute. A better method would be to use a stack as an
instance variable, however since we are only interested in leaf-node
data this is a simpler and workable solution.
processElement();
currentText = "";
this.currentElement = "";
if (name.equals(EJB_REF) || name.equals(EJB_LOCAL_REF)) {
inEJBRef = false;
} else if (parseState == STATE_IN_ENTITY && name.equals(ENTITY_BEAN)) {
parseState = STATE_IN_BEANS;
} else if (parseState == STATE_IN_SESSION && name.equals(SESSION_BEAN)) {
parseState = STATE_IN_BEANS;
} else if (parseState == STATE_IN_MESSAGE && name.equals(MESSAGE_BEAN)) {
parseState = STATE_IN_BEANS;
} else if (parseState == STATE_IN_BEANS && name.equals(ENTERPRISE_BEANS)) {
parseState = STATE_IN_EJBJAR;
} else if (parseState == STATE_IN_EJBJAR && name.equals(EJB_JAR)) {
parseState = STATE_LOOKING_EJBJAR;
}
|
public java.lang.String | getEjbName()Getter method that returns the value of the <ejb-name> element.
return ejbName;
|
public java.util.Hashtable | getFiles()Getter method that returns the set of files to include in the EJB jar.
return (ejbFiles == null) ? new Hashtable() : ejbFiles;
|
public java.lang.String | getPublicId()Get the publicId of the DTD
return publicId;
|
protected void | processElement()Called when an endelement is seen.
This may be overridden in derived classes.
This updates the ejbfiles if the element is an interface or a bean class.
This updates the ejbname if the element is an ejb name.
if (inEJBRef
|| (parseState != STATE_IN_ENTITY
&& parseState != STATE_IN_SESSION
&& parseState != STATE_IN_MESSAGE)) {
return;
}
if (currentElement.equals(HOME_INTERFACE)
|| currentElement.equals(REMOTE_INTERFACE)
|| currentElement.equals(LOCAL_INTERFACE)
|| currentElement.equals(LOCAL_HOME_INTERFACE)
|| currentElement.equals(BEAN_CLASS)
|| currentElement.equals(PK_CLASS)) {
// Get the filename into a String object
File classFile = null;
String className = currentText.trim();
// If it's a primitive wrapper then we shouldn't try and put
// it into the jar, so ignore it.
if (!className.startsWith("java.")
&& !className.startsWith("javax.")) {
// Translate periods into path separators, add .class to the
// name, create the File object and add it to the Hashtable.
className = className.replace('.", File.separatorChar);
className += ".class";
classFile = new File(srcDir, className);
ejbFiles.put(className, classFile);
}
}
// Get the value of the <ejb-name> tag. Only the first occurrence.
if (currentElement.equals(EJB_NAME)) {
if (ejbName == null) {
ejbName = currentText.trim();
}
}
|
public void | registerDTD(java.lang.String publicId, java.lang.String location)Register a dtd with a location.
The location is one of a filename, a resource name in the classpath, or
a URL.
if (location == null) {
return;
}
File fileDTD = new File(location);
if (!fileDTD.exists()) {
// resolve relative to project basedir
fileDTD = owningTask.getProject().resolveFile(location);
}
if (fileDTD.exists()) {
if (publicId != null) {
fileDTDs.put(publicId, fileDTD);
owningTask.log("Mapped publicId " + publicId + " to file "
+ fileDTD, Project.MSG_VERBOSE);
}
return;
}
if (getClass().getResource(location) != null) {
if (publicId != null) {
resourceDTDs.put(publicId, location);
owningTask.log("Mapped publicId " + publicId + " to resource "
+ location, Project.MSG_VERBOSE);
}
}
try {
if (publicId != null) {
URL urldtd = new URL(location);
urlDTDs.put(publicId, urldtd);
}
} catch (java.net.MalformedURLException e) {
//ignored
}
|
public org.xml.sax.InputSource | resolveEntity(java.lang.String publicId, java.lang.String systemId)Resolve the entity.
this.publicId = publicId;
File dtdFile = (File) fileDTDs.get(publicId);
if (dtdFile != null) {
try {
owningTask.log("Resolved " + publicId + " to local file "
+ dtdFile, Project.MSG_VERBOSE);
return new InputSource(new FileInputStream(dtdFile));
} catch (FileNotFoundException ex) {
// ignore
}
}
String dtdResourceName = (String) resourceDTDs.get(publicId);
if (dtdResourceName != null) {
InputStream is = this.getClass().getResourceAsStream(dtdResourceName);
if (is != null) {
owningTask.log("Resolved " + publicId + " to local resource "
+ dtdResourceName, Project.MSG_VERBOSE);
return new InputSource(is);
}
}
URL dtdUrl = (URL) urlDTDs.get(publicId);
if (dtdUrl != null) {
try {
InputStream is = dtdUrl.openStream();
owningTask.log("Resolved " + publicId + " to url "
+ dtdUrl, Project.MSG_VERBOSE);
return new InputSource(is);
} catch (IOException ioe) {
//ignore
}
}
owningTask.log("Could not resolve ( publicId: " + publicId
+ ", systemId: " + systemId + ") to a local entity", Project.MSG_INFO);
return null;
|
public void | startDocument()SAX parser call-back method that is used to initialize the values of some
instance variables to ensure safe operation.
this.ejbFiles = new Hashtable(DEFAULT_HASH_TABLE_SIZE, 1);
this.currentElement = null;
inEJBRef = false;
|
public void | startElement(java.lang.String name, org.xml.sax.AttributeList attrs)SAX parser call-back method that is invoked when a new element is entered
into. Used to store the context (attribute name) in the currentAttribute
instance variable.
this.currentElement = name;
currentText = "";
if (name.equals(EJB_REF) || name.equals(EJB_LOCAL_REF)) {
inEJBRef = true;
} else if (parseState == STATE_LOOKING_EJBJAR && name.equals(EJB_JAR)) {
parseState = STATE_IN_EJBJAR;
} else if (parseState == STATE_IN_EJBJAR && name.equals(ENTERPRISE_BEANS)) {
parseState = STATE_IN_BEANS;
} else if (parseState == STATE_IN_BEANS && name.equals(SESSION_BEAN)) {
parseState = STATE_IN_SESSION;
} else if (parseState == STATE_IN_BEANS && name.equals(ENTITY_BEAN)) {
parseState = STATE_IN_ENTITY;
} else if (parseState == STATE_IN_BEANS && name.equals(MESSAGE_BEAN)) {
parseState = STATE_IN_MESSAGE;
}
|