KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > repository > lib > StorageLoader


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 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: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

23
24 package org.objectweb.fractal.gui.repository.lib;
25
26 import java.util.Map JavaDoc;
27
28 import org.objectweb.fractal.adl.ADLException;
29 import org.objectweb.fractal.adl.Definition;
30 import org.objectweb.fractal.adl.Loader;
31 import org.objectweb.fractal.api.control.BindingController;
32
33 import org.objectweb.fractal.gui.repository.api.Storage;
34
35 /**
36  * Basic {@link Loader} implementation, based on a {@link Storage}.
37  */

38
39 public class StorageLoader implements Loader, BindingController {
40
41   public final static String JavaDoc STORAGE_BINDING = "storage";
42   
43   /**
44    * The storage used by this loader.
45    */

46
47   Storage storage;
48
49   // -------------------------------------------------------------------------
50
// Implementation of the BindingController interface
51
// -------------------------------------------------------------------------
52

53   public String JavaDoc[] listFc () {
54     return new String JavaDoc[] { STORAGE_BINDING };
55   }
56
57   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
58     if (STORAGE_BINDING.equals(clientItfName)) {
59       return storage;
60     }
61     return null;
62   }
63
64   public void bindFc (
65     final String JavaDoc clientItfName,
66     final Object JavaDoc serverItf)
67   {
68     if (STORAGE_BINDING.equals(clientItfName)) {
69       storage = (Storage)serverItf;
70     }
71   }
72
73   public void unbindFc (final String JavaDoc clientItfName) {
74     if (STORAGE_BINDING.equals(clientItfName)) {
75       storage = null;
76     }
77   }
78   
79   // -------------------------------------------------------------------------
80
// Implementation of the Loader interface
81
// -------------------------------------------------------------------------
82

83   public Definition load (final String JavaDoc name, final Map JavaDoc context)
84     throws ADLException
85   {
86     try {
87       return (Definition)storage.load(name);
88     } catch (Exception JavaDoc e) {
89       throw new ADLException("Cannot load '" + name + "'", null, e);
90     }
91   }
92 }
93
Popular Tags