1 16 package org.apache.cocoon.forms.formmodel.tree; 17 18 import org.apache.avalon.framework.CascadingRuntimeException; 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 28 34 public class JavaTreeModelDefinition extends AbstractLogEnabled 35 implements TreeModelDefinition, Contextualizable, Serviceable { 36 37 private Class modelClass; 38 39 Context ctx; 40 ServiceManager manager; 41 42 public void contextualize(Context context) throws ContextException { 43 this.ctx = context; 44 } 45 46 public void service(ServiceManager manager) throws ServiceException { 47 this.manager = manager; 48 } 49 50 public void setModelClass(Class clazz) { 51 this.modelClass = clazz; 52 } 53 54 public TreeModel createInstance() { 55 TreeModel model; 56 try { 57 model = (TreeModel)modelClass.newInstance(); 58 LifecycleHelper.setupComponent(model, getLogger(), ctx, manager, null); 59 } catch (Exception e) { 60 throw new CascadingRuntimeException("Cannot instanciate class " + modelClass.getName(), e); 61 } 62 63 return model; 64 } 65 } 66 | Popular Tags |