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;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.neo4j.server.plugins.ParameterDescriptionConsumer;
26  
27  public final class ExtensionPointRepresentation extends ObjectRepresentation implements
28          ParameterDescriptionConsumer
29  {
30      private final RepresentationType extended;
31      private final String name;
32      private final String desciption;
33      private final List<ParameterRepresentation> parameters = new ArrayList<ParameterRepresentation>();
34  
35      public ExtensionPointRepresentation( String name, Class<?> extended, String desciption )
36      {
37          super( RepresentationType.PLUGIN_DESCRIPTION );
38          this.name = name;
39          this.desciption = desciption;
40          this.extended = RepresentationType.extended( extended );
41      }
42  
43      @Override
44      public void describeParameter( String name, Class<?> type, boolean optional, String description )
45      {
46          parameters.add( new ParameterRepresentation( name, type, optional, description, false ) );
47      }
48  
49      @Override
50      public void describeListParameter( String name, Class<?> type, boolean optional,
51              String description )
52      {
53          parameters.add( new ParameterRepresentation( name, type, optional, description, true ) );
54      }
55  
56      public String getName()
57      {
58          return name;
59      }
60  
61      public String getExtendedEntity()
62      {
63          return extended.valueName;
64      }
65  
66      @Mapping( "name" )
67      public ValueRepresentation methodName()
68      {
69          return ValueRepresentation.string( name );
70      }
71  
72      @Mapping( "description" )
73      public ValueRepresentation description()
74      {
75          return ValueRepresentation.string( desciption );
76      }
77  
78      @Mapping( "extends" )
79      public ValueRepresentation extendedEntity()
80      {
81          return ValueRepresentation.string( getExtendedEntity() );
82      }
83  
84      @Mapping( "parameters" )
85      public ListRepresentation parametersList()
86      {
87          return new ListRepresentation( RepresentationType.PLUGIN_PARAMETER, parameters );
88      }
89  
90      private static class ParameterRepresentation extends MappingRepresentation
91      {
92          private final String name;
93          private final RepresentationType paramType;
94          private final String description;
95          private final boolean optional;
96          private final boolean list;
97  
98          ParameterRepresentation( String name, Class<?> type, boolean optional, String description,
99                  boolean list )
100         {
101             super( RepresentationType.PLUGIN_PARAMETER );
102             this.name = name;
103             this.optional = optional;
104             this.list = list;
105             this.paramType = RepresentationType.extended( type );
106             this.description = description;
107         }
108 
109         @Override
110         protected void serialize( MappingSerializer serializer )
111         {
112             serializer.putString( "name", name );
113             serializer.putString( "type", list ? paramType.listName : paramType.valueName );
114             serializer.putBoolean( "optional", optional );
115             serializer.putString( "description", description );
116         }
117     }
118 }