A non-threadsafe implementation (expects to use the "perthread" service lifecyle).
| Method from org.apache.tapestry5.internal.services.EnvironmentImpl Detail: |
public void clear() {
lock.check();
typeToStack.clear();
for (EnvironmentalAccessImpl closure : typeToAccess.values())
{
closure.invalidate();
}
}
|
public EnvironmentalAccess<T> getAccess(Class<T> type) {
lock.check();
EnvironmentalAccessImpl access = typeToAccess.get(type);
if (access == null)
{
access = new EnvironmentalAccessImpl(this, type);
typeToAccess.put(type, access);
}
return access;
}
|
void invalidate(Class type) {
EnvironmentalAccessImpl access = typeToAccess.get(type);
if (access != null) access.invalidate();
}
|
public T peek(Class<T> type) {
LinkedList< T > stack = stackFor(type);
return stack.isEmpty() ? null : stack.getFirst();
}
|
public T peekRequired(Class<T> type) {
T result = peek(type);
if (result == null)
{
List< Class > types = CollectionFactory.newList();
for (Map.Entry< Class, LinkedList > e : typeToStack.entrySet())
{
LinkedList list = e.getValue();
if (list != null && !list.isEmpty()) types.add(e.getKey());
}
throw new RuntimeException(ServicesMessages.missingFromEnvironment(type, types));
}
return result;
}
|
public T pop(Class<T> type) {
LinkedList< T > stack = stackFor(type);
invalidate(type);
return stack.removeFirst();
}
|
public T push(Class<T> type,
T instance) {
LinkedList< T > stack = stackFor(type);
T result = stack.isEmpty() ? null : stack.getFirst();
stack.addFirst(instance);
invalidate(type);
return result;
}
|
public void threadDidCleanup() {
lock.lock();
}
|