|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jpu.patterns.serviceLocator.Locator
Implementation of the ILocator
interface. See its documentation for more info.
Nested Class Summary | |
class |
Locator.DefaultIdentifierParser
|
static class |
Locator.DefaultLookupStrategy
Simple lookup strategy implementation based on " new InitialContext(System.getProperties()).lookup() ". |
static class |
Locator.DefaultNarrowStrategy
Simple narrow strategy implementation based on " PortableRemoteObject.narrow() ". |
static class |
Locator.NullCache
Simple cache implementation based on HashMap . |
Nested classes inherited from class org.jpu.patterns.serviceLocator.ILocator |
ILocator.ICache, ILocator.IIdentifierParser, ILocator.ILookupStrategy, ILocator.INarrowStrategy |
Constructor Summary | |
Locator()
|
Method Summary | |
void |
clearCache()
Removes all items from the cache. |
ILocator.ICache |
getCache()
Returns the cache. |
java.lang.Class |
getDefaultCast()
By default returns null , but subclasses can override to
return the Class that should be passed as the second parameter
to narrow(Object,Class) if no class is passed via
the castTo attribute of the ServiceLocatorOptions
instance. |
ILocator.ILookupStrategy |
getLookupStrategy()
Returns the current ILocator.ILookupStrategy . |
ILocator.INarrowStrategy |
getNarrowStrategy()
Returns the current ILocator.INarrowStrategy . |
java.lang.Object |
getObject(java.lang.String namingIdentifier)
Convenience alias for " getObject(namingIdentifier, (ServiceLocatorOptions)null) ". |
java.lang.Object |
getObject(java.lang.String namingIdentifier,
java.lang.Class c)
Convenience alias for " getObject( namingIdentifier, new ServiceLocatorOptions().setCastTo(c) ) ". |
java.lang.Object |
getObject(java.lang.String namingIdentifier,
ServiceLocatorOptions options)
Attempts to find the object with the given JNDI name using the given options. |
java.lang.Object |
lookup(java.lang.String namingIdentifier,
ServiceLocatorOptions options)
Simply calls " getLookupStrategy().lookup(namingIdentifier, options) ". |
java.lang.Object |
narrow(java.lang.Object o,
java.lang.Class c)
Simply calls " getNarrowStrategy().narrow(o, c) ". |
java.lang.Object |
narrow(java.lang.Object o,
ServiceLocatorOptions options)
If options.castTo is not null , call narrow(Object,Class)
variant to narrow the given object to this type and return the result; else if
getDefaultCast() is not null , call narrow(Object,Class)
variant to narrow to this type and return the result;
else return the original object passed via "o ". |
ILocator.ICache |
newCache()
By default instantiates a Locator.NullCache , but subclasses can
override to supply their own cache implementation. |
ILocator.IIdentifierParser |
newIdentifier(java.lang.String str,
java.util.Properties props)
|
ILocator.ILookupStrategy |
newLookupStrategy()
By default instantiates a Locator.DefaultLookupStrategy , but subclasses can
override to supply their own ILocator.ILookupStrategy implementation. |
ILocator.INarrowStrategy |
newNarrowStrategy()
By default instantiates a Locator.DefaultNarrowStrategy , but subclasses can
override to supply their own ILocator.INarrowStrategy implementation. |
void |
removeFromCache(java.lang.String namingIdentifier)
Removes the object with the specified JNDI name from the cache. |
void |
setCache(ILocator.ICache cache)
Sets the cache, replacing the previous cache (and hence causing loss of previously cached objects). |
void |
setLookupStrategy(ILocator.ILookupStrategy ls)
Sets the ILocator.ILookupStrategy , replacing the previous one. |
void |
setNarrowStrategy(ILocator.INarrowStrategy ls)
Sets the ILocator.INarrowStrategy , replacing the previous one. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Locator()
Method Detail |
public ILocator.IIdentifierParser newIdentifier(java.lang.String str, java.util.Properties props) throws InvalidIdentifierException
InvalidIdentifierException
public java.lang.Object getObject(java.lang.String namingIdentifier) throws ServiceLocatorException
ILocator
getObject(namingIdentifier, (ServiceLocatorOptions)null)
".
See ILocator.getObject(String, ServiceLocatorOptions)
.
getObject
in interface ILocator
ServiceLocatorException
public void removeFromCache(java.lang.String namingIdentifier)
ILocator
removeFromCache
in interface ILocator
public void clearCache()
ILocator
clearCache
in interface ILocator
public java.lang.Object getObject(java.lang.String namingIdentifier, java.lang.Class c) throws ServiceLocatorException
ILocator
getObject( namingIdentifier, new ServiceLocatorOptions().setCastTo(c) )
".
See ILocator.getObject(String, ServiceLocatorOptions)
.
getObject
in interface ILocator
ServiceLocatorException
public java.lang.Object getObject(java.lang.String namingIdentifier, ServiceLocatorOptions options) throws ServiceLocatorException
ILocator
The method first checks the cache for an object with the given JNDI name, unless
options.noCache
is true
in which case the cache is
bypassed. If the object is not in the cache or the cache is being bypassed,
the method will attempt to find the object using the protected lookup()
method (which subclasses can override). Any exception thrown from that method
will be allowed to propagate from this method. Any object found through
JNDI is automatically entered into the cache via its public put()
method.
If the object is found, either in the cache or via JNDI lookup, then if a narrow
type is defined, either via options.castTo
or
ILocator.getDefaultCast()
, the method will
attempt to narrow the object to that type using the protected narrow()
method (which subclasses are free to override). Narrow's default
implementation uses PortableRemoteObject.narrow()
.
If the named object cannot be found, or if the narrow fails,
ServiceLocatorException
is
thrown wrapping the underlying JNDI exception.
getObject
in interface ILocator
ServiceLocatorException
public void setCache(ILocator.ICache cache)
ILocator
setCache
in interface ILocator
public ILocator.ICache getCache()
ILocator
this
" while querying or modifying it.
getCache
in interface ILocator
public void setNarrowStrategy(ILocator.INarrowStrategy ls)
ILocator
ILocator.INarrowStrategy
, replacing the previous one.
setNarrowStrategy
in interface ILocator
public ILocator.INarrowStrategy getNarrowStrategy()
ILocator
ILocator.INarrowStrategy
.
getNarrowStrategy
in interface ILocator
public void setLookupStrategy(ILocator.ILookupStrategy ls)
ILocator
ILocator.ILookupStrategy
, replacing the previous one.
setLookupStrategy
in interface ILocator
public ILocator.ILookupStrategy getLookupStrategy()
ILocator
ILocator.ILookupStrategy
.
getLookupStrategy
in interface ILocator
public ILocator.ICache newCache()
ILocator
Locator.NullCache
, but subclasses can
override to supply their own cache implementation.
newCache
in interface ILocator
public ILocator.ILookupStrategy newLookupStrategy()
ILocator
Locator.DefaultLookupStrategy
, but subclasses can
override to supply their own ILocator.ILookupStrategy
implementation.
newLookupStrategy
in interface ILocator
public ILocator.INarrowStrategy newNarrowStrategy()
ILocator
Locator.DefaultNarrowStrategy
, but subclasses can
override to supply their own ILocator.INarrowStrategy
implementation.
newNarrowStrategy
in interface ILocator
public java.lang.Object narrow(java.lang.Object o, ServiceLocatorOptions options) throws ServiceLocatorException
ILocator
options.castTo
is not null
, call narrow(Object,Class)
variant to narrow the given object to this type and return the result; else if
ILocator.getDefaultCast()
is not null
, call narrow(Object,Class)
variant to narrow to this type and return the result;
else return the original object passed via "o
".
narrow
in interface ILocator
ServiceLocatorException
public java.lang.Object narrow(java.lang.Object o, java.lang.Class c) throws ServiceLocatorException
ILocator
getNarrowStrategy().narrow(o, c)
". If you wish to
change the way narrowing is performed, write your own ILocator.INarrowStrategy
and either override
ILocator.newNarrowStrategy()
to instantiate it, or call the public ILocator.setNarrowStrategy(ILocator.INarrowStrategy)
method to replace the existing strategy.
narrow
in interface ILocator
ServiceLocatorException
public java.lang.Object lookup(java.lang.String namingIdentifier, ServiceLocatorOptions options) throws ServiceLocatorException
getLookupStrategy().lookup(namingIdentifier, options)
". If you wish to
change the way lookups are performed, write your own ILocator.ILookupStrategy
and either override
newLookupStrategy()
to instantiate it, or call the public setLookupStrategy(ILocator.ILookupStrategy)
method to replace the existing lookup strategy.
ServiceLocatorException
public java.lang.Class getDefaultCast()
ILocator
null
, but subclasses can override to
return the Class
that should be passed as the second parameter
to ILocator.narrow(Object,Class)
if no class is passed via
the castTo
attribute of the ServiceLocatorOptions
instance. If both castTo
and the return value of this method
are null
, no cast is performed.
getDefaultCast
in interface ILocator
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |