本文整理汇总了Java中org.exolab.castor.mapping.Mapping类的典型用法代码示例。如果您正苦于以下问题:Java Mapping类的具体用法?Java Mapping怎么用?Java Mapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mapping类属于org.exolab.castor.mapping包,在下文中一共展示了Mapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createXMLContext
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
/**
* Create the Castor {@code XMLContext}. Subclasses can override this to create a custom context.
* <p>The default implementation loads mapping files if defined, or the target class or packages if 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<?>[] 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;
}
示例2: write
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
/**
* @deprecated Replaced by {@link #writeToString(Object)}.
*/
public static String write(Object object, Mapping mapping)
{
StringWriter writer = new StringWriter();
try
{
write(object, mapping, writer);
}
finally
{
try
{
writer.close();
}
catch(IOException e)
{
}
}
return writer.toString();
}
示例3: getStatisticDescriptors
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
@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;
}
}
示例4: readFromFile
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static List<Synonym> readFromFile(String filename) throws Exception {
Mapping mapping = getMapping();
Unmarshaller unmarshaller = new Unmarshaller(ArrayList.class);
unmarshaller.setMapping(mapping);
File file = new File(filename);
if (file.exists() && !file.isFile()) {
throw new IOException("File " + file.getAbsolutePath() + " exists but is not a file.");
}
if (!file.exists() || file.length() == 0) {
return Collections.emptyList();
}
Reader reader = new FileReader(file);
return (List<Synonym>) unmarshaller.unmarshal(reader);
}
示例5: writeToFile
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
public static void writeToFile(List<Synonym> synonyms, String filename)
throws Exception {
Mapping mapping = getMapping();
Writer writer = new FileWriter(new File(filename));
Marshaller marshaller = new Marshaller(writer);
// I have no idea why this does not work, so I added a castor.propeties
// file in the root as workaround.
// marshaller.setProperty("org.exolab.castor.indent", "true");
marshaller.setRootElement("synonyms");
marshaller.setMapping(mapping);
marshaller.setSuppressXSIType(true);
marshaller.marshal(synonyms);
writer.close();
}
示例6: setMapping
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
/**
* Initializes the Castor mapping instance.
* @param mapping a Castor mapping. Shall not be <code>null</code>.
* @throws NullPointerException if <code>mapping</code> is <code>null</code>.
* @throws MappingException an exception indicating an invalid mapping error.
*/
private void setMapping(final Mapping mapping) throws MappingException
{
_unmarshaller = new Unmarshaller(mapping); // May throw MappingException.
_unmarshaller.setValidation(false);
_unmarshaller.setIgnoreExtraElements(true);
_marshaller = new Marshaller();
_marshaller.setMapping(mapping); // May throw MappingException.
_marshaller.setValidation(false);
//_marshaller.setDebug(true);
// Specifies whether to support XML namespaces by default. Default is false.
//_marshaller.setProperty("org.exolab.castor.parser.namespaces", "true");
// Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false.
//_marshaller.setProperty("org.exolab.castor.indent", "true");
}
示例7: createXMLContext
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
/**
* Create the Castor {@code XMLContext}. Subclasses can override this to create a custom context.
* <p>The default implementation loads mapping files if defined, or the target class or packages if 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[] 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;
}
示例8: convertStringToXml
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
/**
* Convert String To XML.
* @param xmlString String.
* @return BulkOperationMetaData.
* @throws BulkOperationException BulkOperationException.
*/
public BulkOperationMetaData convertStringToXml(String xmlString)
throws BulkOperationException
{
BulkOperationMetaData bulkOperationMetaData = null;
try
{
InputSource inputSource = new InputSource(new StringReader(xmlString));
String mappingFilePath = CommonServiceLocator.getInstance().getPropDirPath()
+ File.separator + "mapping.xml";
Mapping mapping = new Mapping();
mapping.loadMapping(mappingFilePath);
Unmarshaller unMarshaller = new Unmarshaller(BulkOperationMetaData.class);
unMarshaller.setMapping(mapping);
bulkOperationMetaData = (BulkOperationMetaData) unMarshaller.unmarshal(inputSource);
}
catch (Exception exp)
{
logger.error(exp.getMessage(), exp);
ErrorKey errorkey = ErrorKey.getErrorKey("bulk.operation.issues");
throw new BulkOperationException(errorkey, exp, exp.getMessage());
}
return bulkOperationMetaData;
}
示例9: readBean
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
protected static void readBean(Object bean, Mapping mapping, ContentHandler contentHandler) {
try {
contentHandler.startDocument();
// Initialize Castor
ParserAdapter adapter = new ParserAdapter(XMLUtils.newSAXParser(XMLUtils.ParserConfiguration.PLAIN).getParser());
adapter.setContentHandler(contentHandler);
Marshaller marshaller = new Marshaller(adapter);
marshaller.setMarshalAsDocument(false);
marshaller.setMapping(mapping);
// Serialize with Castor
marshaller.marshal(bean);
contentHandler.endDocument();
} catch (Exception e) {
throw new OXFException(e);
}
}
示例10: convertAttributeValue
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
protected SequenceIterator convertAttributeValue(XPathContext xpathContext, Object attributeObject, String contentType, String key) throws XPathException {
if (attributeObject instanceof AtomicValue) {
// Found atomic value
// NOTE: This can be a XXFormsSetScopeAttribute.StringValueWithEquals
return SingletonIterator.makeIterator((AtomicValue) attributeObject);
} else if (attributeObject != null) {
// Found something else, hopefully convertible to SAXStore
final SAXStore saxStore;
try {
// We don't have any particular mappings to pass to serialize objects
final Mapping mapping = new Mapping();
mapping.loadMapping(new InputSource(new StringReader("<mapping/>")));
saxStore = ScopeGenerator.getSAXStore(attributeObject, mapping, contentType, key);
} catch (Exception e) {
throw new OXFException(e);
}
// Convert to DocumentInfo
final DocumentInfo documentInfo = TransformerUtils.saxStoreToTinyTree(xpathContext.getConfiguration(), saxStore);
return SingletonIterator.makeIterator(documentInfo);
} else {
// Empty result
return EmptyIterator.getInstance();
}
}
示例11: loadMapping
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
/**
*
*/
private void loadMapping(Mapping mapping, String mappingFile)
{
try
{
byte[] mappingFileData = JRLoader.loadBytesFromResource(mappingFile);
InputSource mappingSource = new InputSource(new ByteArrayInputStream(mappingFileData));
mapping.loadMapping(mappingSource);
}
catch (JRException e)
{
throw new JRRuntimeException(e);
}
}
示例12: loadMapping
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
private Mapping loadMapping() throws IOException, MappingException {
InputStream inputstream = null;
try {
inputstream = CastorXMLSerializer.class.getClassLoader().getResourceAsStream(MAPPING_FILE_LOCATION);
Mapping mapping = new Mapping();
mapping.loadMapping(new InputSource(inputstream));
return mapping;
} finally {
IOUtils.closeQuietly(inputstream);
}
}
示例13: readFromFile
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
public static Configuration readFromFile(String filename) throws Exception {
Mapping mapping = getMapping();
Unmarshaller unmarshaller = new Unmarshaller(mapping);
File file = new File(filename);
Reader reader = new FileReader(file);
Configuration configuration = (Configuration)unmarshaller.unmarshal(reader);
LOG.info("Configuration read from " + file.getAbsoluteFile());
return configuration;
}
示例14: getDemoConfiguration
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
public static String getDemoConfiguration() throws Exception {
Mapping mapping = getMapping();
StringWriter stringWriter = new StringWriter();
Marshaller marshaller = new Marshaller(stringWriter);
// I have no idea why this does not work, so I added a castor.propeties
// file in the root as workaround.
// marshaller.setProperty("org.exolab.castor.indent", "true");
marshaller.setMapping(mapping);
marshaller.marshal(createConfiguration());
return stringWriter.toString();
}
示例15: loadMappingFromString
import org.exolab.castor.mapping.Mapping; //导入依赖的package包/类
protected static Mapping loadMappingFromString(String mappingLocation,
String mappingContents, EntityResolver resolver) {
InputSource mappIS = new org.xml.sax.InputSource(new StringReader(mappingContents));
Mapping mapping = new Mapping();
mapping.setEntityResolver(resolver);
try {
mapping.loadMapping(mappIS);
} catch (Exception ex) {
LOG.error("Error loading castor mapping ("
+ mappingLocation + "): " + ex.getMessage(), ex);
}
return mapping;
}