Package org.freezedry.persistence.tree

Examples of org.freezedry.persistence.tree.InfoNode


//    }
   
//    final int[] test = new int[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3 };
    final int[][] test = new int[][] { { 3, 1 }, { 4, 1 }, { 5, 9 }, { 2, 6 }, { 5, 3 } };
    final PersistenceEngine engine = new PersistenceEngine();
    final InfoNode rootNode = engine.createSemanticModel( test );
    System.out.println( rootNode.treeToString() );

    try( final PrintWriter printWriter = new PrintWriter( new FileWriter( "test.xml" ) ) )
    {
      final XmlWriter writer = new XmlWriter();
      // uncomment this to prevent type information to be written to XML
View Full Code Here


   
    // we must convert the object to the appropriate format
    final String date = DateUtils.createStringFromDate( (Calendar)object, dateFormat );
   
    // create a new leaf node with the new date string
    final InfoNode node = InfoNode.createLeafNode( fieldName, date, persistName, clazz );
   
    // return the node
    return node;
  }
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 String date = DateUtils.createStringFromDate( (Calendar)object, ISO_8601_DATE_FORMAT );
    final InfoNode stringNode = InfoNode.createLeafNode( "value", date, "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 Calendar createObject( final Class< ? > clazz, final InfoNode node )
  {
    final InfoNode valueNode = node.getChild( 0 );
    final String value = (String)valueNode.getValue();
    // try the ISO 8601 format (strict)
    Calendar date = null;
    try
    {
      date = DateUtils.createDateFromString( value, ISO_8601_DATE_FORMAT );
View Full Code Here

    {
      LOGGER.info( DomUtils.toString( document ) );
    }

    // convert the DOM tree to an InfoNode tree (from which we can build the object)
    final InfoNode node = buildInfoNode( clazz, document );
   
    return node;
  }
View Full Code Here

   * @return The {@link InfoNode} tree representing the DOM
   * @throws ClassNotFoundException
   */
  public static InfoNode buildInfoNode( final Class< ? > rootClass, final Document document )
  {
    InfoNode rootInfoNode = null;
//    if( hosOnlyTextChildNodes( document ) )
//    {
//      rootInfoNode = InfoNode.createRootNode( rootClass.getSimpleName(), rootClass );
//     
//      final Node textNode = document.getChildNodes().item( 0 );
View Full Code Here

    final NodeList domSubnodes = domNode.getChildNodes();
    for( int i = 0; i < domSubnodes.getLength(); ++i )
    {
      // grab the sub node for the index, create an info node, and add it to the parent
      final Node domSubnode = domSubnodes.item( i );
      final InfoNode newInfoNode = createInfoNode( domSubnode );
      infoNode.addChild( newInfoNode );
    }
  }
View Full Code Here

      message.append( "Nodes can either have elements or one text element." );
      LOGGER.error( message.toString() );
      throw new IllegalStateException( message.toString() );
    }
   
    InfoNode infoNode = null;
    // compound node (no text value and there are subnodes
    if( nodeValue == null && numNodes > 0 )
    {
      // create the compound info node and then recursively to build out its children
      infoNode = InfoNode.createCompoundNode( null, persistName, type );
View Full Code Here

    final XmlReader reader = new XmlReader();
    final Class< ? > inputClazz = int[][].class;
//    reader.setRemoveEmptyTextNodes( false );
    final InputStream inputStream = new BufferedInputStream( new FileInputStream( "test.xml" ) );
    final Reader input = new InputStreamReader( inputStream );
    final InfoNode infoNode = reader.read( inputClazz, input );
    System.out.println( infoNode.simpleTreeToString() );
   
    final PersistenceEngine engine = new PersistenceEngine();
    final Object reperson = engine.parseSemanticModel( inputClazz, infoNode );
    System.out.println( reperson );
  }
View Full Code Here

     
    // the first/top of the json string must be the class name, so there should only be one key,
    // and one value associated with that key { "root_key" : { members } }, where members is
    // defined by { pair, members } and pair is defined by "key", "value" (see class documentation).
    // we still have to add the value as a node.
    final InfoNode rootNode = createRootNode( jsonObject, clazz );
   
    // grab the value and deal with one of the three possibilities:
    // 1. the value is a json object and therefore has name-value pairs
    // 2. the value is a json array and therefore has elements
    // 3. the value is neither, and therefore is a simple value
    // In the first two cases, we build out the remainder of the nodes recursively. In
    // the third case, we set in the value and class in root node and we're done.
    final Object value = JsonUtils.getValue( jsonObject, rootNode.getPersistName() );
    if( value instanceof JSONObject )
    {
      buildInfoNode( (JSONObject)value, rootNode );
    }
    else if( value instanceof JSONArray )
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.