Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / xml / dom / ImplementationSource.java
blob913079cd0c39ad846e5a273e999a1819a5f2ecb4
1 /* ImplementationSource.java --
2 Copyright (C) 2004 Free Software Foundation, Inc..
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
37 package gnu.xml.dom;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.Iterator;
42 import java.util.List;
44 import org.w3c.dom.DOMImplementation;
45 import org.w3c.dom.DOMImplementationList;
46 import org.w3c.dom.DOMImplementationSource;
48 /**
49 * Implementation source for GNU JAXP.
51 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
53 public class ImplementationSource
54 implements DOMImplementationSource
57 private static final String DIGITS = "1234567890";
60 * GNU DOM implementations.
62 private static final DOMImplementation[] implementations;
64 static
66 List acc = new ArrayList();
67 acc.add(new gnu.xml.dom.DomImpl());
68 try
70 Class t = Class.forName("gnu.xml.libxmlj.dom.GnomeDocumentBuilder");
71 acc.add(t.newInstance());
73 catch (Exception e)
75 // libxmlj not available
77 catch (UnsatisfiedLinkError e)
79 // libxmlj not available
81 implementations = new DOMImplementation[acc.size()];
82 acc.toArray(implementations);
85 public DOMImplementation getDOMImplementation(String features)
87 List available = getImplementations(features);
88 if (available.isEmpty())
90 return null;
92 return (DOMImplementation) available.get(0);
95 public DOMImplementationList getDOMImplementationList(String features)
97 List available = getImplementations(features);
98 return new ImplementationList(available);
102 * Returns a list of the implementations that support the specified
103 * features.
105 private final List getImplementations(String features)
107 List available = new ArrayList(Arrays.asList(implementations));
108 for (Iterator i = parseFeatures(features).iterator(); i.hasNext(); )
110 String feature = (String) i.next();
111 String version = null;
112 int si = feature.indexOf(' ');
113 if (si != -1)
115 version = feature.substring(si + 1);
116 feature = feature.substring(0, si);
118 for (Iterator j = available.iterator(); j.hasNext(); )
120 DOMImplementation impl = (DOMImplementation) j.next();
121 if (!impl.hasFeature(feature, version))
123 j.remove();
127 return available;
131 * Parses the feature list into feature tokens.
133 final List parseFeatures(String features)
135 List list = new ArrayList();
136 int pos = 0, start = 0;
137 int len = features.length();
138 for (; pos < len; pos++)
140 char c = features.charAt(pos);
141 if (c == ' ')
143 if (pos + 1 < len &&
144 DIGITS.indexOf(features.charAt(pos + 1)) == -1)
146 list.add(getFeature(features, start, pos));
147 start = pos + 1;
151 if (pos > start)
153 list.add(getFeature(features, start, len));
155 return list;
158 final String getFeature(String features, int start, int end)
160 if (features.length() > 0 && features.charAt(start) == '+')
162 return features.substring(start + 1, end);
164 return features.substring(start, end);