Marshaller marshaller = new Marshaller(); Mapping mapping = new Mapping(); mapping.loadMapping("test-mapping.xml"); marshaller.setMapping(mapping); TestObj obj = new TestObj(); StringWriter writer = new StringWriter(); obj.setParam1("1"); obj.setParam2("2"); marshaller.setWriter(writer); marshaller.marshal(obj); System.out.println("output:"+writer.toString());
/** * Creates a new Unmarshaller with the given Mapping. * * @param internalContext the internal context to use * @param mapping The Mapping to use. * @throws MappingException in case that Unmarshaller fails to be instantiated */ public Unmarshaller(final InternalContext internalContext, final Mapping mapping) throws MappingException { this(internalContext, null, null); if (mapping != null) { setMapping(mapping); this._loader = mapping.getClassLoader(); } }
/** * Loads the mapping from the specified URL with type defaults to 'CastorXmlMapping'. If an entity * resolver was specified, will use the entity resolver to resolve the URL. This method is also * used to load mappings referenced from another mapping or configuration file. * * @param url The URL of the mapping file. * @throws IOException An error occured when reading the mapping file. * @throws MappingException The mapping file is invalid. */ public void loadMapping(final String url) throws IOException, MappingException { loadMapping(url, DEFAULT_SOURCE_TYPE); }
/** * Creates an instance of a Castor XML specific {@link Mapping} instance. * * @return a Castor XML specific {@link Mapping} instance. */ public Mapping createMapping() { Mapping mapping = new Mapping(); // mapping.setBindingType(BindingType.XML); return mapping; }
/** * Loads the mapping from the specified URL. If an entity resolver * was specified, will use the entity resolver to resolve the URL. * This method is also used to load mappings referenced from another * mapping or configuration file. * * @param url The URL of the mapping file. * @param type The source type. * @throws IOException An error occured when reading the mapping file. * @throws MappingException The mapping file is invalid. */ public void loadMapping(final String url, final String type) throws IOException, MappingException { String location = url; if (_resolver.getBaseURL() == null) { setBaseURL(location); location = URIUtils.getRelativeURI(location); } try { InputSource source = _resolver.resolveEntity(null, location); if (source == null) { source = new InputSource(location); } if (source.getSystemId() == null) { source.setSystemId(location); } LOG.info(Messages.format("mapping.loadingFrom", location)); loadMapping(source, type); } catch (SAXException ex) { throw new MappingException(ex); } }
Mapping mapping = new Mapping(loader); if (resolver != null) { mapping.setEntityResolver(resolver); } if (baseURI != null) { mapping.setBaseURL(baseURI); }
Mapping oMapping = new Mapping(); Map<String, Map<String, String>> oMap = oMapping.classifyMapEntries();
/** * Returns a mapping resolver for the suitable engine. The engine's specific mapping loader is * created and used to create engine specific descriptors, returning a suitable mapping resolver. * The mapping resolver is cached in memory and returned in subsequent method calls. * * @param mapping The mapping to load and resolve. * @param bindingType The binding type to read from mapping. * @param param Arbitrary parameter that is to be passed to resolver.loadMapping(). * @return A mapping resolver * @throws MappingException A mapping error occured preventing descriptors from being generated * from the loaded mapping. */ public MappingLoader getMappingLoader(final Mapping mapping, final BindingType bindingType, final Object param) throws MappingException { synchronized (this) { Iterator iter = mapping.getMappingSources().iterator(); while (iter.hasNext()) { MappingSource source = (MappingSource) iter.next(); loadMappingInternal(mapping, source.getResolver(), source.getSource()); } AbstractMappingLoader loader; loader = (AbstractMappingLoader) _registry.getMappingLoader("CastorXmlMapping", bindingType); loader.setClassLoader(mapping.getClassLoader()); loader.setAllowRedefinitions(_allowRedefinitions); loader.setInternalContext(_internalContext); loader.loadMapping(mapping.getRoot(), param); return loader; } }
if (mapping.processed(id)) { return; mapping.markAsProcessed(id); MappingRoot root = mapping.getRoot(); _idResolver.setMapping(root); while (includes.hasMoreElements()) { Include include = (Include) includes.nextElement(); if (!mapping.processed(include.getHref())) { try { loadMappingInternal(mapping, resolver, include.getHref());
/** * Return the ClassMapping which associated with parameter name. * * @param name Name of class to get ClassMapping of. * @return ClassMapping of the named class or <code>null</code> if no such * ClassMapping was found. */ public ClassMapping getClassMappingByName(final String name) { Enumeration<? extends ClassMapping> ec = _mapping.getRoot().enumerateClassMapping(); while (ec.hasMoreElements()) { ClassMapping cm = ec.nextElement(); String cmName = cm.getName(); if ((cmName != null) && cmName.equals(name)) { return cm; } } return null; }
/** * Loads the mapping from the specified URL with type defaults to 'CastorXmlMapping'. * * @param url The URL of the mapping file. * @throws IOException An error occured when reading the mapping file. * @throws MappingException The mapping file is invalid. */ public void loadMapping(final URL url) throws IOException, MappingException { loadMapping(url, DEFAULT_SOURCE_TYPE); }
/** * Creates an instance of a Castor XML specific {@link Mapping} instance. * @return a Castor XML specific {@link Mapping} instance. */ public Mapping createMapping() { Mapping mapping = new Mapping(); // mapping.setBindingType(BindingType.XML); return mapping; }
String location = url; if (_resolver.getBaseURL() == null) { setBaseURL(location); location = URIUtils.getRelativeURI(location); loadMapping(source, type); } catch (SAXException ex) { throw new MappingException(ex);
throws MappingException { synchronized (this) { Iterator iter = mapping.getMappingSources().iterator(); while (iter.hasNext()) { MappingSource source = (MappingSource) iter.next(); loader = (AbstractMappingLoader) _registry.getMappingLoader( "CastorXmlMapping", bindingType); loader.setClassLoader(mapping.getClassLoader()); loader.setAllowRedefinitions(_allowRedefinitions); loader.setInternalContext(_internalContext); loader.loadMapping(mapping.getRoot(), param); return loader;
if (id != null) { if (mapping.processed(id)) { return; } mapping.markAsProcessed(id); MappingRoot root = mapping.getRoot(); _idResolver.setMapping(root); while (includes.hasMoreElements()) { Include include = (Include) includes.nextElement(); if (!mapping.processed(include.getHref())) { try { loadMappingInternal(mapping, resolver, include.getHref());
MappingRoot root = _mapping.getRoot(); _schema = _schemaFactory.createSchema(); _schema.setConfiguration(_configuration);
/** * Loads a package mapping file for the given package name using the * provided ClassLoader. * * @param packageName The name of the package to load the mapping file for. * @return The loaded Mapping or <code>null</code> if no mapping file * is available for the given package. * @throws MappingException */ private Mapping loadMapping(final String packageName, final ClassLoader classLoader) throws MappingException { URL url = classLoader.getResource(ResolveHelpers.getQualifiedFileName( XMLConstants.PKG_MAPPING_FILE, packageName)); if (url == null) { return null; } try { Mapping mapping = new Mapping(classLoader); mapping.loadMapping(url); return mapping; } catch (java.io.IOException ioex) { throw new MappingException(ioex); } }
/** * Loads the mapping from the specified URL with type defaults to * 'CastorXmlMapping'. * * @param url The URL of the mapping file. * @throws IOException An error occured when reading the mapping file. * @throws MappingException The mapping file is invalid. */ public void loadMapping(final URL url) throws IOException, MappingException { loadMapping(url, DEFAULT_SOURCE_TYPE); }
private String fileLoadPath="conf/Configuration.xml"; private String mappingPath="conf/mapping.xml"; Mapping mapping = new Mapping(); mapping.loadMapping(mappingPath); Configuration configuration = (Configuration)new Unmarshaller(mapping).unmarshal(fileLoadPath);
/** * Creates a new Unmarshaller with the given Mapping. * * @param internalContext the internal context to use * @param mapping The Mapping to use. * @throws MappingException in case that Unmarshaller fails to be instantiated * * @throws IllegalArgumentException if internalContext is null */ public Unmarshaller(final InternalContext internalContext, final Mapping mapping) throws MappingException { this(internalContext, null, null); if (mapping != null) { setMapping(mapping); this._loader = mapping.getClassLoader(); } }