View Javadoc

1   /**
2    * Copyright (c) 2002-2011 "Neo Technology,"
3    * Network Engine for Objects in Lund AB [http://neotechnology.com]
4    *
5    * This file is part of Neo4j.
6    *
7    * Neo4j is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19   */
20  package org.neo4j.server.rest.repr.formats;
21  
22  import java.util.ArrayList;
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.neo4j.server.rest.repr.ListWriter;
28  import org.neo4j.server.rest.repr.MappingWriter;
29  
30  public class ListWrappingWriter extends ListWriter
31  {
32      final List<Object> data;
33      private final boolean interactive;
34  
35      public ListWrappingWriter( List<Object> data )
36      {
37          this( data, false );
38      }
39  
40      ListWrappingWriter( List<Object> data, boolean interactive )
41      {
42          this.data = data;
43          this.interactive = interactive;
44      }
45  
46      @Override
47      protected ListWriter newList( String type )
48      {
49          List<Object> list = new ArrayList<Object>();
50          data.add( list );
51          return new ListWrappingWriter( list, interactive );
52      }
53  
54      @Override
55      protected MappingWriter newMapping( String type )
56      {
57          Map<String, Object> map = new HashMap<String, Object>();
58          data.add( map );
59          return new MapWrappingWriter( map, interactive );
60      }
61  
62      @Override
63      protected void writeValue( String type, Object value )
64      {
65          data.add( value );
66      }
67  
68      @Override
69      protected void done()
70      {
71      }
72  }