dkulp wrote:
>
>
> It would most likely be something like:
>
> public class CollectionOfHashtableType{
> List<MyHashtable> listHashtable;
> }
> public class MyHashtable {
> List<MyHashPair> listHashtable;
> }
> public class MyHashPair {
> String key;
> String value;
> }
>
> Dan
>
>
> On Thursday 25 March 2010 1:15:29 am chengy wrote:
>> dkulp wrote:
>> > On Wednesday 24 March 2010 9:38:14 am chengy wrote:
>> >> Is it possible to adapter a List<Hashtable<String, String>> type??I
>> try
>> >> some way,but always throws Unmarshalling Error
>> >>
>> >> java method:
>> >> String sayHi2(@XmlJavaTypeAdapter(HashtableAdapter.class)
>> >> List<Hashtable<String, String>> list);
>> >>
>> >> Below is not correct:
>> >> public class HashtableAdapter extends XmlAdapter<HashtableType,
>> >> Hashtable<String, String>> {
>> >> ...
>> >> }
>> >
>> > I think the XmlAdapter would have to be for the entire parameter.
>> Like
>> > XmlAdapter<CollectionOfHashtableType, List<Hashtable<String, String>>
>> or
>> > similar.
>>
>> I think so.XmlAdapter<CollectionOfHashtableType, List<Hashtable<String,
>> String>> .But I dont know how to implement CollectionOfHashtableType,In
>> my
>> opinion,It may like this:
>>
>> public class CollectionOfHashtableType{
>> List<MyHashtableExtendsHashtable<String, String>>
>> listHashtable;//how
>> to ???
>> }
>>
>> @XmlJavaTypeAdapter
>> public class MyHashtableExtendsHashtable{
>> List<HashtableEntryPair> listHashtablePair;
>> }
>>
>> But it seems not correct, so any suggestion ?
>
> --
> Daniel Kulp
> [email protected]
> http://dankulp.com/blog
>
>
When,invoke form client,I get a exception.Kulp, Can you find something
wrong:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException:
Unmarshalling Error: java.lang.IllegalArgumentException: Can not set
java.util.Hashtable field cxf225.server.jaxws_asm.SayHi2.arg0 to
java.util.Vector
public static void main(String[] args) throws Exception {
HelloWorldService s = new HelloWorldService();
CollectionOfHashtableType collectionOfHashtableType = new
CollectionOfHashtableType();
HashtableType hashtableType = new HashtableType();
HashtableEntryType hashtableEntryType = new HashtableEntryType();
hashtableEntryType.setKey("key");
hashtableEntryType.setValue("val");
hashtableType.getEntry().add(hashtableEntryType);
collectionOfHashtableType.getHashtableList().add(hashtableType);
System.out.println(s.getHelloWorldPort().sayHi2(collectionOfHashtableType));
}
package cxf225.server;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public class Server {
protected Server() throws Exception {
HelloWorldImpl helloworldImpl = new HelloWorldImpl();
JaxWsServerFactoryBean svrFactory = new
JaxWsServerFactoryBean();
svrFactory.setServiceClass(HelloWorld.class);
svrFactory.setAddress("http://localhost/Hello");
svrFactory.setServiceBean(helloworldImpl);
svrFactory.create();
}
public static void main(String args[]) throws Exception {
new Server();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.exit(0);
}
}
package cxf225.server;
import java.util.Hashtable;
import java.util.Vector;
import javax.jws.WebService;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@WebService
public interface HelloWorld {
String
sayHi2(@XmlJavaTypeAdapter(CollectionOfHashtableTypeAdapter.class)
Vector<Hashtable<String, String>> m);
}
package cxf225.server;
import java.util.Hashtable;
import java.util.Vector;
import javax.jws.WebService;
@WebService
public class HelloWorldImpl implements HelloWorld {
public String sayHi2(Vector<Hashtable<String, String>> m) {
return m.toString();
}
}
package cxf225.server;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import cxf225.server.HashtableType.HashtableEntryType;
public class CollectionOfHashtableTypeAdapter extends
XmlAdapter<CollectionOfHashtableType, Vector<Hashtable<String, String>>> {
public CollectionOfHashtableType marshal(Vector<Hashtable<String,
String>>
v) throws Exception {
CollectionOfHashtableType collectionOfHashtableType = new
CollectionOfHashtableType();
for (int i = 0; i < v.size(); i++) {
Hashtable<String, String> h = v.get(i);
HashtableType hashtableType = new HashtableType();
for (Iterator<String> it = h.keySet().iterator();
it.hasNext();) {
HashtableEntryType hashtableEntryType = new
HashtableEntryType();
hashtableEntryType.key = it.next();
hashtableEntryType.value =
h.get(hashtableEntryType.key);
hashtableType.getEntry().add(hashtableEntryType);
}
collectionOfHashtableType.hashtableList.add(hashtableType);
}
return collectionOfHashtableType;
}
public Vector<Hashtable<String, String>>
unmarshal(CollectionOfHashtableType v) throws Exception {
Vector<Hashtable<String, String>> vector = new
Vector<Hashtable<String,
String>>();
for (int i = 0; i < v.hashtableList.size(); i++) {
HashtableType hashtableType = v.hashtableList.get(i);
Hashtable h = new Hashtable();
for (int j = 0; j < hashtableType.getEntry().size();
j++) {
HashtableEntryType hashtableEntryType =
hashtableType.getEntry().get(j);
h.put(hashtableEntryType.key,
hashtableEntryType.value);
}
vector.add(h);
}
return vector;
}
}
package cxf225.server;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
@XmlType(name = "HashtableType")
@XmlAccessorType(XmlAccessType.FIELD)
public class HashtableType {
List<HashtableEntryType> entry;
public List<HashtableEntryType> getEntry() {
return entry;
}
public void setEntry(List<HashtableEntryType> entry) {
this.entry = entry;
}
@XmlType(name = "HashtableEntryType")
@XmlAccessorType(XmlAccessType.FIELD)
static class HashtableEntryType {
public String key;
public String value;
}
}
--
View this message in context:
http://old.nabble.com/Is-it-possible-to-adapter-a-List%3CHashtable%3CString%2C-String%3E%3E-type--tp28015118p28037976.html
Sent from the cxf-user mailing list archive at Nabble.com.