1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22package com.sun.org.apache.xerces.internal.impl.xs;
23
24import com.sun.org.apache.xerces.internal.dom.CoreDOMImplementationImpl;
25import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter;
26import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl;
27import com.sun.org.apache.xerces.internal.xs.StringList;
28import com.sun.org.apache.xerces.internal.xs.XSException;
29import com.sun.org.apache.xerces.internal.xs.XSImplementation;
30import com.sun.org.apache.xerces.internal.xs.XSLoader;
31import org.w3c.dom.DOMImplementation;
32
33
34/**
35 * Implements XSImplementation interface that allows one to retrieve an instance of <code>XSLoader</code>.
36 * This interface should be implemented on the same object that implements
37 * DOMImplementation.
38 *
39 * @xerces.internal
40 *
41 * @author Elena Litani, IBM
42 */
43public class XSImplementationImpl extends CoreDOMImplementationImpl
44                                                                  implements XSImplementation {
45
46    //
47    // Data
48    //
49
50    // static
51
52    /** Dom implementation singleton. */
53    static XSImplementationImpl singleton = new XSImplementationImpl();
54
55    //
56    // Public methods
57    //
58
59    /** NON-DOM: Obtain and return the single shared object */
60    public static DOMImplementation getDOMImplementation() {
61        return singleton;
62    }
63
64    //
65    // DOMImplementation methods
66    //
67
68    /**
69     * Test if the DOM implementation supports a specific "feature" --
70     * currently meaning language and level thereof.
71     *
72     * @param feature      The package name of the feature to test.
73     * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
74     * At this writing, com.sun.org.apache.xerces.internal.dom supports only XML.
75     *
76     * @param version      The version number of the feature being tested.
77     * This is interpreted as "Version of the DOM API supported for the
78     * specified Feature", and in Level 1 should be "1.0"
79     *
80     * @return    true iff this implementation is compatable with the specified
81     * feature and version.
82     */
83    public boolean hasFeature(String feature, String version) {
84
85        return (feature.equalsIgnoreCase("XS-Loader") && (version == null || version.equals("1.0")) ||
86                super.hasFeature(feature, version));
87    } // hasFeature(String,String):boolean
88
89
90
91    /* (non-Javadoc)
92     * @see com.sun.org.apache.xerces.internal.xs.XSImplementation#createXSLoader(com.sun.org.apache.xerces.internal.xs.StringList)
93     */
94    public XSLoader createXSLoader(StringList versions) throws XSException {
95        XSLoader loader = new XSLoaderImpl();
96        if (versions == null){
97                        return loader;
98        }
99        for (int i=0; i<versions.getLength();i++){
100                if (!versions.item(i).equals("1.0")){
101                                String msg =
102                                        DOMMessageFormatter.formatMessage(
103                                                DOMMessageFormatter.DOM_DOMAIN,
104                                                "FEATURE_NOT_SUPPORTED",
105                                                new Object[] { versions.item(i) });
106                                throw new XSException(XSException.NOT_SUPPORTED_ERR, msg);
107                }
108        }
109        return loader;
110    }
111
112    /* (non-Javadoc)
113     * @see com.sun.org.apache.xerces.internal.xs.XSImplementation#getRecognizedVersions()
114     */
115    public StringList getRecognizedVersions() {
116        StringListImpl list = new StringListImpl(new String[]{"1.0"}, 1);
117        return list;
118    }
119
120} // class XSImplementationImpl
121