Polishing
This commit is contained in:
parent
facf31f01a
commit
b25876fd0f
|
|
@ -170,30 +170,32 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the locations of the Castor XML Mapping files.
|
* Set the locations of the Castor XML mapping files.
|
||||||
*/
|
*/
|
||||||
public void setMappingLocations(Resource... mappingLocations) {
|
public void setMappingLocations(Resource... mappingLocations) {
|
||||||
this.mappingLocations = mappingLocations;
|
this.mappingLocations = mappingLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Castor target class. Alternative means of configuring {@code CastorMarshaller} for unmarshalling
|
* Set the Castor target class.
|
||||||
* multiple classes include use of mapping files, and specifying packages with Castor descriptor classes.
|
* @see #setTargetPackage
|
||||||
|
* @see #setMappingLocation
|
||||||
*/
|
*/
|
||||||
public void setTargetClass(Class<?> targetClass) {
|
public void setTargetClass(Class<?> targetClass) {
|
||||||
this.targetClasses = new Class<?>[] {targetClass};
|
this.targetClasses = new Class<?>[] {targetClass};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Castor target classes. Alternative means of configuring {@code CastorMarshaller} for unmarshalling
|
* Set the Castor target classes.
|
||||||
* multiple classes include use of mapping files, and specifying packages with Castor descriptor classes.
|
* @see #setTargetPackages
|
||||||
|
* @see #setMappingLocations
|
||||||
*/
|
*/
|
||||||
public void setTargetClasses(Class<?>... targetClasses) {
|
public void setTargetClasses(Class<?>... targetClasses) {
|
||||||
this.targetClasses = targetClasses;
|
this.targetClasses = targetClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the names of package with the Castor descriptor classes.
|
* Set the name of a package with the Castor descriptor classes.
|
||||||
*/
|
*/
|
||||||
public void setTargetPackage(String targetPackage) {
|
public void setTargetPackage(String targetPackage) {
|
||||||
this.targetPackages = new String[] {targetPackage};
|
this.targetPackages = new String[] {targetPackage};
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
||||||
|
|
||||||
private IBindingFactory bindingFactory;
|
private IBindingFactory bindingFactory;
|
||||||
|
|
||||||
private TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
private final TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,6 +127,7 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
||||||
public void setTargetPackage(String targetPackage) {
|
public void setTargetPackage(String targetPackage) {
|
||||||
this.targetPackage = targetPackage;
|
this.targetPackage = targetPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the optional binding name for this instance.
|
* Set the optional binding name for this instance.
|
||||||
*/
|
*/
|
||||||
|
|
@ -167,7 +168,7 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the system Id for the DTD declaration written when marshalling.
|
* Set the system id for the DTD declaration written when marshalling.
|
||||||
* By default, this is {@code null}. Only used when the root element also has been set.
|
* By default, this is {@code null}. Only used when the root element also has been set.
|
||||||
* <p>Set either this property or {@code docTypePublicId}, not both.
|
* <p>Set either this property or {@code docTypePublicId}, not both.
|
||||||
* @see #setDocTypeRootElementName(String)
|
* @see #setDocTypeRootElementName(String)
|
||||||
|
|
@ -177,7 +178,7 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the public Id for the DTD declaration written when marshalling.
|
* Set the public id for the DTD declaration written when marshalling.
|
||||||
* By default, this is {@code null}. Only used when the root element also has been set.
|
* By default, this is {@code null}. Only used when the root element also has been set.
|
||||||
* <p>Set either this property or {@code docTypeSystemId}, not both.
|
* <p>Set either this property or {@code docTypeSystemId}, not both.
|
||||||
* @see #setDocTypeRootElementName(String)
|
* @see #setDocTypeRootElementName(String)
|
||||||
|
|
@ -217,12 +218,12 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
||||||
bindingName = DEFAULT_BINDING_NAME;
|
bindingName = DEFAULT_BINDING_NAME;
|
||||||
}
|
}
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("Configured for target package [" + targetPackage + "] using binding [" + bindingName + "]");
|
logger.info("Configured for target package [" + this.targetPackage + "] using binding [" + this.bindingName + "]");
|
||||||
}
|
}
|
||||||
this.bindingFactory = BindingDirectory.getFactory(bindingName, targetPackage);
|
this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetPackage);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("either 'targetClass' or 'targetPackage' is required");
|
throw new IllegalArgumentException("Either 'targetClass' or 'targetPackage' is required");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -407,12 +408,13 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
||||||
@Override
|
@Override
|
||||||
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
|
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
|
||||||
throws XmlMappingException, IOException {
|
throws XmlMappingException, IOException {
|
||||||
|
|
||||||
return transformAndUnmarshal(new SAXSource(xmlReader, inputSource));
|
return transformAndUnmarshal(new SAXSource(xmlReader, inputSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object transformAndUnmarshal(Source source) throws IOException {
|
private Object transformAndUnmarshal(Source source) throws IOException {
|
||||||
try {
|
try {
|
||||||
Transformer transformer = transformerFactory.newTransformer();
|
Transformer transformer = this.transformerFactory.newTransformer();
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
transformer.transform(source, new StreamResult(os));
|
transformer.transform(source, new StreamResult(os));
|
||||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue