cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r632014 - in /incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw: client/Client.java server/HelloWorld.java server/HelloWorldImpl.java server/IntegerUserMap.java server/IntegerUserMapAdapter.java
Date Thu, 28 Feb 2008 15:42:05 GMT
Author: dkulp
Date: Thu Feb 28 07:42:02 2008
New Revision: 632014

URL: http://svn.apache.org/viewvc?rev=632014&view=rev
Log:
Sample of another advanced use case of passing a Map as a service param/response

Added:
    incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMap.java
  (with props)
    incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMapAdapter.java
  (with props)
Modified:
    incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/client/Client.java
    incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorld.java
    incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorldImpl.java

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/client/Client.java?rev=632014&r1=632013&r2=632014&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/client/Client.java
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/client/Client.java
Thu Feb 28 07:42:02 2008
@@ -19,6 +19,9 @@
 
 package demo.hw.client;
 
+import java.util.Map;
+import java.util.Map.Entry;
+
 import javax.xml.namespace.QName;
 import javax.xml.ws.Service;
 import javax.xml.ws.soap.SOAPBinding;
@@ -51,6 +54,21 @@
 
         User user = new UserImpl("World");
         System.out.println(hw.sayHiToUser(user));
+
+        //say hi to some more users to fill up the map a bit
+        user = new UserImpl("Galaxy");
+        System.out.println(hw.sayHiToUser(user));
+
+        user = new UserImpl("Universe");
+        System.out.println(hw.sayHiToUser(user));
+
+        System.out.println();
+        System.out.println("Users: ");
+        Map<Integer, User> users = hw.getUsers();
+        for (Map.Entry<Integer, User> e : users.entrySet()) {
+            System.out.println("  " + e.getKey() + ": " + e.getValue().getName());
+        }
+
     }
 
 }

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorld.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorld.java?rev=632014&r1=632013&r2=632014&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorld.java
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorld.java
Thu Feb 28 07:42:02 2008
@@ -18,7 +18,10 @@
  */
 package demo.hw.server;
 
+import java.util.Map;
+
 import javax.jws.WebService;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
 @WebService
 public interface HelloWorld {
@@ -31,5 +34,14 @@
      * be written to handle them
      */
     String sayHiToUser(User user);
+
+
+    /* Map passing
+     * JAXB also does not support Maps.  It handles Lists great, but Maps are
+     * not supported directly.  They also require use of a XmlAdapter to map
+     * the maps into beans that JAXB can use. 
+     */
+    @XmlJavaTypeAdapter(IntegerUserMapAdapter.class)
+    Map<Integer, User> getUsers();
 }
 // END SNIPPET: service

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorldImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorldImpl.java?rev=632014&r1=632013&r2=632014&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorldImpl.java
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/HelloWorldImpl.java
Thu Feb 28 07:42:02 2008
@@ -19,18 +19,28 @@
 // START SNIPPET: service
 package demo.hw.server;
 
+import java.util.LinkedHashMap;
+import java.util.Map;
+
 import javax.jws.WebService;
 
 @WebService(endpointInterface = "demo.hw.server.HelloWorld", 
             serviceName = "HelloWorld")
 public class HelloWorldImpl implements HelloWorld {
+    Map<Integer, User> users = new LinkedHashMap<Integer, User>();
+
 
     public String sayHi(String text) {
         return "Hello " + text;
     }
 
     public String sayHiToUser(User user) {
+        users.put(users.size() + 1, user);
         return "Hello "  + user.getName();
+    }
+
+    public Map<Integer, User> getUsers() {
+        return users;
     }
 
 }

Added: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMap.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMap.java?rev=632014&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMap.java
(added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMap.java
Thu Feb 28 07:42:02 2008
@@ -0,0 +1,65 @@
+
+/**
+ * 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 demo.hw.server;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+@XmlType(name = "IntegerUserMap")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class IntegerUserMap {
+    @XmlElement(nillable = false, name = "entry")
+    List<IntegerUserEntry> entries = new ArrayList<IntegerUserEntry>();
+
+    public List<IntegerUserEntry> getEntries() {
+        return entries;
+    }
+
+    @XmlAccessorType(XmlAccessType.FIELD)
+    @XmlType(name = "IdentifiedUser")
+    static class IntegerUserEntry {
+        //Map keys cannot be null
+        @XmlElement(required = true, nillable = false)
+        Integer id;
+
+        User user;
+
+        public void setId(Integer k) {
+            id = k;
+        }
+        public Integer getId() {
+            return id;
+        }
+
+        public void setUser(User u) {
+            user = u;
+        }
+        public User getUser() {
+            return user;
+        }
+    }
+}
+

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMap.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMapAdapter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMapAdapter.java?rev=632014&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMapAdapter.java
(added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMapAdapter.java
Thu Feb 28 07:42:02 2008
@@ -0,0 +1,50 @@
+/**
+ * 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 demo.hw.server;
+
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+public class IntegerUserMapAdapter extends XmlAdapter<IntegerUserMap, Map<Integer,
User>> {
+    public IntegerUserMap marshal(Map<Integer, User> v) throws Exception {
+        IntegerUserMap map = new IntegerUserMap();
+        for (Map.Entry<Integer, User> e : v.entrySet()) { 
+            IntegerUserMap.IntegerUserEntry iue = new IntegerUserMap.IntegerUserEntry();
+            iue.setUser(e.getValue());
+            iue.setId(e.getKey());
+            map.getEntries().add(iue);
+        }
+        return map;
+    }
+
+    public Map<Integer, User> unmarshal(IntegerUserMap v) throws Exception {
+        Map<Integer, User> map = new LinkedHashMap<Integer, User>();
+        for (IntegerUserMap.IntegerUserEntry e : v.getEntries()) {
+            map.put(e.getId(), e.getUser());
+        }
+        return map;
+    }
+
+}
+

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMapAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/IntegerUserMapAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message