cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r744105 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/
Date Fri, 13 Feb 2009 13:00:25 GMT
Author: sergeyb
Date: Fri Feb 13 13:00:25 2009
New Revision: 744105

URL: http://svn.apache.org/viewvc?rev=744105&view=rev
Log:
JAXRS : missing files plus fixing a typo

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java 
 (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/XMLSourceTest.java
  (with props)
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CglibProxyHelper.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CglibProxyHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CglibProxyHelper.java?rev=744105&r1=744104&r2=744105&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CglibProxyHelper.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CglibProxyHelper.java
Fri Feb 13 13:00:25 2009
@@ -33,7 +33,7 @@
  */
 class CglibProxyHelper extends ProxyHelper {
     CglibProxyHelper() throws Exception {
-        Class.forName("net.sf.cglib.proxy.Proxy");
+        Class.forName("net.sf.cglib.proxy.Enhancer");
         Class.forName("net.sf.cglib.proxy.MethodInterceptor");
         Class.forName("net.sf.cglib.proxy.MethodProxy");
     }
@@ -48,7 +48,7 @@
         for (Class c : interfaces) {
             if (!c.isInterface()) {
                 if (superClass != null) {
-                    throw new IllegalArgumentException("Only a single supreclass is supported");
+                    throw new IllegalArgumentException("Only a single superclass is supported");
                 }
                 superClass = c; 
             } else {

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java?rev=744105&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java Fri
Feb 13 13:00:25 2009
@@ -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.client;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Node;
+
+import org.xml.sax.InputSource;
+
+import org.apache.cxf.helpers.CastUtils;
+
+public class XMLSource {
+    
+    private InputSource source; 
+    
+    public XMLSource(InputStream is) {
+        source = new InputSource(is);
+    }
+    
+    public <T> T getNode(String expression, Class<T> cls) {
+        return getNode(expression, CastUtils.cast(Collections.emptyMap(), String.class, String.class),
cls);
+    }
+    
+    public <T> T getNode(String expression, Map<String, String> namespaces, Class<T>
cls) {
+        XPath xpath = XPathFactory.newInstance().newXPath();
+        xpath.setNamespaceContext(new NamespaceContextImpl(namespaces));
+        try {
+            Node node = (Node)xpath.evaluate(expression, source, XPathConstants.NODE);
+            if (node == null) {
+                return null;
+            }
+            DOMSource ds = new DOMSource(node);
+            return readFromSource(ds, cls);
+        } catch (XPathExpressionException ex) {
+            throw new IllegalArgumentException("Illegal XPath expression '" + expression
+ "'", ex);
+        }
+    }
+
+    private static class NamespaceContextImpl implements NamespaceContext {
+        
+        private Map<String, String> namespaces;
+        
+        public NamespaceContextImpl(Map<String, String> namespaces) {
+            this.namespaces = namespaces;    
+        }
+
+        public String getNamespaceURI(String prefix) {
+            return namespaces.get(prefix);
+        }
+
+        public String getPrefix(String namespace) {
+            for (Map.Entry<String, String> entry : namespaces.entrySet()) {
+                if (entry.getValue().equals(namespace)) {
+                    return entry.getKey();
+                }
+            }
+            return null;
+        }
+
+        public Iterator getPrefixes(String namespace) {
+            String prefix = namespaces.get(namespace);
+            if (prefix == null) {
+                return null;
+            }
+            return Collections.singletonList(prefix).iterator();
+        }
+    }
+    
+    private <T> T readFromSource(Source s, Class<T> cls) {
+        try {
+            JAXBContext c = JAXBContext.newInstance(new Class[]{cls});
+            Unmarshaller u = c.createUnmarshaller();
+            return cls.cast(u.unmarshal(s));
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+}

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

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

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/XMLSourceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/XMLSourceTest.java?rev=744105&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/XMLSourceTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/XMLSourceTest.java
Fri Feb 13 13:00:25 2009
@@ -0,0 +1,95 @@
+/**
+ * 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.client;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class XMLSourceTest extends Assert {
+
+    @Test
+    public void testGetNodeNoNamespace() {
+        InputStream is = new ByteArrayInputStream("<foo><bar/></foo>".getBytes());
+        XMLSource xp = new XMLSource(is);
+        Bar bar = xp.getNode("/foo/bar", Bar.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeNamespace() {
+        String data = "<x:foo xmlns:x=\"http://baz\"><x:bar/></x:foo>";

+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeNamespace2() {
+        String data = "<z:foo xmlns:z=\"http://baz\"><z:bar/></z:foo>";

+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeNamespace3() {
+        String data = "<x:foo xmlns:x=\"http://foo\" xmlns:z=\"http://baz\"><z:bar/></x:foo>";

+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://foo");
+        map.put("y", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/y:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeDefaultNamespace() {
+        String data = "<foo xmlns=\"http://baz\"><bar/></foo>"; 
+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @XmlRootElement
+    private static class Bar {
+        
+    }
+    
+    @XmlRootElement(name = "bar", namespace = "http://baz")
+    private static class Bar2 {
+        
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/XMLSourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/XMLSourceTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message