KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > message > codec > CodecRepositoryImpl


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.message.codec;
26
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.util.Properties JavaDoc;
30
31 import org.objectweb.dream.AbstractComponent;
32 import org.objectweb.dream.util.EmptyStringArray;
33 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
34
35 /**
36  * Codec repository implementation using a {@link Properties }to map codec name
37  * with codec ADL. The content of the <code>Properties</code> object is
38  * initialized by reading a properties file (see
39  * {@link Properties#load(InputStream)}). The name of this file is given by the
40  * attribute <code>PropertiesRessourceName</code> (see
41  * {@link CodecRepositoryAttributeController}). This attribute must be set
42  * before the component is started.
43  */

44 public class CodecRepositoryImpl extends AbstractComponent
45     implements
46       CodecRepository,
47       CodecRepositoryAttributeController
48 {
49
50   protected String JavaDoc repositoryRessourceName;
51   protected Properties JavaDoc repository;
52
53   /**
54    * @see CodecRepository#getCodecADL(String)
55    */

56   public String JavaDoc getCodecADL(String JavaDoc codecName)
57   {
58     return repository.getProperty(codecName);
59   }
60
61   // ---------------------------------------------------------------------------
62
// Implementation of CodecRepositoryAttributeController interface
63
// ---------------------------------------------------------------------------
64

65   /**
66    * @see CodecRepositoryAttributeController#getPropertiesRessourceName()
67    */

68   public String JavaDoc getPropertiesRessourceName()
69   {
70     return repositoryRessourceName;
71   }
72
73   /**
74    * @see CodecRepositoryAttributeController#setPropertiesRessourceName(String)
75    */

76   public void setPropertiesRessourceName(String JavaDoc name)
77       throws CodecManagerException
78   {
79     InputStream JavaDoc is = ClassLoader.getSystemResourceAsStream(name);
80     if (is == null)
81     {
82       throw new CodecManagerException(null, "Can't find properties file :"
83           + name);
84     }
85     repository = new Properties JavaDoc();
86     try
87     {
88       repository.load(is);
89     }
90     catch (IOException JavaDoc e)
91     {
92       throw new CodecManagerException(null,
93           "Error while reading properties file : " + e.getLocalizedMessage());
94     }
95     repositoryRessourceName = name;
96   }
97
98   // ---------------------------------------------------------------------------
99
// Implementation of BindingController interface
100
// ---------------------------------------------------------------------------
101

102   /**
103    * @see org.objectweb.fractal.api.control.BindingController#listFc()
104    */

105   public String JavaDoc[] listFc()
106   {
107     return EmptyStringArray.EMPTY_STRING_ARRAY;
108   }
109
110   // ---------------------------------------------------------------------------
111
// Implementation of LifeCycleControlle interface
112
// ---------------------------------------------------------------------------
113

114   /**
115    * @see org.objectweb.fractal.api.control.LifeCycleController#startFc()
116    */

117   public void startFc() throws IllegalLifeCycleException
118   {
119     super.startFc();
120     if (repository == null)
121     {
122       throw new IllegalLifeCycleException(
123           "Properties Ressource Name attribute not set");
124     }
125   }
126 }
Popular Tags