de.topicmapslab.majortom.cache
Class IdentityCache

java.lang.Object
  extended by de.topicmapslab.majortom.cache.IdentityCache
All Implemented Interfaces:
de.topicmapslab.majortom.model.event.ITopicMapListener

 class IdentityCache
extends java.lang.Object
implements de.topicmapslab.majortom.model.event.ITopicMapListener

Base implementation of a store object containing all identity informations

Author:
Sven Krosse

Nested Class Summary
(package private)  class IdentityCache.BestIdentifierKey
           
(package private)  class IdentityCache.BestLabelKey
           
(package private) static class IdentityCache.Key
          enumeration used as key for internal storage
 
Field Summary
private  java.util.Map<IdentityCache.BestIdentifierKey,java.lang.String> bestIdentifiers
          map to store the best identifiers of a topic
private  java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<IdentityCache.BestLabelKey>> bestLabelCacheKeys
          A Map containing all cache keys of the specified topic
private  java.util.Map<IdentityCache.BestLabelKey,java.lang.String> bestLabels
          map to store the best labels of a topic
private  java.util.Map<de.topicmapslab.majortom.model.core.IConstruct,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> constructItemIdentifiers
          construct to item-identifiers mapping
private  java.util.Map<IdentityCache.Key,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> identities
          Map to store the all identities contained by the topic map instance
private  org.apache.commons.collections.BidiMap ids
          Map to store IDs and the corresponding constructs
private  java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.IConstruct> itemIdentifiers
          item-identifier mapping of the topic map engine
private  java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.ILocator> locators
          storage map of the reference-locator mapping of the topic map
private  java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.ITopic> subjectIdentifiers
          subject-identifier mapping of the topic map engine
private  java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.ITopic> subjectLocators
          subject-locator mapping of the topic map engine
private  java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> topicSubjectIdentifiers
          topic to subject-identifiers mapping
private  java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> topicSubjectLocators
          topic to subject-locators mapping
 
Constructor Summary
IdentityCache()
           
 
Method Summary
 de.topicmapslab.majortom.model.core.IConstruct byId(java.lang.String id)
          Return the construct identified by the given id.
<T extends de.topicmapslab.majortom.model.core.IConstruct>
T
byIdentity(java.util.Map<de.topicmapslab.majortom.model.core.ILocator,T> map, de.topicmapslab.majortom.model.core.ILocator l)
          Secure extraction of a construct by its identity from the given map.
 de.topicmapslab.majortom.model.core.IConstruct byItemIdentifier(de.topicmapslab.majortom.model.core.ILocator l)
          Return the construct identified by the given item-identifier.
 de.topicmapslab.majortom.model.core.ITopic bySubjectIdentifier(de.topicmapslab.majortom.model.core.ILocator l)
          Return the topic identified by the given subject-identifier.
 de.topicmapslab.majortom.model.core.ITopic bySubjectLocator(de.topicmapslab.majortom.model.core.ILocator l)
          Return the topic identified by the given subject-locator.
 void cacheBestIdentifier(de.topicmapslab.majortom.model.core.ITopic t, boolean withPrefix, java.lang.String bestIdentifier)
          Cache the best label of the given topic to the internal store.
 void cacheBestLabel(de.topicmapslab.majortom.model.core.ITopic t, de.topicmapslab.majortom.model.core.ITopic theme, boolean strict, java.lang.String bestLabel)
          Cache the best label of the given topic to the internal store.
 void cacheBestLabel(de.topicmapslab.majortom.model.core.ITopic t, java.lang.String bestLabel)
          Cache the best label of the given topic to the internal store.
 void cacheId(java.lang.String id, de.topicmapslab.majortom.model.core.IConstruct c)
          Cache the mapping between the id and the construct into internal store.
 void cacheIdentities(IdentityCache.Key key, java.util.Set<de.topicmapslab.majortom.model.core.ILocator> locators)
          Cache the given identities to the internal cache
 void cacheItemIdentifier(de.topicmapslab.majortom.model.core.ILocator l, de.topicmapslab.majortom.model.core.IConstruct c)
          Cache the mapping between the item-identifier and the construct into internal store.
 void cacheItemIdentifiers(de.topicmapslab.majortom.model.core.IConstruct c, java.util.Set<de.topicmapslab.majortom.model.core.ILocator> identifiers)
          Cache the item-identifiers of the given construct to the internal store.
 void cacheSubjectIdentifier(de.topicmapslab.majortom.model.core.ILocator l, de.topicmapslab.majortom.model.core.ITopic t)
          Cache the mapping between the subject-identifier and the topic into internal store.
 void cacheSubjectIdentifiers(de.topicmapslab.majortom.model.core.ITopic t, java.util.Set<de.topicmapslab.majortom.model.core.ILocator> identifiers)
          Cache the subject-identifiers of the given topic to the internal store.
 void cacheSubjectLocator(de.topicmapslab.majortom.model.core.ILocator l, de.topicmapslab.majortom.model.core.ITopic t)
          Cache the mapping between the subject-locator and the topic into internal store.
 void cacheSubjectLocators(de.topicmapslab.majortom.model.core.ITopic t, java.util.Set<de.topicmapslab.majortom.model.core.ILocator> identifiers)
          Cache the subject-locators of the given topic to the internal store.
 void clear()
          
private  IdentityCache.BestLabelKey generateKey(de.topicmapslab.majortom.model.core.ITopic topic, de.topicmapslab.majortom.model.core.ITopic theme, boolean strict)
          Generates a key for the given topic and theme
 java.lang.String getBestIdentifier(de.topicmapslab.majortom.model.core.ITopic t, boolean withPrefix)
          Returns the best label for the given topic
 java.lang.String getBestLabel(de.topicmapslab.majortom.model.core.ITopic t)
          Returns the best label for the given topic
 java.lang.String getBestLabel(de.topicmapslab.majortom.model.core.ITopic t, de.topicmapslab.majortom.model.core.ITopic theme, boolean strict)
          Returns the best label for the given topic
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getIdentifiers()
          Return all internal stored identifiers.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getIdentities(IdentityCache.Key key)
          Extract the identities contained by the current topic map of the specified type.
<T extends de.topicmapslab.majortom.model.core.IConstruct>
java.util.Set<de.topicmapslab.majortom.model.core.ILocator>
getIdentities(java.util.Map<T,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> map, T construct)
          Secure extraction of the identities of the given construct from the given map.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getItemIdentifiers()
          Return all internal stored item-identifiers.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getItemIdentifiers(de.topicmapslab.majortom.model.core.IConstruct c)
          Return all item-identifiers of the given construct.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectIdentifiers()
          Return all internal stored subject-identifiers.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectIdentifiers(de.topicmapslab.majortom.model.core.ITopic t)
          Return all subject-identifiers of the given topic.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectLocators()
          Return all internal stored subject-locators.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectLocators(de.topicmapslab.majortom.model.core.ITopic t)
          Return all subject-locator of the given topic.
private  void removeBestIdentifiers(de.topicmapslab.majortom.model.core.ITopic topic)
          Removing all best-identifiers of the given topic
private  void removeBestLabels(de.topicmapslab.majortom.model.core.ITopic topic, de.topicmapslab.majortom.model.core.ITopic... themes)
          Removing all best-labels for the given topic and all themes
private  void removeConstructItemFromCache(de.topicmapslab.majortom.model.core.IConstruct construct, de.topicmapslab.majortom.model.core.IConstruct notifier)
          Remove all relevant cache entries for the given construct
private  void removeTopicItemFromCache(de.topicmapslab.majortom.model.core.ITopic topic, de.topicmapslab.majortom.model.core.IConstruct notifier)
          Internal method to remove all topic dependent entries from internal caches.
 void topicMapChanged(java.lang.String id, de.topicmapslab.majortom.model.event.TopicMapEventType event, org.tmapi.core.Construct notifier, java.lang.Object newValue, java.lang.Object oldValue)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ids

private org.apache.commons.collections.BidiMap ids
Map to store IDs and the corresponding constructs


identities

private java.util.Map<IdentityCache.Key,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> identities
Map to store the all identities contained by the topic map instance


locators

private java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.ILocator> locators
storage map of the reference-locator mapping of the topic map


itemIdentifiers

private java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.IConstruct> itemIdentifiers
item-identifier mapping of the topic map engine


constructItemIdentifiers

private java.util.Map<de.topicmapslab.majortom.model.core.IConstruct,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> constructItemIdentifiers
construct to item-identifiers mapping


subjectIdentifiers

private java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.ITopic> subjectIdentifiers
subject-identifier mapping of the topic map engine


topicSubjectIdentifiers

private java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> topicSubjectIdentifiers
topic to subject-identifiers mapping


subjectLocators

private java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.ITopic> subjectLocators
subject-locator mapping of the topic map engine


topicSubjectLocators

private java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> topicSubjectLocators
topic to subject-locators mapping


bestLabels

private java.util.Map<IdentityCache.BestLabelKey,java.lang.String> bestLabels
map to store the best labels of a topic


bestLabelCacheKeys

private java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<IdentityCache.BestLabelKey>> bestLabelCacheKeys
A Map containing all cache keys of the specified topic


bestIdentifiers

private java.util.Map<IdentityCache.BestIdentifierKey,java.lang.String> bestIdentifiers
map to store the best identifiers of a topic

Constructor Detail

IdentityCache

IdentityCache()
Method Detail

clear

public void clear()


byId

public de.topicmapslab.majortom.model.core.IConstruct byId(java.lang.String id)
Return the construct identified by the given id.

Parameters:
id - the id
Returns:
the construct or null

byIdentity

public <T extends de.topicmapslab.majortom.model.core.IConstruct> T byIdentity(java.util.Map<de.topicmapslab.majortom.model.core.ILocator,T> map,
                                                                               de.topicmapslab.majortom.model.core.ILocator l)
Secure extraction of a construct by its identity from the given map.

Type Parameters:
T - the generic type of construct to extract
Parameters:
map - the map
l - the locator
Returns:
the construct or null if the given map is null or does not contain the given key.

byItemIdentifier

public de.topicmapslab.majortom.model.core.IConstruct byItemIdentifier(de.topicmapslab.majortom.model.core.ILocator l)
Return the construct identified by the given item-identifier.

Parameters:
l - the item-identifier
Returns:
the construct or null

bySubjectIdentifier

public de.topicmapslab.majortom.model.core.ITopic bySubjectIdentifier(de.topicmapslab.majortom.model.core.ILocator l)
Return the topic identified by the given subject-identifier.

Parameters:
l - the subject-identifier
Returns:
the topic or null

bySubjectLocator

public de.topicmapslab.majortom.model.core.ITopic bySubjectLocator(de.topicmapslab.majortom.model.core.ILocator l)
Return the topic identified by the given subject-locator.

Parameters:
l - the subject-locator
Returns:
the topic or null

cacheId

public void cacheId(java.lang.String id,
                    de.topicmapslab.majortom.model.core.IConstruct c)
Cache the mapping between the id and the construct into internal store.

Parameters:
id - the id
c - the construct

cacheItemIdentifier

public void cacheItemIdentifier(de.topicmapslab.majortom.model.core.ILocator l,
                                de.topicmapslab.majortom.model.core.IConstruct c)
Cache the mapping between the item-identifier and the construct into internal store.

Parameters:
l - the item-identifier
c - the construct

cacheSubjectIdentifier

public void cacheSubjectIdentifier(de.topicmapslab.majortom.model.core.ILocator l,
                                   de.topicmapslab.majortom.model.core.ITopic t)
Cache the mapping between the subject-identifier and the topic into internal store.

Parameters:
l - the subject-identifier
t - the topic

cacheSubjectLocator

public void cacheSubjectLocator(de.topicmapslab.majortom.model.core.ILocator l,
                                de.topicmapslab.majortom.model.core.ITopic t)
Cache the mapping between the subject-locator and the topic into internal store.

Parameters:
l - the subject-locator
t - the topic

getIdentities

public <T extends de.topicmapslab.majortom.model.core.IConstruct> java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getIdentities(java.util.Map<T,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> map,
                                                                                                                                            T construct)
Secure extraction of the identities of the given construct from the given map.

Type Parameters:
T - the generic type of construct
Parameters:
map - the map
construct - the construct
Returns:
the identities or null if the given map is null or does not contain the given key.

getItemIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getItemIdentifiers(de.topicmapslab.majortom.model.core.IConstruct c)
Return all item-identifiers of the given construct.

Parameters:
c - the construct
Returns:
the identifiers

getSubjectIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectIdentifiers(de.topicmapslab.majortom.model.core.ITopic t)
Return all subject-identifiers of the given topic.

Parameters:
t - the topic
Returns:
the identifiers

getSubjectLocators

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectLocators(de.topicmapslab.majortom.model.core.ITopic t)
Return all subject-locator of the given topic.

Parameters:
t - the topic
Returns:
the locators

cacheItemIdentifiers

public void cacheItemIdentifiers(de.topicmapslab.majortom.model.core.IConstruct c,
                                 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> identifiers)
Cache the item-identifiers of the given construct to the internal store.

Parameters:
c - the construct
identifiers - the item-identifiers

cacheSubjectIdentifiers

public void cacheSubjectIdentifiers(de.topicmapslab.majortom.model.core.ITopic t,
                                    java.util.Set<de.topicmapslab.majortom.model.core.ILocator> identifiers)
Cache the subject-identifiers of the given topic to the internal store.

Parameters:
t - the topic
identifiers - the subject-identifiers

cacheSubjectLocators

public void cacheSubjectLocators(de.topicmapslab.majortom.model.core.ITopic t,
                                 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> identifiers)
Cache the subject-locators of the given topic to the internal store.

Parameters:
t - the topic
identifiers - the subject-locators

getIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getIdentifiers()
Return all internal stored identifiers.

Returns:
all identifiers

getIdentities

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getIdentities(IdentityCache.Key key)
Extract the identities contained by the current topic map of the specified type.

Parameters:
key - the type of identities ( item-identifiers, subject-identifiers, subject-locators )
Returns:
the identifiers or null

getItemIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getItemIdentifiers()
Return all internal stored item-identifiers.

Returns:
all item-identifiers

getSubjectIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectIdentifiers()
Return all internal stored subject-identifiers.

Returns:
all subject-identifiers

getSubjectLocators

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectLocators()
Return all internal stored subject-locators.

Returns:
all subject-locators

cacheIdentities

public void cacheIdentities(IdentityCache.Key key,
                            java.util.Set<de.topicmapslab.majortom.model.core.ILocator> locators)
Cache the given identities to the internal cache

Parameters:
key - the key declare the type of identities
locators - the locators

getBestIdentifier

public java.lang.String getBestIdentifier(de.topicmapslab.majortom.model.core.ITopic t,
                                          boolean withPrefix)
Returns the best label for the given topic

Parameters:
t - the topic
withPrefix - flag indicates if the identifier is prefixes
Returns:
the best label

cacheBestIdentifier

public void cacheBestIdentifier(de.topicmapslab.majortom.model.core.ITopic t,
                                boolean withPrefix,
                                java.lang.String bestIdentifier)
Cache the best label of the given topic to the internal store.

Parameters:
t - the topic
withPrefix - flag indicates if the identifier is prefixes
bestIdentifier - the best identifier

getBestLabel

public java.lang.String getBestLabel(de.topicmapslab.majortom.model.core.ITopic t)
Returns the best label for the given topic

Parameters:
t - the topic
Returns:
the best label

cacheBestLabel

public void cacheBestLabel(de.topicmapslab.majortom.model.core.ITopic t,
                           java.lang.String bestLabel)
Cache the best label of the given topic to the internal store.

Parameters:
t - the topic
bestLabel - the best label

getBestLabel

public java.lang.String getBestLabel(de.topicmapslab.majortom.model.core.ITopic t,
                                     de.topicmapslab.majortom.model.core.ITopic theme,
                                     boolean strict)
Returns the best label for the given topic

Parameters:
t - the topic
theme - the theme
strict - the strict flag
Returns:
the best label

cacheBestLabel

public void cacheBestLabel(de.topicmapslab.majortom.model.core.ITopic t,
                           de.topicmapslab.majortom.model.core.ITopic theme,
                           boolean strict,
                           java.lang.String bestLabel)
Cache the best label of the given topic to the internal store.

Parameters:
t - the topic
theme - the theme
strict - the strict flag
bestLabel - the best label

generateKey

private IdentityCache.BestLabelKey generateKey(de.topicmapslab.majortom.model.core.ITopic topic,
                                               de.topicmapslab.majortom.model.core.ITopic theme,
                                               boolean strict)
Generates a key for the given topic and theme

Parameters:
topic - the topic
theme - the theme
Returns:
the generated key

removeBestLabels

private void removeBestLabels(de.topicmapslab.majortom.model.core.ITopic topic,
                              de.topicmapslab.majortom.model.core.ITopic... themes)
Removing all best-labels for the given topic and all themes

Parameters:
topic - the topic
themes - the themes

removeBestIdentifiers

private void removeBestIdentifiers(de.topicmapslab.majortom.model.core.ITopic topic)
Removing all best-identifiers of the given topic

Parameters:
topic - the topic

topicMapChanged

public void topicMapChanged(java.lang.String id,
                            de.topicmapslab.majortom.model.event.TopicMapEventType event,
                            org.tmapi.core.Construct notifier,
                            java.lang.Object newValue,
                            java.lang.Object oldValue)

Specified by:
topicMapChanged in interface de.topicmapslab.majortom.model.event.ITopicMapListener

removeTopicItemFromCache

private final void removeTopicItemFromCache(de.topicmapslab.majortom.model.core.ITopic topic,
                                            de.topicmapslab.majortom.model.core.IConstruct notifier)
Internal method to remove all topic dependent entries from internal caches.

Parameters:
topic - the topic reference to remove
notifier - the parent

removeConstructItemFromCache

private final void removeConstructItemFromCache(de.topicmapslab.majortom.model.core.IConstruct construct,
                                                de.topicmapslab.majortom.model.core.IConstruct notifier)
Remove all relevant cache entries for the given construct

Parameters:
construct - the construct
notifier - the parent