FileDocCategorySizeDatePackage
AbstractMarshallerImpl.javaAPI DocJava SE 6 API14885Tue Jun 10 00:27:04 BST 2008javax.xml.bind.helpers

AbstractMarshallerImpl

public abstract class AbstractMarshallerImpl extends Object implements Marshaller
Partial default Marshaller implementation.

This class provides a partial default implementation for the {@link javax.xml.bind.Marshaller} interface.

The only methods that a JAXB Provider has to implement are {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.transform.Result)}, {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.stream.XMLStreamWriter)}, and {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.stream.XMLEventWriter)}.

author
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
version
$Revision$ $Date$
see
javax.xml.bind.Marshaller
since
JAXB1.0

Fields Summary
private ValidationEventHandler
eventHandler
handler that will be used to process errors and warnings during marshal
private String
encoding
store the value of the encoding property.
private String
schemaLocation
store the value of the schemaLocation property.
private String
noNSSchemaLocation
store the value of the noNamespaceSchemaLocation property.
private boolean
formattedOutput
store the value of the formattedOutput property.
private boolean
fragment
store the value of the fragment property.
static String[]
aliases
Constructors Summary
Methods Summary
private voidcheckBoolean(java.lang.String name, java.lang.Object value)

        if(!(value instanceof Boolean))
            throw new PropertyException(
                Messages.format( Messages.MUST_BE_BOOLEAN, name ) );
    
private voidcheckNotNull(java.lang.Object o1, java.lang.String o1Name, java.lang.Object o2, java.lang.String o2Name)

    
        if( o1 == null ) {
            throw new IllegalArgumentException( 
                Messages.format( Messages.MUST_NOT_BE_NULL, o1Name ) );
        }
        if( o2 == null ) {
            throw new IllegalArgumentException( 
                Messages.format( Messages.MUST_NOT_BE_NULL, o2Name ) );
        }
    
private voidcheckString(java.lang.String name, java.lang.Object value)

        if(!(value instanceof String))
            throw new PropertyException(
                Messages.format( Messages.MUST_BE_STRING, name ) );
    
public AgetAdapter(java.lang.Class type)

        throw new UnsupportedOperationException();
    
public javax.xml.bind.attachment.AttachmentMarshallergetAttachmentMarshaller()

        throw new UnsupportedOperationException();
    
protected java.lang.StringgetEncoding()
Convenience method for getting the current output encoding.

return
the current encoding or "UTF-8" if it hasn't been set.

        return encoding;
    
public javax.xml.bind.ValidationEventHandlergetEventHandler()

see
javax.xml.bind.Marshaller#getEventHandler()

        return eventHandler;
    
protected java.lang.StringgetJavaEncoding(java.lang.String encoding)
Gets the corresponding Java encoding name from an IANA name. This method is a helper method for the derived class to convert encoding names.

exception
UnsupportedEncodingException If this implementation couldn't find the Java encoding name.

    
                                                   
            
        try {
            "1".getBytes(encoding);
            return encoding;
        } catch( UnsupportedEncodingException e ) {
            // try known alias
            for( int i=0; i<aliases.length; i+=2 ) {
                if(encoding.equals(aliases[i])) {
                    "1".getBytes(aliases[i+1]);
                    return aliases[i+1];
                }
            }
            
            throw new UnsupportedEncodingException(encoding);
        }
        /* J2SE1.4 feature
        try {
            this.encoding = Charset.forName( _encoding );
        } catch( UnsupportedCharsetException uce ) {
            throw new JAXBException( uce );
        }
         */
    
public ListenergetListener()

        throw new UnsupportedOperationException();
    
protected java.lang.StringgetNoNSSchemaLocation()
Convenience method for getting the current noNamespaceSchemaLocation.

return
the current noNamespaceSchemaLocation or null if it hasn't been set

        return noNSSchemaLocation;
    
public org.w3c.dom.NodegetNode(java.lang.Object obj)
By default, the getNode method is unsupported and throw an {@link java.lang.UnsupportedOperationException}. Implementations that choose to support this method must override this method.

        
        checkNotNull( obj, "obj", Boolean.TRUE, "foo" );
        
        throw new UnsupportedOperationException();
    
public java.lang.ObjectgetProperty(java.lang.String name)
Default implementation of the getProperty method handles the four defined properties in Marshaller. If a provider needs to support additional provider specific properties, it should override this method in a derived class.

            
        if( name == null ) {
            throw new IllegalArgumentException( 
                Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) );
        }
        
        // recognize and handle four pre-defined properties.
        if( JAXB_ENCODING.equals(name) )
            return getEncoding();
        if( JAXB_FORMATTED_OUTPUT.equals(name) )
            return isFormattedOutput()?Boolean.TRUE:Boolean.FALSE;
        if( JAXB_NO_NAMESPACE_SCHEMA_LOCATION.equals(name) )
            return getNoNSSchemaLocation();
        if( JAXB_SCHEMA_LOCATION.equals(name) )
            return getSchemaLocation();
        if( JAXB_FRAGMENT.equals(name) )
            return isFragment()?Boolean.TRUE:Boolean.FALSE;

        throw new PropertyException(name);
    
public javax.xml.validation.SchemagetSchema()

        throw new UnsupportedOperationException();
    
protected java.lang.StringgetSchemaLocation()
Convenience method for getting the current schemaLocation.

return
the current schemaLocation or null if it hasn't been set

        return schemaLocation;
    
protected booleanisFormattedOutput()
Convenience method for getting the formatted output flag.

return
the current value of the formatted output flag or false if it hasn't been set.

        return formattedOutput;
    
protected booleanisFragment()
Convenience method for getting the fragment flag.

return
the current value of the fragment flag or false if it hasn't been set.

        return fragment;
    
public final voidmarshal(java.lang.Object obj, java.io.OutputStream os)


            
          
            
        checkNotNull( obj, "obj", os, "os" );
        marshal( obj, new StreamResult(os) );
    
public voidmarshal(java.lang.Object jaxbElement, java.io.File output)

        checkNotNull(jaxbElement, "jaxbElement", output, "output" );
        try {
            OutputStream os = new BufferedOutputStream(new FileOutputStream(output));
            try {
                marshal( jaxbElement, new StreamResult(os) );
            } finally {
                os.close();
            }
        } catch (IOException e) {
            throw new JAXBException(e);
        }
    
public voidmarshal(java.lang.Object obj, javax.xml.stream.XMLEventWriter writer)

        
        throw new UnsupportedOperationException();
    
public voidmarshal(java.lang.Object obj, javax.xml.stream.XMLStreamWriter writer)

        
        throw new UnsupportedOperationException();
    
public final voidmarshal(java.lang.Object obj, java.io.Writer w)

            
        checkNotNull( obj, "obj", w, "writer" );
        marshal( obj, new StreamResult(w) );
    
public final voidmarshal(java.lang.Object obj, org.xml.sax.ContentHandler handler)

            
        checkNotNull( obj, "obj", handler, "handler" );
        marshal( obj, new SAXResult(handler) );
    
public final voidmarshal(java.lang.Object obj, org.w3c.dom.Node node)

            
        checkNotNull( obj, "obj", node, "node" );
        marshal( obj, new DOMResult(node) );
    
public voidsetAdapter(javax.xml.bind.annotation.adapters.XmlAdapter adapter)

        if(adapter==null)
            throw new IllegalArgumentException();
        setAdapter((Class)adapter.getClass(),adapter);
    
public voidsetAdapter(java.lang.Class type, A adapter)

        throw new UnsupportedOperationException();
    
public voidsetAttachmentMarshaller(javax.xml.bind.attachment.AttachmentMarshaller am)

        throw new UnsupportedOperationException();
    
protected voidsetEncoding(java.lang.String encoding)
Convenience method for setting the output encoding.

param
encoding a valid encoding as specified in the Marshaller class documentation

        this.encoding = encoding;
    
public voidsetEventHandler(javax.xml.bind.ValidationEventHandler handler)

see
javax.xml.bind.Marshaller#setEventHandler(ValidationEventHandler)

        
        if( handler == null ) {
            eventHandler = new DefaultValidationEventHandler();
        } else {
            eventHandler = handler;
        }
    
protected voidsetFormattedOutput(boolean v)
Convenience method for setting the formatted output flag.

param
v value of the formatted output flag.

        formattedOutput = v;
    
protected voidsetFragment(boolean v)
Convenience method for setting the fragment flag.

param
v value of the fragment flag.

        fragment = v;
    
public voidsetListener(Listener listener)

        throw new UnsupportedOperationException();
    
protected voidsetNoNSSchemaLocation(java.lang.String location)
Convenience method for setting the noNamespaceSchemaLocation.

param
location the noNamespaceSchemaLocation value

        noNSSchemaLocation = location;
    
public voidsetProperty(java.lang.String name, java.lang.Object value)
Default implementation of the setProperty method handles the four defined properties in Marshaller. If a provider needs to handle additional properties, it should override this method in a derived class.

        
        if( name == null ) {
            throw new IllegalArgumentException( 
                Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) );
        }
        
        // recognize and handle four pre-defined properties.
        if( JAXB_ENCODING.equals(name) ) {
            checkString( name, value );
            setEncoding( (String)value );
            return;
        }
        if( JAXB_FORMATTED_OUTPUT.equals(name) ) {
            checkBoolean( name, value );                    
            setFormattedOutput((Boolean) value );
            return;
        }
        if( JAXB_NO_NAMESPACE_SCHEMA_LOCATION.equals(name) ) {
            checkString( name, value );
            setNoNSSchemaLocation( (String)value );
            return;
        }
        if( JAXB_SCHEMA_LOCATION.equals(name) ) {
            checkString( name, value );
            setSchemaLocation( (String)value );
            return;
        }
        if( JAXB_FRAGMENT.equals(name) )  {
            checkBoolean(name, value);
            setFragment((Boolean) value );
            return;
        }

        throw new PropertyException(name, value);
    
public voidsetSchema(javax.xml.validation.Schema schema)

        throw new UnsupportedOperationException();
    
protected voidsetSchemaLocation(java.lang.String location)
Convenience method for setting the schemaLocation.

param
location the schemaLocation value

        schemaLocation = location;