User: deerwood Date: 01/07/23 09:28:46 Modified: src/main/org/jboss/ejb/plugins/jaws/metadata FinderMetaData.java JawsApplicationMetaData.java Log: o Indentation and formatting to project standards. Revision Changes Path 1.5 +41 -29 jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/FinderMetaData.java Index: FinderMetaData.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/FinderMetaData.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- FinderMetaData.java 2001/06/21 21:52:38 1.4 +++ FinderMetaData.java 2001/07/23 16:28:46 1.5 @@ -4,6 +4,7 @@ * Distributable under LGPL license. * See terms of license at gnu.org. */ + package org.jboss.ejb.plugins.jaws.metadata; import org.w3c.dom.Element; @@ -15,71 +16,82 @@ /** - * <description> - * - * @see <related> - * @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a> - * @author <a href="[EMAIL PROTECTED]">danch</a> - * @author <a href="[EMAIL PROTECTED]">Bill Burke</a> - * @version $Revision: 1.4 $ + * <description> + * + * @see <related> + * @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a> + * @author <a href="[EMAIL PROTECTED]">danch</a> + * @author <a href="[EMAIL PROTECTED]">Bill Burke</a> + * @version $Revision: 1.5 $ * * Revisions: * 20010621 Bill Burke: setReadAhead added. * */ -public class FinderMetaData extends MetaData implements XmlLoadable { +public class FinderMetaData + extends MetaData + implements XmlLoadable +{ // Constants ----------------------------------------------------- - + // Attributes ---------------------------------------------------- + private String name; private String order; private String query; - + /** do we perform 'read-ahead' of column values? (avoid making n+1 database hits) */ private boolean readAhead = false; - + // Static -------------------------------------------------------- - + // Constructors -------------------------------------------------- + /** default constructor */ - public FinderMetaData() { - } - - /** constructor used to provide non-defined finders (findAll, BMP style - * finders) with their metadata. */ - public FinderMetaData(String name) { + public FinderMetaData() {} + + /** + * constructor used to provide non-defined finders (findAll, BMP style + * finders) with their metadata. + */ + public FinderMetaData(String name) + { this.name = name; } - + // Public -------------------------------------------------------- + public String getName() { return name; } - + public String getOrder() { return order; } - + public String getQuery() { return query; } - + public boolean hasReadAhead() { return readAhead; } public void setReadAhead(boolean newval) { readAhead = newval; } - + // XmlLoadable implementation ------------------------------------ - public void importXml(Element element) throws DeploymentException { + + public void importXml(Element element) + throws DeploymentException + { name = getElementContent(getUniqueChild(element, "name")); query = getElementContent(getUniqueChild(element, "query")); order = getElementContent(getUniqueChild(element, "order")); - + // read ahead? If not provided, keep default. String readAheadStr = getElementContent(getOptionalChild(element, "read-ahead")); if (readAheadStr != null) readAhead = Boolean.valueOf(readAheadStr).booleanValue(); - } - + } + // Package protected --------------------------------------------- - + // Protected ----------------------------------------------------- - + // Private ------------------------------------------------------- // Inner classes ------------------------------------------------- 1.9 +216 -178 jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/JawsApplicationMetaData.java Index: JawsApplicationMetaData.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/JawsApplicationMetaData.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- JawsApplicationMetaData.java 2001/06/27 03:55:36 1.8 +++ JawsApplicationMetaData.java 2001/07/23 16:28:46 1.9 @@ -4,6 +4,7 @@ * Distributable under LGPL license. * See terms of license at gnu.org. */ + package org.jboss.ejb.plugins.jaws.metadata; import java.util.Hashtable; @@ -26,201 +27,238 @@ /** - * <description> - * - * @see <related> - * @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a> - * @version $Revision: 1.8 $ + * <description> + * + * @see <related> + * @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a> + * @version $Revision: 1.9 $ */ public class JawsApplicationMetaData extends MetaData implements XmlLoadable { - // Constants ----------------------------------------------------- - public static final String JPM = "org.jboss.ejb.plugins.jaws.JAWSPersistenceManager"; - - // Attributes ---------------------------------------------------- - - // the classloader comes from the container. It is used to load the classes of the beans - // and their primary keys - private ClassLoader classLoader; - - // the "parent" applicationmetadata - private ApplicationMetaData applicationMetaData; - - // this only contains the jaws-managed cmp entities - private Hashtable entities = new Hashtable(); - - // the datasource to use for this application - private String dbURL; - private DataSource dataSource; - + // Constants ----------------------------------------------------- + + public static final String JPM = "org.jboss.ejb.plugins.jaws.JAWSPersistenceManager"; + + // Attributes ---------------------------------------------------- + + /** + * The classloader comes from the container. It is used to load + * the classes of the beans and their primary keys. + */ + private ClassLoader classLoader; + + /** The "parent" applicationmetadata. */ + private ApplicationMetaData applicationMetaData; + + /** This only contains the jaws-managed cmp entities. */ + private Hashtable entities = new Hashtable(); + + /** The datasource to use for this application. */ + private String dbURL; + private DataSource dataSource; + private boolean debug = false; - // all the available type mappings - private Hashtable typeMappings = new Hashtable(); - - // the type mapping to use with the specified database - private TypeMappingMetaData typeMapping; - - - // Static -------------------------------------------------------- - - // Constructors -------------------------------------------------- - public JawsApplicationMetaData(ApplicationMetaData amd, ClassLoader cl) throws DeploymentException { - // initialisation of this object goes as follows: - // - constructor - // - importXml() for standardjaws.xml and jaws.xml - // - init() - - // the classloader is the same for all the beans in the application - classLoader = cl; - applicationMetaData = amd; - - // create metadata for all jaws-managed cmp entities - // we do that here in case there is no jaws.xml - Iterator beans = applicationMetaData.getEnterpriseBeans(); - while (beans.hasNext()) { - BeanMetaData bean = (BeanMetaData)beans.next(); - - // only take entities - if (bean.isEntity()) { - EntityMetaData entity = (EntityMetaData)bean; - - // only take jaws-managed CMP entities - if (entity.isCMP() && entity.getContainerConfiguration().getPersistenceManager().equals(JPM)) { - JawsEntityMetaData jawsEntity = new JawsEntityMetaData(this, entity); - entities.put(entity.getEjbName(), jawsEntity); - } - } - } - } - - - // Public -------------------------------------------------------- - public DataSource getDataSource() { return dataSource; } - - public String getDbURL() { return dbURL; } + /** All the available type mappings. */ + private Hashtable typeMappings = new Hashtable(); + + /** The type mapping to use with the specified database. */ + private TypeMappingMetaData typeMapping; + + // Static -------------------------------------------------------- + + // Constructors -------------------------------------------------- + + public JawsApplicationMetaData(ApplicationMetaData amd, ClassLoader cl) + throws DeploymentException + { + // initialisation of this object goes as follows: + // - constructor + // - importXml() for standardjaws.xml and jaws.xml + // - init() + + // the classloader is the same for all the beans in the application + classLoader = cl; + applicationMetaData = amd; + + // create metadata for all jaws-managed cmp entities + // we do that here in case there is no jaws.xml + Iterator beans = applicationMetaData.getEnterpriseBeans(); + while (beans.hasNext()) + { + BeanMetaData bean = (BeanMetaData)beans.next(); + + // only take entities + if (bean.isEntity()) + { + EntityMetaData entity = (EntityMetaData)bean; + + // only take jaws-managed CMP entities + if (entity.isCMP() && + entity.getContainerConfiguration().getPersistenceManager().equals(JPM)) + { + JawsEntityMetaData jawsEntity = new JawsEntityMetaData(this, entity); + entities.put(entity.getEjbName(), jawsEntity); + } + } + } + } - public TypeMappingMetaData getTypeMapping() { return typeMapping; } + // Public -------------------------------------------------------- + public DataSource getDataSource() { return dataSource; } + + public String getDbURL() { return dbURL; } + + public TypeMappingMetaData getTypeMapping() { return typeMapping; } + public boolean getDebug() { return debug; } - + protected ClassLoader getClassLoader() { return classLoader; } + + public JawsEntityMetaData getBeanByEjbName(String name) + { + return (JawsEntityMetaData)entities.get(name); + } + + public void init() + throws DeploymentException + { + // find the datasource + if (! dbURL.startsWith("jdbc:")) { + try { + dataSource = (DataSource)new InitialContext().lookup(dbURL); + } catch (NamingException e) { + throw new DeploymentException(e.getMessage()); + } + } + } - public JawsEntityMetaData getBeanByEjbName(String name) { - return (JawsEntityMetaData)entities.get(name); - } - - - public void init() throws DeploymentException { - - // find the datasource - if (! dbURL.startsWith("jdbc:")) { - try { - dataSource = (DataSource)new InitialContext().lookup(dbURL); - } catch (NamingException e) { - throw new DeploymentException(e.getMessage()); - } - } - - } - - - - // XmlLoadable implementation ------------------------------------ - - public void importXml(Element element) throws DeploymentException { - // importXml will be called at least once: with standardjaws.xml - // it may be called a second time with user-provided jaws.xml - // we must ensure to set all defaults values in the first call - Iterator iterator; - - // first get the type mappings. (optional, but always set in standardjaws.xml) - Element typeMaps = getOptionalChild(element, "type-mappings"); - - if (typeMaps != null) { - iterator = getChildrenByTagName(typeMaps, "type-mapping-definition"); - - while (iterator.hasNext()) { - Element typeMappingElement = (Element)iterator.next(); - TypeMappingMetaData typeMapping = new TypeMappingMetaData(); - try { - typeMapping.importXml(typeMappingElement); - } catch (DeploymentException e) { - throw new DeploymentException("Error in jaws.xml for type-mapping-definition " + typeMapping.getName() + ": " + e.getMessage()); - } - typeMappings.put(typeMapping.getName(), typeMapping); - } - } - - // get the datasource (optional, but always set in standardjaws.xml) - Element db = getOptionalChild(element, "datasource"); - if (db != null) dbURL = getElementContent(db); - + // XmlLoadable implementation ------------------------------------ + + public void importXml(Element element) + throws DeploymentException + { + // importXml will be called at least once: with standardjaws.xml + // it may be called a second time with user-provided jaws.xml + // we must ensure to set all defaults values in the first call + Iterator iterator; + + // first get the type mappings. (optional, but always set in standardjaws.xml) + Element typeMaps = getOptionalChild(element, "type-mappings"); + + if (typeMaps != null) + { + iterator = getChildrenByTagName(typeMaps, "type-mapping-definition"); + + while (iterator.hasNext()) + { + Element typeMappingElement = (Element)iterator.next(); + TypeMappingMetaData typeMapping = new TypeMappingMetaData(); + try + { + typeMapping.importXml(typeMappingElement); + } + catch (DeploymentException e) + { + throw new DeploymentException( + "Error in jaws.xml for type-mapping-definition " + + typeMapping.getName() + ": " + e.getMessage() + ); + } + typeMappings.put(typeMapping.getName(), typeMapping); + } + } + + // get the datasource (optional, but always set in standardjaws.xml) + Element db = getOptionalChild(element, "datasource"); + if (db != null) dbURL = getElementContent(db); + // Make sure it is prefixed with java: - if (!dbURL.startsWith("java:/")) - dbURL = "java:/"+dbURL; - - // get the type mapping for this datasource (optional, but always set in standardjaws.xml) - String typeMappingString = getElementContent(getOptionalChild(element, "type-mapping")); - - if (typeMappingString != null) { - typeMapping = (TypeMappingMetaData)typeMappings.get(typeMappingString); - - if (typeMapping == null) { - throw new DeploymentException("Error in jaws.xml : type-mapping " + typeMappingString + " not found"); - } - } - + if (!dbURL.startsWith("java:/")) + dbURL = "java:/"+dbURL; + + // get the type mapping for this datasource + // (optional, but always set in standardjaws.xml) + String typeMappingString = + getElementContent(getOptionalChild(element, "type-mapping")); + + if (typeMappingString != null) + { + typeMapping = (TypeMappingMetaData)typeMappings.get(typeMappingString); + + if (typeMapping == null) + { + throw new DeploymentException( + "Error in jaws.xml : type-mapping " + typeMappingString + " not found"); + } + } + //enable extra debugging? Element debugElement = getOptionalChild(element, "debug"); - if (debugElement != null) { + if (debugElement != null) + { String stringDebug = getElementContent( debugElement ); debug = Boolean.valueOf(stringDebug).booleanValue(); + } + + + // get default settings for the beans (optional, but always set in standardjaws.xml) + Element defaultEntity = getOptionalChild(element, "default-entity"); + + if (defaultEntity != null) + { + iterator = entities.values().iterator(); + + while (iterator.hasNext()) + { + ((JawsEntityMetaData)iterator.next()).importXml(defaultEntity); + } + } + + // get the beans data (only in jaws.xml) + Element enterpriseBeans = getOptionalChild(element, "enterprise-beans"); + + if (enterpriseBeans != null) + { + String ejbName = null; + + try + { + iterator = getChildrenByTagName(enterpriseBeans, "entity"); + + while (iterator.hasNext()) + { + Element bean = (Element) iterator.next(); + ejbName = getElementContent(getUniqueChild(bean, "ejb-name")); + JawsEntityMetaData entity = (JawsEntityMetaData)entities.get(ejbName); + + if (entity != null) + { + entity.importXml(bean); + } + else + { + Logger.warning( + "Warning: data found in jaws.xml for entity " + ejbName + + " but bean is not a jaws-managed cmp entity in ejb-jar.xml" + ); + } + } + + } + catch (DeploymentException e) + { + throw new DeploymentException( + "Error in jaws.xml for Entity " + ejbName + ": " + e.getMessage()); + } } - + } - // get default settings for the beans (optional, but always set in standardjaws.xml) - Element defaultEntity = getOptionalChild(element, "default-entity"); + // Package protected --------------------------------------------- - if (defaultEntity != null) { - iterator = entities.values().iterator(); + // Protected ----------------------------------------------------- - while (iterator.hasNext()) { - ((JawsEntityMetaData)iterator.next()).importXml(defaultEntity); - } - } - - // get the beans data (only in jaws.xml) - Element enterpriseBeans = getOptionalChild(element, "enterprise-beans"); - - if (enterpriseBeans != null) { - String ejbName = null; - - try { - iterator = getChildrenByTagName(enterpriseBeans, "entity"); - - while (iterator.hasNext()) { - Element bean = (Element) iterator.next(); - ejbName = getElementContent(getUniqueChild(bean, "ejb-name")); - JawsEntityMetaData entity = (JawsEntityMetaData)entities.get(ejbName); - - if (entity != null) { - entity.importXml(bean); - } else { - Logger.warning("Warning: data found in jaws.xml for entity " + ejbName + " but bean is not a jaws-managed cmp entity in ejb-jar.xml"); - } - } - - } catch (DeploymentException e) { - throw new DeploymentException("Error in jaws.xml for Entity " + ejbName + ": " + e.getMessage()); - } - } - } - - // Package protected --------------------------------------------- - - // Protected ----------------------------------------------------- - - // Private ------------------------------------------------------- + // Private ------------------------------------------------------- - // Inner classes ------------------------------------------------- + // Inner classes ------------------------------------------------- } _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-development