org.exolab.castor.mapping.Mapping类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(229)

本文整理了Java中org.exolab.castor.mapping.Mapping类的一些代码示例,展示了Mapping类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mapping类的具体详情如下:
包路径:org.exolab.castor.mapping.Mapping
类名称:Mapping

Mapping介绍

[英]Utility class for loading mapping files and providing them to the XML marshaller, JDO engine etc. The mapping file can be loaded from a URL, input stream or SAX InputSource.

Multiple mapping files can be loaded with the same Mapping object. When loading master mapping files that include other mapping files it might be convenient to use #setBaseURL or #setEntityResolver.

If the desired class loader is different than the one used by Castor (e.g. if Castor is installed as a Java extension), the Mapping object can be constructed with the proper class loader.

The following example loads two mapping files:

Mapping mapping; 
mapping = new Mapping( getClass().getClassLoader() ); 
mapping.loadMapping( "mapping.xml" ); 
mapping.loadMapping( url );

[中]用于加载映射文件并将其提供给XML封送器、JDO引擎等的实用程序类。可以从URL、输入流或SAX InputSource加载映射文件。
可以使用同一映射对象加载多个映射文件。加载包含其他映射文件的主映射文件时,可以方便地使用#setBaseURL或#setEntityResolver。
如果所需的类加载器不同于Castor使用的类加载器(例如,如果Castor作为Java扩展安装),则可以使用适当的类加载器构造映射对象。
以下示例加载两个映射文件:

Mapping mapping; 
mapping = new Mapping( getClass().getClassLoader() ); 
mapping.loadMapping( "mapping.xml" ); 
mapping.loadMapping( url );

代码示例

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

/**
 * 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();
  }
}

代码示例来源:origin: org.codehaus.castor/castor-xml

/**
 * 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);
}

代码示例来源:origin: org.codehaus.castor/castor-xml

/**
 * 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;
}

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

/**
 * 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);
  }
}

代码示例来源:origin: org.codehaus.castor/castor-jdo

Mapping mapping = new Mapping(loader);
if (resolver != null) { mapping.setEntityResolver(resolver); }
if (baseURI != null) { mapping.setBaseURL(baseURI); }

代码示例来源:origin: stackoverflow.com

Mapping oMapping = new Mapping();
Map<String, Map<String, String>> oMap = oMapping.classifyMapEntries();

代码示例来源:origin: org.codehaus.castor/castor-xml

/**
 * 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;
 }
}

代码示例来源:origin: org.codehaus.castor/castor-xml

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

代码示例来源:origin: org.codehaus.castor/castor-ddlgen

/**
 * 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;
}

代码示例来源:origin: org.codehaus.castor/castor-xml

/**
 * 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);
}

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

/**
   * 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;
  }

代码示例来源:origin: org.codehaus.castor/castor-xml

String location = url;
if (_resolver.getBaseURL() == null) {
 setBaseURL(location);
 location = URIUtils.getRelativeURI(location);
 loadMapping(source, type);
} catch (SAXException ex) {
 throw new MappingException(ex);

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

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;

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

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

代码示例来源:origin: org.codehaus.castor/castor-ddlgen

MappingRoot root = _mapping.getRoot();
_schema = _schemaFactory.createSchema();
_schema.setConfiguration(_configuration);

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

/**
 * 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);
  }
}

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

/**
 * 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);
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: org.codehaus.castor/castor-xml

/**
 * 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();
 }
}

相关文章