01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.formmodel.tree;
18:
19: import org.apache.avalon.framework.CascadingRuntimeException;
20: import org.apache.avalon.framework.context.Context;
21: import org.apache.avalon.framework.context.ContextException;
22: import org.apache.avalon.framework.context.Contextualizable;
23: import org.apache.avalon.framework.logger.AbstractLogEnabled;
24: import org.apache.avalon.framework.service.ServiceException;
25: import org.apache.avalon.framework.service.ServiceManager;
26: import org.apache.avalon.framework.service.Serviceable;
27: import org.apache.cocoon.components.LifecycleHelper;
28:
29: /**
30: * A {@link org.apache.cocoon.forms.formmodel.tree.TreeModelDefinition} based on an Java class
31: * implementing {@link org.apache.cocoon.forms.formmodel.tree.TreeModel}.
32: *
33: * @version $Id: JavaTreeModelDefinition.java 449149 2006-09-23 03:58:05Z crossley $
34: */
35: public class JavaTreeModelDefinition extends AbstractLogEnabled
36: implements TreeModelDefinition, Contextualizable, Serviceable {
37:
38: private Class modelClass;
39:
40: Context ctx;
41: ServiceManager manager;
42:
43: public void contextualize(Context context) throws ContextException {
44: this .ctx = context;
45: }
46:
47: public void service(ServiceManager manager) throws ServiceException {
48: this .manager = manager;
49: }
50:
51: public void setModelClass(Class clazz) {
52: this .modelClass = clazz;
53: }
54:
55: public TreeModel createInstance() {
56: TreeModel model;
57: try {
58: model = (TreeModel) modelClass.newInstance();
59: LifecycleHelper.setupComponent(model, getLogger(), ctx,
60: manager, null);
61: } catch (Exception e) {
62: throw new CascadingRuntimeException(
63: "Cannot instanciate class " + modelClass.getName(),
64: e);
65: }
66:
67: return model;
68: }
69: }
|