KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > language > programming > python > PythonProgram


1 /*
2  * Copyright 1999-2004 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.components.language.programming.python;
17
18 import org.apache.avalon.framework.configuration.DefaultConfiguration;
19 import org.apache.avalon.framework.configuration.Configurable;
20 import org.apache.avalon.framework.component.ComponentManager;
21 import org.apache.avalon.framework.context.Context;
22
23 import org.apache.avalon.excalibur.component.ComponentHandler;
24 import org.apache.avalon.excalibur.component.RoleManager;
25 import org.apache.avalon.excalibur.component.LogkitLoggerManager;
26
27 import org.apache.cocoon.components.language.programming.Program;
28 import org.apache.cocoon.components.language.generator.CompiledComponent;
29
30 import java.io.File JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 /**
35  * This class represents program in the Python language.
36  *
37  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
38  * @version CVS $Id: PythonProgram.java 30932 2004-07-29 17:35:38Z vgritsenko $
39  */

40 public class PythonProgram implements Program {
41
42     protected File JavaDoc file;
43     protected Class JavaDoc clazz;
44     protected DefaultConfiguration config;
45
46     public PythonProgram(File JavaDoc file, Class JavaDoc clazz, Collection JavaDoc dependecies) {
47         this.file = file;
48         this.clazz = clazz;
49
50         config = new DefaultConfiguration("", "GeneratorSelector");
51         DefaultConfiguration child = new DefaultConfiguration("file", "");
52         child.setValue(file.toString());
53         config.addChild(child);
54
55         for (Iterator JavaDoc i = dependecies.iterator(); i.hasNext(); ) {
56             child = new DefaultConfiguration("dependency", "");
57             child.setValue(i.next().toString());
58             config.addChild(child);
59         }
60     }
61
62     public String JavaDoc getName() {
63         return file.toString();
64     }
65
66     public ComponentHandler getHandler(ComponentManager manager,
67                                        Context context,
68                                        RoleManager roles,
69                                        LogkitLoggerManager logKitManager)
70             throws Exception JavaDoc {
71
72         return ComponentHandler.getComponentHandler(
73                 clazz, config, manager, context, roles, logKitManager, null, "N/A");
74     }
75
76     public CompiledComponent newInstance() throws Exception JavaDoc {
77         CompiledComponent instance = (CompiledComponent) clazz.newInstance();
78         if (instance instanceof Configurable)
79             ((Configurable) instance).configure(config);
80         return instance;
81     }
82 }
83
Popular Tags