Package com.cedarsoft.version

Examples of com.cedarsoft.version.Version


   */
  @Theory
  public void testVersion( @Nonnull VersionEntry entry ) throws Exception {
    Serializer<T, OutputStream, InputStream> serializer = getSerializer();

    Version version = entry.getVersion();
    byte[] serialized = entry.getSerialized( serializer );

    T deserialized = serializer.deserialize( new ByteArrayInputStream( serialized ) );
    verifyDeserialized( deserialized, version );
  }
View Full Code Here


    Serializer<T, OutputStream, InputStream> 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

      verifyType(in);
    } catch (InvalidTypeException e) {
      throw new IOException("Could not parse due to " + e.getMessage(), e);
    }

    Version version = readVersion( in );
    verifyVersionReadable(version);

    return deserialize(in, version);
  }
View Full Code Here

  @Override
  protected void serializeInternal( @Nonnull Node serializeTo, @Nonnull T object, @Nonnull Version formatVersion ) throws IOException {
    assert isVersionWritable( formatVersion );

    SerializingStrategy<T, Node, Node, IOException, Node, Node> strategy = serializingStrategySupport.findStrategy( object );
    Version resolvedVersion = serializingStrategySupport.resolveVersion( strategy, formatVersion );

    serializeTo.setProperty( PROPERTY_SUB_TYPE, strategy.getId() );

    strategy.serialize( serializeTo, object, resolvedVersion );
  }
View Full Code Here

    assert isVersionReadable( formatVersion );

    try {
      @Nonnull String subType = ( String ) deserializeFrom.getProperty( PROPERTY_SUB_TYPE );
      SerializingStrategy<? extends T, Node, Node, IOException, Node, Node> strategy = serializingStrategySupport.findStrategy( subType );
      Version resolvedVersion = serializingStrategySupport.resolveVersion( strategy, formatVersion );
      return strategy.deserialize( deserializeFrom, resolvedVersion );

    } catch ( NotFoundException e ) {
      throw new IOException( "Invalid node. Expected property <" + PROPERTY_SUB_TYPE + "> but only contained <" + deserializeFrom.getPropertyKeys() + "> @ " + deserializeFrom.getId(), e );
    }
View Full Code Here

*/
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, 1 ) ) );
    //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 )
      .map( 1, 5, 1 ).toDelegateVersion( 1, 0, 1 ) //this is the only line that has to be added! Everything else (below) stays the same!
View Full Code Here

* Writing is only supported for the latest file.
*/
public class MoneySerializer extends AbstractStaxMateSerializer<Money> {
  public MoneySerializer() {
    //This serializer supports an old version, too
    super( "money", "http://thecompany.com/test/money", new VersionRange( new Version( 1, 0, 0 ), new Version( 1, 0, 1 ) ) );
  }
View Full Code Here

    //So it seems easier to add just one if/else.
    //If a serializer evolves further a switch to the strategy pattern might be done. A simple map holding the strategies should do it.


    //The common case - current version
    if ( formatVersion.equals( new Version( 1, 0, 1 ) ) ) {
      int cents = Integer.parseInt( deserializeFrom.getAttributeValue( null, "cents" ) );

      //We have to close the tag! Every stax based serializer has to close its tag
      //getText does this automatically for us. But when only using attributes, we have to close it manually.
      closeTag( deserializeFrom );

      return new Money( cents );

      //The old format that does not use an attribute but text instead
    } else if ( formatVersion.equals( new Version( 1, 0, 0 ) ) ) {
      int cents = Integer.parseInt( getText( deserializeFrom ) );

      //We don't have to close the tag. The getText method does that for us
      return new Money( cents );
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

  public Application deserialize( @Nonnull XMLStreamReader deserializeFrom, @Nonnull Version formatVersion ) throws IOException, XMLStreamException {
    assert isVersionReadable( formatVersion );
    String name = getChildText( deserializeFrom, ELEMENT_NAME );

    nextTag( deserializeFrom, ELEMENT_VERSION );
    Version applicationVersion = deserialize( Version.class, formatVersion, deserializeFrom );
    closeTag( deserializeFrom );

    return new Application( name, applicationVersion );
  }
View Full Code Here

TOP

Related Classes of com.cedarsoft.version.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.