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 MapWrappingWriter extends MappingWriter
    31  {
    32      final Map<String, Object> data;
    33      final boolean interactive;
    34
    35      public MapWrappingWriter( Map<String, Object> data )
    36      {
    37          this( data, false );
    38      }
    39
    40      public MapWrappingWriter( Map<String, Object> data, boolean interactive )
    41      {
    42          this.data = data;
    43          this.interactive = interactive;
    44      }
    45
    46      @Override
    47      final protected boolean isInteractive()
    48      {
    49          return interactive;
    50      }
    51
    52      @Override
    53      protected ListWriter newList( String type, String key )
    54      {
    55          List<Object> list = new ArrayList<Object>();
    56          data.put( key, list );
    57          return new ListWrappingWriter( list, interactive );
    58      }
    59
    60      @Override
    61      protected MappingWriter newMapping( String type, String key )
    62      {
    63          Map<String, Object> map = new HashMap<String, Object>();
    64          data.put( key, map );
    65          return new MapWrappingWriter( map, interactive );
    66      }
    67
    68      @Override
    69      protected void writeValue( String type, String key, Object value )
    70      {
    71          data.put( key, value );
    72      }
    73
    74      @Override
    75      protected void done()
    76      {
    77      }
    78  }