与编组JAXB活动对象?(Marshalling an active object with JAX

2019-10-17 08:38发布

我想元帅延伸主题到XML的代码如下一类:

@XmlRootElement
public class TransitionXML extends Thread {

ArcXML[] preArcs;
ArcXML[] postArcs;
int[] preArcTokens;
int[] postArcTokens;
int leastTime;
int longestTime;
String name;

//some methods 

//a lot of get-set

@Override
public void run() {
    while (true) {
        if (this.postTransition() & this.preTransition()) {
            //We take out the tokens.
            this.executePreTranstion();
            this.checkPreTransition();


            try {
                this.sleep(1000 * this.getTimeToPass());
            } catch (InterruptedException ex) {
                Logger.getLogger(TransitionXML.class.getName()).log(Level.SEVERE, null, ex);
            }

            //We see if we can put them in.
            if (this.postTransition()) {
                this.executePostTranstion();
                this.checkPostTransition();
            }

        } else {
            try {
                this.sleep(2000);
            } catch (InterruptedException ex) {
                Logger.getLogger(TransitionXML.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}


}

public TransitionXML()
{

}

}

}

这使我这个错误: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions java.lang.Thread$UncaughtExceptionHandler is an interface, and JAXB can't handle interfaces. ... java.lang.Thread$UncaughtExceptionHandler does not have a no-arg default constructor. com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions java.lang.Thread$UncaughtExceptionHandler is an interface, and JAXB can't handle interfaces. ... java.lang.Thread$UncaughtExceptionHandler does not have a no-arg default constructor.

如果我理解这一点正确的张女士它继承Thread的原因这个问题,但我还没有看到网上的解决方案。

有谁知道一个解决方案或变通为此,除了使类实现Runnable目的?

Answer 1:

注:我是的EclipseLink JAXB(莫西)领导和成员JAXB(JSR-222)专家小组。

如果您使用的莫西为您的JAXB提供者,那么你可以用你的TransitionXML类原样。 这是因为莫西将不会试图在一个类创建元数据javajavax包,如java.lang.Thread

您可以从以下位置莫西二:

  • http://www.eclipse.org/eclipselink/downloads/

要指定莫西为您的JAXB提供你需要把一个名为jaxb.properties在同一个包为您的域类具有以下条目(请参阅: http://blog.bdoughan.com/2011/05/specifying-eclipselink- MOXY-AS-your.html )。

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory


文章来源: Marshalling an active object with JAXB?