Index: xml/src/main/java/org/exolab/castor/xml/Marshaller.java =================================================================== --- xml/src/main/java/org/exolab/castor/xml/Marshaller.java (revision 8041) +++ xml/src/main/java/org/exolab/castor/xml/Marshaller.java (working copy) @@ -295,7 +295,7 @@ setContentHandler(new DocumentHandlerAdapter(handler)); // call internal initializer - initialize(); + initialize(null); } /** @@ -333,7 +333,18 @@ setContentHandler(contentHandler); // call internal initializer - initialize(); + initialize(null); + } + + /** + * The one {@link Marshaller} constructor that is used by {@link XMLContext} which + * sets an {@link InternalContext} that comes from outside. Writer or {@link ContentHandler} + * have to be set in a second step. + * @param internalContext the {@link InternalContext} to initialize the {@link Marshaller} + * instance with + */ + public Marshaller(final InternalContext internalContext) { + initialize(internalContext); } /** @@ -341,7 +352,7 @@ * separately. */ public Marshaller () { - initialize(); + initialize(null); } /** @@ -357,7 +368,7 @@ * **/ public Marshaller(final Writer out) throws IOException { - initialize(); + initialize(null); setWriter(out); } @@ -419,7 +430,7 @@ setContentHandler(new DocumentHandlerAdapter(new SAX2DOMHandler(node))); // call internal initializer - initialize(); + initialize(null); } /** @@ -435,11 +446,16 @@ } /** - * Initializes this Marshaller. This is common code shared among the - * Constructors + * Either sets the internalContext as provided - or if null was provided it is + * set to a new instance of {@link BackwardCompatibilityContext}. + * @param internalContext the {@link InternalContext} to set */ - private void initialize() { - setInternalContext(new BackwardCompatibilityContext()); + private void initialize(final InternalContext internalContext) { + if (internalContext == null) { + setInternalContext(new BackwardCompatibilityContext()); + } else { + setInternalContext(internalContext); + } } /** Index: xml/src/main/java/org/exolab/castor/xml/XMLContext.java =================================================================== --- xml/src/main/java/org/exolab/castor/xml/XMLContext.java (revision 8041) +++ xml/src/main/java/org/exolab/castor/xml/XMLContext.java (working copy) @@ -163,8 +163,7 @@ if (LOG.isDebugEnabled()) { LOG.debug("Creating new Marshaller instance."); } - Marshaller marshaller = new Marshaller(); - marshaller.setInternalContext(_internalContext); + Marshaller marshaller = new Marshaller(_internalContext); return marshaller; }