eXo WS :: REST :: Extentions 2.3.0-GA

org.exoplatform.services.rest.ext.groovy
Class GroovyJaxrsPublisher

java.lang.Object
  extended by org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher

public class GroovyJaxrsPublisher
extends Object

Manage via ResourceBinder Groovy based RESTful services.

Version:
$Id$
Author:
Andrey Parfonov

Field Summary
protected  ResourceBinder binder
           
protected  GroovyClassLoaderProvider classLoaderProvider
           
protected static Charset DEFAULT_CHARSET
          Default character set.
protected static String DEFAULT_CHARSET_NAME
          Default character set name.
protected  org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator
           
protected  Map<ResourceId,String> resources
           
 
Constructor Summary
GroovyJaxrsPublisher(ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator)
          Create GroovyJaxrsPublisher which is able publish per-request and singleton resources.
GroovyJaxrsPublisher(ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator, GroovyClassLoaderProvider classLoaderProvider)
           
 
Method Summary
protected  groovy.lang.GroovyCodeSource createCodeSource(InputStream in, String name)
          Create GroovyCodeSource from given stream and name.
protected  Object createInstance(Class clazz)
           
 groovy.lang.GroovyClassLoader getGroovyClassLoader()
          Deprecated. 
 ObjectFactory<AbstractResourceDescriptor> getResource(ResourceId resourceId)
          Get resource corresponded to specified id resourceId .
 boolean isPublished(ResourceId resourceId)
          Check is groovy resource with specified id is published or not
 void publishPerRequest(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
          Parse given stream and publish result as per-request RESTful service.
 void publishPerRequest(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
          Parse given stream and publish result as per-request RESTful service.
 void publishPerRequest(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
          Parse given source and publish result as per-request RESTful service.
 void publishPerRequest(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
          Parse given source and publish result as per-request RESTful service.
 void publishPerRequest(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
          Parse given source and publish result as per-request RESTful service.
 void publishPerRequest(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
          Parse given source and publish result as per-request RESTful service.
 void publishSingleton(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
          Parse given stream and publish result as singleton RESTful service.
 void publishSingleton(InputStream in, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
          Parse given stream and publish result as singleton RESTful service.
 void publishSingleton(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
          Parse given source and publish result as singleton RESTful service.
 void publishSingleton(String source, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
          Parse given source and publish result as singleton RESTful service.
 void publishSingleton(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties)
          Parse given source and publish result as singleton RESTful service.
 void publishSingleton(String source, String charset, ResourceId resourceId, javax.ws.rs.core.MultivaluedMap<String,String> properties, SourceFolder[] src, SourceFile[] files)
          Parse given source and publish result as singleton RESTful service.
 void setGroovyClassLoader(groovy.lang.GroovyClassLoader gcl)
          Deprecated. 
 ObjectFactory<AbstractResourceDescriptor> unpublishResource(ResourceId resourceId)
          Unpublish resource with specified id.
 void validateResource(InputStream in, String name)
          Validate does stream contain Groovy source code which is conforms with requirement to JAX-RS resource.
 void validateResource(InputStream in, String name, SourceFolder[] src, SourceFile[] files)
          Validate does stream contain Groovy source code which is conforms with requirement to JAX-RS resource.
 void validateResource(String source, String name)
          Validate does source contain Groovy source code which is conforms with requirement to JAX-RS resource.
 void validateResource(String source, String name, SourceFolder[] src, SourceFile[] files)
          Validate does source contain Groovy source code which is conforms with requirement to JAX-RS resource.
 void validateResource(String source, String charset, String name, SourceFolder[] src, SourceFile[] files)
          Validate does source contain Groovy source code which is conforms with requirement to JAX-RS resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHARSET_NAME

protected static final String DEFAULT_CHARSET_NAME
Default character set name.

See Also:
Constant Field Values

DEFAULT_CHARSET

protected static final Charset DEFAULT_CHARSET
Default character set.


binder

protected final ResourceBinder binder

instantiator

protected final org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator

classLoaderProvider

protected final GroovyClassLoaderProvider classLoaderProvider

resources

protected final Map<ResourceId,String> resources
Constructor Detail

GroovyJaxrsPublisher

public GroovyJaxrsPublisher(ResourceBinder binder,
                            org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator,
                            GroovyClassLoaderProvider classLoaderProvider)

GroovyJaxrsPublisher

public GroovyJaxrsPublisher(ResourceBinder binder,
                            org.exoplatform.services.script.groovy.GroovyScriptInstantiator instantiator)
Create GroovyJaxrsPublisher which is able publish per-request and singleton resources. Any required dependencies for per-request resource injected by PerRequestObjectFactory, instance of singleton resources will be created by GroovyScriptInstantiator.

Parameters:
binder - resource binder
instantiator - instantiate java object from given groovy source
Method Detail

getGroovyClassLoader

@Deprecated
public groovy.lang.GroovyClassLoader getGroovyClassLoader()
Deprecated. 

Returns:
get underling groovy class loader

setGroovyClassLoader

@Deprecated
public void setGroovyClassLoader(groovy.lang.GroovyClassLoader gcl)
Deprecated. 

Set groovy class loader.

Parameters:
gcl - groovy class loader
Throws:
NullPointerException - if gcl == null

getResource

public ObjectFactory<AbstractResourceDescriptor> getResource(ResourceId resourceId)
Get resource corresponded to specified id resourceId .

Parameters:
resourceId - resource id
Returns:
resource or null

isPublished

public boolean isPublished(ResourceId resourceId)
Check is groovy resource with specified id is published or not

Parameters:
resourceId - id of resource to be checked
Returns:
true if resource is published and false otherwise

publishPerRequest

public void publishPerRequest(InputStream in,
                              ResourceId resourceId,
                              javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse given stream and publish result as per-request RESTful service.

Parameters:
in - stream which contains groovy source code of RESTful service
resourceId - id to be assigned to resource
properties - optional resource properties. This parameter may be null
Throws:
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Class, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishPerRequest

public void publishPerRequest(InputStream in,
                              ResourceId resourceId,
                              javax.ws.rs.core.MultivaluedMap<String,String> properties,
                              SourceFolder[] src,
                              SourceFile[] files)
Parse given stream and publish result as per-request RESTful service.

Parameters:
in - stream which contains Groovy source code of RESTful service
resourceId - id to be assigned to resource
properties - optional resource properties. This parameter may be null
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Class, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishPerRequest

public final void publishPerRequest(String source,
                                    ResourceId resourceId,
                                    javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse given source and publish result as per-request RESTful service.

Parameters:
source - groovy source code of RESTful service
resourceId - id to be assigned to resource
properties - optional resource properties. This parameter may be null
Throws:
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Class, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishPerRequest

public final void publishPerRequest(String source,
                                    ResourceId resourceId,
                                    javax.ws.rs.core.MultivaluedMap<String,String> properties,
                                    SourceFolder[] src,
                                    SourceFile[] files)
Parse given source and publish result as per-request RESTful service.

Parameters:
source - groovy source code of RESTful service
resourceId - id to be assigned to resource
properties - optional resource properties. This parameter may be null
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Class, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishPerRequest

public final void publishPerRequest(String source,
                                    String charset,
                                    ResourceId resourceId,
                                    javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse given source and publish result as per-request RESTful service.

Parameters:
source - groovy source code of RESTful service
charset - source string charset. May be null than default charset will be in use
resourceId - id to be assigned to resource
properties - optional resource properties. This parameter may be null.
Throws:
UnsupportedCharsetException - if charset is unsupported
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Class, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishPerRequest

public final void publishPerRequest(String source,
                                    String charset,
                                    ResourceId resourceId,
                                    javax.ws.rs.core.MultivaluedMap<String,String> properties,
                                    SourceFolder[] src,
                                    SourceFile[] files)
Parse given source and publish result as per-request RESTful service.

Parameters:
source - groovy source code of RESTful service
charset - source string charset. May be null than default charset will be in use
resourceId - id to be assigned to resource
properties - optional resource properties. This parameter may be null.
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
UnsupportedCharsetException - if charset is unsupported
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Class, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishSingleton

public void publishSingleton(InputStream in,
                             ResourceId resourceId,
                             javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse given stream and publish result as singleton RESTful service.

Parameters:
in - stream which contains groovy source code of RESTful service
resourceId - id to be assigned to resource
properties - optional resource properties. This parameter may be null
Throws:
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Object, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishSingleton

public void publishSingleton(InputStream in,
                             ResourceId resourceId,
                             javax.ws.rs.core.MultivaluedMap<String,String> properties,
                             SourceFolder[] src,
                             SourceFile[] files)
Parse given stream and publish result as singleton RESTful service.

Parameters:
in - stream which contains groovy source code of RESTful service
resourceId - id to be assigned to resource
properties - optional resource properties. This parameter may be null
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Object, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishSingleton

public final void publishSingleton(String source,
                                   ResourceId resourceId,
                                   javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse given source and publish result as singleton RESTful service.

Parameters:
source - groovy source code of RESTful service
resourceId - name of resource
properties - optional resource properties. This parameter may be null.
Throws:
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Object, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishSingleton

public final void publishSingleton(String source,
                                   ResourceId resourceId,
                                   javax.ws.rs.core.MultivaluedMap<String,String> properties,
                                   SourceFolder[] src,
                                   SourceFile[] files)
Parse given source and publish result as singleton RESTful service.

Parameters:
source - groovy source code of RESTful service
resourceId - name of resource
properties - optional resource properties. This parameter may be null.
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Object, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishSingleton

public final void publishSingleton(String source,
                                   String charset,
                                   ResourceId resourceId,
                                   javax.ws.rs.core.MultivaluedMap<String,String> properties)
Parse given source and publish result as singleton RESTful service.

Parameters:
source - groovy source code of RESTful service
charset - source string charset. May be null than default charset will be in use
resourceId - name of resource
properties - optional resource properties. This parameter may be null.
Throws:
UnsupportedCharsetException - if charset is unsupported
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Object, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

publishSingleton

public final void publishSingleton(String source,
                                   String charset,
                                   ResourceId resourceId,
                                   javax.ws.rs.core.MultivaluedMap<String,String> properties,
                                   SourceFolder[] src,
                                   SourceFile[] files)
Parse given source and publish result as singleton RESTful service.

Parameters:
source - groovy source code of RESTful service
charset - source string charset. May be null than default charset will be in use
resourceId - name of resource
properties - optional resource properties. This parameter may be null.
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
UnsupportedCharsetException - if charset is unsupported
NullPointerException - if resourceId == null
ResourcePublicationException - see ResourceBinder.addResource(Object, MultivaluedMap)
org.codehaus.groovy.control.CompilationFailedException - if compilation fails from source errors

unpublishResource

public ObjectFactory<AbstractResourceDescriptor> unpublishResource(ResourceId resourceId)
Unpublish resource with specified id.

Parameters:
resourceId - id of resource to be unpublished
Returns:
true if resource was published and false otherwise, e.g. because there is not resource corresponded to supplied resourceId

validateResource

public void validateResource(InputStream in,
                             String name,
                             SourceFolder[] src,
                             SourceFile[] files)
                      throws MalformedScriptException
Validate does stream contain Groovy source code which is conforms with requirement to JAX-RS resource.

Parameters:
in - Groovy source stream
name - script name. This name will be used by GroovyClassLoader to identify script, e.g. specified name will be used in error message in compilation of Groovy fails. If this parameter is null then GroovyClassLoader will use automatically generated name
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
MalformedScriptException - if source has errors or there is no required JAX-RS annotation

validateResource

public void validateResource(InputStream in,
                             String name)
                      throws MalformedScriptException
Validate does stream contain Groovy source code which is conforms with requirement to JAX-RS resource.

Parameters:
in - Groovy source stream
name - script name. This name will be used by GroovyClassLoader to identify script, e.g. specified name will be used in error message in compilation of Groovy fails. If this parameter is null then GroovyClassLoader will use automatically generated name
Throws:
MalformedScriptException - if source has errors or there is no required JAX-RS annotation

validateResource

public final void validateResource(String source,
                                   String charset,
                                   String name,
                                   SourceFolder[] src,
                                   SourceFile[] files)
                            throws MalformedScriptException
Validate does source contain Groovy source code which is conforms with requirement to JAX-RS resource.

Parameters:
source - Groovy source code as String
charset - source string charset. May be null than default charset will be in use
name - script name. This name will be used by GroovyClassLoader to identify script, e.g. specified name will be used in error message in compilation of Groovy fails. If this parameter is null then GroovyClassLoader will use automatically generated name
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
MalformedScriptException - if source has errors or there is no required JAX-RS annotation

validateResource

public final void validateResource(String source,
                                   String name,
                                   SourceFolder[] src,
                                   SourceFile[] files)
                            throws MalformedScriptException
Validate does source contain Groovy source code which is conforms with requirement to JAX-RS resource.

Parameters:
source - Groovy source code as String
name - script name. This name will be used by GroovyClassLoader to identify script, e.g. specified name will be used in error message in compilation of Groovy fails. If this parameter is null then GroovyClassLoader will use automatically generated name
src - additional path to Groovy sources
files - Groovy source files to be added in build path directly
Throws:
MalformedScriptException - if source has errors or there is no required JAX-RS annotation

validateResource

public final void validateResource(String source,
                                   String name)
                            throws MalformedScriptException
Validate does source contain Groovy source code which is conforms with requirement to JAX-RS resource.

Parameters:
source - Groovy source code as String
name - script name. This name will be used by GroovyClassLoader to identify script, e.g. specified name will be used in error message in compilation of Groovy fails. If this parameter is null then GroovyClassLoader will use automatically generated name
Throws:
MalformedScriptException - if source has errors or there is no required JAX-RS annotation

createInstance

protected Object createInstance(Class clazz)
                         throws IllegalArgumentException,
                                InstantiationException,
                                IllegalAccessException,
                                InvocationTargetException
Throws:
IllegalArgumentException
InstantiationException
IllegalAccessException
InvocationTargetException

createCodeSource

protected groovy.lang.GroovyCodeSource createCodeSource(InputStream in,
                                                        String name)
Create GroovyCodeSource from given stream and name. Code base 'file:/groovy/script/jaxrs' will be used.

Parameters:
in - groovy source code stream
name - code source name
Returns:
GroovyCodeSource

eXo WS :: REST :: Extentions 2.3.0-GA

Copyright © 2012 eXo Platform SAS. All Rights Reserved.