|
1 | 1 | /* |
2 | | - * Copyright 2005 the original author or authors. |
| 2 | + * Copyright 2002-2009 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -99,6 +99,10 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
99 | 99 |
|
100 | 100 | private Properties namespaceMappings; |
101 | 101 |
|
| 102 | + private boolean suppressNamespaces = false; |
| 103 | + |
| 104 | + private boolean suppressXsiType = false; |
| 105 | + |
102 | 106 | /** Returns whether the Castor {@link Unmarshaller} should ignore attributes that do not match a specific field. */ |
103 | 107 | public boolean getIgnoreExtraAttributes() { |
104 | 108 | return ignoreExtraAttributes; |
@@ -191,11 +195,39 @@ public void setMappingLocations(Resource[] mappingLocations) { |
191 | 195 | this.mappingLocations = mappingLocations; |
192 | 196 | } |
193 | 197 |
|
| 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 | + |
194 | 228 | /** |
195 | 229 | * Sets the Castor target class. If this property is set, this <code>CastorMarshaller</code> is tied to this one |
196 | 230 | * specific class. Use a mapping file for unmarshalling multiple classes. |
197 | | - * <p/> |
198 | | - * You cannot set both this property and the mapping (location). |
199 | 231 | */ |
200 | 232 | public void setTargetClass(Class targetClass) { |
201 | 233 | this.targetClass = targetClass; |
@@ -313,6 +345,8 @@ private void marshal(Object graph, Marshaller marshaller) { |
313 | 345 | */ |
314 | 346 | protected void customizeMarshaller(Marshaller marshaller) { |
315 | 347 | marshaller.setValidation(isValidating()); |
| 348 | + marshaller.setSuppressNamespaces(isSuppressNamespaces()); |
| 349 | + marshaller.setSuppressXSIType(isSuppressXsiType()); |
316 | 350 | Properties namespaceMappings = getNamespaceMappings(); |
317 | 351 | if (namespaceMappings != null) { |
318 | 352 | for (Iterator iterator = namespaceMappings.keySet().iterator(); iterator.hasNext();) { |
|
0 commit comments