You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2009/08/12 15:21:25 UTC
svn commit: r803493 - in /cxf/trunk/rt/frontend/jaxrs/src:
main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/
test/java/org/apache/cxf/jaxrs/utils/
Author: sergeyb
Date: Wed Aug 12 13:21:25 2009
New Revision: 803493
URL: http://svn.apache.org/viewvc?rev=803493&view=rev
Log:
CXF-2390 : support for fromValue static methods
Added:
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Timezone.java (with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=803493&r1=803492&r2=803493&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Wed Aug 12 13:21:25 2009
@@ -291,16 +291,19 @@
throw new WebApplicationException(ex, HttpUtils.getParameterFailureStatus(pType));
}
+ Object result = null;
// check for valueOf(String) static methods
String[] methodNames = pClass.isEnum()
- ? new String[] {"fromString", "valueOf"}
+ ? new String[] {"fromString", "fromValue", "valueOf"}
: new String[] {"valueOf", "fromString"};
- Object result = evaluateFactoryMethod(value, pClass, pType, methodNames[0]);
- if (result == null) {
- result = evaluateFactoryMethod(value, pClass, pType, methodNames[1]);
+ for (String mName : methodNames) {
+ result = evaluateFactoryMethod(value, pClass, pType, mName);
+ if (result != null) {
+ break;
+ }
}
- if (message != null) {
+ if (result == null && message != null) {
ParameterHandler<?> pm = ProviderFactory.getInstance(message)
.createParameterHandler(pClass);
if (pm != null) {
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=803493&r1=803492&r2=803493&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Wed Aug 12 13:21:25 2009
@@ -110,7 +110,7 @@
@QueryParam("b")
private String b;
private String name;
-
+
public Customer() {
}
@@ -285,6 +285,11 @@
@QueryParam("p3") CustomerGender gender2) {
// complete
}
+
+ public void testFromValueParam(@QueryParam("p1") Timezone tzone) {
+ // complete
+ }
+
// CHECKSTYLE:OFF
public void testWrongType(@QueryParam("p1") HashMap map) {
// complete
Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Timezone.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Timezone.java?rev=803493&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Timezone.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Timezone.java Wed Aug 12 13:21:25 2009
@@ -0,0 +1,69 @@
+/**
+ * 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;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlEnumValue;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for timezone.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * <p>
+ * <pre>
+ * <simpleType name="timezone">
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ * <enumeration value="Europe/London"/>
+ * <enumeration value="America/New_York"/>
+ * </restriction>
+ * </simpleType>
+ * </pre>
+ *
+ */
+@XmlType(name = "timezone")
+@XmlEnum
+public enum Timezone {
+
+ @XmlEnumValue("Europe/London")
+ EUROPE_LONDON("Europe/London"),
+ @XmlEnumValue("America/New_York")
+ AMERICA_NEW_YORK("America/New_York");
+ private final String value;
+
+ Timezone(String v) {
+ value = v;
+ }
+
+ public String value() {
+ return value;
+ }
+
+ public static Timezone fromValue(String v) {
+ for (Timezone c : Timezone.values()) {
+ if (c.value.equals(v)) {
+ return c;
+ }
+ }
+ throw new IllegalArgumentException(v);
+ }
+
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Timezone.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Timezone.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=803493&r1=803492&r2=803493&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Wed Aug 12 13:21:25 2009
@@ -52,6 +52,7 @@
import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
import org.apache.cxf.jaxrs.JAXRSServiceImpl;
import org.apache.cxf.jaxrs.SimpleFactory;
+import org.apache.cxf.jaxrs.Timezone;
import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -572,6 +573,20 @@
}
@Test
+ public void testFromValueEnum() throws Exception {
+ Class[] argType = {Timezone.class};
+ Method m = Customer.class.getMethod("testFromValueParam", argType);
+ Message messageImpl = createMessage();
+ messageImpl.put(Message.QUERY_STRING, "p1=Europe%2FLondon");
+ List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+ null,
+ messageImpl);
+ assertEquals(1, params.size());
+ assertSame("Timezone Parameter was not processed correctly",
+ Timezone.EUROPE_LONDON, params.get(0));
+ }
+
+ @Test
public void testCustomerParameter() throws Exception {
Message messageImpl = createMessage();
ProviderFactory.getInstance(messageImpl).registerUserProvider(