[geotk] Issues with ISO 19115 XML marshaller

Damiano ALBANI damiano.albani at univ-nantes.fr
Fri Jul 23 11:32:16 EDT 2010


Hello,

I've done some prototyping with Geotoolkit in order to eventually
develop a CSW client application.
First, my goal is to generate ISO 19115 XML data from Java objects that
I would populate.
My initial, basic, tests went fine, no problem.

Then I tried to follow the advice explained on
<http://www.geotoolkit.org/modules/metadata/faq.html>, to use a proxy,
instead of implementing completely all the interfaces.
Here's some snippet of code that fails : 


[...]
import org.opengis.metadata.Metadata;
import org.geotoolkit.metadata.iso.DefaultMetadata;

InvocationHandler handler = new InvocationHandler() {
    @Override
    public Object invoke(Object arg0, Method arg1, Object[] arg2)
            throws Throwable {
        UML uml = arg1.getAnnotation(UML.class);
        if (uml != null) {
            String name = uml.identifier();
            System.out.println(name);
        }
        
        return null;
    }
};

DefaultMetadata d = new DefaultMetadata();

Metadata data =
    (Metadata) Proxy.newProxyInstance(d.getClass().getClassLoader(),
            new Class[] { Metadata.class },
            handler);       

MarshallerPool pool = new MarshallerPool(MarshallerPool.defaultClassesToBeBound());
Marshaller marshaller = pool.acquireMarshaller();
marshaller.marshal(data, System.out);
pool.release(marshaller);



Exception in thread "main" javax.xml.bind.JAXBException: class $Proxy0 nor any of its super class is known to this context.
	at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:554)
	at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:470)
	at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)
	at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)
	at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
	at org.geotoolkit.xml.PooledMarshaller.marshal(PooledMarshaller.java:120)
	at Test.test1(Test.java:667)
	at Test.main(Test.java:615)


I suppose that's due to the fact that I'm using the Metadata interface
instead of the DefaultMetadata class. But, as I'm no JAVA or JAXB
expert, I don't really know where I'm wrong :-)
That's not a blocking issue for me but I was wondering if you could
provide more information on how to use this proxy method.


Then, I have another "issue" with the marshaller, or at least, a
question : how can I return some DataIdentification items from
Metadata::getIdentificationInfo() ?
Let's say that the implementation looks something like:


@Override
public synchronized Collection<Identification> getIdentificationInfo() {
    Collection<Identification> identificationInfo
        = new ArrayList<Identification>();
    
    DataIdentification identification = new DataIdentification() {
         @Override
         public InternationalString getAbstract() {
            NameFactory factory = FactoryFinder.getNameFactory(null);
            Map<Locale, String> names = new HashMap<Locale, String>();
            names.put(Locale.ENGLISH, "Description");
            return factory.createInternationalString(names);
                }

        @Override
        public InternationalString getEnvironmentDescription() {
            NameFactory factory = FactoryFinder.getNameFactory(null);
            Map<Locale, String> names = new HashMap<Locale, String>();
            names.put(Locale.ENGLISH, "Environment");
            return factory.createInternationalString(names);
        }

        [...]
    };

    identificationInfo.add(identification);
    return identificationInfo;
}


It compiles and runs fine... except that the marshaller doesn't output
any DataIdentification-specific information, e.g. "environment
description". Whereas the "abstract information", from the the parent
Identification interface, is correctly present in the XML. Again, I
suppose that must surely require some Java "trick" that I don't know :-)

Thanks for your help!

-- 
Damiano ALBANI
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20100723/d563d966/attachment.html


More information about the Geotoolkit mailing list