org.exolab.castor.mapping.Mapping Java Examples
The following examples show how to use
org.exolab.castor.mapping.Mapping.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CastorMarshaller.java From java-technology-stack with MIT License | 6 votes |
/** * 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(@Nullable Resource[] mappingLocations, @Nullable Class<?>[] targetClasses, @Nullable 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) { this.castorProperties.forEach(context::setProperty); } return context; }
Example #2
Source File: CastorMarshaller.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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; }
Example #3
Source File: CastorUtil.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * @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(); }
Example #4
Source File: CastorUtil.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ 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); } }