KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > adl > components > ComponentCompiler


1 /***
2  * Fractal ADL Parser
3  * Copyright (C) 2002-2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package org.objectweb.fractal.adl.components;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.TreeMap JavaDoc;
31
32 import org.objectweb.fractal.adl.ADLException;
33 import org.objectweb.fractal.adl.Compiler;
34 import org.objectweb.fractal.adl.Definition;
35 import org.objectweb.fractal.adl.TaskMap;
36 import org.objectweb.fractal.api.control.BindingController;
37
38 /**
39  * Basic implementation of the {@link Compiler} interface. This implementation
40  * delegates definition compilation requests to a set of
41  * {@link PrimitiveCompiler}s.
42  */

43
44 public class ComponentCompiler implements BindingController, Compiler JavaDoc {
45
46   /**
47    * Name of the collection interface bound to the {@link PrimitiveCompiler}s
48    * used by this compiler.
49    */

50   
51   public final static String JavaDoc PRIMITIVE_COMPILERS_BINDING = "primitive-compilers";
52   
53   /**
54    * The primitive compilers used by this compiler.
55    */

56   
57   public Map JavaDoc primitiveCompilers = new TreeMap JavaDoc();
58   
59   // --------------------------------------------------------------------------
60
// Implementation of the BindingController interface
61
// --------------------------------------------------------------------------
62

63   public String JavaDoc[] listFc() {
64     return (String JavaDoc[])primitiveCompilers.keySet().toArray(new String JavaDoc[primitiveCompilers.size()]);
65   }
66
67   public Object JavaDoc lookupFc (final String JavaDoc itf) {
68     if (itf.startsWith(PRIMITIVE_COMPILERS_BINDING)) {
69       return primitiveCompilers.get(itf);
70     }
71     return null;
72   }
73
74   public void bindFc (final String JavaDoc itf, final Object JavaDoc value) {
75     if (itf.startsWith(PRIMITIVE_COMPILERS_BINDING)) {
76       primitiveCompilers.put(itf, value);
77     }
78   }
79
80   public void unbindFc (final String JavaDoc itf) {
81     if (itf.startsWith(PRIMITIVE_COMPILERS_BINDING)) {
82       primitiveCompilers.remove(itf);
83     }
84   }
85   
86   // --------------------------------------------------------------------------
87
// Implementation of the Compiler interface
88
// --------------------------------------------------------------------------
89

90   public void compile (
91     final Definition definition,
92     final TaskMap tasks,
93     final Map JavaDoc context) throws ADLException
94   {
95     if (definition instanceof ComponentContainer) {
96       compile(new ArrayList JavaDoc(), (ComponentContainer)definition, tasks, context);
97     }
98   }
99   
100   // --------------------------------------------------------------------------
101
// Compilation methods
102
// --------------------------------------------------------------------------
103

104   void compile (
105     final List JavaDoc path,
106     final ComponentContainer container,
107     final TaskMap tasks,
108     final Map JavaDoc context) throws ADLException
109  {
110     path.add(container);
111     Component[] comps = container.getComponents();
112     for (int i = 0; i < comps.length; i++) {
113       compile(path, comps[i], tasks, context);
114     }
115     path.remove(path.size() - 1);
116     
117     Iterator JavaDoc it = primitiveCompilers.values().iterator();
118     while (it.hasNext()) {
119       ((PrimitiveCompiler)it.next()).compile(path, container, tasks, context);
120     }
121   }
122 }
123
Popular Tags