KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > adl > types > FractalTypeBuilder


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.types;
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.type.InterfaceType;
31 import org.objectweb.fractal.util.Fractal;
32
33 /**
34  * A Fractal based implementation of the {@link TypeBuilder} interface.
35  * This implementation uses the Fractal API to create types.
36  */

37
38 public class FractalTypeBuilder implements TypeBuilder {
39   
40   // --------------------------------------------------------------------------
41
// Implementation of the TypeBuilder interface
42
// --------------------------------------------------------------------------
43

44   public Object JavaDoc createInterfaceType (
45     final String JavaDoc name,
46     final String JavaDoc signature,
47     final String JavaDoc role,
48     final String JavaDoc contingency,
49     final String JavaDoc cardinality,
50     final Object JavaDoc context) throws Exception JavaDoc
51   {
52     ClassLoader JavaDoc loader = null;
53     if (context instanceof Map JavaDoc) {
54       loader = (ClassLoader JavaDoc)((Map JavaDoc)context).get("classloader");
55     }
56     if (loader == null) {
57       loader = getClass().getClassLoader();
58     }
59
60     // TODO : cache already created types ?
61
Component bootstrap = null;
62     if (context != null) {
63       bootstrap = (Component)((Map JavaDoc)context).get("bootstrap");
64     }
65     if (bootstrap == null) {
66       Map JavaDoc ctxt = new HashMap JavaDoc();
67       ctxt.put("classloader", loader);
68       bootstrap = Fractal.getBootstrapComponent(ctxt);
69     }
70     boolean client = "client".equals(role);
71     boolean optional = "optional".equals(contingency);
72     boolean collection = "collection".equals(cardinality);
73     
74     return Fractal.getTypeFactory(bootstrap).createFcItfType(
75       name, signature, client, optional, collection);
76   }
77
78   public Object JavaDoc createComponentType (
79     final String JavaDoc name,
80     final Object JavaDoc[] interfaceTypes,
81     final Object JavaDoc context) throws Exception JavaDoc
82   {
83     ClassLoader JavaDoc loader = null;
84     if (context instanceof Map JavaDoc) {
85       loader = (ClassLoader JavaDoc)((Map JavaDoc)context).get("classloader");
86     }
87     if (loader == null) {
88       loader = getClass().getClassLoader();
89     }
90
91     Component bootstrap = null;
92     if (context != null) {
93       bootstrap = (Component)((Map JavaDoc)context).get("bootstrap");
94     }
95     if (bootstrap == null) {
96       Map JavaDoc ctxt = new HashMap JavaDoc();
97       ctxt.put("classloader", loader);
98       bootstrap = Fractal.getBootstrapComponent(ctxt);
99     }
100     InterfaceType[] types = new InterfaceType[interfaceTypes.length];
101     for (int i = 0; i < types.length; ++i) {
102       types[i] = (InterfaceType)interfaceTypes[i];
103     }
104     return Fractal.getTypeFactory(bootstrap).createFcType(types);
105   }
106 }
107
Popular Tags