incubator-wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngalla...@apache.org
Subject svn commit: r787557 [6/12] - in /incubator/wink/contrib/ibm-jaxrs: ./ lib/ src/ src/com/ src/com/ibm/ src/com/ibm/ws/ src/com/ibm/ws/jaxrs/ src/com/ibm/ws/jaxrs/annotations/ src/com/ibm/ws/jaxrs/context/ src/com/ibm/ws/jaxrs/core/ src/com/ibm/ws/jaxrs/...
Date Tue, 23 Jun 2009 05:41:55 GMT
Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/dd/jaxb/jaxrs_dd_schema.xsd
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/dd/jaxb/jaxrs_dd_schema.xsd?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/dd/jaxb/jaxrs_dd_schema.xsd (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/dd/jaxb/jaxrs_dd_schema.xsd Tue Jun 23 05:41:49 2009
@@ -0,0 +1,202 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
+	    targetNamespace="http://www.ibm.com/xml/ns/jaxrs"
+	    xmlns:jaxrs="http://www.ibm.com/xml/ns/jaxrs"
+	    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+	    elementFormDefault="qualified"
+	    attributeFormDefault="unqualified"
+	    version="1">
+
+	<xsd:element 
+		name="resources" 
+		type="jaxrs:resourcesType">
+	</xsd:element>
+	
+	<xsd:complexType name="resourcesType">
+	
+		<xsd:sequence>
+			<xsd:element name="resource"
+			   type="jaxrs:resourceType"
+			   minOccurs="0"
+			   maxOccurs="unbounded"/>
+			   
+			<xsd:element name="provider"
+			   type="jaxrs:providerType"
+			   minOccurs="0"
+			   maxOccurs="unbounded"/>
+			
+		</xsd:sequence>
+		
+	</xsd:complexType>
+	
+	<xsd:complexType name="resourceType">
+		<xsd:sequence>
+		
+			<xsd:element name="class-name"
+				type="xsd:string"
+				minOccurs="1"
+				maxOccurs="1"/>
+				
+			<xsd:element name="path"
+			   type="xsd:string"
+			   minOccurs="0"
+			   maxOccurs="1"/>
+			
+			<xsd:element name="provider"
+			   type="xsd:boolean"
+			   default="false"
+			   minOccurs="0"
+			   maxOccurs="1"/>
+			   
+			<xsd:choice
+				minOccurs="0"
+				maxOccurs="1">
+				<xsd:element name="aliases"
+			   		type="jaxrs:aliasesType"
+			   		minOccurs="0"
+			   		maxOccurs="1"/>
+			   	<xsd:element name="alias"
+			   		type="xsd:string"
+			   		minOccurs="0"
+			   		maxOccurs="1"/>
+			</xsd:choice>
+			
+			<xsd:element name="consumes"
+				type="jaxrs:consumesType"
+				minOccurs="0"
+				maxOccurs="1"/>
+			
+			<xsd:element name="produces"
+				type="jaxrs:producesType"
+				minOccurs="0"
+				maxOccurs="1"/>
+				
+			<xsd:element name="encoded"
+				type="xsd:boolean"
+				minOccurs="0"
+				maxOccurs="1"/>
+			
+			<xsd:element name="methods"
+				type="jaxrs:methodsType"
+				minOccurs="1"
+				maxOccurs="1"/>
+			
+		</xsd:sequence>
+	</xsd:complexType>
+	
+	<xsd:complexType name="aliasesType">
+		<xsd:sequence>
+			<xsd:element name="alias"
+				   		type="xsd:string"
+				   		minOccurs="0"
+				   		maxOccurs="unbounded"/>
+		</xsd:sequence>
+	</xsd:complexType>
+	
+	<xsd:complexType name="consumesType">
+		
+		<xsd:sequence>
+			<xsd:element name="mimeType"
+				   		type="xsd:string"
+				   		minOccurs="0"
+				   		maxOccurs="unbounded"/>
+		</xsd:sequence>	   		
+	</xsd:complexType>
+	
+	<xsd:complexType name="producesType">
+		<xsd:sequence>
+			<xsd:element name="mimeType"
+				   		type="xsd:string"
+				   		minOccurs="0"
+				   		maxOccurs="unbounded"/>
+		</xsd:sequence>	   		
+	</xsd:complexType>
+	
+	<xsd:complexType name="methodsType">
+		<xsd:sequence>
+			<xsd:element name="method"
+				   		type="jaxrs:methodType"
+				   		minOccurs="0"
+				   		maxOccurs="unbounded"/>
+		</xsd:sequence>	   		
+	</xsd:complexType>
+	
+	<xsd:complexType name="methodType">
+		<xsd:sequence>
+		
+			<xsd:element name="method-name"
+				type="xsd:string"
+				minOccurs="1"
+				maxOccurs="1"/>
+				
+			<xsd:element name="parameter"
+				type="jaxrs:parameterType"
+				minOccurs="0"
+				maxOccurs="unbounded"/>
+				
+			<xsd:element name="method-type"
+				   		type="xsd:string"
+				   		minOccurs="0"
+				   		maxOccurs="1"/>
+				   		
+			<xsd:element name="path"
+				   		type="xsd:string"
+				   		minOccurs="0"
+				   		maxOccurs="1"/>
+				   		
+			<xsd:element name="consumes"
+					type="jaxrs:consumesType"
+					minOccurs="0"
+					maxOccurs="1"/>
+				
+			<xsd:element name="produces"
+					type="jaxrs:producesType"
+					minOccurs="0"
+					maxOccurs="1"/>
+					
+			<xsd:element name="encoded"
+				type="xsd:boolean"
+				minOccurs="0"
+				maxOccurs="1"/>
+				
+			<xsd:element name="defaultValue"
+				type="xsd:string"
+				minOccurs="0"
+				maxOccurs="1"/>
+				
+		</xsd:sequence>	   		
+	</xsd:complexType>
+	
+	<xsd:complexType name="parameterType">
+		<xsd:sequence>
+		
+			<xsd:element name="type"
+				type="xsd:string"
+				minOccurs="0"
+				maxOccurs="1"/>
+				
+		</xsd:sequence>
+	</xsd:complexType>
+	
+	<xsd:complexType name="providerType">
+		<xsd:sequence>
+		
+			<xsd:element name="class-name"
+				type="xsd:string"
+				minOccurs="1"
+				maxOccurs="1"/>
+			
+			<xsd:element name="consumes"
+					type="jaxrs:consumesType"
+					minOccurs="0"
+					maxOccurs="1"/>
+				
+			<xsd:element name="produces"
+					type="jaxrs:producesType"
+					minOccurs="0"
+					maxOccurs="1"/>
+			
+		</xsd:sequence>
+	</xsd:complexType>
+
+</xsd:schema>	    
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/dd/jaxb/package-info.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/dd/jaxb/package-info.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/dd/jaxb/package-info.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/dd/jaxb/package-info.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.3 in JDK 1.6
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2008.12.05 at 12:47:27 PM CST
+//
+
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.ibm.com/xml/ns/jaxrs", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package com.ibm.ws.jaxrs.model.dd.jaxb;
+

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/AbstractResourceInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/AbstractResourceInfoImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/AbstractResourceInfoImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/AbstractResourceInfoImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,397 @@
+/*
+ * 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 com.ibm.ws.jaxrs.model.reflective;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.MatrixParam;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+public abstract class AbstractResourceInfoImpl implements AbstractResourceInfo {
+
+    private static final Log log = LogFactory
+            .getLog(AbstractResourceInfoImpl.class);
+
+    final private boolean root;
+
+    final private Class<?> resourceClass;
+
+    final private Class<?> serviceClass;
+
+    private List<Field> contextFields;
+
+    private List<Field> resourceFields;
+
+    private Map<Class<?>, Method> contextMethods;
+
+    private Map<Field, ThreadLocalProxy> fieldProxyMap;
+
+    private Map<Field, ThreadLocalProxy> resourceProxyMap;
+
+    private Map<Method, ThreadLocalProxy> setterProxyMap;
+
+    private Map<Constructor<?>, Map<Class<?>, ThreadLocalProxy>> constructorContextProxyMap;
+
+    final private Constructor<?> selectedConstructor;
+
+    protected AbstractResourceInfoImpl(Class<?> resourceClass, Class<?> serviceClass, boolean isRoot) {
+        this.serviceClass = serviceClass;
+        this.resourceClass = resourceClass;
+        root = isRoot;
+        if (root && resourceClass != null) {
+            initConstructorParams();
+            initContextFields();
+            initContextSetterMethods();
+        }
+        if (this.serviceClass != null) {
+            selectedConstructor = selectConstructor(this.serviceClass);
+        } else {
+            selectedConstructor = null;
+        }
+    }
+
+    public Class<?> getServiceClass() {
+        return serviceClass;
+    }
+
+    public Constructor<?> getSelectedServiceClassConstructor() {
+        return selectedConstructor;
+    }
+
+    /**
+     * Initialize our map of constructors to ThreadLocalProxy objects that will
+     * enable injection of constructor parameters.
+     *
+     */
+    public void initConstructorParams() {
+        Constructor<?>[] cstrs = resourceClass.getDeclaredConstructors();
+        for (Constructor<?> cstr : cstrs) {
+            Class<?>[] paramTypes = cstr.getParameterTypes();
+            Annotation[][] allAnnots = cstr.getParameterAnnotations();
+            int paramIndex = 0;
+            for (Class<?> paramType : paramTypes) {
+                if (paramIndex < allAnnots.length) {
+                    Annotation[] paramAnnots = allAnnots[paramIndex];
+                    for (Annotation annot : paramAnnots) {
+                        if (annot.annotationType().equals(Context.class)) {
+
+                            // initialize map if necessary
+                            if (constructorContextProxyMap == null) {
+                                constructorContextProxyMap = new HashMap<Constructor<?>, Map<Class<?>, ThreadLocalProxy>>();
+                            }
+
+                            // get the mapping of constructor parameter types to proxy objects
+                            Map<Class<?>, ThreadLocalProxy> cstrParamProxies = constructorContextProxyMap
+                                    .get(cstr);
+
+                            // initalize map if necessary
+                            if (cstrParamProxies == null) {
+                                cstrParamProxies = new HashMap<Class<?>, ThreadLocalProxy>();
+                                constructorContextProxyMap.put(cstr,
+                                        cstrParamProxies);
+                            }
+
+                            // create the appropriate proxy object and save in the map
+                            ThreadLocalProxy tlp = InjectionUtils
+                                    .createThreadLocalProxy(paramType);
+                            cstrParamProxies.put(paramType, tlp);
+                        }
+                    }
+                }
+                paramIndex++;
+            }
+        }
+    }
+
+    public void initContextFields() {
+        if (resourceClass == null || !root) {
+            return;
+        }
+
+        for (Field f : getServiceClass().getDeclaredFields()) {
+            for (Annotation a : f.getAnnotations()) {
+                if (a.annotationType() == Context.class) {
+                    if (contextFields == null) {
+                        contextFields = new ArrayList<Field>();
+                    }
+                    contextFields.add(f);
+                    if (fieldProxyMap == null) {
+                        fieldProxyMap = new HashMap<Field, ThreadLocalProxy>();
+                    }
+                    fieldProxyMap.put(f, InjectionUtils
+                            .createThreadLocalProxy(f.getType()));
+                } else if (a.annotationType() == Resource.class) {
+                    /*
+                     * should eventually add the other resources
+                     */
+                    if (resourceFields == null) {
+                        resourceFields = new ArrayList<Field>();
+                    }
+                    resourceFields.add(f);
+                    if (resourceProxyMap == null) {
+                        resourceProxyMap = new HashMap<Field, ThreadLocalProxy>();
+                    }
+                    resourceProxyMap.put(f, InjectionUtils
+                            .createThreadLocalProxy(f.getType()));
+                }
+            }
+        }
+    }
+
+    public void initContextSetterMethods() {
+
+        for (Method m : getServiceClass().getMethods()) {
+
+            if (!m.getName().startsWith("set")
+                    || m.getParameterTypes().length != 1) {
+                continue;
+            }
+            for (Annotation a : m.getAnnotations()) {
+                if (a.annotationType() == Context.class) {
+                    checkContextMethod(m);
+                    break;
+                }
+            }
+        }
+    }
+
+    private void checkContextMethod(Method m) {
+        Class<?> type = m.getParameterTypes()[0];
+        if (AnnotationUtils.isContextClass(type)
+                && m.getName().startsWith("set")) {
+            addContextMethod(type, m);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public Map<Class<?>, Method> getContextMethods() {
+        return contextMethods == null ? Collections.EMPTY_MAP : Collections
+                .unmodifiableMap(contextMethods);
+    }
+
+    private void addContextMethod(Class<?> contextClass, Method m) {
+        if (contextMethods == null) {
+            contextMethods = new HashMap<Class<?>, Method>();
+        }
+        contextMethods.put(contextClass, m);
+        if (setterProxyMap == null) {
+            setterProxyMap = new HashMap<Method, ThreadLocalProxy>();
+        }
+        setterProxyMap.put(m, InjectionUtils.createThreadLocalProxy(m
+                .getParameterTypes()[0]));
+    }
+
+    public boolean isRoot() {
+        return root;
+    }
+
+    public Class<?> getResourceClass() {
+        return resourceClass;
+    }
+
+    public List<Field> getContextFields() {
+        return getList(contextFields);
+    }
+
+    public List<Field> getResourceFields() {
+        return getList(resourceFields);
+    }
+
+    private static List<Field> getList(List<Field> fields) {
+        List<Field> ret;
+        if (fields != null) {
+            ret = Collections.unmodifiableList(fields);
+        } else {
+            ret = Collections.emptyList();
+        }
+        return ret;
+    }
+
+    public Map<Class<?>, ThreadLocalProxy> getConstructorContextProxies(Constructor<?> cstr) {
+        return constructorContextProxyMap == null ? null
+                : constructorContextProxyMap.get(cstr);
+    }
+
+    public ThreadLocalProxy getContextFieldProxy(Field f) {
+        return fieldProxyMap == null ? null : fieldProxyMap.get(f);
+    }
+
+    public ThreadLocalProxy getResourceFieldProxy(Field f) {
+        return resourceProxyMap == null ? null : resourceProxyMap.get(f);
+    }
+
+    public ThreadLocalProxy getContextSetterProxy(Method m) {
+        return setterProxyMap == null ? null : setterProxyMap.get(m);
+    }
+
+    public abstract boolean isSingleton();
+
+    public abstract Object getSingleton();
+
+    public void clearThreadLocalProxies() {
+        clearProxies(fieldProxyMap);
+        clearProxies(resourceProxyMap);
+        clearProxies(setterProxyMap);
+
+        // clear the constructor map as well
+        if (constructorContextProxyMap != null
+                && constructorContextProxyMap.values() != null
+                && !constructorContextProxyMap.values().isEmpty()) {
+            for (Map<Class<?>, ThreadLocalProxy> proxyMap : constructorContextProxyMap
+                    .values()) {
+                clearProxies(proxyMap);
+            }
+        }
+
+    }
+
+    private static void clearProxies(Map<?, ThreadLocalProxy> tlps) {
+        if (tlps == null) {
+            return;
+        }
+        for (ThreadLocalProxy tlp : tlps.values()) {
+            if (tlp != null) {
+                tlp.remove();
+            }
+        }
+    }
+
+    /**
+     * This will select the appropriate constructor with which a resource or
+     * provider instance will be created. It will select the constructor with
+     * the most acceptable annotated parameters. If there are no parameters
+     * annotated with acceptable annotatiosn, a public no-arg constructor will
+     * be selected. If a constructor is not found, an exception will be thrown.
+     *
+     */
+    static Constructor<?> selectConstructor(final Class<?> clazz)
+            throws WebApplicationException {
+        Constructor<?>[] constructors = null;
+
+        constructors = AccessController
+                .doPrivileged(new PrivilegedAction<Constructor<?>[]>() {
+                    public Constructor<?>[] run() {
+                        return clazz.getDeclaredConstructors();
+                    }
+                });
+
+        if (constructors == null) {
+            if (log.isErrorEnabled()) {
+                log.error(Messages.getMessage("invalidCstr", clazz.getName()));
+            }
+            return null;
+        }
+
+        int maxParams = 0;
+        Constructor<?> annotatedConstructor = null;
+        Constructor<?> defaultConstructor = null;
+
+        for (Constructor<?> constructor : constructors) {
+            int annotationCount = 0;
+
+            // if it is the default no-arg cstr, save it off
+            if (constructor.getParameterTypes() == null
+                    || constructor.getParameterTypes().length == 0) {
+                defaultConstructor = constructor;
+            }
+
+            // otherwise, we need to look for annotations
+            else {
+                Annotation[][] paramAnnotations = constructor
+                        .getParameterAnnotations();
+
+                if (paramAnnotations != null) {
+                    for (Annotation[] annotations : paramAnnotations) {
+                        if (annotations != null) {
+                            for (Annotation annotation : annotations) {
+                                if (annotation.annotationType().equals(
+                                        Context.class)
+                                        || annotation.annotationType().equals(
+                                                QueryParam.class)
+                                        || annotation.annotationType().equals(
+                                                HeaderParam.class)
+                                        || annotation.annotationType().equals(
+                                                CookieParam.class)
+                                        || annotation.annotationType().equals(
+                                                MatrixParam.class)
+                                        || annotation.annotationType().equals(
+                                                PathParam.class)) {
+                                    annotationCount++;
+                                }
+                            }
+                        }
+                    }
+                }
+                if (annotationCount > maxParams
+                        && annotationCount == constructor.getParameterTypes().length) {
+                    maxParams = annotationCount;
+                    annotatedConstructor = constructor;
+                }
+            }
+
+        }
+
+        // make sure we have a constructor
+        if (annotatedConstructor == null && defaultConstructor == null) {
+            if (log.isErrorEnabled()) {
+                log.error(Messages.getMessage("invalidCstr", clazz.getName()));
+            }
+        } else if (log.isDebugEnabled()) {
+            Constructor<?> dbgCstr = annotatedConstructor != null ? annotatedConstructor
+                    : defaultConstructor;
+            log.debug("The selected constructor for the " + clazz.getName()
+                    + " class has " + "the following argument types: ");
+            Class<?>[] cstrParams = dbgCstr.getParameterTypes();
+            for (Class<?> cstrParam : cstrParams) {
+                log.debug("Type: " + cstrParam.getName());
+            }
+        }
+
+        return annotatedConstructor != null ? annotatedConstructor
+                : defaultConstructor;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ClassResourceInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ClassResourceInfoImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ClassResourceInfoImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ClassResourceInfoImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,283 @@
+/*
+ * 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 com.ibm.ws.jaxrs.model.reflective;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.MethodDispatcher;
+import org.apache.cxf.jaxrs.model.URITemplate;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+import com.ibm.ws.jaxrs.annotations.Alias;
+import com.ibm.ws.jaxrs.annotations.Aliases;
+
+public class ClassResourceInfoImpl extends AbstractResourceInfoImpl implements ClassResourceInfo {
+
+    protected URITemplate uriTemplate;
+
+    protected List<URITemplate> uriAliasTemplates;
+
+    protected MethodDispatcher methodDispatcher;
+
+    protected List<ClassResourceInfo> subClassResourceInfo = new ArrayList<ClassResourceInfo>();
+
+    protected List<Field> paramFields;
+
+    protected List<Method> paramMethods;
+
+    protected boolean isSingleton = false;
+
+    protected Object singleton;
+
+    protected Map<Property, Object> values = new HashMap<Property, Object>();
+
+    private List<MediaType> produces = null;
+
+    private List<MediaType> consumes = null;
+
+    private String path = null;
+
+    private boolean pathInit = false;
+
+    private String[] aliasPaths = null;
+
+    private boolean apInit = false;
+
+    public ClassResourceInfoImpl(Class<?> theResourceClass, Object singleton, boolean isRoot) {
+        this(theResourceClass, theResourceClass, isRoot);
+        if (singleton != null) {
+            this.singleton = singleton;
+            isSingleton = true;
+            InjectionUtils.injectContextProxies(this, singleton);
+        }
+        uriAliasTemplates = new ArrayList<URITemplate>();
+    }
+
+    public ClassResourceInfoImpl(Class<?> theResourceClass) {
+        this(theResourceClass, theResourceClass, false);
+    }
+
+    public ClassResourceInfoImpl(Class<?> theResourceClass, Class<?> theServiceClass, boolean theRoot) {
+        super(theResourceClass, theServiceClass, theRoot);
+        if (theRoot) {
+            initParamFields();
+            initParamMethods();
+        }
+    }
+
+    private void initParamFields() {
+        if (getResourceClass() == null || !isRoot()) {
+            return;
+        }
+
+        for (Field f : getServiceClass().getDeclaredFields()) {
+            for (Annotation a : f.getAnnotations()) {
+                if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
+                    if (paramFields == null) {
+                        paramFields = new ArrayList<Field>();
+                    }
+                    paramFields.add(f);
+                }
+            }
+        }
+    }
+
+    private void initParamMethods() {
+
+        for (Method m : getServiceClass().getMethods()) {
+
+            if (!m.getName().startsWith("set")
+                    || m.getParameterTypes().length != 1) {
+                continue;
+            }
+            for (Annotation a : m.getAnnotations()) {
+                if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
+                    checkParamMethod(m, AnnotationUtils.getAnnotationValue(a));
+                    break;
+                }
+            }
+        }
+    }
+
+    public URITemplate getURITemplate() {
+        return uriTemplate;
+    }
+
+    public void setURITemplate(URITemplate u) {
+        uriTemplate = u;
+    }
+
+    public MethodDispatcher getMethodDispatcher() {
+        return methodDispatcher;
+    }
+
+    public void setMethodDispatcher(MethodDispatcher md) {
+        methodDispatcher = md;
+    }
+
+    public boolean hasSubResources() {
+        return !subClassResourceInfo.isEmpty();
+    }
+
+    public void addSubClassResourceInfo(ClassResourceInfo cri) {
+        subClassResourceInfo.add(cri);
+    }
+
+    public List<ClassResourceInfo> getSubClassResourceInfo() {
+        return subClassResourceInfo;
+    }
+
+    public List<MediaType> getProduces() {
+        if (values.containsKey(Property.PRODUCES)) {
+            produces = (List<MediaType>) values.get(Property.PRODUCES);
+        } else if (produces == null) {
+            Produces producesAnnot = (Produces) AnnotationUtils
+                    .getClassAnnotation(getServiceClass(), Produces.class);
+            produces = JAXRSUtils.getProduceTypes(producesAnnot);
+        }
+        return produces;
+    }
+
+    public List<MediaType> getConsumes() {
+        if (values.containsKey(Property.CONSUMES)) {
+            consumes = (List<MediaType>) values.get(Property.CONSUMES);
+        } else if (consumes == null) {
+            Consumes consumesAnnot = (Consumes) AnnotationUtils
+                    .getClassAnnotation(getServiceClass(), Consumes.class);
+            consumes = JAXRSUtils.getConsumeTypes(consumesAnnot);
+        }
+        return consumes;
+    }
+
+    public String getPath() {
+        if (values.containsKey(Property.PATH)) {
+            path = (String) values.get(Property.PATH);
+        } else if (!pathInit) {
+            Path pathAnnot = (Path) AnnotationUtils.getClassAnnotation(
+                    getServiceClass(), Path.class);
+            path = pathAnnot != null ? pathAnnot.value() : null;
+            pathInit = true;
+        }
+        return path;
+    }
+
+    /**
+     * This returns the paths indicated by @Alias annotations that may
+     * optionally be present on the class.
+     */
+    public String[] getAliasPaths() {
+        if (values.containsKey(Property.ALIAS_PATHS)) {
+            aliasPaths = (String[]) values.get(Property.ALIAS_PATHS);
+        } else if (!apInit) {
+            if (values.containsKey(Property.ALIAS_PATH)) {
+                String[] myAliasPaths = new String[1];
+                myAliasPaths[0] = (String) values.get(Property.ALIAS_PATH);
+            } else {
+                // look for @Aliases first
+                Aliases aliases = (Aliases) AnnotationUtils.getClassAnnotation(
+                        getServiceClass(), Aliases.class);
+                if (aliases != null && aliases.value() != null) {
+                    aliasPaths = new String[aliases.value().length];
+                    int i = 0;
+                    for (Alias alias : aliases.value()) {
+                        aliasPaths[i] = alias.value();
+                        i++;
+                    }
+                }
+
+                // if not found look for @Alias
+                else {
+                    Alias alias = (Alias) AnnotationUtils.getClassAnnotation(
+                            getServiceClass(), Alias.class);
+                    if (alias != null && alias.value() != null) {
+                        aliasPaths = new String[1];
+                        aliasPaths[0] = alias.value();
+                    }
+                }
+            }
+            apInit = true;
+        }
+
+        return aliasPaths;
+    }
+
+    private void addParamMethod(Method m) {
+        if (paramMethods == null) {
+            paramMethods = new ArrayList<Method>();
+        }
+        paramMethods.add(m);
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<Method> getParameterMethods() {
+        return paramMethods == null ? Collections.EMPTY_LIST : Collections
+                .unmodifiableList(paramMethods);
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<Field> getParameterFields() {
+        return paramFields == null ? Collections.EMPTY_LIST : Collections
+                .unmodifiableList(paramFields);
+    }
+
+    private void checkParamMethod(Method m, String value) {
+        if (m.getName().equalsIgnoreCase("set" + value)) {
+            addParamMethod(m);
+        }
+    }
+
+    public void addURIAliasTemplate(URITemplate myURITemplate) {
+        uriAliasTemplates.add(myURITemplate);
+    }
+
+    public List<URITemplate> getURIAliasTemplates() {
+        return uriAliasTemplates;
+    }
+
+    @Override
+    public boolean isSingleton() {
+        return isSingleton;
+    }
+
+    @Override
+    public Object getSingleton() {
+        return singleton;
+    }
+
+    public void setValue(Property property, Object value) {
+        values.put(property, value);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,233 @@
+/*
+ * 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 com.ibm.ws.jaxrs.model.reflective;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.URITemplate;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+public class OperationResourceInfoImpl implements OperationResourceInfo {
+
+    protected URITemplate uriTemplate;
+
+    protected ClassResourceInfo classResourceInfo;
+
+    protected Method methodToInvoke;
+
+    protected Method annotatedMethod;
+
+    protected String httpMethod;
+
+    protected List<MediaType> produceMimes;
+
+    protected List<MediaType> consumeMimes;
+
+    private String path;
+
+    private boolean pathInit = false;
+
+    protected boolean encoded;
+
+    protected String defaultParamValue;
+
+    protected boolean subResourceMethod;
+
+    protected boolean subResourceLocator;
+
+    protected Map<Property, Object> values = new HashMap<Property, Object>();
+
+    protected boolean isFormParamFound;
+
+    public OperationResourceInfoImpl(Method m, ClassResourceInfo cri) {
+        methodToInvoke = m;
+        annotatedMethod = m;
+        classResourceInfo = cri;
+        isFormParamFound = false;
+        checkMediaTypes();
+        checkEncoded();
+        checkDefaultParameterValue();
+    }
+
+    public URITemplate getURITemplate() {
+        return uriTemplate;
+    }
+
+    public void setURITemplate(URITemplate u) {
+        uriTemplate = u;
+    }
+
+    public ClassResourceInfo getClassResourceInfo() {
+        return classResourceInfo;
+    }
+
+    public void setClassResourceInfo(ClassResourceInfo c) {
+        classResourceInfo = c;
+    }
+
+    public Method getMethodToInvoke() {
+        return methodToInvoke;
+    }
+
+    public void setMethodToInvoke(Method m) {
+        methodToInvoke = m;
+    }
+
+    public String getHttpMethod() {
+        return httpMethod;
+    }
+
+    public void setHttpMethod(String m) {
+        httpMethod = m;
+    }
+
+    public void setAnnotatedMethod(Method m) {
+        annotatedMethod = m;
+        checkMediaTypes();
+    }
+
+    public Method getAnnotatedMethod() {
+        return annotatedMethod;
+    }
+
+    public boolean isSubResourceLocator() {
+        return subResourceLocator;
+    }
+
+    public void setIsSubResourceLocator(boolean subResourceLocator) {
+        this.subResourceLocator = subResourceLocator;
+    }
+
+    public boolean isSubResourceMethod() {
+        return subResourceMethod;
+    }
+
+    public void setIsSubResourceMethod(boolean subResourceMethod) {
+        this.subResourceMethod = subResourceMethod;
+    }
+
+    public List<MediaType> getProduces() {
+        if (values.containsKey(Property.PRODUCES)) {
+            return (List<MediaType>) values.get(Property.PRODUCES);
+        }
+        return produceMimes;
+    }
+
+    public List<MediaType> getConsumes() {
+        if (values.containsKey(Property.CONSUMES)) {
+            return (List<MediaType>) values.get(Property.CONSUMES);
+        }
+        return consumeMimes;
+    }
+
+    protected void checkMediaTypes() {
+        Consumes cm = (Consumes) AnnotationUtils.getMethodAnnotation(
+                annotatedMethod, Consumes.class);
+        if (cm != null) {
+            consumeMimes = JAXRSUtils.sortMediaTypes(JAXRSUtils
+                    .getMediaTypes(cm.value()));
+        } else if (classResourceInfo != null) {
+            consumeMimes = JAXRSUtils.sortMediaTypes(classResourceInfo
+                    .getConsumes());
+        }
+
+        Produces pm = (Produces) AnnotationUtils.getMethodAnnotation(
+                annotatedMethod, Produces.class);
+        if (pm != null) {
+            produceMimes = JAXRSUtils.sortMediaTypes(JAXRSUtils
+                    .getMediaTypes(pm.value()));
+        } else if (classResourceInfo != null) {
+            produceMimes = JAXRSUtils.sortMediaTypes(classResourceInfo
+                    .getProduces());
+        }
+    }
+
+    public String getPath() {
+        if (values.containsKey(Property.PATH)) {
+            path = (String) values.get(Property.PATH);
+        } else if (!pathInit) {
+            Path pathAnnot = (Path) AnnotationUtils.getMethodAnnotation(
+                    annotatedMethod, Path.class);
+            path = pathAnnot != null ? pathAnnot.value() : null;
+        }
+        return path;
+    }
+
+    public boolean isEncodedEnabled() {
+        if (values.containsKey(Property.ENCODED)) {
+            encoded = ((Boolean) values.get(Property.ENCODED)).booleanValue();
+        }
+        return encoded;
+    }
+
+    public String getDefaultParameterValue() {
+        if (values.containsKey(Property.DEFAULT_VALUE)) {
+            defaultParamValue = (String) values.get(Property.DEFAULT_VALUE);
+        }
+        return defaultParamValue;
+    }
+
+    protected void checkEncoded() {
+        encoded = AnnotationUtils.getMethodAnnotation(annotatedMethod,
+                Encoded.class) != null;
+        if (!encoded && classResourceInfo != null) {
+            encoded = AnnotationUtils.getClassAnnotation(classResourceInfo
+                    .getServiceClass(), Encoded.class) != null;
+        }
+    }
+
+    protected void checkDefaultParameterValue() {
+        DefaultValue dv = (DefaultValue) AnnotationUtils.getMethodAnnotation(
+                annotatedMethod, DefaultValue.class);
+        if (dv == null && classResourceInfo != null) {
+            dv = (DefaultValue) AnnotationUtils.getClassAnnotation(
+                    classResourceInfo.getServiceClass(), DefaultValue.class);
+        }
+        if (dv != null) {
+            defaultParamValue = dv.value();
+        }
+    }
+
+    public void setValue(Property property, Object value) {
+        values.put(property, value);
+    }
+
+    public boolean isFormParamFound() {
+        return isFormParamFound;
+    }
+
+    public void setIsFormParamFound(boolean isFormParamFound) {
+        this.isFormParamFound = isFormParamFound;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,233 @@
+/*
+ * 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 com.ibm.ws.jaxrs.model.reflective;
+
+import java.lang.reflect.ParameterizedType;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+public class ProviderInfoImpl<T> extends AbstractResourceInfoImpl implements ProviderInfo<T> {
+
+    final private Class providerClass;
+
+    final private static Log log = LogFactory.getLog(ProviderInfoImpl.class);
+
+    final protected List<Type> providerTypes;
+
+    final protected T providerInstance;
+
+    final private List<MediaType> produces;
+
+    final private List<MediaType> consumes;
+
+    final private Map<Type, java.lang.reflect.Type> reflectedTypes;
+
+    public ProviderInfoImpl(Class<T> providerClass) {
+        this(providerClass,
+                (providerClass == null) ? new ArrayList<MediaType>()
+                        : JAXRSUtils.getConsumeTypes((providerClass
+                                .getAnnotation(Consumes.class))),
+                (providerClass == null) ? new ArrayList<MediaType>()
+                        : JAXRSUtils.getProduceTypes(providerClass
+                                .getAnnotation(Produces.class)));
+    }
+
+    public ProviderInfoImpl(Class<T> providerClass, List<MediaType> consumes, List<MediaType> produces) {
+        super(providerClass, providerClass, true);
+        this.providerClass = providerClass;
+        this.providerInstance = null;
+        if (consumes == null) {
+            this.consumes = Collections.singletonList(MediaType.WILDCARD_TYPE);
+        } else {
+            List<MediaType> temp = new ArrayList<MediaType>();
+            temp.addAll(consumes);
+            this.consumes = Collections.unmodifiableList(temp);
+        }
+        if (produces == null) {
+            this.produces = Collections.singletonList(MediaType.WILDCARD_TYPE);
+        } else {
+            List<MediaType> temp = new ArrayList<MediaType>();
+            temp.addAll(produces);
+            this.produces = Collections.unmodifiableList(temp);
+        }
+        if (providerClass != null) {
+            this.providerTypes = Collections.unmodifiableList(JAXRSUtils
+                    .getProviderTypes(providerClass));
+        } else {
+            this.providerTypes = null;
+        }
+        this.reflectedTypes = Collections
+                .unmodifiableMap(initParameterizedType(providerClass));
+    }
+
+    public ProviderInfoImpl(T providerInstance) {
+        this(providerInstance, JAXRSUtils.getConsumeTypes((providerInstance
+                .getClass().getAnnotation(Consumes.class))), JAXRSUtils
+                .getProduceTypes((providerInstance.getClass()
+                        .getAnnotation(Produces.class))));
+    }
+
+    public ProviderInfoImpl(T providerInstance, List<MediaType> consumes, List<MediaType> produces) {
+        super(providerInstance.getClass(), providerInstance.getClass(), true);
+        this.providerClass = providerInstance.getClass();
+        this.providerInstance = providerInstance;
+        if (consumes == null) {
+            this.consumes = Collections.singletonList(MediaType.WILDCARD_TYPE);
+        } else {
+            List<MediaType> temp = new ArrayList<MediaType>();
+            temp.addAll(consumes);
+            this.consumes = Collections.unmodifiableList(temp);
+        }
+        if (produces == null) {
+            this.produces = Collections.singletonList(MediaType.WILDCARD_TYPE);
+        } else {
+            List<MediaType> temp = new ArrayList<MediaType>();
+            temp.addAll(produces);
+            this.produces = Collections.unmodifiableList(temp);
+        }
+        this.providerTypes = Collections.unmodifiableList(JAXRSUtils
+                .getProviderTypes(providerClass));
+        this.reflectedTypes = Collections
+                .unmodifiableMap(initParameterizedType(providerClass));
+
+        /*
+         * init the context proxies
+         */
+        InjectionUtils.injectContextProxies(this, providerInstance);
+    }
+
+    /**
+     * Return the Class object that was annotated with
+     *
+     * @Provider.
+     */
+    public Class<T> getProviderClass() {
+        return providerClass;
+    }
+
+    /**
+     * This method will return a list of enums that convey the types that are
+     * implemented by the class annotated with @Provider.
+     *
+     */
+    public List<Type> getProviderTypes() {
+        return providerTypes;
+    }
+
+    public List<MediaType> getConsumesTypes() {
+        return consumes;
+    }
+
+    public List<MediaType> getProducesTypes() {
+        return produces;
+    }
+
+    @Override
+    public boolean isSingleton() {
+        return providerInstance != null;
+    }
+
+    @Override
+    public Object getSingleton() {
+        return providerInstance;
+    }
+
+    public Map<Type, java.lang.reflect.Type> getParameterizedType() {
+        return reflectedTypes;
+    }
+
+    final static private Map<Type, java.lang.reflect.Type> initParameterizedType(Class<?> clazz) {
+        Class<?> inspectedClass = clazz;
+        Map<Type, java.lang.reflect.Type> mappedTypes = new HashMap<Type, java.lang.reflect.Type>();
+        while (inspectedClass != null) {
+            java.lang.reflect.Type[] types = inspectedClass
+                    .getGenericInterfaces();
+            List<ParameterizedType> allInterfaces = new ArrayList<ParameterizedType>();
+            for (java.lang.reflect.Type t : types) {
+                allInterfaces.addAll(findAllParameterizedTypes(t));
+            }
+            for (ParameterizedType pt : allInterfaces) {
+                if (MessageBodyReader.class.equals(pt.getRawType())) {
+                    java.lang.reflect.Type[] args = pt.getActualTypeArguments();
+                    if (args.length != 1) {
+                        throw new IllegalStateException();
+                    }
+                    mappedTypes.put(Type.MessageBodyReader, args[0]);
+                } else if (MessageBodyWriter.class.equals(pt.getRawType())) {
+                    java.lang.reflect.Type[] args = pt.getActualTypeArguments();
+                    if (args.length != 1) {
+                        throw new IllegalStateException();
+                    }
+                    mappedTypes.put(Type.MessageBodyWriter, args[0]);
+                } else if (ContextResolver.class.equals(pt.getRawType())) {
+                    java.lang.reflect.Type[] args = pt.getActualTypeArguments();
+                    if (args.length != 1) {
+                        throw new IllegalStateException();
+                    }
+                    mappedTypes.put(Type.ContextResolver, args[0]);
+                } else if (ExceptionMapper.class.equals(pt.getRawType())) {
+                    java.lang.reflect.Type[] args = pt.getActualTypeArguments();
+                    if (args.length != 1) {
+                        throw new IllegalStateException();
+                    }
+                    mappedTypes.put(Type.ExceptionMapper, args[0]);
+                }
+            }
+            inspectedClass = inspectedClass.getSuperclass();
+        }
+
+        return mappedTypes;
+    }
+
+    private static List<ParameterizedType> findAllParameterizedTypes(java.lang.reflect.Type t) {
+        List<ParameterizedType> types = new ArrayList<ParameterizedType>();
+        if (t instanceof ParameterizedType) {
+            types.add((ParameterizedType) t);
+        }
+        if (t instanceof Class) {
+            Class<?> c = (Class<?>) t;
+            if (c.isInterface()) {
+                for (java.lang.reflect.Type implementedType : c
+                        .getGenericInterfaces()) {
+                    types.addAll(findAllParameterizedTypes(implementedType));
+                }
+            }
+        }
+        return types;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,84 @@
+/*
+ * 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 com.ibm.ws.jaxrs.provider;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.activation.DataSource;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.helpers.IOUtils;
+
+/**
+ * This EntityProvider will handle the serializing/deserializing of input/output
+ * types that implement the javax.activation.DataSource interface.
+ *
+ */
+@Provider
+public class DataSourceProvider implements MessageBodyReader<DataSource>, MessageBodyWriter<DataSource> {
+
+    public long getSize(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        long size = -1;
+
+        // get the size based on the number of bytes in the InputStream
+        try {
+            InputStream is = dataSource.getInputStream();
+            if (is != null) {
+                int count = 0;
+                while (is.read() != -1) {
+                    count++;
+                }
+                size = count;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return size;
+    }
+
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return DataSource.class.isAssignableFrom(type);
+    }
+
+    public void writeTo(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream os)
+            throws IOException, WebApplicationException {
+        IOUtils.copy(dataSource.getInputStream(), os);
+    }
+
+    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return DataSource.class.equals(type);
+    }
+
+    public DataSource readFrom(Class<DataSource> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream)
+            throws IOException, WebApplicationException {
+        byte[] inputBytes = IOUtils.readBytesFromStream(inputStream);
+        return new RESTDataSource(inputBytes, null, mediaType.toString());
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,207 @@
+/*
+ * 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 com.ibm.ws.jaxrs.provider;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+
+import com.ibm.ws.jaxrs.context.ContextConstants;
+import com.ibm.ws.jaxrs.context.RESTContext;
+import com.ibm.ws.jaxrs.integration.OptionsResponseProvider;
+import com.ibm.ws.jaxrs.metadata.RESTMetaData;
+import com.ibm.wsspi.jaxrs.options.Consumes;
+import com.ibm.wsspi.jaxrs.options.Produces;
+import com.ibm.wsspi.jaxrs.options.Representation;
+import com.ibm.wsspi.jaxrs.options.Resource;
+import com.ibm.wsspi.jaxrs.options.ResourceLocator;
+import com.ibm.wsspi.jaxrs.options.ResourceMethod;
+import com.ibm.wsspi.jaxrs.options.Resources;
+import com.ibm.wsspi.jaxrs.options.SubResource;
+
+public class JAXBOptionsResponseProvider implements OptionsResponseProvider {
+
+    private static final Log log = LogFactory
+            .getLog(JAXBOptionsResponseProvider.class);
+
+    private static final JAXBOptionsResponseProvider singleton = new JAXBOptionsResponseProvider();
+
+    public static JAXBOptionsResponseProvider getInstance() {
+        return singleton;
+    }
+
+    /*
+     * Returns true if the type is compatible with 'application/xml' or 'text/xml'
+     */
+    public boolean isWriteable(MediaType acceptType) {
+        MediaType appXml = MediaType.APPLICATION_XML_TYPE;
+        MediaType textXml = MediaType.TEXT_XML_TYPE;
+        return (appXml.isCompatible(acceptType) || textXml
+                .isCompatible(acceptType));
+    }
+
+    public Response createOptionsResponse(RESTContext context) {
+
+        // let's get a list of all the HTTP methods allowed by this resource
+        // we'll set the information in the 'Public' header of the response
+        ClassResourceInfo info = (ClassResourceInfo) context
+                .getProperty(ContextConstants.SUB_RESOURCE_INFO);
+        if (info == null) {
+            info = (ClassResourceInfo) context
+                    .getProperty(ContextConstants.ROOT_RESOURCE);
+        }
+        List<ClassResourceInfo> infos = null;
+
+        // this could be the case where nothing is specifically targetted, but
+        // an options request is being sent to the context root, in that case,
+        // we will return information about each resource in the web app
+        if (info == null) {
+            RESTMetaData rmd = (RESTMetaData) context
+                    .getProperty(ContextConstants.REST_METADATA);
+            if (rmd != null && rmd.getClassInfoList() != null) {
+                infos = new ArrayList<ClassResourceInfo>();
+                infos.addAll(rmd.getClassInfoList());
+            }
+        } else {
+            infos = new ArrayList<ClassResourceInfo>();
+            infos.add(info);
+        }
+
+        Resources resources = new Resources();
+        List<Resource> resourceList = new ArrayList<Resource>();
+        List<SubResource> subResourceList = new ArrayList<SubResource>();
+        resources.setResources(resourceList);
+        resources.setSubResources(subResourceList);
+        Set<String> httpMethods = new HashSet<String>();
+        Set<String> allowTypes = new HashSet<String>();
+        if (infos != null) {
+
+            // let's process each of the infos we have identified as either a
+            // root resource or subresource, this may only be a single info,
+            // or in the case of an OPTIONS request to the context root, it
+            // may be multiple
+            for (ClassResourceInfo classInfo : infos) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Adding resource metadata for "
+                            + classInfo.getResourceClass().getName()
+                            + " to OPTIONS response");
+                }
+                Resource resource = classInfo.isRoot() ? new Resource()
+                        : new SubResource();
+                resource.setPath(classInfo.getPath());
+                List<ResourceMethod> resourceMethods = new ArrayList<ResourceMethod>();
+                List<ResourceLocator> resourceLocators = new ArrayList<ResourceLocator>();
+                resource.setResourceMethods(resourceMethods);
+                resource.setResourceLocators(resourceLocators);
+                Iterator<OperationResourceInfo> opIter = classInfo
+                        .getMethodDispatcher().getOperationResourceInfos()
+                        .iterator();
+
+                while (opIter.hasNext()) {
+                    OperationResourceInfo opInfo = opIter.next();
+                    if (opInfo.getHttpMethod() != null) {
+                        httpMethods.add(opInfo.getHttpMethod());
+                    }
+                    List<MediaType> mediaTypes = opInfo.getConsumes();
+                    for (MediaType mediaType : mediaTypes) {
+                        allowTypes.add(mediaType.toString());
+                    }
+                    augmentBodyContent(opInfo, resourceMethods,
+                            resourceLocators);
+                }
+
+                // add it to the appropriate list
+                if (classInfo.isRoot()) {
+                    resourceList.add(resource);
+                } else {
+                    subResourceList.add((SubResource) resource);
+                }
+            }
+        }
+
+        Response resp = Response.ok(resources).build();
+
+        // add the OPTIONS and HEAD methods as they can always be fulfilled
+        httpMethods.add("OPTIONS");
+        httpMethods.add("HEAD");
+        resp.getMetadata().put("Allow", new ArrayList<Object>(httpMethods));
+        resp.getMetadata().put(HttpHeaders.ACCEPT, new ArrayList<Object>(allowTypes));
+        return resp;
+    }
+
+    /*
+     * For the given OperationResourceInfo, this will add either a ResourceMethod
+     * or ResourceLocator instance to the supplied lists. The added object will
+     * be initialized with all appropriate data.
+     */
+    void augmentBodyContent(OperationResourceInfo opInfo, List<ResourceMethod> resourceMethods, List<ResourceLocator> resourceLocators) {
+
+        if (opInfo.isSubResourceLocator()) {
+            ResourceLocator locator = new ResourceLocator();
+            locator.setPath(opInfo.getPath());
+            resourceLocators.add(locator);
+        }
+
+        // otherwise this is a resource or subresource method
+        else {
+            ResourceMethod method = new ResourceMethod();
+
+            List<Representation> cRepList = new ArrayList<Representation>();
+            List<Representation> pRepList = new ArrayList<Representation>();
+            List<MediaType> producesMT = opInfo.getProduces();
+
+            // resource representation info
+            for (MediaType produce : producesMT) {
+                Representation rep = new Representation();
+                rep.setMediaType(produce.toString());
+                pRepList.add(rep);
+            }
+            List<MediaType> consumesMT = opInfo.getConsumes();
+            for (MediaType consume : consumesMT) {
+                Representation rep = new Representation();
+                rep.setMediaType(consume.toString());
+                cRepList.add(rep);
+            }
+
+            // set all method data and add to list
+            method.setPath(opInfo.getPath());
+            method.setHttpMethod(opInfo.getHttpMethod());
+            Consumes consumes = new Consumes();
+            consumes.setRepresentations(cRepList);
+            Produces produces = new Produces();
+            produces.setRepresentations(pRepList);
+            method.setConsumes(consumes);
+            method.setProduces(produces);
+            resourceMethods.add(method);
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/RESTDataSource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/RESTDataSource.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/RESTDataSource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/RESTDataSource.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,66 @@
+/*
+ * 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 com.ibm.ws.jaxrs.provider;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+/**
+ * This class will be the implementation of the DataSource interface that is
+ * used to serialize an incoming REST request that maps to a DataSource.
+ *
+ */
+public class RESTDataSource implements DataSource {
+
+    private byte[] inputBytes = null;
+
+    private OutputStream os = null;
+
+    private String contentType = null;
+
+    public static String REST_DATA_SOURCE_NAME = "IBM_REST_DATA";
+
+    public RESTDataSource(byte[] inputBytes, OutputStream os, String contentType) {
+        this.inputBytes = inputBytes;
+        this.os = os;
+        this.contentType = contentType;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public InputStream getInputStream() throws IOException {
+        return new ByteArrayInputStream(inputBytes);
+    }
+
+    public String getName() {
+        return REST_DATA_SOURCE_NAME;
+    }
+
+    public OutputStream getOutputStream() throws IOException {
+        return os;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,63 @@
+/*
+ * 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 com.ibm.ws.jaxrs.resolver;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+/**
+ * This is a simple JAXB ContextResolver that will create a JAXBContext
+ * using the supplied Class argument. Each created JAXBContext will be
+ * kept in a static cache for more peformant use.
+ *
+ */
+@Provider
+public class JAXBContextResolver implements ContextResolver<JAXBContext> {
+
+    private static final Log log = LogFactory.getLog(JAXBContextResolver.class);
+
+    private Map<String, JAXBContext> contextMap = new ConcurrentHashMap<String, JAXBContext>();
+
+    public JAXBContext getContext(Class<?> clazz) {
+        JAXBContext context = null;
+        try {
+            String packageName = clazz.getPackage().getName();
+            context = contextMap.get(packageName);
+            if (context == null) {
+                context = JAXBContext.newInstance(packageName);
+                contextMap.put(packageName, context);
+            }
+        } catch (JAXBException e) {
+            log.error(Messages.getMessage("jaxbContextFail"), e);
+        }
+        return context;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/tools/WebBuilder.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/tools/WebBuilder.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/tools/WebBuilder.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/tools/WebBuilder.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,120 @@
+/*
+ * 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 com.ibm.ws.jaxrs.tools;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
+
+/**
+ * This class will produce a web.xml to be packaged with an application that
+ * contains the IBM JAX-RS runtime. This class will be called when a user runs
+ * the 'build.xml' script to package their classes into a deployable WAR.
+ *
+ */
+public class WebBuilder {
+
+    public static void main(String[] args) {
+        if (args == null || args.length < 3) {
+            return;
+        }
+        try {
+            String appClassName = args[0];
+            String outputDirPath = args[1] + java.io.File.separator
+                    + "ibmjaxrs_tmp_dd_output";
+            String jaxrsHome = args[2];
+            String webxmlTemplate = jaxrsHome + java.io.File.separator
+                    + "resources" + java.io.File.separator + "template_web.xml";
+            String outputFilePath = outputDirPath + java.io.File.separator
+                    + "web.xml";
+
+            // create the temporary output directory
+            File outputDir = new File(outputDirPath);
+            outputDir.mkdirs();
+
+            // create the web.xml from template
+            File source = new File(webxmlTemplate);
+            File file = new File(outputFilePath);
+            file.createNewFile();
+
+            DocumentBuilder builder = DocumentBuilderFactory.newInstance()
+                    .newDocumentBuilder();
+
+            Document document = builder.parse(source);
+            Element rootElement = document.getDocumentElement();
+
+            // should be the web-app element, let's add the servlet
+            Element servletElement = document.createElement("servlet");
+            rootElement.appendChild(servletElement);
+
+            Element servletName = document.createElement("servlet-name");
+            servletName.setTextContent("IBM JAX-RS Servlet");
+            Element servletClass = document.createElement("servlet-class");
+            servletClass.setTextContent("com.ibm.ws.jaxrs.web.RESTServlet");
+            Element initParam = document.createElement("init-param");
+            Element paramName = document.createElement("param-name");
+            paramName.setTextContent("javax.ws.rs.Application");
+            Element paramValue = document.createElement("param-value");
+            paramValue.setTextContent(appClassName);
+            initParam.appendChild(paramName);
+            initParam.appendChild(paramValue);
+
+            servletElement.appendChild(initParam);
+            servletElement.appendChild(servletName);
+            servletElement.appendChild(servletClass);
+
+            // now we'll add the servlet-mapping
+            Element servletMapping = document.createElement("servlet-mapping");
+            rootElement.appendChild(servletMapping);
+
+            Element servletName2 = document.createElement("servlet-name");
+            servletName2.setTextContent("IBM JAX-RS Servlet");
+            Element urlPattern = document.createElement("url-pattern");
+            urlPattern.setTextContent("/*");
+            servletMapping.appendChild(servletName2);
+            servletMapping.appendChild(urlPattern);
+
+            // now write the document
+            DOMImplementationLS domLS = (DOMImplementationLS) builder
+                    .getDOMImplementation().getFeature("LS", "3.0");
+            LSSerializer serializer = domLS.createLSSerializer();
+            LSOutput output = domLS.createLSOutput();
+            output.setByteStream(new FileOutputStream(file));
+            serializer.write(rootElement, output);
+
+        } catch (Exception e) {
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+            e.printStackTrace(pw);
+            System.out.println("Error in WebBuilder: " + sw.toString());
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/utils/ClassUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/utils/ClassUtils.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/utils/ClassUtils.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/utils/ClassUtils.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,66 @@
+/*
+ * 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 com.ibm.ws.jaxrs.utils;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * A collection of utilities for dealing with classes and reflection.
+ *
+ */
+public class ClassUtils {
+
+    /**
+     * Loads the class with the specified name using the specified loader.
+     */
+    public static Class<?> loadClass(final String className, final ClassLoader classLoader)
+            throws Exception {
+        try {
+            return AccessController
+                    .doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
+                        public Class<?> run() throws ClassNotFoundException {
+                            return classLoader.loadClass(className);
+                        }
+                    });
+        } catch (PrivilegedActionException e) {
+            throw (e.getException() != null ? e.getException() : e);
+        }
+    }
+
+    /**
+     * Creates an instance of the specified class using the 'newInstance' method.
+     */
+    public static Object newInstance(final Class<?> clazz) throws Exception {
+        try {
+            return AccessController
+                    .doPrivileged(new PrivilegedExceptionAction<Object>() {
+                        public Object run() throws InstantiationException,
+                                IllegalAccessException {
+                            return clazz.newInstance();
+                        }
+                    });
+        } catch (PrivilegedActionException e) {
+            throw (e.getException() != null ? e.getException() : e);
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/ClassResourceValidator.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/ClassResourceValidator.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/ClassResourceValidator.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/ClassResourceValidator.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 com.ibm.ws.jaxrs.validation;
+
+import java.util.List;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+
+/**
+ * This interface will be implemented by classes that provide validation
+ * function on a set of ClassResourceInfo objects.
+ *
+ */
+public interface ClassResourceValidator {
+
+    /**
+     * This method will validate the set of ClassResourceInfo objects that
+     * are provided. It will return a list of ValidationMessage objects that
+     * represent any validation error, warning, or debug messages.
+     *
+     */
+    public List<ValidationMessage> validate(List<ClassResourceInfo> infos);
+
+}
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/JAXRSClassResourceValidator.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/JAXRSClassResourceValidator.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/JAXRSClassResourceValidator.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/JAXRSClassResourceValidator.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,224 @@
+/*
+ * 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 com.ibm.ws.jaxrs.validation;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+/**
+ * This class will perform validation on ClassResourceInfo objects based
+ * on requirements in the JSR-311 specification. The validations done by
+ * this class are those listed in the JAX-RS specification.
+ *
+ */
+public class JAXRSClassResourceValidator implements ClassResourceValidator {
+
+    public JAXRSClassResourceValidator() {
+    }
+
+    /**
+     * This method will validate the list of ClassResourceInfo objects that
+     * the validator was supplied. A list of ValidationMessage objects will
+     * be returned containing any necessary messages.
+     *
+     */
+    public List<ValidationMessage> validate(List<ClassResourceInfo> infos) {
+        List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
+
+        checkForDuplicatePaths(infos, messages);
+        for (ClassResourceInfo info : infos) {
+            checkForValidConstructor(info, messages);
+            validateFields(info, messages);
+        }
+
+        return messages;
+    }
+
+    /**
+     * This method will check to ensure that among a collection of ClassResourceInfo
+     * objects for a given application, that the @Path.value is unique among the collection.
+     *
+     */
+    void checkForDuplicatePaths(List<ClassResourceInfo> infos, List<ValidationMessage> messages) {
+        Map<String, List<String>> paths = new HashMap<String, List<String>>();
+        for (ClassResourceInfo info : infos) {
+
+            // let's keep track of all the @Path.value attributes, if we find
+            // a duplicate we'll report it as an error later
+            List<String> classNames = paths.get(info.getPath());
+            if (classNames == null) {
+                classNames = new ArrayList<String>();
+                paths.put(info.getPath(), classNames);
+            }
+            classNames.add(info.getServiceClass().getName());
+        }
+
+        // check for duplicates and construct the appropriate ValidationMessage
+        if (!paths.isEmpty()) {
+            Iterator<Entry<String, List<String>>> entries = paths.entrySet()
+                    .iterator();
+            while (entries.hasNext()) {
+                Entry<String, List<String>> entry = entries.next();
+                List<String> values = entry.getValue();
+                if (values != null && values.size() > 1) {
+                    ValidationMessage message = new ValidationMessage(
+                            ValidationMessage.Type.ERROR);
+                    StringBuffer sb = new StringBuffer();
+                    for (String value : values) {
+                        sb.append(" ").append(value);
+                    }
+                    String msg = Messages.getMessage("pathAnnotFail00", entry
+                            .getKey(), sb.toString().trim());
+                    message.setMessage(msg);
+                    messages.add(message);
+                }
+            }
+        }
+    }
+
+    /**
+     * This method will ensure that a valid constructor can be found according to
+     * JSR-311. If one cannot be found, or there is ambiguity as to the appropriate
+     * constructor, an appropriate ValidationMessage will be added to the supplied list.
+     *
+     */
+    void checkForValidConstructor(ClassResourceInfo info, List<ValidationMessage> messages) {
+        if(info.isSingleton()) {
+            return;
+        }
+        Class<?> svcClass = info.getServiceClass();
+        Constructor<?>[] cstrs = svcClass.getDeclaredConstructors();
+        List<Constructor<?>> goodCstrs = new ArrayList<Constructor<?>>();
+        for (Constructor<?> cstr : cstrs) {
+            Annotation[][] allParamAnnotations = cstr.getParameterAnnotations();
+            Class<?>[] params = cstr.getParameterTypes();
+
+            // if it is the public, zero-arg constructor let's add it
+            if (params.length == 0 && Modifier.isPublic(cstr.getModifiers())) {
+                goodCstrs.add(cstr);
+                continue;
+            }
+
+            // if not all of the parameters are annotated there is no need to
+            // continue processing this constructor
+            if (params.length != allParamAnnotations.length) {
+                continue;
+            }
+
+            // now make sure that each parameter of the constructor has an annotation
+            // that tells us what its value should be
+            boolean conformingAnnotFound = false;
+            for (int i = 0; i < params.length; ++i) {
+                Annotation[] annotations = allParamAnnotations[i];
+                for (Annotation annotation : annotations) {
+                    if (AnnotationUtils.isParamAnnotationClass(annotation
+                            .annotationType())) {
+                        conformingAnnotFound = true;
+                        break;
+                    }
+                }
+                if (!conformingAnnotFound) {
+                    break;
+                }
+            }
+            if (!conformingAnnotFound) {
+                continue;
+            }
+            goodCstrs.add(cstr);
+        }
+
+        // if no good constructors are found create the error message
+        if (goodCstrs.isEmpty()) {
+            ValidationMessage message = new ValidationMessage(
+                    ValidationMessage.Type.WARNING);
+            message.setMessage(Messages.getMessage("invalidCstr", svcClass
+                    .getName()));
+            messages.add(message);
+        }
+
+        // otherwise, let's warn if there are multiple viable constructors with the same
+        // number of parameters
+        else {
+            int maxParams = 0;
+            int cstrsWithMaxParams = 0;
+            for (Constructor<?> goodCstr : goodCstrs) {
+                if (goodCstr.getParameterTypes().length == maxParams) {
+                    cstrsWithMaxParams++;
+                } else if (goodCstr.getParameterTypes().length > maxParams) {
+                    maxParams = goodCstr.getParameterTypes().length;
+                    cstrsWithMaxParams = 1;
+                }
+            }
+
+            // record the warning if there is ambiguity
+            if (cstrsWithMaxParams > 1) {
+                ValidationMessage message = new ValidationMessage(
+                        ValidationMessage.Type.WARNING);
+                message.setMessage(Messages.getMessage("multipleCstrs",
+                        svcClass.getName()));
+                messages.add(message);
+            }
+        }
+    }
+
+    /**
+     * This will check fields of a resource class which is a singleton. Certain
+     * annotations should not be present, and if they are, we will log a warning.
+     *
+     */
+    void validateFields(ClassResourceInfo info, List<ValidationMessage> messages) {
+        if (info.isSingleton()) {
+            String className = info.getServiceClass().getName();
+            Field[] fields = info.getServiceClass().getDeclaredFields();
+            for (Field field : fields) {
+                Annotation[] annotations = field.getAnnotations();
+                for (Annotation annotation : annotations) {
+
+                    // if the annotation indicates injection, let's log a warning
+                    if (AnnotationUtils.isParamAnnotationClass(annotation
+                            .annotationType())) {
+                        ValidationMessage message = new ValidationMessage(
+                                ValidationMessage.Type.WARNING);
+                        String msg = Messages.getMessage(
+                                "invalidSingletonAnnot", field.getName(),
+                                className, annotation.annotationType()
+                                        .getName());
+                        message.setMessage(msg);
+                        messages.add(message);
+                    }
+                }
+            }
+        }
+    }
+
+}



Mime
View raw message