> This code does not work because the classloader is different than the
> servlet class loader.  The "Class home = Class.forName(homeClassName);"
> line fails with "Class.forName() failed: java.lang.ClassNotFoundException:
> cool.models.coop07.java.S_STRESS_31KpsHome".
> This same line works in the servlet.

I thought this would be equivalent, but Class.forName doesn't use the
context class loader. Instead, I should directly use the context class
loader to load the home interface ...

I re-read the J2EE 1.3 PFD spec, and I mistakenly interpreted paragraph
5.3.3 as things I had to enforce.

> Actually, I do not think the test of class type returned is necessary.
> When it is eliminated, the servlet will get an exception when casting the
> remote object to the home interface anyway (assuming some type of
problem).
>  Otherwise, it works and less code is executed.
> Also, if this were an LDAP/IIOP class, ordinary class casting will not
> work, the servlet would be using "PortableRemoteObject.narrow(...)"
> instead.

True.

> So, my suggestion is to erase lines:
> >   +                String homeClassName = ref.getClassName();
> >   +                Class home = Class.forName(homeClassName);
> >   +                if (home.isInstance(beanObj)) {
> >   +                } else {
> >   +                    throw new NamingException
> >   +                        ("Bean of type " +
beanObj.getClass().getName()
> >   +                         + " doesn't implement home interface "
> >   +                         + home.getName());
> >   +                }
> And leave only line:
> >   +                return beanObj;

Ok.

Remy

Reply via email to