org.semanticdesktop.aperture.accessor.base
Class ModelAccessData

java.lang.Object
  extended by org.semanticdesktop.aperture.accessor.base.ModelAccessData
All Implemented Interfaces:
AccessData

public class ModelAccessData
extends Object
implements AccessData

ModelAccessData provides an AccessData implementation storing its information to and retrieving it from a Model.

This implementation assumes that IDs used to store data are valid URIs and that keys contain only characters that can be used in URIs.

The AccessData.DATE_KEY, AccessData.BYTE_SITE_KEY and AccessData.REDIRECTS_TO_KEY keys are mapped to Aperture DATA predicates. In that case the value must be a long encoded as a String or, in the last case, a URL encoded as a String.


Field Summary
static URI aggregates
           
static URI byteSize
           
static URI dateAsNumber
           
static URI linksTo
           
static URI NS_MAD
           
static String NS_MAD_STRING
           
static URI redirectsTo
           
static URI timestamp
           
static String URI_PREFIX
          Used as a prefix to derive URIs from AccessData key names.
 
Fields inherited from interface org.semanticdesktop.aperture.accessor.AccessData
BYTE_SIZE_KEY, DATE_KEY, REDIRECTS_TO_KEY
 
Constructor Summary
ModelAccessData(Model model)
          Creates a new ModelAccessData instance.
 
Method Summary
 void clear()
          Clears this AccessData.
 String get(String id, String key)
          Gets specific information about the specified id.
 Set getAggregatedIDs(String id)
          Returns a set of id's that are aggregated immediately below the given one.
 ClosableIterator getAggregatedIDsClosure(String id)
          Returns an iterator over all ids aggregated within the given one, both directly and indirectly.
 Set<String> getReferredIDs(String id)
          Returns all referred resources of the specified resource.
 int getSize()
          Warning: expensive operation, as this implementation queries for all unique subjects used in this ModelAccessData's context.
 Set<String> getStoredIDs()
          Gets the IDs of all resources for which information has been stored in this AccessData.
 ClosableIterator getUntouchedIDsIterator()
          Returns an iterator over all ID's in this access data instance that have not been touched since the last call to AccessData.initialize()
 void initialize()
          Prepares the AccessData for operation.
 boolean isKnownId(String id)
          Returns whether this AccessData holds any information about the specified ID.
 boolean isTouched(String id)
          Returns true if this id is known and has been touched since the last call to AccessData.initialize(), false if the id is not known, or hasn't been touched since the last call to AccessData.initialize().
 void put(String id, String key, String value)
          Stores information (a key-value pair) for the specified id.
 void putAggregatedID(String id, String aggregatedID)
          Puts a link between the given id and the aggregated ID.
 void putReferredID(String id, String referredID)
          Stores a reference relation between two resources, modeling e.g. a link.
 void remove(String id)
          Removes all information about the resource with the specified ID.
 void remove(String id, String key)
          Removes the value for the specified id and key.
 void removeAggregatedID(String id, String aggregatedID)
          Removes the link between the given id and the aggregated ID.
 void removeReferredID(String id, String referredID)
          Removes a reference relationship between two resources.
 void removeReferredIDs(String id)
          Removes all referred IDs of a resource.
 void removeUntouchedIDs()
          Removes all untouched IDS
 void store()
          Informs the AccessData that processing has completed and, in case of a persistent storage, now is a good time to write or flush results.
 void touch(String id)
          Touches an id.
 void touchRecursively(String id)
          Recursively touches all ids within the aggregation subtree beginning with the given id
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NS_MAD_STRING

public static final String NS_MAD_STRING
See Also:
Constant Field Values

NS_MAD

public static final URI NS_MAD

linksTo

public static final URI linksTo

aggregates

public static final URI aggregates

redirectsTo

public static final URI redirectsTo

dateAsNumber

public static final URI dateAsNumber

byteSize

public static final URI byteSize

timestamp

public static final URI timestamp

URI_PREFIX

public static final String URI_PREFIX
Used as a prefix to derive URIs from AccessData key names.

See Also:
Constant Field Values
Constructor Detail

ModelAccessData

public ModelAccessData(Model model)
Creates a new ModelAccessData instance.

Parameters:
model - The Model used to store all access data in and retrieve all data from. This cannot be null.
Method Detail

clear

public void clear()
           throws IOException
Description copied from interface: AccessData
Clears this AccessData. This may be invoked on initialized and unititialized AccessData's. Both in-memory information as any persistent storage will be cleared. Afterwards the AccessData may be in an unusable state until 'initialize' is invoked again.

Specified by:
clear in interface AccessData
Throws:
IOException

touch

public void touch(String id)
Description copied from interface: AccessData
Touches an id. This id will not appear on the list returned by AccessData.getUntouchedIDsIterator() and will not be removed by AccessData.removeUntouchedIDs()

Specified by:
touch in interface AccessData

isTouched

public boolean isTouched(String id)
Description copied from interface: AccessData
Returns true if this id is known and has been touched since the last call to AccessData.initialize(), false if the id is not known, or hasn't been touched since the last call to AccessData.initialize().

Specified by:
isTouched in interface AccessData
Parameters:
id - the id to check
Returns:
true if the id has been touched, false if not

get

public String get(String id,
                  String key)
Description copied from interface: AccessData
Gets specific information about the specified id.

Specified by:
get in interface AccessData
Parameters:
id - The resource's ID.
key - The info key.
Returns:
The stored info value, or null if no info has been stored for the specified id and key.

getReferredIDs

public Set<String> getReferredIDs(String id)
Description copied from interface: AccessData
Returns all referred resources of the specified resource.

Specified by:
getReferredIDs in interface AccessData
Returns:
A Set of Strings, or null when there are no referred resources registered for this resource.

getSize

public int getSize()
Warning: expensive operation, as this implementation queries for all unique subjects used in this ModelAccessData's context.

Specified by:
getSize in interface AccessData
Returns:
The number of registered resources.

getStoredIDs

public Set<String> getStoredIDs()
Description copied from interface: AccessData
Gets the IDs of all resources for which information has been stored in this AccessData.

Specified by:
getStoredIDs in interface AccessData
Returns:
A Set of Strings.

initialize

public void initialize()
                throws IOException
Description copied from interface: AccessData
Prepares the AccessData for operation. This may for example mean reading files or opening repositories that hold the stored data.

Specified by:
initialize in interface AccessData
Throws:
IOException

isKnownId

public boolean isKnownId(String id)
Description copied from interface: AccessData
Returns whether this AccessData holds any information about the specified ID.

Specified by:
isKnownId in interface AccessData
Returns:
"true" when this AccessData has information about the specified ID, "false" otherwise.

put

public void put(String id,
                String key,
                String value)
Description copied from interface: AccessData
Stores information (a key-value pair) for the specified id.

Specified by:
put in interface AccessData
Parameters:
id - The resource's ID.
key - The info key.
value - The info value.

putReferredID

public void putReferredID(String id,
                          String referredID)
Description copied from interface: AccessData
Stores a reference relation between two resources, modeling e.g. a link.

Specified by:
putReferredID in interface AccessData
Parameters:
id - The referring resource's ID.
referredID - The referred resource's ID.

remove

public void remove(String id,
                   String key)
Description copied from interface: AccessData
Removes the value for the specified id and key.

Specified by:
remove in interface AccessData
Parameters:
id - A resource ID.
key - A key under which info is stored.

remove

public void remove(String id)
Description copied from interface: AccessData
Removes all information about the resource with the specified ID.

Specifically: Note that this method does NOT remove ids this id is referred BY. I.e. it does remove "outgoing" referredID links but it does NOT remove "incomming" referred ID's. To be on the safe side - the crawler should take care about this by itself.

Specified by:
remove in interface AccessData
Parameters:
id - A resource ID.

removeReferredID

public void removeReferredID(String id,
                             String referredID)
Description copied from interface: AccessData
Removes a reference relationship between two resources.

Specified by:
removeReferredID in interface AccessData
Parameters:
id - The referring resource's ID.
referredID - The referred resource's ID.

removeReferredIDs

public void removeReferredIDs(String id)
Description copied from interface: AccessData
Removes all referred IDs of a resource.

Specified by:
removeReferredIDs in interface AccessData
Parameters:
id - The referring resource's ID.

store

public void store()
           throws IOException
Description copied from interface: AccessData
Informs the AccessData that processing has completed and, in case of a persistent storage, now is a good time to write or flush results. Afterwards the AccessData may be in an unusable state until 'initialize' is invoked again.

Specified by:
store in interface AccessData
Throws:
IOException

getAggregatedIDs

public Set getAggregatedIDs(String id)
Description copied from interface: AccessData
Returns a set of id's that are aggregated immediately below the given one.

Specified by:
getAggregatedIDs in interface AccessData
Returns:
a set of id's that are aggregated immediately below the given one.

putAggregatedID

public void putAggregatedID(String id,
                            String aggregatedID)
Description copied from interface: AccessData
Puts a link between the given id and the aggregated ID. The aggregated ID will appear in the aggregation closure (returned by AccessData.getAggregatedIDsClosure(String)), will be touched by the AccessData.touchRecursively(String) method, it will be removed if the id is removed (@link AccessData.remove(String)). Note that the aggregation graph must not contain cycles, each id can have at most one parent, the implementations are expected to enforce this. If the aggregatedID had a parent before, the previous link will be removed.

Specified by:
putAggregatedID in interface AccessData
Parameters:
id - the parent id
aggregatedID - the aggregated id

removeAggregatedID

public void removeAggregatedID(String id,
                               String aggregatedID)
Description copied from interface: AccessData
Removes the link between the given id and the aggregated ID. After a call to this method, the aggregated ID will not appear in the aggregation closure (AccessData.getAggregatedIDsClosure(String) and will not be touched by the AccessData.touchRecursively(String) method. A call to remove the id will not remove the aggregated id.

Specified by:
removeAggregatedID in interface AccessData

removeUntouchedIDs

public void removeUntouchedIDs()
Description copied from interface: AccessData
Removes all untouched IDS

Specified by:
removeUntouchedIDs in interface AccessData

getUntouchedIDsIterator

public ClosableIterator getUntouchedIDsIterator()
Description copied from interface: AccessData
Returns an iterator over all ID's in this access data instance that have not been touched since the last call to AccessData.initialize()

Specified by:
getUntouchedIDsIterator in interface AccessData
Returns:
an iterator over all untouched IDs

touchRecursively

public void touchRecursively(String id)
Description copied from interface: AccessData
Recursively touches all ids within the aggregation subtree beginning with the given id

Specified by:
touchRecursively in interface AccessData

getAggregatedIDsClosure

public ClosableIterator getAggregatedIDsClosure(String id)
Description copied from interface: AccessData
Returns an iterator over all ids aggregated within the given one, both directly and indirectly. The iterator will traverse the entire aggregation subtree beginning with the given id.

Specified by:
getAggregatedIDsClosure in interface AccessData
Parameters:
id - the id whose aggregation subtree is to be traversed
Returns:
an iterator over the aggregation subtree


Copyright © 2010 Aperture Development Team. All Rights Reserved.