01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.binding.http.strategy;
19:
20: import java.lang.reflect.Method;
21: import java.util.logging.Logger;
22:
23: import org.apache.cxf.binding.http.URIMapper;
24: import org.apache.cxf.service.model.BindingOperationInfo;
25: import org.codehaus.jra.Delete;
26: import org.codehaus.jra.Get;
27: import org.codehaus.jra.HttpResource;
28: import org.codehaus.jra.Post;
29: import org.codehaus.jra.Put;
30:
31: import static org.apache.cxf.binding.http.HttpConstants.DELETE;
32: import static org.apache.cxf.binding.http.HttpConstants.GET;
33: import static org.apache.cxf.binding.http.HttpConstants.POST;
34: import static org.apache.cxf.binding.http.HttpConstants.PUT;
35:
36: /**
37: * A strategy to map BindingOperationInfos to URI/Verb combos utilizing the
38: * <a href="http://jra.codehaus.org">Java Rest Annotations</a>.
39: */
40: public class JRAStrategy implements ResourceStrategy {
41: private static final Logger LOG = Logger
42: .getLogger(JRAStrategy.class.getName());
43:
44: public boolean map(BindingOperationInfo bop, Method m,
45: URIMapper mapper) {
46: HttpResource r = m.getAnnotation(HttpResource.class);
47: if (r == null) {
48: return false;
49: }
50:
51: String verb;
52: if (m.isAnnotationPresent(Get.class)) {
53: verb = GET;
54: } else if (m.isAnnotationPresent(Post.class)) {
55: verb = POST;
56: } else if (m.isAnnotationPresent(Put.class)) {
57: verb = PUT;
58: } else if (m.isAnnotationPresent(Delete.class)) {
59: verb = DELETE;
60: } else {
61: verb = POST;
62: }
63:
64: mapper.bind(bop, r.location(), verb);
65:
66: LOG.info("Mapping method " + m.getName() + " to resource "
67: + r.location() + " and verb " + verb);
68:
69: return true;
70: }
71:
72: }
|