Author: heiko.braun(a)jboss.com
Date: 2006-12-07 12:10:48 -0500 (Thu, 07 Dec 2006)
New Revision: 1611
Modified:
trunk/src/main/java/javax/xml/soap/MessageFactory.java
trunk/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveXOPScanner.java
trunk/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
trunk/src/test/java/org/jboss/test/ws/jaxws/xop/MimeDeclarationTestCase.java
Log:
Fixed recursive loop in ReflectiveXOPScanner
Modified: trunk/src/main/java/javax/xml/soap/MessageFactory.java
===================================================================
--- trunk/src/main/java/javax/xml/soap/MessageFactory.java 2006-12-07 15:51:30 UTC (rev
1610)
+++ trunk/src/main/java/javax/xml/soap/MessageFactory.java 2006-12-07 17:10:48 UTC (rev
1611)
@@ -61,7 +61,7 @@
{
// provide logging
private static Logger log = Logger.getLogger(MessageFactory.class);
-
+
private static final String DEFAULT_MESSAGE_FACTORY =
"org.jboss.ws.core.soap.MessageFactoryImpl";
private static final String[] alternativeFactories = new String[] {
"org.jboss.axis.soap.MessageFactoryImpl" };
Modified: trunk/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveXOPScanner.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveXOPScanner.java 2006-12-07
15:51:30 UTC (rev 1610)
+++
trunk/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveXOPScanner.java 2006-12-07
17:10:48 UTC (rev 1611)
@@ -1,90 +1,149 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
package org.jboss.ws.extensions.xop.jaxws;
+import org.jboss.ws.core.utils.JavaUtils;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.annotation.XmlMimeType;
+import javax.xml.transform.Source;
+import java.awt.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
-import javax.xml.bind.annotation.XmlMimeType;
-
-import org.jboss.ws.core.utils.JavaUtils;
-
/**
+ * Scans data types for MTOM declarations.
+ * In order to re-use an instance of this class you need to invoke
<code>reset()</code>
+ * in between scans.
+ *
* @author Heiko Braun <heiko.braun(a)jboss.com>
* @version $Id$
* @since 04.12.2006
+ *
*/
-public class ReflectiveXOPScanner
-{
+public class ReflectiveXOPScanner {
+ private static List<Class> SUPPORTED_TYPES = new ArrayList<Class>(5);
+
+ static {
+ SUPPORTED_TYPES.add(String.class);
+ SUPPORTED_TYPES.add(byte[].class);
+ SUPPORTED_TYPES.add(Image.class);
+ SUPPORTED_TYPES.add(Source.class);
+ SUPPORTED_TYPES.add(DataHandler.class);
+ }
+
+ private List<Field> scannedFields = new ArrayList<Field>();
+
/**
* Scan java types for MTOM declarations
*
* @param xmlRoot
- * @return the first matching XmlMimeType#value()
+ * @return the first matching XmlMimeType#value() or <code>null</code> if
none found
*/
public String scan(Class xmlRoot)
{
- for (Field field : xmlRoot.getDeclaredFields())
+
+ if( isJDKType(xmlRoot) )
+ return null;
+
+ String mimeType = null;
+
+ for(Field field : xmlRoot.getDeclaredFields())
{
Class<?> type = field.getType();
- String mimeType = null;
-
- // prevent endless recursion
- if (type == xmlRoot)
- continue;
- if (field.isAnnotationPresent(XmlMimeType.class))
- {
- XmlMimeType mimeTypeDecl = field.getAnnotation(XmlMimeType.class);
- mimeType = mimeTypeDecl.value();
- }
+ boolean exceptionToTheRule = isMTOMDataType(type);
- if (null == mimeType) // try getter methods
+ // only non JDK types are inspected except for byte[] and java.lang.String
+ if( !alreadyScanned(field) && (exceptionToTheRule || !isJDKType(type))
)
{
- mimeType = scanGetterAnnotation(xmlRoot, field);
- }
+ if(field.isAnnotationPresent(XmlMimeType.class))
+ {
+ XmlMimeType mimeTypeDecl = field.getAnnotation(XmlMimeType.class);
+ mimeType = mimeTypeDecl.value();
+ }
- if (null == mimeType) // recursive search
- {
- if (!JavaUtils.isPrimitive(type) && !type.isArray() &&
!type.getName().startsWith("java"))
- scan(type);
+ if(null == mimeType) // try getter methods
+ {
+ mimeType = scanGetterAnnotation(xmlRoot, field);
+ }
+
+ // avoid recursive loops
+ if(!isMTOMDataType(type))
+ scannedFields.add(field);
+
+ // drill down if none found so far
+ if(null == mimeType)
+ mimeType = scan(type);
+
}
- else
- {
- return mimeType;
- }
}
- return null;
+ return mimeType;
}
+ private boolean alreadyScanned(Field field)
+ {
+
+ for(Field f : scannedFields)
+ {
+ if(f.equals(field))
+ return true;
+ }
+
+ return false;
+ }
+
+ public void reset()
+ {
+ scannedFields.clear();
+ }
+
+ private static boolean isMTOMDataType(Class clazz) {
+ for(Class cl : SUPPORTED_TYPES)
+ {
+ if(JavaUtils.isAssignableFrom(cl, clazz))
+ return true;
+ }
+
+ return false;
+ }
+
+ private static boolean isJDKType(Class clazz)
+ {
+ return clazz.getPackage()!= null ?
clazz.getPackage().getName().startsWith("java") : true;
+ }
+
private static String scanGetterAnnotation(Class owner, Field field)
{
- String getterMethodName = "get" + field.getName();
- for (Method method : owner.getDeclaredMethods())
+ String getterMethodName = "get"+field.getName();
+ for(Method method : owner.getDeclaredMethods())
{
- if (method.getName().equalsIgnoreCase(getterMethodName) &&
method.isAnnotationPresent(XmlMimeType.class))
+ if(method.getName().equalsIgnoreCase(getterMethodName)
+ && method.isAnnotationPresent(XmlMimeType.class))
{
XmlMimeType mimeTypeDecl = method.getAnnotation(XmlMimeType.class);
return mimeTypeDecl.value();
Modified:
trunk/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2006-12-07
15:51:30 UTC (rev 1610)
+++
trunk/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2006-12-07
17:10:48 UTC (rev 1611)
@@ -657,6 +657,17 @@
if (anWebService == null)
throw new WSException("Interface does not have a @WebService annotation:
" + seiName);
+ else
+ {
+ if(anWebService.portName().length()>0
+ || anWebService.serviceName().length()>0
+ || anWebService.endpointInterface().length()>0
+ )
+ {
+ throw new WSException(seiName + ": The service endpoint interface
MUST NOT include the JSR-181 annotation " +
+ "elements portName, serviceName and endpointInterface of the
annotation @WebService.");
+ }
+ }
name = anWebService.name();
if (name.length() == 0)
Modified: trunk/src/test/java/org/jboss/test/ws/jaxws/xop/MimeDeclarationTestCase.java
===================================================================
---
trunk/src/test/java/org/jboss/test/ws/jaxws/xop/MimeDeclarationTestCase.java 2006-12-07
15:51:30 UTC (rev 1610)
+++
trunk/src/test/java/org/jboss/test/ws/jaxws/xop/MimeDeclarationTestCase.java 2006-12-07
17:10:48 UTC (rev 1611)
@@ -40,6 +40,12 @@
static ReflectiveXOPScanner SCANNER = new ReflectiveXOPScanner();
+
+ protected void setUp() throws Exception
+ {
+ SCANNER.reset();
+ }
+
public void testFieldAnnotation() throws Exception
{
String mimeType = SCANNER.scan(FieldAnnotation.class);
@@ -75,8 +81,22 @@
String mimeType = SCANNER.scan( m.getParameterTypes()[0]);
assertNotNull("Unable to find xop declaration", mimeType);
+ assertEquals("text/xml", mimeType);
}
+ public void testSimpleRecursion() throws Exception
+ {
+ String mimeType = SCANNER.scan(SimpleRecursion.class);
+ assertNull(mimeType);
+ }
+
+ public void testComplexRecursion() throws Exception
+ {
+ String mimeType = SCANNER.scan(ComplexRecursion.class);
+ assertNotNull("Unable to find xop declaration", mimeType);
+ assertEquals("text/plain", mimeType);
+ }
+
class FieldAnnotation
{
@XmlMimeType("text/xml")
@@ -111,4 +131,20 @@
interface AnnotatedSEI {
void foo(@XmlMimeType("text/xml")byte[] bar);
}
+
+ class SimpleRecursion {
+ private SimpleRecursion data;
+ }
+
+ class ComplexRecursion
+ {
+ String data;
+ Nested nested;
+ }
+
+ class Nested
+ {
+ @XmlMimeType("text/plain")
+ String data;
+ }
}