private Configurable getComponentFromAnnotation(String name, S4Component s4Component) { Configurable configurable; Class<? extends Configurable> defClass = s4Component.defaultClass(); if (defClass.equals(Configurable.class) && s4Component.mandatory()) { throw new InternalConfigurationException( getInstanceName(), name, "mandatory property is not set!"); } if (Modifier.isAbstract(defClass.getModifiers()) && s4Component.mandatory()) throw new InternalConfigurationException( getInstanceName(), name, defClass.getName() + " is abstract!"); // because we're forced to use the default type, make sure that it // is set if (defClass.equals(Configurable.class)) { if (s4Component.mandatory()) { throw new InternalConfigurationException( getInstanceName(), name, instanceName + ": no default class defined for " + name); } else { return null; } } configurable = ConfigurationManager.getInstance(defClass); if (configurable == null) { throw new InternalConfigurationException( getInstanceName(), name, "instantiation of referenenced configurable failed"); } return configurable; }
/** * Returns the class of of a registered component property without instantiating it. * * @param propName the name of the property * @return class of the component corresponding to that property */ public Class<? extends Configurable> getComponentClass(String propName) { Class<? extends Configurable> defClass = null; if (propValues.get(propName) != null) try { Class<?> objClass = Class.forName((String) propValues.get(propName)); defClass = objClass.asSubclass(Configurable.class); } catch (ClassNotFoundException e) { PropertySheet ps = cm.getPropertySheet(flattenProp(propName)); defClass = ps.ownerClass; } else { S4Component comAnno = (S4Component) registeredProperties.get(propName).getAnnotation(); defClass = comAnno.defaultClass(); if (comAnno.mandatory()) defClass = null; } return defClass; }