Package org.exolab.castor.xml

Examples of org.exolab.castor.xml.XMLContext


        super.setUp();
    }

    public void testWithMapping() {
        try {
            XMLContext context = new XMLContext();
            InputStream strmMapping = this.getClass().getClassLoader().getResourceAsStream("withmapping-mapping.xml");
            Assert.assertNotNull("InputStream of mapping must not be null", strmMapping);
            InputSource srcMapping = new InputSource(strmMapping);
            Assert.assertNotNull("InputSource of mapping must not be null", srcMapping);
            Mapping mapping = new Mapping();
            mapping.loadMapping(srcMapping);
            context.addMapping(mapping);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            InputStream stream = this.getClass().getClassLoader().getResourceAsStream("withmapping-input.xml");
            Assert.assertNotNull("InputStream must not be null", stream);
            InputSource is = new InputSource(stream);
            Assert.assertNotNull("Inputstream must not be null", is);
            Object o = unmarshaller.unmarshal(is);
View Full Code Here


        }
    }

    public void testLoadPackage() {
        try {
            XMLContext context = new XMLContext();
            context.addPackage("org.castor.xmlctf.bestpractise.genpackage");
            // context.getInternalContext().getXMLClassDescriptorResolver().getDescriptorCache();
            Unmarshaller u = context.createUnmarshaller();
            InputStream stream = this.getClass().getClassLoader().getResourceAsStream("genpackage-input.xml");
            Assert.assertNotNull("InputStream must not be null", stream);
            InputSource is = new InputSource(stream);
            Assert.assertNotNull("Inputstream must not be null", is);
            Object o = u.unmarshal(is);
View Full Code Here

  private static final String OUTPUT_FILE = "product-mapping.xml";
 
  public CastorMapper() {
    try {
      tool = new XMLContext().createMappingTool();
    }
    catch (Exception e) { 
      log.error (e.getClass().getName(), e)
   
  } 
View Full Code Here

        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

   * @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);
    }
    return context;
  }
View Full Code Here

  XMLContext context;

  public CastorDAO() {
    super();
    try {
      this.context = new XMLContext();
      Mapping mapping = new Mapping();
      mapping.loadMapping(getClass().getClassLoader().getResource(
          "resources/xml/gwesm.cas"));
      this.context.addMapping(mapping);
    } catch (IOException e) {
View Full Code Here

        Reader reader = new InputStreamReader(inputStream, encoding);
        return createUnmarshaller(exchange).unmarshal(reader);
    }

    protected XMLContext createXMLContext(ClassResolver resolver, ClassLoader contextClassLoader) throws Exception {
        XMLContext xmlContext = new XMLContext();

        if (ObjectHelper.isNotEmpty(getMappingFile())) {
            Mapping xmlMap;
            if (contextClassLoader != null) {
                xmlMap = new Mapping(contextClassLoader);
            } else {
                xmlMap = new Mapping();
            }
            xmlMap.loadMapping(resolver.loadResourceAsURL(getMappingFile()));
            xmlContext.addMapping(xmlMap);
        }

        if (getPackages() != null) {
            xmlContext.addPackages(getPackages());
        }
        if (getClassNames() != null) {
            for (String name : getClassNames()) {
                Class<?> clazz = resolver.resolveClass(name);
                xmlContext.addClass(clazz);
            }
        }
        return xmlContext;
    }
View Full Code Here

        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) 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) 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

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.