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