protected void insertImplementation(MutablePicoContainer container, Element rootElement) throws ClassNotFoundException {
String key = rootElement.getAttribute(KEY);
String klass = rootElement.getAttribute(CLASS);
String constructor = rootElement.getAttribute(CONSTRUCTOR);
if (klass == null || "".equals(klass)) {
throw new NanoContainerMarkupException("class specification is required for component implementation");
}
Class clazz = getClassLoader().loadClass(klass);
List parameters = new ArrayList();
NodeList children = rootElement.getChildNodes();
Node child;
String name;
String dependencyKey;
String dependencyClass;
Object parseResult;
for (int i = 0; i < children.getLength(); i++) {
child = children.item(i);
if (child.getNodeType() == Document.ELEMENT_NODE) {
name = child.getNodeName();
// constant parameter. it does not have any attributes.
if (CONSTANT.equals(name)) {
// create constant with xstream
parseResult = parseElementChild((Element) child);
if (parseResult == null) {
throw new NanoContainerMarkupException("could not parse constant parameter");
}
parameters.add(new ConstantParameter(parseResult));
} else if (DEPENDENCY.equals(name)) {
// either key or class must be present. not both
// key has prececence
dependencyKey = ((Element) child).getAttribute(KEY);
if (dependencyKey == null || "".equals(dependencyKey)) {
dependencyClass = ((Element) child).getAttribute(CLASS);
if (dependencyClass == null || "".equals(dependencyClass)) {
throw new NanoContainerMarkupException("either key or class must be present for dependency");
} else {
parameters.add(new ComponentParameter(getClassLoader().loadClass(dependencyClass)));
}
} else {
parameters.add(new ComponentParameter(dependencyKey));