users@jaxb.java.net

Re: problems generating schema with XmlJavaTypeAdapter

From: Jason Corbett <jasoncorbett_at_gmail.com>
Date: Mon, 20 Nov 2006 15:53:50 -0700

Thank you, I knew it was something simple. I was using ant to build
everything, but forgot to put my build dir (containing the classes) in the
class path. I appreciate the response despite the simple error.

Jason Corbett

On 11/20/06, Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_sun.com> wrote:
>
> Jason Corbett wrote:
> > I tried searching the mailing list for this problem, but couldn't find
> > anything. I get the following error when using ant to generate the
> schema
> > from annotated java classes:
>
> APT isn't very good at error recovery, and so in general when you see
> some compilation errors like that, the schema generator that runs later
> could die a horrible death, like this NPE.
>
> But at least the first error message from apt is accurate. APT cannot
> find your ComputerConfigListToMapAdapter. You need to make that
> available to the compiler. I believe you can do so by either compiling
> this class and passing that to schemagen via -cp, or specify the source
> folder as -sourcepath. It's really the same as javac.
>
> > [schemagen] Generating schema from 4 source files
> > [schemagen] C:\Documents and Settings\Jason
> >
> Corbett\workspace\executioner\src\org\opentcdb\executioner\config\ExecutionerConfig.java:50:
> > cannot find symbol
> > [schemagen] symbol : class ComputerConfigListToMapAdapter
> > [schemagen] location: class
> > org.opentcdb.executioner.config.ExecutionerConfig
> > [schemagen] @XmlJavaTypeAdapter(ComputerConfigListToMapAdapter.class)
> > [schemagen] ^
>
> <snip/>
>
> >
> > I noticed the part about XmlJavaTypeAdapter, but as far as I can tell
> I'm
> > doing things really close to how the XmlAdapter example from the samples
> > directory works. This is probably a simple mistake, but I've been
> banging
> > my head against the wall for a while now. I've got the latest release
> of
> > 2.0 (2.0.4) and I've got java 1.5.0_9 on Windows XP. I'm posting
> portions
> > of the files mentioned in case anyone can help me:
> >
> > ExecutionerConfig: (there are getters and setters below this)
> > @XmlRootElement(name="ExecutionerConfig")
> > @XmlType(name="ExecutionerConfigType")
> > public class ExecutionerConfig
> > {
> > private URL tcdbURL;
> > private String tcdbUserName;
> > private String tcdbUserPassword;
> > @XmlJavaTypeAdapter(ComputerConfigListToMapAdapter.class)
> > private HashMap<String, ComputerConfig> Computers;
> >
> > /**
> > * Public empty constructor.
> > *
> > */
> > public ExecutionerConfig()
> > {
> > Computers = new HashMap<String, ComputerConfig>();
> > }
> >
> >
> > ComputerConfigListToMapAdapter:
> > import java.util.HashMap;
> > import java.util.List;
> >
> > import javax.xml.bind.annotation.adapters.XmlAdapter;
> >
> > /**
> > * @author Jason Corbett
> > *
> > */
> > public class ComputerConfigListToMapAdapter extends
> > XmlAdapter<ComputerConfigList, HashMap<String, ComputerConfig>>
> > {
> > /**
> > * Empty public constructor.
> > *
> > */
> > public ComputerConfigListToMapAdapter() {}
> >
> > /* (non-Javadoc)
> > * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(
> > java.lang.Object)
> > */
> > @Override
> > public ComputerConfigList marshal(HashMap<String, ComputerConfig>
> arg0)
> > throws Exception
> > {
> > ComputerConfigList retval = new ComputerConfigList();
> > List<ComputerConfig> configList = retval.getComputerconfig();
> > for(ComputerConfig config: arg0.values())
> > {
> > configList.add(config);
> > }
> > return retval;
> > }
> >
> > /* (non-Javadoc)
> > * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(
> > java.lang.Object)
> > */
> > @Override
> > public HashMap<String, ComputerConfig> unmarshal(ComputerConfigList
> > arg0) throws Exception
> > {
> > HashMap<String, ComputerConfig> configMap = new HashMap<String,
> > ComputerConfig>();
> > List<ComputerConfig> configList = arg0.getComputerconfig();
> > for(ComputerConfig config: configList)
> > {
> > configMap.put(config.getHostname(), config);
> > }
> > return configMap;
> > }
> >
> > }
> >
> > ComputerConfigList:
> > import java.util.List;
> > import java.util.Vector;
> >
> > import javax.xml.bind.annotation.XmlElement;
> > import javax.xml.bind.annotation.XmlRootElement;
> > import javax.xml.bind.annotation.XmlType;
> >
> > /**
> > * @author Jason Corbett
> > *
> > */
> > @XmlRootElement
> > @XmlType(name="ComputerConfigListType")
> > public class ComputerConfigList
> > {
> > /**
> > * List of ComputerConfigs.
> > */
> > @XmlElement(name="ComputerConfig")
> > private List<ComputerConfig> computerconfig;
> >
> > /**
> > * Create an empty ComputerConfigList.
> > *
> > */
> > public ComputerConfigList()
> > {
> > computerconfig = new Vector<ComputerConfig>();
> > }
> >
> >
> > Any help is greatly appreciated, let me know if you need any other
> > information to help. I'm terribly confused.
> > Jason Corbett
> >
>
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>
>
>