Package com.cedarsoft

Examples of com.cedarsoft.Version


*/
public class ExtraSerializer extends AbstractStaxMateSerializer<Extra> {
  //START SNIPPET: fieldsAndConstructors

  public ExtraSerializer( MoneySerializer moneySerializer ) {
    super( "extra", "http://thecompany.com/test/extra", new VersionRange( new Version( 1, 5, 0 ), new Version( 1, 5, 0 ) ) );
    //We choose another version number. Maybe this is an old serializer that has been created within another project.

    add( moneySerializer ).responsibleFor( Money.class )
      .map( 1, 5, 0 ).toDelegateVersion( 1, 0, 0 )
      ;
View Full Code Here


*
*/
//START SNIPPET: body
public class MoneySerializer extends AbstractStaxMateSerializer<Money> {
  public MoneySerializer() {
    super( "money", "http://thecompany.com/test/money",new VersionRange( new Version( 1, 0, 0 ), new Version( 1, 0, 0 ) ) );
  }
View Full Code Here

*/
public class ModelSerializer extends AbstractStaxMateSerializer<Model> {
  //START SNIPPET: constructor

  public ModelSerializer() {
    super( "model", "http://thecompany.com/test/model", new VersionRange( new Version( 1, 0, 0 ), new Version( 1, 0, 0 ) ) );
  }
View Full Code Here

      if ( namespaceURI == null ) {
        throw new VersionException( "Version information is missing for <" + reader.getName().getLocalPart() + ">" );
      }

      //Parse and verify the version
      Version version = parseVersionFromNamespaceUri( namespaceURI );
      if ( !getFormatVersionRange().contains( version ) ) {
        throw new VersionMismatchException( getFormatVersion(), version );
      }

      //Verify the name space
View Full Code Here

    Serializer<T> serializer = getSerializer();

    Map<? extends Version, ? extends byte[]> serializedMap = getSerialized();

    for ( Map.Entry<? extends Version, ? extends byte[]> entry : serializedMap.entrySet() ) {
      Version version = entry.getKey();
      byte[] serialized = entry.getValue();

      T deserialized = serializer.deserialize( new ByteArrayInputStream( serialized ) );

      verifyDeserialized( deserialized, version );
View Full Code Here

  public T deserialize( @NotNull InputStream in ) throws IOException, VersionException {
    try {
      Document document = new SAXBuilder().build( in );

      String namespaceURI = document.getRootElement().getNamespaceURI();
      Version formatVersion = parseVersionFromNamespaceUri( namespaceURI );

      Version.verifyMatch( getFormatVersion(), formatVersion );

      return deserialize( document.getRootElement(), formatVersion );
    } catch ( JDOMException e ) {
View Full Code Here

    writeSeparator( columns.size(), out );
  }

  private static void writeContent( @NotNull List<? extends Version> keyVersions, @NotNull Iterable<? extends Column> columns, @NotNull Writer out ) throws IOException {
    for ( int i = 0, keyVersionsSize = keyVersions.size(); i < keyVersionsSize; i++ ) {
      Version keyVersion = keyVersions.get( i );
      out.write( extend( keyVersion.format() ) );
      out.write( FIRST_COLUMN_SEPARATOR );


      //Now write the columns
      for ( Column column : columns ) {
View Full Code Here

    private final List<String> lines = new ArrayList<String>();

    public Column( @NotNull String header, @NotNull Iterable<? extends Version> versions ) {
      this.header = header;

      Version lastVersion = null;
      for ( Version version : versions ) {
        if ( version.equals( lastVersion ) ) {
          lines.add( COL_VERSION_REPEAT );
        } else {
          lines.add( version.format() );
View Full Code Here

   *
   * @param delegate              the delegate
   * @param expectedFormatVersion the expected format version
   */
  protected static void verifyDelegatingSerializerVersion( @NotNull Serializer<?> delegate, @NotNull Version expectedFormatVersion ) {
    Version actualVersion = delegate.getFormatVersion();
    if ( !actualVersion.equals( expectedFormatVersion ) ) {
      throw new IllegalArgumentException( "Invalid versions. Expected <" + expectedFormatVersion + "> but was <" + actualVersion + ">" );
    }
  }
View Full Code Here

      throw new VersionException( "No mappings available" );
    }

    //Check whether the minimum equals the expected version range minimum
    {
      Version currentMin = entries.get( 0 ).getVersionRange().getMin();
      if ( !currentMin.equals( sourceVersionRange.getMin() ) ) {
        throw new VersionMismatchException( sourceVersionRange.getMin(), currentMin, "Lower border of source range not mapped: " );
      }
    }

    //Verify the last entry. Does the max version range fit?
    {
      Entry last = entries.get( entries.size() - 1 );
      Version currentMax = last.getVersionRange().getMax();
      if ( !currentMax.equals( sourceVersionRange.getMax() ) ) {
        throw new VersionMismatchException( sourceVersionRange.getMax(), currentMax, "Upper border of source range not mapped: " );
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.cedarsoft.Version

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.