/** * 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; }
/** * 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; }
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);
mapper = new DozerBeanMapper(); mapper.addMapping(new Mapping());
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());
final Mapping mapping = new Mapping(XmlSerializer.class.getClassLoader());
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); }
/** * 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 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); } }
this.mapper = new Mapping(); this.mapper.loadMapping(file.toURL());
mapping = new Mapping(); mapping.loadMapping(ClassLoaderUtils.getResource(mappingFile, CastorTypeCreator.class));
this.mapper = new Mapping(); this.mapper.loadMapping(file.toURL());
Mapping mapping = new Mapping(getClass().getClassLoader());
Mapping mapping = new Mapping(); for (Resource mappingLocation : mappingLocations) { mapping.loadMapping(SaxResourceUtils.createInputSource(mappingLocation));
/** * 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; }
Mapping mapping = new Mapping(); mapping.loadMapping("mapping.xml"); XMLContext context = new XMLContext();
@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; } }
_mapping = new Mapping(loader); InputSource source = new InputSource(mappingFile); source.setSystemId(mappingFilePath);
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; }
Mapping mapping = new Mapping(); mapping.loadMapping(getCoreResources().getURL("mappingMarshallerMetadata.xml"));