001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: /*
022: * SkeletonList.java
023: *
024: * Created on 7 août 2003, 20:09
025: */
026:
027: package net.charabia.jsmoothgen.skeleton;
028:
029: import java.io.*;
030: import java.util.*;
031:
032: public class SkeletonList {
033: Hashtable m_skelsToDirs = new Hashtable();
034: Hashtable m_nameToSkel = new Hashtable();
035: Hashtable m_nameToDebugSkel = new Hashtable();
036: Hashtable m_nameToNoDebugSkel = new Hashtable();
037:
038: public class SkelSuffixFilter implements FileFilter {
039: public boolean accept(File pathname) {
040: if (pathname.toString().toLowerCase().endsWith(".skel"))
041: return true;
042: return false;
043: }
044: }
045:
046: /** Creates a new instance of SkeletonList */
047: public SkeletonList(File directoryToScan) {
048: File[] subdirs = directoryToScan.listFiles();
049: SkelSuffixFilter filter = new SkelSuffixFilter();
050:
051: for (int i = 0; i < subdirs.length; i++) {
052: if (subdirs[i].isDirectory()) {
053: File[] skeldescs = subdirs[i]
054: .listFiles((java.io.FileFilter) filter);
055: for (int si = 0; si < skeldescs.length; si++) {
056: addSkeletonDirectory(subdirs[i], skeldescs[si]);
057: }
058: }
059: }
060: }
061:
062: public void addSkeletonDirectory(File dir, File desc) {
063: try {
064: SkeletonBean skel = SkeletonPersistency.loadWithJox(desc);
065: if ((skel != null) && (skel.getShortName() != null)) {
066: m_skelsToDirs.put(skel, dir);
067: if (skel.isDebug() == false)
068: m_nameToNoDebugSkel.put(skel.getShortName(), skel);
069: else
070: m_nameToDebugSkel.put(skel.getShortName(), skel);
071: m_nameToSkel.put(skel.getShortName(), skel);
072: }
073: } catch (Exception exc) {
074: // System.err.println("Error adding skeleton " + dir + " / " + desc);
075: // iox.printStackTrace();
076: }
077: }
078:
079: public String toString() {
080: return m_skelsToDirs.toString();
081: }
082:
083: public Iterator getIteratorSkel() {
084: // return m_skelsToDirs.keySet().iterator();
085: return m_nameToSkel.values().iterator();
086: }
087:
088: public Iterator getIteratorDebugSkel() {
089: return m_nameToDebugSkel.values().iterator();
090: }
091:
092: public File getDirectory(SkeletonBean skel) {
093: return (File) m_skelsToDirs.get(skel);
094: }
095:
096: public Iterator getIteratorName() {
097: return m_nameToSkel.keySet().iterator();
098: }
099:
100: public Iterator getIteratorDebugName() {
101: return m_nameToDebugSkel.keySet().iterator();
102: }
103:
104: public Iterator getIteratorNoDebugName() {
105: return m_nameToNoDebugSkel.keySet().iterator();
106: }
107:
108: public SkeletonBean getSkeleton(String name) {
109: try {
110: return new SkeletonBean((SkeletonBean) m_nameToSkel
111: .get(name));
112: } catch (Exception exc) {
113: return null;
114: }
115: }
116: }
|