Package javax.xml.bind

Examples of javax.xml.bind.JAXBElement


   
    private void doTestMixedContent(String data, boolean ignore, String fileName) throws Exception {
        InputStream is = getClass().getResourceAsStream(fileName);
        JAXBContext context = JAXBContext.newInstance(new Class[]{Books.class, Book.class});
        Unmarshaller um = context.createUnmarshaller();
        JAXBElement jaxbEl = um.unmarshal(new StreamSource(is), Books.class);
        JSONProvider p = new JSONProvider();
        p.setIgnoreMixedContent(ignore);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
       
        p.writeTo(jaxbEl, (Class)JAXBElement.class, JAXBElement.class, JAXBElement.class.getAnnotations(),
View Full Code Here


        if (null != toEpr) {
            ReferenceParametersType params = toEpr.getReferenceParameters();
            if (null != params) {
                for (Object o : params.getAny()) {
                    if (o instanceof Element || o instanceof JAXBElement) {
                        JAXBElement jaxbEl = null;
                        if (o instanceof Element) {
                            Element e = (Element)o;
                            QName elQn = new QName(e.getNamespaceURI(), e.getLocalName());
                            jaxbEl = new JAXBElement<String>(elQn,
                                String.class,
View Full Code Here

        }
        if (name == null && marshalAsJaxbElement) {
            name = convertStringToQName(cls.getSimpleName());
        }
        if (name != null) {
            return new JAXBElement(name, cls, null, obj);
        }
        return obj;
    }
View Full Code Here

            }
        } else {
            value = fromObj;
        }
       
        return new JAXBElement(name, value.getClass(), value);
    }
View Full Code Here

        Fault fault = new Fault();
        fault.setFaultcode(FAULT_CODE_SERVER);
        fault.setFaultstring(exception.getMessage());
        Detail detailEl = new ObjectFactory().createDetail();
        @SuppressWarnings("rawtypes")
        JAXBElement<?> faultDetailContent = new JAXBElement(name, faultObject.getClass(), faultObject);
        detailEl.getAny().add(faultDetailContent);
        fault.setDetail(detailEl);
        return new ObjectFactory().createFault(fault);
    }
View Full Code Here

    public static <T> String marshal(T object) throws DeploymentException {
        try {
            Class type = object.getClass();

            if (object instanceof JAXBElement) {
                JAXBElement element = (JAXBElement) object;
                type = element.getValue().getClass();
            }

            JAXBContext ctx = JAXBContext.newInstance(type);
            Marshaller marshaller = ctx.createMarshaller();
View Full Code Here

    public static OpenejbGeronimoEjbJarType convertToXmlbeans(GeronimoEjbJarType geronimoEjbJarType) throws DeploymentException {
        //
        // it would be nice if Jaxb had a way to convert the object to a
        // sax reader that could be fed directly into xmlbeans
        //
        JAXBElement root = new JAXBElement(new QName("http://geronimo.apache.org/xml/ns/j2ee/ejb/openejb-2.0","ejb-jar"), GeronimoEjbJarType.class, geronimoEjbJarType);

        // marshal to xml

        String xml = marshal(root);
        try {
View Full Code Here

      Object results = containerPolicy.containerInstance(containerPolicy.sizeFor(value));
      Object iterator = containerPolicy.iteratorFor(value);
      while(containerPolicy.hasNext(iterator)) {
        Object next = containerPolicy.next(iterator, null);
        if(next instanceof JAXBElement) {
          JAXBElement element = (JAXBElement)next;
          XMLRoot root = new XMLRoot();
          root.setLocalName(element.getName().getLocalPart());
          root.setNamespaceURI(element.getName().getNamespaceURI());
          root.setObject(element.getValue());
          containerPolicy.addInto(root, results, null);
        } else {
          containerPolicy.addInto(next, results, null);
        }
      }
      value = results;
    } else {
      if(value instanceof JAXBElement) {
        JAXBElement element = (JAXBElement)value;
        XMLRoot root = new XMLRoot();
        root.setLocalName(element.getName().getLocalPart());
        root.setNamespaceURI(element.getName().getNamespaceURI());
        root.setObject(element.getValue());
        value = root;
      }
    }
    return value;
  }
View Full Code Here

      while(containerPolicy.hasNext(iterator)) {
        Object next = containerPolicy.next(iterator, null);
        if(next instanceof XMLRoot) {
          XMLRoot root = (XMLRoot)next;
          QName name = new QName(root.getNamespaceURI(), root.getLocalName());
          JAXBElement element = new JAXBElement(name, root.getObject().getClass(), root.getObject());
          containerPolicy.addInto(element, results, null);
        } else {
          containerPolicy.addInto(next, results, null);
        }
      }
      attributeValue = results;
    } else {
      if(attributeValue instanceof XMLRoot) {
        XMLRoot root = (XMLRoot)attributeValue;
        QName name = new QName(root.getNamespaceURI(), root.getLocalName());
        JAXBElement element = new JAXBElement(name, root.getObject().getClass(), root.getObject());
        attributeValue = element;
      }     
    }
    nestedAccessor.setAttributeValueInObject(object, attributeValue);
  }
View Full Code Here

        return null;
    }
   
    public JAXBElement getJAXBNode(Object obj) {
        Element elem = (Element)xmlBinder.getXMLNode(obj);
        return new JAXBElement(new QName(elem.getNamespaceURI(), elem.getLocalName()), obj.getClass(), obj);
    }
View Full Code Here

TOP

Related Classes of javax.xml.bind.JAXBElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.