Author: djencks
Date: Sun Jun 27 06:44:07 2010
New Revision: 958340
URL: http://svn.apache.org/viewvc?rev=958340&view=rev
Log:
Since there are getting to be more and more marshal methods, give the original
javaee one a better name
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/SunCmpConversionTest.java
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=958340&r1=958339&r2=958340&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
Sun Jun 27 06:44:07 2010
@@ -1118,7 +1118,7 @@ public class DeploymentLoader {
@SuppressWarnings({"unchecked"})
public static <T>T unmarshal(Class<T> type, String descriptor, URL url)
throws OpenEJBException {
try {
- return (T) JaxbJavaee.unmarshal(type, url.openStream());
+ return (T) JaxbJavaee.unmarshalJavaee(type, url.openStream());
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the " + descriptor + "
file: "+ url.toExternalForm(), e);
} catch (JAXBException e) {
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=958340&r1=958339&r2=958340&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
Sun Jun 27 06:44:07 2010
@@ -263,7 +263,7 @@ public class ReadDescriptors implements
} else if (data instanceof URL) {
URL url = (URL) data;
try {
- EntityMappings entitymappings = (EntityMappings)
JaxbJavaee.unmarshal(EntityMappings.class, url.openStream());
+ EntityMappings entitymappings = (EntityMappings)
JaxbJavaee.unmarshalJavaee(EntityMappings.class, url.openStream());
ejbModule.getAltDDs().put("openejb-cmp-orm.xml",
entitymappings);
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the
openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
@@ -312,7 +312,7 @@ public class ReadDescriptors implements
public static ApplicationClient readApplicationClient(URL url) throws
OpenEJBException {
ApplicationClient applicationClient;
try {
- applicationClient = (ApplicationClient)
JaxbJavaee.unmarshal(ApplicationClient.class, url.openStream());
+ applicationClient = (ApplicationClient)
JaxbJavaee.unmarshalJavaee(ApplicationClient.class, url.openStream());
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the
application-client.xml file: "+ url.toExternalForm(), e);
} catch (JAXBException e) {
@@ -328,7 +328,7 @@ public class ReadDescriptors implements
public static EjbJar readEjbJar(URL url) throws OpenEJBException {
try {
if (isEmptyEjbJar(url)) return new EjbJar();
- return (EjbJar) JaxbJavaee.unmarshal(EjbJar.class,
url.openStream());
+ return (EjbJar) JaxbJavaee.unmarshalJavaee(EjbJar.class,
url.openStream());
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the ejb-jar.xml file: " +
url.toExternalForm(), e);
} catch (JAXBException e) {
@@ -367,7 +367,7 @@ public class ReadDescriptors implements
public static Webservices readWebservices(URL url) throws OpenEJBException
{
Webservices webservices;
try {
- webservices = (Webservices)
JaxbJavaee.unmarshal(Webservices.class, url.openStream());
+ webservices = (Webservices)
JaxbJavaee.unmarshalJavaee(Webservices.class, url.openStream());
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the webservices.xml file:
" + url.toExternalForm(), e);
} catch (JAXBException e) {
@@ -383,7 +383,7 @@ public class ReadDescriptors implements
public static HandlerChains readHandlerChains(URL url) throws
OpenEJBException {
HandlerChains handlerChains;
try {
- handlerChains = (HandlerChains)
JaxbJavaee.unmarshal(HandlerChains.class, url.openStream());
+ handlerChains = (HandlerChains)
JaxbJavaee.unmarshalJavaee(HandlerChains.class, url.openStream());
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the webservices.xml file:
" + url.toExternalForm(), e);
} catch (JAXBException e) {
@@ -399,7 +399,7 @@ public class ReadDescriptors implements
public static JavaWsdlMapping readJaxrpcMapping(URL url) throws
OpenEJBException {
JavaWsdlMapping wsdlMapping;
try {
- wsdlMapping = (JavaWsdlMapping)
JaxbJavaee.unmarshal(JavaWsdlMapping.class, url.openStream());
+ wsdlMapping = (JavaWsdlMapping)
JaxbJavaee.unmarshalJavaee(JavaWsdlMapping.class, url.openStream());
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the JaxRPC mapping file:
" + url.toExternalForm(), e);
} catch (JAXBException e) {
@@ -432,10 +432,10 @@ public class ReadDescriptors implements
public static Connector readConnector(URL url) throws OpenEJBException {
Connector connector;
try {
- connector = (Connector) JaxbJavaee.unmarshal(Connector16.class,
url.openStream());
+ connector = (Connector)
JaxbJavaee.unmarshalJavaee(Connector16.class, url.openStream());
} catch (JAXBException e) {
try {
- connector = (Connector)
JaxbJavaee.unmarshal(Connector10.class, url.openStream());
+ connector = (Connector)
JaxbJavaee.unmarshalJavaee(Connector10.class, url.openStream());
} catch (ParserConfigurationException e1) {
throw new OpenEJBException("Cannot parse the ra.xml file: " +
url.toExternalForm(), e);
} catch (SAXException e1) {
@@ -458,7 +458,7 @@ public class ReadDescriptors implements
public static WebApp readWebApp(URL url) throws OpenEJBException {
WebApp webApp;
try {
- webApp = (WebApp) JaxbJavaee.unmarshal(WebApp.class,
url.openStream());
+ webApp = (WebApp) JaxbJavaee.unmarshalJavaee(WebApp.class,
url.openStream());
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the web.xml file: " +
url.toExternalForm(), e);
} catch (JAXBException e) {
@@ -474,7 +474,7 @@ public class ReadDescriptors implements
public static TldTaglib readTldTaglib(URL url) throws OpenEJBException {
TldTaglib tldTaglib;
try {
- tldTaglib = (TldTaglib) JaxbJavaee.unmarshal(TldTaglib.class,
url.openStream());
+ tldTaglib = (TldTaglib)
JaxbJavaee.unmarshalJavaee(TldTaglib.class, url.openStream());
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the JSP tag library
definition file: " + url.toExternalForm(), e);
} catch (JAXBException e) {
@@ -491,7 +491,7 @@ public class ReadDescriptors implements
FacesConfig facesConfig;
try {
JAXBElement<FacesConfig> element = (JAXBElement<FacesConfig>)
JaxbJavaee
- .unmarshal(FacesConfig.class, url.openStream());
+ .unmarshalJavaee(FacesConfig.class, url.openStream());
facesConfig = element.getValue();
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the faces configuration
file: " + url.toExternalForm(), e);
Modified:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/SunCmpConversionTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/SunCmpConversionTest.java?rev=958340&r1=958339&r2=958340&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/SunCmpConversionTest.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/SunCmpConversionTest.java
Sun Jun 27 06:44:07 2010
@@ -21,7 +21,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
@@ -89,7 +88,7 @@ public class SunCmpConversionTest extend
private EntityMappings convert(String ejbJarFileName, String
sunEjbJarFileName, String sunCmpMappingsFileName, String expectedFileName)
throws Exception {
InputStream in =
getClass().getClassLoader().getResourceAsStream(ejbJarFileName);
- EjbJar ejbJar = (EjbJar) JaxbJavaee.unmarshal(EjbJar.class, new
ByteArrayInputStream(readContent(in).getBytes()));
+ EjbJar ejbJar = (EjbJar) JaxbJavaee.unmarshalJavaee(EjbJar.class, new
ByteArrayInputStream(readContent(in).getBytes()));
// create and configure the module
EjbModule ejbModule = new EjbModule(getClass().getClassLoader(),
"TestModule", ejbJarFileName, ejbJar, new OpenejbJar());
Modified:
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java?rev=958340&r1=958339&r2=958340&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
(original)
+++
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
Sun Jun 27 06:44:07 2010
@@ -76,7 +76,18 @@ public class JaxbJavaee {
return jaxbContext;
}
- public static <T>Object unmarshal(Class<T> type, InputStream in) throws
ParserConfigurationException, SAXException, JAXBException {
+ /**
+ * Convert the namespaceURI in the input to the javaee URI, do not
validate the xml, and read in a T.
+ *
+ * @param type Class of object to be read in
+ * @param in input stream to read
+ * @param <T> class of object to be returned
+ * @return a T read from the input stream
+ * @throws ParserConfigurationException is the SAX parser can not be
configured
+ * @throws SAXException if there is an xml problem
+ * @throws JAXBException if the xml cannot be marshalled into a T.
+ */
+ public static <T>Object unmarshalJavaee(Class<T> type, InputStream in)
throws ParserConfigurationException, SAXException, JAXBException {
InputSource inputSource = new InputSource(in);
SAXParserFactory factory = SAXParserFactory.newInstance();
@@ -94,7 +105,7 @@ public class JaxbJavaee {
});
- JaxbJavaee.NamespaceFilter xmlFilter = new
JaxbJavaee.NamespaceFilter(parser.getXMLReader());
+ JavaeeNamespaceFilter xmlFilter = new
JavaeeNamespaceFilter(parser.getXMLReader());
xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
SAXSource source = new SAXSource(xmlFilter, inputSource);
@@ -107,6 +118,55 @@ public class JaxbJavaee {
}
}
+ /**
+ * Read in a T from the input stream.
+ *
+ * @param type Class of object to be read in
+ * @param in input stream to read
+ * @param validate whether to validate the input.
+ * @param <T> class of object to be returned
+ * @return a T read from the input stream
+ * @throws ParserConfigurationException is the SAX parser can not be
configured
+ * @throws SAXException if there is an xml problem
+ * @throws JAXBException if the xml cannot be marshalled into a T.
+ */
+ public static <T>Object unmarshal(Class<T> type, InputStream in, boolean
validate) throws ParserConfigurationException, SAXException, JAXBException {
+ InputSource inputSource = new InputSource(in);
+
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setValidating(validate);
+
+ JAXBContext ctx = JaxbJavaee.getContext(type);
+ Unmarshaller unmarshaller = ctx.createUnmarshaller();
+ unmarshaller.setEventHandler(new ValidationEventHandler(){
+ public boolean handleEvent(ValidationEvent validationEvent) {
+ System.out.println(validationEvent);
+ return false;
+ }
+ });
+
+ SAXSource source = new SAXSource(inputSource);
+
+ currentPublicId.set(new TreeSet<String>());
+ try {
+ return unmarshaller.unmarshal(source);
+ } finally {
+ currentPublicId.set(null);
+ }
+ }
+
+ /**
+ * Convert the namespaceURI in the input to the taglib URI, do not
validate the xml, and read in a T.
+ *
+ * @param type Class of object to be read in
+ * @param in input stream to read
+ * @param <T> class of object to be returned
+ * @return a T read from the input stream
+ * @throws ParserConfigurationException is the SAX parser can not be
configured
+ * @throws SAXException if there is an xml problem
+ * @throws JAXBException if the xml cannot be marshalled into a T.
+ */
public static <T>Object unmarshalTaglib(Class<T> type, InputStream in)
throws ParserConfigurationException, SAXException, JAXBException {
InputSource inputSource = new InputSource(in);
@@ -138,13 +198,14 @@ public class JaxbJavaee {
}
}
- public static class NamespaceFilter extends XMLFilterImpl {
+ public static class JavaeeNamespaceFilter extends XMLFilterImpl {
private static final InputSource EMPTY_INPUT_SOURCE = new
InputSource(new ByteArrayInputStream(new byte[0]));
- public NamespaceFilter(XMLReader xmlReader) {
+ public JavaeeNamespaceFilter(XMLReader xmlReader) {
super(xmlReader);
}
+ @Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
Set<String> publicIds = currentPublicId.get();
if (publicIds != null) {
@@ -153,9 +214,15 @@ public class JaxbJavaee {
return EMPTY_INPUT_SOURCE;
}
+ @Override
public void startElement(String uri, String localName, String qname,
Attributes atts) throws SAXException {
super.startElement("http://java.sun.com/xml/ns/javaee", localName,
qname, atts);
}
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
throws SAXException {
+ super.endElement("http://java.sun.com/xml/ns/javaee", localName,
qName);
+ }
}
public static class TaglibNamespaceFilter extends XMLFilterImpl {
@@ -165,6 +232,7 @@ public class JaxbJavaee {
super(xmlReader);
}
+ @Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
Set<String> publicIds = currentPublicId.get();
if (publicIds != null) {
@@ -173,6 +241,7 @@ public class JaxbJavaee {
return EMPTY_INPUT_SOURCE;
}
+ @Override
public void startElement(String uri, String localName, String qname,
Attributes atts) throws SAXException {
localName = fixLocalName(localName);
super.startElement("http://java.sun.com/xml/ns/javaee", localName,
qname, atts);
@@ -203,4 +272,5 @@ public class JaxbJavaee {
super.endElement("http://java.sun.com/xml/ns/javaee", localName,
qName);
}
}
+
}
Modified:
openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java?rev=958340&r1=958339&r2=958340&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
(original)
+++
openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
Sun Jun 27 06:44:07 2010
@@ -92,7 +92,7 @@ public class JeeTest extends TestCase {
String fileName = "ejb-jar-timeout.xml";
InputStream in =
this.getClass().getClassLoader().getResourceAsStream(fileName);
- Object o = JaxbJavaee.unmarshal(EjbJar.class, in);
+ Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
EjbJar ejbJar = (EjbJar) o;
EnterpriseBean bean = ejbJar.getEnterpriseBean("A");
@@ -108,7 +108,7 @@ public class JeeTest extends TestCase {
String fileName = "ejb-session-synchronization.xml";
InputStream in =
this.getClass().getClassLoader().getResourceAsStream(fileName);
- Object o = JaxbJavaee.unmarshal(EjbJar.class, in);
+ Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
EjbJar ejbJar = (EjbJar) o;
EnterpriseBean bean = ejbJar.getEnterpriseBean("TestBean");
@@ -129,7 +129,7 @@ public class JeeTest extends TestCase {
String fileName = "ejb-jar-aroundtimeout.xml";
InputStream in =
this.getClass().getClassLoader().getResourceAsStream(fileName);
- Object o = JaxbJavaee.unmarshal(EjbJar.class, in);
+ Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
EjbJar ejbJar = (EjbJar) o;
EnterpriseBean bean = ejbJar.getEnterpriseBean("TestBean");
@@ -148,7 +148,7 @@ public class JeeTest extends TestCase {
String fileName = "ejb-jar-mdb-2.0.xml";
InputStream in =
this.getClass().getClassLoader().getResourceAsStream(fileName);
- Object o = JaxbJavaee.unmarshal(EjbJar.class, in);
+ Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
EjbJar ejbJar = (EjbJar) o;
@@ -215,7 +215,7 @@ public class JeeTest extends TestCase {
managedBeanClasses.add("org.apache.openejb.faces.OneBean");
managedBeanClasses.add("org.apache.openejb.faces.TwoBean");
InputStream inputStream =
this.getClass().getClassLoader().getResourceAsStream("faces-config.xml");
- JAXBElement<FacesConfig> element = (JAXBElement<FacesConfig>)
JaxbJavaee.unmarshal(FacesConfig.class, inputStream);
+ JAXBElement<FacesConfig> element = (JAXBElement<FacesConfig>)
JaxbJavaee.unmarshalJavaee(FacesConfig.class, inputStream);
FacesConfig facesConfig = element.getValue();
List<FacesManagedBean> managedBean = facesConfig.getManagedBean();