org.exolab.castor.mapping.Mapping.loadMapping()方法的使用及代码示例

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

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

Mapping.loadMapping介绍

[英]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.
[中]从指定的URL加载映射,类型默认为“CastorXmlMapping”。如果指定了实体解析程序,则将使用实体解析程序解析URL。此方法还用于加载从另一个映射或配置文件引用的映射。

代码示例

代码示例来源: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

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

/**
 * Loads the mapping from the specified input source with type defaults to 'CastorXmlMapping'.
 *
 * @param source The input source.
 */
public void loadMapping(final InputSource source) {
 loadMapping(source, DEFAULT_SOURCE_TYPE);
}

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

/**
 * Loads the mapping from the specified input source with type defaults to
 * 'CastorXmlMapping'.
 *
 * @param source The input source.
 */
public void loadMapping(final InputSource source) {
  loadMapping(source, DEFAULT_SOURCE_TYPE);
}

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

/**
 * 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-jdo

private void loadHistory() {
  try {
    Unmarshaller unmarshaller = new Unmarshaller(
        Class.forName("org.exolab.castor.gui.QueryHistory"));
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    _mapping.loadMapping(cl.getResource("org/exolab/castor/gui/Queryanlyser.xml"));
    unmarshaller.setMapping(_mapping);
    FileReader reader = new FileReader("queryhistory.xml");
    _qhistory = (QueryHistory) unmarshaller.unmarshal(reader);
  } catch (Exception e) {
    e.printStackTrace();
    // if there is no file, it's ok also
    // then we have an empty History
  }
}

代码示例来源: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/castor-xml

/**
 * Loads the mapping from the specified URL.
 *
 * @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 URL url, final String type) throws IOException, MappingException {
 try {
  if (_resolver.getBaseURL() == null) {
   _resolver.setBaseURL(url);
  }
  InputSource source = _resolver.resolveEntity(null, url.toExternalForm());
  if (source == null) {
   source = new InputSource(url.toExternalForm());
   source.setByteStream(url.openStream());
  } else
   source.setSystemId(url.toExternalForm());
  LOG.info(Messages.format("mapping.loadingFrom", url.toExternalForm()));
  loadMapping(source, type);
 } catch (SAXException ex) {
  throw new MappingException(ex);
 }
}

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

/**
 * Loads the mapping from the specified URL.
 *
 * @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 URL url, final String type)
throws IOException, MappingException {
  try {
    if (_resolver.getBaseURL() == null) {
      _resolver.setBaseURL(url);
    }
    InputSource source = _resolver.resolveEntity(null, url.toExternalForm());
    if (source == null) {
      source = new InputSource(url.toExternalForm());
      source.setByteStream(url.openStream());
    } else
      source.setSystemId(url.toExternalForm());
    LOG.info(Messages.format("mapping.loadingFrom", url.toExternalForm()));
    loadMapping(source, type);
  } catch (SAXException ex) {
    throw new MappingException(ex);
  }
}

代码示例来源:origin: org.apache.portals.jetspeed-2/jetspeed-page-manager

protected void createCastorClassDescriptorResolver(String mappingFile) throws MappingException
{
  Mapping mapping=null;
  try
  {
    InputStream stream = getClass().getResourceAsStream(mappingFile);
    if (log.isDebugEnabled())
    {
      log.debug("Loading psml mapping file " + mappingFile);
    }
    mapping = new Mapping();
    InputSource is = new InputSource(stream);
    is.setSystemId(mappingFile);
    mapping.loadMapping(is);
  }
  catch (Exception e)
  {
    IllegalStateException ise = new IllegalStateException("Error in psml mapping creation");
    ise.initCause(e);
    throw ise;
  }
  this.classDescriptorResolver =
    ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
   MappingUnmarshaller mappingUnmarshaller = new MappingUnmarshaller();
   MappingLoader mappingLoader = mappingUnmarshaller.getMappingLoader(mapping, BindingType.XML);
   classDescriptorResolver.setMappingLoader(mappingLoader);
}

代码示例来源: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/castor-xml

/**
 * 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. 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-xml

loadMapping(source, type);
} catch (SAXException ex) {
 throw new MappingException(ex);

代码示例来源:origin: OpenClinica/OpenClinica

public Html unMarshall(String xml) throws Exception {
  xmlContext = new XMLContext();
  Mapping mapping = xmlContext.createMapping();
  mapping.loadMapping(coreResources.getURL("xformMapping.xml"));
  xmlContext.addMapping(mapping);
  // XML to Object
  Reader reader = new StringReader(xml);
  Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
  unmarshaller.setClass(Html.class);
  unmarshaller.setWhitespacePreserve(false);
  Html html = (Html) unmarshaller.unmarshal(reader);
  reader.close();
  return html;
}

代码示例来源:origin: org.springframework.ws/spring-oxm

/**
 * Creates the Castor <code>XMLContext</code>. Subclasses can override this to create a custom context.
 * <p/>
 * The default implementation loads mapping files if defined, and the target class if not defined.
 *
 * @return the created resolver
 * @throws MappingException when the mapping file cannot be loaded
 * @throws IOException      in case of I/O errors
 * @see XMLContext#addMapping(org.exolab.castor.mapping.Mapping)
 * @see XMLContext#addClass(Class)
 */
protected XMLContext createXMLContext(Resource[] mappingLocations, Class targetClass)
    throws MappingException, IOException, ResolverException {
  XMLContext context = new XMLContext();
  if (!ObjectUtils.isEmpty(mappingLocations)) {
    Mapping mapping = new Mapping();
    for (int i = 0; i < mappingLocations.length; i++) {
      mapping.loadMapping(SaxUtils.createInputSource(mappingLocations[i]));
    }
    context.addMapping(mapping);
  }
  if (targetClass != null) {
    context.addClass(targetClass);
  }
  return context;
}

代码示例来源:origin: tflobbe/solrmeter

@Override
public List<StatisticDescriptor> getStatisticDescriptors(String filePath)
    throws ParserException {
  try {
    Mapping mapping = new Mapping();
    mapping.loadMapping(FileUtils.findFileAsResource("StatisticDescriptorMapping.xml"));
    XMLContext context = new XMLContext();
    context.addMapping(mapping);
    InputSource source = new InputSource(FileUtils.findFileAsStream(filePath));
    Unmarshaller unmarshaller = context.createUnmarshaller();
    unmarshaller.setClass(StatisticList.class);
    StatisticList list = (StatisticList)unmarshaller.unmarshal(source);
    validate(list.getDescriptors());
    return list.getDescriptors();
  } catch (Exception e) {
    ParserException parserException = new ParserException("Exception parsing statistic descriptor files", e);
    Logger.getLogger(this.getClass()).error(parserException.getMessage(), parserException);
    throw parserException;
  } 
}

代码示例来源:origin: OpenClinica/OpenClinica

public String marshall(Html html) throws Exception {
  StringWriter writer = new StringWriter();
  xmlContext = new XMLContext();
  Mapping mapping = xmlContext.createMapping();
  mapping.loadMapping(coreResources.getURL("xformMapping.xml"));
  xmlContext.addMapping(mapping);
  Marshaller marshaller = xmlContext.createMarshaller();
  marshaller.setNamespaceMapping("h", "http://www.w3.org/1999/xhtml");
  marshaller.setNamespaceMapping("jr", "http://openrosa.org/javarosa");
  marshaller.setNamespaceMapping("xsd", "http://www.w3.org/2001/XMLSchema");
  marshaller.setNamespaceMapping("ev", "http://www.w3.org/2001/xml-events");
  marshaller.setNamespaceMapping("", "http://www.w3.org/2002/xforms");
  marshaller.setNamespaceMapping("enk", "http://enketo.org/xforms");
  marshaller.setNamespaceMapping("oc", "http://openclinica.org/xforms");
  marshaller.setWriter(writer);
  marshaller.marshal(html);
  String xform = writer.toString();
  return xform;
}

代码示例来源:origin: org.apache.camel/camel-castor

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

相关文章