JBoss MetaData Repository 2.2.0.SP1

org.jboss.metadata.spi.scope
Class ScopeKey

java.lang.Object
  extended by org.jboss.metadata.spi.scope.ScopeKey
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
UnmodifiableScopeKey

public class ScopeKey
extends Object
implements Serializable, Cloneable

The ScopeKey represents a path which is made up of the path entries. Elements may be added dynamically until the ScopeKey is frozen. If you want to add more elements to a frozen ScopeKey, clone it (cloned objects are not frozen). To use the ScopeKey as a key object, use the UnmodifiableScopeKey returned from getOptimizedKey(). UnmodifiableScopeKey's are immutable and suitable for use as a key (also thread-safe with no object lock contention). The ScopeKey (Server=Bob,Deployment=Foo.war,Class=Bar) is the child of (Server=Bob,Deployment=Foo.war), which is the child of (Server=Bob). Think about this statement in terms of a path relationship. The server (Bob) contains a deployment (Foo.war) and the deployment contains a class (Bar). See historical design notes http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3972233#3972233 http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4013747#4013747 Thread Safety: This class is thread safe. Warning: This class is (delicately) extended by UnmodifiableScopeKey. Since there is no common interface class between the two classes, there are risks to be aware of. If a new method is added to ScopeKey and not to UnmodifiableScopeKey, undesireable behavior will occur when that UnmodifiableScopeKey.method is invoked (ScopeKey's member variables will be null).

Version:
$Revision: 101076 $
Author:
Adrian Brock
See Also:
Serialized Form

Field Summary
static ScopeKey DEFAULT_SCOPE
          The default scope
 
Constructor Summary
ScopeKey()
          Create a new ScopeKey.
ScopeKey(Collection<Scope> scopes)
          Create a new ScopeKey.
ScopeKey(Scope scope)
          Create a new ScopeKey.
ScopeKey(Scope[] scopes)
          Create a new ScopeKey.
ScopeKey(ScopeLevel level, Object qualifier)
          Create a new ScopeKey.
 
Method Summary
 Scope addScope(Scope scope)
          Add a scope
 Scope addScope(ScopeLevel level, Object qualifier)
          Add a scope
 ScopeKey clone()
          Clone a ScopeKey instance.
protected static int computeHashCode(Iterable<Scope> scopeCollection)
           
protected static int computeHashCode(Scope[] scopeArray)
           
 boolean equals(Object object)
           
 void freeze()
          Set to frozen.
protected  Scope[] getArray()
           
 ScopeLevel getMaxScopeLevel()
          Get the maximum scope level
 ScopeKey getOptimizedKey()
          The returned ScopeKey is immutable and optimized for use at runtime.
 ScopeKey getParent()
          Get the parent scope key
 Scope getScope(ScopeLevel level)
          Get a scope
 Scope getScopeLevel(ScopeLevel scopeLevel)
          Get a scope level
 Collection<Scope> getScopes()
          Get the scopes
protected  Collection<Scope> getScopesCollection()
           
 int hashCode()
           
 boolean isFrozen()
          Get the frozen.
 boolean isParent(ScopeKey key)
          Is this parent of key parameter.
 Scope removeScope(Scope scope)
          Remove a scope
 Scope removeScopeLevel(ScopeLevel scopeLevel)
          Remove a scope level
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SCOPE

public static final ScopeKey DEFAULT_SCOPE
The default scope

Constructor Detail

ScopeKey

public ScopeKey()
Create a new ScopeKey.


ScopeKey

public ScopeKey(Scope scope)
Create a new ScopeKey.

Parameters:
scope - the scope

ScopeKey

public ScopeKey(ScopeLevel level,
                Object qualifier)
Create a new ScopeKey.

Parameters:
level - the scope level
qualifier - the scope qualifier

ScopeKey

public ScopeKey(Collection<Scope> scopes)
Create a new ScopeKey.

Parameters:
scopes - is a collection of Scope instances that make up the represented path
Throws:
IllegalArgumentException - if parameter scopes is null

ScopeKey

public ScopeKey(Scope[] scopes)
Create a new ScopeKey.

Parameters:
scopes - is zero or more Scope instances that make up the represented path
Throws:
IllegalArgumentException - if parameter scopes is null
Method Detail

isFrozen

public boolean isFrozen()
Get the frozen.

Returns:
the frozen.

freeze

public void freeze()
Set to frozen.

Throws:
IllegalArgumentException - if there are no Scope entries added.

getOptimizedKey

public ScopeKey getOptimizedKey()
The returned ScopeKey is immutable and optimized for use at runtime.

Returns:
Optimized immutable ScopeKey

getScopes

public Collection<Scope> getScopes()
Get the scopes

Returns:
the scopes in expected path order

getScope

public Scope getScope(ScopeLevel level)
Get a scope

Parameters:
level - the scope level
Returns:
the scope
Throws:
IllegalArgumentException - if level is null.

getMaxScopeLevel

public ScopeLevel getMaxScopeLevel()
Get the maximum scope level

Returns:
the largest scope level

getParent

public ScopeKey getParent()
Get the parent scope key

Returns:
the parent or null if there is no parent (meaning that we are at the top most element in the path)

isParent

public boolean isParent(ScopeKey key)
Is this parent of key parameter.

Parameters:
key - the key parameter
Returns:
true if this is direct parent of key param
Throws:
IllegalArgumentException - if parameter key is null

addScope

public Scope addScope(Scope scope)
Add a scope

Parameters:
scope - the scope
Returns:
the previous value or null if there wasn't one
Throws:
IllegalArgumentException - if scope is null.
IllegalStateException - if frozen

addScope

public Scope addScope(ScopeLevel level,
                      Object qualifier)
Add a scope

Parameters:
level - the scope level
qualifier - the scope qualifier
Returns:
the previous value or null if there wasn't one

removeScope

public Scope removeScope(Scope scope)
Remove a scope

Parameters:
scope - the scope
Returns:
the previous value or null if there wasn't one

getScopeLevel

public Scope getScopeLevel(ScopeLevel scopeLevel)
Get a scope level

Parameters:
scopeLevel - the scope level
Returns:
the scope or null if there is no such level
Throws:
IllegalArgumentException - if parameter key is null

removeScopeLevel

public Scope removeScopeLevel(ScopeLevel scopeLevel)
Remove a scope level

Parameters:
scopeLevel - the scope level
Returns:
the scope or null if there is no such level

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

clone

public ScopeKey clone()
Clone a ScopeKey instance.

Overrides:
clone in class Object
Returns:
an unfrozen instance (even if the current instance is frozen).

getArray

protected Scope[] getArray()

getScopesCollection

protected Collection<Scope> getScopesCollection()

computeHashCode

protected static int computeHashCode(Scope[] scopeArray)

computeHashCode

protected static int computeHashCode(Iterable<Scope> scopeCollection)

JBoss MetaData Repository 2.2.0.SP1

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.