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 [8/12] - in /incubator/wink/contrib/ibm-jaxrs: ./ lib/ src/ src/com/ src/com/ibm/ src/com/ibm/ws/ src/com/ibm/ws/jaxrs/ src/com/ibm/ws/jaxrs/annotations/ src/com/ibm/ws/jaxrs/context/ src/com/ibm/ws/jaxrs/core/ src/com/ibm/ws/jaxrs/...
Date Tue, 23 Jun 2009 05:41:55 GMT
Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/http/DateHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/http/DateHandler.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/http/DateHandler.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/http/DateHandler.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.wsspi.jaxrs.http;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The DateHandler provides convenience methods to create and manipulate
+ * dates that conform to the HTTP format dictated for date headers.
+ *
+ */
+public class DateHandler {
+
+    private static final String GMT_TIMEZONE = "GMT";
+
+    private static final Log log = LogFactory.getLog(DateHandler.class);
+
+    private static final ThreadLocal<DateFormat> rfc1123DateFormat = new ThreadLocal<DateFormat>() {
+        @Override
+        public DateFormat initialValue() {
+            /*
+             * this is the format that RFC 1123 uses
+             */
+            DateFormat format = new SimpleDateFormat(
+                    "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
+            format.setLenient(false);
+            return format;
+        }
+
+        @Override
+        public DateFormat get() {
+            DateFormat format = super.get();
+            format.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
+            return format;
+        }
+    };
+
+    private static final ThreadLocal<DateFormat> rfc850DateFormat = new ThreadLocal<DateFormat>() {
+        @Override
+        public DateFormat initialValue() {
+            /*
+             * this is the format that RFC 850 uses
+             */
+            DateFormat format = new SimpleDateFormat(
+                    "EEEE, dd-MMM-yy HH:mm:ss zzz", Locale.ENGLISH);
+            format.setLenient(false);
+            return format;
+        }
+
+        @Override
+        public DateFormat get() {
+            DateFormat format = super.get();
+            format.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
+            return format;
+        }
+    };
+
+    private static final ThreadLocal<DateFormat> asctimeDateFormat = new ThreadLocal<DateFormat>() {
+        @Override
+        public DateFormat initialValue() {
+            /*
+             * this is the format that asctime uses
+             */
+            DateFormat format = new SimpleDateFormat(
+                    "EEE MMM dd HH:mm:ss yyyy", Locale.ENGLISH);
+            format.setLenient(false);
+            return format;
+        }
+
+        @Override
+        public DateFormat get() {
+            /* override here because ASCTIME format does not specify GMT time so let's assume it was sent in GMT time when parsing */
+            DateFormat format = super.get();
+            format.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
+            return format;
+        }
+    };
+
+    private static final ThreadLocal<DateFormat> asctimeDateFormatWithOneDayDigit = new ThreadLocal<DateFormat>() {
+        @Override
+        public DateFormat initialValue() {
+            /*
+             * this is the format that asctime uses with a single day digit
+             */
+            DateFormat format = new SimpleDateFormat(
+                    "EEE MMM  d HH:mm:ss yyyy", Locale.ENGLISH);
+            format.setLenient(false);
+            return format;
+        }
+
+        @Override
+        public DateFormat get() {
+            /* override here because ASCTIME format does not specify GMT time so let's assume it was sent in GMT time when parsing */
+            DateFormat format = super.get();
+            format.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
+            return format;
+        }
+    };
+
+    /**
+     * Creates an instance of java.util.Date from the specified String.
+     * The String represents the value of an HTTP date header.
+     */
+    public static Date formatStringToDateInRFC1123Only(String httpDateHeader)
+            throws ParseException {
+        return rfc1123DateFormat.get().parse(httpDateHeader);
+    }
+
+    /**
+     * Extracts the date from the string in as many HTTP supported ways as possible.
+     * @param dateInString the date in string format
+     * @return a Date object representing the date, null if it could not be parsed 
+     */
+    public static Date extractDateFromString(String dateInString) {
+        /*
+         * tries various defined http-date formats to get the Date
+         */
+        Date dateSince = null;
+        try {
+            dateSince = rfc1123DateFormat.get().parse(dateInString);
+        } catch (ParseException ex) {
+            try {
+                dateSince = rfc850DateFormat.get().parse(dateInString);
+            } catch (ParseException ex2) {
+                try {
+                    dateSince = asctimeDateFormat.get().parse(dateInString);
+                } catch (ParseException ex3) {
+                    try {
+                        dateSince = asctimeDateFormatWithOneDayDigit.get()
+                                .parse(dateInString);
+                    } catch (ParseException ex4) {
+                        if (log.isDebugEnabled()) {
+                            log.debug("Could not parse date: " + dateInString,
+                                    ex4);
+                        }
+                        // could not parse, so return null
+                        return null;
+                    }
+                }
+            }
+        }
+        return dateSince;
+    }
+
+    /**
+     * Creates a String from an instance of java.util.Date. The String
+     * will be in HTTP date header format.
+     */
+    public static String formatDateInRFC1123Format(Date date) {
+        DateFormat formatter = rfc1123DateFormat.get();
+        formatter.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
+        return formatter.format(date);
+    }
+
+    /**
+     * Returns the current time as a String in HTTP date header format.
+     */
+    public static String getCurrentDateAsStringInRFC1123Format(String timeZone) {
+        DateFormat formatter = rfc1123DateFormat.get();
+        formatter.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
+        return formatter.format(Calendar.getInstance(
+                TimeZone.getTimeZone(timeZone)).getTime());
+    }
+
+    /**
+     * Returns the current time as a java.util.Date.
+     */
+    public static Date getCurrentDate(String timeZone) {
+        return Calendar.getInstance(TimeZone.getTimeZone(timeZone)).getTime();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Consumes.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Consumes.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Consumes.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Consumes.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 com.ibm.wsspi.jaxrs.options;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlType(name = "consumes", namespace = "http://com.ibm.wsspi.options")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class Consumes {
+
+    @XmlElement(name = "representation", namespace = "http://com.ibm.wsspi.options")
+    private List<Representation> representations;
+
+    public List<Representation> getRepresentations() {
+        return representations;
+    }
+
+    public void setRepresentations(List<Representation> representations) {
+        this.representations = representations;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ObjectFactory.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ObjectFactory.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ObjectFactory.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.wsspi.jaxrs.options;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+    public Resources createResources() {
+        return new Resources();
+    }
+
+    public Resource createResource() {
+        return new Resource();
+    }
+
+    public SubResource createSubResource() {
+        return new SubResource();
+    }
+
+    public ResourceMethod createResourceMethod() {
+        return new ResourceMethod();
+    }
+
+    public ResourceLocator createResourceLocator() {
+        return new ResourceLocator();
+    }
+
+    public Consumes createConsumes() {
+        return new Consumes();
+    }
+
+    public Produces createProduces() {
+        return new Produces();
+    }
+
+    public Representation createRepresentation() {
+        return new Representation();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Produces.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Produces.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Produces.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Produces.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 com.ibm.wsspi.jaxrs.options;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlType(name = "produces", namespace = "http://com.ibm.wsspi.options")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class Produces {
+
+    @XmlElement(name = "representation", namespace = "http://com.ibm.wsspi.options")
+    private List<Representation> representations;
+
+    public List<Representation> getRepresentations() {
+        return representations;
+    }
+
+    public void setRepresentations(List<Representation> representations) {
+        this.representations = representations;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Representation.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Representation.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Representation.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Representation.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 com.ibm.wsspi.jaxrs.options;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlType(name = "representation", namespace = "http://com.ibm.wsspi.options")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class Representation {
+
+    @XmlAttribute(name = "mediaType", namespace = "http://com.ibm.wsspi.options", required = true)
+    private String mediaType;
+
+    public String getMediaType() {
+        return mediaType;
+    }
+
+    public void setMediaType(String mediaType) {
+        this.mediaType = mediaType;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Resource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Resource.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Resource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Resource.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.wsspi.jaxrs.options;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlAccessorType(value = XmlAccessType.FIELD)
+@XmlType(name = "resource", namespace = "http://com.ibm.wsspi.options")
+public class Resource {
+
+    @XmlAttribute(name = "path", namespace = "http://com.ibm.wsspi.options")
+    private String path;
+
+    @XmlElement(name = "consumes", namespace = "http://com.ibm.wsspi.options")
+    private Consumes consumes;
+
+    @XmlElement(name = "produces", namespace = "http://com.ibm.wsspi.options")
+    private Produces produces;
+
+    @XmlElement(name = "resourceMethod", namespace = "http://com.ibm.wsspi.options")
+    private List<ResourceMethod> resourceMethods;
+
+    @XmlElement(name = "resourceLocator", namespace = "http://com.ibm.wsspi.options")
+    private List<ResourceLocator> resourceLocators;
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public Consumes getConsumes() {
+        return consumes;
+    }
+
+    public void setConsumes(Consumes consumes) {
+        this.consumes = consumes;
+    }
+
+    public Produces getProduces() {
+        return produces;
+    }
+
+    public void setProduces(Produces produces) {
+        this.produces = produces;
+    }
+
+    public List<ResourceMethod> getResourceMethods() {
+        return resourceMethods;
+    }
+
+    public void setResourceMethods(List<ResourceMethod> resourceMethods) {
+        this.resourceMethods = resourceMethods;
+    }
+
+    public List<ResourceLocator> getResourceLocators() {
+        return resourceLocators;
+    }
+
+    public void setResourceLocators(List<ResourceLocator> resourceLocators) {
+        this.resourceLocators = resourceLocators;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ResourceLocator.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ResourceLocator.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ResourceLocator.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ResourceLocator.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.wsspi.jaxrs.options;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class ResourceLocator {
+
+    @XmlAttribute(name = "path", namespace = "http://com.ibm.wsspi.options")
+    private String path;
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ResourceMethod.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ResourceMethod.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ResourceMethod.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/ResourceMethod.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.wsspi.jaxrs.options;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class ResourceMethod {
+
+    @XmlAttribute(name = "httpMethod", namespace = "http://com.ibm.wsspi.options")
+    private String httpMethod;
+
+    @XmlElement(name = "consumes", namespace = "http://com.ibm.wsspi.options")
+    private Consumes consumes;
+
+    @XmlElement(name = "produces", namespace = "http://com.ibm.wsspi.options")
+    private Produces produces;
+
+    @XmlAttribute(name = "path", namespace = "http://com.ibm.wsspi.options")
+    private String path;
+
+    @XmlElement(name = "schemaLocation", namespace = "http://com.ibm.wsspi.options")
+    private String schemaLocation;
+
+    public String getHttpMethod() {
+        return httpMethod;
+    }
+
+    public void setHttpMethod(String httpMethod) {
+        this.httpMethod = httpMethod;
+    }
+
+    public Consumes getConsumes() {
+        return consumes;
+    }
+
+    public void setConsumes(Consumes consumes) {
+        this.consumes = consumes;
+    }
+
+    public Produces getProduces() {
+        return produces;
+    }
+
+    public void setProduces(Produces produces) {
+        this.produces = produces;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public String getSchemaLocation() {
+        return schemaLocation;
+    }
+
+    public void setSchemaLocation(String schemaLocation) {
+        this.schemaLocation = schemaLocation;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Resources.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Resources.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Resources.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/Resources.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.wsspi.jaxrs.options;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlAccessorType(value = XmlAccessType.FIELD)
+@XmlType(name = "resources", namespace = "http://com.ibm.wsspi.options")
+public class Resources {
+
+    @XmlElement(name = "resource", namespace = "http://com.ibm.wsspi.options")
+    private List<Resource> resources;
+
+    @XmlElement(name = "subResource", namespace = "http://com.ibm.wsspi.options")
+    private List<SubResource> subResources;
+
+    public List<Resource> getResources() {
+        return resources;
+    }
+
+    public void setResources(List<Resource> resources) {
+        this.resources = resources;
+    }
+
+    public List<SubResource> getSubResources() {
+        return subResources;
+    }
+
+    public void setSubResources(List<SubResource> subResources) {
+        this.subResources = subResources;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/SubResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/SubResource.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/SubResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/wsspi/jaxrs/options/SubResource.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.wsspi.jaxrs.options;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlAccessorType(value = XmlAccessType.FIELD)
+@XmlType(name = "subResource", namespace = "http://com.ibm.wsspi.options")
+public class SubResource extends Resource {
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/PackageUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/PackageUtils.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/PackageUtils.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/PackageUtils.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,214 @@
+/*
+ * 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.common.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+public final class PackageUtils {
+
+    private static final Set<String> KEYWORDS = new HashSet<String>(Arrays
+            .asList(new String[] { "abstract", "boolean", "break", "byte",
+                    "case", "catch", "char", "class", "const", "continue",
+                    "default", "do", "double", "else", "extends", "final",
+                    "finally", "float", "for", "goto", "if", "implements",
+                    "import", "instanceof", "int", "interface", "long",
+                    "native", "new", "package", "private", "protected",
+                    "public", "return", "short", "static", "strictfp", "super",
+                    "switch", "synchronized", "this", "throw", "throws",
+                    "transient", "try", "void", "volatile", "while", "true",
+                    "false", "null", "assert", "enum" }));
+
+    private PackageUtils() {
+
+    }
+
+    static String getPackageName(String className) {
+        int pos = className.lastIndexOf('.');
+        if (pos != -1) {
+            return className.substring(0, pos);
+        }
+        return "";
+    }
+
+    public static String getPackageName(Class<?> clazz) {
+        String className = clazz.getName();
+        if (className.startsWith("[L")) {
+            className = className.substring(2);
+        }
+        return getPackageName(className);
+    }
+
+    public static String parsePackageName(String namespace, String defaultPackageName) {
+        String packageName = (defaultPackageName != null && defaultPackageName
+                .trim().length() > 0) ? defaultPackageName : null;
+
+        if (packageName == null) {
+            packageName = getPackageNameByNameSpaceURI(namespace);
+        }
+        return packageName;
+    }
+
+    public static String getPackageNameByNameSpaceURI(final String nameSpaceURI) {
+        int idx = nameSpaceURI.indexOf(':');
+        String scheme = "";
+        String nameSpaceURIToTokenize = nameSpaceURI;
+        if (idx >= 0) {
+            scheme = nameSpaceURI.substring(0, idx);
+            if ("http".equalsIgnoreCase(scheme)
+                    || "urn".equalsIgnoreCase(scheme)) {
+                nameSpaceURIToTokenize = nameSpaceURIToTokenize
+                        .substring(idx + 1);
+            }
+        }
+
+        List<String> tokens = tokenize(nameSpaceURI, "/: ");
+        if (tokens.size() == 0) {
+            return null;
+        }
+
+        if (tokens.size() > 1) {
+            String lastToken = tokens.get(tokens.size() - 1);
+            idx = lastToken.lastIndexOf('.');
+            if (idx > 0) {
+                lastToken = lastToken.substring(0, idx);
+                tokens.set(tokens.size() - 1, lastToken);
+            }
+        }
+
+        String domain = tokens.get(0);
+        idx = domain.indexOf(':');
+        if (idx >= 0) {
+            domain = domain.substring(0, idx);
+        }
+        List<String> r = reverse(tokenize(domain, "urn".equals(scheme) ? ".-"
+                : "."));
+        if ("www".equalsIgnoreCase(r.get(r.size() - 1))) {
+            // remove leading www
+            r.remove(r.size() - 1);
+        }
+
+        // replace the domain name with tokenized items
+        tokens.addAll(1, r);
+        tokens.remove(0);
+
+        // iterate through the tokens and apply xml->java name algorithm
+        for (int i = 0; i < tokens.size(); i++) {
+
+            // get the token and remove illegal chars
+            String token = tokens.get(i);
+            token = removeIllegalIdentifierChars(token);
+
+            // this will check for reserved keywords
+            if (containsReservedKeywords(token)) {
+                token = '_' + token;
+            }
+
+            tokens.set(i, token.toLowerCase());
+        }
+
+        // concat all the pieces and return it
+        return combine(tokens, '.');
+    }
+
+    private static List<String> tokenize(String str, String sep) {
+        StringTokenizer tokens = new StringTokenizer(str, sep);
+        List<String> r = new ArrayList<String>(tokens.countTokens());
+
+        while (tokens.hasMoreTokens()) {
+            r.add(tokens.nextToken());
+        }
+        return r;
+    }
+
+    private static <T> List<T> reverse(List<T> a) {
+        List<T> r = new ArrayList<T>(a.size());
+
+        for (int i = a.size() - 1; i >= 0; i--) {
+            r.add(a.get(i));
+        }
+        return r;
+    }
+
+    private static String removeIllegalIdentifierChars(String token) {
+        StringBuffer newToken = new StringBuffer();
+        for (int i = 0; i < token.length(); i++) {
+            char c = token.charAt(i);
+
+            if (i == 0 && !Character.isJavaIdentifierStart(c)) {
+                // prefix an '_' if the first char is illegal
+                newToken.append("_" + c);
+            } else if (!Character.isJavaIdentifierPart(c)) {
+                // replace the char with an '_' if it is illegal
+                newToken.append('_');
+            } else {
+                // add the legal char
+                newToken.append(c);
+            }
+        }
+        return newToken.toString();
+    }
+
+    private static String combine(List r, char sep) {
+        StringBuilder buf = new StringBuilder(r.get(0).toString());
+
+        for (int i = 1; i < r.size(); i++) {
+            buf.append(sep);
+            buf.append(r.get(i));
+        }
+
+        return buf.toString();
+    }
+
+    private static boolean containsReservedKeywords(String token) {
+        return KEYWORDS.contains(token);
+    }
+
+    public static String getNamespace(String packageName) {
+        if (packageName == null || packageName.length() == 0) {
+            return null;
+        }
+        StringTokenizer tokenizer = new StringTokenizer(packageName, ".");
+        String[] tokens;
+        if (tokenizer.countTokens() == 0) {
+            tokens = new String[0];
+        } else {
+            tokens = new String[tokenizer.countTokens()];
+            for (int i = tokenizer.countTokens() - 1; i >= 0; i--) {
+                tokens[i] = tokenizer.nextToken();
+            }
+        }
+        StringBuffer namespace = new StringBuffer("http://");
+        String dot = "";
+        for (int i = 0; i < tokens.length; i++) {
+            if (i == 1) {
+                dot = ".";
+            }
+            namespace.append(dot + tokens[i]);
+        }
+        namespace.append('/');
+        return namespace.toString();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/PrimitiveUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/PrimitiveUtils.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/PrimitiveUtils.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/PrimitiveUtils.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,86 @@
+/*
+ * 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.common.util;
+
+public final class PrimitiveUtils {
+
+    private PrimitiveUtils() {
+
+    }
+
+    public static Class getClass(String value) {
+        Class clz = null;
+        if ("int".equals(value)) {
+            clz = int.class;
+        }
+        if ("byte".equals(value)) {
+            clz = byte.class;
+        }
+        if ("short".equals(value)) {
+            clz = short.class;
+        }
+        if ("long".equals(value)) {
+            clz = long.class;
+        }
+        if ("float".equals(value)) {
+            clz = float.class;
+        }
+        if ("double".equals(value)) {
+            clz = double.class;
+        }
+        if ("boolean".equals(value)) {
+            clz = boolean.class;
+        }
+        if ("char".equals(value)) {
+            clz = char.class;
+        }
+        return clz;
+    }
+
+    public static Object read(String value, Class type) {
+        Object ret = value;
+        if (Integer.TYPE.equals(type)) {
+            ret = Integer.valueOf(value);
+        }
+        if (Byte.TYPE.equals(type)) {
+            ret = Byte.valueOf(value);
+        }
+        if (Short.TYPE.equals(type)) {
+            ret = Short.valueOf(value);
+        }
+        if (Long.TYPE.equals(type)) {
+            ret = Long.valueOf(value);
+        }
+        if (Float.TYPE.equals(type)) {
+            ret = Float.valueOf(value);
+        }
+        if (Double.TYPE.equals(type)) {
+            ret = Double.valueOf(value);
+        }
+        if (Boolean.TYPE.equals(type)) {
+            ret = Boolean.valueOf(value);
+        }
+        if (Character.TYPE.equals(type)) {
+            ret = Character.valueOf(value.charAt(0));
+        }
+        // TODO others.
+        return ret;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/StringUtils.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/StringUtils.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/common/util/StringUtils.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,241 @@
+/*
+ * 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.common.util;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public final class StringUtils {
+
+    private StringUtils() {
+    }
+
+    public static String extract(String string, String startToken, String endToken) {
+        int start = string.indexOf(startToken) + startToken.length();
+        int end = string.lastIndexOf(endToken);
+
+        if (start == -1 || end == -1) {
+            return null;
+        }
+
+        return string.substring(start, end);
+    }
+
+    public static String wrapper(String string, String startToken, String endToken) {
+        StringBuffer sb = new StringBuffer();
+        sb.append(startToken);
+        sb.append(string);
+        sb.append(endToken);
+        return sb.toString();
+    }
+
+    public static boolean isFileExist(String file) {
+        return new File(file).exists() && new File(file).isFile();
+    }
+
+    public static boolean isFileAbsolute(String file) {
+        return isFileExist(file) && new File(file).isAbsolute();
+    }
+
+    public static URL getURL(String spec) throws MalformedURLException {
+        try {
+            return new URL(spec);
+        } catch (MalformedURLException e) {
+            return new File(spec).toURI().toURL();
+        }
+    }
+
+    public static boolean isEmpty(String str) {
+        if (str != null && str.trim().length() > 0) {
+            return false;
+        }
+        return true;
+    }
+
+    public static boolean isEmpty(List<String> list) {
+        if (list == null || list.size() == 0) {
+            return true;
+        }
+        if (list.size() == 1 && isEmpty(list.get(0))) {
+            return true;
+        }
+        return false;
+    }
+
+    public static String trim(String target, String token) {
+        int tokenLength = token.length();
+        int targetLength = target.length();
+
+        if (target.startsWith(token)) {
+            return trim(target.substring(tokenLength), token);
+        }
+        if (target.endsWith(token)) {
+            return trim(target.substring(0, targetLength - tokenLength), token);
+        }
+        return target;
+    }
+
+    public static boolean isEqualUri(String uri1, String uri2) {
+
+        if (uri1.substring(uri1.length() - 1).equals("/")
+                && !uri2.substring(uri2.length() - 1).equals("/")) {
+            return uri1.substring(0, uri1.length() - 1).equals(uri2);
+        } else if (uri2.substring(uri2.length() - 1).equals("/")
+                && !uri1.substring(uri1.length() - 1).equals("/")) {
+            return uri2.substring(0, uri2.length() - 1).equals(uri1);
+        } else {
+            return uri1.equals(uri2);
+        }
+    }
+
+    public static String diff(String str1, String str2) {
+        int index = str1.lastIndexOf(str2);
+        if (index > -1) {
+            return str1.substring(str2.length());
+        }
+        return str1;
+    }
+
+    public static List<String> getParts(String str, String sperator) {
+        List<String> parts = Arrays.asList(str.split("/"));
+        List<String> ret = new ArrayList<String>(parts != null ? parts.size()
+                : 0);
+        for (String part : parts) {
+            if (!isEmpty(part)) {
+                ret.add(part);
+            }
+        }
+        return ret;
+    }
+
+    public static String getFirstNotEmpty(String str, String sperator) {
+        List<String> parts = Arrays.asList(str.split("/"));
+        for (String part : parts) {
+            if (!isEmpty(part)) {
+                return part;
+            }
+        }
+        return str;
+    }
+
+    public static String getFirstNotEmpty(List<String> list) {
+        if (isEmpty(list)) {
+            return null;
+        }
+        for (String item : list) {
+            if (!isEmpty(item)) {
+                return item;
+            }
+        }
+        return null;
+    }
+
+    public static List<String> getFound(String contents, String regex) {
+        if (isEmpty(regex) || isEmpty(contents)) {
+            return null;
+        }
+        List<String> results = new ArrayList<String>();
+        Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE);
+        Matcher matcher = pattern.matcher(contents);
+
+        while (matcher.find()) {
+            if (matcher.groupCount() > 0) {
+                results.add(matcher.group(1));
+            } else {
+                results.add(matcher.group());
+            }
+        }
+        return results;
+    }
+
+    public static String getFirstFound(String contents, String regex) {
+        List<String> founds = getFound(contents, regex);
+        if (isEmpty(founds)) {
+            return null;
+        }
+        return founds.get(0);
+    }
+
+    public static String formatVersionNumber(String target) {
+        List<String> found = StringUtils
+                .getFound(target, "\\d+\\.\\d+\\.?\\d*");
+        if (isEmpty(found)) {
+            return target;
+        }
+        return getFirstNotEmpty(found);
+    }
+
+    public static String addDefaultPortIfMissing(String urlString) {
+        return addDefaultPortIfMissing(urlString, "80");
+    }
+
+    public static String addDefaultPortIfMissing(String urlString, String defaultPort) {
+        URL url = null;
+        try {
+            url = new URL(urlString);
+        } catch (MalformedURLException e) {
+            return urlString;
+        }
+        if (url.getPort() != -1) {
+            return urlString;
+        }
+        String regex = "http://([^/]+)";
+        String found = StringUtils.getFirstFound(urlString, regex);
+        String replacer = "http://" + found + ":" + defaultPort;
+
+        if (!StringUtils.isEmpty(found)) {
+            return urlString.replaceFirst(regex, replacer);
+        }
+        return urlString;
+    }
+
+    /**
+     * Return input string with first character in upper case.
+     * @param name input string.
+     * @return capitalized form.
+     */
+    public static String capitalize(String name) {
+        if (name == null || name.length() == 0) {
+            return name;
+        }
+        char chars[] = name.toCharArray();
+        chars[0] = Character.toUpperCase(chars[0]);
+        return new String(chars);
+    }
+
+    public static String uncapitalize(String str) {
+        if (str == null) {
+            return null;
+        }
+        int strLen = str.length();
+        if (strLen == 0) {
+            return str;
+        }
+        return new StringBuffer(strLen).append(
+                Character.toLowerCase(str.charAt(0))).append(str.substring(1))
+                .toString();
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/helpers/IOUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/helpers/IOUtils.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/helpers/IOUtils.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/helpers/IOUtils.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,208 @@
+/*
+ * 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.helpers;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+
+public final class IOUtils {
+    public static final Charset UTF8_CHARSET = Charset.forName("utf-8");
+    private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+    private IOUtils() {
+
+    }
+
+    /**
+     * Use this function instead of new String(byte[]) to avoid surprises from non-standard default encodings.
+     * @param bytes
+     * @return
+     */
+    public static String newStringFromBytes(byte[] bytes) {
+        try {
+            return new String(bytes, UTF8_CHARSET.name());
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Use this function instead of new String(byte[], int, int)
+     * to avoid surprises from non-standard default encodings.
+     * @param bytes
+     * @param start
+     * @param length
+     * @return
+     */
+    public static String newStringFromBytes(byte[] bytes, int start, int length) {
+        try {
+            return new String(bytes, start, length, UTF8_CHARSET.name());
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static int copy(final InputStream input, final OutputStream output)
+            throws IOException {
+        return copy(input, output, DEFAULT_BUFFER_SIZE);
+    }
+
+    public static int copyAndCloseInput(final InputStream input, final OutputStream output)
+            throws IOException {
+        try {
+            return copy(input, output, DEFAULT_BUFFER_SIZE);
+        } finally {
+            input.close();
+        }
+    }
+
+    public static int copyAndCloseInput(final InputStream input, final OutputStream output, int bufferSize)
+            throws IOException {
+        try {
+            return copy(input, output, bufferSize);
+        } finally {
+            input.close();
+        }
+    }
+
+    public static int copy(final InputStream input, final OutputStream output, final int suggestedBufferSize)
+            throws IOException {
+        int avail = input.available();
+        if (avail > 262144) {
+            avail = 262144;
+        }
+        int bufferSize = suggestedBufferSize;
+        if (avail > bufferSize) {
+            bufferSize = avail;
+        }
+        final byte[] buffer = new byte[bufferSize];
+        int n = 0;
+        n = input.read(buffer);
+        int total = 0;
+        while (-1 != n) {
+            output.write(buffer, 0, n);
+            total += n;
+            n = input.read(buffer);
+        }
+        return total;
+    }
+
+    public static void copy(final Reader input, final Writer output, final int bufferSize)
+            throws IOException {
+        final char[] buffer = new char[bufferSize];
+        int n = 0;
+        n = input.read(buffer);
+        while (-1 != n) {
+            output.write(buffer, 0, n);
+            n = input.read(buffer);
+        }
+    }
+
+    public static String toString(final InputStream input) throws IOException {
+        return toString(input, DEFAULT_BUFFER_SIZE);
+    }
+
+    public static String toString(final InputStream input, final int suggestedBufferSize)
+            throws IOException {
+
+        int avail = input.available();
+        int bufferSize = suggestedBufferSize;
+        if (avail > bufferSize) {
+            bufferSize = avail;
+        }
+
+        StringBuilder buf = new StringBuilder();
+        final byte[] buffer = new byte[bufferSize];
+        int n = 0;
+        n = input.read(buffer);
+        while (-1 != n) {
+            buf.append(newStringFromBytes(buffer, 0, n));
+            n = input.read(buffer);
+        }
+        input.close();
+        return buf.toString();
+    }
+
+    public static String toString(final Reader input) throws IOException {
+
+        StringBuilder buf = new StringBuilder();
+        final char[] buffer = new char[DEFAULT_BUFFER_SIZE];
+        int n = 0;
+        n = input.read(buffer);
+        while (-1 != n) {
+            buf.append(new String(buffer, 0, n));
+            n = input.read(buffer);
+        }
+        input.close();
+        return buf.toString();
+    }
+
+    public static String readStringFromStream(InputStream in)
+            throws IOException {
+
+        StringBuilder sb = new StringBuilder(1024);
+
+        for (int i = in.read(); i != -1; i = in.read()) {
+            sb.append((char) i);
+        }
+
+        in.close();
+
+        return sb.toString();
+    }
+
+    /**
+     * Load the InputStream into memory and return a ByteArrayInputStream that
+     * represents it. Closes the in stream.
+     *
+     * @param in
+     * @return
+     * @throws IOException
+     */
+    public static ByteArrayInputStream loadIntoBAIS(InputStream in)
+            throws IOException {
+        int i = in.available();
+        if (i < DEFAULT_BUFFER_SIZE) {
+            i = DEFAULT_BUFFER_SIZE;
+        }
+        LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(i);
+        copy(in, bout);
+        in.close();
+        return bout.createInputStream();
+    }
+
+    public static byte[] readBytesFromStream(InputStream in) throws IOException {
+        int i = in.available();
+        if (i < DEFAULT_BUFFER_SIZE) {
+            i = DEFAULT_BUFFER_SIZE;
+        }
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(i);
+        copy(in, bos);
+        in.close();
+        return bos.toByteArray();
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,62 @@
+/*
+ * 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.helpers;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * Subclass of ByteArrayOutputStream that allows creation of a
+ * ByteArrayInputStream directly without creating a copy of the byte[].
+ *
+ * Also, on "toByteArray()" it truncates it's buffer to the current size
+ * and returns the new buffer directly.  Multiple calls to toByteArray()
+ * will return the exact same byte[] unless a write is called in between.
+ *
+ * Note: once the InputStream is created, the output stream should
+ * no longer be used.  In particular, make sure not to call reset()
+ * and then write as that may overwrite the data that the InputStream
+ * is using.
+ */
+public class LoadingByteArrayOutputStream extends ByteArrayOutputStream {
+    public LoadingByteArrayOutputStream() {
+        super(1024);
+    }
+
+    public LoadingByteArrayOutputStream(int i) {
+        super(i);
+    }
+
+    public ByteArrayInputStream createInputStream() {
+        return new ByteArrayInputStream(buf, 0, count);
+    }
+
+    @Override
+    public byte[] toByteArray() {
+        if (count != buf.length) {
+            buf = super.toByteArray();
+        }
+        return buf;
+    }
+
+    public byte[] getRawBytes() {
+        return buf;
+    }
+}
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,175 @@
+/*
+ * 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.Iterator;
+import java.util.List;
+
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+public class CacheControlHeaderProvider implements HeaderDelegate<CacheControl> {
+
+    private static final String PUBLIC = "public";
+
+    private static final String PRIVATE = "private";
+
+    private static final String NO_CACHE = "no-cache";
+
+    private static final String NO_STORE = "no-store";
+
+    private static final String NO_TRANSFORM = "no-transform";
+
+    private static final String MUST_REVALIDATE = "must-revalidate";
+
+    private static final String PROXY_REVALIDATE = "proxy-revalidate";
+
+    private static final String MAX_AGE = "max-age";
+
+    private static final String SMAX_AGE = "s-maxage";
+
+    public CacheControl fromString(String c) {
+        if (c == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        boolean isPrivate = false;
+        List<String> privateFields = new ArrayList<String>();
+        boolean noCache = false;
+        List<String> noCacheFields = new ArrayList<String>();
+        boolean noStore = false;
+        boolean noTransform = false;
+        boolean mustRevalidate = false;
+        boolean proxyRevalidate = false;
+        int maxAge = -1;
+        int sMaxAge = -1;
+
+        String[] tokens = c.split(";");
+        for (String token : tokens) {
+            if (token.startsWith(MAX_AGE)) {
+                maxAge = Integer
+                        .parseInt(token.substring(MAX_AGE.length() + 1));
+            } else if (token.startsWith(SMAX_AGE)) {
+                sMaxAge = Integer.parseInt(token
+                        .substring(SMAX_AGE.length() + 1));
+            } else if (token.startsWith(PUBLIC)) {
+                // ignore
+            } else if (token.startsWith(NO_STORE)) {
+                noStore = true;
+            } else if (token.startsWith(NO_TRANSFORM)) {
+                noTransform = true;
+            } else if (token.startsWith(MUST_REVALIDATE)) {
+                mustRevalidate = true;
+            } else if (token.startsWith(PROXY_REVALIDATE)) {
+                proxyRevalidate = true;
+            } else if (token.startsWith(PRIVATE)) {
+                isPrivate = true;
+                addFields(privateFields, token);
+            } else if (token.startsWith(NO_CACHE)) {
+                noCache = true;
+                addFields(noCacheFields, token);
+            }
+        }
+
+        CacheControl cc = new CacheControl();
+        cc.setMaxAge(maxAge);
+        cc.setSMaxAge(sMaxAge);
+        cc.setPrivate(isPrivate);
+        cc.getPrivateFields().addAll(privateFields);
+        cc.setMustRevalidate(mustRevalidate);
+        cc.setProxyRevalidate(proxyRevalidate);
+        cc.setNoCache(noCache);
+        cc.getNoCacheFields().addAll(noCacheFields);
+        cc.setNoStore(noStore);
+        cc.setNoTransform(noTransform);
+
+        return cc;
+    }
+
+    public String toString(CacheControl c) {
+        if (c == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        StringBuilder sb = new StringBuilder();
+        if (c.isPrivate()) {
+            sb.append(PRIVATE).append('=');
+            for (Iterator<String> it = c.getPrivateFields().iterator(); it
+                    .hasNext();) {
+                sb.append('\"').append(it.next()).append('\"');
+                if (it.hasNext()) {
+                    sb.append(',');
+                }
+            }
+            sb.append(';');
+        }
+        if (c.isNoCache()) {
+            sb.append(NO_CACHE).append('=');
+            for (Iterator<String> it = c.getNoCacheFields().iterator(); it
+                    .hasNext();) {
+                sb.append('\"').append(it.next()).append('\"');
+                if (it.hasNext()) {
+                    sb.append(',');
+                }
+            }
+            sb.append(';');
+        }
+        if (c.isNoStore()) {
+            sb.append(NO_STORE).append(';');
+        }
+        if (c.isNoTransform()) {
+            sb.append(NO_TRANSFORM).append(';');
+        }
+        if (c.isMustRevalidate()) {
+            sb.append(MUST_REVALIDATE).append(';');
+        }
+        if (c.isProxyRevalidate()) {
+            sb.append(PROXY_REVALIDATE).append(';');
+        }
+        if (c.getMaxAge() != -1) {
+            sb.append(MAX_AGE).append('=').append(c.getMaxAge()).append(';');
+        }
+        if (c.getSMaxAge() != -1) {
+            sb.append(SMAX_AGE).append('=').append(c.getSMaxAge()).append(';');
+        }
+        String s = sb.toString();
+        return s.endsWith(";") ? s.substring(0, s.length() - 1) : s;
+    }
+
+    private static void addFields(List<String> fields, String token) {
+        String f = null;
+        int i = token.indexOf('=');
+        if (i != -1) {
+            f = i == token.length() + 1 ? "" : token.substring(i + 1);
+            if (f.length() < 2 || !f.startsWith("\"") || !f.endsWith("\"")) {
+                f = "";
+            } else {
+                f = f.length() == 2 ? "" : f.substring(1, f.length() - 1);
+            }
+        }
+        if (f != null) {
+            fields.add(f);
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,117 @@
+/*
+ * 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.Cookie;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+public class CookieHeaderProvider implements HeaderDelegate<Cookie> {
+
+    private static final String VERSION = "$Version";
+
+    private static final String PATH = "$Path";
+
+    private static final String DOMAIN = "$Domain";
+
+    public Cookie fromString(String c) {
+
+        if (c == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        int version = 0;
+        String name = null;
+        String value = null;
+        String path = null;
+        String domain = null;
+
+        // ignore the fact the possible version may be seperated by ','
+        String[] tokens = c.split(";");
+        for (String token : tokens) {
+            token = token.trim();
+            if (token.startsWith(VERSION)) {
+                String vStr = token.substring(VERSION.length() + 1);
+                vStr = parseToken(vStr);
+                version = Integer.parseInt(vStr);
+            } else if (token.startsWith(PATH)) {
+                path = token.substring(PATH.length() + 1);
+                path = parseToken(path);
+            } else if (token.startsWith(DOMAIN)) {
+                domain = token.substring(DOMAIN.length() + 1);
+                domain = parseToken(domain);
+            } else {
+                int i = token.indexOf('=');
+                if (i != -1) {
+                    name = token.substring(0, i);
+                    value = i == token.length() + 1 ? "" : token
+                            .substring(i + 1);
+                    value = parseToken(value);
+                }
+            }
+        }
+
+        if (name == null || value == null) {
+            throw new IllegalArgumentException("Cookie is malformed : " + c);
+        }
+
+        return new Cookie(name, value, path, domain, version);
+    }
+
+    /**
+     * Parses a token to remove any preceding or trailing double quotations.
+     */
+    String parseToken(String token) {
+        String parsedToken = token;
+        if (parsedToken != null) {
+            if (parsedToken.startsWith("\"")) {
+                parsedToken = parsedToken.substring(1);
+            }
+            if (parsedToken.endsWith("\"") && parsedToken.length() > 0) {
+                parsedToken = parsedToken
+                        .substring(0, parsedToken.length() - 1);
+            }
+        }
+        return parsedToken;
+    }
+
+    public String toString(Cookie c) {
+
+        if (c == null) {
+            throw new IllegalArgumentException("Cookie is null");
+        }
+
+        StringBuilder sb = new StringBuilder();
+
+        if (c.getVersion() != -1) {
+            sb.append(VERSION).append('=').append(c.getVersion()).append(';');
+        }
+        sb.append(c.getName()).append('=').append(c.getValue());
+        if (c.getPath() != null) {
+            sb.append(';').append(PATH).append('=').append(c.getPath());
+        }
+        if (c.getDomain() != null) {
+            sb.append(';').append(DOMAIN).append('=').append(c.getDomain());
+        }
+        return sb.toString();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,70 @@
+/*
+ * 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.EntityTag;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+public class EntityTagHeaderProvider implements HeaderDelegate<EntityTag> {
+
+    private static final String WEAK_PREFIX = "W/";
+
+    public EntityTag fromString(String header) {
+        if (header == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        String tag = null;
+        boolean weak = false;
+        int i = header.indexOf(WEAK_PREFIX);
+        if (i != -1) {
+            weak = true;
+            if (i + 2 < header.length()) {
+                tag = header.substring(i + 2);
+            } else {
+                return new EntityTag("", weak);
+            }
+        } else {
+            tag = header;
+        }
+        if (tag.length() < 2 || !tag.startsWith("\"") || !tag.endsWith("\"")) {
+            throw new IllegalArgumentException(Messages.getMessage(
+                    "invalidETag", header));
+        }
+        tag = tag.length() == 2 ? "" : tag.substring(1, tag.length() - 1);
+        return new EntityTag(tag, weak);
+    }
+
+    public String toString(EntityTag tag) {
+        if (tag == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        StringBuilder sb = new StringBuilder();
+        if (tag.isWeak()) {
+            sb.append(WEAK_PREFIX);
+        }
+        sb.append("\"").append(tag.getValue()).append("\"");
+        return sb.toString();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,103 @@
+/*
+ * 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.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+public class MediaTypeHeaderProvider implements HeaderDelegate<MediaType> {
+
+    public MediaType fromString(String mType) {
+        if (mType == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        if (mType.equals(MediaType.MEDIA_TYPE_WILDCARD)
+                || mType.startsWith("*;")) {
+            return MediaType.WILDCARD_TYPE;
+        }
+
+        int i = mType.indexOf('/');
+        if (i == -1) {
+            throw new IllegalArgumentException(Messages.getMessage(
+                    "invalidMIMEType", mType));
+        }
+
+        int paramsStart = mType.indexOf(';', i + 1);
+        int end = paramsStart == -1 ? mType.length() : paramsStart;
+
+        String type = mType.substring(0, i);
+        String subtype = mType.substring(i + 1, end);
+
+        Map<String, String> parameters = Collections.emptyMap();
+        if (paramsStart != -1) {
+            // Using Pattern.compile might be marginally faster ?
+            // though it's rare when more than one parameter is provided
+            parameters = new LinkedHashMap<String, String>();
+            StringTokenizer st = new StringTokenizer(mType
+                    .substring(paramsStart + 1), ";");
+            while (st.hasMoreTokens()) {
+                String token = st.nextToken();
+                int equalSign = token.indexOf('=');
+                if (equalSign == -1) {
+                    throw new IllegalArgumentException(Messages.getMessage(
+                            "invalidMIMEType", mType));
+                }
+                parameters.put(token.substring(0, equalSign).trim()
+                        .toLowerCase(), token.substring(equalSign + 1).trim()
+                        .toLowerCase());
+            }
+
+        }
+
+        return new MediaType(type.trim().toLowerCase(), subtype.trim()
+                .toLowerCase(), parameters);
+    }
+
+    public String toString(MediaType type) {
+        if (type == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(type.getType()).append('/').append(type.getSubtype());
+
+        Map<String, String> params = type.getParameters();
+        if (params != null) {
+            for (Iterator<Map.Entry<String, String>> iter = params.entrySet()
+                    .iterator(); iter.hasNext();) {
+                Map.Entry<String, String> entry = iter.next();
+                sb.append(';').append(entry.getKey()).append('=').append(
+                        entry.getValue());
+            }
+        }
+
+        return sb.toString();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/MetadataMap.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/MetadataMap.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/MetadataMap.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/MetadataMap.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,136 @@
+/*
+ * 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.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+public class MetadataMap<K, V> implements MultivaluedMap<K, V> {
+
+    private Map<K, List<V>> m;
+
+    public MetadataMap() {
+        this(new HashMap<K, List<V>>());
+    }
+
+    public MetadataMap(Map<K, List<V>> store) {
+        this(store, null);
+    }
+
+    public MetadataMap(Map<K, List<V>> store, Comparator keyComparator) {
+        if (keyComparator == null) {
+            this.m = store;
+        } else {
+            this.m = new TreeMap<K, List<V>>(keyComparator);
+            this.m.putAll(store);
+        }
+    }
+
+    public void add(K key, V value) {
+        List<V> data = m.get(key);
+        if (data == null) {
+            data = new ArrayList<V>();
+            m.put(key, data);
+        }
+        data.add(value);
+    }
+
+    public V getFirst(K key) {
+        List<V> data = m.get(key);
+        return data == null ? null : data.get(0);
+    }
+
+    public void putSingle(K key, V value) {
+        List<V> data = new ArrayList<V>();
+        data.add(value);
+        m.put(key, data);
+    }
+
+    public void clear() {
+        m.clear();
+    }
+
+    public boolean containsKey(Object key) {
+        return m.containsKey(key);
+    }
+
+    public boolean containsValue(Object value) {
+        return m.containsValue(value);
+    }
+
+    public Set<Entry<K, List<V>>> entrySet() {
+        return m.entrySet();
+    }
+
+    public List<V> get(Object key) {
+        return m.get(key);
+    }
+
+    public boolean isEmpty() {
+        return m.isEmpty();
+    }
+
+    public Set<K> keySet() {
+        return m.keySet();
+    }
+
+    public List<V> put(K key, List<V> value) {
+        return m.put(key, value);
+    }
+
+    public void putAll(Map<? extends K, ? extends List<V>> map) {
+        m.putAll(map);
+    }
+
+    public List<V> remove(Object key) {
+        return m.remove(key);
+    }
+
+    public int size() {
+        return m.size();
+    }
+
+    public Collection<List<V>> values() {
+        return m.values();
+    }
+
+    @Override
+    public int hashCode() {
+        return m.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return m.equals(o);
+    }
+
+    @Override
+    public String toString() {
+        return m.toString();
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,117 @@
+/*
+ * 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.NewCookie;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
+
+import com.ibm.ws.jaxrs.i18n.Messages;
+
+public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie> {
+
+    private static final String VERSION = "Version";
+
+    private static final String PATH = "Path";
+
+    private static final String DOMAIN = "Domain";
+
+    private static final String MAX_AGE = "Max-Age";
+
+    private static final String COMMENT = "Comment";
+
+    private static final String SECURE = "Secure";
+
+    public NewCookie fromString(String c) {
+        if (c == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        String name = null;
+        String value = null;
+        String path = null;
+        String domain = null;
+        String comment = null;
+        int maxAge = -1;
+        boolean isSecure = false;
+
+        String[] tokens = c.split(";");
+        for (String token : tokens) {
+            token = token.trim();
+            if (token.startsWith(VERSION)) {
+                // should we throw an exception if it's not == 1 ?
+            } else if (token.startsWith(MAX_AGE)) {
+                maxAge = Integer
+                        .parseInt(token.substring(MAX_AGE.length() + 1));
+            } else if (token.startsWith(PATH)) {
+                path = token.substring(PATH.length() + 1);
+            } else if (token.startsWith(DOMAIN)) {
+                domain = token.substring(DOMAIN.length() + 1);
+            } else if (token.startsWith(COMMENT)) {
+                comment = token.substring(COMMENT.length() + 1);
+            } else if (token.startsWith(SECURE)) {
+                isSecure = true;
+            } else {
+                int i = token.indexOf('=');
+                if (i != -1) {
+                    name = token.substring(0, i);
+                    value = i == token.length() + 1 ? "" : token
+                            .substring(i + 1);
+                }
+            }
+        }
+
+        if (name == null || value == null) {
+            throw new IllegalArgumentException(Messages.getMessage(
+                    "invalidSetCookie", c));
+        }
+
+        return new NewCookie(name, value, path, domain, comment, maxAge,
+                isSecure);
+    }
+
+    public String toString(NewCookie value) {
+        if (value == null) {
+            throw new IllegalArgumentException(Messages.getMessage("nullInput"));
+        }
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(value.getName()).append('=').append(value.getValue());
+        if (value.getComment() != null) {
+            sb.append(';').append(COMMENT).append('=').append(
+                    value.getComment());
+        }
+        if (value.getDomain() != null) {
+            sb.append(';').append(DOMAIN).append('=').append(value.getDomain());
+        }
+        if (value.getMaxAge() != -1) {
+            sb.append(';').append(MAX_AGE).append('=')
+                    .append(value.getMaxAge());
+        }
+        if (value.getPath() != null) {
+            sb.append(';').append(PATH).append('=').append(value.getPath());
+        }
+        if (value.isSecure()) {
+            sb.append(';').append(SECURE);
+        }
+        sb.append(';').append(VERSION).append('=').append(1);
+        return sb.toString();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java?rev=787557&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java Tue Jun 23 05:41:49 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.PathSegment;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+@Provider
+public class PathSegmentImpl implements PathSegment {
+
+    private String path;
+
+    public PathSegmentImpl(String path) {
+        this(path, true);
+    }
+
+    public PathSegmentImpl(String path, boolean decode) {
+        this.path = decode ? JAXRSUtils.uriDecode(path) : path;
+    }
+
+    public MultivaluedMap<String, String> getMatrixParameters() {
+        return JAXRSUtils.getMatrixParams(path, false);
+    }
+
+    public String getPath() {
+        int index = path.indexOf(';');
+        return index != -1 ? path.substring(0, index) : path;
+    }
+
+    public String getOriginalPath() {
+        return path;
+    }
+
+}



Mime
View raw message