org.semanticdesktop.aperture.accessor.base
Class AccessDataImpl

java.lang.Object
  extended by org.semanticdesktop.aperture.accessor.base.AccessDataImpl
All Implemented Interfaces:
AccessData
Direct Known Subclasses:
FileAccessData

public class AccessDataImpl
extends Object
implements AccessData

Simple AccessData implementation that holds all information in main memory. No persistency facilities are provided, see FileAccessData for that.

See Also:
FileAccessData

Field Summary
protected  Map<String,org.semanticdesktop.aperture.accessor.base.AccessDataImpl.AggregationNode> aggregatedIDMap
          A mapping from IDs to Sets of IDs that the former ID aggregates.
protected  Map<String,Map<String,String>> idMap
          A Map mapping IDs to another Map that contains the key-value pairs for that ID.
protected  Map<String,Set<String>> referredIDMap
          A mapping from IDs to Sets of IDs that the former ID refers to.
 
Fields inherited from interface org.semanticdesktop.aperture.accessor.AccessData
BYTE_SIZE_KEY, DATE_KEY, REDIRECTS_TO_KEY
 
Constructor Summary
AccessDataImpl()
           
 
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 getReferredIDs(String id)
          Returns all referred resources of the specified resource.
 int getSize()
          Gets the number of resources for which information has been stored in this AccessData.
 Set 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 the given id has been touched during the current crawl, false otherwise
 void put(String id, String key, String value)
          Stores information (a key-value pair) for the specified id.
 void putAggregatedID(String parentId, String childID)
          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

idMap

protected Map<String,Map<String,String>> idMap
A Map mapping IDs to another Map that contains the key-value pairs for that ID.


referredIDMap

protected Map<String,Set<String>> referredIDMap
A mapping from IDs to Sets of IDs that the former ID refers to. This can be used to model links between IDs. The use of this mapping is typically to register IDs that need special treatment once the referring ID has been changed or removed.


aggregatedIDMap

protected Map<String,org.semanticdesktop.aperture.accessor.base.AccessDataImpl.AggregationNode> aggregatedIDMap
A mapping from IDs to Sets of IDs that the former ID aggregates. This can be used to model aggregation relationships and implement cascade touch and cascade delete functionality.

Constructor Detail

AccessDataImpl

public AccessDataImpl()
Method Detail

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
See Also:
AccessData.initialize()

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
See Also:
AccessData.store()

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
See Also:
AccessData.clear()

getSize

public int getSize()
Description copied from interface: AccessData
Gets the number of resources for which information has been stored in this AccessData.

Specified by:
getSize in interface AccessData
Returns:
The number of registered resources.
See Also:
AccessData.getSize()

getStoredIDs

public Set 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.
See Also:
AccessData.getStoredIDs()

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.
See Also:
AccessData.isKnownId(String)

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.
See Also:
AccessData.put(String, String, String)

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.
See Also:
AccessData.putReferredID(String, String)

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.
See Also:
AccessData.get(String, String)

getReferredIDs

public Set 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.
See Also:
AccessData.getReferredIDs(String)

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.
See Also:
AccessData.remove(String, String)

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.
See Also:
AccessData.removeReferredID(String, String)

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.

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.

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 parentId,
                            String childID)
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:
parentId - the parent id
childID - 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

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

removeUntouchedIDs

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

Specified by:
removeUntouchedIDs in interface AccessData

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

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

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

isTouched

public boolean isTouched(String id)
Returns true if the given id has been touched during the current crawl, false otherwise

Specified by:
isTouched in interface AccessData
Parameters:
id -
Returns:
true if the file has been touched during the current crawl, false otherwise


Copyright © 2010 Aperture Development Team. All Rights Reserved.