wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r939752 [1/2] - in /incubator/wink/trunk: wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/ wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/ wink-providers/wink-jackson-provider/...
Date Fri, 30 Apr 2010 17:37:29 GMT
Author: bluk
Date: Fri Apr 30 17:37:29 2010
New Revision: 939752

URL: http://svn.apache.org/viewvc?rev=939752&view=rev
Log:
Fix some line ending corrections

Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/UriBuilderTest.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java?rev=939752&r1=939751&r2=939752&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java Fri Apr 30 17:37:29 2010
@@ -1,199 +1,199 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *  
- *   http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *  
- *******************************************************************************/
-
-package org.apache.wink.common.internal.providers.entity.json;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-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 javax.ws.rs.ext.Providers;
-
-import org.apache.wink.common.internal.providers.entity.xml.AbstractJAXBCollectionProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Provider
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class JAXBArrayJSONProvider extends AbstractJAXBCollectionProvider implements
-    MessageBodyReader<Object[]>, MessageBodyWriter<Object[]> {
-
-    protected volatile MessageBodyReader<Object> readerProvider = null;
-    protected volatile MessageBodyWriter<Object> writerProvider = null;
-    
-    private static final Logger logger = LoggerFactory.getLogger(JAXBArrayJSONProvider.class);
-
-    @Context
-    Providers                           injectedProviders;
-
-    public boolean isReadable(Class<?> type,
-                              Type genericType,
-                              Annotation[] annotations,
-                              MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
-        if (theType != null)
-            return (type.isArray() && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
-                                                                                           genericType));
-        return false;
-    }
-
-    public long getSize(Object[] t,
-                        Class<?> type,
-                        Type genericType,
-                        Annotation[] annotations,
-                        MediaType mediaType) {
-        return -1;
-    }
-
-    @SuppressWarnings("unchecked")
-    public Object[] readFrom(Class<Object[]> type,
-                             Type genericType,
-                             Annotation[] annotations,
-                             MediaType mediaType,
-                             MultivaluedMap<String, String> httpHeaders,
-                             InputStream entityStream) throws IOException, WebApplicationException {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
-        if (this.readerProvider == null) {
-            this.readerProvider =
-                injectedProviders.getMessageBodyReader((Class<Object>)theType,
-                                                       theType,
-                                                       annotations,
-                                                       mediaType);
-            logger.debug("readerProvider was {} of type {}", System.identityHashCode(readerProvider), readerProvider.getClass().getName()); //$NON-NLS-1$
-        }
-        Queue<String> queue = new LinkedList<String>();
-        List<Object> collection = new ArrayList<Object>();
-        Pattern p = Pattern.compile("\\S"); //$NON-NLS-1$
-        Matcher m = null;
-        int next = entityStream.read();
-        while (next != -1) {
-            m = p.matcher("" + (char)next); //$NON-NLS-1$
-            if (m.matches() && (char)next != '[')
-                throw new WebApplicationException(500);
-            else if (!m.matches())
-                next = (char)entityStream.read();
-            else {
-                // we found the first non-whitespace character is '['. Read the
-                // next character and begin parsing
-                next = entityStream.read();
-                break;
-            }
-        }
-
-        // parse the content and deserialize the JSON Object one by one
-        String objectString = ""; //$NON-NLS-1$
-        while (next != -1) {
-            if (((char)next != ',') || ((char)next == ',' && !queue.isEmpty()))
-                objectString += (char)next;
-            if ((char)next == '{')
-                queue.offer("" + (char)next); //$NON-NLS-1$
-            else if ((char)next == '}') {
-                queue.poll();
-                if (queue.isEmpty()) {
-                    collection.add(this.readerProvider
-                        .readFrom((Class<Object>)theType,
-                                  theType,
-                                  annotations,
-                                  mediaType,
-                                  httpHeaders,
-                                  new ByteArrayInputStream(objectString.getBytes())));
-                    objectString = ""; //$NON-NLS-1$
-                }
-            }
-            next = entityStream.read();
-        }
-        return (Object[])getArray(theType, collection);
-    }
-
-    @SuppressWarnings("unchecked")
-    protected static <T> Object getArray(Class<T> type, List<?> collection) {
-        T[] ret = (T[])Array.newInstance(type, collection.size());
-        int i = 0;
-        for (Object o : collection) {
-            ret[i++] = (T)o;
-        }
-        return ret;
-    }
-
-    @SuppressWarnings("unchecked")
-    public void writeTo(Object[] t,
-                        Class<?> type,
-                        Type genericType,
-                        Annotation[] annotations,
-                        MediaType mediaType,
-                        MultivaluedMap<String, Object> httpHeaders,
-                        OutputStream entityStream) throws IOException, WebApplicationException {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
-        if (this.writerProvider == null) {
-            this.writerProvider =
-                injectedProviders.getMessageBodyWriter((Class<Object>)theType,
-                                                       theType,
-                                                       annotations,
-                                                       mediaType);
-            logger.debug("writerProvider was {} of type {}", System.identityHashCode(writerProvider), writerProvider.getClass().getName()); //$NON-NLS-1$
-        }
-        entityStream.write("[".getBytes()); //$NON-NLS-1$
-        int i = 0;
-        for (Object o : t) {
-            this.writerProvider.writeTo(o,
-                                        theType,
-                                        theType,
-                                        annotations,
-                                        mediaType,
-                                        httpHeaders,
-                                        entityStream);
-            if ((++i) != t.length)
-                entityStream.write(",".getBytes()); //$NON-NLS-1$
-        }
-        entityStream.write("]".getBytes()); //$NON-NLS-1$
-    }
-
-    public boolean isWriteable(Class<?> type,
-                               Type genericType,
-                               Annotation[] annotations,
-                               MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
-
-        if (theType != null)
-            return (isJAXBObject(theType, genericType) && !isJAXBElement(theType, genericType));
-        return false;
-    }
-
-}
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *  
+ *******************************************************************************/
+
+package org.apache.wink.common.internal.providers.entity.json;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+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 javax.ws.rs.ext.Providers;
+
+import org.apache.wink.common.internal.providers.entity.xml.AbstractJAXBCollectionProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Provider
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class JAXBArrayJSONProvider extends AbstractJAXBCollectionProvider implements
+    MessageBodyReader<Object[]>, MessageBodyWriter<Object[]> {
+
+    protected volatile MessageBodyReader<Object> readerProvider = null;
+    protected volatile MessageBodyWriter<Object> writerProvider = null;
+    
+    private static final Logger logger = LoggerFactory.getLogger(JAXBArrayJSONProvider.class);
+
+    @Context
+    Providers                           injectedProviders;
+
+    public boolean isReadable(Class<?> type,
+                              Type genericType,
+                              Annotation[] annotations,
+                              MediaType mediaType) {
+        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        if (theType != null)
+            return (type.isArray() && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
+                                                                                           genericType));
+        return false;
+    }
+
+    public long getSize(Object[] t,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType) {
+        return -1;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Object[] readFrom(Class<Object[]> type,
+                             Type genericType,
+                             Annotation[] annotations,
+                             MediaType mediaType,
+                             MultivaluedMap<String, String> httpHeaders,
+                             InputStream entityStream) throws IOException, WebApplicationException {
+        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        if (this.readerProvider == null) {
+            this.readerProvider =
+                injectedProviders.getMessageBodyReader((Class<Object>)theType,
+                                                       theType,
+                                                       annotations,
+                                                       mediaType);
+            logger.debug("readerProvider was {} of type {}", System.identityHashCode(readerProvider), readerProvider.getClass().getName()); //$NON-NLS-1$
+        }
+        Queue<String> queue = new LinkedList<String>();
+        List<Object> collection = new ArrayList<Object>();
+        Pattern p = Pattern.compile("\\S"); //$NON-NLS-1$
+        Matcher m = null;
+        int next = entityStream.read();
+        while (next != -1) {
+            m = p.matcher("" + (char)next); //$NON-NLS-1$
+            if (m.matches() && (char)next != '[')
+                throw new WebApplicationException(500);
+            else if (!m.matches())
+                next = (char)entityStream.read();
+            else {
+                // we found the first non-whitespace character is '['. Read the
+                // next character and begin parsing
+                next = entityStream.read();
+                break;
+            }
+        }
+
+        // parse the content and deserialize the JSON Object one by one
+        String objectString = ""; //$NON-NLS-1$
+        while (next != -1) {
+            if (((char)next != ',') || ((char)next == ',' && !queue.isEmpty()))
+                objectString += (char)next;
+            if ((char)next == '{')
+                queue.offer("" + (char)next); //$NON-NLS-1$
+            else if ((char)next == '}') {
+                queue.poll();
+                if (queue.isEmpty()) {
+                    collection.add(this.readerProvider
+                        .readFrom((Class<Object>)theType,
+                                  theType,
+                                  annotations,
+                                  mediaType,
+                                  httpHeaders,
+                                  new ByteArrayInputStream(objectString.getBytes())));
+                    objectString = ""; //$NON-NLS-1$
+                }
+            }
+            next = entityStream.read();
+        }
+        return (Object[])getArray(theType, collection);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected static <T> Object getArray(Class<T> type, List<?> collection) {
+        T[] ret = (T[])Array.newInstance(type, collection.size());
+        int i = 0;
+        for (Object o : collection) {
+            ret[i++] = (T)o;
+        }
+        return ret;
+    }
+
+    @SuppressWarnings("unchecked")
+    public void writeTo(Object[] t,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType,
+                        MultivaluedMap<String, Object> httpHeaders,
+                        OutputStream entityStream) throws IOException, WebApplicationException {
+        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        if (this.writerProvider == null) {
+            this.writerProvider =
+                injectedProviders.getMessageBodyWriter((Class<Object>)theType,
+                                                       theType,
+                                                       annotations,
+                                                       mediaType);
+            logger.debug("writerProvider was {} of type {}", System.identityHashCode(writerProvider), writerProvider.getClass().getName()); //$NON-NLS-1$
+        }
+        entityStream.write("[".getBytes()); //$NON-NLS-1$
+        int i = 0;
+        for (Object o : t) {
+            this.writerProvider.writeTo(o,
+                                        theType,
+                                        theType,
+                                        annotations,
+                                        mediaType,
+                                        httpHeaders,
+                                        entityStream);
+            if ((++i) != t.length)
+                entityStream.write(",".getBytes()); //$NON-NLS-1$
+        }
+        entityStream.write("]".getBytes()); //$NON-NLS-1$
+    }
+
+    public boolean isWriteable(Class<?> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType) {
+        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+
+        if (theType != null)
+            return (isJAXBObject(theType, genericType) && !isJAXBElement(theType, genericType));
+        return false;
+    }
+
+}

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java?rev=939752&r1=939751&r2=939752&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java Fri Apr 30 17:37:29 2010
@@ -1,98 +1,98 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *  
- *   http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *  
- *******************************************************************************/
-
-package org.apache.wink.common.internal.providers.entity.xml;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-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;
-
-@Provider
-@Consumes( {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
-@Produces( {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
-public class JAXBArrayXmlProvider extends AbstractJAXBCollectionProvider implements
-    MessageBodyReader<Object[]>, MessageBodyWriter<Object[]> {
-
-    public boolean isReadable(Class<?> type,
-                              Type genericType,
-                              Annotation[] annotations,
-                              MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
-        if (theType != null)
-            return (isSupportedMediaType(mediaType) && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
-                                                                                                            genericType));
-        return false;
-    }
-
-    public Object[] readFrom(Class<Object[]> type,
-                             Type genericType,
-                             Annotation[] annotations,
-                             MediaType mediaType,
-                             MultivaluedMap<String, String> httpHeaders,
-                             InputStream entityStream) throws IOException, WebApplicationException {
-        return (Object[])super.read(type,
-                                    genericType,
-                                    annotations,
-                                    mediaType,
-                                    httpHeaders,
-                                    entityStream);
-    }
-
-    public long getSize(Object[] t,
-                        Class<?> type,
-                        Type genericType,
-                        Annotation[] annotations,
-                        MediaType mediaType) {
-        return -1;
-    }
-
-    public boolean isWriteable(Class<?> type,
-                               Type genericType,
-                               Annotation[] annotations,
-                               MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
-        if (theType != null)
-            return (isSupportedMediaType(mediaType) && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
-                                                                                                            genericType));
-        return false;
-    }
-
-    public void writeTo(Object[] t,
-                        Class<?> type,
-                        Type genericType,
-                        Annotation[] annotations,
-                        MediaType mediaType,
-                        MultivaluedMap<String, Object> httpHeaders,
-                        OutputStream entityStream) throws IOException, WebApplicationException {
-        super.write(t, type, genericType, annotations, mediaType, httpHeaders, entityStream);
-    }
-
-}
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *  
+ *******************************************************************************/
+
+package org.apache.wink.common.internal.providers.entity.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+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;
+
+@Provider
+@Consumes( {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
+@Produces( {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
+public class JAXBArrayXmlProvider extends AbstractJAXBCollectionProvider implements
+    MessageBodyReader<Object[]>, MessageBodyWriter<Object[]> {
+
+    public boolean isReadable(Class<?> type,
+                              Type genericType,
+                              Annotation[] annotations,
+                              MediaType mediaType) {
+        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        if (theType != null)
+            return (isSupportedMediaType(mediaType) && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
+                                                                                                            genericType));
+        return false;
+    }
+
+    public Object[] readFrom(Class<Object[]> type,
+                             Type genericType,
+                             Annotation[] annotations,
+                             MediaType mediaType,
+                             MultivaluedMap<String, String> httpHeaders,
+                             InputStream entityStream) throws IOException, WebApplicationException {
+        return (Object[])super.read(type,
+                                    genericType,
+                                    annotations,
+                                    mediaType,
+                                    httpHeaders,
+                                    entityStream);
+    }
+
+    public long getSize(Object[] t,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType) {
+        return -1;
+    }
+
+    public boolean isWriteable(Class<?> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType) {
+        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        if (theType != null)
+            return (isSupportedMediaType(mediaType) && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
+                                                                                                            genericType));
+        return false;
+    }
+
+    public void writeTo(Object[] t,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType,
+                        MultivaluedMap<String, Object> httpHeaders,
+                        OutputStream entityStream) throws IOException, WebApplicationException {
+        super.write(t, type, genericType, annotations, mediaType, httpHeaders, entityStream);
+    }
+
+}

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java?rev=939752&r1=939751&r2=939752&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java Fri Apr 30 17:37:29 2010
@@ -1,93 +1,93 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *  
- *   http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *  
- *******************************************************************************/
-
-package org.apache.wink.common.internal.providers.entity.xml;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-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;
-
-@Provider
-@Consumes( {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
-@Produces( {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
-public class JAXBCollectionXmlProvider extends AbstractJAXBCollectionProvider implements
-    MessageBodyReader<Object>, MessageBodyWriter<Object> {
-
-    public boolean isReadable(Class<?> type,
-                              Type genericType,
-                              Annotation[] annotations,
-                              MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
-        if (theType != null)
-            return (Collection.class.isAssignableFrom(type) && isSupportedMediaType(mediaType) && (isJAXBObject(theType, genericType) || (isJAXBElement(theType,
-                                                                                                             genericType))));
-        return false;
-    }
-
-    public Object readFrom(Class<Object> type,
-                           Type genericType,
-                           Annotation[] annotations,
-                           MediaType mediaType,
-                           MultivaluedMap<String, String> httpHeaders,
-                           InputStream entityStream) throws IOException, WebApplicationException {
-        return super.read(type, genericType, annotations, mediaType, httpHeaders, entityStream);
-    }
-
-    public long getSize(Object t,
-                        Class<?> type,
-                        Type genericType,
-                        Annotation[] annotations,
-                        MediaType mediaType) {
-        return -1;
-    }
-
-    public boolean isWriteable(Class<?> type,
-                               Type genericType,
-                               Annotation[] annotations,
-                               MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
-        if (theType != null)
-            return (Collection.class.isAssignableFrom(type) && isSupportedMediaType(mediaType) && (isJAXBObject(theType, genericType) || (isJAXBElement(theType,
-                                                                                                             genericType))));
-        return false;
-    }
-
-    public void writeTo(Object t,
-                        Class<?> type,
-                        Type genericType,
-                        Annotation[] annotations,
-                        MediaType mediaType,
-                        MultivaluedMap<String, Object> httpHeaders,
-                        OutputStream entityStream) throws IOException, WebApplicationException {
-        super.write(t, type, genericType, annotations, mediaType, httpHeaders, entityStream);
-    }
-}
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *  
+ *******************************************************************************/
+
+package org.apache.wink.common.internal.providers.entity.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collection;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+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;
+
+@Provider
+@Consumes( {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
+@Produces( {MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
+public class JAXBCollectionXmlProvider extends AbstractJAXBCollectionProvider implements
+    MessageBodyReader<Object>, MessageBodyWriter<Object> {
+
+    public boolean isReadable(Class<?> type,
+                              Type genericType,
+                              Annotation[] annotations,
+                              MediaType mediaType) {
+        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        if (theType != null)
+            return (Collection.class.isAssignableFrom(type) && isSupportedMediaType(mediaType) && (isJAXBObject(theType, genericType) || (isJAXBElement(theType,
+                                                                                                             genericType))));
+        return false;
+    }
+
+    public Object readFrom(Class<Object> type,
+                           Type genericType,
+                           Annotation[] annotations,
+                           MediaType mediaType,
+                           MultivaluedMap<String, String> httpHeaders,
+                           InputStream entityStream) throws IOException, WebApplicationException {
+        return super.read(type, genericType, annotations, mediaType, httpHeaders, entityStream);
+    }
+
+    public long getSize(Object t,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType) {
+        return -1;
+    }
+
+    public boolean isWriteable(Class<?> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType) {
+        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        if (theType != null)
+            return (Collection.class.isAssignableFrom(type) && isSupportedMediaType(mediaType) && (isJAXBObject(theType, genericType) || (isJAXBElement(theType,
+                                                                                                             genericType))));
+        return false;
+    }
+
+    public void writeTo(Object t,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType,
+                        MultivaluedMap<String, Object> httpHeaders,
+                        OutputStream entityStream) throws IOException, WebApplicationException {
+        super.write(t, type, genericType, annotations, mediaType, httpHeaders, entityStream);
+    }
+}

Modified: incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java?rev=939752&r1=939751&r2=939752&view=diff
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java (original)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java Fri Apr 30 17:37:29 2010
@@ -1,349 +1,349 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *  
- *   http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *  
- *******************************************************************************/
-
-package org.apache.wink.providers.jackson.internal;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.xml.bind.JAXBElement;
-import javax.xml.datatype.DatatypeConfigurationException;
-import javax.xml.datatype.DatatypeFactory;
-import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.namespace.QName;
-
-import org.apache.wink.common.model.atom.AtomEntry;
-import org.apache.wink.providers.jackson.internal.jaxb.Person;
-import org.apache.wink.providers.json.JSONUtils;
-import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
-import org.apache.wink.test.mock.MockRequestConstructor;
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-import org.json.JSONArray;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
-
-public class JAXBCollectionJSONTest extends MockServletInvocationTest {
-
-    private static final String ENTRY_STR_1         =
-                                                        "<entry xml:base=\"http://b216:8080/reporting/reports\" xmlns=\"http://www.w3.org/2005/Atom\">\n" + "    <id>toptenvalidators</id>\n"
-                                                            + "    <updated>2009-08-31T18:30:02Z</updated>\n"
-                                                            + "    <title type=\"text\" xml:lang=\"en\">top ten validators 1</title>\n"
-                                                            + "    <published>2009-08-31T18:30:02Z</published>\n"
-                                                            + "    <link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\" type=\"application/json\" rel=\"alternate\"/>\n"
-                                                            + "    <author>\n"
-                                                            + "        <name>admin 1</name>\n"
-                                                            + "    </author>\n"
-                                                            + "    <category label=\"report definition\" scheme=\"urn:com:systinet:reporting:kind\" term=\"urn:com:systinet:reporting:kind:definition\"/>\n"
-                                                            + "</entry>";
-    private static final String ENTRY_STR_2         =
-                                                        "<entry xml:base=\"http://b216:8080/reporting/reports\" xmlns=\"http://www.w3.org/2005/Atom\">\n" + "    <id>toptenvalidators</id>\n"
-                                                            + "    <updated>2009-08-31T18:30:02Z</updated>\n"
-                                                            + "    <title type=\"text\" xml:lang=\"en\">top ten validators 2</title>\n"
-                                                            + "    <published>2009-08-31T18:30:02Z</published>\n"
-                                                            + "    <link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\" type=\"application/json\" rel=\"alternate\"/>\n"
-                                                            + "    <author>\n"
-                                                            + "        <name>admin 2</name>\n"
-                                                            + "    </author>\n"
-                                                            + "    <category label=\"report definition\" scheme=\"urn:com:systinet:reporting:kind\" term=\"urn:com:systinet:reporting:kind:definition\"/>\n"
-                                                            + "</entry>";
-
-    private static final String ENTRY_STR_JSON_1    =
-                                                        "{\"base\":\"http://b216:8080/reporting/reports\"," + "\"otherAttributes\":{},"
-                                                            + "\"id\":\"toptenvalidators\","
-                                                            + "\"updated\":\"2009-08-31T18:30:02Z\","
-                                                            + "\"title\":{\"lang\":\"en\",\"otherAttributes\":{},\"type\":\"text\"},"
-                                                            + "\"published\":\"2009-08-31T18:30:02Z\","
-                                                            + "\"link\":[{\"otherAttributes\":{},\"rel\":\"alternate\",\"type\":\"application/json\",\"href\":\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\"}],"
-                                                            + "\"author\":[{\"name\":\"admin 1\"}],"
-                                                            + "\"category\":[{\"otherAttributes\":{},\"term\":\"urn:com:systinet:reporting:kind:definition\",\"scheme\":\"urn:com:systinet:reporting:kind\",\"label\":\"report definition\"}]"
-                                                            + "}";
-    private static final String ENTRY_STR_JSON_2    =
-                                                        "{\"base\":\"http://b216:8080/reporting/reports\"," + "\"otherAttributes\":{},"
-                                                            + "\"id\":\"toptenvalidators\","
-                                                            + "\"updated\":\"2009-08-31T18:30:02Z\","
-                                                            + "\"title\":{\"lang\":\"en\",\"otherAttributes\":{},\"type\":\"text\"},"
-                                                            + "\"published\":\"2009-08-31T18:30:02Z\","
-                                                            + "\"link\":[{\"otherAttributes\":{},\"rel\":\"alternate\",\"type\":\"application/json\",\"href\":\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\"}],"
-                                                            + "\"author\":[{\"name\":\"admin 2\"}],"
-                                                            + "\"category\":[{\"otherAttributes\":{},\"term\":\"urn:com:systinet:reporting:kind:definition\",\"scheme\":\"urn:com:systinet:reporting:kind\",\"label\":\"report definition\"}]"
-                                                            + "}";
-
-    private static final String ENTRY_STR_JSON_GET  =
-                                                        "[{\"name\":\"{http://www.w3.org/2005/Atom}entry\"," + "\"declaredType\":\"org.apache.wink.common.model.atom.AtomEntry\","
-                                                            + "\"scope\":\"javax.xml.bind.JAXBElement$GlobalScope\","
-                                                            + "\"value\":"
-                                                            + ENTRY_STR_JSON_1
-                                                            + ",\"nil\":false, \"typeSubstituted\":false,\"globalScope\":true},"
-                                                            + "{\"name\":\"{http://www.w3.org/2005/Atom}entry\"," + "\"declaredType\":\"org.apache.wink.common.model.atom.AtomEntry\","
-                                                            + "\"scope\":\"javax.xml.bind.JAXBElement$GlobalScope\","
-                                                            + "\"value\":"
-                                                            + ENTRY_STR_JSON_2
-                                                            + ",\"nil\":false, \"typeSubstituted\":false,\"globalScope\":true}]";
-
-    private static final String ENTRY_JSON_1;
-    private static final String ENTRY_JSON_2;
-
-    static {
-
-        GregorianCalendar gCal = new GregorianCalendar();
-        XMLGregorianCalendar xmlGCal = null;
-        try {
-            xmlGCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCal);
-        } catch (DatatypeConfigurationException e) {
-            fail("could not construct XMLGregorianCalendar: " + e.getMessage());
-            e.printStackTrace();
-        }
-        String jsonTimeStr1 = "{";
-        jsonTimeStr1 += "\"eon\":" + xmlGCal.getEon() + ",";
-        jsonTimeStr1 += "\"year\":" + xmlGCal.getYear() + ",";
-        jsonTimeStr1 += "\"day\":" + xmlGCal.getDay() + ",";
-        jsonTimeStr1 += "\"timezone\":" + xmlGCal.getTimezone() + ",";
-        jsonTimeStr1 += "\"hour\":" + xmlGCal.getHour() + ",";
-        jsonTimeStr1 += "\"minute\":" + xmlGCal.getMinute() + ",";
-        jsonTimeStr1 += "\"second\":" + xmlGCal.getSecond() + ",";
-        jsonTimeStr1 += "\"millisecond\":" + xmlGCal.getMillisecond();
-        jsonTimeStr1 += "}";
-        try {
-            Thread.sleep(2000);
-        } catch (InterruptedException e) {
-        }
-        String jsonTimeStr2 = "{";
-        jsonTimeStr2 += "\"eon\":" + xmlGCal.getEon() + ",";
-        jsonTimeStr2 += "\"year\":" + xmlGCal.getYear() + ",";
-        jsonTimeStr2 += "\"day\":" + xmlGCal.getDay() + ",";
-        jsonTimeStr2 += "\"timezone\":" + xmlGCal.getTimezone() + ",";
-        jsonTimeStr2 += "\"hour\":" + xmlGCal.getHour() + ",";
-        jsonTimeStr2 += "\"minute\":" + xmlGCal.getMinute() + ",";
-        jsonTimeStr2 += "\"second\":" + xmlGCal.getSecond() + ",";
-        jsonTimeStr2 += "\"millisecond\":" + xmlGCal.getMillisecond();
-        jsonTimeStr2 += "}";
-
-        ENTRY_JSON_1 = ENTRY_STR_JSON_1.replaceAll("@TIME_JSON@", jsonTimeStr1);
-        ENTRY_JSON_2 = ENTRY_STR_JSON_2.replaceAll("@TIME_JSON@", jsonTimeStr2);
-    }
-
-    @Override
-    protected Class<?>[] getClasses() {
-        return new Class<?>[] {TestResource.class, PersonResource.class};
-    }
-
-    @Override
-    protected Object[] getSingletons() {
-    	JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
-        return new Object[] {jacksonProvider};
-    }
-
-    @Path("/test/person")
-    public static class PersonResource {
-
-        @GET
-        @Path("collection")
-        public List<Person> getPeopleCollection() throws IOException {
-            List<Person> people = new ArrayList<Person>();
-            Person p = new Person();
-            p.setName("My Name");
-            p.setDesc("My desc");
-            people.add(p);
-            p = new Person();
-            p.setName("My Name 2");
-            p.setDesc("My desc 2");
-            people.add(p);
-            return people;
-        }
-
-        @GET
-        @Path("array")
-        public Person[] getPeopleArray() throws IOException {
-            return getPeopleCollection().toArray(new Person[] {});
-        }
-
-        @GET
-        @Path("jaxbelement")
-        public List<JAXBElement<Person>> getPeopleJAXBElementCollection() throws IOException {
-            List<Person> people = getPeopleCollection();
-            List<JAXBElement<Person>> ret = new ArrayList<JAXBElement<Person>>();
-            JAXBElement<Person> element = null;
-            for (Person p : people) {
-                element = new JAXBElement<Person>(new QName("", "person"), Person.class, p);
-                ret.add(element);
-            }
-            return ret;
-        }
-
-        @POST
-        @Path("collection")
-        public List<Person> postPeopleCollection(List<Person> p) {
-            return p;
-        }
-
-        @POST
-        @Path("array")
-        public Person[] postPeopleArray(Person[] p) {
-            return p;
-        }
-
-    }
-
-    @Path("test")
-    public static class TestResource {
-
-        @GET
-        @Path("atomentries/collection")
-        @Produces("application/json")
-        public List<AtomEntry> getAtomEntriesCollection() throws IOException {
-            List<AtomEntry> entries = new ArrayList<AtomEntry>();
-            AtomEntry entry1 = AtomEntry.unmarshal(new StringReader(ENTRY_STR_1));
-            AtomEntry entry2 = AtomEntry.unmarshal(new StringReader(ENTRY_STR_2));
-            entries.add(entry1);
-            entries.add(entry2);
-            return entries;
-        }
-
-        @GET
-        @Path("atomentries/array")
-        @Produces("application/json")
-        public AtomEntry[] getAtomEntriesArray() throws IOException {
-            return getAtomEntriesCollection().toArray(new AtomEntry[] {});
-        }
-
-        @GET
-        @Path("atomentryelements/collection")
-        @Produces("application/json")
-        public List<JAXBElement<AtomEntry>> getAtomEntryElementCollection() throws IOException {
-            List<JAXBElement<AtomEntry>> entries = new ArrayList<JAXBElement<AtomEntry>>();
-            AtomEntry entry1 = AtomEntry.unmarshal(new StringReader(ENTRY_STR_1));
-            AtomEntry entry2 = AtomEntry.unmarshal(new StringReader(ENTRY_STR_2));
-            org.apache.wink.common.model.atom.ObjectFactory of =
-                new org.apache.wink.common.model.atom.ObjectFactory();
-            entries.add(of.createEntry(entry1));
-            entries.add(of.createEntry(entry2));
-            return entries;
-        }
-    }
-
-    public void testGetPeople() throws Exception {
-        MockHttpServletRequest request =
-            MockRequestConstructor.constructMockRequest("GET",
-                                                        "/test/person/collection",
-                                                        "application/json");
-        MockHttpServletResponse response = invoke(request);
-        assertEquals(200, response.getStatus());
-
-        assertTrue(JSONUtils
-            .equals(new JSONArray(
-                                  "[{\"desc\":\"My desc\",\"name\":\"My Name\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"),
-                    new JSONArray(response.getContentAsString())));
-
-        request =
-            MockRequestConstructor.constructMockRequest("GET",
-                                                        "/test/person/array",
-                                                        "application/json");
-        response = invoke(request);
-        assertEquals(200, response.getStatus());
-
-        assertTrue(JSONUtils
-            .equals(new JSONArray(
-                                  "[{\"desc\":\"My desc\",\"name\":\"My Name\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"),
-                    new JSONArray(response.getContentAsString())));
-
-        request =
-            MockRequestConstructor.constructMockRequest("GET",
-                                                        "/test/person/jaxbelement",
-                                                        "application/json");
-        response = invoke(request);
-        assertEquals(200, response.getStatus());
-
-        assertTrue(JSONUtils
-            .equals(new JSONArray(
-                                  "[{\"name\":\"person\",\"declaredType\":\"org.apache.wink.providers.jackson.internal.jaxb.Person\",\"scope\":\"javax.xml.bind.JAXBElement$GlobalScope\",\"value\":{\"name\":\"My Name\",\"desc\":\"My desc\"},\"nil\":false, \"typeSubstituted\":false,\"globalScope\":true},{\"name\":\"person\",\"declaredType\":\"org.apache.wink.providers.jackson.internal.jaxb.Person\",\"scope\":\"javax.xml.bind.JAXBElement$GlobalScope\",\"value\":{\"name\":\"My Name 2\",\"desc\":\"My desc 2\"},\"nil\":false, \"typeSubstituted\":false,\"globalScope\":true}]"),
-                    new JSONArray(response.getContentAsString())));
-    }
-
-    public void testPostPeople() throws Exception {
-        MockHttpServletRequest request =
-            MockRequestConstructor.constructMockRequest("POST",
-                                                        "/test/person/collection",
-                                                        "application/json");
-        request.setContentType("application/json");
-        request
-            .setContent("[{\"desc\":\"My desc 1\",\"name\":\"My Name 1\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"
-                .getBytes());
-        MockHttpServletResponse response = invoke(request);
-        assertEquals(200, response.getStatus());
-        assertTrue(JSONUtils
-            .equals(new JSONArray(
-                                  "[{\"desc\":\"My desc 1\",\"name\":\"My Name 1\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"),
-                    new JSONArray(response.getContentAsString())));
-
-        request =
-            MockRequestConstructor.constructMockRequest("POST",
-                                                        "/test/person/array",
-                                                        "application/json");
-        request.setContentType("application/json");
-        request
-            .setContent("[{\"desc\":\"My desc 1\",\"name\":\"My Name 1\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"
-                .getBytes());
-        response = invoke(request);
-        assertEquals(200, response.getStatus());
-        assertTrue(JSONUtils
-            .equals(new JSONArray(
-                                  "[{\"desc\":\"My desc 1\",\"name\":\"My Name 1\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"),
-                    new JSONArray(response.getContentAsString())));
-
-    }
-
-    public void testGetAtomEntries() throws Exception {
-        MockHttpServletRequest request =
-            MockRequestConstructor.constructMockRequest("GET",
-                                                        "/test/atomentries/collection",
-                                                        "application/json");
-        MockHttpServletResponse response = invoke(request);
-        assertEquals(200, response.getStatus());
-        assertTrue(JSONUtils.equals(new JSONArray("[" + ENTRY_JSON_1 + "," + ENTRY_JSON_2 + "]"),
-                                    new JSONArray(response.getContentAsString())));
-
-        request =
-            MockRequestConstructor.constructMockRequest("GET",
-                                                        "/test/atomentries/array",
-                                                        "application/json");
-        response = invoke(request);
-        assertEquals(200, response.getStatus());
-        assertTrue(JSONUtils.equals(new JSONArray("[" + ENTRY_JSON_1 + "," + ENTRY_JSON_2 + "]"),
-                                    new JSONArray(response.getContentAsString())));
-    }
-
-    public void testGetAtomEntryElements() throws Exception {
-        MockHttpServletRequest request =
-            MockRequestConstructor.constructMockRequest("GET",
-                                                        "/test/atomentryelements/collection",
-                                                        "application/json");
-        MockHttpServletResponse response = invoke(request);
-        assertEquals(200, response.getStatus());
-        assertTrue(JSONUtils.equals(new JSONArray(ENTRY_STR_JSON_GET), new JSONArray(response
-            .getContentAsString())));
-    }
-}
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *  
+ *******************************************************************************/
+
+package org.apache.wink.providers.jackson.internal;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.xml.bind.JAXBElement;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+
+import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.providers.jackson.internal.jaxb.Person;
+import org.apache.wink.providers.json.JSONUtils;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
+import org.json.JSONArray;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class JAXBCollectionJSONTest extends MockServletInvocationTest {
+
+    private static final String ENTRY_STR_1         =
+                                                        "<entry xml:base=\"http://b216:8080/reporting/reports\" xmlns=\"http://www.w3.org/2005/Atom\">\n" + "    <id>toptenvalidators</id>\n"
+                                                            + "    <updated>2009-08-31T18:30:02Z</updated>\n"
+                                                            + "    <title type=\"text\" xml:lang=\"en\">top ten validators 1</title>\n"
+                                                            + "    <published>2009-08-31T18:30:02Z</published>\n"
+                                                            + "    <link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\" type=\"application/json\" rel=\"alternate\"/>\n"
+                                                            + "    <author>\n"
+                                                            + "        <name>admin 1</name>\n"
+                                                            + "    </author>\n"
+                                                            + "    <category label=\"report definition\" scheme=\"urn:com:systinet:reporting:kind\" term=\"urn:com:systinet:reporting:kind:definition\"/>\n"
+                                                            + "</entry>";
+    private static final String ENTRY_STR_2         =
+                                                        "<entry xml:base=\"http://b216:8080/reporting/reports\" xmlns=\"http://www.w3.org/2005/Atom\">\n" + "    <id>toptenvalidators</id>\n"
+                                                            + "    <updated>2009-08-31T18:30:02Z</updated>\n"
+                                                            + "    <title type=\"text\" xml:lang=\"en\">top ten validators 2</title>\n"
+                                                            + "    <published>2009-08-31T18:30:02Z</published>\n"
+                                                            + "    <link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\" type=\"application/json\" rel=\"alternate\"/>\n"
+                                                            + "    <author>\n"
+                                                            + "        <name>admin 2</name>\n"
+                                                            + "    </author>\n"
+                                                            + "    <category label=\"report definition\" scheme=\"urn:com:systinet:reporting:kind\" term=\"urn:com:systinet:reporting:kind:definition\"/>\n"
+                                                            + "</entry>";
+
+    private static final String ENTRY_STR_JSON_1    =
+                                                        "{\"base\":\"http://b216:8080/reporting/reports\"," + "\"otherAttributes\":{},"
+                                                            + "\"id\":\"toptenvalidators\","
+                                                            + "\"updated\":\"2009-08-31T18:30:02Z\","
+                                                            + "\"title\":{\"lang\":\"en\",\"otherAttributes\":{},\"type\":\"text\"},"
+                                                            + "\"published\":\"2009-08-31T18:30:02Z\","
+                                                            + "\"link\":[{\"otherAttributes\":{},\"rel\":\"alternate\",\"type\":\"application/json\",\"href\":\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\"}],"
+                                                            + "\"author\":[{\"name\":\"admin 1\"}],"
+                                                            + "\"category\":[{\"otherAttributes\":{},\"term\":\"urn:com:systinet:reporting:kind:definition\",\"scheme\":\"urn:com:systinet:reporting:kind\",\"label\":\"report definition\"}]"
+                                                            + "}";
+    private static final String ENTRY_STR_JSON_2    =
+                                                        "{\"base\":\"http://b216:8080/reporting/reports\"," + "\"otherAttributes\":{},"
+                                                            + "\"id\":\"toptenvalidators\","
+                                                            + "\"updated\":\"2009-08-31T18:30:02Z\","
+                                                            + "\"title\":{\"lang\":\"en\",\"otherAttributes\":{},\"type\":\"text\"},"
+                                                            + "\"published\":\"2009-08-31T18:30:02Z\","
+                                                            + "\"link\":[{\"otherAttributes\":{},\"rel\":\"alternate\",\"type\":\"application/json\",\"href\":\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\"}],"
+                                                            + "\"author\":[{\"name\":\"admin 2\"}],"
+                                                            + "\"category\":[{\"otherAttributes\":{},\"term\":\"urn:com:systinet:reporting:kind:definition\",\"scheme\":\"urn:com:systinet:reporting:kind\",\"label\":\"report definition\"}]"
+                                                            + "}";
+
+    private static final String ENTRY_STR_JSON_GET  =
+                                                        "[{\"name\":\"{http://www.w3.org/2005/Atom}entry\"," + "\"declaredType\":\"org.apache.wink.common.model.atom.AtomEntry\","
+                                                            + "\"scope\":\"javax.xml.bind.JAXBElement$GlobalScope\","
+                                                            + "\"value\":"
+                                                            + ENTRY_STR_JSON_1
+                                                            + ",\"nil\":false, \"typeSubstituted\":false,\"globalScope\":true},"
+                                                            + "{\"name\":\"{http://www.w3.org/2005/Atom}entry\"," + "\"declaredType\":\"org.apache.wink.common.model.atom.AtomEntry\","
+                                                            + "\"scope\":\"javax.xml.bind.JAXBElement$GlobalScope\","
+                                                            + "\"value\":"
+                                                            + ENTRY_STR_JSON_2
+                                                            + ",\"nil\":false, \"typeSubstituted\":false,\"globalScope\":true}]";
+
+    private static final String ENTRY_JSON_1;
+    private static final String ENTRY_JSON_2;
+
+    static {
+
+        GregorianCalendar gCal = new GregorianCalendar();
+        XMLGregorianCalendar xmlGCal = null;
+        try {
+            xmlGCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCal);
+        } catch (DatatypeConfigurationException e) {
+            fail("could not construct XMLGregorianCalendar: " + e.getMessage());
+            e.printStackTrace();
+        }
+        String jsonTimeStr1 = "{";
+        jsonTimeStr1 += "\"eon\":" + xmlGCal.getEon() + ",";
+        jsonTimeStr1 += "\"year\":" + xmlGCal.getYear() + ",";
+        jsonTimeStr1 += "\"day\":" + xmlGCal.getDay() + ",";
+        jsonTimeStr1 += "\"timezone\":" + xmlGCal.getTimezone() + ",";
+        jsonTimeStr1 += "\"hour\":" + xmlGCal.getHour() + ",";
+        jsonTimeStr1 += "\"minute\":" + xmlGCal.getMinute() + ",";
+        jsonTimeStr1 += "\"second\":" + xmlGCal.getSecond() + ",";
+        jsonTimeStr1 += "\"millisecond\":" + xmlGCal.getMillisecond();
+        jsonTimeStr1 += "}";
+        try {
+            Thread.sleep(2000);
+        } catch (InterruptedException e) {
+        }
+        String jsonTimeStr2 = "{";
+        jsonTimeStr2 += "\"eon\":" + xmlGCal.getEon() + ",";
+        jsonTimeStr2 += "\"year\":" + xmlGCal.getYear() + ",";
+        jsonTimeStr2 += "\"day\":" + xmlGCal.getDay() + ",";
+        jsonTimeStr2 += "\"timezone\":" + xmlGCal.getTimezone() + ",";
+        jsonTimeStr2 += "\"hour\":" + xmlGCal.getHour() + ",";
+        jsonTimeStr2 += "\"minute\":" + xmlGCal.getMinute() + ",";
+        jsonTimeStr2 += "\"second\":" + xmlGCal.getSecond() + ",";
+        jsonTimeStr2 += "\"millisecond\":" + xmlGCal.getMillisecond();
+        jsonTimeStr2 += "}";
+
+        ENTRY_JSON_1 = ENTRY_STR_JSON_1.replaceAll("@TIME_JSON@", jsonTimeStr1);
+        ENTRY_JSON_2 = ENTRY_STR_JSON_2.replaceAll("@TIME_JSON@", jsonTimeStr2);
+    }
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {TestResource.class, PersonResource.class};
+    }
+
+    @Override
+    protected Object[] getSingletons() {
+    	JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
+        return new Object[] {jacksonProvider};
+    }
+
+    @Path("/test/person")
+    public static class PersonResource {
+
+        @GET
+        @Path("collection")
+        public List<Person> getPeopleCollection() throws IOException {
+            List<Person> people = new ArrayList<Person>();
+            Person p = new Person();
+            p.setName("My Name");
+            p.setDesc("My desc");
+            people.add(p);
+            p = new Person();
+            p.setName("My Name 2");
+            p.setDesc("My desc 2");
+            people.add(p);
+            return people;
+        }
+
+        @GET
+        @Path("array")
+        public Person[] getPeopleArray() throws IOException {
+            return getPeopleCollection().toArray(new Person[] {});
+        }
+
+        @GET
+        @Path("jaxbelement")
+        public List<JAXBElement<Person>> getPeopleJAXBElementCollection() throws IOException {
+            List<Person> people = getPeopleCollection();
+            List<JAXBElement<Person>> ret = new ArrayList<JAXBElement<Person>>();
+            JAXBElement<Person> element = null;
+            for (Person p : people) {
+                element = new JAXBElement<Person>(new QName("", "person"), Person.class, p);
+                ret.add(element);
+            }
+            return ret;
+        }
+
+        @POST
+        @Path("collection")
+        public List<Person> postPeopleCollection(List<Person> p) {
+            return p;
+        }
+
+        @POST
+        @Path("array")
+        public Person[] postPeopleArray(Person[] p) {
+            return p;
+        }
+
+    }
+
+    @Path("test")
+    public static class TestResource {
+
+        @GET
+        @Path("atomentries/collection")
+        @Produces("application/json")
+        public List<AtomEntry> getAtomEntriesCollection() throws IOException {
+            List<AtomEntry> entries = new ArrayList<AtomEntry>();
+            AtomEntry entry1 = AtomEntry.unmarshal(new StringReader(ENTRY_STR_1));
+            AtomEntry entry2 = AtomEntry.unmarshal(new StringReader(ENTRY_STR_2));
+            entries.add(entry1);
+            entries.add(entry2);
+            return entries;
+        }
+
+        @GET
+        @Path("atomentries/array")
+        @Produces("application/json")
+        public AtomEntry[] getAtomEntriesArray() throws IOException {
+            return getAtomEntriesCollection().toArray(new AtomEntry[] {});
+        }
+
+        @GET
+        @Path("atomentryelements/collection")
+        @Produces("application/json")
+        public List<JAXBElement<AtomEntry>> getAtomEntryElementCollection() throws IOException {
+            List<JAXBElement<AtomEntry>> entries = new ArrayList<JAXBElement<AtomEntry>>();
+            AtomEntry entry1 = AtomEntry.unmarshal(new StringReader(ENTRY_STR_1));
+            AtomEntry entry2 = AtomEntry.unmarshal(new StringReader(ENTRY_STR_2));
+            org.apache.wink.common.model.atom.ObjectFactory of =
+                new org.apache.wink.common.model.atom.ObjectFactory();
+            entries.add(of.createEntry(entry1));
+            entries.add(of.createEntry(entry2));
+            return entries;
+        }
+    }
+
+    public void testGetPeople() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/person/collection",
+                                                        "application/json");
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+
+        assertTrue(JSONUtils
+            .equals(new JSONArray(
+                                  "[{\"desc\":\"My desc\",\"name\":\"My Name\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"),
+                    new JSONArray(response.getContentAsString())));
+
+        request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/person/array",
+                                                        "application/json");
+        response = invoke(request);
+        assertEquals(200, response.getStatus());
+
+        assertTrue(JSONUtils
+            .equals(new JSONArray(
+                                  "[{\"desc\":\"My desc\",\"name\":\"My Name\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"),
+                    new JSONArray(response.getContentAsString())));
+
+        request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/person/jaxbelement",
+                                                        "application/json");
+        response = invoke(request);
+        assertEquals(200, response.getStatus());
+
+        assertTrue(JSONUtils
+            .equals(new JSONArray(
+                                  "[{\"name\":\"person\",\"declaredType\":\"org.apache.wink.providers.jackson.internal.jaxb.Person\",\"scope\":\"javax.xml.bind.JAXBElement$GlobalScope\",\"value\":{\"name\":\"My Name\",\"desc\":\"My desc\"},\"nil\":false, \"typeSubstituted\":false,\"globalScope\":true},{\"name\":\"person\",\"declaredType\":\"org.apache.wink.providers.jackson.internal.jaxb.Person\",\"scope\":\"javax.xml.bind.JAXBElement$GlobalScope\",\"value\":{\"name\":\"My Name 2\",\"desc\":\"My desc 2\"},\"nil\":false, \"typeSubstituted\":false,\"globalScope\":true}]"),
+                    new JSONArray(response.getContentAsString())));
+    }
+
+    public void testPostPeople() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/test/person/collection",
+                                                        "application/json");
+        request.setContentType("application/json");
+        request
+            .setContent("[{\"desc\":\"My desc 1\",\"name\":\"My Name 1\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"
+                .getBytes());
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertTrue(JSONUtils
+            .equals(new JSONArray(
+                                  "[{\"desc\":\"My desc 1\",\"name\":\"My Name 1\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"),
+                    new JSONArray(response.getContentAsString())));
+
+        request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/test/person/array",
+                                                        "application/json");
+        request.setContentType("application/json");
+        request
+            .setContent("[{\"desc\":\"My desc 1\",\"name\":\"My Name 1\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"
+                .getBytes());
+        response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertTrue(JSONUtils
+            .equals(new JSONArray(
+                                  "[{\"desc\":\"My desc 1\",\"name\":\"My Name 1\"},{\"desc\":\"My desc 2\",\"name\":\"My Name 2\"}]"),
+                    new JSONArray(response.getContentAsString())));
+
+    }
+
+    public void testGetAtomEntries() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/atomentries/collection",
+                                                        "application/json");
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertTrue(JSONUtils.equals(new JSONArray("[" + ENTRY_JSON_1 + "," + ENTRY_JSON_2 + "]"),
+                                    new JSONArray(response.getContentAsString())));
+
+        request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/atomentries/array",
+                                                        "application/json");
+        response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertTrue(JSONUtils.equals(new JSONArray("[" + ENTRY_JSON_1 + "," + ENTRY_JSON_2 + "]"),
+                                    new JSONArray(response.getContentAsString())));
+    }
+
+    public void testGetAtomEntryElements() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/atomentryelements/collection",
+                                                        "application/json");
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertTrue(JSONUtils.equals(new JSONArray(ENTRY_STR_JSON_GET), new JSONArray(response
+            .getContentAsString())));
+    }
+}



Mime
View raw message