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 2012/11/28 11:58:26 UTC

svn commit: r1414635 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model: BeanParamInfo.java BeanResourceInfo.java

Author: sergeyb
Date: Wed Nov 28 10:58:25 2012
New Revision: 1414635

URL: http://svn.apache.org/viewvc?rev=1414635&view=rev
Log:
Adding missing files

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanParamInfo.java   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java   (with props)

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanParamInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanParamInfo.java?rev=1414635&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanParamInfo.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanParamInfo.java Wed Nov 28 10:58:25 2012
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.model;
+
+import org.apache.cxf.Bus;
+
+public class BeanParamInfo extends BeanResourceInfo {
+    public BeanParamInfo(Class<?> beanClass, Bus bus) {
+        super(beanClass, beanClass, true, bus);
+    }
+
+    @Override
+    public boolean isSingleton() {
+        return false;
+    }
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanParamInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanParamInfo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java?rev=1414635&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java Wed Nov 28 10:58:25 2012
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+
+public abstract class BeanResourceInfo extends AbstractResourceInfo {
+    protected List<Field> paramFields;
+    protected List<Method> paramMethods;
+    
+    
+    protected BeanResourceInfo(Bus bus) {
+        super(bus);
+    }
+
+    protected BeanResourceInfo(Class<?> resourceClass, Class<?> serviceClass, boolean isRoot, Bus bus) {
+        super(resourceClass, serviceClass, isRoot, bus);
+        if (isRoot && resourceClass != null) {
+            setParamField(serviceClass);
+            setParamMethods(serviceClass);
+        }
+    }
+    
+    private void setParamField(Class<?> cls) {
+        if (Object.class == cls || cls == null) {
+            return;
+        }
+        for (Field f : cls.getDeclaredFields()) {
+            for (Annotation a : f.getAnnotations()) {
+                if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
+                    if (paramFields == null) {
+                        paramFields = new ArrayList<Field>();
+                    }
+                    paramFields.add(f);
+                }
+            }
+        }
+        setParamField(cls.getSuperclass());
+    }
+    
+    private void setParamMethods(Class<?> cls) {
+        
+        for (Method m : cls.getMethods()) {
+        
+            if (!m.getName().startsWith("set") || m.getParameterTypes().length != 1) {
+                continue;
+            }
+            for (Annotation a : m.getAnnotations()) {
+                if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
+                    checkParamMethod(m, AnnotationUtils.getAnnotationValue(a));
+                    break;
+                }
+            }
+        }
+        Class<?>[] interfaces = cls.getInterfaces();
+        for (Class<?> i : interfaces) {
+            setParamMethods(i);
+        }
+    }
+    
+    private void addParamMethod(Method m) {
+        if (paramMethods == null) {
+            paramMethods = new ArrayList<Method>();
+        }
+        paramMethods.add(m);
+    }
+    
+    public List<Method> getParameterMethods() {
+        return paramMethods == null ? Collections.<Method>emptyList() 
+                                    : Collections.unmodifiableList(paramMethods);
+    }
+    
+    public List<Field> getParameterFields() {
+        return paramFields == null ? Collections.<Field>emptyList() 
+                                    : Collections.unmodifiableList(paramFields);
+    }
+    
+    private void checkParamMethod(Method m, String value) {
+        if (m.getName().equalsIgnoreCase("set" + value)) {
+            addParamMethod(m);
+        }
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date