Package javax.xml.bind

Examples of javax.xml.bind.MarshalException


    throws JAXBException
  {
    ClassSkeleton skeleton = _context.findSkeletonForObject(jaxbObject);

    if (skeleton == null)
      throw new MarshalException(L.l("Unable to update {0}: its type unknown to this JAXBContext", jaxbObject));

    try {
      return skeleton.bindTo(this, xmlNode, jaxbObject, null, null);
    }
    catch (IOException e) {
View Full Code Here


    throws JAXBException
  {
    ClassSkeleton skeleton = _context.findSkeletonForObject(jaxbElement);

    if (skeleton == null)
      throw new MarshalException(L.l("Unable to marshal {0}: its type unknown to this JAXBContext", jaxbElement));

    Class c = skeleton.getType();
    writer = StaxUtil.toRepairingXMLStreamWriter(writer);

    // tck/JAXBMarshall
    if (! _context.createJAXBIntrospector().isElement(jaxbElement) &&
        ! c.isAnnotationPresent(XmlRootElement.class))
      throw new MarshalException("JAXBIntrospector.isElement()==false");

    /*
    String name = null;
    String namespace = null;

View Full Code Here

  }

  public void marshal(Object obj, Result result) throws JAXBException
  {
    if (! _context.createJAXBIntrospector().isElement(obj))
      throw new MarshalException(L.l("Object is not a JAXB element: {0}", obj));

    try {
      XMLStreamWriter out = _xmlOutputFactory.createXMLStreamWriter(result);

      marshal(obj, out);
View Full Code Here

    public void marshal(Object obj, Result result) throws JAXBException {
        //XMLSerializable so = Util.toXMLSerializable(obj);
        XMLSerializable so = context.getGrammarInfo().castToXMLSerializable(obj);

        if(so==null)
            throw new MarshalException(
                Messages.format( Messages.NOT_MARSHALLABLE ) );


        if (result instanceof SAXResult) {
            write(so, ((SAXResult) result).getHandler());
            return;
        }
        if (result instanceof DOMResult) {
            Node node = ((DOMResult) result).getNode();

            if (node == null) {
                try {
                    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                    dbf.setNamespaceAware(true);
                    DocumentBuilder db = dbf.newDocumentBuilder();
                    Document doc = db.newDocument();
                    ((DOMResult) result).setNode(doc);
                    write(so, new SAX2DOMEx(doc));
                } catch (ParserConfigurationException pce) {
                    throw new JAXBAssertionError(pce);
                }
            } else {
                write(so, new SAX2DOMEx(node));
            }

            return;
        }
        if (result instanceof StreamResult) {
            StreamResult sr = (StreamResult) result;
            XMLWriter w = null;

            if (sr.getWriter() != null)
                w = createWriter(sr.getWriter());
            else if (sr.getOutputStream() != null)
                w = createWriter(sr.getOutputStream());
            else if (sr.getSystemId() != null) {
                String fileURL = sr.getSystemId();

                if (fileURL.startsWith("file:///")) {
                    if (fileURL.substring(8).indexOf(":") > 0)
                        fileURL = fileURL.substring(8);
                    else
                        fileURL = fileURL.substring(7);
                } // otherwise assume that it's a file name

                try {
                    w = createWriter(new FileOutputStream(fileURL));
                } catch (IOException e) {
                    throw new MarshalException(e);
                }
            }

            if (w == null)
                throw new IllegalArgumentException();

            write(so, w);
            return;
        }

        // unsupported parameter type
        throw new MarshalException(
            Messages.format( Messages.UNSUPPORTED_RESULT ) );
    }
View Full Code Here

            obj.serializeBody(serializer);
            writer.endDocument();
           
            serializer.reconcileID();   // extra check
        } catch( SAXException e ) {
            throw new MarshalException(e);
        }
    }
View Full Code Here

        try {
            return createWriter(
                new OutputStreamWriter(os,getJavaEncoding(encoding)),
                encoding );
        } catch( UnsupportedEncodingException e ) {
            throw new MarshalException(
                Messages.format( Messages.UNSUPPORTED_ENCODING, encoding ),
                e );
        }
    }
View Full Code Here

      object = createXMLRootFromJAXBElement((JAXBElement) object);
    }
    try {
      xmlMarshaller.marshal(object, contentHandler);
    } catch (Exception e) {
      throw new MarshalException(e);
    }
  }
View Full Code Here

      Class staxResult = PrivilegedAccessHelper.getClassForName(STAX_RESULT_CLASS_NAME);
      Constructor cons = PrivilegedAccessHelper.getDeclaredConstructorFor(staxResult, new Class[]{XMLEventWriter.class}, false);
      Result result = (Result)PrivilegedAccessHelper.invokeConstructor(cons, new Object[]{eventWriter});
      this.marshal(object, result);
    } catch(Exception ex) {
      throw new MarshalException(ex);
    }
  }
View Full Code Here

      object = createXMLRootFromJAXBElement((JAXBElement) object);
    }
    try {
      xmlMarshaller.marshal(object, node);
    } catch (Exception e) {
      throw new MarshalException(e);
    }
  }
View Full Code Here

      object = createXMLRootFromJAXBElement((JAXBElement) object);
    }
    try {
      xmlMarshaller.marshal(object, outputStream);
    } catch (Exception e) {
      throw new MarshalException(e);
    }
  }
View Full Code Here

TOP

Related Classes of javax.xml.bind.MarshalException

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.