>>>>> "Alex" == Alex Paransky <[EMAIL PROTECTED]> writes:

    David> How do you have a method which returns a Collection (or array) of
    Alex> value
    Selvarajah> objects
    David> (non-primitives, user-defined)?
    David>
    David> I was able to write a method which returns a single value object,
    Alex> but I
    Selvarajah> can't
    David> figure out how to write a method which returns a Collection of
    Alex> them.
    David>
    David> Using JBoss, the method returned in the client without error, and
    Alex> it was a
    David> Collection, but when I got the Iterator and started stepping
    Alex> through it,
    Selvarajah> the
    David> first entry wasn't an object of my value object class, but of the
    Alex> class
    David> "$Proxy2".

    Selvarajah> Hi David,
    Selvarajah> make sure your VO implements serialaizable.( and also your
    Alex> collection class)
    Selvarajah> I am not sure about arrays. But I used Vector and it's
    Alex> worked with almost
    Selvarajah> all app servers including JBoss.( any other java.util.
    Alex> COLLECTION CLASSES
    Selvarajah> that implements io.serializable should also work)
    Selvarajah> I don't think you need any of these for primitives.

    Alex> I was using "Collection".  I just tried changing to "ArrayList", and it had
    Alex> no
    Alex> effect.

    Alex> Note that I appear to have no problem getting the object of the collection
    Alex> class, either "Collection" or "ArrayList", but when I try to pull an object
    Alex> out
    Alex> of the collection, it is of type "$Proxy2", and not my value object class.
    Alex> Also note that my value object class implements Serializable.

    Alex> Your value objects wouldn't by some strange chance be EJB entity objects, or
    Alex> remote implementation objects, would they?  How about a code snippet of your
    Alex> Value object definition, and the method which returns the value object to
    Alex> the client, and the client code which tries to access the value object.

Value object:
------------------
package com.intsoft.sgs.ejb;
import java.io.*;
public class RosterEntry implements Serializable
{
   public   String   studentSsn;
   public   String   grade;
   public   RosterEntry() {}
   public   RosterEntry(String studentSsn, String grade)
   {
      this.studentSsn   = studentSsn;
      this.grade        = grade;
   }
   public   String   getStudentSsn()   { return (studentSsn); }
   public   String   getGrade()        { return (grade); }
   public   void  setStudentSsn(String studentSsn)
   { this.studentSsn   = studentSsn; }
   public   void  setGrade(String grade)
   { this.grade   = grade; }
}
------------------

Method which returns the list of RosterEntry objects:
------------------
   public   ArrayList   getRoster() throws IllegalRosterAccessException
   {
      ArrayList   result   = null;
      try
      {
         InitialContext jndiContext = new InitialContext();
         Object         ref         =
            jndiContext.lookup("sgs/StudentClassGrade");
         StudentClassGradeHome   scgHome  =
            (StudentClassGradeHome) PortableRemoteObject.
            narrow(ref, StudentClassGradeHome.class);
         Collection  scgList  = scgHome.findByClassName(name);
         result   = new ArrayList(scgList);
      }
      catch (NamingException ex)
      {
         System.out.println(ex);
         ex.printStackTrace();
      }
      catch (RemoteException ex)
      {
         System.out.println(ex);
         ex.printStackTrace();
      }
      catch (FinderException ex)
      {
         System.out.println(ex);
         ex.printStackTrace();
      }
      return (result);
   }
------------------

Client code:
------------------
         Object      ref   = jndiContext.lookup("sgs/Class");
         ClassHome   home  =
            (ClassHome) PortableRemoteObject.narrow(ref, ClassHome.class);
         Collection  allClasses  = home.findAll();
         Object[] classes  = allClasses.toArray();

         for (int ctr = 0; ctr < classes.length; ++ ctr)
         {
            ClassRemote classRemote = (ClassRemote) classes[ctr];
            ArrayList   roster   = classRemote.getRoster();
------------------

--
===================================================================
David M. Karr          ; Best Consulting
[EMAIL PROTECTED]   ; Java/Unix/XML/C++/X ; BrainBench CJ12P (#12004)

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to