没有ObjectFactory和@XmlElementDecl [英] There's no ObjectFactory with an @XmlElementDecl
问题描述
导致:java.security.PrivilegedActionException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:1计数
IllegalAnnotationExceptions对于元素
{http:// www没有带
@XmlElementDecl的ObjectFactory .w3.org / 2004/08 / XOP /包括}包含。
此问题与以下位置有关:
位于protected java.util.List ru.gosuslugi.smev.rev120315.ReferenceType.content
位于ru.gosuslugi.smev.rev120315.ReferenceType
at public javax.xml.bind.JAXBElement ru.gosuslugi.smev.rev120315.ObjectFactory.createReference(ru.gosuslugi.smev.rev120315.ReferenceType)
at ru.gosuslugi.smev.rev120315.ObjectFactory
at protected java.util.List ru.gosuslugi.smev.rev120315.AppDataType.any
at ru.gosuslugi.smev.rev120315.AppDataType
at protected ru.gosuslugi.smev.rev120315.AppDataType ru .gosuslugi.smev.rev120315.MessageDataType.appData
at ru.gosuslugi.smev.rev120315.MessageDataType
at protected ru.gosuslugi.smev.rev120315.MessageDataType
ru.gosuslugi.smev.rev120315 .BaseMessageType.messageData
在ru.gosus
/w3/_2004/_08/xop/include/Include.java
//
//生成此文件由JavaTM Architecture for XML Binding(JAXB)参考实现,v2.2.4-2
//参见< a href =http://java.sun.com/xml/jaxb> http:/ /java.sun.com/xml/jaxb</a>
//在重新编译源模式时,对该文件的任何修改都将丢失。
//生成日期:2012.08.22 at 04:13:30 PM MSK
//
package org.w3._2004._08.xop.include ;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;
/ **
*< p>包含复杂类型的Java类。
*
*< p>以下模式片段指定了此类中包含的预期内容。
*
*< pre>
*& lt; complexType name =Include>
*& lt; complexContent>
*& lt; restriction base ={http://www.w3.org/2001/XMLSchema}anyType>
*& lt; sequence>
*& lt; any namespace ='## other'maxOccurs =unboundedminOccurs =0/>
*& lt; / sequence>
*& lt; attribute name =hrefuse =requiredtype ={http://www.w3.org/2001/XMLSchema}anyURI/>
*& lt; anyAttribute namespace ='## other'/>
*& lt; / restriction>
*& lt; / complexContent>
*& lt; / complexType>
*< / pre>
*
*
* /
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name =Include,propOrder = {
any
})
public class Include {
@XmlAnyElement(lax = true)
protected List< Object>任何;
@XmlAttribute(name =href,required = true)
@XmlSchemaType(name =anyURI)
protected String href;
@XmlAnyAttribute
私人地图< QName,String> otherAttributes = new HashMap< QName,String>();
/ **
*获取任何属性的值。
*
*< p>
*此访问器方法返回实时列表的引用,
*不是快照。因此,对
*返回列表所做的任何修改都将出现在JAXB对象内。
*这就是为什么没有< CODE>集合< / CODE>方法的任何财产。
*
*< p>
*例如,要添加新项目,请执行以下操作:
*< pre>
* getAny()。add(newItem);
*< / pre>
*
*
*< p>
*列表中允许使用以下类型的对象
* {@link Object}
*
*
* /
public List< ;对象> getAny(){
if(any == null){
any = new ArrayList< Object>();
}
返回this.any;
}
/ **
*获取href属性的值。
*
* @return
*可能的对象是
* {@link String}
*
* /
public String getHref() {
return href;
}
/ **
*设置href属性的值。
*
* @param value
*允许的对象是
* {@link String}
*
* /
public void setHref字符串值){
this.href = value;
}
/ **
*获取包含未绑定到此类上的任何类型属性的属性的映射。
*
*< p>
*映射由属性的名称和
*键值,该值是属性的字符串值。
*
*此方法返回的地图是实时的,您可以通过直接更新地图来添加新属性
*。由于这个设计,没有二传手。
*
*
* @return
*总是非空的
* /
public Map< QName,String> getOtherAttributes(){
return otherAttributes;
}
}
org / w3 / _2004 / _08 /xop/include/ObjectFactory.java
//
//这个文件是由JavaTM Architecture for XML绑定(JAXB)参考实现,v2.2.4-2
//请参阅< a href =http://java.sun.com/xml/jaxb> http://java.sun.com / XML / JAXB< / A>
//在重新编译源模式时,对该文件的任何修改都将丢失。
//生成日期:2012.08.22 at 04:13:30 PM MSK
//
package org.w3._2004._08.xop.include ;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
$ b / **
*此对象包含org.w3中生成的每个
* Java内容接口和Java元素接口
*的工厂方法._2004._08.xop.include包。
*< p> ObjectFactory允许您以编程方式
*为XML内容构建Java表示形式
*的新实例。 XML
*内容的Java表示可以由模式派生接口
*和表示模式
*类型定义,元素声明和模型
*组的绑定的类组成。每个工厂的方法都是在这个类中提供的
*。
*
* /
@XmlRegistry
public class ObjectFactory {
private final QName _Include_QNAME = new QName(http://www.w3 .org / 2004/08 / xop / include,Include);
/ **
*创建一个新的ObjectFactory,可用于为包创建模式派生类的新实例:org.w3._2004._08.xop.include
*
* /
public ObjectFactory(){
}
/ **
*创建一个{@link Include}的实例
*
* /
public include createInclude(){
return new Include();
}
/ **
*创建一个{@link JAXBElement}实例{@ code<} {@ link Include} {@ code>}}
*
* /
@XmlElementDecl(namespace =http://www.w3.org/2004/08/xop/include,name =Include)
public JAXBElement<包括(include)GT; createInclude(包含值){
返回新的JAXBElement< Include>(_ Include_QNAME,Include.class,null,value);
}
}
当从XML模式生成JAXB模型时,我总是建议使用生成的模型的包名称来创建 JAXBContext
。
JAXBContext jc = JAXBContext.newInstance(org.w3._2004._08.xop.include);
您不指定要部署到GlassFish的应用程序类型,但如果它是JAX -RS / Jersey应用程序我建议使用 ContextResolver
。这是一个标准机制,可以让您更好地控制如何创建 JAXBContext
。下面是一个例子。
import java.util。*;
import javax.ws.rs.Produces;
import javax.ws.rs.ext。*;
import javax.xml.bind。*;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
@Provider
@Produces({application / xml,application / json})
public class SampleContextResolver实现ContextResolver< JAXBContext> {
私人JAXBContext jc;
public SampleContextResolver(){
try {
jc = JAXBContext.newInstance(org.w3._2004._08.xop.include);
catch(JAXBException e){
抛出新的RuntimeException(e);
$ b $ public JAXBContext getContext(Class <?> clazz){
if(clazz.getPackage()。getName()。equals(org .w3._2004._08.xop.include)){
return jc;
}
返回null;
}
}
To deploy in GlassFish Server Open Source Edition 3.1.1 (build 12):
Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions There's no ObjectFactory with an @XmlElementDecl for the element {http://www.w3.org/2004/08/xop/include}Include. this problem is related to the following location: at protected java.util.List ru.gosuslugi.smev.rev120315.ReferenceType.content at ru.gosuslugi.smev.rev120315.ReferenceType at public javax.xml.bind.JAXBElement ru.gosuslugi.smev.rev120315.ObjectFactory.createReference(ru.gosuslugi.smev.rev120315.ReferenceType) at ru.gosuslugi.smev.rev120315.ObjectFactory at protected java.util.List ru.gosuslugi.smev.rev120315.AppDataType.any at ru.gosuslugi.smev.rev120315.AppDataType at protected ru.gosuslugi.smev.rev120315.AppDataType ru.gosuslugi.smev.rev120315.MessageDataType.appData at ru.gosuslugi.smev.rev120315.MessageDataType at protected ru.gosuslugi.smev.rev120315.MessageDataType ru.gosuslugi.smev.rev120315.BaseMessageType.messageData at ru.gosuslugi.smev.rev120315.BaseMessageType
Sources:
src/org/w3/_2004/_08/xop/include/Include.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.08.22 at 04:13:30 PM MSK
//
package org.w3._2004._08.xop.include;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;
/**
* <p>Java class for Include complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="Include">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <any namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* <attribute name="href" use="required" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
* <anyAttribute namespace='##other'/>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Include", propOrder = {
"any"
})
public class Include {
@XmlAnyElement(lax = true)
protected List<Object> any;
@XmlAttribute(name = "href", required = true)
@XmlSchemaType(name = "anyURI")
protected String href;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
/**
* Gets the value of the any property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the any property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getAny().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Object }
*
*
*/
public List<Object> getAny() {
if (any == null) {
any = new ArrayList<Object>();
}
return this.any;
}
/**
* Gets the value of the href property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getHref() {
return href;
}
/**
* Sets the value of the href property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setHref(String value) {
this.href = value;
}
/**
* Gets a map that contains attributes that aren't bound to any typed property on this class.
*
* <p>
* the map is keyed by the name of the attribute and
* the value is the string value of the attribute.
*
* the map returned by this method is live, and you can add new attribute
* by updating the map directly. Because of this design, there's no setter.
*
*
* @return
* always non-null
*/
public Map<QName, String> getOtherAttributes() {
return otherAttributes;
}
}
org/w3/_2004/_08/xop/include/ObjectFactory.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.08.22 at 04:13:30 PM MSK
//
package org.w3._2004._08.xop.include;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the org.w3._2004._08.xop.include package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _Include_QNAME = new QName("http://www.w3.org/2004/08/xop/include", "Include");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.w3._2004._08.xop.include
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Include }
*
*/
public Include createInclude() {
return new Include();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Include }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://www.w3.org/2004/08/xop/include", name = "Include")
public JAXBElement<Include> createInclude(Include value) {
return new JAXBElement<Include>(_Include_QNAME, Include.class, null, value);
}
}
When a JAXB model is generated from an XML schema, I always recommend creating the JAXBContext
using the package name of the generated model.
JAXBContext jc = JAXBContext.newInstance("org.w3._2004._08.xop.include");
You don't specify what kind of application you are deploying to GlassFish, but if it is a JAX-RS/Jersey application I would recommend the use of a ContextResolver
. This is a standard mechanism that gives you greater control over how your JAXBContext
is created. Below is an example.
import java.util.*;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.*;
import javax.xml.bind.*;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
@Provider
@Produces({"application/xml", "application/json"})
public class SampleContextResolver implements ContextResolver<JAXBContext> {
private JAXBContext jc;
public SampleContextResolver() {
try {
jc = JAXBContext.newInstance("org.w3._2004._08.xop.include");
} catch(JAXBException e) {
throw new RuntimeException(e);
}
}
public JAXBContext getContext(Class<?> clazz) {
if(clazz.getPackage().getName().equals("org.w3._2004._08.xop.include")) {
return jc;
}
return null;
}
}
这篇关于没有ObjectFactory和@XmlElementDecl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!