In our application, we need to examine the XML elements according to
their schema.

For instance, given an object, we need to identify which of its
attributes are required and which are not. Currently, we're doing the
following, where 'catClass' is the object whose attributes we want to
find.

   /**
    * Give a class in Castor's XML binding, return the matching
descriptor class
    */
   static Class getDescriptorClass(Class catClass) {
       // as of Castor 1.1, descriptor classes are in subpackage "descriptor"
       try {
           String descClass = catClass.getPackage().getName()
               + ".descriptors."
               + catClass.getName().replaceFirst(".*\\.", "") + "Descriptor";
           return Class.forName(descClass);

       } catch (ClassNotFoundException cne) {
           cne.printStackTrace();
       }
       return null;
   }

Then we create an object of the descriptor class of type
XMLClassDescriptor, and iterate over its XMLFieldDescriptors.

This is obviously ugly; and incidentally had to be rewritten when we
upgraded from 1.0.5 to 1.1 because the Descriptor classes were moved
in the package hierarchy.

My question: is there another way to examine, at runtime, a bean's
descriptor given only a reference to the bean?  If not, would it be
possible to add a "getDescriptor()" method to each bean to retrieve
the descriptor, or some other means to do that?  "getDescriptor()" is
probably not a good idea since it would conflict with a "descriptor"
property, so either call it something else or provide a static method
maybe to map beans to the descriptor classes. It could be a build
option as well.

- Godmar

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to