Author: rmannibucau Date: Thu Sep 26 08:52:45 2013 New Revision: 1526419 URL: http://svn.apache.org/r1526419 Log: TOMEE-1050 tolerate weld/candi config in beans.xml
Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/BeansXmlNamespaceTest.java tomee/tomee/trunk/container/openejb-core/src/test/resources/beans-namespace.xml Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java tomee/tomee/trunk/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=1526419&r1=1526418&r2=1526419&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java Thu Sep 26 08:52:45 2013 @@ -633,6 +633,7 @@ public class ReadDescriptors implements } catch (SAXException e) { throw new OpenEJBException("Cannot parse the beans.xml");// file: " + url.toExternalForm(), e); } catch (JAXBException e) { + e.printStackTrace(); 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); Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/BeansXmlNamespaceTest.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/BeansXmlNamespaceTest.java?rev=1526419&view=auto ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/BeansXmlNamespaceTest.java (added) +++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/BeansXmlNamespaceTest.java Thu Sep 26 08:52:45 2013 @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.cdi; + +import org.apache.openejb.OpenEJBException; +import org.apache.openejb.config.ReadDescriptors; +import org.apache.openejb.jee.Beans; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BeansXmlNamespaceTest { + @Test + public void read() throws OpenEJBException { + final Beans beans = ReadDescriptors.readBeans(getClass().getResourceAsStream("/beans-namespace.xml")); + assertEquals(1, beans.getInterceptors().size()); + assertEquals("foo", beans.getInterceptors().iterator().next()); + assertEquals(1, beans.getDecorators().size()); + assertEquals("bar", beans.getDecorators().iterator().next()); + } +} Added: tomee/tomee/trunk/container/openejb-core/src/test/resources/beans-namespace.xml URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/resources/beans-namespace.xml?rev=1526419&view=auto ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/test/resources/beans-namespace.xml (added) +++ tomee/tomee/trunk/container/openejb-core/src/test/resources/beans-namespace.xml Thu Sep 26 08:52:45 2013 @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<beans xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:weld="http://jboss.org/schema/weld/beans" + xsi:schemaLocation=" + http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd + http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd"> + <interceptors> + <class>foo</class> + </interceptors> + <weld:scan> + <weld:exclude name="com.acme.swing.**"/> + <weld:exclude name="com.acme.gwt.**"> + <weld:if-class-available name="!com.google.GWT"/> + </weld:exclude> + <weld:exclude pattern="^(.*)Blether$"> + <weld:if-system-property name="verbosity" value="low"/> + </weld:exclude> + <weld:exclude name="com.acme.jsf.**"> + <weld:if-class-available name="org.pahce.wicket.Wicket"/> + <weld:if-system-property name="!viewlayer"/> + </weld:exclude> + </weld:scan> + <decorators> + <class>bar</class> + </decorators> +</beans> Modified: tomee/tomee/trunk/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java?rev=1526419&r1=1526418&r2=1526419&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java (original) +++ tomee/tomee/trunk/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java Thu Sep 26 08:52:45 2013 @@ -266,6 +266,8 @@ public class JaxbJavaee { public static class JavaeeNamespaceFilter extends XMLFilterImpl { private static final InputSource EMPTY_INPUT_SOURCE = new InputSource(new ByteArrayInputStream(new byte[0])); + private boolean ignore = false; + public JavaeeNamespaceFilter(XMLReader xmlReader) { super(xmlReader); } @@ -281,12 +283,38 @@ public class JaxbJavaee { @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); + if (ignore) { + return; + } + + if (uri != null && (uri.startsWith("http://jboss.org") || uri.startsWith("urn:java:"))) { // ignore it to be able to read beans.xml with weld config for instances + ignore = true; + } else { + super.startElement("http://java.sun.com/xml/ns/javaee", localName, qname, atts); + } + } + + @Override + public void characters(final char ch[], final int start, final int length) throws SAXException { + if (!ignore) { + super.characters(ch, start, length); + } + } + + @Override + public void ignorableWhitespace(final char ch[], final int start, final int length) throws SAXException { + if (!ignore) { + super.ignorableWhitespace(ch, start, length); + } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { - super.endElement("http://java.sun.com/xml/ns/javaee", localName, qName); + if (uri != null && (uri.startsWith("http://jboss.org") || uri.startsWith("urn:java:"))) { // ignore it + ignore = false; + } else if (!ignore) { + super.endElement("http://java.sun.com/xml/ns/javaee", localName, qName); + } } }