001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.dom;
019:
020: import org.apache.xerces.impl.xs.XSImplementationImpl;
021: import org.w3c.dom.DOMImplementationList;
022: import org.w3c.dom.DOMImplementation;
023: import java.util.Vector;
024:
025: /**
026: * Allows to retrieve <code>XSImplementation</code>, DOM Level 3 Core and LS implementations
027: * and PSVI implementation.
028: * <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#DOMImplementationSource'>Document Object Model (DOM) Level 3 Core Specification</a>.
029: *
030: * @xerces.internal
031: *
032: * @author Elena Litani, IBM
033: * @version $Id: DOMXSImplementationSourceImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
034: */
035: public class DOMXSImplementationSourceImpl extends
036: DOMImplementationSourceImpl {
037:
038: /**
039: * A method to request a DOM implementation.
040: * @param features A string that specifies which features are required.
041: * This is a space separated list in which each feature is specified
042: * by its name optionally followed by a space and a version number.
043: * This is something like: "XML 1.0 Traversal Events 2.0"
044: * @return An implementation that has the desired features, or
045: * <code>null</code> if this source has none.
046: */
047: public DOMImplementation getDOMImplementation(String features) {
048: DOMImplementation impl = super .getDOMImplementation(features);
049: if (impl != null) {
050: return impl;
051: }
052: // if not try the PSVIDOMImplementation
053: impl = PSVIDOMImplementationImpl.getDOMImplementation();
054: if (testImpl(impl, features)) {
055: return impl;
056: }
057: // if not try the XSImplementation
058: impl = XSImplementationImpl.getDOMImplementation();
059: if (testImpl(impl, features)) {
060: return impl;
061: }
062:
063: return null;
064: }
065:
066: /**
067: * A method to request a list of DOM implementations that support the
068: * specified features and versions, as specified in .
069: * @param features A string that specifies which features and versions
070: * are required. This is a space separated list in which each feature
071: * is specified by its name optionally followed by a space and a
072: * version number. This is something like: "XML 3.0 Traversal +Events
073: * 2.0"
074: * @return A list of DOM implementations that support the desired
075: * features.
076: */
077: public DOMImplementationList getDOMImplementationList(
078: String features) {
079: final Vector implementations = new Vector();
080:
081: // first check whether the CoreDOMImplementation would do
082: DOMImplementationList list = super
083: .getDOMImplementationList(features);
084: //Add core DOMImplementations
085: for (int i = 0; i < list.getLength(); i++) {
086: implementations.addElement(list.item(i));
087: }
088:
089: DOMImplementation impl = PSVIDOMImplementationImpl
090: .getDOMImplementation();
091: if (testImpl(impl, features)) {
092: implementations.addElement(impl);
093: }
094:
095: impl = XSImplementationImpl.getDOMImplementation();
096: if (testImpl(impl, features)) {
097: implementations.addElement(impl);
098: }
099: return new DOMImplementationListImpl(implementations);
100: }
101: }
|