cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1550181 - in /cxf/trunk/rt/rs/extensions/search/src: main/java/org/apache/cxf/jaxrs/ext/search/ main/java/org/apache/cxf/jaxrs/ext/search/fiql/ test/java/org/apache/cxf/jaxrs/ext/search/ test/java/org/apache/cxf/jaxrs/ext/search/jpa/
Date Wed, 11 Dec 2013 16:19:30 GMT
Author: sergeyb
Date: Wed Dec 11 16:19:30 2013
New Revision: 1550181

URL: http://svn.apache.org/r1550181
Log:
[CXF-5453] Support for beans with interfaces

Added:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/InterfaceProxy.java
  (with props)
Modified:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/InterfaceProxy.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/InterfaceProxy.java?rev=1550181&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/InterfaceProxy.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/InterfaceProxy.java
Wed Dec 11 16:19:30 2013
@@ -0,0 +1,45 @@
+/**
+ * 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.ext.search;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+public class InterfaceProxy implements InvocationHandler {
+
+    private Map<String, Object> map = new HashMap<String, Object>(); 
+
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        String methodName = method.getName();
+        if (methodName.length() <= 3) {
+            throw new UnsupportedOperationException();
+        }
+        String property = methodName.substring(3);
+        boolean isGetter = "get".equals(methodName.substring(0,  3));
+        if (isGetter) {
+            return map.get(property);
+        } else {
+            map.put(property, args[0]);
+            return null;
+        }
+    }
+
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/InterfaceProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/InterfaceProxy.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java?rev=1550181&r1=1550180&r2=1550181&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
Wed Dec 11 16:19:30 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.ext.search.fiql;
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -37,6 +38,7 @@ import org.apache.cxf.jaxrs.ext.search.A
 import org.apache.cxf.jaxrs.ext.search.Beanspector;
 import org.apache.cxf.jaxrs.ext.search.Beanspector.TypeInfo;
 import org.apache.cxf.jaxrs.ext.search.ConditionType;
+import org.apache.cxf.jaxrs.ext.search.InterfaceProxy;
 import org.apache.cxf.jaxrs.ext.search.OrSearchCondition;
 import org.apache.cxf.jaxrs.ext.search.PropertyNotFoundException;
 import org.apache.cxf.jaxrs.ext.search.SearchBean;
@@ -381,7 +383,12 @@ public class FiqlParser<T> implements Se
                 boolean lastTry = names.length == 2 
                     && (isPrimitive || returnType == Date.class || returnCollection);
                 
-                Object valueObject = lastTry && ownerBean != null ? ownerBean : actualType.newInstance();
+                Object valueObject = lastTry && ownerBean != null ? ownerBean 
+                    : actualType.isInterface() 
+                    ? Proxy.newProxyInstance(this.getClass().getClassLoader(), 
+                                             new Class[]{actualType}, 
+                                             new InterfaceProxy())
+                    : actualType.newInstance();
                 Object nextObject;
                 
                 if (lastTry) {

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java?rev=1550181&r1=1550180&r2=1550181&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
Wed Dec 11 16:19:30 2013
@@ -19,8 +19,10 @@
 package org.apache.cxf.jaxrs.ext.search;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
+import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 
@@ -238,4 +240,76 @@ public class SearchContextImplTest exten
         assertEquals(ConditionType.EQUALS, ps.getCondition());
         assertEquals(String.class, ps.getValueType());
     }
+    
+    @Test
+    public void testIsMetCompositeObject() throws Exception {
+        SearchCondition<TheBook> filter = 
+            new FiqlParser<TheBook>(TheBook.class,
+                null,                          
+                Collections.singletonMap("address", "address.street")).parse("address==Street1");
+        
+        TheBook b = new TheBook();
+        b.setAddress(new TheOwnerAddress("Street1"));
+        assertTrue(filter.isMet(b));
+        
+        b.setAddress(new TheOwnerAddress("Street2"));
+        assertFalse(filter.isMet(b));
+    }
+    @Test
+    public void testIsMetCompositeInterface() throws Exception {
+        SearchCondition<TheBook> filter = 
+            new FiqlParser<TheBook>(TheBook.class,
+                null,                          
+                Collections.singletonMap("address", "addressInterface.street"))
+                    .parse("address==Street1");
+        
+        TheBook b = new TheBook();
+        b.setAddress(new TheOwnerAddress("Street1"));
+        assertTrue(filter.isMet(b));
+        
+        b.setAddress(new TheOwnerAddress("Street2"));
+        assertFalse(filter.isMet(b));
+    }
+        
+    public static class TheBook {
+        private TheOwnerAddressInterface address;
+
+        public TheOwnerAddress getAddress() {
+            return (TheOwnerAddress)address;
+        }
+
+        public void setAddress(TheOwnerAddress a) {
+            this.address = a;
+        }
+        
+        public TheOwnerAddressInterface getAddressInterface() {
+            return address;
+        }
+
+        public void setAddressInterface(TheOwnerAddressInterface a) {
+            this.address = a;
+        }
+    }
+    public interface TheOwnerAddressInterface {
+        String getStreet();
+        void setStreet(String street);
+    }
+    public static class TheOwnerAddress implements TheOwnerAddressInterface {
+        private String street;
+
+        public TheOwnerAddress() {
+            
+        }
+        public TheOwnerAddress(String s) {
+            this.street = s;
+        }
+        
+        public String getStreet() {
+            return street;
+        }
+
+        public void setStreet(String street) {
+            this.street = street;
+        }
+    }
 }

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java?rev=1550181&r1=1550180&r2=1550181&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
Wed Dec 11 16:19:30 2013
@@ -337,21 +337,6 @@ public class JPATypedQueryVisitorTest ex
     }
     
     @Test
-    public void testIsMet() throws Exception {
-        SearchCondition<Book> filter = 
-            new FiqlParser<Book>(Book.class,
-                null,                          
-                Collections.singletonMap("address", "address.street")).parse("address==Street1");
-        
-        Book b = new Book();
-        b.setAddress(new OwnerAddress("Street1"));
-        assertTrue(filter.isMet(b));
-        
-        b.setAddress(new OwnerAddress("Street2"));
-        assertFalse(filter.isMet(b));
-    }
-    
-    @Test
     public void testEqualsAddressQuery2() throws Exception {
         List<Book> books = queryBooks("street==Street1",
             null,                          



Mime
View raw message