Skip to content

Commit b83432a

Browse files
committed
SWS-548 - Expose suppressNamespace and suppressXSIType as properties to CastorMarshaller
1 parent 57fc696 commit b83432a

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,6 +99,10 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
9999

100100
private Properties namespaceMappings;
101101

102+
private boolean suppressNamespaces = false;
103+
104+
private boolean suppressXsiType = false;
105+
102106
/** Returns whether the Castor {@link Unmarshaller} should ignore attributes that do not match a specific field. */
103107
public boolean getIgnoreExtraAttributes() {
104108
return ignoreExtraAttributes;
@@ -191,11 +195,39 @@ public void setMappingLocations(Resource[] mappingLocations) {
191195
this.mappingLocations = mappingLocations;
192196
}
193197

198+
/** Returns whether this marshaller should output namespaces. */
199+
public boolean isSuppressNamespaces() {
200+
return suppressNamespaces;
201+
}
202+
203+
/**
204+
* Sets whether this marshaller should output namespaces. The default is {@code false}, i.e. namespaces are
205+
* written.
206+
*
207+
* @see org.exolab.castor.xml.Marshaller#setSuppressNamespaces(boolean)
208+
*/
209+
public void setSuppressNamespaces(boolean suppressNamespaces) {
210+
this.suppressNamespaces = suppressNamespaces;
211+
}
212+
213+
/** Sets whether this marshaller should output the xsi:type attribute. */
214+
public boolean isSuppressXsiType() {
215+
return suppressXsiType;
216+
}
217+
218+
/**
219+
* Sets whether this marshaller should output the {@code xsi:type} attribute. The default is {@code false}, i.e. the
220+
* {@code xsi:type} is written.
221+
*
222+
* @see org.exolab.castor.xml.Marshaller#setSuppressXSIType(boolean)
223+
*/
224+
public void setSuppressXsiType(boolean suppressXsiType) {
225+
this.suppressXsiType = suppressXsiType;
226+
}
227+
194228
/**
195229
* Sets the Castor target class. If this property is set, this <code>CastorMarshaller</code> is tied to this one
196230
* specific class. Use a mapping file for unmarshalling multiple classes.
197-
* <p/>
198-
* You cannot set both this property and the mapping (location).
199231
*/
200232
public void setTargetClass(Class targetClass) {
201233
this.targetClass = targetClass;
@@ -313,6 +345,8 @@ private void marshal(Object graph, Marshaller marshaller) {
313345
*/
314346
protected void customizeMarshaller(Marshaller marshaller) {
315347
marshaller.setValidation(isValidating());
348+
marshaller.setSuppressNamespaces(isSuppressNamespaces());
349+
marshaller.setSuppressXSIType(isSuppressXsiType());
316350
Properties namespaceMappings = getNamespaceMappings();
317351
if (namespaceMappings != null) {
318352
for (Iterator iterator = namespaceMappings.keySet().iterator(); iterator.hasNext();) {

0 commit comments

Comments
 (0)