| Method from org.apache.cocoon.components.CocoonComponentManager Detail: |
public void addComponent(String role,
Class clazz,
Configuration conf) throws ComponentException {
super.addComponent(role, clazz, conf);
// Note that at this point, we're not initialized and cannot do
// lookups, so defer parental introductions to initialize().
if (ParentAware.class.isAssignableFrom(clazz)) {
this.parentAwareComponents.add(role);
}
}
|
public static void addComponentForAutomaticRelease(ComponentManager manager,
Component component) throws ProcessingException {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.isEmpty()) {
final EnvironmentStack.Item objects = (EnvironmentStack.Item)stack.get(0);
final Map objectModel = objects.env.getObjectModel();
EnvironmentDescription desc = (EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
desc.addToAutoRelease(manager, component);
}
} else {
throw new ProcessingException("Unable to add component for automatic release: no environment available.");
}
}
Add an automatically released component |
public static void addComponentForAutomaticRelease(ComponentSelector selector,
Component component,
ComponentManager manager) throws ProcessingException {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.isEmpty()) {
final EnvironmentStack.Item objects = (EnvironmentStack.Item)stack.get(0);
final Map objectModel = objects.env.getObjectModel();
EnvironmentDescription desc = (EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
desc.addToAutoRelease(selector, component, manager);
}
} else {
throw new ProcessingException("Unable to add component for automatic release: no environment available.");
}
}
Add an automatically released component |
public static void checkEnvironment(int depth,
Logger logger) throws Exception {
// TODO (CZ): This is only for testing - remove it later on. See also Cocoon.java.
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
int currentDepth = stack != null? stack.size() : 0;
if (currentDepth != depth) {
logger.error("ENVIRONMENT STACK HAS NOT BEEN CLEANED PROPERLY!");
throw new ProcessingException("Environment stack has not been cleaned up properly. " +
"Please report this (and if possible, together with a test case) " +
"to the Cocoon developers.");
}
}
INTERNAL METHOD. Do not use, can be removed without warning or deprecation cycle. |
public static XMLConsumer createEnvironmentAwareConsumer(XMLConsumer consumer) {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
final EnvironmentStack.Item objs = stack.getCurrent();
return stack.getEnvironmentAwareConsumerWrapper(consumer, objs.offset);
}
Create an environment aware xml consumer for the cocoon
protocol |
public void dispose() {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("CocoonComponentManager.dispose() called");
}
if (null != this.sourceResolver) {
super.release((Component)this.sourceResolver);
// We cannot null out sourceResolver here yet as some other not
// disposed yet components might still have unreleased sources,
// and they will call {@link #release(Source)} during their
// dispose().
}
super.dispose();
// All components now are released so sourceResolver should be not
// needed anymore.
this.sourceResolver = null;
// This is used to track bug 27249
this.wasDisposed = true;
}
|
public static void endProcessing(Environment env,
Object key) {
env.finishingProcessing();
final EnvironmentDescription desc = (EnvironmentDescription)key;
desc.release();
env.getObjectModel().remove(PROCESS_KEY);
}
This hook has to be called before a request is processed.
The hook is called by the Cocoon component and by the
cocoon protocol implementation. |
public static void enterEnvironment(Environment env,
ComponentManager manager,
Processor processor) {
if (null == env || null == manager || null == processor) {
throw new RuntimeException("CocoonComponentManager.enterEnvironment: " +
"All parameters must be set: " + env + " - " + manager + " - " + processor);
}
EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if (stack == null) {
stack = new EnvironmentStack();
environmentStack.set(stack);
}
stack.push(new EnvironmentStack.Item(env, processor, manager, stack.getOffset()));
stack.setOffset(stack.size()-1);
env.setAttribute(PROCESSOR_ATTR, processor);
}
This hook must be called by the sitemap each time a sitemap is entered
This method should never raise an exception, except when the
parameters are not set! |
public static Processor getActiveProcessor(Environment env) {
return (Processor) env.getAttribute(PROCESSOR_ATTR);
}
Return the processor that has actually processed the request |
public static Environment getCurrentEnvironment() {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if (null != stack && !stack.isEmpty()) {
return stack.getCurrent().env;
}
return null;
}
Return the current environment (for the cocoon: protocol) |
public static Processor getCurrentProcessor() {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if (null != stack && !stack.isEmpty()) {
return stack.getCurrent().processor;
}
return null;
}
Return the current processor (for the cocoon: protocol) |
public static ComponentManager getSitemapComponentManager() {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if (null != stack && !stack.isEmpty()) {
EnvironmentStack.Item o = (EnvironmentStack.Item) stack.peek();
return o.manager;
}
// If we don't have an environment yet, just return null
return null;
}
Get the current sitemap component manager.
This method return the current sitemap component manager. This
is the manager that holds all the components of the currently
processed (sub)sitemap. |
public void initialize() throws Exception {
super.initialize();
if (this.parentAwareComponents == null) {
throw new ComponentException(null, "CocoonComponentManager already initialized");
}
// Set parents for parentAware components
Iterator iter = this.parentAwareComponents.iterator();
while (iter.hasNext()) {
String role = (String)iter.next();
this.getLogger().debug(".. "+role);
if ( this.parentManager != null && this.parentManager.hasComponent( role ) ) {
// lookup new component
Component component = null;
try {
component = this.lookup( role );
((ParentAware)component).setParentLocator( new ComponentLocatorImpl(this.parentManager, role ));
} catch (ComponentException ignore) {
// we don't set the parent then
} finally {
this.release( component );
}
}
}
this.parentAwareComponents = null; // null to save memory, and catch logic bugs.
}
|
public static void leaveEnvironment() {
// Calling with true will avoid any change on the active processor
leaveEnvironment(true);
}
|
public static void leaveEnvironment(boolean success) {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
final EnvironmentStack.Item objs = (EnvironmentStack.Item)stack.pop();
stack.setOffset(objs.offset);
if (stack.isEmpty()) {
final Environment env = objs.env;
final Map globalComponents = (Map)env.getAttribute(GlobalRequestLifecycleComponent.class.getName());
if (globalComponents != null) {
final Iterator iter = globalComponents.values().iterator();
while (iter.hasNext()) {
final Object[] o = (Object[])iter.next();
final Component c = (Component)o[0];
((CocoonComponentManager)o[1]).releaseRLComponent( c );
}
}
env.removeAttribute(GlobalRequestLifecycleComponent.class.getName());
// Setting this ThreadLocal to null allows it to be garbage collected
CocoonComponentManager.environmentStack.set(null);
} else {
if (!success) {
// Restore the current processor as being the active one
getCurrentEnvironment().setAttribute(PROCESSOR_ATTR, getCurrentProcessor());
}
}
}
|
public Component lookup(String role) throws ComponentException {
if (null == role) {
final String message =
"ComponentLocator Attempted to retrieve component with null role.";
throw new ComponentException(role, message);
}
if (role.equals(SourceResolver.ROLE)) {
if (null == this.sourceResolver) {
if(this.wasDisposed) {
// (BD) working on bug 27249: I think we could throw an Exception here, as
// the following call fails anyway, but I'm not sure enough ;-)
this.getLogger().warn("Trying to lookup SourceResolver on disposed CocoonComponentManager");
}
this.sourceResolver = (SourceResolver) super.lookup( role );
}
return this;
}
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.isEmpty()) {
final EnvironmentStack.Item objects = stack.getCurrent();
final Map objectModel = objects.env.getObjectModel();
EnvironmentDescription desc = (EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
Component component = desc.getRequestLifecycleComponent(role);
if (null != component) {
return component;
}
component = desc.getGlobalRequestLifecycleComponent(role);
if (null != component) {
return component;
}
}
}
final Component component = super.lookup(role);
if (component != null && component instanceof RequestLifecycleComponent) {
if (stack == null || stack.isEmpty()) {
throw new ComponentException(role, "ComponentManager has no Environment Stack.");
}
final EnvironmentStack.Item objects = stack.getCurrent();
final Map objectModel = objects.env.getObjectModel();
EnvironmentDescription desc = (EnvironmentDescription) objectModel.get(PROCESS_KEY);
if (null != desc) {
// first test if the parent CM has already initialized this component
if (!desc.containsRequestLifecycleComponent(role)) {
try {
if (component instanceof Recomposable) {
((Recomposable) component).recompose(this);
}
((RequestLifecycleComponent) component).setup(objects.env, objectModel);
} catch (Exception local) {
throw new ComponentException(role, "Exception during setup of RequestLifecycleComponent.", local);
}
desc.addRequestLifecycleComponent(role, component, this);
}
}
}
if (component != null && component instanceof GlobalRequestLifecycleComponent) {
if (stack == null || stack.isEmpty()) {
throw new ComponentException(role, "ComponentManager has no Environment Stack.");
}
final EnvironmentStack.Item objects = stack.getCurrent();
final Map objectModel = objects.env.getObjectModel();
EnvironmentDescription desc = (EnvironmentDescription) objectModel.get(PROCESS_KEY);
if (null != desc) {
// first test if the parent CM has already initialized this component
if ( !desc.containsGlobalRequestLifecycleComponent( role ) ) {
try {
if (component instanceof Recomposable) {
((Recomposable) component).recompose(this);
}
((GlobalRequestLifecycleComponent) component).setup(objects.env, objectModel);
} catch (Exception local) {
throw new ComponentException(role, "Exception during setup of RequestLifecycleComponent.", local);
}
desc.addGlobalRequestLifecycleComponent(role, component, this);
}
}
}
if (component != null && component instanceof SitemapConfigurable) {
// FIXME: how can we prevent that this is called over and over again?
SitemapConfigurationHolder holder;
holder = (SitemapConfigurationHolder) this.sitemapConfigurationHolders.get(role);
if (null == holder) {
// create new holder
holder = new DefaultSitemapConfigurationHolder(role);
this.sitemapConfigurationHolders.put(role, holder);
}
try {
((SitemapConfigurable)component).configure(holder);
} catch (ConfigurationException ce) {
throw new ComponentException(role, "Exception during setup of SitemapConfigurable.", ce);
}
}
return component;
}
Return an instance of a component based on a Role. The Role is usually the Interface's
Fully Qualified Name(FQN)--unless there are multiple Components for the same Role. In that
case, the Role's FQN is appended with "Selector", and we return a ComponentSelector. |
public static int markEnvironment() {
// TODO (CZ): This is only for testing - remove it later on. See also Cocoon.java.
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if (stack != null) {
return stack.size();
}
return 0;
}
INTERNAL METHOD. Do not use, can be removed without warning or deprecation cycle. |
public void release(Component component) {
if (null == component) {
return;
}
if (component instanceof RequestLifecycleComponent
|| component instanceof GlobalRequestLifecycleComponent) {
return;
}
if (component == this) {
return;
}
super.release(component);
}
Release a Component. This implementation makes sure it has a handle on the propper
ComponentHandler, and let's the ComponentHandler take care of the actual work. |
public void release(Source source) {
this.sourceResolver.release(source);
}
Releases a resolved resource |
protected void releaseRLComponent(Component component) {
super.release(component);
}
Release a RequestLifecycleComponent |
public static void removeFromAutomaticRelease(Component component) throws ProcessingException {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.isEmpty()) {
final EnvironmentStack.Item objects = (EnvironmentStack.Item)stack.get(0);
final Map objectModel = objects.env.getObjectModel();
EnvironmentDescription desc = (EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
desc.removeFromAutoRelease(component);
}
} else {
throw new ProcessingException("Unable to remove component from automatic release: no environment available.");
}
}
Remove from automatically released components |
public Source resolveURI(String location) throws MalformedURLException, SourceException, IOException {
return this.resolveURI(location, null, null);
}
|
public Source resolveURI(String location,
String baseURI,
Map parameters) throws MalformedURLException, SourceException, IOException {
if (baseURI == null) {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.isEmpty()) {
final EnvironmentStack.Item objects = stack.getCurrent();
baseURI = objects.env.getContext();
}
}
return this.sourceResolver.resolveURI(location, baseURI, parameters);
}
|
public void setInstrumentManager(InstrumentManager iManager) {
this.instrumentManager = iManager;
super.setInstrumentManager(iManager);
}
|
protected void setParentManager(ComponentManager manager) {
this.parentManager = manager;
if ( manager instanceof CocoonComponentManager ) {
this.setInstrumentManager(((CocoonComponentManager)manager).instrumentManager);
}
}
|
public static Object startProcessing(Environment env) {
if (null == env) {
throw new RuntimeException("CocoonComponentManager.startProcessing: environment must be set.");
}
final EnvironmentDescription desc = new EnvironmentDescription(env);
env.getObjectModel().put(PROCESS_KEY, desc);
env.startingProcessing();
return desc;
}
This hook has to be called before a request is processed.
The hook is called by the Cocoon component and by the
cocoon protocol implementation.
This method should never raise an exception, except when
the environment is not set. |