Package javax.xml.bind

Examples of javax.xml.bind.MarshalException


  public void marshal(Object pObject, Result pResult) throws JAXBException {
    if (pResult instanceof SAXResult) {
      ContentHandler ch = ((SAXResult) pResult).getHandler();
      if (ch == null) {
        throw new MarshalException("The SAXResult doesn't have its ContentHandler set.");
      }
      marshal(pObject, ch);
    } else if (pResult instanceof StreamResult) {
      StreamResult sr = (StreamResult) pResult;
      Writer w = sr.getWriter();
      if (w == null) {
        OutputStream s = sr.getOutputStream();
        if (s == null) {
          throw new MarshalException("The StreamResult doesn't have its Writer or OutputStream set.");
        }
        marshal(pObject, s);
      } else {
        marshal(pObject, w);
      }
    } else if (pResult instanceof DOMResult) {
      Node node = ((DOMResult) pResult).getNode();
      if (node == null) {
        throw new MarshalException("The DOMResult doesn't have its Node set.");
      }
      marshal(pObject, node);
    } else {
      throw new MarshalException("Unknown type of Result: " + pResult.getClass().getName() +
                                  ", only SAXResult, StreamResult and DOMResult are supported.");
    }
  }
View Full Code Here


   *   was not declared or creating the instance caused an exception.
   */
  public JMXmlSerializer getJMXmlSerializer(Class pElementInterface) throws MarshalException {
    Class c = getManagerByInterface(pElementInterface).getMarshallerClass();
    if (c == null) {
      throw new MarshalException("No marshaller class configured for " +
                                  pElementInterface.getName());
    }
    try {
      JMXmlSerializer xs = (JMXmlSerializer) c.newInstance();
      xs.init(this);
      return xs;
    } catch (Exception e) {
      throw new MarshalException("Could not instantiate marshaller class " +
                                  c.getName(), e);
    }
  }
View Full Code Here

   *   was not declared or creating the instance caused an exception.
   */
  public JMXmlSerializer getJMXmlSerializer(QName pQName) throws MarshalException {
    JMManager manager = getManagerByQName(pQName);
    if (manager == null) {
      throw new MarshalException("No manager registered for " + pQName);
    }
    Class c = manager.getMarshallerClass();
    if (c == null) {
      throw new MarshalException("No marshaller class configured for " + pQName);
    }
    try {
      JMXmlSerializer xs = (JMXmlSerializer) c.newInstance();
      xs.init(this);
      return xs;
    } catch (Exception e) {
      throw new MarshalException("Could not instantiate marshaller class " + c.getName(), e);
    }
  }
View Full Code Here

  /** <p>Returns a new JMMarshaller.</p>
   */
  public JMMarshaller getJMMarshaller() throws MarshalException {
    Class c = getJMMarshallerClass();
    if (c == null) {
      throw new MarshalException("A JMMarshaller class is not set.");
    }
    try {
      return (JMMarshaller) c.newInstance();
    } catch (Exception e) {
      throw new MarshalException("Failed to instantiate JMMarshaller class " + c, e);
    }
  }
View Full Code Here

    throws JAXBException
  {
    String out = _nameMap.get(in);

    if (out == null)
      throw new MarshalException(L.l("Unknown enum value: {0}", in));

    return 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

  public void marshal(Object pObject, OutputStream pStream) throws JAXBException {
    Writer writer;
    try {
      writer = new OutputStreamWriter(pStream, getEncoding());
    } catch(UnsupportedEncodingException e) {
      throw new MarshalException("Unsupported encoding: " + getEncoding(), e);
    }
    marshal(pObject, writer);
    try {
      writer.close();
    } catch (IOException e) {
      throw new MarshalException(e);
    }
  }
View Full Code Here

    JMElement element = (JMElement) pObject;
    try {
      JMXmlSerializer serializer = getJAXBContextImpl().getJMXmlSerializer(element.getQName());
      serializer.marshal(serializer.getData(this, pHandler), element.getQName(), element);
    } catch (SAXException 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.