org.apache.clerezza.rdf.core.access
Class TcManager

java.lang.Object
  extended by org.apache.clerezza.rdf.core.access.TcProviderMultiplexer
      extended by org.apache.clerezza.rdf.core.access.TcManager
All Implemented Interfaces:
TcProvider

@Service(value=TcManager.class)
@Reference(name="weightedTcProvider",
           policy=DYNAMIC,
           referenceInterface=WeightedTcProvider.class,
           cardinality=MANDATORY_MULTIPLE)
public class TcManager
extends TcProviderMultiplexer

This class implements TcManager, delegating the actual provision and creation of Graphs or MGraphs to registered TcProviders. The class attempts to satisfy the request using the register WeightedTcProvider in decreasing order of weight. If multiple providers have the same weight the lexicographical order of the fully qualified class name determines which one is used, namely the one that occurs earlier. If a call to a registered provider causes an IllegalArgumentException, NoSuchEntityException or UnsupportedOperationException then the call is delegated to the next provider. Only one instance of this class should exist in a system, the public no argument constructor is meant for initialization by dependency injection systems such as OSGi-DS. Applications should use the static getInstance() method if they aren't using a framework that injects them the instance. This class returns LockableMGraphs a subtype of MGraph that allows read/write locks.

Author:
reto, mir, hasan

Field Summary
protected  QueryEngine queryEngine
           
 
Constructor Summary
TcManager()
          the constructor sets the singleton instance to allow instantiation by OSGi-DS.
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext componentContext)
           
protected  void bindWeightedTcProvider(WeightedTcProvider provider)
          Registers a provider
 Graph createGraph(UriRef name, TripleCollection triples)
          Creates a Graph with a specified name
 LockableMGraph createMGraph(UriRef name)
          Creates an initially empty MGraph with a specified name
protected  void deactivate(org.osgi.service.component.ComponentContext componentContext)
           
 void deleteTripleCollection(UriRef name)
          Deletes the Graph or MGraph of a specified name.
 boolean executeSparqlQuery(AskQuery query, TripleCollection defaultGraph)
          Executes a sparql ASK query.
 Graph executeSparqlQuery(ConstructQuery query, TripleCollection defaultGraph)
          Executes a sparql CONSTRUCT query.
 Graph executeSparqlQuery(DescribeQuery query, TripleCollection defaultGraph)
          Executes a sparql DESCRIBE query.
 Object executeSparqlQuery(Query query, TripleCollection defaultGraph)
          Executes any sparql query.
 ResultSet executeSparqlQuery(SelectQuery query, TripleCollection defaultGraph)
          Executes a sparql SELECT query.
 Graph getGraph(UriRef name)
          Get a Graph by its name
static TcManager getInstance()
          This returns the singleton instance.
 LockableMGraph getMGraph(UriRef name)
          Get an MGraph by its name.
 Set<UriRef> getNames(Graph graph)
          get a set of the names of a Graph
 TcAccessController getTcAccessController()
           
 TripleCollection getTriples(UriRef name)
          This method is used to get a TripleCollection indifferently whether it's a Graph or an MGraph.
protected  void graphAppears(UriRef name)
          subclasses overwrite this method to be notified when a new Graph is available (either because it has been created or being provided by a newly added WeightedTcProvider).
 Set<UriRef> listGraphs()
          Lists the name of the Graphs available through this TcProvider, implementations may take into account the security context and omit Graphs for which access is not allowed.
 Set<UriRef> listMGraphs()
          Lists the name of the MGraphs available through this TcProvider, implementations may take into account the security context and omit MGraphs for which access is not allowed.
 Set<UriRef> listTripleCollections()
          Lists the name of the TripleCollections available through this TcProvider indifferently whether they are Graphs or an MGraphs, implementations may take into account the security context and omit TripleCollections for which access is not allowed.
protected  void mGraphAppears(UriRef name)
          subclasses overwrite this method to be notified when a new MGraph is available (either because it has been created or being provided by a newly added WeightedTcProvider).
protected  void tcDisappears(UriRef name)
          subclasses overwrite this method to be notified whenTripleCollection is no longer available (either because it has been deleted or bacause its WeightedTcProvider was removed).
protected  void unbindWeightedTcProvider(WeightedTcProvider provider)
          Unregister a provider
 
Methods inherited from class org.apache.clerezza.rdf.core.access.TcProviderMultiplexer
addWeightedTcProvider, getProviderList, removeWeightedTcProvider
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queryEngine

@Reference(policy=DYNAMIC,
           cardinality=MANDATORY_UNARY)
protected QueryEngine queryEngine
Constructor Detail

TcManager

public TcManager()
the constructor sets the singleton instance to allow instantiation by OSGi-DS. This constructor should not be called except by OSGi-DS, otherwise the static getInstance method should be used.

Method Detail

getInstance

public static TcManager getInstance()
This returns the singleton instance. If an instance has been previously created (e.g. by OSGi declarative services) this instance is returned, otherwise a new instance is created and providers are injected using the service provider interface (META-INF/services/)

Returns:
the singleton instance

activate

protected void activate(org.osgi.service.component.ComponentContext componentContext)

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext componentContext)

getGraph

public Graph getGraph(UriRef name)
               throws NoSuchEntityException
Description copied from interface: TcProvider
Get a Graph by its name

Specified by:
getGraph in interface TcProvider
Overrides:
getGraph in class TcProviderMultiplexer
Parameters:
name - the name of the Graph
Returns:
the Graph with the specified name
Throws:
NoSuchEntityException - if there is no Graph with the specified name

getMGraph

public LockableMGraph getMGraph(UriRef name)
Description copied from interface: TcProvider
Get an MGraph by its name. The instances returned in different invocations are equals.

Specified by:
getMGraph in interface TcProvider
Overrides:
getMGraph in class TcProviderMultiplexer
Returns:
name the MGraph with the specified name

getTriples

public TripleCollection getTriples(UriRef name)
Description copied from interface: TcProvider
This method is used to get a TripleCollection indifferently whether it's a Graph or an MGraph. If the name names an MGraph the result is the same as when invoking getMGraph with that argument, analogously for GraphS the method returns an instance equals to what getGraph would return.

Specified by:
getTriples in interface TcProvider
Overrides:
getTriples in class TcProviderMultiplexer
Parameters:
name - the name of the Graph or MGraph
Returns:
the Graph or MGraph

createMGraph

public LockableMGraph createMGraph(UriRef name)
                            throws UnsupportedOperationException
Description copied from interface: TcProvider
Creates an initially empty MGraph with a specified name

Specified by:
createMGraph in interface TcProvider
Overrides:
createMGraph in class TcProviderMultiplexer
Parameters:
name - names the new MGraph
Returns:
the newly created MGraph
Throws:
UnsupportedOperationException - if this provider doesn't support creating MGraphS

createGraph

public Graph createGraph(UriRef name,
                         TripleCollection triples)
Description copied from interface: TcProvider
Creates a Graph with a specified name

Specified by:
createGraph in interface TcProvider
Overrides:
createGraph in class TcProviderMultiplexer
Parameters:
name - the name of the Graph to be created
triples - the triples of the new Graph
Returns:
the newly created Graph

deleteTripleCollection

public void deleteTripleCollection(UriRef name)
Description copied from interface: TcProvider
Deletes the Graph or MGraph of a specified name. If name references a Graph and the graph has other names, it will still be available with those other names.

Specified by:
deleteTripleCollection in interface TcProvider
Overrides:
deleteTripleCollection in class TcProviderMultiplexer
Parameters:
name - the entity to be removed

getNames

public Set<UriRef> getNames(Graph graph)
Description copied from interface: TcProvider
get a set of the names of a Graph

Specified by:
getNames in interface TcProvider
Overrides:
getNames in class TcProviderMultiplexer
Returns:
the set names of Graph, the set is empty if Graph is unknown

listGraphs

public Set<UriRef> listGraphs()
Description copied from interface: TcProvider
Lists the name of the Graphs available through this TcProvider, implementations may take into account the security context and omit Graphs for which access is not allowed.

Specified by:
listGraphs in interface TcProvider
Overrides:
listGraphs in class TcProviderMultiplexer
Returns:
the list of Graphs

listMGraphs

public Set<UriRef> listMGraphs()
Description copied from interface: TcProvider
Lists the name of the MGraphs available through this TcProvider, implementations may take into account the security context and omit MGraphs for which access is not allowed.

Specified by:
listMGraphs in interface TcProvider
Overrides:
listMGraphs in class TcProviderMultiplexer
Returns:
the list of MGraphs

listTripleCollections

public Set<UriRef> listTripleCollections()
Description copied from interface: TcProvider
Lists the name of the TripleCollections available through this TcProvider indifferently whether they are Graphs or an MGraphs, implementations may take into account the security context and omit TripleCollections for which access is not allowed.

Specified by:
listTripleCollections in interface TcProvider
Overrides:
listTripleCollections in class TcProviderMultiplexer
Returns:
the list of TripleCollections

executeSparqlQuery

public Object executeSparqlQuery(Query query,
                                 TripleCollection defaultGraph)
Executes any sparql query. The type of the result object will vary depending on the type of the query.

Parameters:
query - the sparql query to execute
defaultGraph - the default graph against which to execute the query if not FROM clause is present
Returns:
the resulting ResultSet, Graph or Boolean value

executeSparqlQuery

public ResultSet executeSparqlQuery(SelectQuery query,
                                    TripleCollection defaultGraph)
Executes a sparql SELECT query.

Parameters:
query - the sparql SELECT query to execute
defaultGraph - the default graph against which to execute the query if not FROM clause is present
Returns:
the resulting ResultSet

executeSparqlQuery

public boolean executeSparqlQuery(AskQuery query,
                                  TripleCollection defaultGraph)
Executes a sparql ASK query.

Parameters:
query - the sparql ASK query to execute
defaultGraph - the default graph against which to execute the query if not FROM clause is present
Returns:
the boolean value this query evaluates to

executeSparqlQuery

public Graph executeSparqlQuery(DescribeQuery query,
                                TripleCollection defaultGraph)
Executes a sparql DESCRIBE query.

Parameters:
query - the sparql DESCRIBE query to execute
defaultGraph - the default graph against which to execute the query if not FROM clause is present
Returns:
the resulting Graph

executeSparqlQuery

public Graph executeSparqlQuery(ConstructQuery query,
                                TripleCollection defaultGraph)
Executes a sparql CONSTRUCT query.

Parameters:
query - the sparql CONSTRUCT query to execute
defaultGraph - the default graph against which to execute the query if not FROM clause is present
Returns:
the resulting Graph

getTcAccessController

public TcAccessController getTcAccessController()
Returns:
the TcAccessController that can be used to set the permissions needed to access a Triple Collection

bindWeightedTcProvider

protected void bindWeightedTcProvider(WeightedTcProvider provider)
Registers a provider

Parameters:
provider - the provider to be registered

unbindWeightedTcProvider

protected void unbindWeightedTcProvider(WeightedTcProvider provider)
Unregister a provider

Parameters:
provider - the provider to be deregistered

mGraphAppears

protected void mGraphAppears(UriRef name)
Description copied from class: TcProviderMultiplexer
subclasses overwrite this method to be notified when a new MGraph is available (either because it has been created or being provided by a newly added WeightedTcProvider). The default implementation does nothing.

Overrides:
mGraphAppears in class TcProviderMultiplexer

graphAppears

protected void graphAppears(UriRef name)
Description copied from class: TcProviderMultiplexer
subclasses overwrite this method to be notified when a new Graph is available (either because it has been created or being provided by a newly added WeightedTcProvider). The default implementation does nothing.

Overrides:
graphAppears in class TcProviderMultiplexer

tcDisappears

protected void tcDisappears(UriRef name)
Description copied from class: TcProviderMultiplexer
subclasses overwrite this method to be notified whenTripleCollection is no longer available (either because it has been deleted or bacause its WeightedTcProvider was removed). The default implementation does nothing. for implementational reasons even for name of TripleCollection not previously registered.

Overrides:
tcDisappears in class TcProviderMultiplexer


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.