You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2003/10/01 21:03:40 UTC
cvs commit: incubator-geronimo/modules/core/src/test-data/xml/deployment .cvsignore
ammulder 2003/10/01 12:03:40
Modified: modules/core/src/test/org/apache/geronimo/xml/deployment
GeronimoEjbJarLoaderTest.java
Added: modules/core/src/java/org/apache/geronimo/xml/deployment
EjbJarStorer.java GeronimoEjbJarStorer.java
GeronimoJ2EEStorer.java J2EEStorer.java
StorerUtil.java
modules/core/src/test/org/apache/geronimo/xml/deployment
EjbJarStorerTest.java GeronimoEjbJarStorerTest.java
modules/core/src/test-data/xml/deployment .cvsignore
Log:
Now you can write out the EJB POJOs as well as reading them.
Mostly, anyway.
Revision Changes Path
1.1 incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/EjbJarStorer.java
Index: EjbJarStorer.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" 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",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* 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.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import java.io.Writer;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.apache.geronimo.deployment.model.ejb.EjbJarDocument;
import org.apache.geronimo.deployment.model.ejb.EjbJar;
import org.apache.geronimo.deployment.model.ejb.EnterpriseBeans;
import org.apache.geronimo.deployment.model.ejb.Session;
import org.apache.geronimo.deployment.model.ejb.RpcBean;
import org.apache.geronimo.deployment.model.ejb.Ejb;
import org.apache.geronimo.deployment.model.ejb.SecurityIdentity;
import org.apache.geronimo.deployment.model.ejb.MessageDriven;
import org.apache.geronimo.deployment.model.ejb.Entity;
import org.apache.geronimo.deployment.model.ejb.ActivationConfig;
import org.apache.geronimo.deployment.model.ejb.ActivationConfigProperty;
import org.apache.geronimo.deployment.model.ejb.CmpField;
import org.apache.geronimo.deployment.model.ejb.Query;
import org.apache.geronimo.deployment.model.ejb.QueryMethod;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Stores an ejb-jar.xml DD from POJOs to a DOM tree
*
* @version $Revision: 1.1 $ $Date: 2003/10/01 19:03:40 $
*/
public class EjbJarStorer {
public static void store(EjbJarDocument jarDoc, Writer out) throws IOException {
try {
EjbJar jar = jarDoc.getEjbJar();
Document doc = StorerUtil.createDocument();
Element root = doc.createElementNS("http://java.sun.com/xml/ns/j2ee", "ejb-jar");
root.setAttribute("xmlns", "http://java.sun.com/xml/ns/j2ee");
root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd");
root.setAttribute("version", jar.getVersion());
doc.appendChild(root);
J2EEStorer.storeDisplayable(root, jar);
if(jar.getEnterpriseBeans() != null && jar.getEnterpriseBeans().hasBeans()) {
storeEjbs(StorerUtil.createChild(root, "enterprise-beans"), jar.getEnterpriseBeans());
}
//todo: relationships, assembly descriptor
StorerUtil.writeXML(doc, out);
} catch(ParserConfigurationException e) {
throw new IOException("Unable to generate DOM document: "+e);
} catch(TransformerException e) {
throw new IOException("Unable to write document: "+e);
}
}
static void storeEjbs(Element root, EnterpriseBeans beans) {
Session[] session = beans.getSession();
for(int i = 0; i < session.length; i++) {
Element se = StorerUtil.createChild(root, "session");
storeSessionBean(se, session[i]);
}
Entity[] entity = beans.getEntity();
for(int i = 0; i < entity.length; i++) {
Element ee = StorerUtil.createChild(root, "entity");
storeEntityBean(ee, entity[i]);
}
MessageDriven[] mdb = beans.getMessageDriven();
for(int i = 0; i < mdb.length; i++) {
Element me = StorerUtil.createChild(root, "message-driven");
storeMessageDrivenBean(me, mdb[i]);
}
}
static void storeSessionBean(Element root, Session session) {
storeRpcBean(root, session);
StorerUtil.createOptionalChildText(root, "service-endpoint", session.getServiceEndpoint());
StorerUtil.createChildText(root, "ejb-class", session.getEJBClass());
StorerUtil.createOptionalChildText(root, "session-type", session.getSessionType());
StorerUtil.createOptionalChildText(root, "transaction-type", session.getTransactionType());
storeReferences(root, session);
J2EEStorer.storeSecurityRoleRefs(root, session.getSecurityRoleRef());
if(session.getSecurityIdentity() != null) {
storeSecurityIdentity(StorerUtil.createChild(root, "security-identity"), session.getSecurityIdentity());
}
}
static void storeEntityBean(Element root, Entity bean) {
storeRpcBean(root, bean);
StorerUtil.createChildText(root, "ejb-class", bean.getEJBClass());
StorerUtil.createChildText(root, "persistence-type", bean.getPersistenceType());
StorerUtil.createChildText(root, "prim-key-class", bean.getPrimKeyClass());
StorerUtil.createChildText(root, "reentrant", bean.getReentrant());
StorerUtil.createOptionalChildText(root, "cmp-version", bean.getCmpVersion());
StorerUtil.createOptionalChildText(root, "abstract-schema-name", bean.getAbstractSchemaName());
for(int i = 0; i < bean.getCmpField().length; i++) {
storeCmpField(StorerUtil.createChild(root, "cmp-field"), bean.getCmpField(i));
}
StorerUtil.createOptionalChildText(root, "primkey-field", bean.getPrimkeyField());
storeReferences(root, bean);
J2EEStorer.storeSecurityRoleRefs(root, bean.getSecurityRoleRef());
if(bean.getSecurityIdentity() != null) {
storeSecurityIdentity(StorerUtil.createChild(root, "security-identity"), bean.getSecurityIdentity());
}
for(int i = 0; i < bean.getQuery().length; i++) {
storeQuery(StorerUtil.createChild(root, "query"), bean.getQuery(i));
}
}
static void storeQuery(Element parent, Query query) {
J2EEStorer.storeDescribable(parent, query);
storeQueryMethod(StorerUtil.createChild(parent, "query-method"), query.getQueryMethod());
StorerUtil.createChildText(parent, "result-type-mapping", query.getResultTypeMapping());
StorerUtil.createChildText(parent, "ejb-ql", query.getEjbQl());
}
static void storeQueryMethod(Element parent, QueryMethod method) {
StorerUtil.createChildText(parent, "method-name", method.getMethodName());
Element e = StorerUtil.createChild(parent, "method-params");
for(int i = 0; i < method.getMethodParam().length; i++) {
StorerUtil.createChildText(e, "method-param", method.getMethodParam(i));
}
}
static void storeCmpField(Element parent, CmpField field) {
J2EEStorer.storeDescribable(parent, field);
StorerUtil.createChildText(parent, "field-name", field.getFieldName());
}
static void storeMessageDrivenBean(Element root, MessageDriven bean) {
J2EEStorer.storeDisplayable(root, bean);
StorerUtil.createChildText(root, "ejb-name", bean.getEJBName());
StorerUtil.createChildText(root, "ejb-class", bean.getEJBClass());
StorerUtil.createOptionalChildText(root, "messaging-type", bean.getMessagingType());
StorerUtil.createChildText(root, "transaction-type", bean.getTransactionType());
StorerUtil.createOptionalChildText(root, "message-destination-type", bean.getMessageDestinationType());
StorerUtil.createOptionalChildText(root, "message-destination-link", bean.getMessageDestinationLink());
if(bean.getActivationConfig() != null) {
storeActivationConfig(StorerUtil.createChild(root, "activation-config"), bean.getActivationConfig());
}
storeReferences(root, bean);
if(bean.getSecurityIdentity() != null) {
storeSecurityIdentity(StorerUtil.createChild(root, "security-identity"), bean.getSecurityIdentity());
}
}
static void storeActivationConfig(Element parent, ActivationConfig config) {
J2EEStorer.storeDescribable(parent, config);
for(int i = 0; i < config.getActivationConfigProperty().length; i++) {
storeActivationConfigProperty(StorerUtil.createChild(parent, "activation-config-property"), config.getActivationConfigProperty(i));
}
}
static void storeActivationConfigProperty(Element parent, ActivationConfigProperty property) {
StorerUtil.createChildText(parent, "activation-config-property-name", property.getActivationConfigPropertyName());
StorerUtil.createChildText(parent, "activation-config-property-value", property.getActivationConfigPropertyValue());
}
static void storeRpcBean(Element root, RpcBean bean) {
J2EEStorer.storeDisplayable(root, bean);
StorerUtil.createChildText(root, "ejb-name", bean.getEJBName());
StorerUtil.createOptionalChildText(root, "home", bean.getHome());
StorerUtil.createOptionalChildText(root, "remote", bean.getRemote());
StorerUtil.createOptionalChildText(root, "local-home", bean.getLocalHome());
StorerUtil.createOptionalChildText(root, "local", bean.getLocal());
}
static void storeReferences(Element root, Ejb bean) {
J2EEStorer.storeEnvEntries(root, bean.getEnvEntry());
J2EEStorer.storeEJBRefs(root, bean.getEJBRef());
J2EEStorer.storeEJBLocalRefs(root, bean.getEJBLocalRef());
J2EEStorer.storeServiceRefs(root, bean.getServiceRef());
J2EEStorer.storeResourceRefs(root, bean.getResourceRef());
J2EEStorer.storeResourceEnvRefs(root, bean.getResourceEnvRef());
J2EEStorer.storeMessageDestinationRefs(root, bean.getMessageDestinationRef());
}
static void storeSecurityIdentity(Element root, SecurityIdentity identity) {
J2EEStorer.storeDescribable(root, identity);
if(identity.isUseCallerIdentity()) {
StorerUtil.createChild(root, "use-caller-identity");
} else if(identity.getRunAs() != null) {
J2EEStorer.storeRunAs(StorerUtil.createChild(root, "run-as"), identity.getRunAs());
}
}
}
1.1 incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/GeronimoEjbJarStorer.java
Index: GeronimoEjbJarStorer.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" 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",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* 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.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import java.io.Writer;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.geronimo.deployment.model.geronimo.ejb.MessageDriven;
import org.apache.geronimo.deployment.model.geronimo.ejb.Entity;
import org.apache.geronimo.deployment.model.geronimo.ejb.Session;
import org.apache.geronimo.deployment.model.geronimo.ejb.EnterpriseBeans;
import org.apache.geronimo.deployment.model.geronimo.ejb.EjbJar;
import org.apache.geronimo.deployment.model.geronimo.ejb.GeronimoEjbJarDocument;
/**
* Knows how to store geronimo-ejb-jar.xml POJOs to a DOM
*
* @version $Revision: 1.1 $ $Date: 2003/10/01 19:03:40 $
*/
public class GeronimoEjbJarStorer {
public static void store(GeronimoEjbJarDocument jarDoc, Writer out) throws IOException {
try {
EjbJar jar = jarDoc.getEjbJar();
Document doc = StorerUtil.createDocument();
Element root = doc.createElementNS("http://java.sun.com/xml/ns/j2ee", "ejb-jar");
root.setAttribute("xmlns", "http://java.sun.com/xml/ns/j2ee");
root.setAttribute("xmlns:ger", "http://geronimo.apache.org/xml/schema/j2ee");
root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "http://java.sun.com/xml/ns/j2ee http://geronimo.apache.org/xml/schema/1.0/j2ee14/geronimo-ejb-jar.xsd");
root.setAttribute("version", jar.getVersion());
doc.appendChild(root);
J2EEStorer.storeDisplayable(root, jar);
if(jar.getEnterpriseBeans() != null && jar.getEnterpriseBeans().hasBeans()) {
storeEjbs(StorerUtil.createChild(root, "enterprise-beans"), jar.getGeronimoEnterpriseBeans());
}
//todo: there will probably be Geronimo-specific content for relationships, assembly descriptor
StorerUtil.writeXML(doc, out);
} catch(ParserConfigurationException e) {
throw new IOException("Unable to generate DOM document: "+e);
} catch(TransformerException e) {
throw new IOException("Unable to write document: "+e);
}
}
static void storeEjbs(Element root, EnterpriseBeans beans) {
Session[] session = beans.getGeronimoSession();
for(int i = 0; i < session.length; i++) {
Element se = StorerUtil.createChild(root, "session");
storeSessionBean(se, session[i]);
}
Entity[] entity = beans.getGeronimoEntity();
for(int i = 0; i < entity.length; i++) {
Element ee = StorerUtil.createChild(root, "entity");
storeEntityBean(ee, entity[i]);
}
MessageDriven[] mdb = beans.getGeronimoMessageDriven();
for(int i = 0; i < mdb.length; i++) {
Element me = StorerUtil.createChild(root, "message-driven");
storeMessageDrivenBean(me, mdb[i]);
}
}
static void storeSessionBean(Element root, Session bean) {
J2EEStorer.storeDisplayable(root, bean);
StorerUtil.createChildText(root, "ejb-name", bean.getEJBName());
StorerUtil.createOptionalChildText(root, "home", bean.getHome());
StorerUtil.createOptionalChildText(root, "remote", bean.getRemote());
StorerUtil.createOptionalChildText(root, "local-home", bean.getLocalHome());
StorerUtil.createOptionalChildText(root, "local", bean.getLocal());
StorerUtil.createOptionalChildText(root, "service-endpoint", bean.getServiceEndpoint());
StorerUtil.createChildText(root, "ejb-class", bean.getEJBClass());
StorerUtil.createOptionalChildText(root, "session-type", bean.getSessionType());
StorerUtil.createOptionalChildText(root, "transaction-type", bean.getTransactionType());
GeronimoJ2EEStorer.storeJNDIEnvironmentRefs(root, bean);
J2EEStorer.storeSecurityRoleRefs(root, bean.getSecurityRoleRef());
if(bean.getSecurityIdentity() != null) {
EjbJarStorer.storeSecurityIdentity(StorerUtil.createChild(root, "security-identity"), bean.getSecurityIdentity());
}
StorerUtil.createOptionalChildText(root, "jndi-name", bean.getJndiName());
}
static void storeEntityBean(Element root, Entity bean) {
J2EEStorer.storeDisplayable(root, bean);
StorerUtil.createChildText(root, "ejb-name", bean.getEJBName());
StorerUtil.createOptionalChildText(root, "home", bean.getHome());
StorerUtil.createOptionalChildText(root, "remote", bean.getRemote());
StorerUtil.createOptionalChildText(root, "local-home", bean.getLocalHome());
StorerUtil.createOptionalChildText(root, "local", bean.getLocal());
StorerUtil.createChildText(root, "ejb-class", bean.getEJBClass());
StorerUtil.createChildText(root, "persistence-type", bean.getPersistenceType());
StorerUtil.createChildText(root, "prim-key-class", bean.getPrimKeyClass());
StorerUtil.createChildText(root, "reentrant", bean.getReentrant());
StorerUtil.createOptionalChildText(root, "cmp-version", bean.getCmpVersion());
StorerUtil.createOptionalChildText(root, "abstract-schema-name", bean.getAbstractSchemaName());
for(int i = 0; i < bean.getCmpField().length; i++) {
EjbJarStorer.storeCmpField(StorerUtil.createChild(root, "cmp-field"), bean.getCmpField(i));
}
StorerUtil.createOptionalChildText(root, "primkey-field", bean.getPrimkeyField());
GeronimoJ2EEStorer.storeJNDIEnvironmentRefs(root, bean);
J2EEStorer.storeSecurityRoleRefs(root, bean.getSecurityRoleRef());
if(bean.getSecurityIdentity() != null) {
EjbJarStorer.storeSecurityIdentity(StorerUtil.createChild(root, "security-identity"), bean.getSecurityIdentity());
}
for(int i = 0; i < bean.getQuery().length; i++) {
EjbJarStorer.storeQuery(StorerUtil.createChild(root, "query"), bean.getQuery(i));
}
StorerUtil.createOptionalChildText(root, "jndi-name", bean.getJndiName());
}
static void storeMessageDrivenBean(Element root, MessageDriven bean) {
J2EEStorer.storeDisplayable(root, bean);
StorerUtil.createChildText(root, "ejb-name", bean.getEJBName());
StorerUtil.createChildText(root, "ejb-class", bean.getEJBClass());
StorerUtil.createOptionalChildText(root, "messaging-type", bean.getMessagingType());
StorerUtil.createChildText(root, "transaction-type", bean.getTransactionType());
StorerUtil.createOptionalChildText(root, "message-destination-type", bean.getMessageDestinationType());
StorerUtil.createOptionalChildText(root, "message-destination-link", bean.getMessageDestinationLink());
if(bean.getActivationConfig() != null) {
EjbJarStorer.storeActivationConfig(StorerUtil.createChild(root, "activation-config"), bean.getActivationConfig());
}
GeronimoJ2EEStorer.storeJNDIEnvironmentRefs(root, bean);
if(bean.getSecurityIdentity() != null) {
EjbJarStorer.storeSecurityIdentity(StorerUtil.createChild(root, "security-identity"), bean.getSecurityIdentity());
}
}
}
1.1 incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/GeronimoJ2EEStorer.java
Index: GeronimoJ2EEStorer.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" 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",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* 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.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import org.w3c.dom.Element;
import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbRef;
import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbLocalRef;
import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceRef;
import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceEnvRef;
import org.apache.geronimo.deployment.model.geronimo.j2ee.MessageDestinationRef;
import org.apache.geronimo.deployment.model.geronimo.j2ee.ServiceRef;
import org.apache.geronimo.deployment.model.geronimo.j2ee.SecurityRoleRef;
import org.apache.geronimo.deployment.model.geronimo.j2ee.JndiContextParam;
import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDIEnvironmentRefs;
/**
* Knows how ot store common Geronimo elements from POJOs to DOM
*
* @version $Revision: 1.1 $ $Date: 2003/10/01 19:03:40 $
*/
public class GeronimoJ2EEStorer {
public static void storeEJBRefs(Element parent, EjbRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "ejb-ref");
storeEJBRef(ref, refs[i]);
}
}
static void storeEJBRef(Element parent, EjbRef ref) {
J2EEStorer.storeEJBRef(parent, ref);
StorerUtil.createOptionalChildTextWithNS(parent, "ger:jndi-name", "http://geronimo.apache.org/xml/schema/j2ee", ref.getJndiName());
for(int i = 0; i < ref.getJndiContextParam().length; i++) {
storeContextParam(StorerUtil.createChild(parent, "context-param"), ref.getJndiContextParam(i));
}
}
public static void storeEJBLocalRefs(Element parent, EjbLocalRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "ejb-local-ref");
storeEJBLocalRef(ref, refs[i]);
}
}
static void storeEJBLocalRef(Element parent, EjbLocalRef ref) {
J2EEStorer.storeEJBLocalRef(parent, ref);
StorerUtil.createOptionalChildTextWithNS(parent, "ger:jndi-name", "http://geronimo.apache.org/xml/schema/j2ee", ref.getJndiName());
for(int i = 0; i < ref.getJndiContextParam().length; i++) {
storeContextParam(StorerUtil.createChild(parent, "context-param"), ref.getJndiContextParam(i));
}
}
public static void storeResourceRefs(Element parent, ResourceRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "resource-ref");
storeResourceRef(ref, refs[i]);
}
}
static void storeResourceRef(Element parent, ResourceRef ref) {
J2EEStorer.storeResourceRef(parent, ref);
StorerUtil.createChildTextWithNS(parent, "ger:jndi-name", "http://geronimo.apache.org/xml/schema/j2ee", ref.getJndiName());
for(int i = 0; i < ref.getJndiContextParam().length; i++) {
storeContextParam(StorerUtil.createChild(parent, "context-param"), ref.getJndiContextParam(i));
}
}
public static void storeResourceEnvRefs(Element parent, ResourceEnvRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "resource-env-ref");
storeResourceEnvRef(ref, refs[i]);
}
}
static void storeResourceEnvRef(Element parent, ResourceEnvRef ref) {
J2EEStorer.storeResourceEnvRef(parent, ref);
StorerUtil.createChildTextWithNS(parent, "ger:jndi-name", "http://geronimo.apache.org/xml/schema/j2ee", ref.getJndiName());
}
public static void storeMessageDestinationRefs(Element parent, MessageDestinationRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "message-destination-ref");
storeMessageDestinationRef(ref, refs[i]);
}
}
static void storeMessageDestinationRef(Element parent, MessageDestinationRef ref) {
J2EEStorer.storeMessageDestinationRef(parent, ref);
StorerUtil.createOptionalChildTextWithNS(parent, "ger:jndi-name", "http://geronimo.apache.org/xml/schema/j2ee", ref.getJndiName());
for(int i = 0; i < ref.getJndiContextParam().length; i++) {
storeContextParam(StorerUtil.createChild(parent, "context-param"), ref.getJndiContextParam(i));
}
}
public static void storeServiceRefs(Element parent, ServiceRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "service-ref");
storeServiceRef(ref, refs[i]);
}
}
static void storeServiceRef(Element parent, ServiceRef ref) {
J2EEStorer.storeServiceRef(parent, ref);
}
static void storeSecurityRoleRefs(Element parent, SecurityRoleRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element e = StorerUtil.createChild(parent, "security-role-ref");
storeSecurityRoleRef(e, refs[i]);
}
}
static void storeSecurityRoleRef(Element parent, SecurityRoleRef ref) {
J2EEStorer.storeSecurityRoleRef(parent, ref);
}
private static void storeContextParam(Element parent, JndiContextParam param) {
StorerUtil.createChildText(parent, "param-name", param.getParamName());
StorerUtil.createChildText(parent, "param-value", param.getParamValue());
}
public static void storeJNDIEnvironmentRefs(Element parent, JNDIEnvironmentRefs owner) {
J2EEStorer.storeEnvEntries(parent, owner.getEnvEntry());
storeEJBRefs(parent, owner.getGeronimoEJBRef());
storeEJBLocalRefs(parent, owner.getGeronimoEJBLocalRef());
storeServiceRefs(parent, owner.getGeronimoServiceRef());
storeResourceRefs(parent, owner.getGeronimoResourceRef());
storeResourceEnvRefs(parent, owner.getGeronimoResourceEnvRef());
storeMessageDestinationRefs(parent, owner.getGeronimoMessageDestinationRef());
}
}
1.1 incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/J2EEStorer.java
Index: J2EEStorer.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" 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",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* 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.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import org.apache.geronimo.deployment.model.j2ee.Describable;
import org.apache.geronimo.deployment.model.j2ee.Description;
import org.apache.geronimo.deployment.model.j2ee.Displayable;
import org.apache.geronimo.deployment.model.j2ee.DisplayName;
import org.apache.geronimo.deployment.model.j2ee.Icon;
import org.apache.geronimo.deployment.model.j2ee.RunAs;
import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
import org.apache.geronimo.deployment.model.j2ee.EJBRef;
import org.apache.geronimo.deployment.model.j2ee.EJBLocalRef;
import org.apache.geronimo.deployment.model.j2ee.ResourceRef;
import org.apache.geronimo.deployment.model.j2ee.ResourceEnvRef;
import org.apache.geronimo.deployment.model.j2ee.ServiceRef;
import org.apache.geronimo.deployment.model.j2ee.PortComponentRef;
import org.apache.geronimo.deployment.model.j2ee.Handler;
import org.apache.geronimo.deployment.model.j2ee.ParamValue;
import org.apache.geronimo.deployment.model.j2ee.MessageDestinationRef;
import org.apache.geronimo.deployment.model.j2ee.SecurityRoleRef;
import org.w3c.dom.Element;
/**
* Utility methods to write common J2EE elements to a DOM tree.
*
* @version $Revision: 1.1 $ $Date: 2003/10/01 19:03:40 $
*/
public class J2EEStorer {
public static void storeDescribable(Element parent, Describable desc) {
Description[] ds = desc.getDescription();
for(int i = 0; i < ds.length; i++) {
Element e = StorerUtil.createChild(parent, "description");
if(ds[i].getLang() != null && !ds[i].getLang().equals("")) {
e.setAttribute("lang", ds[i].getLang());
}
StorerUtil.setText(e, ds[i].getContent());
}
}
public static void storeDisplayable(Element parent, Displayable disp) {
storeDescribable(parent, disp);
DisplayName[] ds = disp.getDisplayName();
for(int i = 0; i < ds.length; i++) {
Element e = StorerUtil.createChild(parent, "display-name");
if(ds[i].getLang() != null && !ds[i].getLang().equals("")) {
e.setAttribute("lang", ds[i].getLang());
}
StorerUtil.setText(e, ds[i].getContent());
}
Icon[] is = disp.getIcon();
for(int i = 0; i < is.length; i++) {
Element icon = StorerUtil.createChild(parent, "icon");
if(is[i].getLang() != null && !is[i].getLang().equals("")) {
icon.setAttribute("lang", ds[i].getLang());
}
if(is[i].getSmallIcon() != null) {
StorerUtil.createChildText(icon, "small-icon", is[i].getLargeIcon());
}
if(is[i].getLargeIcon() != null) {
StorerUtil.createChildText(icon, "large-icon", is[i].getLargeIcon());
}
}
}
public static void storeRunAs(Element parent, RunAs as) {
storeDescribable(parent, as);
StorerUtil.createChildText(parent, "role-name", as.getRoleName());
}
public static void storeEnvEntries(Element parent, EnvEntry[] entries) {
for(int i = 0; i < entries.length; i++) {
Element entry = StorerUtil.createChild(parent, "env-entry");
storeEnvEntry(entry, entries[i]);
}
}
static void storeEnvEntry(Element parent, EnvEntry entry) {
StorerUtil.createChildText(parent, "env-entry-name", entry.getEnvEntryName());
StorerUtil.createChildText(parent, "env-entry-type", entry.getEnvEntryType());
StorerUtil.createOptionalChildText(parent, "env-entry-value", entry.getEnvEntryValue());
}
public static void storeEJBRefs(Element parent, EJBRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "ejb-ref");
storeEJBRef(ref, refs[i]);
}
}
static void storeEJBRef(Element parent, EJBRef ref) {
StorerUtil.createChildText(parent, "ejb-ref-name", ref.getEJBRefName());
StorerUtil.createChildText(parent, "ejb-ref-type", ref.getEJBRefType());
StorerUtil.createChildText(parent, "home", ref.getHome());
StorerUtil.createChildText(parent, "remote", ref.getRemote());
StorerUtil.createOptionalChildText(parent, "ejb-link", ref.getEJBLink());
}
public static void storeEJBLocalRefs(Element parent, EJBLocalRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "ejb-local-ref");
storeEJBLocalRef(ref, refs[i]);
}
}
static void storeEJBLocalRef(Element parent, EJBLocalRef ref) {
StorerUtil.createChildText(parent, "ejb-ref-name", ref.getEJBRefName());
StorerUtil.createChildText(parent, "ejb-ref-type", ref.getEJBRefType());
StorerUtil.createChildText(parent, "local-home", ref.getLocalHome());
StorerUtil.createChildText(parent, "local", ref.getLocal());
StorerUtil.createOptionalChildText(parent, "ejb-link", ref.getEJBLink());
}
public static void storeResourceRefs(Element parent, ResourceRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "resource-ref");
storeResourceRef(ref, refs[i]);
}
}
static void storeResourceRef(Element parent, ResourceRef ref) {
StorerUtil.createChildText(parent, "res-ref-name", ref.getResRefName());
StorerUtil.createChildText(parent, "res-type", ref.getResType());
StorerUtil.createChildText(parent, "res-auth", ref.getResAuth());
StorerUtil.createOptionalChildText(parent, "res-sharing-scope", ref.getResSharingScope());
}
public static void storeResourceEnvRefs(Element parent, ResourceEnvRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "resource-env-ref");
storeResourceEnvRef(ref, refs[i]);
}
}
static void storeResourceEnvRef(Element parent, ResourceEnvRef ref) {
StorerUtil.createChildText(parent, "resource-env-ref-name", ref.getResourceEnvRefName());
StorerUtil.createChildText(parent, "resource-env-ref-type", ref.getResourceEnvRefType());
}
public static void storeMessageDestinationRefs(Element parent, MessageDestinationRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "message-destination-ref");
storeMessageDestinationRef(ref, refs[i]);
}
}
static void storeMessageDestinationRef(Element parent, MessageDestinationRef ref) {
storeDescribable(parent, ref);
StorerUtil.createChildText(parent, "message-destination-ref-name", ref.getMessageDestinationRefName());
StorerUtil.createChildText(parent, "message-destination-type", ref.getMessageDestinationType());
StorerUtil.createChildText(parent, "message-destination-usage", ref.getMessageDestinationUsage());
StorerUtil.createOptionalChildText(parent, "message-destination-link", ref.getMessageDestinationLink());
}
public static void storeServiceRefs(Element parent, ServiceRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "service-ref");
storeServiceRef(ref, refs[i]);
}
}
static void storeServiceRef(Element parent, ServiceRef ref) {
StorerUtil.createChildText(parent, "service-ref-name", ref.getServiceRefName());
StorerUtil.createChildText(parent, "service-interface", ref.getServiceInterface());
StorerUtil.createOptionalChildText(parent, "wsdl-file", ref.getWSDLFile());
StorerUtil.createOptionalChildText(parent, "jaxrpc-mapping-file", ref.getJAXRPCMappingFile());
StorerUtil.createOptionalChildText(parent, "service-qname", ref.getServiceQName());
storePortComponentRefs(parent, ref.getPortComponentRef());
storeHandlers(parent, ref.getHandler());
}
static void storePortComponentRefs(Element parent, PortComponentRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element ref = StorerUtil.createChild(parent, "port-component-ref");
storePortComponentRef(ref, refs[i]);
}
}
static void storePortComponentRef(Element parent, PortComponentRef ref) {
StorerUtil.createChildText(parent, "service-endpoint-interface", ref.getServiceEndpointInterface());
StorerUtil.createOptionalChildText(parent, "port-component-link", ref.getPortComponentLink());
}
static void storeHandlers(Element parent, Handler[] handlers) {
for(int i = 0; i < handlers.length; i++) {
Element ref = StorerUtil.createChild(parent, "handler");
storeHandler(ref, handlers[i]);
}
}
static void storeHandler(Element parent, Handler handler) {
storeDisplayable(parent, handler);
StorerUtil.createChildText(parent, "handler-name", handler.getHandlerName());
StorerUtil.createChildText(parent, "handler-class", handler.getHandlerClass());
storeParamValue(parent, handler.getInitParam(), "init-param");
for(int i = 0; i < handler.getSoapHeader().length; i++) {
StorerUtil.createChildText(parent, "soap-header", handler.getSoapHeader(i));
}
for(int i = 0; i < handler.getSoapRole().length; i++) {
StorerUtil.createChildText(parent, "soap-role", handler.getSoapRole(i));
}
for(int i = 0; i < handler.getPortName().length; i++) {
StorerUtil.createChildText(parent, "port-name", handler.getPortName(i));
}
}
public static void storeParamValue(Element parent, ParamValue[] param, String name) {
for(int i = 0; i < param.length; i++) {
Element e = StorerUtil.createChild(parent, name);
storeDescribable(e, param[i]);
StorerUtil.createChildText(parent, "param-name", param[i].getParamName());
StorerUtil.createChildText(parent, "param-value", param[i].getParamValue());
}
}
static void storeSecurityRoleRefs(Element parent, SecurityRoleRef[] refs) {
for(int i = 0; i < refs.length; i++) {
Element e = StorerUtil.createChild(parent, "security-role-ref");
storeSecurityRoleRef(e, refs[i]);
}
}
static void storeSecurityRoleRef(Element parent, SecurityRoleRef ref) {
storeDescribable(parent, ref);
StorerUtil.createChildText(parent, "role-name", ref.getRoleName());
StorerUtil.createOptionalChildText(parent, "role-link", ref.getRoleName());
}
}
1.1 incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/StorerUtil.java
Index: StorerUtil.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" 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",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* 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.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import java.io.Writer;
import java.util.Properties;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
/**
* Holds utility methods for writing to a DOM tree
*
* @version $Revision: 1.1 $ $Date: 2003/10/01 19:03:40 $
*/
public class StorerUtil {
/**
* Creates a new child of the specified element, adds it as a child, and
* returns it.
*
* @param parent The parent element for the new child
* @param name The name of the new child element
*
* @return The created and added child element
*/
public static Element createChild(Element parent, String name) {
Element elem = parent.getOwnerDocument().createElement(name);
parent.appendChild(elem);
return elem;
}
/**
* Creates a new child of the specified element, adds it as a child, and
* sets the specified value to be its text content.
*
* @param parent The parent element for the new child
* @param name The name of the new child element
* @param value The text to set on the new element
*/
public static void createChildText(Element parent, String name, String value) {
Element child = parent.getOwnerDocument().createElement(name);
parent.appendChild(child);
setText(child, value);
}
/**
* Creates a new child of the specified element if the specified value is
* not empty, adds it as a child, and sets the value to be its text
* content. If the value is null or an empty String, nothing is done.
*
* @param parent The parent element for the new child
* @param name The name of the new child element
* @param value The text to set on the new element
*/
public static void createOptionalChildText(Element parent, String name, String value) {
if(value == null || value.equals(""))
return;
Element child = parent.getOwnerDocument().createElement(name);
parent.appendChild(child);
setText(child, value);
}
/**
* Utility method to store the contents of a DOM Document to a stream.
*
* @param doc The document to store
* @param out The stream to write to
*
* @throws javax.xml.transform.TransformerException Occurs when the writing did not complete
* successfully
*/
public static void writeXML(Document doc, Writer out) throws TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Properties props = new Properties();
props.put(OutputKeys.INDENT, "yes");
props.put(OutputKeys.METHOD, "xml");
props.put(OutputKeys.OMIT_XML_DECLARATION, "no");
props.put(OutputKeys.VERSION, "1.0");
transformer.setOutputProperties(props);
transformer.transform(new DOMSource(doc), new StreamResult(out));
}
/**
* Utility method to create an empty Document to work with.
*/
public static Document createDocument() throws ParserConfigurationException {
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
fac.setValidating(true);
fac.setNamespaceAware(true);
fac.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
DocumentBuilder builder = fac.newDocumentBuilder();
builder.setEntityResolver(new LocalEntityResolver());
return builder.newDocument();
}
/**
* Sets the text for an element, removing any text that used to be there.
*/
public static void setText(Element e, String s) {
boolean cdata = s != null && (s.indexOf('>') > -1 ||
s.indexOf('<') > -1 ||
s.indexOf('&') > -1);
NodeList nl = e.getChildNodes();
boolean found = false;
int max = nl.getLength();
if(cdata) {
for(int i=0; i<max; i++) {
Node n = nl.item(i);
if(n.getNodeType() == Node.TEXT_NODE) {
e.removeChild(n);
} else if(n.getNodeType() == Node.CDATA_SECTION_NODE) {
if(!found) {
n.setNodeValue(s);
found = true;
} else {
e.removeChild(n);
}
}
}
if(!found) {
e.appendChild(e.getOwnerDocument().createCDATASection(s));
}
} else {
for(int i=0; i<max; i++) {
Node n = nl.item(i);
if(n.getNodeType() == Node.TEXT_NODE) {
if(!found) {
n.setNodeValue(s);
found = true;
} else {
e.removeChild(n);
}
} else if(n.getNodeType() == Node.CDATA_SECTION_NODE) {
e.removeChild(n);
}
}
if(!found) {
e.appendChild(e.getOwnerDocument().createTextNode(s == null ? "" : s));
}
}
}
/**
* Creates a child element in the specified namespace with the specified
* value as its text contents.
*
* @param elem The parent element for the new child
* @param qualifiedName The namespace-qualified element name (i.e. <tt>foo:someElement</tt>)
* @param namespace The namespace URI that the prefix on the qualified name should
* map to (i.e. <tt>http://somewhere</tt> with the qualifiedName
* <tt>foo:someElement</tt> means <tt>foo</tt> = <tt>http://somewhere</tt>)
* @param value The text value to use as the content of the new element
*/
public static void createChildTextWithNS(Element elem, String qualifiedName, String namespace, String value) {
Element child = elem.getOwnerDocument().createElementNS(namespace, qualifiedName);
elem.appendChild(child);
setText(child, value);
}
/**
* If the value is not empty/null, creates a child element in the specified
* namespace with the specified value as its text contents.
*
* @param elem The parent element for the new child
* @param qualifiedName The namespace-qualified element name (i.e. <tt>foo:someElement</tt>)
* @param namespace The namespace URI that the prefix on the qualified name should
* map to (i.e. <tt>http://somewhere</tt> with the qualifiedName
* <tt>foo:someElement</tt> means <tt>foo</tt> = <tt>http://somewhere</tt>)
* @param value The text value to use as the content of the new element
*/
public static void createOptionalChildTextWithNS(Element elem, String qualifiedName, String namespace, String value) {
if(value == null || value.equals(""))
return;
Element child = elem.getOwnerDocument().createElementNS(namespace, qualifiedName);
elem.appendChild(child);
setText(child, value);
}
}
1.3 +7 -3 incubator-geronimo/modules/core/src/test/org/apache/geronimo/xml/deployment/GeronimoEjbJarLoaderTest.java
Index: GeronimoEjbJarLoaderTest.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/xml/deployment/GeronimoEjbJarLoaderTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GeronimoEjbJarLoaderTest.java 29 Sep 2003 19:32:23 -0000 1.2
+++ GeronimoEjbJarLoaderTest.java 1 Oct 2003 19:03:40 -0000 1.3
@@ -81,6 +81,10 @@
File f = new File(docDir, "simple-geronimo-ejb-jar.xml");
Document xmlDoc = LoaderUtil.parseXML(new FileReader(f));
GeronimoEjbJarDocument doc = loader.load(xmlDoc);
+ checkGeronimoJar(doc);
+ }
+
+ static void checkGeronimoJar(GeronimoEjbJarDocument doc) {
EjbJar jar = doc.getEjbJar();
EjbJarLoaderTest.checkEjbJar(jar, "OverrideExample");
EnterpriseBeans beans = jar.getGeronimoEnterpriseBeans();
@@ -92,7 +96,7 @@
checkStateful(session[1]);
}
- private void checkStateless(Session session) {
+ static void checkStateless(Session session) {
assertEquals("StatelessTest", session.getEJBName());
assertEquals("StatelessTestJNDI", session.getJndiName());
@@ -109,7 +113,7 @@
assertEquals("java:jdbc/MyDatabase", resEnvRef.getJndiName());
}
- private void checkStateful(Session session) {
+ static void checkStateful(Session session) {
assertEquals("StatefulTest", session.getEJBName());
assertEquals("StatefulTestJNDI", session.getJndiName());
1.1 incubator-geronimo/modules/core/src/test/org/apache/geronimo/xml/deployment/EjbJarStorerTest.java
Index: EjbJarStorerTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" 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",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* 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.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import org.w3c.dom.Document;
import org.apache.geronimo.deployment.model.ejb.EjbJarDocument;
import org.apache.geronimo.deployment.model.ejb.EjbJar;
import junit.framework.TestCase;
/**
* Tests for storing an EJB JAR
*
* @version $Revision: 1.1 $ $Date: 2003/10/01 19:03:40 $
*/
public class EjbJarStorerTest extends TestCase {
private File docDir;
private EjbJarLoader loader;
private EjbJarStorer storer;
protected void setUp() throws Exception {
docDir = new File("src/test-data/xml/deployment");
loader = new EjbJarLoader();
storer = new EjbJarStorer();
}
public void testLoadStoreLoad() throws Exception {
File f = new File(docDir, "simple-ejb-jar.xml");
Document xmlDoc = LoaderUtil.parseXML(new FileReader(f));
EjbJarDocument doc = loader.load(xmlDoc);
EjbJar jar = doc.getEjbJar();
EjbJarLoaderTest.checkEjbJar(jar, "example");
File of = new File(docDir, "test-copy-ejb-jar.xml");
FileWriter out = new FileWriter(of);
storer.store(doc, out);
out.flush();
out.close();
f = new File(docDir, "test-copy-ejb-jar.xml");
xmlDoc = LoaderUtil.parseXML(new FileReader(f));
doc = loader.load(xmlDoc);
jar = doc.getEjbJar();
EjbJarLoaderTest.checkEjbJar(jar, "example");
}
}
1.1 incubator-geronimo/modules/core/src/test/org/apache/geronimo/xml/deployment/GeronimoEjbJarStorerTest.java
Index: GeronimoEjbJarStorerTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" 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",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* 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.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import org.w3c.dom.Document;
import org.apache.geronimo.deployment.model.geronimo.ejb.GeronimoEjbJarDocument;
import junit.framework.TestCase;
/**
* Tests for storing a Geronimo EJB JAR
*
* @version $Revision: 1.1 $ $Date: 2003/10/01 19:03:40 $
*/
public class GeronimoEjbJarStorerTest extends TestCase {
private File docDir;
private GeronimoEjbJarLoader loader;
private GeronimoEjbJarStorer storer;
protected void setUp() throws Exception {
docDir = new File("src/test-data/xml/deployment");
loader = new GeronimoEjbJarLoader();
storer = new GeronimoEjbJarStorer();
}
public void testLoadStoreLoad() throws Exception {
File f = new File(docDir, "simple-geronimo-ejb-jar.xml");
Document xmlDoc = LoaderUtil.parseXML(new FileReader(f));
GeronimoEjbJarDocument doc = loader.load(xmlDoc);
GeronimoEjbJarLoaderTest.checkGeronimoJar(doc);
File of = new File(docDir, "test-copy-geronimo-ejb-jar.xml");
FileWriter out = new FileWriter(of);
storer.store(doc, out);
out.flush();
out.close();
f = new File(docDir, "test-copy-geronimo-ejb-jar.xml");
xmlDoc = LoaderUtil.parseXML(new FileReader(f));
doc = loader.load(xmlDoc);
GeronimoEjbJarLoaderTest.checkGeronimoJar(doc);
}
}
1.1 incubator-geronimo/modules/core/src/test-data/xml/deployment/.cvsignore
Index: .cvsignore
===================================================================
test-copy-ejb-jar.xml
test-copy-geronimo-ejb-jar.xml