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 [9/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/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,305 @@
+/*
+ * 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.cxf.jaxrs.impl;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.NewCookie;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Variant;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import com.ibm.ws.jaxrs.core.CaseInsensitiveComparator;
+import com.ibm.ws.jaxrs.i18n.Messages;
+import com.ibm.wsspi.jaxrs.http.DateHandler;
+
+public final class ResponseBuilderImpl extends ResponseBuilder {
+
+    private int status = 200;
+
+    private Object entity;
+
+    private MultivaluedMap<String, Object> metadata = new MetadataMap<String, Object>();
+
+    public ResponseBuilderImpl() {
+    }
+
+    private ResponseBuilderImpl(ResponseBuilderImpl copy) {
+        status = copy.status;
+        if (entity != null) {
+            entity = copy.entity;
+            metadata.putAll(copy.metadata);
+        }
+    }
+
+    @Override
+    public Response build() {
+        ResponseImpl r = new ResponseImpl(status, entity);
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>(
+                metadata, new CaseInsensitiveComparator());
+        r.addMetadata(m);
+        reset();
+        return r;
+    }
+
+    @Override
+    public ResponseBuilder status(int s) {
+        if (s < 100 || s > 599) {
+            throw new IllegalArgumentException(Messages.getMessage(
+                    "statusCodeInvalid", String.valueOf(s)));
+        }
+        status = s;
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder entity(Object e) {
+        entity = e;
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder type(MediaType type) {
+        if (type == null) {
+            metadata.remove(HttpHeaders.CONTENT_TYPE);
+        } else {
+            type(type.toString());
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder type(String type) {
+        if (type == null) {
+            metadata.remove(HttpHeaders.CONTENT_TYPE);
+        } else {
+            metadata.putSingle(HttpHeaders.CONTENT_TYPE, type);
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder language(String language) {
+        if (language == null) {
+            metadata.remove(HttpHeaders.CONTENT_LANGUAGE);
+        } else {
+            metadata.putSingle(HttpHeaders.CONTENT_LANGUAGE, language);
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder location(URI location) {
+        if (location == null) {
+            metadata.remove(HttpHeaders.LOCATION);
+        } else {
+            metadata.putSingle(HttpHeaders.LOCATION, location.toString());
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder contentLocation(URI location) {
+        if (location == null) {
+            metadata.remove(HttpHeaders.CONTENT_LOCATION);
+        } else {
+            metadata.putSingle(HttpHeaders.CONTENT_LOCATION, location
+                    .toString());
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder tag(EntityTag tag) {
+        if (tag == null) {
+            metadata.remove(HttpHeaders.ETAG);
+        } else {
+            tag(tag.toString());
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder tag(String tag) {
+        if (tag == null) {
+            metadata.remove(HttpHeaders.ETAG);
+        } else {
+            metadata.putSingle(HttpHeaders.ETAG, tag);
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder lastModified(Date lastModified) {
+        if (lastModified == null) {
+            metadata.remove(HttpHeaders.LAST_MODIFIED);
+        } else {
+            metadata.putSingle("Last-Modified", DateHandler
+                    .formatDateInRFC1123Format(lastModified));
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder cacheControl(CacheControl cacheControl) {
+        if (cacheControl == null) {
+            metadata.remove(HttpHeaders.CACHE_CONTROL);
+        } else {
+            metadata.putSingle(HttpHeaders.CACHE_CONTROL, cacheControl
+                    .toString());
+        }
+        return this;
+    }
+
+    public ResponseBuilder cookie(NewCookie cookie) {
+        if (cookie == null) {
+            metadata.remove(HttpHeaders.SET_COOKIE);
+        } else {
+            metadata.putSingle(HttpHeaders.SET_COOKIE, cookie.toString());
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder cookie(NewCookie... cookies) {
+        if (cookies == null || cookies.length == 0
+                || (cookies.length == 1 && cookies[0] == null)) {
+            metadata.remove(HttpHeaders.SET_COOKIE);
+        } else {
+            for (NewCookie cookie : cookies) {
+                metadata.add(HttpHeaders.SET_COOKIE, cookie.toString());
+            }
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder header(String name, Object value) {
+        if (value == null) {
+            metadata.remove(name);
+        } else {
+            metadata.add(name, value.toString());
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder variant(Variant variant) {
+        if (variant != null) {
+            if (variant.getMediaType() != null) {
+                type(variant.getMediaType());
+            }
+            if (variant.getLanguage() != null) {
+                language(variant.getLanguage());
+            }
+            if (variant.getEncoding() != null) {
+                metadata.putSingle(HttpHeaders.CONTENT_ENCODING, variant
+                        .getEncoding());
+            }
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder expires(Date expires) {
+        if (expires == null) {
+            metadata.remove(HttpHeaders.EXPIRES);
+        } else {
+            metadata.putSingle(HttpHeaders.EXPIRES, expires.toString());
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder language(Locale locale) {
+        if (locale == null) {
+            metadata.remove(HttpHeaders.CONTENT_LANGUAGE);
+        } else {
+            String lang = locale.getLanguage();
+            if (locale.getCountry() != null) {
+                lang = lang + "_" + locale.getCountry();
+            }
+            metadata.putSingle(HttpHeaders.CONTENT_LANGUAGE, lang);
+        }
+        return this;
+    }
+
+    @Override
+    public ResponseBuilder variants(List<Variant> variants) {
+        if (variants == null) {
+            metadata.remove(HttpHeaders.VARY);
+        } else {
+            boolean isEncodingFound = false;
+            boolean isLanguageFound = false;
+            boolean isMediaTypeFound = false;
+            List<String> headers = new ArrayList<String>();
+            for (Variant v : variants) {
+                if (!isEncodingFound && v.getEncoding() != null) {
+                    isEncodingFound = true;
+                    headers.add(HttpHeaders.ACCEPT_ENCODING);
+                }
+                if (!isLanguageFound && v.getLanguage() != null) {
+                    isLanguageFound = true;
+                    headers.add(HttpHeaders.ACCEPT_LANGUAGE);
+                }
+                if (!isMediaTypeFound && v.getLanguage() != null) {
+                    isMediaTypeFound = true;
+                    headers.add(HttpHeaders.ACCEPT);
+                }
+                if (isEncodingFound && isLanguageFound && isMediaTypeFound) {
+                    break;
+                }
+            }
+            if (headers.size() > 0) {
+                StringBuilder sb = new StringBuilder();
+                sb.append(headers.get(0));
+                for (int c = 1; c < headers.size(); ++c) {
+                    sb.append("," + headers.get(c));
+                }
+                metadata.putSingle(HttpHeaders.VARY, sb.toString());
+            }
+        }
+        return this;
+    }
+
+    //  CHECKSTYLE:OFF
+    @Override
+    public ResponseBuilder clone() {
+        return new ResponseBuilderImpl(this);
+    }
+
+    //  CHECKSTYLE:ON
+
+    private void reset() {
+        metadata.clear();
+        entity = null;
+        status = 200;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/ResponseImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/ResponseImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,55 @@
+/*
+ * 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.cxf.jaxrs.impl;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+
+public final class ResponseImpl extends Response {
+    private final int status;
+    private final Object entity;
+    private MultivaluedMap<String, Object> metadata;
+
+    ResponseImpl(int s, Object e) {
+        this.status = s;
+        this.entity = e;
+    }
+
+    @Override
+    public Object getEntity() {
+        return entity;
+    }
+
+    @Override
+    public int getStatus() {
+        return status;
+    }
+
+    void addMetadata(MultivaluedMap<String, Object> meta) {
+        this.metadata = meta;
+    }
+
+    @Override
+    public MultivaluedMap<String, Object> getMetadata() {
+        // don't worry about cloning for now
+        return metadata;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,330 @@
+/*
+ * 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.cxf.jaxrs.impl;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriBuilderException;
+
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+public class UriBuilderImpl extends UriBuilder {
+
+    private String scheme;
+    private String userInfo;
+    private int port;
+    private String host;
+    private String path;
+    private List<PathSegment> paths;
+    private MultivaluedMap<String, String> matrix;
+    private String fragment;
+    private MultivaluedMap<String, String> query;
+    private URI opaqueURI;
+
+    public UriBuilderImpl() {
+    }
+
+    public UriBuilderImpl(URI uri) {
+        setUriParts(uri);
+    }
+
+    @Override
+    public URI buildFromMap(Map<String, ? extends Object> parts)
+            throws IllegalArgumentException, UriBuilderException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public URI buildFromEncoded(Object... values)
+            throws IllegalArgumentException, UriBuilderException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UriBuilder clone() {
+        return new UriBuilderImpl(build());
+    }
+
+    @Override
+    public UriBuilder fragment(String theFragment)
+            throws IllegalArgumentException {
+        this.fragment = theFragment;
+        return this;
+    }
+
+    @Override
+    public UriBuilder host(String theHost) throws IllegalArgumentException {
+        this.host = theHost;
+        return this;
+    }
+
+    @Override
+    public UriBuilder matrixParam(String name, Object... values)
+            throws IllegalArgumentException {
+        if (matrix == null) {
+            matrix = new MetadataMap<String, String>();
+        }
+
+        if (values == null || name == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+        List<String> stringValues = JAXRSUtils.convertToStringList(values);
+        matrix.put(name, stringValues);
+        return this;
+    }
+
+    @Override
+    public UriBuilder path(String myPath) throws IllegalArgumentException {
+        if (this.path == null) {
+            this.path = myPath;
+        } else {
+            this.path += myPath;
+        }
+        return this;
+    }
+
+    @Override
+    public UriBuilder path(Class resource) throws IllegalArgumentException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UriBuilder path(Method method) throws IllegalArgumentException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UriBuilder path(Class resource, String method)
+            throws IllegalArgumentException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UriBuilder port(int thePort) throws IllegalArgumentException {
+        this.port = thePort;
+        return this;
+    }
+
+    @Override
+    public UriBuilder queryParam(String name, Object... values)
+            throws IllegalArgumentException {
+        if (query == null) {
+            query = new MetadataMap<String, String>();
+        }
+
+        if (values == null || name == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+        List<String> stringValues = JAXRSUtils.convertToStringList(values);
+        query.put(name, stringValues);
+        return this;
+    }
+
+    @Override
+    public UriBuilder replaceMatrixParam(String name, Object... values)
+            throws IllegalArgumentException {
+        if (matrix == null) {
+            matrix = new MetadataMap<String, String>();
+        }
+
+        // if values was empty or null, we'll remove any existing matrix values
+        // stored by this parameter name
+        if (values == null || values.length == 0) {
+            matrix.remove(name);
+        } else {
+            List<String> stringValues = JAXRSUtils.convertToStringList(values);
+            matrix.put(name, stringValues);
+        }
+        return this;
+    }
+
+    @Override
+    public UriBuilder replaceQueryParam(String name, Object... values)
+            throws IllegalArgumentException {
+        if (query == null) {
+            query = new MetadataMap<String, String>();
+        }
+
+        // if values was empty or null, we'll remove any existing query values
+        // stored by this parameter name
+        if (values == null || values.length == 0) {
+            query.remove(name);
+        } else {
+            List<String> stringValues = JAXRSUtils.convertToStringList(values);
+            query.put(name, stringValues);
+        }
+        return this;
+    }
+
+    @Override
+    public UriBuilder scheme(String s) throws IllegalArgumentException {
+        scheme = s;
+        return this;
+    }
+
+    @Override
+    public UriBuilder schemeSpecificPart(String ssp)
+            throws IllegalArgumentException {
+        //schemeSpPart = ssp;
+        return this;
+    }
+
+    @Override
+    public UriBuilder uri(URI uri) throws IllegalArgumentException {
+        if (uri == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+        setUriParts(uri);
+        return this;
+    }
+
+    @Override
+    public UriBuilder userInfo(String ui) throws IllegalArgumentException {
+        this.userInfo = ui;
+        return this;
+    }
+
+    private void setUriParts(URI uri) {
+        if (uri.isOpaque()) {
+            opaqueURI = uri;
+        }
+        scheme = uri.getScheme();
+        port = uri.getPort();
+        host = uri.getHost();
+        path = uri.getPath();
+        paths = JAXRSUtils.getPathSegments(uri.getPath(), false);
+        fragment = uri.getFragment();
+        query = JAXRSUtils.getStructuredParams(uri.getQuery(), "&", true);
+        userInfo = uri.getUserInfo();
+    }
+
+    private String buildPath() {
+        StringBuilder sb = new StringBuilder();
+        for (PathSegment ps : paths) {
+            String p = ps.getPath();
+            if (!p.startsWith("/")) {
+                sb.append('/');
+            }
+            sb.append(p);
+        }
+        return sb.toString();
+
+    }
+
+    private String buildQuery() {
+        StringBuilder b = new StringBuilder();
+        for (Iterator<Map.Entry<String, List<String>>> it = query.entrySet()
+                .iterator(); it.hasNext();) {
+            Map.Entry<String, List<String>> entry = it.next();
+            b.append(entry.getKey());
+            if (entry.getValue().get(0) != null
+                    && !"".equals(entry.getValue().get(0))) {
+                b.append('=').append(entry.getValue().get(0));
+            }
+            if (it.hasNext()) {
+                b.append('&');
+            }
+        }
+        return b.length() > 0 ? b.toString() : null;
+    }
+
+    @Override
+    public UriBuilder replacePath(String aPath) throws IllegalArgumentException {
+        if (aPath == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+        this.path = aPath;
+        return this;
+    }
+
+    @Override
+    public URI build(Object... values) throws IllegalArgumentException,
+            UriBuilderException {
+        try {
+            if (opaqueURI != null) {
+                return opaqueURI;
+            }
+            return new URI(scheme, userInfo, host, port, buildPath(),
+                    buildQuery(), fragment);
+        } catch (URISyntaxException ex) {
+            throw new UriBuilderException(Messages.getMessage("uriBuildFail"),
+                    ex);
+        }
+    }
+
+    @Override
+    public URI buildFromEncodedMap(Map<String, ? extends Object> arg0)
+            throws IllegalArgumentException, UriBuilderException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UriBuilder replaceMatrix(String matrixString)
+            throws IllegalArgumentException {
+        if (matrixString == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+        matrix = JAXRSUtils.getStructuredParams(matrixString, ";", true);
+        return this;
+    }
+
+    @Override
+    public UriBuilder replaceQuery(String queryString)
+            throws IllegalArgumentException {
+        if (queryString == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+        query = JAXRSUtils.getStructuredParams(queryString, "&", true);
+        return this;
+    }
+
+    @Override
+    public UriBuilder segment(String... newSegments)
+            throws IllegalArgumentException {
+        if (newSegments == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+        for (String segment : newSegments) {
+            if (segment == null) {
+                throw new IllegalArgumentException(Messages
+                        .getMessage("nullInput"));
+            }
+            paths.add(new PathSegmentImpl(segment));
+        }
+        return this;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/VariantListBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/VariantListBuilderImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/VariantListBuilderImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/VariantListBuilderImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,125 @@
+/*
+ * 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.cxf.jaxrs.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Variant;
+import javax.ws.rs.core.Variant.VariantListBuilder;
+
+public class VariantListBuilderImpl extends VariantListBuilder {
+
+    private Set<String> encodings = new HashSet<String>();
+    private Set<Locale> languages = new HashSet<Locale>();
+    private Set<MediaType> mediaTypes = new HashSet<MediaType>();
+    private List<Variant> variants = new ArrayList<Variant>();
+
+    public VariantListBuilderImpl() {
+
+    }
+
+    @Override
+    public VariantListBuilder add() {
+        addVariants();
+        resetMeta();
+        return this;
+    }
+
+    @Override
+    public List<Variant> build() {
+        List<Variant> vs = new ArrayList<Variant>(variants);
+        reset();
+        return vs;
+    }
+
+    @Override
+    public VariantListBuilder encodings(String... encs) {
+        encodings.addAll(Arrays.asList(encs));
+        return this;
+    }
+
+    @Override
+    public VariantListBuilder languages(Locale... locales) {
+        languages.addAll(Arrays.asList(locales));
+        return this;
+    }
+
+    @Override
+    public VariantListBuilder mediaTypes(MediaType... types) {
+        mediaTypes.addAll(Arrays.asList(types));
+        return this;
+    }
+
+    private void reset() {
+        variants.clear();
+        resetMeta();
+    }
+
+    private void resetMeta() {
+        mediaTypes.clear();
+        languages.clear();
+        encodings.clear();
+    }
+
+    private void addVariants() {
+        if (mediaTypes.size() > 0) {
+            handleMediaTypes();
+        } else if (languages.size() > 0) {
+            handleLanguages(null);
+        } else if (encodings.size() > 0) {
+            for (String enc : encodings) {
+                variants.add(new Variant(null, null, enc));
+            }
+        }
+    }
+
+    private void handleMediaTypes() {
+        for (MediaType type : mediaTypes) {
+            if (languages.size() > 0) {
+                handleLanguages(type);
+            } else if (encodings.size() > 0) {
+                for (String enc : encodings) {
+                    variants.add(new Variant(type, null, enc));
+                }
+            } else {
+                variants.add(new Variant(type, null, null));
+            }
+        }
+    }
+
+    private void handleLanguages(MediaType type) {
+        for (Locale lang : languages) {
+            if (encodings.size() > 0) {
+                for (String enc : encodings) {
+                    variants.add(new Variant(type, lang, enc));
+                }
+            } else {
+                variants.add(new Variant(type, lang, null));
+            }
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,34 @@
+/*
+ * 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.cxf.jaxrs.impl;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class WebApplicationExceptionMapper implements ExceptionMapper<WebApplicationException> {
+
+    public Response toResponse(WebApplicationException ex) {
+        return ex.getResponse();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/AbstractThreadLocalProxy.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/AbstractThreadLocalProxy.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/AbstractThreadLocalProxy.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/AbstractThreadLocalProxy.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,42 @@
+/*
+ * 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.cxf.jaxrs.impl.tl;
+
+public class AbstractThreadLocalProxy<T> implements ThreadLocalProxy<T> {
+
+    private ThreadLocal<T> infos = new ThreadLocal<T>();
+
+    protected AbstractThreadLocalProxy() {
+
+    }
+
+    public T get() {
+        return infos.get();
+    }
+
+    public void remove() {
+        infos.remove();
+    }
+
+    public void set(T value) {
+        infos.set(value);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpHeaders.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpHeaders.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpHeaders.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpHeaders.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.cxf.jaxrs.impl.tl;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+
+public class ThreadLocalHttpHeaders extends AbstractThreadLocalProxy<HttpHeaders> implements HttpHeaders {
+
+    public List<MediaType> getAcceptableMediaTypes() {
+        return get().getAcceptableMediaTypes();
+    }
+
+    public Map<String, Cookie> getCookies() {
+        return get().getCookies();
+    }
+
+    public Locale getLanguage() {
+        return get().getLanguage();
+    }
+
+    public MediaType getMediaType() {
+        return get().getMediaType();
+    }
+
+    public MultivaluedMap<String, String> getRequestHeaders() {
+        return get().getRequestHeaders();
+    }
+
+    public List<Locale> getAcceptableLanguages() {
+        return get().getAcceptableLanguages();
+    }
+
+    public List<String> getRequestHeader(String name) {
+        return get().getRequestHeader(name);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletRequest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletRequest.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletRequest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletRequest.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,302 @@
+/*
+ * 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.cxf.jaxrs.impl.tl;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+public class ThreadLocalHttpServletRequest extends AbstractThreadLocalProxy<HttpServletRequest> implements HttpServletRequest {
+
+    public String getAuthType() {
+        return get().getAuthType();
+    }
+
+    public String getContextPath() {
+        return get().getContextPath();
+    }
+
+    public Cookie[] getCookies() {
+        return get().getCookies();
+    }
+
+    public long getDateHeader(String name) {
+        return get().getDateHeader(name);
+    }
+
+    public String getHeader(String name) {
+        return get().getHeader(name);
+    }
+
+    public Enumeration getHeaderNames() {
+        return get().getHeaderNames();
+    }
+
+    public Enumeration getHeaders(String name) {
+        return get().getHeaders(name);
+    }
+
+    public int getIntHeader(String name) {
+        return get().getIntHeader(name);
+    }
+
+    public String getMethod() {
+        return get().getMethod();
+    }
+
+    public String getPathInfo() {
+        return get().getPathInfo();
+    }
+
+    public String getPathTranslated() {
+        return get().getPathTranslated();
+    }
+
+    public String getQueryString() {
+        return get().getQueryString();
+    }
+
+    public String getRemoteUser() {
+        return get().getRemoteUser();
+    }
+
+    public String getRequestURI() {
+        return get().getRequestURI();
+    }
+
+    public StringBuffer getRequestURL() {
+        return get().getRequestURL();
+    }
+
+    public String getRequestedSessionId() {
+        return get().getRequestedSessionId();
+    }
+
+    public String getServletPath() {
+        return get().getServletPath();
+    }
+
+    public HttpSession getSession() {
+        return get().getSession();
+    }
+
+    public HttpSession getSession(boolean create) {
+        return get().getSession(create);
+    }
+
+    public Principal getUserPrincipal() {
+        return get().getUserPrincipal();
+    }
+
+    public boolean isRequestedSessionIdFromCookie() {
+        return get().isRequestedSessionIdFromCookie();
+    }
+
+    public boolean isRequestedSessionIdFromURL() {
+        return get().isRequestedSessionIdFromURL();
+    }
+
+    @SuppressWarnings("deprecation")
+    public boolean isRequestedSessionIdFromUrl() {
+        return get().isRequestedSessionIdFromUrl();
+    }
+
+    public boolean isRequestedSessionIdValid() {
+        return get().isRequestedSessionIdValid();
+    }
+
+    public boolean isUserInRole(String role) {
+        return get().isUserInRole(role);
+    }
+
+    public Object getAttribute(String name) {
+        return get().getAttribute(name);
+    }
+
+    public Enumeration getAttributeNames() {
+        return get().getAttributeNames();
+    }
+
+    public String getCharacterEncoding() {
+        return get().getCharacterEncoding();
+    }
+
+    public int getContentLength() {
+        return get().getContentLength();
+    }
+
+    public String getContentType() {
+        return get().getContentType();
+    }
+
+    public ServletInputStream getInputStream() throws IOException {
+        return get().getInputStream();
+    }
+
+    public String getLocalAddr() {
+        return get().getLocalAddr();
+    }
+
+    public String getLocalName() {
+        return get().getLocalName();
+    }
+
+    public int getLocalPort() {
+        return get().getLocalPort();
+    }
+
+    public Locale getLocale() {
+        return get().getLocale();
+    }
+
+    public Enumeration getLocales() {
+        return get().getLocales();
+    }
+
+    public String getParameter(String name) {
+        return get().getParameter(name);
+    }
+
+    public Map getParameterMap() {
+        return get().getParameterMap();
+    }
+
+    public Enumeration getParameterNames() {
+        return get().getParameterNames();
+    }
+
+    public String[] getParameterValues(String name) {
+        return get().getParameterValues(name);
+    }
+
+    public String getProtocol() {
+        return get().getProtocol();
+    }
+
+    public BufferedReader getReader() throws IOException {
+        return get().getReader();
+    }
+
+    @SuppressWarnings("deprecation")
+    public String getRealPath(String path) {
+        return get().getRealPath(path);
+    }
+
+    public String getRemoteAddr() {
+        return get().getRemoteAddr();
+    }
+
+    public String getRemoteHost() {
+        return get().getRemoteHost();
+    }
+
+    public int getRemotePort() {
+        return get().getRemotePort();
+    }
+
+    public RequestDispatcher getRequestDispatcher(String path) {
+        return get().getRequestDispatcher(path);
+    }
+
+    public String getScheme() {
+        return get().getScheme();
+    }
+
+    public String getServerName() {
+        return get().getServerName();
+    }
+
+    public int getServerPort() {
+        return get().getServerPort();
+    }
+
+    public boolean isSecure() {
+        return get().isSecure();
+    }
+
+    public void removeAttribute(String name) {
+        get().removeAttribute(name);
+
+    }
+
+    public void setAttribute(String name, Object o) {
+        get().setAttribute(name, o);
+
+    }
+
+    public void setCharacterEncoding(String env)
+            throws UnsupportedEncodingException {
+        get().setCharacterEncoding(env);
+
+    }
+
+    public boolean isResumed() {
+        return get().isResumed();
+    }
+
+    public boolean isSuspended() {
+        return get().isSuspended();
+    }
+
+    public ServletContext getServletContext() {
+        return get().getServletContext();
+    }
+
+    public void complete() throws IllegalStateException {
+        get().complete();
+    }
+
+    public ServletResponse getServletResponse() {
+        return get().getServletResponse();
+    }
+
+    public boolean isInitial() {
+        return get().isInitial();
+    }
+
+    public boolean isTimeout() {
+        return get().isTimeout();
+    }
+
+    public void resume() throws IllegalStateException {
+        get().resume();
+    }
+
+    public void suspend() throws IllegalStateException {
+        get().suspend();
+    }
+
+    public void suspend(long time) throws IllegalStateException {
+        get().suspend(time);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProxy.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProxy.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProxy.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProxy.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,28 @@
+/*
+ * 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.cxf.jaxrs.impl.tl;
+
+public interface ThreadLocalProxy<T> {
+    void set(T value);
+
+    T get();
+
+    void remove();
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalRequest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalRequest.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalRequest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalRequest.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,53 @@
+/*
+ * 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.cxf.jaxrs.impl.tl;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Variant;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+public class ThreadLocalRequest extends AbstractThreadLocalProxy<Request> implements Request {
+
+    public String getMethod() {
+        return get().getMethod();
+    }
+
+    public ResponseBuilder evaluatePreconditions(EntityTag eTag) {
+        return get().evaluatePreconditions(eTag);
+    }
+
+    public ResponseBuilder evaluatePreconditions(Date lastModified) {
+        return get().evaluatePreconditions(lastModified);
+    }
+
+    public ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) {
+        return get().evaluatePreconditions(lastModified, eTag);
+    }
+
+    public Variant selectVariant(List<Variant> vars)
+            throws IllegalArgumentException {
+        return get().selectVariant(vars);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSecurityContext.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSecurityContext.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSecurityContext.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSecurityContext.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,44 @@
+/*
+ * 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.cxf.jaxrs.impl.tl;
+
+import java.security.Principal;
+
+import javax.ws.rs.core.SecurityContext;
+
+public class ThreadLocalSecurityContext extends AbstractThreadLocalProxy<SecurityContext> implements SecurityContext {
+
+    public String getAuthenticationScheme() {
+        return get().getAuthenticationScheme();
+    }
+
+    public Principal getUserPrincipal() {
+        return get().getUserPrincipal();
+    }
+
+    public boolean isSecure() {
+        return get().isSecure();
+    }
+
+    public boolean isUserInRole(String role) {
+        return get().isUserInRole(role);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,100 @@
+/*
+ * 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.cxf.jaxrs.impl.tl;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+public class ThreadLocalUriInfo extends AbstractThreadLocalProxy<UriInfo> implements UriInfo {
+
+    public URI getAbsolutePath() {
+        return get().getAbsolutePath();
+    }
+
+    public UriBuilder getAbsolutePathBuilder() {
+        return get().getAbsolutePathBuilder();
+    }
+
+    public URI getBaseUri() {
+        return get().getBaseUri();
+    }
+
+    public UriBuilder getBaseUriBuilder() {
+        return get().getBaseUriBuilder();
+    }
+
+    public String getPath() {
+        return get().getPath();
+    }
+
+    public String getPath(boolean decode) {
+        return get().getPath(decode);
+    }
+
+    public List<PathSegment> getPathSegments() {
+        return get().getPathSegments();
+    }
+
+    public List<PathSegment> getPathSegments(boolean decode) {
+        return get().getPathSegments(decode);
+    }
+
+    public MultivaluedMap<String, String> getQueryParameters() {
+        return get().getQueryParameters();
+    }
+
+    public MultivaluedMap<String, String> getQueryParameters(boolean decode) {
+        return get().getQueryParameters(decode);
+    }
+
+    public URI getRequestUri() {
+        return get().getRequestUri();
+    }
+
+    public UriBuilder getRequestUriBuilder() {
+        return get().getRequestUriBuilder();
+    }
+
+    public MultivaluedMap<String, String> getPathParameters() {
+        return get().getPathParameters();
+    }
+
+    public MultivaluedMap<String, String> getPathParameters(boolean decode) {
+        return get().getPathParameters(decode);
+    }
+
+    public List<Object> getMatchedResources() {
+        return get().getMatchedResources();
+    }
+
+    public List<String> getMatchedURIs() {
+        return get().getMatchedURIs();
+    }
+
+    public List<String> getMatchedURIs(boolean decoded) {
+        return get().getMatchedURIs(decoded);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,76 @@
+/*
+ * 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.cxf.jaxrs.model;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
+
+public interface AbstractResourceInfo {
+
+    public Class<?> getServiceClass();
+
+    public Constructor<?> getSelectedServiceClassConstructor();
+
+    /**
+     * Initialize our map of constructors to ThreadLocalProxy objects that will
+     * enable injection of constructor parameters.
+     *
+     */
+    public void initConstructorParams();
+
+    public void initContextFields();
+
+    public void initContextSetterMethods();
+
+    public Map<Class<?>, Method> getContextMethods();
+
+    public boolean isRoot();
+
+    public Class<?> getResourceClass();
+
+    public List<Field> getContextFields();
+
+    /*
+     * this is used for the Java EE @Resource fields right now.  it should be expanded to the other types
+     */
+    public List<Field> getResourceFields();
+
+    public Map<Class<?>, ThreadLocalProxy> getConstructorContextProxies(Constructor<?> cstr);
+
+    public ThreadLocalProxy getContextFieldProxy(Field f);
+
+    /*
+     * this is used for the Java EE @Resource fields right now.  it should be expanded to the other types
+     */
+    public ThreadLocalProxy getResourceFieldProxy(Field f);
+
+    public ThreadLocalProxy getContextSetterProxy(Method m);
+
+    public boolean isSingleton();
+
+    public Object getSingleton();
+
+    public void clearThreadLocalProxies();
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/ClassResourceInfo.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/ClassResourceInfo.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 org.apache.cxf.jaxrs.model;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+public interface ClassResourceInfo extends AbstractResourceInfo {
+
+    // names of properties that can be associated with a value
+    public enum Property {
+        // String
+        PATH,
+
+        // String
+        ALIAS_PATH,
+
+        // String[]
+        ALIAS_PATHS,
+
+        // List<MediaType>
+        CONSUMES,
+
+        // List<MediaType>
+        PRODUCES
+    }
+
+    public URITemplate getURITemplate();
+
+    public void setURITemplate(URITemplate u);
+
+    public void addURIAliasTemplate(URITemplate u);
+
+    public List<URITemplate> getURIAliasTemplates();
+
+    public MethodDispatcher getMethodDispatcher();
+
+    public void setMethodDispatcher(MethodDispatcher md);
+
+    public boolean hasSubResources();
+
+    public void addSubClassResourceInfo(ClassResourceInfo cri);
+
+    public List<ClassResourceInfo> getSubClassResourceInfo();
+
+    public List<MediaType> getProduces();
+
+    public List<MediaType> getConsumes();
+
+    public String getPath();
+
+    public String[] getAliasPaths();
+
+    public List<Method> getParameterMethods();
+
+    public List<Field> getParameterFields();
+
+    public boolean isSingleton();
+
+    public Object getSingleton();
+
+    public void setValue(Property property, Object value);
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/MethodDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/MethodDispatcher.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/MethodDispatcher.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/MethodDispatcher.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.cxf.jaxrs.model;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class MethodDispatcher {
+
+    private List<OperationResourceInfo> opInfos = new ArrayList<OperationResourceInfo>();
+
+    private Map<OperationResourceInfo, Method> oriToMethod = new ConcurrentHashMap<OperationResourceInfo, Method>();
+
+    private Map<Method, OperationResourceInfo> methodToOri = new ConcurrentHashMap<Method, OperationResourceInfo>();
+
+    public void bind(OperationResourceInfo o, Method... methods) {
+        Method primary = methods[0];
+
+        for (Method m : methods) {
+            methodToOri.put(m, o);
+        }
+
+        oriToMethod.put(o, primary);
+
+        if (!opInfos.contains(o)) {
+            opInfos.add(o);
+        }
+    }
+
+    public OperationResourceInfo getOperationResourceInfo(Method method) {
+        return methodToOri.get(method);
+    }
+
+    public List<OperationResourceInfo> getOperationResourceInfos() {
+        return opInfos;
+    }
+
+    public Method getMethod(OperationResourceInfo op) {
+        return oriToMethod.get(op);
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/OperationResourceInfo.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/OperationResourceInfo.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/OperationResourceInfo.java Tue Jun 23 05:41:49 2009
@@ -0,0 +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.cxf.jaxrs.model;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+public interface OperationResourceInfo {
+
+    // names of properties that can be associated with a value
+    public enum Property {
+
+        // String
+        PATH,
+
+        // List<MediaType>
+        CONSUMES,
+
+        // List<MediaType>
+        PRODUCES,
+
+        // Boolean
+        ENCODED,
+
+        // String
+        DEFAULT_VALUE
+
+    }
+
+    public URITemplate getURITemplate();
+
+    public void setURITemplate(URITemplate u);
+
+    public ClassResourceInfo getClassResourceInfo();
+
+    public void setClassResourceInfo(ClassResourceInfo c);
+
+    public Method getMethodToInvoke();
+
+    public void setMethodToInvoke(Method m);
+
+    public String getHttpMethod();
+
+    public void setHttpMethod(String m);
+
+    public void setAnnotatedMethod(Method m);
+
+    public Method getAnnotatedMethod();
+
+    public boolean isSubResourceLocator();
+
+    public void setIsSubResourceLocator(boolean subResourceLocator);
+
+    public boolean isSubResourceMethod();
+
+    public void setIsSubResourceMethod(boolean subResourceMethod);
+
+    public List<MediaType> getProduces();
+
+    public List<MediaType> getConsumes();
+
+    public String getPath();
+
+    public boolean isEncodedEnabled();
+
+    public String getDefaultParameterValue();
+
+    public void setValue(Property property, Object value);
+
+    public void setIsFormParamFound(boolean isFormParamFound);
+
+    public boolean isFormParamFound();
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.cxf.jaxrs.model;
+
+import java.util.Comparator;
+import java.util.List;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+public class OperationResourceInfoComparator implements Comparator<OperationResourceInfo> {
+
+    public int compare(OperationResourceInfo e1, OperationResourceInfo e2) {
+
+        // take care of the cases when we have both HEAD and GET operations
+        // since the GET can serve HEAD requests
+        if (HttpMethod.GET.equalsIgnoreCase(e1.getHttpMethod())
+                && HttpMethod.HEAD.equalsIgnoreCase(e2.getHttpMethod())) {
+            return 1;
+        }
+
+        if (HttpMethod.HEAD.equalsIgnoreCase(e1.getHttpMethod())
+                && HttpMethod.GET.equalsIgnoreCase(e2.getHttpMethod())) {
+            return -1;
+        }
+
+        if (e1.getHttpMethod() != null && e2.getHttpMethod() == null
+                || e1.getHttpMethod() == null && e2.getHttpMethod() != null) {
+            // subresource method takes precedence over a subresource locator
+            return e1.getHttpMethod() != null ? -1 : 1;
+        }
+
+        String l1 = e1.getURITemplate().getLiteralChars();
+        String l2 = e2.getURITemplate().getLiteralChars();
+        if (!l1.equals(l2)) {
+            // descending order
+            return l1.length() < l2.length() ? 1 : -1;
+        }
+
+        int g1 = e1.getURITemplate().getNumberOfGroups();
+        int g2 = e2.getURITemplate().getNumberOfGroups();
+        if (g1 != g2) {
+            // descending order
+            return g1 < g2 ? 1 : -1;
+        }
+
+        int ce1 = e1.getURITemplate().getNumberOfGroupsWithCustomExpression();
+        int ce2 = e2.getURITemplate().getNumberOfGroupsWithCustomExpression();
+        if (ce1 != ce2) {
+            return ce1 < ce2 ? 1 : -1;
+        }
+
+        List<MediaType> mimeType1 = e1.getConsumes();
+        List<MediaType> mimeType2 = e2.getConsumes();
+
+        int result = JAXRSUtils.compareMediaTypes(mimeType1.get(0), mimeType2
+                .get(0));
+        if (result == 0) {
+            //use the media type of output data as the secondary key.
+            List<MediaType> mimeTypeP1 = e1.getProduces();
+            List<MediaType> mimeTypeP2 = e2.getProduces();
+            result = JAXRSUtils.compareMediaTypes(mimeTypeP1.get(0), mimeTypeP2
+                    .get(0));
+        }
+
+        return result;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/ProviderInfo.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/ProviderInfo.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/ProviderInfo.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/ProviderInfo.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,72 @@
+/*
+ * 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.cxf.jaxrs.model;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+public interface ProviderInfo<T> extends AbstractResourceInfo {
+
+    public enum Type {
+        MessageBodyReader, MessageBodyWriter, ContextResolver, ExceptionMapper
+    }
+
+    // names of properties that can be associated with a value
+    public enum Property {
+
+        // List<MediaType>
+        CONSUMES,
+
+        // List<MediaType>
+        PRODUCES
+    }
+
+    /**
+     * Return the Class object that was annotated with
+     *
+     * @Provider.
+     */
+    public Class<T> getProviderClass();
+
+    /**
+     * This method returns a list of MediaTypes consumed by the Provider.
+     */
+    public List<MediaType> getConsumesTypes();
+
+    /**
+     * This method returns a list of MediaTypes produced by Provider.
+     */
+    public List<MediaType> getProducesTypes();
+
+    /**
+     * 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();
+
+    public Map<Type, java.lang.reflect.Type> getParameterizedType();
+
+    public boolean isSingleton();
+
+    public Object getSingleton();
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/URITemplate.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/URITemplate.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/model/URITemplate.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 org.apache.cxf.jaxrs.model;
+
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+
+import org.apache.cxf.jaxrs.utils.HttpUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+public final class URITemplate {
+
+    public static final String TEMPLATE_PARAMETERS = "jaxrs.template.parameters";
+
+    public static final String LIMITED_REGEX_SUFFIX = "(/.*)?";
+    public static final String FINAL_MATCH_GROUP = "FINAL_MATCH_GROUP";
+
+    /**
+     * The regular expression for matching URI templates and names.
+     */
+    private static final Pattern TEMPLATE_NAMES_PATTERN = Pattern
+            .compile("\\{(\\w[-\\w\\.]*)(\\:(.+?))?\\}");
+
+    private static final String DEFAULT_PATH_VARIABLE_REGEX = "([^/]+?)";
+
+    private final String template;
+    private final List<String> templateVariables = new ArrayList<String>();
+    private final List<String> customTemplateVariables = new ArrayList<String>();
+    private final Pattern templateRegexPattern;
+    private final String literals;
+
+    public URITemplate(String theTemplate) {
+
+        this.template = theTemplate;
+
+        StringBuilder literalChars = new StringBuilder();
+        StringBuilder patternBuilder = new StringBuilder();
+
+        // compute a regular expression from URI template
+        Matcher matcher = TEMPLATE_NAMES_PATTERN.matcher(template);
+        int i = 0;
+        while (matcher.find()) {
+            templateVariables.add(matcher.group(1).trim());
+
+            String substr = escapeCharacters(template.substring(i, matcher
+                    .start()));
+            literalChars.append(substr);
+            patternBuilder.append(substr);
+            i = matcher.end();
+            if (matcher.group(2) != null && matcher.group(3) != null) {
+                patternBuilder.append('(');
+                patternBuilder.append(matcher.group(3).trim());
+                patternBuilder.append(')');
+                customTemplateVariables.add(matcher.group(1).trim());
+            } else {
+                patternBuilder.append(DEFAULT_PATH_VARIABLE_REGEX);
+            }
+        }
+        String substr = escapeCharacters(template.substring(i, template
+                .length()));
+        literalChars.append(substr);
+        patternBuilder.append(substr);
+
+        literals = literalChars.toString();
+
+        int endPos = patternBuilder.length() - 1;
+        boolean endsWithSlash = (endPos >= 0) ? patternBuilder.charAt(endPos) == '/'
+                : false;
+        if (endsWithSlash) {
+            patternBuilder.deleteCharAt(endPos);
+        }
+        patternBuilder.append(LIMITED_REGEX_SUFFIX);
+
+        templateRegexPattern = Pattern.compile(patternBuilder.toString());
+    }
+
+    public String getLiteralChars() {
+        return literals;
+    }
+
+    public String getValue() {
+        return template;
+    }
+
+    public int getNumberOfGroups() {
+        return templateVariables.size();
+    }
+
+    public int getNumberOfGroupsWithCustomExpression() {
+        return customTemplateVariables.size();
+    }
+
+    private static String escapeCharacters(String expression) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < expression.length(); i++) {
+            char ch = expression.charAt(i);
+            sb.append(isReservedCharater(ch) ? "\\" + ch : Character
+                    .valueOf(ch));
+        }
+        return sb.toString();
+    }
+
+    private static boolean isReservedCharater(char ch) {
+        return '.' == ch;
+    }
+
+    public boolean match(String uri, MultivaluedMap<String, String> templateVariableToValue) {
+
+        if (uri == null) {
+            return (templateRegexPattern == null) ? true : false;
+        }
+
+        if (templateRegexPattern == null) {
+            return false;
+        }
+
+        // if we can, we need to decode the URI, this will help in cases
+        // where parts of the literal path have been encoded
+        String uriDecoded = null;
+        try {
+            uriDecoded = URLDecoder.decode(uri, "UTF-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Matcher m = templateRegexPattern.matcher(uri);
+        if (!m.matches()) {
+
+            // first check against the decoded version
+            if (uriDecoded != null) {
+                m = templateRegexPattern.matcher(uriDecoded);
+            }
+
+            // now handle matrix parameters in the path
+            if (!m.matches() && uri.contains(";")) {
+                m = templateRegexPattern.matcher(handleMatrixParams(uri));
+
+                // if it still doesn't match, let's try it on the
+                // decoded URI value
+                if (!m.matches() && uriDecoded != null) {
+                    uriDecoded = handleMatrixParams(uriDecoded);
+                    m = templateRegexPattern.matcher(uriDecoded);
+                    if (!m.matches()) {
+                        return false;
+                    }
+                } else if (!m.matches()) {
+                    return false;
+                }
+            } else if (!m.matches()) {
+                return false;
+            }
+        }
+
+        if (!m.matches()) {
+            return false;
+        }
+
+        // Assign the matched template values to template variables
+        int i = 1;
+        for (String name : templateVariables) {
+            String value = m.group(i++);
+            templateVariableToValue.add(name, value);
+        }
+
+        // The right hand side value, might be used to further resolve sub-resources.
+
+        String finalGroup = m.group(i);
+        templateVariableToValue.putSingle(FINAL_MATCH_GROUP,
+                finalGroup == null ? "/" : finalGroup);
+
+        return true;
+    }
+
+    /**
+     * This method handles the case where matrix parameters are embedded
+     * within a request URI.
+     */
+    String handleMatrixParams(String uri) {
+
+        // we might be trying to match one or few path segments containing matrix
+        // parameters against a clear path segment as in @Path("base").
+        List<PathSegment> pList = JAXRSUtils.getPathSegments(template, false);
+        List<PathSegment> uList = JAXRSUtils.getPathSegments(uri, false);
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < uList.size(); i++) {
+            sb.append('/');
+            if (pList.size() > i && pList.get(i).getPath().indexOf('{') != -1) {
+                // if it's URI template variable then keep the original value
+                sb.append(HttpUtils.fromPathSegment(uList.get(i)));
+            } else {
+                sb.append(uList.get(i).getPath());
+            }
+        }
+        return sb.toString();
+    }
+
+    public static URITemplate createTemplate(ClassResourceInfo cri, String pathValue) {
+
+        if (pathValue == null) {
+            return new URITemplate("/");
+        }
+
+        String slashPath = pathValue;
+        if (!slashPath.startsWith("/")) {
+            slashPath = "/" + slashPath;
+        }
+
+        return new URITemplate(slashPath);
+    }
+}
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,273 @@
+/*
+ * 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.cxf.jaxrs.provider;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.annotation.XmlElementDecl;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+import com.ibm.ws.jaxrs.utils.ClassUtils;
+
+public abstract class AbstractJAXBProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
+
+    private static final Log log = LogFactory
+            .getLog(AbstractJAXBProvider.class);
+
+    private static final String CHARSET_PARAMETER = "charset";
+
+    private Map<String, JAXBContext> packageContexts = new ConcurrentHashMap<String, JAXBContext>();
+    private Map<Class<?>, JAXBContext> classContexts = new ConcurrentHashMap<Class<?>, JAXBContext>();
+
+    private ContextResolver<JAXBContext> resolver;
+
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns, MediaType mediaTYpe) {
+        return isSupported(type, genericType, anns)
+                || AnnotationUtils
+                        .getAnnotation(anns, XmlJavaTypeAdapter.class) != null;
+    }
+
+    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return isSupported(type, genericType, annotations);
+    }
+
+    public long getSize(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return -1;
+    }
+
+    protected JAXBContext getJAXBContext(Class<?> type, Type genericType)
+            throws JAXBException {
+
+        if (resolver != null) {
+            JAXBContext context = resolver.getContext(type);
+            // it's up to the resolver to keep its contexts in a map
+            if (context != null) {
+                return context;
+            }
+        }
+
+        JAXBContext context = classContexts.get(type);
+        if (context != null) {
+            return context;
+        }
+
+        context = getPackageContext(type);
+        if (context == null && type != genericType) {
+            context = getPackageContext(InjectionUtils
+                    .getActualType(genericType));
+        }
+
+        return context != null ? context : getClassContext(type);
+    }
+
+    private JAXBContext getClassContext(Class<?> type) throws JAXBException {
+        JAXBContext context = classContexts.get(type);
+        if (context == null) {
+            context = JAXBContext.newInstance(type);
+            classContexts.put(type, context);
+        }
+        return context;
+    }
+
+    private JAXBContext getPackageContext(Class<?> type) {
+        if (type == null) {
+            return null;
+        }
+        String packageName = PackageUtils.getPackageName(type);
+        JAXBContext context = packageContexts.get(packageName);
+        if (context == null) {
+            try {
+                context = JAXBContext.newInstance(packageName, type
+                        .getClassLoader());
+                packageContexts.put(packageName, context);
+                return context;
+            } catch (JAXBException ex) {
+                throw new WebApplicationException(ex);
+            }
+        }
+        return null;
+    }
+
+    protected boolean isSupported(Class<?> type, Type genericType, Annotation[] annotations) {
+
+        return type.getAnnotation(XmlRootElement.class) != null
+                || JAXBElement.class.isAssignableFrom(type)
+                || objectFactoryForClass(type)
+                || (type != genericType && objectFactoryForType(genericType));
+
+    }
+
+    private boolean objectFactoryForClass(Class<?> type) {
+        try {
+            return type.getClassLoader().loadClass(
+                    PackageUtils.getPackageName(type) + ".ObjectFactory") != null;
+        } catch (Exception ex) {
+            return false;
+        }
+    }
+
+    private boolean objectFactoryForType(Type genericType) {
+        return objectFactoryForClass(InjectionUtils.getActualType(genericType));
+    }
+
+    protected Marshaller createMarshaller(Object obj, Class<?> cls, Type genericType, MediaType m)
+            throws JAXBException {
+
+        Class<?> objClazz = JAXBElement.class.isAssignableFrom(cls) ? ((JAXBElement) obj)
+                .getDeclaredType()
+                : cls;
+        JAXBContext context = getJAXBContext(objClazz, genericType);
+        Marshaller marshaller = context.createMarshaller();
+        String enc = m.getParameters().get(CHARSET_PARAMETER);
+        if (enc != null) {
+            marshaller.setProperty(Marshaller.JAXB_ENCODING, enc);
+        }
+        return marshaller;
+    }
+
+    protected Class<?> getActualType(Class<?> type, Type genericType) {
+        Class<?> theType = null;
+        if (JAXBElement.class.isAssignableFrom(type)) {
+            theType = InjectionUtils.getActualType(genericType);
+        } else {
+            theType = type;
+        }
+
+        return theType;
+    }
+
+    @SuppressWarnings("unchecked")
+    protected Object checkAdapter(Object obj, Annotation[] anns) {
+        XmlJavaTypeAdapter typeAdapter = AnnotationUtils.getAnnotation(anns,
+                XmlJavaTypeAdapter.class);
+        if (typeAdapter != null) {
+            try {
+                XmlAdapter xmlAdapter = typeAdapter.value().newInstance();
+                return xmlAdapter.marshal(obj);
+            } catch (Exception ex) {
+                throw new WebApplicationException(ex);
+            }
+        }
+        return obj;
+    }
+
+    /**
+     * Allows subclasses to set an instance of the ContextResolver
+     * @param resolver
+     */
+    protected void setContextResolver(ContextResolver<JAXBContext> resolver) {
+        this.resolver = resolver;
+    }
+
+    protected QName getElementName(Class<?> type) {
+        Class objectFactoryClass = null;
+        String objectFactoryName = PackageUtils.getPackageName(type)
+                + ".ObjectFactory";
+        try {
+            objectFactoryClass = ClassUtils.loadClass(objectFactoryName, Thread
+                    .currentThread().getContextClassLoader());
+        } catch (Exception e) {
+            // suppress
+        }
+        if (objectFactoryClass != null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Looking in " + objectFactoryName
+                        + " for XML element " + "declarations for the type: "
+                        + type.getName());
+            }
+            Method[] methods = objectFactoryClass.getDeclaredMethods();
+            for (Method method : methods) {
+                if (type == method.getReturnType()
+                        && method.getAnnotation(XmlElementDecl.class) != null) {
+                    XmlElementDecl decl = method
+                            .getAnnotation(XmlElementDecl.class);
+                    if (log.isDebugEnabled()) {
+                        log.debug("Found element declaration for type: "
+                                + type.getName() + " with namespace: "
+                                + decl.namespace() + " and name: "
+                                + decl.name());
+                    }
+                    return new QName(decl.namespace(), decl.name());
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Unwraps a deserialized response in the case that the result of unmarshalling
+     * was a JAXBElement. This will throw an exception if the result of unwrapping
+     * is not compatible with expected input.
+     */
+    protected Object unwrapResponse(Class<?> type, Object response) {
+        Object unwrappedResponse = response;
+        // if JAXB deserialized the request into a JAXBElement, and the
+        // value of the element is compatible with the class represented
+        // by 'type', unwrap the object
+        if (response instanceof JAXBElement
+                && !JAXBElement.class.isAssignableFrom(type)) {
+            unwrappedResponse = ((JAXBElement) unwrappedResponse).getValue();
+            if (unwrappedResponse != null
+                    && type.isAssignableFrom(unwrappedResponse.getClass())) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Unwrapping JAXBElement to type: "
+                            + unwrappedResponse.getClass().getName());
+                }
+            } else {
+                String uType = null;
+                if (unwrappedResponse instanceof JAXBElement
+                        && ((JAXBElement) unwrappedResponse).getValue() != null) {
+                    uType = ((JAXBElement) unwrappedResponse).getValue()
+                            .getClass().getName();
+                } else if (unwrappedResponse != null) {
+                    uType = unwrappedResponse.getClass().getName();
+                }
+                throw new RuntimeException(Messages.getMessage("badParamType",
+                        uType, type.getName()));
+            }
+        }
+
+        return unwrappedResponse;
+    }
+
+}



Mime
View raw message