KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > tree > JavaTreeModelDefinition


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
29  * A {@link org.apache.cocoon.forms.formmodel.tree.TreeModelDefinition} based on an Java class
30  * implementing {@link org.apache.cocoon.forms.formmodel.tree.TreeModel}.
31  *
32  * @version $Id: JavaTreeModelDefinition.java 190962 2005-06-16 17:17:00Z sylvain $
33  */

34 public class JavaTreeModelDefinition extends AbstractLogEnabled
35     implements TreeModelDefinition, Contextualizable, Serviceable {
36     
37     private Class JavaDoc 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 JavaDoc 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 JavaDoc e) {
60             throw new CascadingRuntimeException("Cannot instanciate class " + modelClass.getName(), e);
61         }
62         
63         return model;
64     }
65 }
66
Popular Tags