Author: rmannibucau
Date: Wed May 2 20:41:20 2012
New Revision: 1333187
URL: http://svn.apache.org/viewvc?rev=1333187&view=rev
Log:
TOMEE-183 some refactoring to avoid duplicated code reading descriptors
Modified:
openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
openejb/trunk/openejb/pom.xml
openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml
openejb/trunk/openejb/server/openejb-cxf-transport/pom.xml
openejb/trunk/openejb/server/openejb-cxf/pom.xml
Modified:
openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java?rev=1333187&r1=1333186&r2=1333187&view=diff
==============================================================================
---
openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
(original)
+++
openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
Wed May 2 20:41:20 2012
@@ -1,5 +1,6 @@
package org.apache.openejb.arquillian.openejb;
+import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -10,17 +11,14 @@ import java.util.logging.Logger;
import org.apache.openejb.config.AppModule;
import org.apache.openejb.config.EjbModule;
import org.apache.openejb.config.PersistenceModule;
-import org.apache.openejb.config.sys.JaxbOpenejb;
-import org.apache.openejb.jee.Beans;
+import org.apache.openejb.config.ReadDescriptors;
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.JaxbJavaee;
import org.apache.openejb.jee.ManagedBean;
import org.apache.openejb.jee.TransactionType;
-import org.apache.openejb.jee.bval.ValidationConfigType;
import org.apache.openejb.jee.jpa.unit.JaxbPersistenceFactory;
import org.apache.openejb.jee.jpa.unit.Persistence;
import org.apache.openejb.jee.oejb3.EjbDeployment;
-import org.apache.openejb.jee.oejb3.JaxbOpenejbJar3;
import org.apache.openejb.jee.oejb3.OpenejbJar;
import org.apache.openejb.loader.IO;
import org.apache.openejb.util.LengthInputStream;
@@ -34,20 +32,20 @@ import org.jboss.arquillian.test.spi.ann
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.Node;
+import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.impl.base.filter.IncludeRegExpPaths;
public class OpenEJBArchiveProcessor implements ApplicationArchiveProcessor {
private static final Logger LOGGER =
Logger.getLogger(OpenEJBArchiveProcessor.class.getName());
private static final String META_INF = "META-INF/";
- public static final String ENV_ENTRIES_PROPERTIES_NAME =
"env-entries.properties";
+ private static final String EJB_JAR_XML = "ejb-jar.xml";
- private static final String BEANS_XML = META_INF.concat("beans.xml");
- private static final String EJB_JAR_XML = META_INF.concat("ejb-jar.xml");
- private static final String VALIDATION_XML =
META_INF.concat("validation.xml");
- private static final String PERSISTENCE_XML =
META_INF.concat("persistence.xml");
- private static final String OPENEJB_JAR_XML =
META_INF.concat("openejb-jar.xml");
- private static final String ENV_ENTRIES_PROPERTIES =
META_INF.concat(ENV_ENTRIES_PROPERTIES_NAME);
+ private static final String BEANS_XML = "beans.xml";
+ private static final String VALIDATION_XML = "validation.xml";
+ private static final String PERSISTENCE_XML = "persistence.xml";
+ private static final String OPENEJB_JAR_XML = "openejb-jar.xml";
+ private static final String ENV_ENTRIES_PROPERTIES =
"env-entries.properties";
@Inject
@SuiteScoped
@@ -72,7 +70,7 @@ public class OpenEJBArchiveProcessor imp
final org.apache.xbean.finder.archive.Archive finderArchive =
finderArchive(archive, appModule.getClassLoader());
final EjbJar ejbJar;
- final Node ejbJarXml = archive.get(EJB_JAR_XML);
+ final Node ejbJarXml = archive.get(META_INF.concat(EJB_JAR_XML));
if (ejbJarXml != null) {
EjbJar readEjbJar = null;
LengthInputStream lis = null;
@@ -98,27 +96,14 @@ public class OpenEJBArchiveProcessor imp
appModule.getEjbModules().add(ejbModule);
{
- final Node beansXml = archive.get(BEANS_XML);
+ final Node beansXml = archive.get(META_INF.concat(BEANS_XML));
if (beansXml != null) {
- LengthInputStream lis = null;
- try {
- lis = new
LengthInputStream(beansXml.getAsset().openStream());
- final Beans beans = (Beans)
JaxbJavaee.unmarshalJavaee(Beans.class, lis);
- ejbModule.setBeans(beans);
- } catch (Exception e) {
- if (lis != null && lis.getLength() == 0) {
- ejbModule.setBeans(new Beans());
- } else {
- LOGGER.log(Level.SEVERE, "can't read beans.xml", e);
- }
- } finally {
- IO.close(lis);
- }
+ ejbModule.getAltDDs().put(BEANS_XML, new
AssetSource(beansXml.getAsset()));
}
}
{
- final Node persistenceXml = archive.get(PERSISTENCE_XML);
+ final Node persistenceXml =
archive.get(META_INF.concat(PERSISTENCE_XML));
if (persistenceXml != null) {
String rootUrl =
persistenceXml.getPath().getParent().getParent().get();
if ("/".equals(rootUrl)) {
@@ -141,49 +126,31 @@ public class OpenEJBArchiveProcessor imp
}
{
- final Node openejbJarXml = archive.get(OPENEJB_JAR_XML);
+ final Node openejbJarXml =
archive.get(META_INF.concat(OPENEJB_JAR_XML));
if (openejbJarXml != null) {
- InputStream is = null;
- try {
- is = openejbJarXml.getAsset().openStream();
- final OpenejbJar openejbJar =
JaxbOpenejbJar3.unmarshal(OpenejbJar.class, is);
- ejbModule.setOpenejbJar(openejbJar);
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, "can't read openejb-jar.xml", e);
- } finally {
- IO.close(is);
- }
+ ejbModule.getAltDDs().put(OPENEJB_JAR_XML, new
AssetSource(openejbJarXml.getAsset()));
}
}
{
- final Node validationXml = archive.get(VALIDATION_XML);
+ final Node validationXml =
archive.get(META_INF.concat(VALIDATION_XML));
if (validationXml != null) {
- InputStream is = null;
- try {
- is = validationXml.getAsset().openStream();
- final ValidationConfigType validation =
JaxbOpenejb.unmarshal(ValidationConfigType.class, is, false);
- ejbModule.setValidationConfig(validation);
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, "can't read validation.xml", e);
- } finally {
- IO.close(is);
- }
+ ejbModule.getAltDDs().put(VALIDATION_XML, new
AssetSource(validationXml.getAsset()));
}
}
{
- final Node envEntriesProperties =
archive.get(ENV_ENTRIES_PROPERTIES);
+ final Node envEntriesProperties =
archive.get(META_INF.concat(ENV_ENTRIES_PROPERTIES));
if (envEntriesProperties != null) {
InputStream is = null;
final Properties properties = new Properties();
try {
is = envEntriesProperties.getAsset().openStream();
properties.load(is);
- ejbModule.getAltDDs().put(ENV_ENTRIES_PROPERTIES_NAME,
properties);
+ ejbModule.getAltDDs().put(ENV_ENTRIES_PROPERTIES,
properties);
// do it for test class too
-
appModule.getEjbModules().iterator().next().getAltDDs().put(ENV_ENTRIES_PROPERTIES_NAME,
properties);
+
appModule.getEjbModules().iterator().next().getAltDDs().put(ENV_ENTRIES_PROPERTIES,
properties);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "can't read
env-entries.properties", e);
} finally {
@@ -192,8 +159,6 @@ public class OpenEJBArchiveProcessor imp
}
}
- // "env-entries.properties"
-
// export it to be usable in the container
module.set(appModule);
}
@@ -216,4 +181,17 @@ public class OpenEJBArchiveProcessor imp
final String name = raw.replace('/', '.');
return name.substring(1, name.length() - 6);
}
+
+ private static class AssetSource implements ReadDescriptors.Source {
+ private Asset asset;
+
+ private AssetSource(Asset asset) {
+ this.asset = asset;
+ }
+
+ @Override
+ public InputStream get() throws IOException {
+ return asset.openStream();
+ }
+ }
}
Modified:
openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java?rev=1333187&r1=1333186&r2=1333187&view=diff
==============================================================================
---
openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
(original)
+++
openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
Wed May 2 20:41:20 2012
@@ -78,7 +78,7 @@ public class OpenEJBDeployableContainer
@Override
public void start() throws LifecycleException {
- // todo: manage properties (aquillian.xml/annotation on test)
+ // todo: manage properties (aquillian.xml)
try {
initialContext = new InitialContext(PROPERTIES);
} catch (NamingException e) {
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=1333187&r1=1333186&r2=1333187&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
Wed May 2 20:41:20 2012
@@ -263,14 +263,14 @@ public class ReadDescriptors implements
if (module.getValidationConfig() != null) {
return;
}
- URL url = getUrl(module, "validation.xml");
- if (url != null) {
- ValidationConfigType validationConfigType;
+
+ final Source value =
getSource(module.getAltDDs().get("validation.xml"));
+ if (value != null) {
try {
- validationConfigType =
JaxbOpenejb.unmarshal(ValidationConfigType.class, IO.read(url), false);
+ ValidationConfigType validationConfigType =
JaxbOpenejb.unmarshal(ValidationConfigType.class, ((Source) value).get(),
false);
module.setValidationConfig(validationConfigType);
} catch (Exception e) {
- logger.warning("can't read " + url.toString() + " to construct
a validation factory, it will be ignored");
+ logger.warning("can't read validation.xml to construct a
validation factory, it will be ignored");
}
}
}
@@ -394,16 +394,17 @@ public class ReadDescriptors implements
}
}
- private void readEjbJar(EjbModule ejbModule, AppModule appModule) throws
OpenEJBException {
+ public void readEjbJar(EjbModule ejbModule, AppModule appModule) throws
OpenEJBException {
if (ejbModule.getEjbJar() != null) return;
- Object data = ejbModule.getAltDDs().get("ejb-jar.xml");
- if (data instanceof EjbJar) {
- ejbModule.setEjbJar((EjbJar) data);
- } else if (data instanceof URL) {
- URL url = (URL) data;
- EjbJar ejbJar = readEjbJar(url);
- ejbModule.setEjbJar(ejbJar);
+ final Source data =
getSource(ejbModule.getAltDDs().get("ejb-jar.xml"));
+ if (data != null) {
+ try {
+ EjbJar ejbJar = readEjbJar(((Source) data).get());
+ ejbModule.setEjbJar(ejbJar);
+ } catch (IOException e) {
+ throw new OpenEJBException(e);
+ }
} else {
DeploymentLoader.logger.debug("No ejb-jar.xml found assuming
annotated beans present: " + appModule.getJarLocation() + ", module: " +
ejbModule.getModuleId());
ejbModule.setEjbJar(new EjbJar());
@@ -413,13 +414,14 @@ public class ReadDescriptors implements
private void readBeans(EjbModule ejbModule, AppModule appModule) throws
OpenEJBException {
if (ejbModule.getBeans() != null) return;
- Object data = ejbModule.getAltDDs().get("beans.xml");
- if (data instanceof Beans) {
- ejbModule.setBeans((Beans) data);
- } else if (data instanceof URL) {
- URL url = (URL) data;
- Beans beans = readBeans(url);
- ejbModule.setBeans(beans);
+ final Source data = getSource(ejbModule.getAltDDs().get("beans.xml"));
+ if (data != null) {
+ try {
+ Beans beans = readBeans(((Source) data).get());
+ ejbModule.setBeans(beans);
+ } catch (IOException e) {
+ throw new OpenEJBException(e);
+ }
} else {
// DeploymentLoader.logger.debug("No beans.xml found assuming
annotated beans present: " + appModule.getJarLocation() + ", module: " +
ejbModule.getModuleId());
// ejbModule.setBeans(new Beans());
@@ -495,46 +497,46 @@ public class ReadDescriptors implements
return applicationClient;
}
- public static EjbJar readEjbJar(URL url) throws OpenEJBException {
+ public static EjbJar readEjbJar(final InputStream is) throws
OpenEJBException {
try {
- if (isEmptyEjbJar(url)) return new EjbJar();
- return (EjbJar) JaxbJavaee.unmarshalJavaee(EjbJar.class,
IO.read(url));
+ if (isEmptyEjbJar(is)) return new EjbJar();
+ return (EjbJar) JaxbJavaee.unmarshalJavaee(EjbJar.class, is);
} catch (SAXException e) {
- throw new OpenEJBException("Cannot parse the ejb-jar.xml file: " +
url.toExternalForm(), e);
+ throw new OpenEJBException("Cannot parse the ejb-jar.xml"); //
file: " + url.toExternalForm(), e);
} catch (JAXBException e) {
- throw new OpenEJBException("Cannot unmarshall the ejb-jar.xml
file: " + url.toExternalForm(), e);
+ throw new OpenEJBException("Cannot unmarshall the ejb-jar.xml");
// file: " + url.toExternalForm(), e);
} catch (IOException e) {
- throw new OpenEJBException("Cannot read the ejb-jar.xml file: " +
url.toExternalForm(), e);
+ throw new OpenEJBException("Cannot read the ejb-jar.xml"); //
file: " + url.toExternalForm(), e);
} catch (Exception e) {
- throw new OpenEJBException("Encountered unknown error parsing the
ejb-jar.xml file: " + url.toExternalForm(), e);
+ throw new OpenEJBException("Encountered unknown error parsing the
ejb-jar.xml"); // file: " + url.toExternalForm(), e);
}
}
- public static Beans readBeans(URL url) throws OpenEJBException {
+ public static Beans readBeans(final InputStream inputStream) throws
OpenEJBException {
try {
- if (isEmptyBeansXml(url)) return new Beans();
- return (Beans) JaxbJavaee.unmarshalJavaee(Beans.class,
IO.read(url));
+ if (isEmptyBeansXml(inputStream)) return new Beans();
+ return (Beans) JaxbJavaee.unmarshalJavaee(Beans.class,
inputStream);
} catch (SAXException e) {
- throw new OpenEJBException("Cannot parse the beans.xml file: " +
url.toExternalForm(), e);
+ throw new OpenEJBException("Cannot parse the beans.xml");// file:
" + url.toExternalForm(), e);
} catch (JAXBException e) {
- throw new OpenEJBException("Cannot unmarshall the beans.xml file:
" + url.toExternalForm(), e);
+ throw new OpenEJBException("Cannot unmarshall the beans.xml");//
file: " + url.toExternalForm(), e);
} catch (IOException e) {
- throw new OpenEJBException("Cannot read the beans.xml file: " +
url.toExternalForm(), e);
+ throw new OpenEJBException("Cannot read the beans.xml");// file: "
+ url.toExternalForm(), e);
} catch (Exception e) {
- throw new OpenEJBException("Encountered unknown error parsing the
beans.xml file: " + url.toExternalForm(), e);
+ throw new OpenEJBException("Encountered unknown error parsing the
beans.xml");// file: " + url.toExternalForm(), e);
}
}
- private static boolean isEmptyEjbJar(URL url) throws IOException,
ParserConfigurationException, SAXException {
- return isEmpty(url, "ejb-jar");
+ private static boolean isEmptyEjbJar(final InputStream is) throws
IOException, ParserConfigurationException, SAXException {
+ return isEmpty(is, "ejb-jar");
}
- private static boolean isEmptyBeansXml(URL url) throws IOException,
ParserConfigurationException, SAXException {
- return isEmpty(url, "beans");
+ private static boolean isEmptyBeansXml(final InputStream is) throws
IOException, ParserConfigurationException, SAXException {
+ return isEmpty(is, "beans");
}
- private static boolean isEmpty(URL url, final String rootElement) throws
IOException, ParserConfigurationException, SAXException {
- final LengthInputStream in = new LengthInputStream(IO.read(url));
+ private static boolean isEmpty(final InputStream is, final String
rootElement) throws IOException, ParserConfigurationException, SAXException {
+ final LengthInputStream in = new LengthInputStream(is);
InputSource inputSource = new InputSource(in);
SAXParserFactory factory = SAXParserFactory.newInstance();
@@ -725,30 +727,32 @@ public class ReadDescriptors implements
return null;
}
- public static abstract class Source {
- abstract InputStream get() throws IOException;
+ public interface Source {
+ InputStream get() throws IOException;
}
- public static class UrlSource extends Source {
+ public static class UrlSource implements Source {
private final URL url;
public UrlSource(URL url) {
this.url = url;
}
- InputStream get() throws IOException {
+ @Override
+ public InputStream get() throws IOException {
return IO.read(url);
}
}
- public static class StringSource extends Source {
+ public static class StringSource implements Source {
private byte[] bytes;
public StringSource(String content) {
bytes = content.getBytes();
}
- InputStream get() throws IOException {
+ @Override
+ public InputStream get() throws IOException {
return new ByteArrayInputStream(bytes);
}
}
Modified: openejb/trunk/openejb/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/pom.xml?rev=1333187&r1=1333186&r2=1333187&view=diff
==============================================================================
--- openejb/trunk/openejb/pom.xml (original)
+++ openejb/trunk/openejb/pom.xml Wed May 2 20:41:20 2012
@@ -118,7 +118,7 @@
<tomcat.version>7.0.27</tomcat.version>
<!-- used mainly by jetty modules -->
- <openejb-cxf.version>2.6.0-SNAPSHOT</openejb-cxf.version>
+ <openejb-cxf.version>2.6.0</openejb-cxf.version>
<jetty.version>7.5.3.v20111011</jetty.version>
<pax-url.version>1.3.5</pax-url.version>
<aether.version>1.13.1</aether.version>
@@ -757,8 +757,8 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.apache.openejb.patch</groupId>
- <artifactId>openejb-cxf-bundle</artifactId>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-bundle</artifactId>
<version>${openejb-cxf.version}</version>
</dependency>
<dependency>
Modified: openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml?rev=1333187&r1=1333186&r2=1333187&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml (original)
+++ openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml Wed May 2 20:41:20 2012
@@ -47,8 +47,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.openejb.patch</groupId>
- <artifactId>openejb-cxf-bundle</artifactId>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-bundle</artifactId>
<exclusions>
<exclusion>
<groupId>antlr</groupId>
Modified: openejb/trunk/openejb/server/openejb-cxf-transport/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-transport/pom.xml?rev=1333187&r1=1333186&r2=1333187&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-cxf-transport/pom.xml (original)
+++ openejb/trunk/openejb/server/openejb-cxf-transport/pom.xml Wed May 2
20:41:20 2012
@@ -33,8 +33,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.openejb.patch</groupId>
- <artifactId>openejb-cxf-bundle</artifactId>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-bundle</artifactId>
<exclusions>
<exclusion>
<groupId>antlr</groupId>
Modified: openejb/trunk/openejb/server/openejb-cxf/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf/pom.xml?rev=1333187&r1=1333186&r2=1333187&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-cxf/pom.xml (original)
+++ openejb/trunk/openejb/server/openejb-cxf/pom.xml Wed May 2 20:41:20 2012
@@ -84,8 +84,8 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.openejb.patch</groupId>
- <artifactId>openejb-cxf-bundle</artifactId>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-bundle</artifactId>
<exclusions>
<exclusion>
<groupId>antlr</groupId>