下面列出了怎么用javax.xml.bind.annotation.XmlAnyElement的API类实例代码及写法,或者点击链接到github查看源代码。
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
/**
* Returns the code list wrapped in a JAXB element, or {@code null} if the {@link #text} is not a wrapper for
* a code list. Only one of {@link #getValue()} and {@code getCodeList()} should return a non-null value.
*
* <div class="note"><b>Note:</b>
* we have to rely on a somewhat complicated mechanism because the code lists implementations in GeoAPI
* do not have JAXB annotations. If those annotations are added in a future GeoAPI implementation, then
* we could replace this mechanism by a simple property annotated with {@code XmlElementRef}.</div>
*
* @since 0.7
*/
@XmlAnyElement
@Workaround(library = "GeoAPI", version = "3.0")
private Object getCodeList() {
if (type != ENUM) {
return null;
}
final CodeList<?> code = Types.forCodeTitle(text);
final String name = Types.getListName(code);
/*
* The namespace has have various value like CIT, SRV, MDQ, MRI, MSR, LAN, etc.
* The real namespace is declared in the @XmlElement annotation of the getElement
* method in the JAXB adapter. We could use reflection, but we do not in order to
* avoid potential class loading issue and also because not all CodeList are in the
* same package.
*/
String namespace = Namespaces.guessForType(name);
if (namespace == null) {
namespace = XMLConstants.NULL_NS_URI;
}
return new JAXBElement<>(new QName(namespace, name), CodeListUID.class,
new CodeListUID(Context.current(), code));
}
private void walkDom(String pfx, Element element, Binder<Node> binder, Object parent) {
try {
Object o = binder.getJAXBNode(element);
if (o instanceof JAXBElement) {
o = ((JAXBElement<?>)o).getValue();
}
//System.out.println(pfx + DOMUtils.getElementQName(element) + " -> "
// + (o == null ? "null" : o.getClass()));
if (o == null && parent != null) {
// if it's not able to bind to an object, it's possibly an xsd:any
// we'll check the parent for the standard "any" and replace with
// the original element.
Field f = parent.getClass().getDeclaredField("any");
if (f.getAnnotation(XmlAnyElement.class) != null) {
Object old = ReflectionUtil.setAccessible(f).get(parent);
if (old instanceof Element
&& DOMUtils.getElementQName(element).equals(DOMUtils.getElementQName((Element)old))) {
ReflectionUtil.setAccessible(f).set(parent, element);
}
}
}
if (o == null) {
return;
}
Node nd = element.getFirstChild();
while (nd != null) {
if (nd instanceof Element) {
walkDom(pfx + " ", (Element)nd, binder, o);
}
nd = nd.getNextSibling();
}
} catch (Throwable t) {
//ignore -this is a complete hack anyway
}
}
private void walkDom(String pfx, Element element, Binder<Node> binder, Object parent) {
try {
Object o = binder.getJAXBNode(element);
if (o instanceof JAXBElement) {
o = ((JAXBElement<?>)o).getValue();
}
//System.out.println(pfx + DOMUtils.getElementQName(element) + " -> "
// + (o == null ? "null" : o.getClass()));
if (o == null && parent != null) {
// if it's not able to bind to an object, it's possibly an xsd:any
// we'll check the parent for the standard "any" and replace with
// the original element.
Field f = parent.getClass().getDeclaredField("any");
if (f.getAnnotation(XmlAnyElement.class) != null) {
Object old = ReflectionUtil.setAccessible(f).get(parent);
if (old instanceof Element
&& DOMUtils.getElementQName(element).equals(DOMUtils.getElementQName((Element)old))) {
ReflectionUtil.setAccessible(f).set(parent, element);
}
}
}
if (o == null) {
return;
}
Node nd = element.getFirstChild();
while (nd != null) {
if (nd instanceof Element) {
walkDom(pfx + " ", (Element)nd, binder, o);
}
nd = nd.getNextSibling();
}
} catch (Throwable t) {
//ignore -this is a complete hack anyway
}
}
private void walkDom(String pfx, Element element, Binder<Node> binder, Object parent) {
try {
Object o = binder.getJAXBNode(element);
if (o instanceof JAXBElement) {
o = ((JAXBElement<?>)o).getValue();
}
//System.out.println(pfx + DOMUtils.getElementQName(element) + " -> "
// + (o == null ? "null" : o.getClass()));
if (o == null && parent != null) {
// if it's not able to bind to an object, it's possibly an xsd:any
// we'll check the parent for the standard "any" and replace with
// the original element.
Field f = parent.getClass().getDeclaredField("any");
if (f.getAnnotation(XmlAnyElement.class) != null) {
Object old = ReflectionUtil.setAccessible(f).get(parent);
if (old instanceof Element
&& DOMUtils.getElementQName(element).equals(DOMUtils.getElementQName((Element)old))) {
ReflectionUtil.setAccessible(f).set(parent, element);
}
}
}
if (o == null) {
return;
}
Node nd = element.getFirstChild();
while (nd != null) {
if (nd instanceof Element) {
walkDom(pfx + " ", (Element)nd, binder, o);
}
nd = nd.getNextSibling();
}
} catch (Throwable t) {
//ignore -this is a complete hack anyway
}
}
private void walkDom(String pfx, Element element, Binder<Node> binder, Object parent) {
try {
Object o = binder.getJAXBNode(element);
if (o instanceof JAXBElement) {
o = ((JAXBElement<?>)o).getValue();
}
//System.out.println(pfx + DOMUtils.getElementQName(element) + " -> "
// + (o == null ? "null" : o.getClass()));
if (o == null && parent != null) {
// if it's not able to bind to an object, it's possibly an xsd:any
// we'll check the parent for the standard "any" and replace with
// the original element.
Field f = parent.getClass().getDeclaredField("any");
if (f.getAnnotation(XmlAnyElement.class) != null) {
Object old = ReflectionUtil.setAccessible(f).get(parent);
if (old instanceof Element
&& DOMUtils.getElementQName(element).equals(DOMUtils.getElementQName((Element)old))) {
ReflectionUtil.setAccessible(f).set(parent, element);
}
}
}
if (o == null) {
return;
}
Node nd = element.getFirstChild();
while (nd != null) {
if (nd instanceof Element) {
walkDom(pfx + " ", (Element)nd, binder, o);
}
nd = nd.getNextSibling();
}
} catch (Throwable t) {
//ignore -this is a complete hack anyway
}
}
public void testXmlAnyElementLax() throws Exception {
final Field contentField = IssueJIIB10Type.class.getDeclaredField("content");
final XmlAnyElement xmlAnyElementAnnotation = contentField
.getAnnotation(XmlAnyElement.class);
Assert.assertTrue(xmlAnyElementAnnotation.lax());
}
private void renderFutureElementsField(JDefinedClass classModel) throws Exception {
JType collectionType = codeModel.parseType("java.util.Collection<org.w3c.dom.Element>");
JFieldVar field = classModel.field(JMod.PRIVATE | JMod.FINAL, collectionType, "_futureElements");
field.init(JExpr._null());
JAnnotationUse annotation = field.annotate(SuppressWarnings.class);
annotation.param("value", "unused");
field.annotate(XmlAnyElement.class);
}
private void walkDom(String pfx, Element element, Binder<Node> binder, Object parent) {
try {
Object o = binder.getJAXBNode(element);
if (o instanceof JAXBElement) {
o = ((JAXBElement<?>)o).getValue();
}
//System.out.println(pfx + DOMUtils.getElementQName(element) + " -> "
// + (o == null ? "null" : o.getClass()));
if (o == null && parent != null) {
// if it's not able to bind to an object, it's possibly an xsd:any
// we'll check the parent for the standard "any" and replace with
// the original element.
Field f = parent.getClass().getDeclaredField("any");
if (f.getAnnotation(XmlAnyElement.class) != null) {
Object old = ReflectionUtil.setAccessible(f).get(parent);
if (old instanceof Element
&& DOMUtils.getElementQName(element).equals(DOMUtils.getElementQName((Element)old))) {
ReflectionUtil.setAccessible(f).set(parent, element);
}
}
}
if (o == null) {
return;
}
Node nd = element.getFirstChild();
while (nd != null) {
if (nd instanceof Element) {
walkDom(pfx + " ", (Element)nd, binder, o);
}
nd = nd.getNextSibling();
}
} catch (Throwable t) {
//ignore -this is a complete hack anyway
}
}
@XmlAnyElement
public List<JAXBElement<GEffect>> getEffectsXml(){
List<JAXBElement<GEffect>> res = new LinkedList<JAXBElement<GEffect>>();
for(GEffect effect : effects){
res.add(new JAXBElement<GEffect>(new QName(effect.getEventType().toString()),GEffect.class, effect));
}
return res;
}
@XmlAnyElement
public List<JAXBElement<Integer>> getElements() {
return list;
}
@XmlAnyElement
public Object getDsXMLConfiguration() {
return dsXMLConfiguration;
}
@XmlAnyElement(value = FormatHandler.class,
lax = true)
public void setPayload(String payload) {
this.payload = payload;
}
@XmlAnyElement(lax = true)
public List<T> getInstances() {
return instances;
}
@XmlAnyElement
public List<Element> getEntries() {
return entries;
}
/**
* Get the the prop element from a propstat response.
* @return the property element
*/
@XmlAnyElement
public List<Element> getNodes() {
return nodes;
}
@XmlElementWrapper(name="value-assist")
@XmlAnyElement
public List<Element> getValueAssistElement() {
return valueAssistElement;
}
@XmlAnyElement
public List<Element> getElements() {
return elements;
}
@XmlAnyElement
public List<Element> getElements() {
return elements;
}
@XmlAnyElement
public Element getElement() {
return element;
}
@XmlElementWrapper(name="value-assist")
@XmlAnyElement
public List<Element> getValueAssistElement() {
return valueAssistElement;
}
@XmlAnyElement
public Element getAttributeRulesElement() {
return attributeRulesElement;
}
@XmlAnyElement
public List<Element> getElements() {
return elements;
}