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.components.language.programming.python;
18:
19: import org.apache.avalon.framework.configuration.DefaultConfiguration;
20: import org.apache.avalon.framework.configuration.Configurable;
21: import org.apache.avalon.framework.component.ComponentManager;
22: import org.apache.avalon.framework.context.Context;
23:
24: import org.apache.avalon.excalibur.component.ComponentHandler;
25: import org.apache.avalon.excalibur.component.RoleManager;
26: import org.apache.avalon.excalibur.component.LogkitLoggerManager;
27:
28: import org.apache.cocoon.components.language.programming.Program;
29: import org.apache.cocoon.components.language.generator.CompiledComponent;
30:
31: import java.io.File;
32: import java.util.Collection;
33: import java.util.Iterator;
34:
35: /**
36: * This class represents program in the Python language.
37: *
38: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
39: * @version CVS $Id: PythonProgram.java 433543 2006-08-22 06:22:54Z crossley $
40: */
41: public class PythonProgram implements Program {
42:
43: protected File file;
44: protected Class clazz;
45: protected DefaultConfiguration config;
46:
47: public PythonProgram(File file, Class clazz, Collection dependecies) {
48: this .file = file;
49: this .clazz = clazz;
50:
51: config = new DefaultConfiguration("", "GeneratorSelector");
52: DefaultConfiguration child = new DefaultConfiguration("file",
53: "");
54: child.setValue(file.toString());
55: config.addChild(child);
56:
57: for (Iterator i = dependecies.iterator(); i.hasNext();) {
58: child = new DefaultConfiguration("dependency", "");
59: child.setValue(i.next().toString());
60: config.addChild(child);
61: }
62: }
63:
64: public String getName() {
65: return file.toString();
66: }
67:
68: public ComponentHandler getHandler(ComponentManager manager,
69: Context context, RoleManager roles,
70: LogkitLoggerManager logKitManager) throws Exception {
71:
72: return ComponentHandler.getComponentHandler(clazz, config,
73: manager, context, roles, logKitManager, null, "N/A");
74: }
75:
76: public CompiledComponent newInstance() throws Exception {
77: CompiledComponent instance = (CompiledComponent) clazz
78: .newInstance();
79: if (instance instanceof Configurable)
80: ((Configurable) instance).configure(config);
81: return instance;
82: }
83: }
|