Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: openfuture/editxml/model/DomainManager.java


1   package openfuture.editxml.model;
2   /*
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2 of the License, or (at your option) any later version.<p>
7    *
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11   * Lesser General Public License for more details.<p>
12   *
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA<br>
16   * http://www.gnu.org/copyleft/lesser.html
17   */
18  
19  import java.io.File;
20  import java.util.Enumeration;
21  import java.util.HashSet;
22  import java.util.Hashtable;
23  import java.util.Iterator;
24  import java.util.LinkedList;
25  import openfuture.util.error.I18NException;
26  
27  // Configuration Management Information: 
28  // -------------------------------------
29  // $Id: DomainManager.java,v 1.1.1.1 2001/07/08 18:29:29 wreissen Exp $
30  //
31  // Version History:
32  // ----------------
33  // $Log: DomainManager.java,v $
34  // Revision 1.1.1.1  2001/07/08 18:29:29  wreissen
35  // initial version registered ad SourceForge
36  //
37  // Revision 1.1  2001/05/09 20:07:27  wreissen
38  // initial version.
39  //
40  //
41  // ***********************************************************************************
42  /**
43   * Manages XML domains.<p>
44   *
45   *
46   * Created: Wed Apr 11 06:18:36 2001
47   *
48   * @author <a href="mailto:wolfgang@openfuture.de">Wolfgang Reissenberger</a>
49   * @version $Revision: 1.1.1.1 $
50   */
51  
52  public class DomainManager  {
53      
54      private LinkedList xmlDomains;
55      private Hashtable domainTable;
56      private Hashtable fileTable;
57      
58      /**
59       * Initialize with a {@link java.util.LinkedList list} of 
60       * {@link openfuture.editxml.model.XmlDomain XML Domains}.
61       *
62       * @param xmlDomains XML domains.
63       */
64      public DomainManager(LinkedList xmlDomains) {
65    setXmlDomains(xmlDomains);
66      }
67  
68  
69      /**
70       * Delivers the 
71       * {@link openfuture.editxml.model.XmlDomain XML Domain}
72       * where {@link openfuture.editxml.model.XmlDomain#getName() getName()}
73       * equals to <code>name</code>.
74       *
75       * @param name a value of type 'String'
76       * @return a value of type 'LinkedList'
77       */
78      public XmlDomain getXmlDomain(String name) {
79  
80    return ((XmlDomain) getDomainTable().get(name));
81      }
82  
83  
84  
85      /**
86       * Retrieve the list of files below the 
87       * {@link openfuture.editxml.model.XmlDomain#getDirectory()
88       * XML domain directory}.
89       *
90       * @param domainName name of the XML domain
91       * @return file list
92       */
93      public LinkedList getFileNames (String domainName) {
94  
95    XmlDomain domain = (XmlDomain) getDomainTable().get(domainName);
96  
97    if (domain == null) return null;
98  
99    File dir = new File(domain.getDirectory());
100 
101   String[] reasons = new String[1];
102   LinkedList names = new LinkedList();
103 
104   reasons[0] = domainName;
105 
106   if (dir.isDirectory()) {
107       // dir is a valid directory
108       File[] files = dir.listFiles(new REFilenameFilter(domain.getNameFilter()));
109       for (int i = 0; i < files.length; i++) {
110 
111     File file = files[i];
112     if (file.isFile()) names.add(files[i].getName());
113       }
114   }
115 
116   return names;
117     }
118 
119 
120     /**
121      * Retrieve the list of domain names
122      *
123      * @return list of domain namesy
124      */
125     public LinkedList getDomainNames() {
126 
127   Enumeration enum = getDomainTable().keys();
128 
129   LinkedList domainnames = new LinkedList();
130   while(enum.hasMoreElements()) {
131       domainnames.add((String) enum.nextElement());
132   }
133 
134   return domainnames;
135     }
136 
137 
138     /**
139      * Retrieve a hashtable with the list of file names for each
140      * domain. Domain names are the keys in the hashtable.
141      *
142      * @return table with file name lists
143      */
144     public Hashtable getFileTable() {
145   if (fileTable == null) { 
146       fileTable = new Hashtable();
147 
148       Iterator it = getDomainNames().iterator();
149 
150       while(it.hasNext()) {
151     String domainName = (String) it.next();
152     fileTable.put(domainName, getFileNames(domainName));
153       }
154   }
155 
156   return fileTable;
157     }
158 
159 
160 
161     /**
162      * Deliver the table of all available 
163      * {@link openfuture.editxml.model.XmlDomain XML Domain}s.
164      *
165      * @return a value of type 'Hashtable'
166      */
167     public Hashtable getDomainTable() {
168   if (domainTable == null) {
169       domainTable = new Hashtable();
170       if (getXmlDomains() != null) {
171     Iterator it = getXmlDomains().iterator();
172     
173     while(it.hasNext()) {
174         XmlDomain domain = (XmlDomain) it.next();
175         domainTable.put(domain.getName(), domain);
176     }
177       }
178   }
179   return domainTable;
180     }
181 
182 
183     /**
184      * Get the value of xmlDomains.
185      * @return value of xmlDomains.
186      */
187     public LinkedList getXmlDomains() {
188   return xmlDomains;
189     }
190     
191     /**
192      * Set the value of xmlDomains.
193      * @param v  Value to assign to xmlDomains.
194      */
195     public void setXmlDomains(LinkedList  v) {
196   this.xmlDomains = v;
197     }
198     
199     
200 } // DomainManager