Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@jakarta.apache.org Received: (qmail 13299 invoked by uid 500); 16 Aug 2001 20:37:11 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: ant-dev@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 13281 invoked from network); 16 Aug 2001 20:37:11 -0000 From: "Josh Lannin" To: Subject: Another contributions- EJB related Date: Thu, 16 Aug 2001 14:36:09 -0600 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_000B_01C12660.CA029F90" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <01bd01c12683$b493c940$5614000a@GILAMONSTER> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_000B_01C12660.CA029F90 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Here is a new version of DescrptorHandler, this one includes message bean support and support for container manager persistence beans (CMP) with local interfaces. I posted a couple files a day or so ago but got no response from this list--- is someone taking care of adding this stuff to CVS? If not can I get CVS access? Thanks! Josh ------=_NextPart_000_000B_01C12660.CA029F90 Content-Type: application/octet-stream; name="DescriptorHandler.java" Content-Disposition: attachment; filename="DescriptorHandler.java" Content-Transfer-Encoding: quoted-printable /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software = itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products = derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ package org.apache.tools.ant.taskdefs.optional.ejb; import java.util.*; import java.io.*; import java.net.*; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.AttributeList; import org.apache.tools.ant.*; /** * Inner class used by EjbJar to facilitate the parsing of deployment * descriptors and the capture of appropriate information. Extends * HandlerBase so it only implements the methods needed. During parsing * creates a hashtable consisting of entries mapping the name it should = be * inserted into an EJB jar as to a File representing the file on disk. = This * list can then be accessed through the getFiles() method. */ public class DescriptorHandler extends org.xml.sax.HandlerBase { static private final int STATE_LOOKING_EJBJAR =3D 1; static private final int STATE_IN_EJBJAR =3D 2; static private final int STATE_IN_BEANS =3D 3; static private final int STATE_IN_SESSION =3D 4; static private final int STATE_IN_ENTITY =3D 5; static private final int STATE_IN_MESSAGE =3D 6; private Task owningTask; private String publicId =3D null; /** * Bunch 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 HOME_INTERFACE =3D "home"; private static final String REMOTE_INTERFACE =3D "remote"; private static final String LOCAL_HOME_INTERFACE =3D "local-home"; private static final String LOCAL_INTERFACE =3D "local"; private static final String BEAN_CLASS =3D "ejb-class"; private static final String PK_CLASS =3D = "prim-key-class"; private static final String EJB_NAME =3D "ejb-name"; private static final String EJB_JAR =3D "ejb-jar"; private static final String ENTERPRISE_BEANS =3D = "enterprise-beans"; private static final String ENTITY_BEAN =3D "entity"; private static final String SESSION_BEAN =3D "session"; private static final String MESSAGE_BEAN =3D = "message-driven"; /** * The state of the parsing */ private int parseState =3D STATE_LOOKING_EJBJAR; /** * Instance 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 currentElement =3D null; /** * The text of the current element */ protected String currentText =3D null; /** * Instance 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 Hashtable ejbFiles =3D null; /** * Instance variable that stores the value found in the = element */ protected String ejbName =3D null; private Hashtable fileDTDs =3D new Hashtable(); private Hashtable resourceDTDs =3D new Hashtable(); private Hashtable urlDTDs =3D new Hashtable(); /** * The directory containing the bean classes and interfaces. This is * used for performing dependency file lookups. */ private File srcDir; public DescriptorHandler(Task task, File srcDir) { this.owningTask =3D task; this.srcDir =3D srcDir; } public void registerDTD(String publicId, String location) { if (location =3D=3D null) { return; } File fileDTD =3D new File(location); if (fileDTD.exists()) { if (publicId !=3D null) { fileDTDs.put(publicId, fileDTD); owningTask.log("Mapped publicId " + publicId + " to file = " + fileDTD, Project.MSG_VERBOSE); } return; } if (getClass().getResource(location) !=3D null) { if (publicId !=3D null) { resourceDTDs.put(publicId, location); owningTask.log("Mapped publicId " + publicId + " to = resource " + location, Project.MSG_VERBOSE); } } try { if (publicId !=3D null) { URL urldtd =3D new URL(location); urlDTDs.put(publicId, urldtd); } } catch ( java.net.MalformedURLException e) { //ignored } } public InputSource resolveEntity(String publicId, String systemId) throws SAXException { this.publicId =3D publicId; File dtdFile =3D (File) fileDTDs.get(publicId); if (dtdFile !=3D 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 =3D (String)resourceDTDs.get(publicId); if (dtdResourceName !=3D null) { InputStream is =3D = this.getClass().getResourceAsStream(dtdResourceName); if (is !=3D null) { owningTask.log("Resolved " + publicId + " to local = resource " + dtdResourceName, Project.MSG_VERBOSE); return new InputSource(is); } } URL dtdUrl =3D (URL) urlDTDs.get(publicId); if ( dtdUrl !=3D null ) { try { InputStream is =3D 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; } /** * Getter method that returns the set of files to include in the EJB = jar. */ public Hashtable getFiles() { return (ejbFiles =3D=3D null) ? new Hashtable() : ejbFiles; } /** * Get the publicId of the DTD */ public String getPublicId() { return publicId; } /** * Getter method that returns the value of the element. */ public String getEjbName() { return ejbName; } /** * SAX parser call-back method that is used to initialize the values = of some * instance variables to ensure safe operation. */ public void startDocument() throws SAXException { this.ejbFiles =3D new Hashtable(10, 1); this.currentElement =3D null; } /** * 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. * @param name The name of the element being entered. * @param attrs Attributes associated to the element. */ public void startElement(String name, AttributeList attrs) throws SAXException { this.currentElement =3D name; currentText =3D ""; if (parseState =3D=3D STATE_LOOKING_EJBJAR && = name.equals(EJB_JAR)) { parseState =3D STATE_IN_EJBJAR; } else if (parseState =3D=3D STATE_IN_EJBJAR && = name.equals(ENTERPRISE_BEANS)) { parseState =3D STATE_IN_BEANS; } else if (parseState =3D=3D STATE_IN_BEANS && = name.equals(SESSION_BEAN)) { parseState =3D STATE_IN_SESSION; } else if (parseState =3D=3D STATE_IN_BEANS && = name.equals(ENTITY_BEAN )) { parseState =3D STATE_IN_ENTITY; } else if (parseState =3D=3D STATE_IN_BEANS && = name.equals(MESSAGE_BEAN )) { parseState =3D STATE_IN_MESSAGE; } } /** * 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. * @param name The name of the attribute being exited. Ignored * in this implementation. */ public void endElement(String name) throws SAXException { processElement(); currentText =3D ""; this.currentElement =3D ""; if (parseState =3D=3D STATE_IN_ENTITY && name.equals(ENTITY_BEAN = )) { parseState =3D STATE_IN_BEANS; } else if (parseState =3D=3D STATE_IN_SESSION && = name.equals(SESSION_BEAN)) { parseState =3D STATE_IN_BEANS; } else if (parseState =3D=3D STATE_IN_MESSAGE && = name.equals(MESSAGE_BEAN)) { parseState =3D STATE_IN_BEANS; } else if (parseState =3D=3D STATE_IN_BEANS && = name.equals(ENTERPRISE_BEANS)) { parseState =3D STATE_IN_EJBJAR; } else if (parseState =3D=3D STATE_IN_EJBJAR && = name.equals(EJB_JAR)) { parseState =3D STATE_LOOKING_EJBJAR; } } /** * 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. * @param ch A character array containing all the characters in * the element, and maybe others that should be ignored. * @param start An integer marking the position in the char * array to start reading from. * @param length An integer representing an offset into the * char array where the current data terminates. */ public void characters(char[] ch, int start, int length) throws SAXException { currentText +=3D new String(ch, start, length); } protected void processElement() { if (parseState !=3D STATE_IN_ENTITY && parseState !=3D = STATE_IN_SESSION && parseState !=3D 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 =3D null; String className =3D 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 =3D className.replace('.', = File.separatorChar); className +=3D ".class"; classFile =3D new File(srcDir, className); ejbFiles.put(className, classFile); } } // Get the value of the tag. Only the first occurence. if (currentElement.equals(EJB_NAME)) { if ( ejbName =3D=3D null ) { ejbName =3D currentText.trim(); } } } } ------=_NextPart_000_000B_01C12660.CA029F90--