users@jaxb.java.net

problems generating schema with XmlJavaTypeAdapter

From: Jason Corbett <jasoncorbett_at_gmail.com>
Date: Sun, 19 Nov 2006 17:02:40 -0700

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:

[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] ^
[schemagen] Problem encountered during annotation processing;
[schemagen] see stacktrace below for more information.
[schemagen] java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException
[schemagen] at
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getClassValue(
InlineAnnotationReaderImpl.java:107)
[schemagen] at
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getClassValue(
InlineAnnotationReaderImpl.java:26)
[schemagen] at com.sun.xml.bind.v2.model.core.Adapter.<init>(Adapter.java
:43)
[schemagen] at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.<init>(
PropertyInfoImpl.java:98)
[schemagen] at com.sun.xml.bind.v2.model.impl.ERPropertyInfoImpl.<init>(
ERPropertyInfoImpl.java:17)
[schemagen] at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl
.<init>(ElementPropertyInfoImpl.java:60)
[schemagen] at
com.sun.xml.bind.v2.model.impl.ClassInfoImpl.createElementProperty(
ClassInfoImpl.java:821)
[schemagen] at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.addProperty(
ClassInfoImpl.java:776)
[schemagen] at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getProperties(
ClassInfoImpl.java:266)
[schemagen] at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(
ModelBuilder.java:127)
[schemagen] at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(
ModelBuilder.java:189)
[schemagen] at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(
ModelBuilder.java:204)
[schemagen] at com.sun.tools.xjc.api.impl.j2s.JavaCompilerImpl.bind(
JavaCompilerImpl.java:54)
[schemagen] at com.sun.tools.jxc.apt.SchemaGenerator$1.process(
SchemaGenerator.java:73)
[schemagen] at
com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process
(AnnotationProcessors.java:60)
[schemagen] at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
[schemagen] at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java
:448)
[schemagen] at com.sun.tools.apt.main.Main.compile(Main.java:1075)
[schemagen] at com.sun.tools.apt.main.Main.compile(Main.java:938)
[schemagen] at com.sun.tools.apt.Main.processing(Main.java:95)
[schemagen] at com.sun.tools.apt.Main.process(Main.java:85)
[schemagen] at com.sun.tools.apt.Main.process(Main.java:67)
[schemagen] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[schemagen] at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
[schemagen] at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
[schemagen] at java.lang.reflect.Method.invoke(Method.java:585)
[schemagen] at com.sun.tools.jxc.AptBasedTask$InternalAptAdapter.execute(
AptBasedTask.java:61)
[schemagen] at com.sun.tools.jxc.AptBasedTask.compile(AptBasedTask.java:108)
[schemagen] at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:757)
[schemagen] at org.apache.tools.ant.UnknownElement.execute(
UnknownElement.java:275)
[schemagen] at org.apache.tools.ant.Task.perform(Task.java:364)
[schemagen] at org.apache.tools.ant.Target.execute(Target.java:341)
[schemagen] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[schemagen] at org.apache.tools.ant.Project.executeSortedTargets(
Project.java:1216)
[schemagen] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
[schemagen] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(
DefaultExecutor.java:40)
[schemagen] at
org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets
(EclipseDefaultExecutor.java:32)
[schemagen] at org.apache.tools.ant.Project.executeTargets(Project.java
:1068)
[schemagen] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(
InternalAntRunner.java:423)
[schemagen] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main
(InternalAntRunner.java:137)
[schemagen] Caused by: java.lang.reflect.InvocationTargetException
[schemagen] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[schemagen] at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
[schemagen] at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
[schemagen] at java.lang.reflect.Method.invoke(Method.java:585)
[schemagen] at
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getClassValue(
InlineAnnotationReaderImpl.java:96)
[schemagen] ... 39 more
[schemagen] Caused by: java.lang.annotation.AnnotationTypeMismatchException:
Incorrectly typed data found for annotation element public abstract
java.lang.Class javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.value()
(Found data of type java.lang.Class<? extends
javax.xml.bind.annotation.adapters.XmlAdapter>)
[schemagen] at
com.sun.tools.apt.mirror.declaration.AnnotationProxyMaker$ValueVisitor$1
.<init>(AnnotationProxyMaker.java:239)
[schemagen] at
com.sun.tools.apt.mirror.declaration.AnnotationProxyMaker$ValueVisitor.typeMismatch
(AnnotationProxyMaker.java:238)
[schemagen] at
com.sun.tools.apt.mirror.declaration.AnnotationProxyMaker$ValueVisitor.getValue
(AnnotationProxyMaker.java:151)
[schemagen] at
com.sun.tools.apt.mirror.declaration.AnnotationProxyMaker.generateValue(
AnnotationProxyMaker.java:125)
[schemagen] at
com.sun.tools.apt.mirror.declaration.AnnotationProxyMaker.getAllReflectedValues
(AnnotationProxyMaker.java:81)
[schemagen] at
com.sun.tools.apt.mirror.declaration.AnnotationProxyMaker.generateAnnotation
(AnnotationProxyMaker.java:66)
[schemagen] at
com.sun.tools.apt.mirror.declaration.AnnotationProxyMaker.generateAnnotation
(AnnotationProxyMaker.java:57)
[schemagen] at
com.sun.tools.apt.mirror.declaration.DeclarationImpl.getAnnotation(
DeclarationImpl.java:123)
[schemagen] at
com.sun.tools.apt.mirror.declaration.DeclarationImpl.getAnnotation(
DeclarationImpl.java:111)
[schemagen] at
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getFieldAnnotation(
InlineAnnotationReaderImpl.java:38)
[schemagen] at
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getFieldAnnotation(
InlineAnnotationReaderImpl.java:26)
[schemagen] at
com.sun.xml.bind.v2.model.impl.FieldPropertySeed.readAnnotation(
FieldPropertySeed.java:24)
[schemagen] at
com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.getApplicableAdapter(
PropertyInfoImpl.java:152)
[schemagen] at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.<init>(
PropertyInfoImpl.java:88)
[schemagen] ... 36 more

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