Package org.freezedry.persistence.tree

Examples of org.freezedry.persistence.tree.InfoNode


    }
    else
    {
      rawValue = decorator.undecorate( value );
    }
    final InfoNode node = InfoNode.createLeafNode( null, rawValue, key, null );
    parentNode.addChild( node );
  }
View Full Code Here


    }
    if( persistName == null || persistName.isEmpty() )
    {
      persistName = fieldName;
    }
    final InfoNode node = InfoNode.createCompoundNode( fieldName, persistName, clazz );
   
    // set the entry, key, and value persistence names to the default value of the annotation. if the
    // map field is annotated, then we over write the default values with the annotated values.
    // does the class have a @PersistMap( keyPersistName = "xxxx", valuePersistName = "yyyy", entryPeristName = "zzzz" )
    String entryPersistName = PersistMap.ENTRY_PERSIST_NAME;
    String keyPersistName = PersistMap.KEY_PERSIST_NAME;
    String valuePersistName = PersistMap.VALUE_PERSIST_NAME;
    try
    {
      final Field field = ReflectionUtils.getDeclaredField( containingClass, fieldName );
      final PersistMap mapAnnotation = field.getAnnotation( PersistMap.class );
      if( mapAnnotation != null )
      {
        if( !mapAnnotation.entryPersistName().isEmpty() )
        {
          entryPersistName = mapAnnotation.entryPersistName();
        }
        if( !mapAnnotation.keyPersistName().isEmpty() )
        {
          keyPersistName = mapAnnotation.keyPersistName();
        }
        if( !mapAnnotation.valuePersistName().isEmpty() )
        {
          valuePersistName = mapAnnotation.valuePersistName();
        }
      }
    }
    catch( ReflectiveOperationException e )
    {
      final StringBuffer message = new StringBuffer();
      message.append( "Field not found in containing class:" + Constants.NEW_LINE );
      message.append( "  Containing class: " + containingClass.getName() + Constants.NEW_LINE );
      message.append( "  Field name: " + fieldName + Constants.NEW_LINE );
      LOGGER.debug( message.toString() );
    }
   
    // run through the Map entries, recursively calling createNode(...) to create
    // the appropriate node which to add to the newly created compound node.
    for( Map.Entry< ?, ? > entry : ((Map< ?, ? >)object).entrySet() )
    {
      // create the map entry node
      final InfoNode entryNode = InfoNode.createCompoundNode( "", entryPersistName, entry.getClass() );
     
      // create the key node and add it to the entry node
      entryNode.addChild( createNode( clazz, entry.getKey(), keyPersistName ) );
     
      // create the value node and add it to the entry node
      entryNode.addChild( createNode( clazz, entry.getValue(), valuePersistName ) );
     
      // add the entry node to the info node representing the map
      node.addChild( entryNode );
    }
   
View Full Code Here

    // create the InfoNode object (we first have to determine the node type, down the road, we'll check the
    // factories for registered node generators for the Class< ? > of the object)
    final Class< ? > clazz = object.getClass();

    // create the root node
    final InfoNode node = InfoNode.createRootNode( clazz.getName(), clazz );

    // run through the Collection elements, recursively calling createNode(...) to create
    // the appropriate node which to add to the newly created compound node.
    // run through the Map entries, recursively calling createNode(...) to create
    // the appropriate node which to add to the newly created compound node.
    for( Map.Entry< ?, ? > entry : ((Map< ?, ? >)object).entrySet() )
    {
      // create the map entry node
      final InfoNode entryNode = InfoNode.createCompoundNode( "", entry.getClass().getSimpleName(), entry.getClass() );
     
      // create the key node and add it to the entry node
      entryNode.addChild( createNode( null, entry.getKey(), KEY_PREFIX + KEY_VALUE_SEPARATOR + entry.getKey().getClass().getName() ) );
     
      // create the value node and add it to the entry node
      entryNode.addChild( createNode( null, entry.getValue(), VALUE_PREFIX + KEY_VALUE_SEPARATOR + entry.getValue().getClass().getName() ) );
     
      // add the entry node to the info node representing the map
      node.addChild( entryNode );
    }
   
View Full Code Here

     
      // the order of the elements can be reversed. For example, the key could be the second
      // element (instead of the first) and the value could be the first. We check both possibilities
      Object key = null;
      Object value = null;
      final InfoNode firstNode = keyValue.get( 0 );
      final InfoNode secondNode = keyValue.get( 1 );
      if( keyPersistenceName.equals( firstNode.getPersistName() ) &&
        valuePersistenceName.equals( secondNode.getPersistName() )  )
      {
        key = buildObject( containingClass, keyClass, keyTypes, firstNode, node );
        value = buildObject( containingClass, valueClass, valueTypes, secondNode, node );
      }
      else if( keyPersistenceName.equals( secondNode.getPersistName() ) &&
           valuePersistenceName.equals( firstNode.getPersistName() ) )
      {
        key = buildObject( containingClass, keyClass, keyTypes, secondNode, node );
        value = buildObject( containingClass, valueClass, valueTypes, firstNode, node );
      }
View Full Code Here

        throw new IllegalArgumentException( message.toString() );
      }
     
      // the order of the elements can be reversed. For example, the key could be the second
      // element (instead of the first) and the value could be the first. We check both possibilities
      final InfoNode firstNode = keyValue.get( 0 );
      final InfoNode secondNode = keyValue.get( 1 );
      Pair< Object, Object > keyValuePair = null;
      if( firstNode.getPersistName().startsWith( KEY_PREFIX + KEY_VALUE_SEPARATOR ) &&
        secondNode.getPersistName().startsWith( VALUE_PREFIX + KEY_VALUE_SEPARATOR ) )
      {
        keyValuePair = getKeyValuePair( firstNode, secondNode, node );
      }
      else if( firstNode.getPersistName().startsWith( VALUE_PREFIX + KEY_VALUE_SEPARATOR ) &&
           secondNode.getPersistName().startsWith( KEY_PREFIX + KEY_VALUE_SEPARATOR ) )
      {
        keyValuePair = getKeyValuePair( secondNode, firstNode, node );
      }

      // add the new objects to the map
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

   * @return The flattened version of the object
   * @see KeyValueBuilder
   */
  public final Map< String, Object > flattenObject( final Object object )
  {
    final InfoNode rootNode = persistenceEngine.createSemanticModel( object );
    return mapWriter.createMap( rootNode );
  }
View Full Code Here

  {
    // grab the class for the object to persist
    final Class< ? > clazz = object.getClass();
   
    // we must convert the object to the appropriate format
    final InfoNode stringNode = InfoNode.createLeafNode( "value", (String)object, "value", String.class );

    // create the root node and add the string rep of the date
    final InfoNode node = InfoNode.createRootNode( persistName, clazz );
    node.addChild( stringNode );
   
    // return the node
    return node;
  }
View Full Code Here

   * @see org.freezedry.persistence.builders.AbstractLeafNodeBuilder#createObject(java.lang.Class, org.freezedry.persistence.tree.InfoNode)
   */
  @Override
  public String createObject( final Class< ? > clazz, final InfoNode node ) throws ReflectiveOperationException
  {
    final InfoNode valueNode = node.getChild( 0 );
    final String value = (String)valueNode.getValue();
    return value;
  }
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.