javax.xml.bind.Binder Java Examples

The following examples show how to use javax.xml.bind.Binder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecurityTokenServiceProvider.java    From steady with Apache License 2.0 5 votes vote down vote up
private Object convertToJAXBObject(Source source) throws Exception {
    //this is entirely to work around http://java.net/jira/browse/JAXB-909
    //if that bug is ever fixed and we can detect it, we can remove this 
    //complete and total HACK HACK HACK and replace with just:  
    //Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    //JAXBElement<?> jaxbElement = (JAXBElement<?>) unmarshaller.unmarshal(source);
    //return jaxbElement.getValue();
    
    Document d = StaxUtils.read(source);
    Binder<Node> binder = jaxbContext.createBinder();
    JAXBElement<?> jaxbElement = (JAXBElement<?>)binder.unmarshal(d);
    walkDom("", d.getDocumentElement(), binder, null);
    return jaxbElement.getValue();
}
 
Example #2
Source File: JAXBContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Binder<T> createBinder(Class<T> domType) {
    if(domType==Node.class)
        return (Binder<T>)createBinder();
    else
        return super.createBinder(domType);
}
 
Example #3
Source File: JAXBContextImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Binder<T> createBinder(Class<T> domType) {
    if(domType==Node.class)
        return (Binder<T>)createBinder();
    else
        return super.createBinder(domType);
}
 
Example #4
Source File: JAXBContextImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Binder<T> createBinder(Class<T> domType) {
    if(domType==Node.class)
        return (Binder<T>)createBinder();
    else
        return super.createBinder(domType);
}
 
Example #5
Source File: JAXBContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Binder<T> createBinder(Class<T> domType) {
    if(domType==Node.class)
        return (Binder<T>)createBinder();
    else
        return super.createBinder(domType);
}
 
Example #6
Source File: JAXBContextImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Binder<T> createBinder(Class<T> domType) {
    if(domType==Node.class)
        return (Binder<T>)createBinder();
    else
        return super.createBinder(domType);
}
 
Example #7
Source File: JAXBContextImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Binder<T> createBinder(Class<T> domType) {
    if(domType==Node.class)
        return (Binder<T>)createBinder();
    else
        return super.createBinder(domType);
}
 
Example #8
Source File: JAXBContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Binder<T> createBinder(Class<T> domType) {
    if(domType==Node.class)
        return (Binder<T>)createBinder();
    else
        return super.createBinder(domType);
}
 
Example #9
Source File: SecurityTokenServiceProvider.java    From steady with Apache License 2.0 5 votes vote down vote up
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
    }
}
 
Example #10
Source File: SecurityTokenServiceProvider.java    From steady with Apache License 2.0 5 votes vote down vote up
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
    }
}
 
Example #11
Source File: SecurityTokenServiceProvider.java    From steady with Apache License 2.0 5 votes vote down vote up
private Object convertToJAXBObject(Source source) throws Exception {
    //this is entirely to work around http://java.net/jira/browse/JAXB-909
    //if that bug is ever fixed and we can detect it, we can remove this 
    //complete and total HACK HACK HACK and replace with just:  
    //Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    //JAXBElement<?> jaxbElement = (JAXBElement<?>) unmarshaller.unmarshal(source);
    //return jaxbElement.getValue();
    
    Document d = StaxUtils.read(source);
    Binder<Node> binder = jaxbContext.createBinder();
    JAXBElement<?> jaxbElement = (JAXBElement<?>)binder.unmarshal(d);
    walkDom("", d.getDocumentElement(), binder, null);
    return jaxbElement.getValue();
}
 
Example #12
Source File: SecurityTokenServiceProvider.java    From steady with Apache License 2.0 5 votes vote down vote up
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
    }
}
 
Example #13
Source File: SecurityTokenServiceProvider.java    From steady with Apache License 2.0 5 votes vote down vote up
private Object convertToJAXBObject(Source source) throws Exception {
    //this is entirely to work around http://java.net/jira/browse/JAXB-909
    //if that bug is ever fixed and we can detect it, we can remove this 
    //complete and total HACK HACK HACK and replace with just:  
    //Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    //JAXBElement<?> jaxbElement = (JAXBElement<?>) unmarshaller.unmarshal(source);
    //return jaxbElement.getValue();
    
    Document d = StaxUtils.read(source);
    Binder<Node> binder = jaxbContext.createBinder();
    JAXBElement<?> jaxbElement = (JAXBElement<?>)binder.unmarshal(d);
    walkDom("", d.getDocumentElement(), binder, null);
    return jaxbElement.getValue();
}
 
Example #14
Source File: SecurityTokenServiceProvider.java    From steady with Apache License 2.0 5 votes vote down vote up
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
    }
}
 
Example #15
Source File: SecurityTokenServiceProvider.java    From steady with Apache License 2.0 5 votes vote down vote up
private Object convertToJAXBObject(Source source) throws Exception {
    //this is entirely to work around http://java.net/jira/browse/JAXB-909
    //if that bug is ever fixed and we can detect it, we can remove this 
    //complete and total HACK HACK HACK and replace with just:  
    //Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    //JAXBElement<?> jaxbElement = (JAXBElement<?>) unmarshaller.unmarshal(source);
    //return jaxbElement.getValue();
    
    Document d = StaxUtils.read(source);
    Binder<Node> binder = jaxbContext.createBinder();
    JAXBElement<?> jaxbElement = (JAXBElement<?>)binder.unmarshal(d);
    walkDom("", d.getDocumentElement(), binder, null);
    return jaxbElement.getValue();
}
 
Example #16
Source File: SecurityTokenServiceProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Object convertToJAXBObject(Source source) throws Exception {
    //this is entirely to work around http://java.net/jira/browse/JAXB-909
    //if that bug is ever fixed and we can detect it, we can remove this
    //complete and total HACK HACK HACK and replace with just:
    //Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    //JAXBElement<?> jaxbElement = (JAXBElement<?>) unmarshaller.unmarshal(source);
    //return jaxbElement.getValue();

    Document d = StaxUtils.read(source);
    Binder<Node> binder = jaxbContext.createBinder();
    JAXBElement<?> jaxbElement = (JAXBElement<?>)binder.unmarshal(d);
    walkDom("", d.getDocumentElement(), binder, null);
    return jaxbElement.getValue();
}
 
Example #17
Source File: JAXBContextImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> Binder<T> createBinder(Class<T> domType) {
    if(domType==Node.class)
        return (Binder<T>)createBinder();
    else
        return super.createBinder(domType);
}
 
Example #18
Source File: SecurityTokenServiceProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
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
    }
}
 
Example #19
Source File: JAXBContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Binder<Node> createBinder() {
    return new BinderImpl<Node>(this,new DOMScanner());
}
 
Example #20
Source File: JAXBContextImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Binder<Node> createBinder() {
    return new BinderImpl<Node>(this,new DOMScanner());
}
 
Example #21
Source File: JAXBContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Binder<Node> createBinder() {
    return new BinderImpl<Node>(this,new DOMScanner());
}
 
Example #22
Source File: JAXBContextImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Binder<Node> createBinder() {
    return new BinderImpl<Node>(this,new DOMScanner());
}
 
Example #23
Source File: JAXBContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Binder<Node> createBinder() {
    return new BinderImpl<Node>(this,new DOMScanner());
}
 
Example #24
Source File: JAXBContextImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Binder<Node> createBinder() {
    return new BinderImpl<Node>(this,new DOMScanner());
}
 
Example #25
Source File: JAXBContextImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Binder<Node> createBinder() {
    return new BinderImpl<Node>(this,new DOMScanner());
}
 
Example #26
Source File: JAXBContextImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Binder<Node> createBinder() {
    return new BinderImpl<Node>(this,new DOMScanner());
}