KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > language > programming > javascript > JavascriptProgram


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.javascript;
17
18 import org.apache.avalon.framework.component.ComponentManager;
19 import org.apache.avalon.framework.configuration.Configurable;
20 import org.apache.avalon.framework.configuration.DefaultConfiguration;
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.generator.CompiledComponent;
28 import org.apache.cocoon.components.language.programming.Program;
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 Javascript language.
36  *
37  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
38  * @version CVS $Id: JavascriptProgram.java 30932 2004-07-29 17:35:38Z vgritsenko $
39  */

40 public class JavascriptProgram implements Program {
41
42     protected File JavaDoc file;
43     protected Class JavaDoc clazz;
44     protected DefaultConfiguration config;
45
46     public JavascriptProgram(File JavaDoc file, Class JavaDoc clazz, Collection JavaDoc dependecies) {
47         DefaultConfiguration child;
48
49         this.file = file;
50         this.clazz = clazz;
51
52         config = new DefaultConfiguration("", "GeneratorSelector");
53         child = new DefaultConfiguration("file", "");
54         child.setValue(file.toString());
55         config.addChild(child);
56
57         for (Iterator JavaDoc 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 JavaDoc getName() {
65         return file.toString();
66     }
67
68     public ComponentHandler getHandler(ComponentManager manager,
69                                        Context context,
70                                        RoleManager roles,
71                                        LogkitLoggerManager logKitManager)
72             throws Exception JavaDoc {
73
74         return ComponentHandler.getComponentHandler(
75                 clazz, config, manager, context, roles, logKitManager, null, "N/A");
76     }
77
78     public CompiledComponent newInstance() throws Exception JavaDoc {
79         CompiledComponent instance = (CompiledComponent) clazz.newInstance();
80         if (instance instanceof Configurable)
81             ((Configurable) instance).configure(config);
82         return instance;
83     }
84 }
85
Popular Tags