You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Collin Peters <ca...@gmail.com> on 2007/02/27 02:39:33 UTC

Nested complex types

Hello all,

I am trying to figure out how I can get nested types to work within
Axis2.  For example:

Object1.java
-------------------------------
package test;
import java.util.List;
public class Object1 {

    int objectID;
    List<Object2> details;

    public void setObjectID(int objectID){
        this.objectID= objectID;
    }
    public int getObjectID(){
        return objectID;
    }

	public List<Object2> getDetails() {
		return details;
	}
	public void setDetails(List<Object2> details) {
		this.details= details;
	}
}


Object2.java
-------------------------------
package test;
public class Object2 {

    int testID;

    public void setTestID(int testID){
        this.testID= testID;
    }
    public int getTestID(){
        return testID;
    }
}




So Object1 contains a List of Object2's.  My original error was this
"null rcl" but it seems that was a known issue and fixed via patch.  I
downloaded the nightlies and got past that error.  Everything actual
works until I try to grab an Object2 object on the server side out of
the Object1 List.

My service/server code looks like:
    public void saveObject(Object1 ob1){
    	System.out.println("TestService.java - saveObject");
    	System.out.println("ob1.objectID = " + ob1.getObjectID());
    	
    	List<Object2> details = ob1.getDetails();
    	System.out.println("Number of details = " + details.size());
    	
    	Object2 obj2 = details.get(0);
    	System.out.println("Details 1 # = " + obj2.getTestID());
    }


Client code looks like:
        Object1 obj1 = new Object1();

        obj1.setObjectID(15);

        Object2 obj2_1 = new Object2 ();
        obj2_1.setTestID(1);
        Object2 obj2_2 = new Object2 ();
        obj2_2.setTestID(2);

        List<Object2> details = new ArrayList<Object2>();
        details.add(obj2_1);
        details.add(obj2_2);

        obj1.setDetails(details);

        Object[] opArgs = new Object[] { obj1 };

        serviceClient.invokeRobust(opObject, opArgs);



The error that I am getting is in the server code:
Caused by: java.lang.ClassCastException:
org.apache.axiom.om.impl.llom.OMElementImpl

That is on the line: "Object2 obj2 = details.get(0);"

Before that it correctly outputs the count of the details.

Anybody know what the problem is?  Is there any good samples or
tutorials on this subject out there?

Regards,
Collin Peters

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Nested complex types

Posted by Deepal Jayasinghe <de...@opensource.lk>.
Hi Collin ;

The problem you have encounter is a know issue in Axis2, and I do not
think we will be fixing that for 1.2. Most of the core code in Axis2 is
based on JDK 1.5 and if you are going to use List inside your class ,
then there is no way to know the type of the list (in jDK 1.4). Therefor
it creates OMElement array.

To solve the issue , rather than keeping List , try to have Object2
array. So if you make your Object1 class as follows then everything will
work fine.

package test;
import java.util.List;
public class Object1 {

   int objectID;
   Object2 [] details;

   public void setObjectID(int objectID){
       this.objectID= objectID;
   }
   public int getObjectID(){
       return objectID;
   }

    public Object2 [] getDetails() {
        return details;
    }
    public void setDetails(Object2 [] details) {
        this.details= details;
    }
}

Thanks
Deepal

> Hello all,
>
> I am trying to figure out how I can get nested types to work within
> Axis2.  For example:
>
> Object1.java
> -------------------------------
> package test;
> import java.util.List;
> public class Object1 {
>
>    int objectID;
>    List<Object2> details;
>
>    public void setObjectID(int objectID){
>        this.objectID= objectID;
>    }
>    public int getObjectID(){
>        return objectID;
>    }
>
>     public List<Object2> getDetails() {
>         return details;
>     }
>     public void setDetails(List<Object2> details) {
>         this.details= details;
>     }
> }
>
>
> Object2.java
> -------------------------------
> package test;
> public class Object2 {
>
>    int testID;
>
>    public void setTestID(int testID){
>        this.testID= testID;
>    }
>    public int getTestID(){
>        return testID;
>    }
> }
>
>
>
>
> So Object1 contains a List of Object2's.  My original error was this
> "null rcl" but it seems that was a known issue and fixed via patch.  I
> downloaded the nightlies and got past that error.  Everything actual
> works until I try to grab an Object2 object on the server side out of
> the Object1 List.
>
> My service/server code looks like:
>    public void saveObject(Object1 ob1){
>        System.out.println("TestService.java - saveObject");
>        System.out.println("ob1.objectID = " + ob1.getObjectID());
>       
>        List<Object2> details = ob1.getDetails();
>        System.out.println("Number of details = " + details.size());
>       
>        Object2 obj2 = details.get(0);
>        System.out.println("Details 1 # = " + obj2.getTestID());
>    }
>
>
> Client code looks like:
>        Object1 obj1 = new Object1();
>
>        obj1.setObjectID(15);
>
>        Object2 obj2_1 = new Object2 ();
>        obj2_1.setTestID(1);
>        Object2 obj2_2 = new Object2 ();
>        obj2_2.setTestID(2);
>
>        List<Object2> details = new ArrayList<Object2>();
>        details.add(obj2_1);
>        details.add(obj2_2);
>
>        obj1.setDetails(details);
>
>        Object[] opArgs = new Object[] { obj1 };
>
>        serviceClient.invokeRobust(opObject, opArgs);
>
>
>
> The error that I am getting is in the server code:
> Caused by: java.lang.ClassCastException:
> org.apache.axiom.om.impl.llom.OMElementImpl
>
> That is on the line: "Object2 obj2 = details.get(0);"
>
> Before that it correctly outputs the count of the details.
>
> Anybody know what the problem is?  Is there any good samples or
> tutorials on this subject out there?
>
> Regards,
> Collin Peters
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
>

-- 
Thanks,
Deepal
................................................................
"The highest tower is built one brick at a time"



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org