You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2012/05/20 11:46:10 UTC
svn commit: r1340650 - in /axis/axis2/java/core/trunk/modules/jibx/src:
main/java/org/apache/axis2/jibx/
main/resources/org/apache/axis2/jibx/template/
test/java/org/apache/axis2/jibx/handler/
test/java/org/apache/axis2/jibx/library/unwrapped/ test/jav...
Author: veithen
Date: Sun May 20 09:46:10 2012
New Revision: 1340650
URL: http://svn.apache.org/viewvc?rev=1340650&view=rev
Log:
Fixed a couple of prefix mismatches caused by usage of dummy prefixes when creating the OMSourcedElement.
Added:
axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/handler/
axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/handler/OMSourcedElementChecker.java (with props)
axis/axis2/java/core/trunk/modules/jibx/src/test/resources/
axis/axis2/java/core/trunk/modules/jibx/src/test/resources/META-INF/
axis/axis2/java/core/trunk/modules/jibx/src/test/resources/META-INF/module.xml (with props)
Modified:
axis/axis2/java/core/trunk/modules/jibx/src/main/java/org/apache/axis2/jibx/JiBXDataSource.java
axis/axis2/java/core/trunk/modules/jibx/src/main/resources/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl
axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java
axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/service/LibraryImpl.java
axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java
Modified: axis/axis2/java/core/trunk/modules/jibx/src/main/java/org/apache/axis2/jibx/JiBXDataSource.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/main/java/org/apache/axis2/jibx/JiBXDataSource.java?rev=1340650&r1=1340649&r2=1340650&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jibx/src/main/java/org/apache/axis2/jibx/JiBXDataSource.java (original)
+++ axis/axis2/java/core/trunk/modules/jibx/src/main/java/org/apache/axis2/jibx/JiBXDataSource.java Sun May 20 09:46:10 2012
@@ -19,8 +19,8 @@
package org.apache.axis2.jibx;
-import org.apache.axiom.om.OMDataSource;
import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.QNameAwareOMDataSource;
import org.apache.axiom.om.util.StAXUtils;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallable;
@@ -40,7 +40,7 @@ import java.io.OutputStream;
import java.io.Writer;
/** Data source for OM element backed by JiBX data bound object. */
-public class JiBXDataSource implements OMDataSource {
+public class JiBXDataSource implements QNameAwareOMDataSource {
/** Mapping name, for when abstract mapping is used directly; <code>null</code> if not used). */
private final String marshallerName;
@@ -145,6 +145,18 @@ public class JiBXDataSource implements O
openNamespacePrefixes = nsprefixes;
}
+ public String getLocalName() {
+ return elementName;
+ }
+
+ public String getNamespaceURI() {
+ return elementNamespace;
+ }
+
+ public String getPrefix() {
+ return elementNamespacePrefix;
+ }
+
/**
* Internal method to handle the actual marshalling. If the source object is marshallable it's
* it's just marshalled directly, without worrying about redundant namespace declarations and
Modified: axis/axis2/java/core/trunk/modules/jibx/src/main/resources/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/main/resources/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl?rev=1340650&r1=1340649&r2=1340650&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jibx/src/main/resources/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl (original)
+++ axis/axis2/java/core/trunk/modules/jibx/src/main/resources/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl Sun May 20 09:46:10 2012
@@ -202,8 +202,7 @@
</xsl:when>
<xsl:otherwise>
org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(result, _type_name<xsl:value-of select="out-wrapper/return-element/@type-index"/>, "<xsl:value-of select='out-wrapper/return-element/@name'/>", "<xsl:value-of select='out-wrapper/return-element/@ns'/>", "<xsl:value-of select='out-wrapper/return-element/@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory);
- org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='out-wrapper/return-element/@ns'/>", "");
- org.apache.axiom.om.OMElement child = factory.createOMElement(src, "<xsl:value-of select='out-wrapper/return-element/@name'/>", appns);
+ org.apache.axiom.om.OMElement child = factory.createOMElement(src);
wrapper.addChild(child);
</xsl:otherwise>
</xsl:choose>
@@ -274,8 +273,7 @@
</xsl:when>
<xsl:otherwise>
org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(result, _type_name<xsl:value-of select="out-wrapper/return-element/@type-index"/>, "<xsl:value-of select='out-wrapper/return-element/@name'/>", "<xsl:value-of select='out-wrapper/return-element/@ns'/>", "<xsl:value-of select='out-wrapper/return-element/@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory);
- org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='out-wrapper/return-element/@ns'/>", "");
- org.apache.axiom.om.OMElement child = factory.createOMElement(src, "<xsl:value-of select='out-wrapper/return-element/@name'/>", appns);
+ org.apache.axiom.om.OMElement child = factory.createOMElement(src);
wrapper.addChild(child);
</xsl:otherwise>
</xsl:choose>
Added: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/handler/OMSourcedElementChecker.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/handler/OMSourcedElementChecker.java?rev=1340650&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/handler/OMSourcedElementChecker.java (added)
+++ axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/handler/OMSourcedElementChecker.java Sun May 20 09:46:10 2012
@@ -0,0 +1,58 @@
+/*
+ * 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.axis2.jibx.handler;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class OMSourcedElementChecker extends AbstractHandler {
+ private static final Log log = LogFactory.getLog(OMSourcedElementChecker.class);
+
+ public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
+ OMElement bodyElement = msgContext.getEnvelope().getBody().getFirstElement();
+ if (bodyElement instanceof OMSourcedElement) {
+ checkOMSourcedElement((OMSourcedElement)bodyElement);
+ } else {
+ // The body element may be a wrapper; check the children
+ for (Iterator it = bodyElement.getChildElements(); it.hasNext(); ) {
+ OMElement child = (OMElement)it.next();
+ if (child instanceof OMSourcedElement) {
+ checkOMSourcedElement((OMSourcedElement)child);
+ }
+ }
+ }
+ return InvocationResponse.CONTINUE;
+ }
+
+ private void checkOMSourcedElement(OMSourcedElement element) {
+ // Force OMSourcedElement to get the element name via QNameAwareOMDataSource
+ log.info("Found OMSourcedElement: name=" + element.getLocalName()
+ + "; namespace=" + element.getNamespaceURI()
+ + "; prefix=" + element.getPrefix());
+ // Now force expansion to let OMSourcedElement validate that the name is correct
+ element.getFirstOMChild();
+ }
+}
Propchange: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/handler/OMSourcedElementChecker.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java?rev=1340650&r1=1340649&r2=1340650&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java (original)
+++ axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java Sun May 20 09:46:10 2012
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNot
import org.apache.axis2.Constants;
import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.jibx.UtilServer;
import org.apache.axis2.jibx.beans.Book;
import org.apache.axis2.jibx.library.unwrapped.client.LibraryStub;
@@ -35,9 +36,11 @@ public class LibraryTest {
@BeforeClass
public static void startServer() throws Exception {
UtilServer.start(System.getProperty("basedir", ".") + "/target/repo/library-unwrapped");
- AxisService service = UtilServer.getConfigurationContext().getAxisConfiguration().getService("library");
+ AxisConfiguration axisConfiguration = UtilServer.getConfigurationContext().getAxisConfiguration();
+ AxisService service = axisConfiguration.getService("library");
service.getParameter(Constants.SERVICE_CLASS).setValue(LibraryImpl.class.getName());
service.setScope(Constants.SCOPE_APPLICATION);
+ service.engageModule(axisConfiguration.getModule("checker"));
}
@AfterClass
@@ -47,8 +50,11 @@ public class LibraryTest {
@Test
public void test() throws Exception {
- LibraryStub stub = new LibraryStub("http://127.0.0.1:5555/axis2/services/library");
+ LibraryStub stub = new LibraryStub(UtilServer.getConfigurationContext(), "http://127.0.0.1:5555/axis2/services/library");
+ stub._getServiceClient().engageModule("checker");
+
stub.addBook("Paperback", "0618918248", new String[] { "Richard Dawkins" }, "The God Delusion");
+
Book book = stub.getBook("0618918248");
assertNotNull(book);
assertEquals("Paperback", book.getType());
@@ -57,5 +63,9 @@ public class LibraryTest {
String[] authors = book.getAuthors();
assertEquals(1, authors.length);
assertEquals("Richard Dawkins", authors[0]);
+
+ Book[] books = stub.getBooksByType("Paperback");
+ assertEquals(1, books.length);
+ assertEquals("0618918248", books[0].getIsbn());
}
}
Modified: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/service/LibraryImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/service/LibraryImpl.java?rev=1340650&r1=1340649&r2=1340650&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/service/LibraryImpl.java (original)
+++ axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/service/LibraryImpl.java Sun May 20 09:46:10 2012
@@ -18,7 +18,9 @@
*/
package org.apache.axis2.jibx.library.unwrapped.service;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.axis2.jibx.beans.Book;
@@ -42,8 +44,13 @@ public class LibraryImpl implements Libr
}
public Book[] getBooksByType(String type) {
- // TODO Auto-generated method stub
- return null;
+ List<Book> result = new ArrayList<Book>();
+ for (Book book : books.values()) {
+ if (book.getType().equals(type)) {
+ result.add(book);
+ }
+ }
+ return result.toArray(new Book[result.size()]);
}
public boolean addBook(String type, String isbn, String[] authors, String title) {
Modified: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java?rev=1340650&r1=1340649&r2=1340650&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java (original)
+++ axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java Sun May 20 09:46:10 2012
@@ -20,6 +20,7 @@ package org.apache.axis2.jibx.library.wr
import org.apache.axis2.Constants;
import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.jibx.UtilServer;
import org.apache.axis2.jibx.beans.Book;
import org.apache.axis2.jibx.library.wrapped.client.LibraryStub;
@@ -33,8 +34,11 @@ public class LibraryTest {
@BeforeClass
public static void startServer() throws Exception {
UtilServer.start(System.getProperty("basedir", ".") + "/target/repo/library-wrapped");
- AxisService service = UtilServer.getConfigurationContext().getAxisConfiguration().getService("library");
+ AxisConfiguration axisConfiguration = UtilServer.getConfigurationContext().getAxisConfiguration();
+ AxisService service = axisConfiguration.getService("library");
service.getParameter(Constants.SERVICE_CLASS).setValue(LibraryImpl.class.getName());
+ service.setScope(Constants.SCOPE_APPLICATION);
+ service.engageModule(axisConfiguration.getModule("checker"));
}
@AfterClass
@@ -44,7 +48,9 @@ public class LibraryTest {
@Test
public void test() throws Exception {
- LibraryStub stub = new LibraryStub("http://127.0.0.1:5555/axis2/services/library");
+ LibraryStub stub = new LibraryStub(UtilServer.getConfigurationContext(), "http://127.0.0.1:5555/axis2/services/library");
+ stub._getServiceClient().engageModule("checker");
+
stub.addBook(new AddBookRequest(new Book("Paperback", "0618918248", "The God Delusion", new String[] { "Richard Dawkins" })));
}
}
Added: axis/axis2/java/core/trunk/modules/jibx/src/test/resources/META-INF/module.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/resources/META-INF/module.xml?rev=1340650&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/jibx/src/test/resources/META-INF/module.xml (added)
+++ axis/axis2/java/core/trunk/modules/jibx/src/test/resources/META-INF/module.xml Sun May 20 09:46:10 2012
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+ ~ 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.
+ -->
+<module name="checker">
+ <Description>OMSourcedElement/JiBXDataSource checker</Description>
+ <OutFlow>
+ <handler name="OMSourcedElementChecker" class="org.apache.axis2.jibx.handler.OMSourcedElementChecker">
+ <order phase="OperationOutPhase"/>
+ </handler>
+ </OutFlow>
+</module>
\ No newline at end of file
Propchange: axis/axis2/java/core/trunk/modules/jibx/src/test/resources/META-INF/module.xml
------------------------------------------------------------------------------
svn:eol-style = native