You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/12/10 06:08:43 UTC
svn commit: r1419199 [35/35] - in /openejb/trunk/openejb/container:
openejb-jee-accessors/ openejb-jee-accessors/src/main/
openejb-jee-accessors/src/main/java/ openejb-jee-accessors/src/main/java/org/
openejb-jee-accessors/src/main/java/org/apache/ ope...
Added: openejb/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java?rev=1419199&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java (added)
+++ openejb/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java Mon Dec 10 05:08:14 2012
@@ -0,0 +1,157 @@
+/*
+ * 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.sxc;
+
+import com.envoisolutions.sxc.jaxb.ExtendedMarshaller;
+import com.envoisolutions.sxc.jaxb.ExtendedUnmarshaller;
+import com.envoisolutions.sxc.jaxb.JAXBObject;
+import com.envoisolutions.sxc.jaxb.RuntimeContext;
+import com.envoisolutions.sxc.util.PrettyPrintXMLStreamWriter;
+import com.envoisolutions.sxc.util.RuntimeXMLStreamException;
+import com.envoisolutions.sxc.util.XmlFactories;
+import com.envoisolutions.sxc.util.XoXMLStreamReader;
+import com.envoisolutions.sxc.util.XoXMLStreamReaderImpl;
+import com.envoisolutions.sxc.util.XoXMLStreamWriter;
+import com.envoisolutions.sxc.util.XoXMLStreamWriterImpl;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.MarshalException;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Sxc {
+ public static void marshall(final JAXBObject objectType, Object object, OutputStream outputStream) throws JAXBException {
+ final Result result = new StreamResult(outputStream);
+
+ marshal(objectType, object, result);
+ }
+
+ public static void marshal(JAXBObject objectType, Object object, Result result) throws JAXBException {
+ if (result == null) throw new IllegalArgumentException("result is null");
+ if (object == null) throw new IllegalArgumentException("object is null");
+ if (objectType == null) throw new IllegalArgumentException("jaxbObject is null");
+
+ XMLStreamWriter writer = null;
+ try {
+ writer = XmlFactories.getXof().createXMLStreamWriter(result);
+ writer = new PrettyPrintXMLStreamWriter(writer);
+ XoXMLStreamWriter w = new XoXMLStreamWriterImpl(writer);
+
+ try {
+ w.writeStartDocument("UTF-8", null);
+
+ // write xsi:type if there is no default root element for this type
+
+ final RuntimeContext context = new RuntimeContext((ExtendedMarshaller) null);
+
+ try {
+
+ QName name = objectType.getXmlRootElement();
+
+ // open element
+ w.writeStartElementWithAutoPrefix(name.getNamespaceURI(), name.getLocalPart());
+
+ objectType.write(w, object, context);
+
+ w.writeEndElement();
+ } catch (Exception e) {
+ if (e instanceof JAXBException) {
+ // assume event handler has already been notified
+ throw (JAXBException) e;
+ }
+ if (e instanceof RuntimeXMLStreamException) {
+ // simply unwrap and handle below
+ e = ((RuntimeXMLStreamException) e).getCause();
+ }
+
+ if (e instanceof XMLStreamException) {
+ Throwable cause = e.getCause();
+ if (cause instanceof JAXBException) {
+ throw (JAXBException) e;
+ }
+ throw new MarshalException(cause == null ? e : cause);
+ }
+ throw new MarshalException(e);
+
+ }
+
+ w.writeEndDocument();
+ } catch (Exception e) {
+ throw new MarshalException(e);
+ }
+
+
+ } catch (XMLStreamException e) {
+ throw new JAXBException("Could not close XMLStreamWriter.", e);
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (XMLStreamException ignored) {
+ }
+ }
+ }
+ }
+
+ public static <T> T unmarshalJavaee(URL resource, JAXBObject<T> jaxbType) throws Exception {
+ final InputStream inputStream = resource.openStream();
+ try {
+ return unmarshalJavaee(jaxbType, inputStream);
+ } finally {
+ try {
+ inputStream.close();
+ } catch (IOException e1) {
+ }
+ }
+ }
+
+ public static <T> T unmarshalJavaee(JAXBObject<T> jaxbType, InputStream inputStream) throws Exception {
+ final Source source = new StreamSource(inputStream);
+
+ final XMLStreamReader streamReader = XmlFactories.getXif().createXMLStreamReader(source);
+
+ final XMLStreamReader filter = new JavaeeNamespaceFilter(streamReader);
+
+ return unmarhsal(jaxbType, filter);
+ }
+
+ public static <T> T unmarhsal(JAXBObject<T> jaxbType, XMLStreamReader xmlStreamReader) throws Exception {
+
+ final XoXMLStreamReader reader = new XoXMLStreamReaderImpl(xmlStreamReader);
+
+ int event = reader.getEventType();
+ while (event != XMLStreamConstants.START_ELEMENT && reader.hasNext()) {
+ event = reader.next();
+ }
+
+ return jaxbType.read(reader, new RuntimeContext((ExtendedUnmarshaller) null));
+ }
+}
Propchange: openejb/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/DebugStreamReaderDelegate.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/DebugStreamReaderDelegate.java?rev=1419199&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/DebugStreamReaderDelegate.java (added)
+++ openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/DebugStreamReaderDelegate.java Mon Dec 10 05:08:14 2012
@@ -0,0 +1,333 @@
+/*
+ * 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.sxc;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+/**
+* @version $Rev$ $Date$
+*/
+class DebugStreamReaderDelegate extends StreamReaderDelegate {
+ public DebugStreamReaderDelegate(XMLStreamReader streamReader) {
+ super(streamReader);
+ }
+
+ @Override
+ public Object getProperty(String name) {
+ return super.getProperty(name);
+ }
+
+ @Override
+ public String getPIData() {
+ final String s = super.getPIData();
+ System.out.println("getPIData = " + s);
+ return s;
+ }
+
+ @Override
+ public String getPITarget() {
+ final String s = super.getPITarget();
+ System.out.println("getPITarget = " + s);
+ return s;
+ }
+
+ @Override
+ public String getCharacterEncodingScheme() {
+ final String s = super.getCharacterEncodingScheme();
+ System.out.println("getCharacterEncodingScheme = " + s);
+ return s;
+ }
+
+ @Override
+ public boolean standaloneSet() {
+ return super.standaloneSet();
+ }
+
+ @Override
+ public boolean isStandalone() {
+ return super.isStandalone();
+ }
+
+ @Override
+ public String getVersion() {
+ final String s = super.getVersion();
+ System.out.println("getVersion = " + s);
+ return s;
+ }
+
+ @Override
+ public String getPrefix() {
+ final String s = super.getPrefix();
+ System.out.println("getPrefix = " + s);
+ return s;
+ }
+
+ @Override
+ public String getNamespaceURI() {
+ final String s = super.getNamespaceURI();
+ System.out.println("getNamespaceURI() = " + s);
+ return s;
+ }
+
+ @Override
+ public boolean hasName() {
+ return super.hasName();
+ }
+
+ @Override
+ public String getLocalName() {
+ final String s = super.getLocalName();
+ System.out.println("getLocalName = " + s);
+ return s;
+ }
+
+ @Override
+ public QName getName() {
+ return super.getName();
+ }
+
+ @Override
+ public Location getLocation() {
+ return super.getLocation();
+ }
+
+ @Override
+ public boolean hasText() {
+ return super.hasText();
+ }
+
+ @Override
+ public String getEncoding() {
+ final String s = super.getEncoding();
+ System.out.println("getEncoding = " + s);
+ return s;
+ }
+
+ @Override
+ public int getTextLength() {
+ return super.getTextLength();
+ }
+
+ @Override
+ public int getTextStart() {
+ return super.getTextStart();
+ }
+
+ @Override
+ public char[] getTextCharacters() {
+ return super.getTextCharacters();
+ }
+
+ @Override
+ public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException {
+ return super.getTextCharacters(sourceStart, target, targetStart, length);
+ }
+
+ @Override
+ public String getText() {
+ final String s = super.getText();
+ System.out.println("getText = " + s);
+ return s;
+ }
+
+ @Override
+ public int getEventType() {
+ return super.getEventType();
+ }
+
+ @Override
+ public String getNamespaceURI(int index) {
+ final String s = super.getNamespaceURI(index);
+ System.out.println("getNamespaceURI(int) = " + s);
+ return s;
+ }
+
+ @Override
+ public String getNamespacePrefix(int index) {
+ final String s = super.getNamespacePrefix(index);
+ System.out.println("getNamespacePrefix = " + s);
+ return s;
+ }
+
+ @Override
+ public int getNamespaceCount() {
+ return super.getNamespaceCount();
+ }
+
+ @Override
+ public boolean isAttributeSpecified(int index) {
+ return super.isAttributeSpecified(index);
+ }
+
+ @Override
+ public String getAttributeValue(int index) {
+ final String s = super.getAttributeValue(index);
+ System.out.println("getAttributeValue = " + s);
+ return s;
+ }
+
+ @Override
+ public String getAttributeType(int index) {
+ final String s = super.getAttributeType(index);
+ System.out.println("getAttributeType = " + s);
+ return s;
+ }
+
+ @Override
+ public String getAttributeLocalName(int index) {
+ final String s = super.getAttributeLocalName(index);
+ System.out.println("getAttributeLocalName = " + s);
+ return s;
+ }
+
+ @Override
+ public String getAttributeNamespace(int index) {
+ final String s = super.getAttributeNamespace(index);
+ System.out.println("getAttributeNamespace = " + s);
+ return s;
+ }
+
+ @Override
+ public String getAttributePrefix(int index) {
+ final String s = super.getAttributePrefix(index);
+ System.out.println("getAttributePrefix = " + s);
+ return s;
+ }
+
+ @Override
+ public QName getAttributeName(int index) {
+ return super.getAttributeName(index);
+ }
+
+ @Override
+ public int getAttributeCount() {
+ return super.getAttributeCount();
+ }
+
+ @Override
+ public String getAttributeValue(String namespaceUri, String localName) {
+ final String s = super.getAttributeValue(namespaceUri, localName);
+ System.out.println("getAttributeValue = " + s);
+ return s;
+ }
+
+ @Override
+ public boolean isWhiteSpace() {
+ return super.isWhiteSpace();
+ }
+
+ @Override
+ public boolean isCharacters() {
+ return super.isCharacters();
+ }
+
+ @Override
+ public boolean isEndElement() {
+ return super.isEndElement();
+ }
+
+ @Override
+ public boolean isStartElement() {
+ return super.isStartElement();
+ }
+
+ @Override
+ public NamespaceContext getNamespaceContext() {
+ return super.getNamespaceContext();
+ }
+
+ @Override
+ public String getNamespaceURI(String prefix) {
+ final String s = super.getNamespaceURI(prefix);
+ System.out.println("getNamespaceURI(string) = " + s);
+ return s;
+ }
+
+ @Override
+ public void close() throws XMLStreamException {
+ super.close();
+ }
+
+ @Override
+ public boolean hasNext() throws XMLStreamException {
+ return super.hasNext();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ }
+
+ @Override
+ public void require(int type, String namespaceURI, String localName) throws XMLStreamException {
+ super.require(type, namespaceURI, localName);
+ }
+
+ @Override
+ public String getElementText() throws XMLStreamException {
+ final String s = super.getElementText();
+ System.out.println("getElementText = " + s);
+ return s;
+ }
+
+ @Override
+ public int nextTag() throws XMLStreamException {
+ return super.nextTag();
+ }
+
+ @Override
+ public int next() throws XMLStreamException {
+ return super.next();
+ }
+
+ @Override
+ public XMLStreamReader getParent() {
+ return super.getParent();
+ }
+
+ @Override
+ public String toString() {
+ final String s = super.toString();
+ System.out.println("toString = " + s);
+ return s;
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ @Override
+ public void setParent(XMLStreamReader reader) {
+ super.setParent(reader);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+}
Propchange: openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/DebugStreamReaderDelegate.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/EjbJarXmlTest.java (from r1418042, openejb/trunk/openejb/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/EjbJarXmlTest.java?p2=openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/EjbJarXmlTest.java&p1=openejb/trunk/openejb/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java&r1=1418042&r2=1419199&rev=1419199&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java (original)
+++ openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/EjbJarXmlTest.java Mon Dec 10 05:08:14 2012
@@ -1,58 +1,33 @@
-/**
- *
+/*
* 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 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.
+ * 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.jee;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Properties;
-
-import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.ValidationEvent;
-import javax.xml.bind.ValidationEventHandler;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.sax.SAXSource;
+package org.apache.openejb.sxc;
import junit.framework.TestCase;
+import org.apache.openejb.jee.EjbJar$JAXB;
+import org.apache.openejb.loader.IO;
-import org.junit.Test;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLFilterImpl;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+import java.util.concurrent.TimeUnit;
/**
* @version $Revision$ $Date$
*/
-public class JeeTest extends TestCase {
+public class EjbJarXmlTest extends TestCase {
/**
* TODO Doesn't seem there are any asserts here
@@ -60,322 +35,51 @@ public class JeeTest extends TestCase {
*/
public void testEjbJar() throws Exception {
String fileName = "ejb-jar-example1.xml";
- // String fileName = "ejb-jar-empty.xml";
-
- // marshalAndUnmarshal(EjbJar.class, fileName);
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(true);
- factory.setValidating(false);
- SAXParser parser = factory.newSAXParser();
+ final Event test = Event.start("Test");
- long start = System.currentTimeMillis();
+ final URL resource = this.getClass().getClassLoader().getResource(fileName);
- // Unmarshaller unmarshaller = new UnmarshallerImpl(Collections.<JAXBMarshaller>singleton(EjbJarJaxB.INSTANCE));
- // Marshaller marshaller = new MarshallerImpl(Collections.<JAXBMarshaller>singleton(EjbJarJaxB.INSTANCE));
- JAXBContext ctx = JAXBContextFactory.newInstance(EjbJar.class);
- Unmarshaller unmarshaller = ctx.createUnmarshaller();
- Marshaller marshaller = ctx.createMarshaller();
+ final String expected = IO.slurp(resource);
- NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
- xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
- unmarshaller.setEventHandler(new TestValidationEventHandler());
+ final Event ejbJarJAXBCreate = Event.start("EjbJarJAXBCreate");
+ ejbJarJAXBCreate.stop();
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(fileName);
- String expected = readContent(in);
+ final Event unmarshalEvent = Event.start("unmarshal");
+ final Object value;
- SAXSource source = new SAXSource(xmlFilter, new InputSource(new ByteArrayInputStream(expected.getBytes())));
- Object object = unmarshaller.unmarshal(source);
+ final EjbJar$JAXB jaxbType = new EjbJar$JAXB();
+ value = Sxc.unmarshalJavaee(resource, jaxbType);
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ unmarshalEvent.stop();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- marshaller.marshal(object, baos);
-
- System.out.println("time: " + (System.currentTimeMillis() - start));
- }
-
- public void testEjbTimeout() throws Exception {
- String fileName = "ejb-jar-timeout.xml";
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(fileName);
-
- Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
-
- EjbJar ejbJar = (EjbJar) o;
- EnterpriseBean bean = ejbJar.getEnterpriseBean("A");
-
- assertTrue("The bean A is not a SessionBean", bean instanceof SessionBean);
- SessionBean sbean = (SessionBean) bean;
-
- assertNotNull("Unable to get the StatefulTimeout value", sbean.getStatefulTimeout());
- }
-
- public void testSessionSynchronization() throws Exception {
- String fileName = "ejb-session-synchronization.xml";
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(fileName);
-
- Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
-
- EjbJar ejbJar = (EjbJar) o;
- EnterpriseBean bean = ejbJar.getEnterpriseBean("TestBean");
- assertTrue("The bean TestBean is not a SessionBean", bean instanceof SessionBean);
- SessionBean sbean = (SessionBean) bean;
+ final Event marshall = Event.start("marshall");
+ Sxc.marshall(jaxbType, value, baos);
+ marshall.stop();
- assertNotNull("Unable to get the afterBegin value", sbean.getAfterBeginMethod());
- assertNotNull("Unable to get the beforeCompletion value", sbean.getBeforeCompletionMethod());
- assertNotNull("Unable to get the afterCompletion value", sbean.getAfterCompletionMethod());
-
- assertNotNull("Unable to get the afterBegin value", sbean.getAfterBegin());
- assertNotNull("Unable to get the beforeCompletion value", sbean.getBeforeCompletion());
- assertNotNull("Unable to get the afterCompletion value", sbean.getAfterCompletion());
- }
-
- public void testAroundTimeout() throws Exception {
- String fileName = "ejb-jar-aroundtimeout.xml";
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(fileName);
-
- Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
-
- EjbJar ejbJar = (EjbJar) o;
- EnterpriseBean bean = ejbJar.getEnterpriseBean("TestBean");
-
- assertTrue("The bean TestBean is not a SessionBean", bean instanceof SessionBean);
- SessionBean sbean = (SessionBean) bean;
-
- AroundTimeout beanAroundTimeout = sbean.getAroundTimeout().get(0);
- assertEquals("aroundTimeout", beanAroundTimeout.getMethodName());
-
- AroundTimeout interceptorAroundTimeout = ejbJar.getInterceptors()[0].getAroundTimeout().get(0);
- assertEquals("aroundTimeout", interceptorAroundTimeout.getMethodName());
- }
-
- public void testTimerSchedule() throws Exception {
- String fileName = "ejb-jar-timeschedule.xml";
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(fileName);
-
- Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
-
- EjbJar ejbJar = (EjbJar) o;
- EnterpriseBean bean = ejbJar.getEnterpriseBean("TestBean");
-
- assertTrue("The bean TestBean is not a SessionBean", bean instanceof SessionBean);
- SessionBean sbean = (SessionBean) bean;
-
- List<Timer> timers = sbean.getTimer();
- assertEquals(1, timers.size());
-
- Timer timer = timers.get(0);
- TimerSchedule timerSchedule = timer.getSchedule();
- assertEquals("10", timerSchedule.getSecond());
- assertEquals("10", timerSchedule.getMinute());
- assertEquals("*", timerSchedule.getDayOfMonth());
- assertEquals("Mon", timerSchedule.getDayOfWeek());
- assertEquals("*", timerSchedule.getHour());
- assertEquals("Nov", timerSchedule.getMonth());
- assertEquals("*", timerSchedule.getYear());
-
- assertEquals("2010-03-01T13:00:00Z", timer.getStart().toXMLFormat());
- assertEquals("2012-12-11T14:19:00Z", timer.getEnd().toXMLFormat());
-
- NamedMethod timeoutMethod = timer.getTimeoutMethod();
- assertEquals("testScheduleMethod", timeoutMethod.getMethodName());
- assertEquals("javax.ejb.Timer", timeoutMethod.getMethodParams().getMethodParam().get(0));
-
- assertEquals(Boolean.FALSE, timer.getPersistent());
- assertEquals("America/New_York", timer.getTimezone());
- assertEquals("TestInfo", timer.getInfo());
+ final String result = new String(baos.toByteArray());
+ assertEquals(expected, result);
+ test.stop();
}
- public void testEjbJarMdb20() throws Exception {
- String fileName = "ejb-jar-mdb-2.0.xml";
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(fileName);
-
- Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
-
- EjbJar ejbJar = (EjbJar) o;
-
- MessageDrivenBean bean = (MessageDrivenBean) ejbJar.getEnterpriseBean("MyMdb");
-
- Properties properties = bean.getActivationConfig().toProperties();
-
- assertEquals(4, properties.size());
- /*
- <message-selector>mySelector</message-selector>
- <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
- <message-driven-destination>
- <destination-type>javax.jms.Queue</destination-type>
- <subscription-durability>Durable</subscription-durability>
-
- */
- assertEquals("mySelector", properties.get("messageSelector"));
- assertEquals("Auto-acknowledge", properties.get("acknowledgeMode"));
- assertEquals("javax.jms.Queue", properties.get("destinationType"));
- assertEquals("Durable", properties.get("subscriptionDurability"));
- }
+ private static class Event {
+ protected final long start = System.nanoTime();
+ private final String description;
- public void testApplication() throws Exception {
- marshalAndUnmarshal(Application.class, "application-example.xml", null);
- }
-
- public void testApplicationClient() throws Exception {
- marshalAndUnmarshal(ApplicationClient.class, "application-client-example.xml", null);
- }
-
- public void testWar() throws Exception {
- marshalAndUnmarshal(WebApp.class, "web-example.xml", "web-example-expected.xml");
- }
-
- public void testWar2_3() throws Exception {
- marshalAndUnmarshal(WebApp.class, "web_2.3-example.xml", "web_2.3-example-expected.xml");
- }
-
- public void testTld() throws Exception {
- marshalAndUnmarshal(TldTaglib.class, "tld-example.xml", null);
- }
-
- public void testRar10() throws Exception {
- Connector10 c10 = marshalAndUnmarshal(Connector10.class, "connector-1.0-example.xml", null);
- Connector c = Connector.newConnector(c10);
- JAXBContext ctx = JAXBContextFactory.newInstance(Connector.class);
- Marshaller marshaller = ctx.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- marshaller.marshal(c, baos);
-
- byte[] bytes = baos.toByteArray();
- String actual = new String(bytes);
-
- String expected;
- InputStream in2 = this.getClass().getClassLoader().getResourceAsStream("connector-1.0-example-expected-1.6.xml");
- expected = readContent(in2);
-
- try {
- StaxCompare.compare(expected, actual);
- } catch (Exception e) {
-// System.out.append(actual);
- writeToTmpFile(bytes, "connector-1.0-example.xml");
- throw e;
+ private Event(final String description) {
+ this.description = description;
}
- }
-
- public void testRar15() throws Exception {
- marshalAndUnmarshal(Connector.class, "connector-1.5-example.xml", null);
- }
-
- public void testRar16() throws Exception {
- marshalAndUnmarshal(Connector.class, "connector-1.6-example.xml", null);
- }
-
- public void testWebServiceHandlers() throws Exception {
- QName[] expectedServiceNames = { new QName("http://www.helloworld.org", "HelloService", "ns1"), new QName("http://www.bar.org", "HelloService", "bar"),
- new QName("http://www.bar1.org", "HelloService", "bar"), new QName(XMLConstants.NULL_NS_URI, "HelloService", "foo"), new QName(XMLConstants.NULL_NS_URI, "*"), null };
- InputStream in = this.getClass().getClassLoader().getResourceAsStream("handler.xml");
- try {
- HandlerChains handlerChains = (HandlerChains) JaxbJavaee.unmarshalHandlerChains(HandlerChains.class, in);
- for (int index = 0; index < handlerChains.getHandlerChain().size(); index++) {
- HandlerChain handlerChain = handlerChains.getHandlerChain().get(index);
- QName serviceName = handlerChain.getServiceNamePattern();
- QName expectedServiceName = expectedServiceNames[index];
- if (expectedServiceName == null) {
- assertNull(serviceName);
- } else {
- assertEquals("serviceNamePattern at index " + index + " mismatches", expectedServiceName, serviceName );
- }
- }
- System.out.println(JaxbJavaee.marshal(HandlerChains.class, handlerChains));
- } finally {
- in.close();
- }
- }
-
- public static <T> T marshalAndUnmarshal(Class<T> type, String sourceXmlFile, String expectedXmlFile) throws Exception {
- InputStream in = JeeTest.class.getClassLoader().getResourceAsStream(sourceXmlFile);
- T object = (T)JaxbJavaee.unmarshalJavaee(type, in);
- in.close();
- assertTrue(object.getClass().isAssignableFrom(type));
-
- JAXBContext ctx = JAXBContextFactory.newInstance(type);
- Marshaller marshaller = ctx.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- marshaller.marshal(object, baos);
-
- byte[] bytes = baos.toByteArray();
- String actual = new String(bytes);
-
- String expected;
- if (expectedXmlFile == null) {
- InputStream in2 = JeeTest.class.getClassLoader().getResourceAsStream(sourceXmlFile);
- expected = readContent(in2);
- } else {
- InputStream in2 = JeeTest.class.getClassLoader().getResourceAsStream(expectedXmlFile);
- expected = readContent(in2);
+ public static Event start(final String description) {
+ return new Event(description);
}
- try {
- StaxCompare.compare(expected, actual);
- } catch (Exception e) {
-// System.out.append(actual);
- writeToTmpFile(bytes, sourceXmlFile);
- throw e;
+ public void stop() {
+ final String format = String.format("JAXBContext.newInstance %s %s", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - this.start), this.description);
+ System.out.println(format);
}
- return object;
}
- public static class NamespaceFilter extends XMLFilterImpl {
-
- private static final InputSource EMPTY_INPUT_SOURCE = new InputSource(new ByteArrayInputStream(new byte[0]));
-
- public NamespaceFilter(XMLReader xmlReader) {
- super(xmlReader);
- }
-
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
- return EMPTY_INPUT_SOURCE;
- }
-
- 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);
- }
- }
-
- private static void writeToTmpFile(byte[] bytes, String xmlFileName) {
- try {
- File tempFile = File.createTempFile("jaxb-output", "xml");
- FileOutputStream out = new FileOutputStream(tempFile);
- out.write(bytes);
- out.close();
- System.out.println("Jaxb output of " + xmlFileName + " written to " + tempFile.getAbsolutePath());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- private static String readContent(InputStream in) throws IOException {
- StringBuffer sb = new StringBuffer();
- in = new BufferedInputStream(in);
- try {
- int i = in.read();
- while (i != -1) {
- sb.append((char) i);
- i = in.read();
- }
- } finally {
- in.close();
- }
- String content = sb.toString();
- return content;
- }
-
- private static class TestValidationEventHandler implements ValidationEventHandler {
-
- public boolean handleEvent(ValidationEvent validationEvent) {
- System.out.println(validationEvent.getMessage());
- System.out.println(validationEvent.getLocator());
- return false; // if an error occurs we must be aware of
- }
- }
}
Propchange: openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/EjbJarXmlTest.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author Id Revision HeadURL
Added: openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/Foo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/Foo.java?rev=1419199&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/Foo.java (added)
+++ openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/Foo.java Mon Dec 10 05:08:14 2012
@@ -0,0 +1,33 @@
+/*
+ * 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.sxc;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Foo {
+
+ private String message;
+
+
+ public static class JAXB {
+
+ public static void setMessage(Foo foo, String message) {
+ foo.message = message;
+ }
+ }
+}
Propchange: openejb/trunk/openejb/container/openejb-jee-accessors/src/test/java/org/apache/openejb/sxc/Foo.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: openejb/trunk/openejb/container/openejb-jee-accessors/src/test/resources/ejb-jar-example1.xml (from r1418042, openejb/trunk/openejb/container/openejb-jee/src/test/resources/ejb-jar-example1.xml)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee-accessors/src/test/resources/ejb-jar-example1.xml?p2=openejb/trunk/openejb/container/openejb-jee-accessors/src/test/resources/ejb-jar-example1.xml&p1=openejb/trunk/openejb/container/openejb-jee/src/test/resources/ejb-jar-example1.xml&r1=1418042&r2=1419199&rev=1419199&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/src/test/resources/ejb-jar-example1.xml (original)
+++ openejb/trunk/openejb/container/openejb-jee-accessors/src/test/resources/ejb-jar-example1.xml Mon Dec 10 05:08:14 2012
@@ -1,25 +1,5 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!--
-
- 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.
--->
-
-<!-- $Rev$ $Date$ -->
-
-<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" metadata-complete="true">
+<?xml version='1.0' encoding='UTF-8'?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" metadata-complete="true" version="3.0">
<description>String</description>
<display-name>token</display-name>
<icon xml:lang="en">
Modified: openejb/trunk/openejb/container/openejb-jee/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee/pom.xml?rev=1419199&r1=1419198&r2=1419199&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/pom.xml (original)
+++ openejb/trunk/openejb/container/openejb-jee/pom.xml Mon Dec 10 05:08:14 2012
@@ -30,7 +30,8 @@
<packaging>jar</packaging>
<name>OpenEJB :: Container :: Java EE</name>
- <properties>
+
+ <properties>
<openejb.osgi.import.pkg>
org.apache.geronimo.specs.jpa;resolution:=optional,
org.apache.geronimo.specs.activation;resolution:=optional,
@@ -40,32 +41,6 @@
<build>
<plugins>
-<!--
- <plugin>
- <groupId>com.envoisolutions.sxc</groupId>
- <artifactId>sxc-jaxb-maven-plugin</artifactId>
- <version>0.7.2</version>
- <executions>
- <execution>
- <configuration>
- <classes>
- <class>org.apache.openejb.jee</class>
- <class>org.apache.openejb.jee.jba</class>
- <class>org.apache.openejb.jee.jba.cmp</class>
- <class>org.apache.openejb.jee.jpa</class>
- <class>org.apache.openejb.jee.oejb2</class>
- <class>org.apache.openejb.jee.oejb3</class>
- <class>org.apache.openejb.jee.sun</class>
- <class>org.apache.openejb.jee.wls</class>
- </classes>
- </configuration>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
--->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rat-maven-plugin</artifactId>
@@ -78,30 +53,6 @@
</plugins>
</build>
<dependencies>
-<!--
- <dependency>
- <groupId>com.envoisolutions.sxc</groupId>
- <artifactId>sxc-jaxb</artifactId>
- <version>0.7.2</version>
- <exclusions>
- <exclusion>
- <groupId>stax</groupId>
- <artifactId>stax-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
--->
- <!--<dependency>-->
- <!--<groupId>org.codehaus.woodstox</groupId>-->
- <!--<artifactId>woodstox-core-asl</artifactId>-->
- <!--<version>4.0.8</version>-->
- <!--<exclusions>-->
- <!--<exclusion>-->
- <!--<groupId>javax.xml.stream</groupId>-->
- <!--<artifactId>stax-api</artifactId>-->
- <!--</exclusion>-->
- <!--</exclusions>-->
- <!--</dependency>-->
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
Modified: openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/EjbJar.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/EjbJar.java?rev=1419199&r1=1419198&r2=1419199&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/EjbJar.java (original)
+++ openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/EjbJar.java Mon Dec 10 05:08:14 2012
@@ -90,7 +90,7 @@ public class EjbJar implements NamedModu
@XmlTransient
protected Map<String,EnterpriseBean> enterpriseBeans = new LinkedHashMap<String,EnterpriseBean>();
- private Interceptors interceptors;
+ protected Interceptors interceptors;
protected Relationships relationships;
@XmlElement(name = "assembly-descriptor")
protected AssemblyDescriptor assemblyDescriptor;
Modified: openejb/trunk/openejb/container/openejb-jee/src/test/resources/ejb-jar-example1.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee/src/test/resources/ejb-jar-example1.xml?rev=1419199&r1=1419198&r2=1419199&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/src/test/resources/ejb-jar-example1.xml (original)
+++ openejb/trunk/openejb/container/openejb-jee/src/test/resources/ejb-jar-example1.xml Mon Dec 10 05:08:14 2012
@@ -1,25 +1,5 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!--
-
- 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.
--->
-
-<!-- $Rev$ $Date$ -->
-
-<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" metadata-complete="true">
+<?xml version='1.0' encoding='UTF-8'?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" metadata-complete="true" version="3.0">
<description>String</description>
<display-name>token</display-name>
<icon xml:lang="en">