Package com.cedarsoft

Examples of com.cedarsoft.Version


  public void serialize( @NotNull SMOutputElement serializeTo, @NotNull T object, @NotNull Version formatVersion ) throws IOException {
    assert isVersionWritable( formatVersion );

    try {
      SerializingStrategy<T, SMOutputElement, XMLStreamReader, XMLStreamException> strategy = serializingStrategySupport.findStrategy( object );
      Version resolvedVersion = serializingStrategySupport.resolveVersion( strategy, formatVersion );
      serializeTo.addAttribute( ATTRIBUTE_TYPE, strategy.getId() );

      strategy.serialize( serializeTo, object, resolvedVersion );
    } catch ( XMLStreamException e ) {
      throw new IOException( e );
View Full Code Here


    if ( type == null ) {
      throw new XMLStreamException( "No type attribute found. Cannot find strategy." );
    }

    SerializingStrategy<? extends T, SMOutputElement, XMLStreamReader, XMLStreamException> strategy = serializingStrategySupport.findStrategy( type );
    Version resolvedVersion = serializingStrategySupport.resolveVersion( strategy, formatVersion );
    return strategy.deserialize( deserializeFrom, resolvedVersion );
  }
View Full Code Here

  @NonNls
  public static final String ELEMENT_CONTENT_TYPE = "contentType";

  @Inject
  public FileTypeSerializer( @NotNull ExtensionSerializer extensionSerializer ) {
    super( "fileType", "http://www.cedarsoft.com/file/type", new VersionRange( new Version( 1, 0, 0 ), new Version( 1, 0, 1 ) ) );

    add( extensionSerializer ).responsibleFor( Extension.class )
      .map( 1, 0, 0 ).to( 1, 0, 1 ).toDelegateVersion( 1, 0, 0 )
    ;
View Full Code Here

  public Application deserialize( @NotNull XMLStreamReader deserializeFrom, @NotNull 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

      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

    try {
      Document document = new SAXBuilder().build( in );

      ProcessingInstruction processingInstruction = getFormatInstruction( document );

      Version formatVersion = parseVersion( processingInstruction );

      Version.verifyMatch( getFormatVersion(), formatVersion );

      return deserialize( document.getRootElement(), formatVersion );
    } catch ( JDOMException 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

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.