KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > adl > legacy > LegacyImplementationCompiler


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
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: dream@objectweb.org
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.adl.legacy;
26
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.objectweb.deployment.scheduling.component.lib.AbstractInstanceProviderTask;
31 import org.objectweb.fractal.adl.ADLException;
32 import org.objectweb.fractal.adl.Node;
33 import org.objectweb.fractal.adl.TaskMap;
34 import org.objectweb.fractal.adl.components.ComponentContainer;
35 import org.objectweb.fractal.adl.components.PrimitiveCompiler;
36 import org.objectweb.fractal.api.control.BindingController;
37
38 /**
39  * Compiler that register a
40  * {@link org.objectweb.deployment.scheduling.component.api.InstanceProviderTask }
41  * for legacy component instances.
42  */

43 public class LegacyImplementationCompiler
44     implements
45       BindingController,
46       PrimitiveCompiler
47 {
48
49   /**
50    * Name of the mandatory interface bound to the {@link LegacyComponentBuilder}
51    * used by this compiler.
52    */

53   public static final String JavaDoc BUILDER_BINDING = "builder";
54
55   protected LegacyComponentBuilder builder;
56
57   /**
58    * @see PrimitiveCompiler#compile(List, ComponentContainer, TaskMap, Map)
59    */

60   public void compile(List JavaDoc path, ComponentContainer container, TaskMap tasks,
61       Map JavaDoc context) throws ADLException
62   {
63     Object JavaDoc legacyInstance = ((Node) container).astGetDecoration("legacy");
64     if (legacyInstance != null)
65     {
66       tasks.addTask("create", container, new LegacyInstanceProviderTask(
67           legacyInstance, builder));
68     }
69   }
70
71   // --------------------------------------------------------------------------
72
// Implementation of the BindingController interface
73
// --------------------------------------------------------------------------
74

75   /**
76    * @see BindingController#listFc()
77    */

78   public String JavaDoc[] listFc()
79   {
80     return new String JavaDoc[]{BUILDER_BINDING};
81   }
82
83   /**
84    * @see BindingController#lookupFc(String)
85    */

86   public Object JavaDoc lookupFc(final String JavaDoc itf)
87   {
88     if (itf.equals(BUILDER_BINDING))
89     {
90       return builder;
91     }
92     return null;
93   }
94
95   /**
96    * @see BindingController#bindFc(String, Object)
97    */

98   public void bindFc(final String JavaDoc itf, final Object JavaDoc value)
99   {
100     if (itf.equals(BUILDER_BINDING))
101     {
102       builder = (LegacyComponentBuilder) value;
103     }
104   }
105
106   /**
107    * @see BindingController#unbindFc(String)
108    */

109   public void unbindFc(final String JavaDoc itf)
110   {
111     if (itf.equals(BUILDER_BINDING))
112     {
113       builder = null;
114     }
115   }
116
117   static class LegacyInstanceProviderTask extends AbstractInstanceProviderTask
118   {
119
120     private LegacyComponentBuilder builder;
121
122     /**
123      * Creates a instance provider task for the given legacy component.
124      *
125      * @param legacyComponent the legacy component, this task is instance
126      * provider.
127      */

128     public LegacyInstanceProviderTask(Object JavaDoc legacyComponent,
129         LegacyComponentBuilder builder)
130     {
131       setInstance(legacyComponent);
132       this.builder = builder;
133     }
134
135     /**
136      * @see org.objectweb.deployment.scheduling.core.api.Task#execute(Object)
137      */

138     public void execute(Object JavaDoc ctx) throws Exception JavaDoc
139     {
140       // stop the legacy component.
141
builder.stopComponent(getInstance(), ctx);
142     }
143   }
144 }
Popular Tags