1 16 package org.apache.cocoon.forms.formmodel.tree.builder; 17 18 import org.apache.avalon.framework.CascadingException; 19 import org.apache.avalon.framework.context.Context; 20 import org.apache.avalon.framework.context.ContextException; 21 import org.apache.avalon.framework.context.Contextualizable; 22 import org.apache.avalon.framework.logger.AbstractLogEnabled; 23 import org.apache.avalon.framework.service.ServiceException; 24 import org.apache.avalon.framework.service.ServiceManager; 25 import org.apache.avalon.framework.service.Serviceable; 26 import org.apache.cocoon.components.LifecycleHelper; 27 import org.apache.cocoon.forms.formmodel.tree.JavaTreeModelDefinition; 28 import org.apache.cocoon.forms.formmodel.tree.TreeModel; 29 import org.apache.cocoon.forms.formmodel.tree.TreeModelDefinition; 30 import org.apache.cocoon.forms.util.DomHelper; 31 import org.w3c.dom.Element ; 32 33 39 public class JavaTreeModelDefinitionBuilder extends AbstractLogEnabled 40 implements TreeModelDefinitionBuilder, Contextualizable, Serviceable { 41 42 Context ctx; 43 ServiceManager manager; 44 45 public void contextualize(Context context) throws ContextException { 46 this.ctx = context; 47 } 48 49 public void service(ServiceManager manager) throws ServiceException { 50 this.manager = manager; 51 } 52 53 public TreeModelDefinition build(Element treeModelElement) throws Exception { 54 String className = DomHelper.getAttribute(treeModelElement, "class"); 55 56 Class modelClass; 57 try { 58 modelClass = Thread.currentThread().getContextClassLoader().loadClass(className); 59 } catch(Exception e) { 60 throw new CascadingException("Cannot load class '" + className + "', at " + 61 DomHelper.getLocation(treeModelElement), e); 62 } 63 64 if (!TreeModel.class.isAssignableFrom(modelClass)) { 65 throw new Exception ("Class '" + className + "' doesn't implement TreeModel, at " + 66 DomHelper.getLocation(treeModelElement)); 67 } 68 69 JavaTreeModelDefinition definition = new JavaTreeModelDefinition(); 70 71 LifecycleHelper.setupComponent(definition, getLogger(), ctx, manager, null); 72 73 definition.setModelClass(modelClass); 74 75 return definition; 76 } 77 78 } 79 | Popular Tags |