Package org.freezedry.persistence.tree

Examples of org.freezedry.persistence.tree.InfoNode


  {
    // create the root node of the tree, which holds the information about the
    // object we are being asked to persist.
    final Class< ? > clazz = object.getClass();
   
    InfoNode rootNode = null;
   
    // if the object is an array of one or more dimensions, then we need to replace the
    // "[]" which the array suffix (by default = "Array"). Then we use the array node
    // builder to create the semantic model.
    if( clazz.isArray() )
View Full Code Here


    // 4. the object is an array, and the array class hasn't been specified in the node
    //    builder map, then we must treat it as a generic array.
    // the first two cases are handled by the info node builders in the info node builders map. even
    // the leaf node info node builders may need to be overridden. the third case is handled
    // by the compound node
    InfoNode node = null;
    if( containsAnnotatedNodeBuilder( containingClass, fieldName ) )
    {
      final NodeBuilder builder = getAnnotatedNodeBuilder( containingClass, fieldName );
      try
      {
        node = builder.createInfoNode( containingClass, object, fieldName );
      }
      catch( ReflectiveOperationException e )
      {
        final StringBuffer message = new StringBuffer();
        message.append( "Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
        message.append( "  Builder: " + builder.getClass().getName() + Constants.NEW_LINE );
        message.append( "  Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
        message.append( "  Object: " + clazz.getName() + Constants.NEW_LINE );
        message.append( "  Field Name: " + fieldName + Constants.NEW_LINE );
        LOGGER.error( message.toString() );
        throw new IllegalStateException( message.toString(), e );
      }
    }
    else if( containsNodeBuilder( clazz ) )
    {
      final NodeBuilder builder = getNodeBuilder( clazz );
      try
      {
        // if the containing class is null, then this is a root object and we
        // must use the root object version of the createInfoNode method
        if( containingClass == null )
        {
          node = builder.createInfoNode( object, fieldName );
        }
        else
        {
          node = builder.createInfoNode( containingClass, object, fieldName );
        }
      }
      catch( ReflectiveOperationException e )
      {
        final StringBuffer message = new StringBuffer();
        message.append( "Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
        message.append( "  Builder: " + builder.getClass().getName() + Constants.NEW_LINE );
        message.append( "  Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
        message.append( "  Object: " + clazz.getName() + Constants.NEW_LINE );
        message.append( "  Field Name: " + fieldName + Constants.NEW_LINE );
        LOGGER.error( message.toString() );
        throw new IllegalStateException( message.toString(), e );
      }
    }
    else if( clazz.isArray() )
    {
      try
      {
        node = genaralArrayNodeBuilder.createInfoNode( containingClass, object, fieldName );
      }
      catch( ReflectiveOperationException e )
      {
        final StringBuffer message = new StringBuffer();
        message.append( "Default Array Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
        message.append( "  Builder: " + genaralArrayNodeBuilder.getClass().getName() + Constants.NEW_LINE );
        message.append( "  Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
        message.append( "  Object: " + clazz.getName() + Constants.NEW_LINE );
        message.append( "  Field Name: " + fieldName + Constants.NEW_LINE );
        LOGGER.error( message.toString() );
        throw new IllegalStateException( message.toString(), e );
      }
    }
    else
    {
      // create a new compound node to holds this, since it isn't a leaf node, and
      // call (recursively) the addNodes(...) method to add the nodes representing the
      // fields of this object to the newly created compound node.
      final InfoNode compoundNode = InfoNode.createCompoundNode( fieldName, fieldName, clazz );
      node = addNodes( compoundNode, object );
    }
   
    // then call addNodes(...) with the newly created node
    return node;
View Full Code Here

   */
  @Override
  public void write( final Object object, final Writer writer )
  {
    // create the semantic model
    final InfoNode rootNode = getPersistenceEngine().createSemanticModel( object );
    if( LOGGER.isInfoEnabled() )
    {
      LOGGER.info( rootNode.simpleTreeToString() );
    }

    // write out XML
    getPersistenceWriter().write( rootNode, writer );
  }
View Full Code Here

   * @see org.freezedry.persistence.Persistence#read(java.lang.Class, java.io.Reader)
   */
  @Override
  public < T > T read( final Class< ? extends T > clazz, final Reader reader )
  {
    final InfoNode rootNode = getPersistenceReader().read( clazz, reader );
    if( LOGGER.isInfoEnabled() )
    {
      LOGGER.info( rootNode.simpleTreeToString() );
    }
   
    // grab the deserialized object and attempt to cast it to the specified class.
    // if the cast fails, check to see if we need to convert between wrapped types and
    // their primitives
View Full Code Here

  {
    // create the root node of the tree, which holds the information about the
    // object we are being asked to persist.
    final Class< ? > clazz = object.getClass();
   
    InfoNode rootNode = null;
   
    // if the object is an array of one or more dimensions, then we need to replace the
    // "[]" which the array suffix (by default = "Array"). Then we use the array node
    // builder to create the semantic model.
    if( clazz.isArray() )
View Full Code Here

    // 4. the object is an array, and the array class hasn't been specified in the node
    //    builder map, then we must treat it as a generic array.
    // the first two cases are handled by the info node builders in the info node builders map. even
    // the leaf node info node builders may need to be overridden. the third case is handled
    // by the compound node
    InfoNode node = null;
    if( containsAnnotatedNodeBuilder( containingClass, fieldName ) )
    {
      final NodeBuilder builder = getAnnotatedNodeBuilder( containingClass, fieldName );
      try
      {
        node = builder.createInfoNode( containingClass, object, fieldName );
      }
      catch( ReflectiveOperationException e )
      {
        final StringBuffer message = new StringBuffer();
        message.append( "Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
        message.append( "  Builder: " + builder.getClass().getName() + Constants.NEW_LINE );
        message.append( "  Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
        message.append( "  Object: " + clazz.getName() + Constants.NEW_LINE );
        message.append( "  Field Name: " + fieldName + Constants.NEW_LINE );
        LOGGER.error( message.toString() );
        throw new IllegalStateException( message.toString(), e );
      }
    }
    else if( containsNodeBuilder( clazz ) )
    {
      final NodeBuilder builder = getNodeBuilder( clazz );
      try
      {
        // if the containing class is null, then this is a root object and we
        // must use the root object version of the createInfoNode method
        if( containingClass == null )
        {
          node = builder.createInfoNode( object, fieldName );
        }
        else
        {
          node = builder.createInfoNode( containingClass, object, fieldName );
        }
      }
      catch( ReflectiveOperationException e )
      {
        final StringBuffer message = new StringBuffer();
        message.append( "Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
        message.append( "  Builder: " + builder.getClass().getName() + Constants.NEW_LINE );
        message.append( "  Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
        message.append( "  Object: " + clazz.getName() + Constants.NEW_LINE );
        message.append( "  Field Name: " + fieldName + Constants.NEW_LINE );
        LOGGER.error( message.toString() );
        throw new IllegalStateException( message.toString(), e );
      }
    }
    else if( clazz.isArray() )
    {
      try
      {
        node = genaralArrayNodeBuilder.createInfoNode( containingClass, object, fieldName );
      }
      catch( ReflectiveOperationException e )
      {
        final StringBuffer message = new StringBuffer();
        message.append( "Default Array Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
        message.append( "  Builder: " + genaralArrayNodeBuilder.getClass().getName() + Constants.NEW_LINE );
        message.append( "  Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
        message.append( "  Object: " + clazz.getName() + Constants.NEW_LINE );
        message.append( "  Field Name: " + fieldName + Constants.NEW_LINE );
        LOGGER.error( message.toString() );
        throw new IllegalStateException( message.toString(), e );
      }
    }
    else
    {
      // create a new compound node to holds this, since it isn't a leaf node, and
      // call (recursively) the addNodes(...) method to add the nodes representing the
      // fields of this object to the newly created compound node.
      final InfoNode compoundNode = InfoNode.createCompoundNode( fieldName, fieldName, clazz );
      node = addNodes( compoundNode, object );
    }
   
    // then call addNodes(...) with the newly created node
    return node;
View Full Code Here

    }
   
    final String key = keyValues.get( 0 ).getFirst();
    final String value = keyValues.get( 0 ).getSecond();
    final String rawValue = getDecorator( value ).undecorate( value );
    final InfoNode node = InfoNode.createLeafNode( null, rawValue, key, null );
    parentNode.addChild( node );
  }
View Full Code Here

  {
    // create the map for holding the key-value pairs.
    final List< Pair< String, Object > > keyValuePairs = new ArrayList<>();

    // make a deep copy of the semantic model (since there are parts of the code that change the model)
    final InfoNode rootNode = rootInfoNode.getCopy();

    // recursively build the key-value pairs from the info-node tree
    buildKeyValuePairs( rootNode, rootNode.getPersistName(), keyValuePairs );
   
    // once complete, then return the list of key-value pairs
    return keyValuePairs;
  }
View Full Code Here

  {
    // grab the root key from all the values and use it to create the root info node.
    // recall that the root key should have the same name as the clazz we're using as
    // a template.
    final String rootKey = getRootKey( keyValues, clazz );
    final InfoNode rootNode = InfoNode.createRootNode( rootKey, clazz );
   
    // build the semantic model
    buildInfoNode( rootNode, keyValues );
   
    return rootNode;
View Full Code Here

      {
        renderer.buildInfoNode( parentNode, keyValues );
      }
      else
      {
        final InfoNode node = InfoNode.createCompoundNode( null, groupName, null );
        parentNode.addChild( node );
        buildInfoNode( node, keyValues );
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.freezedry.persistence.tree.InfoNode

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.