[jboss-user] [JBoss Web Services Users] - Re: Problem of polymorphism of JBoss WebService

xiangyingbing do-not-reply at jboss.com
Wed Nov 4 05:13:21 EST 2009


package com.ybxiang.ejbws;
  | 
  | import java.util.ArrayList;
  | import java.util.Iterator;
  | 
  | import javax.jws.WebMethod;
  | 
  | public interface EJBWebServiceInterface {
  | 	 public void passParameter1(String s);
  | 	 public void passParameter2(Animal a);
  | 	 public void passParameter3(Human h);	 
  | 	 public void passParameter4(ArrayList<Animal> lst);	 
  | 	 public ArrayList<? extends Animal> returnSomething1(int type);
  | }
  | 
  | 
  | 
  | 
  | 
  | package com.ybxiang.ejbws;
  | 
  | import java.util.ArrayList;
  | import java.util.Iterator;
  | 
  | import javax.ejb.Stateless;
  | import javax.jws.WebMethod;
  | import javax.jws.WebService;
  | import javax.xml.bind.annotation.XmlSeeAlso;
  | 
  | import javax.jws.soap.SOAPBinding;
  | 
  | @Stateless
  | @WebService
  | //@**XmlSeeAlso({Animal.class, Human.class})// Here i tried too!
  | public class EJBWebServiceBean implements EJBWebServiceInterface{
  | 	 @WebMethod
  | 	 public void passParameter1(String s){
  | 		 System.out.println("------------String is got:"+s);
  | 	 }
  | 	 @WebMethod
  | 	 public void passParameter2(Animal a){
  | 		 System.out.println("------------Animal is got:"+a);
  | 		 if(a instanceof Human){
  | 			 System.out.println("************* It's realy human!!! *************"); 
  | 		 }	 
  | 	 }
  | 	 @WebMethod
  | 	 public void passParameter3(Human h){
  | 		 System.out.println("------------Human is got, name:"+h.getName()+", email:"+h.getEmail());
  | 	 }
  | 	 
  | 	 @WebMethod
  | 	 public void passParameter4(ArrayList<Animal> lst){
  | 		 System.out.println("------------ArrayList<Animal> is got:");
  | 		 if(lst!=null){
  | 			 Iterator<Animal> it = lst.iterator();
  | 			 Animal a = it.next();
  | 			 if(a instanceof Human){
  | 				 System.out.println("One human is got:"+((Human)a)); 
  | 			 }else{
  | 				 System.out.println("One Animal is got:"+a); 
  | 			 }
  | 		 }else{
  | 			 System.out.println("------------List is null.");
  | 		 } 
  | 	 }	 
  | 	 
  | 	 @WebMethod
  | 	 public ArrayList<? extends Animal> returnSomething1(int type){
  | 		 if(type==1){
  | 			 ArrayList<Animal> aa = new ArrayList<Animal>();
  | 			 {
  | 				 Animal animal1 = new Animal();
  | 				 animal1.setName("Animal.1");
  | 				 animal1.setAge(new Long(1));
  | 				 aa.add(animal1);
  | 			 }
  | 			 {
  | 				 Animal animal2 = new Animal();
  | 				 animal2.setName("Animal.2");
  | 				 animal2.setAge(new Long(2));
  | 				 aa.add(animal2);
  | 			 }	
  | 			 return aa;
  | 		 }else{
  | 			 ArrayList<Human> bb = new ArrayList<Human>();
  | 			 {
  | 				 Human human1 = new Human();
  | 				 human1.setName("Human.1");
  | 				 human1.setAge(new Long(1));
  | 				 bb.add(human1);
  | 			 }
  | 			 {
  | 				 Human human2 = new Human();
  | 				 human2.setName("Human.2");
  | 				 human2.setAge(new Long(2));
  | 				 bb.add(human2);
  | 			 }	
  | 			 return bb;
  | 		 }
  | 	 }
  | 	 
  | 	 
  | }
  | 

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4263901#4263901

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4263901



More information about the jboss-user mailing list