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

org.infrastructurebuilder.data.model.io.xpp3.IBDataSourceModelXpp3ReaderEx 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.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.text.DateFormat;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.infrastructurebuilder.data.model.DataSet;
import org.infrastructurebuilder.data.model.DataSetInputLocation;
import org.infrastructurebuilder.data.model.DataSetInputSource;
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 IBDataSourceModelXpp3ReaderEx.
 * 
 * @version $Revision$ $Date$
 */
public class IBDataSourceModelXpp3ReaderEx
{

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

    /**
     * If set the parser will be loaded with all single characters
     * from the XHTML specification.
     * The entities used:
     * 
    *
  • http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
  • *
  • http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
  • *
  • http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent
  • *
*/ private boolean addDefaultEntities = true; /** * Field contentTransformer. */ public final ContentTransformer contentTransformer; //----------------/ //- Constructors -/ //----------------/ public IBDataSourceModelXpp3ReaderEx() { this( new ContentTransformer() { public String transform( String source, String fieldName ) { return source; } } ); } //-- org.infrastructurebuilder.data.model.io.xpp3.IBDataSourceModelXpp3ReaderEx() public IBDataSourceModelXpp3ReaderEx(ContentTransformer contentTransformer) { this.contentTransformer = contentTransformer; } //-- org.infrastructurebuilder.data.model.io.xpp3.IBDataSourceModelXpp3ReaderEx(ContentTransformer) //-----------/ //- Methods -/ //-----------/ /** * Method checkFieldWithDuplicate. * * @param parser * @param parsed * @param alias * @param tagName * @throws XmlPullParserException * @return boolean */ private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed ) throws XmlPullParserException { if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) ) { return false; } if ( !parsed.add( tagName ) ) { throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null ); } return true; } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set ) /** * Method checkUnknownAttribute. * * @param parser * @param strict * @param tagName * @param attribute * @throws XmlPullParserException * @throws IOException */ private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict ) throws XmlPullParserException, IOException { // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too if ( strict ) { throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null ); } } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean ) /** * Method checkUnknownElement. * * @param parser * @param strict * @throws XmlPullParserException * @throws IOException */ private void checkUnknownElement( XmlPullParser parser, boolean strict ) throws XmlPullParserException, IOException { if ( strict ) { throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null ); } for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; ) { int eventType = parser.next(); if ( eventType == XmlPullParser.START_TAG ) { unrecognizedTagCount++; } else if ( eventType == XmlPullParser.END_TAG ) { unrecognizedTagCount--; } } } //-- void checkUnknownElement( XmlPullParser, boolean ) /** * Returns the state of the "add default entities" flag. * * @return boolean */ public boolean getAddDefaultEntities() { return addDefaultEntities; } //-- boolean getAddDefaultEntities() /** * Method getBooleanValue. * * @param s * @param parser * @param attribute * @throws XmlPullParserException * @return boolean */ private boolean getBooleanValue( String s, String attribute, XmlPullParser parser ) throws XmlPullParserException { return getBooleanValue( s, attribute, parser, null ); } //-- boolean getBooleanValue( String, String, XmlPullParser ) /** * Method getBooleanValue. * * @param s * @param defaultValue * @param parser * @param attribute * @throws XmlPullParserException * @return boolean */ private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue ) throws XmlPullParserException { if ( s != null && s.length() != 0 ) { return Boolean.valueOf( s ).booleanValue(); } if ( defaultValue != null ) { return Boolean.valueOf( defaultValue ).booleanValue(); } return false; } //-- boolean getBooleanValue( String, String, XmlPullParser, String ) /** * Method getByteValue. * * @param s * @param strict * @param parser * @param attribute * @throws XmlPullParserException * @return byte */ private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Byte.valueOf( s ).byteValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe ); } } } return 0; } //-- byte getByteValue( String, String, XmlPullParser, boolean ) /** * Method getCharacterValue. * * @param s * @param parser * @param attribute * @throws XmlPullParserException * @return char */ private char getCharacterValue( String s, String attribute, XmlPullParser parser ) throws XmlPullParserException { if ( s != null ) { return s.charAt( 0 ); } return 0; } //-- char getCharacterValue( String, String, XmlPullParser ) /** * Method getDateValue. * * @param s * @param parser * @param attribute * @throws XmlPullParserException * @return Date */ private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser ) throws XmlPullParserException { return getDateValue( s, attribute, null, parser ); } //-- java.util.Date getDateValue( String, String, XmlPullParser ) /** * Method getDateValue. * * @param s * @param parser * @param dateFormat * @param attribute * @throws XmlPullParserException * @return Date */ private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser ) throws XmlPullParserException { if ( s != null ) { String effectiveDateFormat = dateFormat; if ( dateFormat == null ) { effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"; } if ( "long".equals( effectiveDateFormat ) ) { try { return new java.util.Date( Long.parseLong( s ) ); } catch ( NumberFormatException e ) { throw new XmlPullParserException( e.getMessage(), parser, e ); } } else { try { DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US ); return dateParser.parse( s ); } catch ( java.text.ParseException e ) { throw new XmlPullParserException( e.getMessage(), parser, e ); } } } return null; } //-- java.util.Date getDateValue( String, String, String, XmlPullParser ) /** * Method getDoubleValue. * * @param s * @param strict * @param parser * @param attribute * @throws XmlPullParserException * @return double */ private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Double.valueOf( s ).doubleValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); } } } return 0; } //-- double getDoubleValue( String, String, XmlPullParser, boolean ) /** * Method getFloatValue. * * @param s * @param strict * @param parser * @param attribute * @throws XmlPullParserException * @return float */ private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Float.valueOf( s ).floatValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); } } } return 0; } //-- float getFloatValue( String, String, XmlPullParser, boolean ) /** * Method getIntegerValue. * * @param s * @param strict * @param parser * @param attribute * @throws XmlPullParserException * @return int */ private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Integer.valueOf( s ).intValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe ); } } } return 0; } //-- int getIntegerValue( String, String, XmlPullParser, boolean ) /** * Method getLongValue. * * @param s * @param strict * @param parser * @param attribute * @throws XmlPullParserException * @return long */ private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Long.valueOf( s ).longValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe ); } } } return 0; } //-- long getLongValue( String, String, XmlPullParser, boolean ) /** * Method getRequiredAttributeValue. * * @param s * @param strict * @param parser * @param attribute * @throws XmlPullParserException * @return String */ private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s == null ) { if ( strict ) { throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null ); } } return s; } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean ) /** * Method getShortValue. * * @param s * @param strict * @param parser * @param attribute * @throws XmlPullParserException * @return short */ private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Short.valueOf( s ).shortValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe ); } } } return 0; } //-- short getShortValue( String, String, XmlPullParser, boolean ) /** * Method getTrimmedValue. * * @param s * @return String */ private String getTrimmedValue( String s ) { if ( s != null ) { s = s.trim(); } return s; } //-- String getTrimmedValue( String ) /** * Method interpolatedTrimmed. * * @param value * @param context * @return String */ private String interpolatedTrimmed( String value, String context ) { return getTrimmedValue( contentTransformer.transform( value, context ) ); } //-- String interpolatedTrimmed( String, String ) /** * Method nextTag. * * @param parser * @throws IOException * @throws XmlPullParserException * @return int */ private int nextTag( XmlPullParser parser ) throws IOException, XmlPullParserException { int eventType = parser.next(); if ( eventType == XmlPullParser.TEXT ) { eventType = parser.next(); } if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG ) { throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null ); } return eventType; } //-- int nextTag( XmlPullParser ) /** * @see ReaderFactory#newXmlReader * * @param reader * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return DataSet */ public DataSet read( Reader reader, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( ); parser.setInput( reader ); return read( parser, strict, source ); } //-- DataSet read( Reader, boolean, DataSetInputSource ) /** * Method read. * * @param in * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return DataSet */ public DataSet read( InputStream in, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { return read( ReaderFactory.newXmlReader( in ), strict, source ); } //-- DataSet read( InputStream, boolean, DataSetInputSource ) /** * Method parseDataSet. * * @param parser * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return DataSet */ private DataSet parseDataSet( XmlPullParser parser, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { String tagName = parser.getName(); DataSet dataSet = new DataSet(); DataSetInputLocation _location; _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "", _location ); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else if ( "xmlns".equals( name ) ) { // ignore xmlns attribute in root class, which is a reserved attribute name } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "modelVersion", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "modelVersion", _location ); dataSet.setModelVersion( interpolatedTrimmed( parser.nextText(), "modelVersion" ) ); } else if ( checkFieldWithDuplicate( parser, "groupId", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "groupId", _location ); dataSet.setGroupId( interpolatedTrimmed( parser.nextText(), "groupId" ) ); } else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "artifactId", _location ); dataSet.setArtifactId( interpolatedTrimmed( parser.nextText(), "artifactId" ) ); } else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "version", _location ); dataSet.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) ); } else if ( checkFieldWithDuplicate( parser, "uuid", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "uuid", _location ); dataSet.setUuid( interpolatedTrimmed( parser.nextText(), "uuid" ) ); } else if ( checkFieldWithDuplicate( parser, "dataSetName", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "dataSetName", _location ); dataSet.setDataSetName( interpolatedTrimmed( parser.nextText(), "dataSetName" ) ); } else if ( checkFieldWithDuplicate( parser, "dataSetDescription", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "dataSetDescription", _location ); dataSet.setDataSetDescription( interpolatedTrimmed( parser.nextText(), "dataSetDescription" ) ); } else if ( checkFieldWithDuplicate( parser, "creationDate", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "creationDate", _location ); String dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"; dataSet.setCreationDate( getDateValue( interpolatedTrimmed( parser.nextText(), "creationDate" ), "creationDate", dateFormat, parser ) ); } else if ( checkFieldWithDuplicate( parser, "streams", null, parsed ) ) { java.util.List streams = new java.util.ArrayList(); dataSet.setStreams( streams ); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "stream".equals( parser.getName() ) ) { streams.add( parseDataStream( parser, strict, source ) ); } else { checkUnknownElement( parser, strict ); } } } else if ( checkFieldWithDuplicate( parser, "path", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "path", _location ); dataSet.setPath( interpolatedTrimmed( parser.nextText(), "path" ) ); } else if ( checkFieldWithDuplicate( parser, "metadata", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataSet.setLocation( "metadata", _location ); dataSet.setMetadata( org.codehaus.plexus.util.xml.Xpp3DomBuilder.build( parser, true, new Xpp3DomBuilderInputLocationBuilder( _location ) ) ); } else { checkUnknownElement( parser, strict ); } } return dataSet; } //-- DataSet parseDataSet( XmlPullParser, boolean, DataSetInputSource ) /** * Method parseDataStream. * * @param parser * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return DataStream */ private DataStream parseDataStream( XmlPullParser parser, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { String tagName = parser.getName(); DataStream dataStream = new DataStream(); DataSetInputLocation _location; _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "", _location ); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "uuid", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "uuid", _location ); dataStream.setUuid( interpolatedTrimmed( parser.nextText(), "uuid" ) ); } else if ( checkFieldWithDuplicate( parser, "dataStreamName", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "dataStreamName", _location ); dataStream.setDataStreamName( interpolatedTrimmed( parser.nextText(), "dataStreamName" ) ); } else if ( checkFieldWithDuplicate( parser, "dataStreamDescription", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "dataStreamDescription", _location ); dataStream.setDataStreamDescription( interpolatedTrimmed( parser.nextText(), "dataStreamDescription" ) ); } else if ( checkFieldWithDuplicate( parser, "mimeType", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "mimeType", _location ); dataStream.setMimeType( interpolatedTrimmed( parser.nextText(), "mimeType" ) ); } else if ( checkFieldWithDuplicate( parser, "creationDate", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "creationDate", _location ); String dateFormat = null; dataStream.setCreationDate( getDateValue( interpolatedTrimmed( parser.nextText(), "creationDate" ), "creationDate", dateFormat, parser ) ); } else if ( checkFieldWithDuplicate( parser, "sourceURL", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "sourceURL", _location ); dataStream.setSourceURL( interpolatedTrimmed( parser.nextText(), "sourceURL" ) ); } else if ( checkFieldWithDuplicate( parser, "sha512", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "sha512", _location ); dataStream.setSha512( interpolatedTrimmed( parser.nextText(), "sha512" ) ); } else if ( checkFieldWithDuplicate( parser, "path", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "path", _location ); dataStream.setPath( interpolatedTrimmed( parser.nextText(), "path" ) ); } else if ( checkFieldWithDuplicate( parser, "structuredDataDescriptor", null, parsed ) ) { dataStream.setStructuredDataDescriptor( parseDataStreamStructuredMetadata( parser, strict, source ) ); } else if ( checkFieldWithDuplicate( parser, "originalLength", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "originalLength", _location ); dataStream.setOriginalLength( interpolatedTrimmed( parser.nextText(), "originalLength" ) ); } else if ( checkFieldWithDuplicate( parser, "originalRowCount", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "originalRowCount", _location ); dataStream.setOriginalRowCount( interpolatedTrimmed( parser.nextText(), "originalRowCount" ) ); } else if ( checkFieldWithDuplicate( parser, "metadata", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStream.setLocation( "metadata", _location ); dataStream.setMetadata( org.codehaus.plexus.util.xml.Xpp3DomBuilder.build( parser, true, new Xpp3DomBuilderInputLocationBuilder( _location ) ) ); } else if ( checkFieldWithDuplicate( parser, "provenance", null, parsed ) ) { dataStream.setProvenance( parseDataStreamProvenance( parser, strict, source ) ); } else { checkUnknownElement( parser, strict ); } } return dataStream; } //-- DataStream parseDataStream( XmlPullParser, boolean, DataSetInputSource ) /** * Method parseDataStreamProvenance. * * @param parser * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return DataStreamProvenance */ private DataStreamProvenance parseDataStreamProvenance( XmlPullParser parser, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { String tagName = parser.getName(); DataStreamProvenance dataStreamProvenance = new DataStreamProvenance(); DataSetInputLocation _location; _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStreamProvenance.setLocation( "", _location ); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "originator", null, parsed ) ) { dataStreamProvenance.setOriginator( parseDependency( parser, strict, source ) ); } else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStreamProvenance.setLocation( "url", _location ); dataStreamProvenance.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) ); } else if ( checkFieldWithDuplicate( parser, "transformations", null, parsed ) ) { java.util.List transformations = new java.util.ArrayList(); dataStreamProvenance.setTransformations( transformations ); DataSetInputLocation _locations; _locations = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStreamProvenance.setLocation( "transformations", _locations ); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "transformation".equals( parser.getName() ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); _locations.setLocation( Integer.valueOf( transformations.size() ), _location ); transformations.add( interpolatedTrimmed( parser.nextText(), "transformations" ) ); } else { checkUnknownElement( parser, strict ); } } } else { checkUnknownElement( parser, strict ); } } return dataStreamProvenance; } //-- DataStreamProvenance parseDataStreamProvenance( XmlPullParser, boolean, DataSetInputSource ) /** * Method parseDataStreamStructuredMetadata. * * @param parser * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return DataStreamStructuredMetadata */ private DataStreamStructuredMetadata parseDataStreamStructuredMetadata( XmlPullParser parser, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { String tagName = parser.getName(); DataStreamStructuredMetadata dataStreamStructuredMetadata = new DataStreamStructuredMetadata(); DataSetInputLocation _location; _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStreamStructuredMetadata.setLocation( "", _location ); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "uuid", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dataStreamStructuredMetadata.setLocation( "uuid", _location ); dataStreamStructuredMetadata.setUuid( interpolatedTrimmed( parser.nextText(), "uuid" ) ); } else if ( checkFieldWithDuplicate( parser, "fields", null, parsed ) ) { java.util.List fields = new java.util.ArrayList(); dataStreamStructuredMetadata.setFields( fields ); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "field".equals( parser.getName() ) ) { fields.add( parseStructuredFieldMetadata( parser, strict, source ) ); } else { checkUnknownElement( parser, strict ); } } } else { checkUnknownElement( parser, strict ); } } return dataStreamStructuredMetadata; } //-- DataStreamStructuredMetadata parseDataStreamStructuredMetadata( XmlPullParser, boolean, DataSetInputSource ) /** * Method parseDependency. * * @param parser * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return Dependency */ private Dependency parseDependency( XmlPullParser parser, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { String tagName = parser.getName(); Dependency dependency = new Dependency(); DataSetInputLocation _location; _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dependency.setLocation( "", _location ); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "groupId", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dependency.setLocation( "groupId", _location ); dependency.setGroupId( interpolatedTrimmed( parser.nextText(), "groupId" ) ); } else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dependency.setLocation( "artifactId", _location ); dependency.setArtifactId( interpolatedTrimmed( parser.nextText(), "artifactId" ) ); } else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dependency.setLocation( "version", _location ); dependency.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) ); } else if ( checkFieldWithDuplicate( parser, "extension", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dependency.setLocation( "extension", _location ); dependency.setExtension( interpolatedTrimmed( parser.nextText(), "extension" ) ); } else if ( checkFieldWithDuplicate( parser, "classifier", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); dependency.setLocation( "classifier", _location ); dependency.setClassifier( interpolatedTrimmed( parser.nextText(), "classifier" ) ); } else { checkUnknownElement( parser, strict ); } } return dependency; } //-- Dependency parseDependency( XmlPullParser, boolean, DataSetInputSource ) /** * Method parseStructuredFieldMetadata. * * @param parser * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return StructuredFieldMetadata */ private StructuredFieldMetadata parseStructuredFieldMetadata( XmlPullParser parser, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { String tagName = parser.getName(); StructuredFieldMetadata structuredFieldMetadata = new StructuredFieldMetadata(); DataSetInputLocation _location; _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); structuredFieldMetadata.setLocation( "", _location ); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "index", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); structuredFieldMetadata.setLocation( "index", _location ); structuredFieldMetadata.setIndex( getIntegerValue( interpolatedTrimmed( parser.nextText(), "index" ), "index", parser, strict ) ); } else if ( checkFieldWithDuplicate( parser, "metadataType", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); structuredFieldMetadata.setLocation( "metadataType", _location ); structuredFieldMetadata.setMetadataType( interpolatedTrimmed( parser.nextText(), "metadataType" ) ); } else if ( checkFieldWithDuplicate( parser, "enumerations", null, parsed ) ) { java.util.List enumerations = new java.util.ArrayList(); structuredFieldMetadata.setEnumerations( enumerations ); DataSetInputLocation _locations; _locations = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); structuredFieldMetadata.setLocation( "enumerations", _locations ); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "enumeration".equals( parser.getName() ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); _locations.setLocation( Integer.valueOf( enumerations.size() ), _location ); enumerations.add( interpolatedTrimmed( parser.nextText(), "enumerations" ) ); } else { checkUnknownElement( parser, strict ); } } } else if ( checkFieldWithDuplicate( parser, "max", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); structuredFieldMetadata.setLocation( "max", _location ); structuredFieldMetadata.setMax( interpolatedTrimmed( parser.nextText(), "max" ) ); } else if ( checkFieldWithDuplicate( parser, "min", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); structuredFieldMetadata.setLocation( "min", _location ); structuredFieldMetadata.setMin( interpolatedTrimmed( parser.nextText(), "min" ) ); } else if ( checkFieldWithDuplicate( parser, "nullable", null, parsed ) ) { _location = new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ); structuredFieldMetadata.setLocation( "nullable", _location ); structuredFieldMetadata.setNullable( interpolatedTrimmed( parser.nextText(), "nullable" ) ); } else { checkUnknownElement( parser, strict ); } } return structuredFieldMetadata; } //-- StructuredFieldMetadata parseStructuredFieldMetadata( XmlPullParser, boolean, DataSetInputSource ) /** * Method read. * * @param parser * @param source * @param strict * @throws IOException * @throws XmlPullParserException * @return DataSet */ private DataSet read( XmlPullParser parser, boolean strict, DataSetInputSource source ) throws IOException, XmlPullParserException { DataSet dataSet = null; int eventType = parser.getEventType(); boolean parsed = false; while ( eventType != XmlPullParser.END_DOCUMENT ) { if ( eventType == XmlPullParser.START_TAG ) { if ( strict && ! "dataSet".equals( parser.getName() ) ) { throw new XmlPullParserException( "Expected root element 'dataSet' but found '" + parser.getName() + "'", parser, null ); } else if ( parsed ) { // fallback, already expected a XmlPullParserException due to invalid XML throw new XmlPullParserException( "Duplicated tag: 'dataSet'", parser, null ); } dataSet = parseDataSet( parser, strict, source ); dataSet.setModelEncoding( parser.getInputEncoding() ); parsed = true; } eventType = parser.next(); } if ( parsed ) { return dataSet; } throw new XmlPullParserException( "Expected root element 'dataSet' but found no element at all: invalid XML document", parser, null ); } //-- DataSet read( XmlPullParser, boolean, DataSetInputSource ) /** * Sets the state of the "add default entities" flag. * * @param addDefaultEntities */ public void setAddDefaultEntities( boolean addDefaultEntities ) { this.addDefaultEntities = addDefaultEntities; } //-- void setAddDefaultEntities( boolean ) //-----------------/ //- Inner Classes -/ //-----------------/ /** * Class Xpp3DomBuilderInputLocationBuilder. * * @version $Revision$ $Date$ */ private static class Xpp3DomBuilderInputLocationBuilder implements org.codehaus.plexus.util.xml.Xpp3DomBuilder.InputLocationBuilder { //--------------------------/ //- Class/Member Variables -/ //--------------------------/ /** * Field rootLocation. */ private final DataSetInputLocation rootLocation; //----------------/ //- Constructors -/ //----------------/ public Xpp3DomBuilderInputLocationBuilder(DataSetInputLocation rootLocation) { this.rootLocation = rootLocation; } //-- org.infrastructurebuilder.data.model.io.xpp3.Xpp3DomBuilderInputLocationBuilder(DataSetInputLocation) //-----------/ //- Methods -/ //-----------/ /** * Method toInputLocation. * * @param parser * @return Object */ public Object toInputLocation( XmlPullParser parser ) { return new DataSetInputLocation( parser.getLineNumber(), parser.getColumnNumber(), rootLocation.getSource() ); } //-- Object toInputLocation( XmlPullParser ) } public static interface ContentTransformer { /** * Interpolate the value read from the xpp3 document * @param source The source value * @param fieldName A description of the field being interpolated. The implementation may use this to * log stuff. * @return The interpolated value. */ String transform( String source, String fieldName ); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy