| Method from org.apache.cocoon.components.ExtendedComponentSelector Detail: |
protected boolean canRelease(Component component) {
if (this.parentSelector != null && this.parentSelector.canRelease(component)) {
return true;
}
return super.canRelease(component);
}
|
public void configure(Configuration config) throws ConfigurationException {
// Store location
this.location = config.getLocation();
this.roleName = getRoleName(config);
// Pass a copy of the top-level object to superclass so that
// our name is properly initialized
// FIXME : could be avoided if parent m_role was protected or had protected accessors
DefaultConfiguration temp = new DefaultConfiguration(config.getName(), this.location);
if (config.getAttribute("role", null) != null) {
temp.setAttribute("role", this.roleName);
}
super.configure(temp);
// Get default hint
this.defaultHint = config.getAttribute(this.getDefaultHintAttributeName(), null);
// Add components
String compInstanceName = getComponentInstanceName();
Configuration[] instances = config.getChildren();
for (int i = 0; i < instances.length; i++) {
Configuration instance = instances[i];
Object hint = instance.getAttribute("name").trim();
String classAttr = instance.getAttribute(getClassAttributeName(), null);
String className;
if (compInstanceName == null) {
// component-instance implicitly defined by the presence of the 'class' attribute
if (classAttr == null) {
className = this.roles.getDefaultClassNameForHint(roleName, instance.getName());
} else {
className = classAttr.trim();
}
} else {
// component-instances names explicitly defined
if (compInstanceName.equals(instance.getName())) {
className = (classAttr == null) ? null : classAttr.trim();
} else {
className = this.roles.getDefaultClassNameForHint(roleName, instance.getName());
}
}
if (className == null) {
String message = "Unable to determine class name for component named '" + hint +
"' at " + instance.getLocation();
getLogger().error(message);
throw new ConfigurationException(message);
}
try {
Class clazz = this.classLoader.loadClass(className);
addComponent(hint, clazz, instance);
} catch (Exception e) {
String message = "Could not load class " + className + " for component named '" +
hint + "' at " + instance.getLocation();
getLogger().error(message, e);
throw new ConfigurationException(message, e);
}
}
}
Configure this selector. This is the main difference with the parent class :
- if #getComponentInstanceName() returns
null,
any child configurations having a attribute named as the result of
#getClassAttributeName() , is considered as a component instance.
- if #getComponentInstanceName() returns a non-null value,
only child configurations having this name are considered as a
component instance.
- if other cases, it's name is considered to be a hint in the role manager.
The behaviour is then the same as
ExcaliburComponentSelector.
|
public void dispose() {
super.dispose();
if (this.parentLocator != null) {
this.parentLocator.release(this.parentSelector);
this.parentLocator = null;
this.parentSelector = null;
}
}
|
protected String getClassAttributeName() {
return "class";
}
Get the name of the attribute giving the class name of a component.
The default here is "class", but this can be overriden in subclasses. |
protected String getComponentInstanceName() {
return null;
}
Get the name for component-instance elements (i.e. components not defined
by their role shortcut. If null, any element having a 'class'
attribute will be considered as a component instance.
The default here is to return null, and subclasses can redefine
this method to return particular values. |
public String getDefaultHint() {
// Inherit parent default hint if have no own
if (this.defaultHint == null && this.parentSelector != null) {
return this.parentSelector.getDefaultHint();
}
return this.defaultHint;
}
Get the default hint, if any for this selector. |
protected String getDefaultHintAttributeName() {
return "default";
}
Get the name of the attribute giving the default hint to use if
none is given. The default here is "default", but this can be
overriden in subclasses. If this method returns null,
no default hint can be specified. |
protected String getRoleName(Configuration config) {
// Get the role for this selector
String roleName = config.getAttribute("role", null);
if (roleName == null && this.roles != null) {
roleName = this.roles.getRoleForName(config.getName());
}
return roleName;
}
Get the role name for this selector. This is called by configure()
to set the value of this.roleName. |
public boolean hasComponent(Object hint) {
boolean exists = super.hasComponent(hint);
if (!exists && this.parentSelector != null) {
exists = this.parentSelector.hasComponent(hint);
}
return exists;
}
Does this selector or its parent have the given hint ? |
protected boolean hasDeclaredComponent(Object hint) {
return super.hasComponent(hint);
}
Does this selector declare a given hint? Check is performed on the components declared for this
selector only, and not those potentially inherited from the parent selector. |
public void release(Component component) {
// Was it selected on the parent ?
if (this.parentSelector != null && this.parentSelector.canRelease(component)) {
// Yes
this.parentSelector.release(component);
} else {
// No
super.release(component);
}
}
|
public Component select(Object hint) throws ComponentException {
if (hint == null) {
hint = this.defaultHint;
}
if (parentSelector == null) {
// No parent: default behaviour
return super.select(hint);
}
try {
// Try in this selector first
final Component component = super.select(hint);
return component;
} catch (ComponentException original) {
try {
// Doesn't exist here: try in parent selector
final Component component = this.parentSelector.select(hint);
return component;
} catch (ComponentException nested) {
// Doesn't exist in parent too: throw exception.
if (nested.getCause() != null) {
// Nested exception has a cause; let's throw it instead of original.
throw nested;
}
// Throw original exception
throw original;
}
}
}
|
public void setParentLocator(ComponentLocator locator) throws ComponentException {
if (this.parentSelector != null) {
throw new ComponentException(null, "Parent selector is already set");
}
this.parentLocator = locator;
this.parentSelector = (ExtendedComponentSelector) locator.lookup();
}
|
public void setRoleManager(RoleManager roles) {
super.setRoleManager(roles);
this.roles = roles;
}
Configure the RoleManager. Redeclared only because parent member is private. |