Package org.freezedry.persistence.tree

Examples of org.freezedry.persistence.tree.InfoNode


    for( String name : names )
    {
      final Object object = JsonUtils.getValue( jsonObject, name );
     
      // build the info node and add it to its parent
      final InfoNode newInfoNode = createInfoNode( name, object, infoNode );
      if( newInfoNode != null )
      {
        infoNode.addChild( newInfoNode );
      }
    }
View Full Code Here


    for( int i = 0; i < jsonArray.length(); ++i )
    {
      final Object object = JsonUtils.getElement( jsonArray, i );
     
      // build the info node and add it to its parent info node
      final InfoNode newInfoNode = createInfoNode( nodeName, object, infoNode );
      infoNode.addChild( newInfoNode );
    }
  }
View Full Code Here

    // there are three possibilities:
    // 1. the value is a json object, in which case the info node is compound
    // 2. the value is a json array, in which case the info node is compound
    // 3. the value is one of the remaining types (boolean, string, int, double, long, etc)
    //    in which case the info node is a leaf
    InfoNode node = null;
    if( value instanceof JSONObject )
    {
      node = InfoNode.createCompoundNode( null, nodeName, null );
      buildInfoNode( (JSONObject)value, node );
    }
View Full Code Here

    }
    if( persistName == null || persistName.isEmpty() )
    {
      persistName = fieldName;
    }
    final InfoNode node = InfoNode.createCompoundNode( fieldName, persistName, clazz );
   
    // grab the annotations for this field and see if the persist name is specified
    // does the class have a @PersistCollection( elementPersistName = "xxxx" )
    String elementPersistName = null;
    try
    {
      // grab the array annotation if the containing class isn't null. If the containing class is null,
      // then later in the code we set the name for which to persist the elements to the classes simple
      // name with the compound array name suffix
      PersistArray arrayAnnotation = null;
      if( containingClass != null && !containingClass.isArray() )
      {
        final Field field = ReflectionUtils.getDeclaredField( containingClass, fieldName );
        arrayAnnotation = field.getAnnotation( PersistArray.class );
      }
      if( arrayAnnotation != null && !arrayAnnotation.elementPersistName().isEmpty() )
      {
        elementPersistName = arrayAnnotation.elementPersistName();
      }
    }
    catch( ReflectiveOperationException e )
    {
      LOGGER.warn( "Field not found in containing class:" + Constants.NEW_LINE +
          "  Containing class: " + containingClass.getName() + Constants.NEW_LINE +
          "  Field name: " + fieldName + Constants.NEW_LINE, e );
    }
   
    // run through the Collection elements, recursively calling createNode(...) to create
    // the appropriate node which to add to the newly created compound node.
    for( int i = 0; i < Array.getLength( object ); ++i )
    {
      // grab the element of the array
      final Class< ? > elementClazz = object.getClass().getComponentType();
     
      String name;
      if( elementPersistName == null )
      {
        name = elementClazz.getSimpleName();
        if( elementClazz.isArray() )
        {
          name = name.replaceAll( "\\[\\]", compoundArrayNameSuffix );
        }
      }
      else
      {
        name = elementPersistName;
      }
     
      // grab the element and create the node. however, because the element may be a primitive
      // we need to set the node's class type to the actual element node. if we don't do this
      // then, for example, all ints will become Integers and if we ask for the type to be
      // set within the node, the type will be incorrect
      final Object element = Array.get( object, i );
      final InfoNode elementNode = createNode( clazz, element, name );
      elementNode.setClazz( elementClazz );
     
      // add the new node as a child to the parent
      node.addChild( elementNode );
    }
   
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 compound name
    final InfoNode node = InfoNode.createCompoundNode( persistName, persistName, clazz );
   
    // run through the Collection elements, recursively calling createNode(...) to create
    // the appropriate node which to add to the newly created compound node.
    for( int i = 0; i < Array.getLength( object ); ++i )
    {
      // grab the array's element type, and then its fully qualified name
      final Class< ? > elementClazz = object.getClass().getComponentType();
      final String name = elementClazz.getSimpleName();
     
      // grab the element and create the node. however, because the element may be a primitive
      // we need to set the node's class type to the actual element node. if we don't do this
      // then, for example, all ints will become Integers and if we ask for the type to be
      // set within the node, the type will be incorrect
      final Object element = Array.get( object, i );
      final InfoNode elementNode = createNode( null, element, name );
      elementNode.setClazz( elementClazz );
     
      // add the new node as a child to the parent
      node.addChild( elementNode );
    }
   
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 primitiveNode = InfoNode.createLeafNode( "value", object, "value", clazz );

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

    {
      persistName = fieldName;
    }

    // create a new leaf node
    final InfoNode node = InfoNode.createLeafNode( fieldName, object, persistName, clazz );
   
    // return the node
    return node;
  }
View Full Code Here

    // grab the class for the object to persist
    final Class< ? > clazz = object.getClass();
   
    // create a new leaf node
    final String name = persistName;//clazz.getName();
    final InfoNode node = InfoNode.createLeafNode( name, object, name, clazz );
   
    // return the node
    return node;
  }
View Full Code Here

    {
      persistName = fieldName;
    }

    // create a compound node that holds the child nodes that forms the element of the Collection.
    final InfoNode node = InfoNode.createCompoundNode( fieldName, persistName, clazz );
   
    // run through the Collection elements, recursively calling createNode(...) to create
    // the appropriate node which to add to the newly created compound node.
    for( Object element : (Collection< ? >)object )
    {
      String name;
      if( elementPersistName == null )
      {
        name = element.getClass().getSimpleName();
      }
      else
      {
        name = elementPersistName;
      }
      node.addChild( createNode( clazz, element, name ) );
    }
   
    return node;
  }
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( persistName, clazz );

    // run through the Collection elements, recursively calling createNode(...) to create
    // the appropriate node which to add to the newly created compound node.
    for( Object element : (Collection< ? >)object )
    {
      node.addChild( createNode( null, element, element.getClass().getName() ) );
    }
   
    return node;
  }
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.