001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/units/resources/SymbolResources.java $
002 /*
003 * Map and oceanographical data visualisation
004 * Copyright (C) 1999 P�ches et Oc�ans Canada
005 * 2000 Institut de Recherche pour le D�veloppement
006 *
007 *
008 * This library is free software; you can redistribute it and/or
009 * modify it under the terms of the GNU Library General Public
010 * License as published by the Free Software Foundation; either
011 * version 2 of the License, or (at your option) any later version.
012 *
013 * This library is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016 * Library General Public License for more details (http://www.gnu.org/).
017 *
018 *
019 * Contacts:
020 * FRANCE: Surveillance de l'Environnement Assist�e par Satellite
021 * Institut de Recherche pour le D�veloppement / US-Espace
022 * mailto:seasnet@teledetection.fr
023 *
024 * CANADA: Observatoire du Saint-Laurent
025 * Institut Maurice-Lamontagne
026 * mailto:osl@osl.gc.ca
027 */
028 package org.deegree.model.csct.units.resources;
029
030 // Utilitaires
031 import java.util.Enumeration;
032 import java.util.NoSuchElementException;
033
034 /**
035 * Liste de ressources s'adaptant � la langue de l'utilisateur. Cette classe s'apparente � la classe
036 * {@link java.util.ListResourceBundle} standard du Java, except� qu'elle est l�g�rement plus
037 * �conome en m�moire.
038 *
039 * @version 1.0
040 * @author Martin Desruisseaux
041 */
042 public class SymbolResources extends java.util.ResourceBundle {
043 /**
044 * Table des ressources adapt�es � la langue de l'utilisateur.
045 */
046 final Object[] map;
047
048 /**
049 * Construit la table des ressources.
050 *
051 * @param contents
052 * Liste des cl�s et des valeurs qui y sont associ�es. Cette liste consiste en un
053 * tableau d'objets. Les objets se trouvant aux index pairs (0, 2, 4...) sont les
054 * cl�s, et les objets se trouvant aux index impairs sont les valeurs (voyez la
055 * description de cette classe pour des exemples).
056 *
057 * @throws IllegalArgumentException
058 * Si une cl� a �t� r�p�t�e deux fois.
059 */
060 protected SymbolResources( final Object[] contents ) throws IllegalArgumentException {
061 map = contents;
062 for ( int i = 0; i < contents.length; i += 2 ) {
063 final String key = contents[i].toString();
064 for ( int j = i; ( j += 2 ) < contents.length; ) {
065 if ( key.equals( contents[j] ) )
066 throw new IllegalArgumentException( "Duplicated key: " + key );
067 }
068 }
069 }
070
071 /**
072 * Renvoie un �num�rateur qui balayera toutes les cl�s que poss�de cette liste de ressources.
073 */
074 public final Enumeration<String> getKeys() {
075 return new Enumeration<String>() {
076 private int i = 0;
077
078 public boolean hasMoreElements() {
079 return i < map.length;
080 }
081
082 public String nextElement() {
083 if ( i < map.length ) {
084 final int i = this.i;
085 this.i += 2;
086 return (String) map[i];
087 }
088 throw new NoSuchElementException();
089 }
090 };
091 }
092
093 /**
094 * Renvoie la ressource associ�e � une cl� donn�e. Cette m�thode est d�finie pour r�pondre aux
095 * exigences de la classe {@link java.util.ResourceBundle} et n'a g�n�ralement pas besoin d'�tre
096 * appell�e directement.
097 *
098 * @param key
099 * Cl� d�signant la ressouce d�sir�e (ne doit pas �tre <code>null</code>).
100 * @return La ressource demand�e, ou <code>null</code> si aucune ressource n'est d�finie pour
101 * cette cl�.
102 */
103 protected final Object handleGetObject( final String key ) {
104 for ( int i = 0; i < map.length; i += 2 )
105 if ( key.equals( map[i] ) )
106 return map[i + 1];
107 return null;
108 }
109 }