cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r912486 - in /cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs: core/Variant.java ext/RuntimeDelegate.java
Date Mon, 22 Feb 2010 05:36:53 GMT
Author: bluk
Date: Mon Feb 22 05:36:53 2010
New Revision: 912486

URL: http://svn.apache.org/viewvc?rev=912486&view=rev
Log:
Add JAX-RS Variant and VariantListBuilder

Added:
    cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Variant.java   (with
props)
Modified:
    cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java

Added: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Variant.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Variant.java?rev=912486&view=auto
==============================================================================
--- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Variant.java (added)
+++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Variant.java Mon Feb
22 05:36:53 2010
@@ -0,0 +1,142 @@
+/*
+ * 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 javax.ws.rs.core;
+
+import java.util.Locale;
+
+import javax.ws.rs.ext.RuntimeDelegate;
+
+public class Variant {
+    public abstract static class VariantListBuilder {
+        protected VariantListBuilder() {
+            /* do nothing */
+        }
+
+        public abstract Variant.VariantListBuilder add();
+
+        public abstract java.util.List<Variant> build();
+
+        public abstract Variant.VariantListBuilder encodings(String... values);
+
+        public abstract Variant.VariantListBuilder languages(Locale... values);
+
+        public abstract Variant.VariantListBuilder mediaTypes(MediaType... values);
+
+        private final static RuntimeDelegate delegate = RuntimeDelegate.getInstance();
+
+        public static Variant.VariantListBuilder newInstance() {
+            return delegate.createVariantListBuilder();
+        }
+    }
+
+    public static Variant.VariantListBuilder encodings(String... values) {
+        return VariantListBuilder.newInstance().encodings(values);
+    }
+
+    public static Variant.VariantListBuilder languages(java.util.Locale... values) {
+        return VariantListBuilder.newInstance().languages(values);
+    }
+
+    public static Variant.VariantListBuilder mediaTypes(MediaType... values) {
+        return VariantListBuilder.newInstance().mediaTypes(values);
+    }
+
+    private final MediaType mediaType;
+    private final Locale    language;
+    private final String    encoding;
+
+    public Variant(MediaType mediaType, Locale language, String encoding) {
+        if (mediaType == null && language == null && encoding == null) {
+            throw new IllegalArgumentException();
+        }
+
+        this.mediaType = mediaType;
+        this.language = language;
+        this.encoding = encoding;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+
+        if (!(obj instanceof Variant)) {
+            return false;
+        }
+
+        Variant other = (Variant)obj;
+
+        String encoding = getEncoding();
+        if (encoding == null) {
+            if (other.getEncoding() != null) {
+                return false;
+            }
+        } else {
+            if (!encoding.equals(other.getEncoding())) {
+                return false;
+            }
+        }
+
+        Locale locale = getLanguage();
+        if (locale == null) {
+            if (other.getLanguage() != null) {
+                return false;
+            }
+        } else {
+            if (!locale.equals(other.getLanguage())) {
+                return false;
+            }
+        }
+
+        MediaType mt = getMediaType();
+        if (mt == null) {
+            if (other.getMediaType() != null) {
+                return false;
+            }
+        } else {
+            return mt.equals(other.getMediaType());
+        }
+
+        return true;
+    }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public java.util.Locale getLanguage() {
+        return language;
+    }
+
+    public MediaType getMediaType() {
+        return mediaType;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = 17;
+        result = 31 * result + ((language == null) ? 0 : language.hashCode());
+        result = 31 * result + ((encoding == null) ? 0 : encoding.hashCode());
+        result = 31 * result + ((mediaType == null) ? 0 : mediaType.hashCode());
+        return result;
+    }
+
+}

Propchange: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Variant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java?rev=912486&r1=912485&r2=912486&view=diff
==============================================================================
--- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java
(original)
+++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java
Mon Feb 22 05:36:53 2010
@@ -20,6 +20,7 @@
 package javax.ws.rs.ext;
 
 import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.Variant;
 
 public abstract class RuntimeDelegate {
 
@@ -29,4 +30,6 @@
         return null;
     }
 
+    public abstract Variant.VariantListBuilder createVariantListBuilder();
+
 }



Mime
View raw message