KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > adl > implementations > FractalImplementationBuilder


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.implementations;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.fractal.api.Component;
30 import org.objectweb.fractal.api.NoSuchInterfaceException;
31 import org.objectweb.fractal.api.type.ComponentType;
32 import org.objectweb.fractal.util.Fractal;
33
34 /**
35  * A Fractal based implementation of the {@link ImplementationBuilder}
36  * interface. This implementation uses the Fractal API to create components.
37  */

38
39 public class FractalImplementationBuilder implements ImplementationBuilder {
40   
41   // --------------------------------------------------------------------------
42
// Implementation of the ImplementationBuilder interface
43
// --------------------------------------------------------------------------
44

45   public Object JavaDoc createComponent (
46     final Object JavaDoc type,
47     final String JavaDoc name,
48     final String JavaDoc definition,
49     final Object JavaDoc controllerDesc,
50     final Object JavaDoc contentDesc,
51     final Object JavaDoc context) throws Exception JavaDoc
52   {
53     ClassLoader JavaDoc loader = null;
54     if (context instanceof Map JavaDoc) {
55       loader = (ClassLoader JavaDoc)((Map JavaDoc)context).get("classloader");
56     }
57
58     Component bootstrap = null;
59     if (context != null) {
60       bootstrap = (Component)((Map JavaDoc)context).get("bootstrap");
61     }
62     if (bootstrap == null) {
63       if (loader != null) {
64         Map JavaDoc ctxt = new HashMap JavaDoc();
65         ctxt.put("classloader", loader);
66         bootstrap = Fractal.getBootstrapComponent(ctxt);
67       } else {
68         bootstrap = Fractal.getBootstrapComponent();
69       }
70     }
71     Component result = Fractal.getGenericFactory(bootstrap).newFcInstance(
72       (ComponentType)type,
73       loader == null ? controllerDesc : new Object JavaDoc[] {loader, controllerDesc},
74       contentDesc);
75     try {
76       Fractal.getNameController(result).setFcName(name);
77     } catch (NoSuchInterfaceException ignored) {
78     }
79     return result;
80   }
81 }
82
Popular Tags