Skip to content

Commit

Permalink
Consistent use of varargs, consistent template method order
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Aug 9, 2013
1 parent 92e3c52 commit b27e240
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing

private String encoding = DEFAULT_ENCODING;

private Class[] targetClasses;
private Class<?>[] targetClasses;

private String[] targetPackages;

Expand Down Expand Up @@ -172,23 +172,23 @@ public void setMappingLocation(Resource mappingLocation) {
/**
* Set the locations of the Castor XML Mapping files.
*/
public void setMappingLocations(Resource[] mappingLocations) {
public void setMappingLocations(Resource... mappingLocations) {
this.mappingLocations = mappingLocations;
}

/**
* Set the Castor target class. Alternative means of configuring {@code CastorMarshaller} for unmarshalling
* multiple classes include use of mapping files, and specifying packages with Castor descriptor classes.
*/
public void setTargetClass(Class targetClass) {
this.targetClasses = new Class[]{targetClass};
public void setTargetClass(Class<?> targetClass) {
this.targetClasses = new Class<?>[] {targetClass};
}

/**
* Set the Castor target classes. Alternative means of configuring {@code CastorMarshaller} for unmarshalling
* multiple classes include use of mapping files, and specifying packages with Castor descriptor classes.
*/
public void setTargetClasses(Class[] targetClasses) {
public void setTargetClasses(Class<?>... targetClasses) {
this.targetClasses = targetClasses;
}

Expand All @@ -202,7 +202,7 @@ public void setTargetPackage(String targetPackage) {
/**
* Set the names of packages with the Castor descriptor classes.
*/
public void setTargetPackages(String[] targetPackages) {
public void setTargetPackages(String... targetPackages) {
this.targetPackages = targetPackages;
}

Expand Down Expand Up @@ -458,8 +458,8 @@ public void afterPropertiesSet() throws CastorMappingException, IOException {
* @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 {
protected XMLContext createXMLContext(Resource[] mappingLocations, Class<?>[] targetClasses,
String[] targetPackages) throws MappingException, ResolverException, IOException {

XMLContext context = new XMLContext();
if (!ObjectUtils.isEmpty(mappingLocations)) {
Expand Down Expand Up @@ -492,47 +492,46 @@ public boolean supports(Class<?> clazz) {
return true;
}


// Marshalling

@Override
protected final void marshalDomNode(Object graph, Node node) throws XmlMappingException {
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException {
marshalSaxHandlers(graph, DomUtils.createContentHandler(node), null);
}

@Override
protected final void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
throws XmlMappingException {

Marshaller marshaller = xmlContext.createMarshaller();
marshaller.setContentHandler(contentHandler);
marshal(graph, marshaller);
protected void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) throws XmlMappingException {
marshalSaxHandlers(graph, StaxUtils.createContentHandler(eventWriter), null);
}

@Override
protected final void marshalOutputStream(Object graph, OutputStream outputStream)
throws XmlMappingException, IOException {

marshalWriter(graph, new OutputStreamWriter(outputStream, encoding));
protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
marshalSaxHandlers(graph, StaxUtils.createContentHandler(streamWriter), null);
}

@Override
protected final void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
throws XmlMappingException {

Marshaller marshaller = xmlContext.createMarshaller();
marshaller.setWriter(writer);
marshal(graph, marshaller);
marshaller.setContentHandler(contentHandler);
doMarshal(graph, marshaller);
}

@Override
protected final void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) throws XmlMappingException {
marshalSaxHandlers(graph, StaxUtils.createContentHandler(eventWriter), null);
protected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException {
marshalWriter(graph, new OutputStreamWriter(outputStream, encoding));
}

@Override
protected final void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
marshalSaxHandlers(graph, StaxUtils.createContentHandler(streamWriter), null);
protected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
Marshaller marshaller = xmlContext.createMarshaller();
marshaller.setWriter(writer);
doMarshal(graph, marshaller);
}

private void marshal(Object graph, Marshaller marshaller) {
private void doMarshal(Object graph, Marshaller marshaller) {
try {
customizeMarshaller(marshaller);
marshaller.marshal(graph);
Expand Down Expand Up @@ -572,10 +571,11 @@ protected void customizeMarshaller(Marshaller marshaller) {
}
}


// Unmarshalling

@Override
protected final Object unmarshalDomNode(Node node) throws XmlMappingException {
protected Object unmarshalDomNode(Node node) throws XmlMappingException {
try {
return createUnmarshaller().unmarshal(node);
}
Expand All @@ -585,27 +585,27 @@ protected final Object unmarshalDomNode(Node node) throws XmlMappingException {
}

@Override
protected final Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
protected Object unmarshalXmlEventReader(XMLEventReader eventReader) {
try {
return createUnmarshaller().unmarshal(new InputSource(inputStream));
return createUnmarshaller().unmarshal(eventReader);
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}

@Override
protected final Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) {
try {
return createUnmarshaller().unmarshal(new InputSource(reader));
return createUnmarshaller().unmarshal(streamReader);
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}

@Override
protected final Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
throws XmlMappingException, IOException {

UnmarshalHandler unmarshalHandler = createUnmarshaller().createHandler();
Expand All @@ -621,19 +621,19 @@ protected final Object unmarshalSaxReader(XMLReader xmlReader, InputSource input
}

@Override
protected final Object unmarshalXmlEventReader(XMLEventReader eventReader) {
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
try {
return createUnmarshaller().unmarshal(eventReader);
return createUnmarshaller().unmarshal(new InputSource(inputStream));
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}

@Override
protected final Object unmarshalXmlStreamReader(XMLStreamReader streamReader) {
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
try {
return createUnmarshaller().unmarshal(streamReader);
return createUnmarshaller().unmarshal(new InputSource(reader));
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
Expand Down Expand Up @@ -679,6 +679,7 @@ protected void customizeUnmarshaller(Unmarshaller unmarshaller) {
}
}


/**
* Convert the given {@code XMLException} to an appropriate exception from the
* {@code org.springframework.oxm} hierarchy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void setValidationEventHandler(ValidationEventHandler validationEventHand
* Specify the {@code XmlAdapter}s to be registered with the JAXB {@code Marshaller}
* and {@code Unmarshaller}
*/
public void setAdapters(XmlAdapter<?, ?>[] adapters) {
public void setAdapters(XmlAdapter<?, ?>... adapters) {
this.adapters = adapters;
}

Expand All @@ -311,7 +311,7 @@ public void setSchema(Resource schemaResource) {
/**
* Set the schema resources to use for validation.
*/
public void setSchemas(Resource[] schemaResources) {
public void setSchemas(Resource... schemaResources) {
this.schemaResources = schemaResources;
}

Expand Down
Loading

0 comments on commit b27e240

Please sign in to comment.