Package org.exolab.castor.xml

Examples of org.exolab.castor.xml.Marshaller


      Mapping mapping = new Mapping();
      URL mappingUrl = Thread.currentThread().getContextClassLoader()
          .getResource(mappingFile);
      mapping.loadMapping(mappingUrl);
      FileWriter writer = new FileWriter(outputFile);
      Marshaller marshaller = new Marshaller(writer);
      marshaller.setEncoding(ConsoleCst.MAPPING_ENCODING);
      marshaller.setMapping(mapping);
      marshaller.marshal(obj);
    } catch (Throwable th) {
      throw new MappingException("Marshall exception occured: "+th);
    }
  }
View Full Code Here


    }

  public void storeObject(OutputStream stream, Map parameters, Object object) throws ConverterException {
        Writer writer = new OutputStreamWriter(stream);
    try {
      Marshaller marshaller = new Marshaller( writer );
      marshaller.setMapping((Mapping)this.mappings.get(parameters.get(parameters.get("profiletype"))));
      marshaller.marshal(object);
      writer.close();
    } catch (MappingException e) {
      throw new ConverterException("can't create Unmarshaller", e);
    } catch (Exception e) {
      throw new ConverterException(e.getMessage(), e);
View Full Code Here

        }
    }

    private void marshal(Map objectModel, String name, String scope, String mappingpath) {
        try {
            Marshaller marshaller = new Marshaller(new IncludeXMLConsumer(super.contentHandler));
            try {
                Mapping mapping = null;
                if (mappingpath != null) {
                    mapping = loadMapping(mappingpath);
                } else {
                    mapping = defaultMapping;
                }
                marshaller.setMapping(mapping);
            } catch (Exception e) {
                getLogger().warn("Unable to load mapping " + mappingpath, e);
            }

            Object bean = this.searchBean(objectModel, name, scope);

            if (bean instanceof Collection) {
                Iterator i = ((Collection)bean).iterator();
                while (i.hasNext()) {
                    marshaller.marshal(i.next());
                }
            } else {
                marshaller.marshal(bean);
            }
        } catch (Exception e) {
            getLogger().warn("Failed to marshal bean " + name, e);
        }
    }
View Full Code Here

           
            file = new File(DEFAULT_OUTPUT);
            FileWriter writer = new FileWriter(file);
            LocalConfiguration config = LocalConfiguration.getInstance();
            config.getProperties().setProperty(Configuration.Property.Indent, "true");
            Marshaller marshaller = new Marshaller(writer);
            marshaller.setRootElement("changelog");
            marshaller.setSuppressXSIType(true);
            marshaller.marshal(changelog);
           
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
View Full Code Here

        try {
            writer = new StringWriter();

            // Create a Castor Marshaller initialized with the output stream
            Marshaller marshaller = new Marshaller(writer);

            // Don't include the DOCTYPE, otherwise an exception occurs due to
            //2 DOCTYPE defined in the document. The XML fragment is included in
            //an XML document containing already a DOCTYPE
            marshaller.setMarshalAsDocument(false);

            // Marshall the Castor object into the stream (sink)
            marshaller.marshal(value);

            context.writeString(writer.toString());
        } catch (MarshalException me) {
            log.error(Messages.getMessage("castorMarshalException00"), me);
            throw new IOException(Messages.getMessage("castorMarshalException00")
View Full Code Here

            // polymorphic collection to strip artifical <menu-element>
            // tags enabling Castor XML binding; see JETSPEED-INF/castor/page-mapping.xml
            writer = new OutputStreamWriter(new FileOutputStream(f), PSML_DOCUMENT_ENCODING);
            Serializer serializer = new XMLSerializer(writer, this.format);
            final DocumentHandler handler = serializer.asDocumentHandler();
            Marshaller marshaller = new Marshaller(new DocumentHandler()
                {
                    private int menuDepth = 0;

                    public void characters(char[] ch, int start, int length) throws SAXException
                    {
                        handler.characters(ch, start, length);
                    }

                    public void endDocument() throws SAXException
                    {
                        handler.endDocument();
                    }
                   
                    public void endElement(String name) throws SAXException
                    {
                        // track menu depth
                        if (name.equals("menu"))
                        {
                            menuDepth--;
                        }

                        // filter menu-element noded within menu definition
                        if ((menuDepth == 0) || !name.equals("menu-element"))
                        {
                            handler.endElement(name);
                        }
                    }
                   
                    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
                    {
                        handler.ignorableWhitespace(ch, start, length);
                    }
                   
                    public void processingInstruction(String target, String data) throws SAXException
                    {
                        handler.processingInstruction(target, data);
                    }
                   
                    public void setDocumentLocator(Locator locator)
                    {
                        handler.setDocumentLocator(locator);
                    }
                   
                    public void startDocument() throws SAXException
                    {
                        handler.startDocument();
                    }
                   
                    public void startElement(String name, AttributeList atts) throws SAXException
                    {
                        // filter menu-element noded within menu definition
                        if ((menuDepth == 0) || !name.equals("menu-element"))
                        {
                            handler.startElement(name, atts);
                        }

                        // track menu depth
                        if (name.equals("menu"))
                        {
                            menuDepth++;
                        }
                    }
                });
            marshaller.setMapping(this.mapping);
            marshaller.marshal(document);
        }
        catch (MarshalException e)
        {
            log.error("Could not marshal the file " + f.getAbsolutePath(), e);
            throw new FailedToUpdateDocumentException(e);
View Full Code Here

                cid.getCopletData().setCopletBaseData(base);
                cid.getCopletData().setAttribute("uri", copletID);
                cid.getCopletData().setTitle(copletID);
                coplets.put(key, cid);

                Marshaller marshaller;
                try {
                    marshaller = new Marshaller(new PrintWriter(System.out));
                    marshaller.setSuppressXSIType(true);
                    marshaller.setMapping(layoutMapping);
                    marshaller.marshal(cid);
                } catch (Exception e) {
                    //e.printStackTrace();
                }
            }
            return cid;
View Full Code Here

    }

  public void storeObject(OutputStream stream, String name, Object object) throws ConverterException {
        Writer writer = new OutputStreamWriter(stream);
    try {
      Marshaller marshaller = new Marshaller( writer );
      Mapping mapping = new Mapping();
      marshaller.setMapping((Mapping)this.mappings.get(name));
      marshaller.marshal(object);
      writer.close();
    } catch (MappingException e) {
      throw new ConverterException("can't create Unmarshaller", e);
    } catch (Exception e) {
      throw new ConverterException(e.getMessage(), e);
View Full Code Here

            // handler, you can't set call marshaller.setDocType(String, String)

            // See Also:
            //  https://issues.apache.org/jira/browse/PLUTO-312
            //  http://castor.org/javadoc/org/exolab/castor/xml/Marshaller.html#setDoctype(java.lang.String,%20java.lang.String)
            Marshaller marshaller = new Marshaller(writer);
            marshaller.setMapping(getCastorMapping());
           
            // Use JAXP if we are instructed to do so.
            LocalConfiguration castorConfig = LocalConfiguration.getInstance();
            if (USING_JAXP) {               
                // empty string means "use JAXP" for Castor
                castorConfig.getProperties().setProperty("org.exolab.castor.parser", "" );               
                castorConfig.getProperties().setProperty("org.exolab.castor.xml.serializer.factory",
                        "org.exolab.castor.xml.XercesJDK5XMLSerializerFactory" );
            }
           
            if (LOG.isDebugEnabled()) {
                LOG.debug("Pluto descriptor service implementation using JAXP: [" + USING_JAXP + "]");                       
            }
           
            castorConfig.getProperties().setProperty("org.exolab.castor.indent", "true");
            setCastorMarshallerOptions(marshaller, object);
            marshaller.marshal(object);
        } catch(IOException io) {
            throw io;
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
View Full Code Here

                          Object value,
                          SerializationContext context)
            throws IOException {
        try {
            AxisContentHandler hand = new AxisContentHandler(context);
            Marshaller marshaller = new Marshaller(hand);

            // Don't include the DOCTYPE, otherwise an exception occurs due to
            //2 DOCTYPE defined in the document. The XML fragment is included in
            //an XML document containing already a DOCTYPE
            marshaller.setMarshalAsDocument(false);
            marshaller.setRootElement(name.getLocalPart());
           
            // Marshall the Castor object into the stream (sink)
            marshaller.marshal(value);
        } catch (MarshalException me) {
            log.error(Messages.getMessage("castorMarshalException00"), me);
            throw new IOException(Messages.getMessage(
                    "castorMarshalException00")
                    + me.getLocalizedMessage());
View Full Code Here

TOP

Related Classes of org.exolab.castor.xml.Marshaller

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.