KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > adl > nodes > VirtualNodeImplementationCompiler


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.nodes;
25
26 import java.util.HashMap JavaDoc;
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.components.ComponentContainer;
32 import org.objectweb.fractal.adl.implementations.ImplementationBuilder;
33 import org.objectweb.fractal.adl.implementations.ImplementationCompiler;
34
35 public class VirtualNodeImplementationCompiler extends ImplementationCompiler {
36   
37   public AbstractInstanceProviderTask newCreateTask (
38     final List JavaDoc path,
39     final ComponentContainer container,
40     final String JavaDoc name,
41     final String JavaDoc definition,
42     final Object JavaDoc controller,
43     final Object JavaDoc implementation,
44     final Map JavaDoc context)
45   {
46     VirtualNode n = null;
47     if (container instanceof VirtualNodeContainer) {
48       n = ((VirtualNodeContainer)container).getVirtualNode();
49     }
50     if (n == null) {
51       for (int i = path.size() - 1; i >= 0; --i) {
52         if (path.get(i) instanceof VirtualNodeContainer) {
53           n = ((VirtualNodeContainer)path.get(i)).getVirtualNode();
54           if (n != null) {
55             break;
56           }
57         }
58       }
59     }
60     if (n != null) {
61       return new RemoteCreateTask(
62         builder, name, definition, controller, implementation, context.get(n.getName()));
63     }
64     return super.newCreateTask(
65       path, container, name, definition, controller, implementation, context);
66   }
67
68   static class RemoteCreateTask extends AbstractInstanceProviderTask {
69
70     ImplementationBuilder builder;
71     
72     String JavaDoc name;
73     
74     String JavaDoc definition;
75     
76     Object JavaDoc controllerDesc;
77     
78     Object JavaDoc contentDesc;
79     
80     Object JavaDoc node;
81     
82     public RemoteCreateTask (
83       final ImplementationBuilder builder,
84       final String JavaDoc name,
85       final String JavaDoc definition,
86       final Object JavaDoc controllerDesc,
87       final Object JavaDoc contentDesc,
88       final Object JavaDoc node)
89     {
90       this.builder = builder;
91       this.name = name;
92       this.definition = definition;
93       this.controllerDesc = controllerDesc;
94       this.contentDesc = contentDesc;
95       this.node = node;
96     }
97     
98     public void execute (Object JavaDoc context) throws Exception JavaDoc {
99       if (getInstance() != null) {
100         return;
101       }
102       if (node != null && context instanceof Map JavaDoc) {
103         context = new HashMap JavaDoc((Map JavaDoc)context);
104         ((Map JavaDoc)context).put("bootstrap", node);
105       }
106       Object JavaDoc type = getFactoryProviderTask().getFactory();
107       Object JavaDoc result = builder.createComponent(
108         type, name, definition, controllerDesc, contentDesc, context);
109       setInstance(result);
110     }
111     
112     public String JavaDoc toString () {
113       return "T" + System.identityHashCode(this) +
114         "[CreateTask(" + name + "," + controllerDesc + "," + contentDesc + ")]";
115     }
116   }
117 }
118
Popular Tags