Package org.exolab.castor.xml

Examples of org.exolab.castor.xml.XMLContext


        return getUnmarshaller(exchange).unmarshal(reader);
    }

    public XMLContext getXmlContext(ClassResolver resolver) throws Exception {
        if (xmlContext == null) {
            xmlContext = new XMLContext();

            if (ObjectHelper.isNotEmpty(getMappingFile())) {
                Mapping xmlMap = new Mapping();
                xmlMap.loadMapping(resolver.loadResourceAsURL(getMappingFile()));
                xmlContext.addMapping(xmlMap);
View Full Code Here


        return getUnmarshaller(exchange).unmarshal(reader);
    }

    public XMLContext getXmlContext(ClassResolver resolver, ClassLoader contextClassLoader) throws Exception {
        if (xmlContext == null) {
            xmlContext = new XMLContext();

            if (ObjectHelper.isNotEmpty(getMappingFile())) {
                Mapping xmlMap;
                if (contextClassLoader != null) {
                    xmlMap = new Mapping(contextClassLoader);
View Full Code Here

   * @see XMLContext#addClass(Class)
   */
  protected XMLContext createXMLContext(Resource[] mappingLocations, Class<?>[] targetClasses,
      String[] targetPackages) throws MappingException, ResolverException, IOException {

    XMLContext context = new XMLContext();
    if (!ObjectUtils.isEmpty(mappingLocations)) {
      Mapping mapping = new Mapping();
      for (Resource mappingLocation : mappingLocations) {
        mapping.loadMapping(SaxResourceUtils.createInputSource(mappingLocation));
      }
      context.addMapping(mapping);
    }
    if (!ObjectUtils.isEmpty(targetClasses)) {
      context.addClasses(targetClasses);
    }
    if (!ObjectUtils.isEmpty(targetPackages)) {
      context.addPackages(targetPackages);
    }
    if (this.castorProperties != null) {
      for (Map.Entry<String, String> property : this.castorProperties.entrySet()) {
        context.setProperty(property.getKey(), property.getValue());
      }
    }
    return context;
  }
View Full Code Here

       
      try {
          //Load Mapping
          Mapping mapping = new Mapping();
      mapping.loadMapping("mapping.xml");
      XMLContext context = new XMLContext();
        context.addMapping(mapping);
       
        //( 1 ) OBJECT --> XML

        //1.1 Prepare file writer
        Writer writer = new FileWriter("mapped_article.xml");

        //1.2 Create a new Marshaller
        Marshaller marshaller = context.createMarshaller();
        marshaller.setWriter(writer);

        //1.3 Marshal "map" to xml
        marshaller.marshal(createArticle());
       
        //1.4
        writer.close();
       
       
        //( 2 ) XML --> OBJECT
       
        //2.1 Prepare file writer
        Reader reader = new FileReader("mapped_article.xml");

        //2.2 Create a new Unmarshaller
        Unmarshaller unmarshaller = context.createUnmarshaller();
        unmarshaller.setClass(Article.class);

        //2.3 Unmarshal "map" to Object
        Article article = (Article) unmarshaller.unmarshal(reader);
       
View Full Code Here

        return getUnmarshaller(exchange).unmarshal(reader);
    }

    public XMLContext getXmlContext(ClassResolver resolver, ClassLoader contextClassLoader) throws Exception {
        if (xmlContext == null) {
            xmlContext = new XMLContext();

            if (ObjectHelper.isNotEmpty(getMappingFile())) {
                Mapping xmlMap;
                if (contextClassLoader != null) {
                    xmlMap = new Mapping(contextClassLoader);
View Full Code Here

  private XMLContext getContext()
    throws MappingException
  {
    if (context == null)
    {
      context = new XMLContext();
      context.setProperty("org.exolab.castor.indent", isPrettyPrint() ? "true" : "false");
      context.setProperty("org.exolab.castor.debug", "true");
      context.addMapping(mapping);
    }
    return context;
View Full Code Here

TOP

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

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.