Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2002-2014 "Neo Technology," Network Engine for Objects in Lund AB [http://neotechnology.com] This file is part of Neo4j. Neo4j is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 package org.neo4j.server.plugins;
 
 import java.util.List;
 
API for creating extensions for the Neo4j server.

Extensions are created by creating a subclass of this class. The subclass should have a public no-argument constructor. Then place this class in a jar-file that contains a file called META-INF/services/org.neo4j.server.plugins.ServerPlugin. This file should contain the fully qualified name of the class that extends ServerPlugin, e.g. com.example.MyNeo4jServerExtension on a single line. If the jar contains multiple extensions to the Neo4j server, this file should contain the fully qualified class names of all extension classes, each class name on its own line in the file. When the jar file is placed on the class path of the server, it will be loaded automatically when the server starts.

The easiest way to implement Neo4j server extensions is by defining public methods on the extension class annotated with @PluginTarget. The parameter for the PluginTarget annotation should be the class representing the entity that the method extends. The entities that can be extended are currently:

You can then use the @Source annotation on one parameter of the method to get the instance that was extended. Additional parameters needs to be of a supported type, and annotated with the @Parameter annotation specifying the name by which the parameter is passed from the client. The supported parameter types are:

All exceptions thrown by an PluginTarget method are treated as server errors, unless the method has declared the ability to throw such an exception, in that case the exception is treated as a bad request and propagated to the invoking client.

Author(s):
Tobias Ivarsson <tobias.ivarsson@neotechnology.com>
See also:
java.util.ServiceLoader
 
 public abstract class ServerPlugin
 {
     final String name;

    
Create a server extension with the specified name.

Parameters:
name the name of this extension.
 
     public ServerPluginString name )
     {
         this. = verifyNamename );
     }

    
Create a server extension using the simple name of the concrete class that extends ServerPlugin as the name for the extension.
    public ServerPlugin()
    {
        this. = verifyNamegetClass().getSimpleName() );
    }
    static String verifyNameString name )
    {
        if ( name == null )
        {
            throw new IllegalArgumentException"Name may not be null" );
        }
        try
        {
            if ( !URLEncoder.encodename"UTF-8" ).equalsname ) )
            {
                throw new IllegalArgumentException"Name contains illegal characters" );
            }
        } catch ( UnsupportedEncodingException e )
        {
            throw new Error"UTF-8 should be supported"e );
        }
        return name;
    }
    @Override
    public String toString()
    {
        return "ServerPlugin[" +  + "]";
    }
    static Iterable<ServerPluginload()
    {
        return Service.loadServerPlugin.class );
    }

    
Loads the extension points of this server extension. Override this method to provide your own, custom way of loading extension points. The default implementation loads PluginPoint based on methods with the PluginTarget annotation.

Parameters:
extender the collection of PluginPoints for this ServerPlugin.
    protected void loadServerExtenderServerExtender extender )
    {
        for ( PluginPoint plugin : getDefaultExtensionPointsextender.getPluginPointFactory() ) )
        {
            extender.addExtensionplugin.forType(), plugin );
        }
    }

    
Loads the extension points of this server extension. Override this method to provide your own, custom way of loading extension points. The default implementation loads PluginPoint based on methods with the PluginTarget annotation.

Returns:
the collection of PluginPoints for this ServerPlugin.
    protected Collection<PluginPointgetDefaultExtensionPointsPluginPointFactory pluginPointFactory )
    {
        List<PluginPointresult = new ArrayList<PluginPoint>();
        for ( Method method : getClass().getMethods() )
        {
            PluginTarget target = method.getAnnotationPluginTarget.class );
            if ( target != null )
            {
                result.addpluginPointFactory.createFromthismethodtarget.value() ) );
            }
        }
        return result;
    }
New to GrepCode? Check out our FAQ X