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.webadmin.rest.representations;
    21
    22  import java.util.ArrayList;
    23
    24  import javax.management.openmbean.CompositeData;
    25
    26  import org.neo4j.server.rest.repr.ListRepresentation;
    27  import org.neo4j.server.rest.repr.ObjectRepresentation;
    28  import org.neo4j.server.rest.repr.Representation;
    29  import org.neo4j.server.rest.repr.ValueRepresentation;
    30
    31  public class JmxCompositeDataRepresentation extends ObjectRepresentation
    32  {
    33      protected CompositeData data;
    34
    35      public JmxCompositeDataRepresentation( CompositeData data )
    36      {
    37          super( "jmxCompositeData" );
    38          this.data = data;
    39      }
    40
    41      @Mapping( "type" )
    42      public ValueRepresentation getType()
    43      {
    44          return ValueRepresentation.string( data.getCompositeType().getTypeName() );
    45      }
    46
    47
    48      @Mapping( "description" )
    49      public ValueRepresentation getDescription()
    50      {
    51          return ValueRepresentation.string( data.getCompositeType().getDescription() );
    52      }
    53
    54      @Mapping( "value" )
    55      public ListRepresentation getValue()
    56      {
    57
    58          JmxAttributeRepresentationDispatcher representationDispatcher = new JmxAttributeRepresentationDispatcher();
    59          ArrayList<Representation> values = new ArrayList<Representation>();
    60          for ( Object key : data.getCompositeType().keySet() )
    61          {
    62              String name = key.toString();
    63              String description = data.getCompositeType().getDescription( name );
    64
    65
    66              Representation value = representationDispatcher.dispatch( data.get( name ) , "");
    67
    68              values.add( new NameDescriptionValueRepresentation( name, description, value ) );
    69          }
    70
    71          return new ListRepresentation( "value", values );
    72      }
    73  }