<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.28.3">
</HEAD>
<BODY>
Hello,<BR>
<BR>
I've done some prototyping with Geotoolkit in order to eventually develop a CSW client application.<BR>
First, my goal is to generate ISO 19115 XML data from Java objects that I would populate.<BR>
My initial, basic, tests went fine, no problem.<BR>
<BR>
Then I tried to follow the advice explained on <<A HREF="http://www.geotoolkit.org/modules/metadata/faq.html">http://www.geotoolkit.org/modules/metadata/faq.html</A>>, to use a proxy, instead of implementing completely all the interfaces.<BR>
Here's some snippet of code that fails : <BR>
<BR>
<PRE>
[...]
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);
</PRE>
<BR>
<PRE>
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)
</PRE>
<BR>
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 :-)<BR>
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.<BR>
<BR>
<BR>
Then, I have another "issue" with the marshaller, or at least, a question : how can I return some DataIdentification items from Metadata::getIdentificationInfo() ?<BR>
Let's say that the implementation looks something like:<BR>
<BR>
<PRE>
@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;
}
</PRE>
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 :-)<BR>
<BR>
Thanks for your help!<BR>
<BR>
-- <BR>
Damiano ALBANI
</BODY>
</HTML>