KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > xml > fastinfoset > stax > StAXManager


1 /*
2  * Fast Infoset ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Software is licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License. You may
8  * obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations.
16  *
17  * Sun supports and benefits from the global community of open source
18  * developers, and thanks the community for its important contributions and
19  * open standards-based technology, which Sun has adopted into many of its
20  * products.
21  *
22  * Please note that portions of Software may be provided with notices and
23  * open source licenses from such communities and third parties that govern the
24  * use of those portions, and any licenses granted hereunder do not alter any
25  * rights and obligations you may have under such open source licenses,
26  * however, the disclaimer of warranty and limitation of liability provisions
27  * in this License will apply to all Software in this distribution.
28  *
29  * You acknowledge that the Software is not designed, licensed or intended
30  * for use in the design, construction, operation or maintenance of any nuclear
31  * facility.
32  *
33  * Apache License
34  * Version 2.0, January 2004
35  * http://www.apache.org/licenses/
36  *
37  */

38
39 package com.sun.xml.fastinfoset.stax;
40
41 import java.util.HashMap JavaDoc;
42 import javax.xml.stream.XMLInputFactory;
43 import javax.xml.stream.XMLOutputFactory;
44 import javax.xml.stream.XMLResolver;
45 import com.sun.xml.fastinfoset.CommonResourceBundle;
46
47 public class StAXManager {
48     protected static final String JavaDoc STAX_NOTATIONS = "javax.xml.stream.notations";
49     protected static final String JavaDoc STAX_ENTITIES = "javax.xml.stream.entities";
50     
51     HashMap JavaDoc features = new HashMap JavaDoc();
52     
53     public static final int CONTEXT_READER = 1;
54     public static final int CONTEXT_WRITER = 2;
55     
56     
57     /** Creates a new instance of StAXManager */
58     public StAXManager() {
59     }
60     
61     public StAXManager(int context) {
62         switch(context){
63             case CONTEXT_READER:{
64                 initConfigurableReaderProperties();
65                 break;
66             }
67             case CONTEXT_WRITER:{
68                 initWriterProps();
69                 break;
70             }
71         }
72     }
73     
74     public StAXManager(StAXManager manager){
75         
76         HashMap JavaDoc properties = manager.getProperties();
77         features.putAll(properties);
78     }
79     
80     private HashMap JavaDoc getProperties(){
81         return features ;
82     }
83     
84     private void initConfigurableReaderProperties(){
85         //spec v1.0 default values
86
features.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
87         features.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
88         features.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
89         features.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
90         features.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
91         features.put(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
92         features.put(XMLInputFactory.REPORTER, null);
93         features.put(XMLInputFactory.RESOLVER, null);
94         features.put(XMLInputFactory.ALLOCATOR, null);
95         features.put(STAX_NOTATIONS,null );
96     }
97     
98     private void initWriterProps(){
99         features.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE);
100     }
101     
102     /**
103      * public void reset(){
104      * features.clear() ;
105      * }
106      */

107     public boolean containsProperty(String JavaDoc property){
108         return features.containsKey(property) ;
109     }
110     
111     public Object JavaDoc getProperty(String JavaDoc name){
112         checkProperty(name);
113         return features.get(name);
114     }
115     
116     public void setProperty(String JavaDoc name, Object JavaDoc value){
117         checkProperty(name);
118         if (name.equals(XMLInputFactory.IS_VALIDATING) &&
119                 Boolean.TRUE.equals(value)){
120             throw new IllegalArgumentException JavaDoc(CommonResourceBundle.getInstance().getString("message.validationNotSupported") +
121                     CommonResourceBundle.getInstance().getString("support_validation"));
122         } else if (name.equals(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES) &&
123                 Boolean.TRUE.equals(value)) {
124             throw new IllegalArgumentException JavaDoc(CommonResourceBundle.getInstance().getString("message.externalEntities") +
125                     CommonResourceBundle.getInstance().getString("resolve_external_entities_"));
126         }
127         features.put(name,value);
128
129     }
130     
131     public void checkProperty(String JavaDoc name) {
132         if (!features.containsKey(name))
133             throw new IllegalArgumentException JavaDoc(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object JavaDoc[]{name}));
134     }
135
136     public String JavaDoc toString(){
137         return features.toString();
138     }
139         
140 }
141
Popular Tags