All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infrastructurebuilder.data.model.io.xpp3.IBDataSourceModelXpp3Writer Maven / Gradle / Ivy

The newest version!
// =================== DO NOT EDIT THIS FILE ====================
// Generated by Modello 1.11,
// any modifications will be overwritten.
// ==============================================================

package org.infrastructurebuilder.data.model.io.xpp3;

  //---------------------------------/
 //- Imported classes and packages -/
//---------------------------------/

import java.io.OutputStream;
import java.io.Writer;
import java.util.Iterator;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.MXSerializer;
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
import org.infrastructurebuilder.data.model.DataSet;
import org.infrastructurebuilder.data.model.DataStream;
import org.infrastructurebuilder.data.model.DataStreamProvenance;
import org.infrastructurebuilder.data.model.DataStreamStructuredMetadata;
import org.infrastructurebuilder.data.model.Dependency;
import org.infrastructurebuilder.data.model.StructuredFieldMetadata;

/**
 * Class IBDataSourceModelXpp3Writer.
 * 
 * @version $Revision$ $Date$
 */
public class IBDataSourceModelXpp3Writer
{

      //--------------------------/
     //- Class/Member Variables -/
    //--------------------------/

    /**
     * Field NAMESPACE.
     */
    private static final String NAMESPACE = null;

    /**
     * Field fileComment.
     */
    private String fileComment = null;


      //-----------/
     //- Methods -/
    //-----------/

    /**
     * Method setFileComment.
     * 
     * @param fileComment
     */
    public void setFileComment( String fileComment )
    {
        this.fileComment = fileComment;
    } //-- void setFileComment( String )

    /**
     * Method write.
     * 
     * @param writer
     * @param dataSet
     * @throws java.io.IOException
     */
    public void write( Writer writer, DataSet dataSet )
        throws java.io.IOException
    {
        XmlSerializer serializer = new MXSerializer();
        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
        serializer.setOutput( writer );
        serializer.startDocument( dataSet.getModelEncoding(), null );
        writeDataSet( dataSet, "dataSet", serializer );
        serializer.endDocument();
    } //-- void write( Writer, DataSet )

    /**
     * Method write.
     * 
     * @param stream
     * @param dataSet
     * @throws java.io.IOException
     */
    public void write( OutputStream stream, DataSet dataSet )
        throws java.io.IOException
    {
        XmlSerializer serializer = new MXSerializer();
        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
        serializer.setOutput( stream, dataSet.getModelEncoding() );
        serializer.startDocument( dataSet.getModelEncoding(), null );
        writeDataSet( dataSet, "dataSet", serializer );
        serializer.endDocument();
    } //-- void write( OutputStream, DataSet )

    /**
     * Method writeDataSet.
     * 
     * @param dataSet
     * @param serializer
     * @param tagName
     * @throws java.io.IOException
     */
    private void writeDataSet( DataSet dataSet, String tagName, XmlSerializer serializer )
        throws java.io.IOException
    {
        if ( this.fileComment != null )
        {
        serializer.comment(this.fileComment);
        }
        serializer.setPrefix( "", "https://resources.infrastructurebuilder.org/IBDataSet/0.15" );
        serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
        serializer.startTag( NAMESPACE, tagName );
        serializer.attribute( "", "xsi:schemaLocation", "https://resources.infrastructurebuilder.org/IBDataSet/0.15 https://resources.infrastructurebuilder.org/xsd/IBDataSet-0.15" );
        if ( dataSet.getModelVersion() != null )
        {
            serializer.startTag( NAMESPACE, "modelVersion" ).text( dataSet.getModelVersion() ).endTag( NAMESPACE, "modelVersion" );
        }
        if ( dataSet.getGroupId() != null )
        {
            serializer.startTag( NAMESPACE, "groupId" ).text( dataSet.getGroupId() ).endTag( NAMESPACE, "groupId" );
        }
        if ( dataSet.getArtifactId() != null )
        {
            serializer.startTag( NAMESPACE, "artifactId" ).text( dataSet.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
        }
        if ( dataSet.getVersion() != null )
        {
            serializer.startTag( NAMESPACE, "version" ).text( dataSet.getVersion() ).endTag( NAMESPACE, "version" );
        }
        if ( dataSet.getUuid() != null )
        {
            serializer.startTag( NAMESPACE, "uuid" ).text( dataSet.getUuid() ).endTag( NAMESPACE, "uuid" );
        }
        if ( dataSet.getDataSetName() != null )
        {
            serializer.startTag( NAMESPACE, "dataSetName" ).text( dataSet.getDataSetName() ).endTag( NAMESPACE, "dataSetName" );
        }
        if ( dataSet.getDataSetDescription() != null )
        {
            serializer.startTag( NAMESPACE, "dataSetDescription" ).text( dataSet.getDataSetDescription() ).endTag( NAMESPACE, "dataSetDescription" );
        }
        if ( dataSet.getCreationDate() != null )
        {
            serializer.startTag( NAMESPACE, "creationDate" ).text( new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS", java.util.Locale.US ).format( dataSet.getCreationDate() ) ).endTag( NAMESPACE, "creationDate" );
        }
        if ( ( dataSet.getStreams() != null ) && ( dataSet.getStreams().size() > 0 ) )
        {
            serializer.startTag( NAMESPACE, "streams" );
            for ( Iterator iter = dataSet.getStreams().iterator(); iter.hasNext(); )
            {
                DataStream o = (DataStream) iter.next();
                writeDataStream( o, "stream", serializer );
            }
            serializer.endTag( NAMESPACE, "streams" );
        }
        if ( dataSet.getPath() != null )
        {
            serializer.startTag( NAMESPACE, "path" ).text( dataSet.getPath() ).endTag( NAMESPACE, "path" );
        }
        if ( dataSet.getMetadata() != null )
        {
            ((Xpp3Dom) dataSet.getMetadata()).writeToSerializer( NAMESPACE, serializer );
        }
        serializer.endTag( NAMESPACE, tagName );
    } //-- void writeDataSet( DataSet, String, XmlSerializer )

    /**
     * Method writeDataStream.
     * 
     * @param dataStream
     * @param serializer
     * @param tagName
     * @throws java.io.IOException
     */
    private void writeDataStream( DataStream dataStream, String tagName, XmlSerializer serializer )
        throws java.io.IOException
    {
        serializer.startTag( NAMESPACE, tagName );
        if ( dataStream.getUuid() != null )
        {
            serializer.startTag( NAMESPACE, "uuid" ).text( dataStream.getUuid() ).endTag( NAMESPACE, "uuid" );
        }
        if ( dataStream.getDataStreamName() != null )
        {
            serializer.startTag( NAMESPACE, "dataStreamName" ).text( dataStream.getDataStreamName() ).endTag( NAMESPACE, "dataStreamName" );
        }
        if ( dataStream.getDataStreamDescription() != null )
        {
            serializer.startTag( NAMESPACE, "dataStreamDescription" ).text( dataStream.getDataStreamDescription() ).endTag( NAMESPACE, "dataStreamDescription" );
        }
        if ( ( dataStream.getMimeType() != null ) && !dataStream.getMimeType().equals( "application/octet-stream" ) )
        {
            serializer.startTag( NAMESPACE, "mimeType" ).text( dataStream.getMimeType() ).endTag( NAMESPACE, "mimeType" );
        }
        if ( dataStream.getCreationDate() != null )
        {
            serializer.startTag( NAMESPACE, "creationDate" ).text( new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS", java.util.Locale.US ).format( dataStream.getCreationDate() ) ).endTag( NAMESPACE, "creationDate" );
        }
        if ( dataStream.getSourceURL() != null )
        {
            serializer.startTag( NAMESPACE, "sourceURL" ).text( dataStream.getSourceURL() ).endTag( NAMESPACE, "sourceURL" );
        }
        if ( dataStream.getSha512() != null )
        {
            serializer.startTag( NAMESPACE, "sha512" ).text( dataStream.getSha512() ).endTag( NAMESPACE, "sha512" );
        }
        if ( dataStream.getPath() != null )
        {
            serializer.startTag( NAMESPACE, "path" ).text( dataStream.getPath() ).endTag( NAMESPACE, "path" );
        }
        if ( dataStream.getStructuredDataDescriptor() != null )
        {
            writeDataStreamStructuredMetadata( (DataStreamStructuredMetadata) dataStream.getStructuredDataDescriptor(), "structuredDataDescriptor", serializer );
        }
        if ( dataStream.getOriginalLength() != null )
        {
            serializer.startTag( NAMESPACE, "originalLength" ).text( dataStream.getOriginalLength() ).endTag( NAMESPACE, "originalLength" );
        }
        if ( dataStream.getOriginalRowCount() != null )
        {
            serializer.startTag( NAMESPACE, "originalRowCount" ).text( dataStream.getOriginalRowCount() ).endTag( NAMESPACE, "originalRowCount" );
        }
        if ( dataStream.getMetadata() != null )
        {
            ((Xpp3Dom) dataStream.getMetadata()).writeToSerializer( NAMESPACE, serializer );
        }
        if ( dataStream.getProvenance() != null )
        {
            writeDataStreamProvenance( (DataStreamProvenance) dataStream.getProvenance(), "provenance", serializer );
        }
        serializer.endTag( NAMESPACE, tagName );
    } //-- void writeDataStream( DataStream, String, XmlSerializer )

    /**
     * Method writeDataStreamProvenance.
     * 
     * @param dataStreamProvenance
     * @param serializer
     * @param tagName
     * @throws java.io.IOException
     */
    private void writeDataStreamProvenance( DataStreamProvenance dataStreamProvenance, String tagName, XmlSerializer serializer )
        throws java.io.IOException
    {
        serializer.startTag( NAMESPACE, tagName );
        if ( dataStreamProvenance.getOriginator() != null )
        {
            writeDependency( (Dependency) dataStreamProvenance.getOriginator(), "originator", serializer );
        }
        if ( dataStreamProvenance.getUrl() != null )
        {
            serializer.startTag( NAMESPACE, "url" ).text( dataStreamProvenance.getUrl() ).endTag( NAMESPACE, "url" );
        }
        if ( ( dataStreamProvenance.getTransformations() != null ) && ( dataStreamProvenance.getTransformations().size() > 0 ) )
        {
            serializer.startTag( NAMESPACE, "transformations" );
            for ( Iterator iter = dataStreamProvenance.getTransformations().iterator(); iter.hasNext(); )
            {
                String transformation = (String) iter.next();
                serializer.startTag( NAMESPACE, "transformation" ).text( transformation ).endTag( NAMESPACE, "transformation" );
            }
            serializer.endTag( NAMESPACE, "transformations" );
        }
        serializer.endTag( NAMESPACE, tagName );
    } //-- void writeDataStreamProvenance( DataStreamProvenance, String, XmlSerializer )

    /**
     * Method writeDataStreamStructuredMetadata.
     * 
     * @param dataStreamStructuredMetadata
     * @param serializer
     * @param tagName
     * @throws java.io.IOException
     */
    private void writeDataStreamStructuredMetadata( DataStreamStructuredMetadata dataStreamStructuredMetadata, String tagName, XmlSerializer serializer )
        throws java.io.IOException
    {
        serializer.startTag( NAMESPACE, tagName );
        if ( dataStreamStructuredMetadata.getUuid() != null )
        {
            serializer.startTag( NAMESPACE, "uuid" ).text( dataStreamStructuredMetadata.getUuid() ).endTag( NAMESPACE, "uuid" );
        }
        if ( ( dataStreamStructuredMetadata.getFields() != null ) && ( dataStreamStructuredMetadata.getFields().size() > 0 ) )
        {
            serializer.startTag( NAMESPACE, "fields" );
            for ( Iterator iter = dataStreamStructuredMetadata.getFields().iterator(); iter.hasNext(); )
            {
                StructuredFieldMetadata o = (StructuredFieldMetadata) iter.next();
                writeStructuredFieldMetadata( o, "field", serializer );
            }
            serializer.endTag( NAMESPACE, "fields" );
        }
        serializer.endTag( NAMESPACE, tagName );
    } //-- void writeDataStreamStructuredMetadata( DataStreamStructuredMetadata, String, XmlSerializer )

    /**
     * Method writeDependency.
     * 
     * @param dependency
     * @param serializer
     * @param tagName
     * @throws java.io.IOException
     */
    private void writeDependency( Dependency dependency, String tagName, XmlSerializer serializer )
        throws java.io.IOException
    {
        serializer.startTag( NAMESPACE, tagName );
        if ( dependency.getGroupId() != null )
        {
            serializer.startTag( NAMESPACE, "groupId" ).text( dependency.getGroupId() ).endTag( NAMESPACE, "groupId" );
        }
        if ( dependency.getArtifactId() != null )
        {
            serializer.startTag( NAMESPACE, "artifactId" ).text( dependency.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
        }
        if ( dependency.getVersion() != null )
        {
            serializer.startTag( NAMESPACE, "version" ).text( dependency.getVersion() ).endTag( NAMESPACE, "version" );
        }
        if ( dependency.getExtension() != null )
        {
            serializer.startTag( NAMESPACE, "extension" ).text( dependency.getExtension() ).endTag( NAMESPACE, "extension" );
        }
        if ( dependency.getClassifier() != null )
        {
            serializer.startTag( NAMESPACE, "classifier" ).text( dependency.getClassifier() ).endTag( NAMESPACE, "classifier" );
        }
        serializer.endTag( NAMESPACE, tagName );
    } //-- void writeDependency( Dependency, String, XmlSerializer )

    /**
     * Method writeStructuredFieldMetadata.
     * 
     * @param structuredFieldMetadata
     * @param serializer
     * @param tagName
     * @throws java.io.IOException
     */
    private void writeStructuredFieldMetadata( StructuredFieldMetadata structuredFieldMetadata, String tagName, XmlSerializer serializer )
        throws java.io.IOException
    {
        serializer.startTag( NAMESPACE, tagName );
        if ( structuredFieldMetadata.getIndex() != -1 )
        {
            serializer.startTag( NAMESPACE, "index" ).text( String.valueOf( structuredFieldMetadata.getIndex() ) ).endTag( NAMESPACE, "index" );
        }
        if ( structuredFieldMetadata.getMetadataType() != null )
        {
            serializer.startTag( NAMESPACE, "metadataType" ).text( structuredFieldMetadata.getMetadataType() ).endTag( NAMESPACE, "metadataType" );
        }
        if ( ( structuredFieldMetadata.getEnumerations() != null ) && ( structuredFieldMetadata.getEnumerations().size() > 0 ) )
        {
            serializer.startTag( NAMESPACE, "enumerations" );
            for ( Iterator iter = structuredFieldMetadata.getEnumerations().iterator(); iter.hasNext(); )
            {
                String enumeration = (String) iter.next();
                serializer.startTag( NAMESPACE, "enumeration" ).text( enumeration ).endTag( NAMESPACE, "enumeration" );
            }
            serializer.endTag( NAMESPACE, "enumerations" );
        }
        if ( structuredFieldMetadata.getMax() != null )
        {
            serializer.startTag( NAMESPACE, "max" ).text( structuredFieldMetadata.getMax() ).endTag( NAMESPACE, "max" );
        }
        if ( structuredFieldMetadata.getMin() != null )
        {
            serializer.startTag( NAMESPACE, "min" ).text( structuredFieldMetadata.getMin() ).endTag( NAMESPACE, "min" );
        }
        if ( structuredFieldMetadata.getNullable() != null )
        {
            serializer.startTag( NAMESPACE, "nullable" ).text( structuredFieldMetadata.getNullable() ).endTag( NAMESPACE, "nullable" );
        }
        serializer.endTag( NAMESPACE, tagName );
    } //-- void writeStructuredFieldMetadata( StructuredFieldMetadata, String, XmlSerializer )

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy