2012-11-05 40 views
1

我想元帥延伸主題到XML類,代碼如下:用JAXB編組活動對象?

@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.

如果我理解這個正確它延伸線程的事實會導致這個問題,但我沒有看到網絡上的解決方案。

有沒有人知道解決方案或解決此問題,除了使該類實現可運行的對象?

回答

1

備註:我是EclipseLink JAXB (MOXy)的領導者和JAXB (JSR-222)專家組的成員。

如果您使用MOXy作爲您的JAXB提供者,那麼您可以按原樣使用您的TransitionXML類。這是因爲MOXy不會嘗試爲javajavax包(例如java.lang.Thread)中的類創建元數據。

您可以從以下位置獲得莫西二進制:

要指定莫西爲您的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 
+0

我忘了提及我正在使用Netbeans,有什麼方法可以將Moxy添加到它,插件也許? –