KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > XSImplementationImpl


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.impl.xs;
18
19 import org.apache.xerces.dom.CoreDOMImplementationImpl;
20 import org.apache.xerces.dom.DOMMessageFormatter;
21 import org.apache.xerces.impl.xs.util.StringListImpl;
22 import org.apache.xerces.xs.StringList;
23 import org.apache.xerces.xs.XSException;
24 import org.apache.xerces.xs.XSImplementation;
25 import org.apache.xerces.xs.XSLoader;
26 import org.w3c.dom.DOMImplementation JavaDoc;
27
28
29 /**
30  * Implements XSImplementation interface that allows one to retrieve an instance of <code>XSLoader</code>.
31  * This interface should be implemented on the same object that implements
32  * DOMImplementation.
33  *
34  * @xerces.internal
35  *
36  * @author Elena Litani, IBM
37  * @version $Id: XSImplementationImpl.java,v 1.6 2004/12/08 22:49:05 mrglavas Exp $
38  */

39 public class XSImplementationImpl extends CoreDOMImplementationImpl
40                                   implements XSImplementation {
41
42     //
43
// Data
44
//
45

46     // static
47

48     /** Dom implementation singleton. */
49     static XSImplementationImpl singleton = new XSImplementationImpl();
50
51     //
52
// Public methods
53
//
54

55     /** NON-DOM: Obtain and return the single shared object */
56     public static DOMImplementation JavaDoc getDOMImplementation() {
57         return singleton;
58     }
59
60     //
61
// DOMImplementation methods
62
//
63

64     /**
65      * Test if the DOM implementation supports a specific "feature" --
66      * currently meaning language and level thereof.
67      *
68      * @param feature The package name of the feature to test.
69      * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
70      * At this writing, org.apache.xerces.dom supports only XML.
71      *
72      * @param version The version number of the feature being tested.
73      * This is interpreted as "Version of the DOM API supported for the
74      * specified Feature", and in Level 1 should be "1.0"
75      *
76      * @return true iff this implementation is compatable with the specified
77      * feature and version.
78      */

79     public boolean hasFeature(String JavaDoc feature, String JavaDoc version) {
80         
81         return (feature.equalsIgnoreCase("XS-Loader") && (version == null || version.equals("1.0")) ||
82         super.hasFeature(feature, version));
83     } // hasFeature(String,String):boolean
84

85
86
87     /* (non-Javadoc)
88      * @see org.apache.xerces.xs.XSImplementation#createXSLoader(org.apache.xerces.xs.StringList)
89      */

90     public XSLoader createXSLoader(StringList versions) throws XSException {
91         XSLoader loader = new XSLoaderImpl();
92         if (versions == null){
93             return loader;
94         }
95         for (int i=0; i<versions.getLength();i++){
96             if (!versions.item(i).equals("1.0")){
97                 String JavaDoc msg =
98                     DOMMessageFormatter.formatMessage(
99                         DOMMessageFormatter.DOM_DOMAIN,
100                         "FEATURE_NOT_SUPPORTED",
101                         new Object JavaDoc[] { versions.item(i) });
102                 throw new XSException(XSException.NOT_SUPPORTED_ERR, msg);
103             }
104         }
105         return loader;
106     }
107
108     /* (non-Javadoc)
109      * @see org.apache.xerces.xs.XSImplementation#getRecognizedVersions()
110      */

111     public StringList getRecognizedVersions() {
112         StringListImpl list = new StringListImpl(new String JavaDoc[]{"1.0"}, 1);
113         return list;
114     }
115
116 } // class XSImplementationImpl
117
Popular Tags