KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > PropertyManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://jaxp.dev.java.net/CDDLv1.0.html.
9  * See the License for the specific language governing
10  * permissions and limitations under the License.
11  *
12  * When distributing Covered Code, include this CDDL
13  * HEADER in each file and include the License file at
14  * https://jaxp.dev.java.net/CDDLv1.0.html
15  * If applicable add the following below this CDDL HEADER
16  * with the fields enclosed by brackets "[]" replaced with
17  * your own identifying information: Portions Copyright
18  * [year] [name of copyright owner]
19  */

20
21 /*
22  * $Id: PropertyManager.java,v 1.5.2.2 2007/01/23 06:25:58 joehw Exp $
23  * @(#)PropertyManager.java 1.9 07/01/24
24  *
25  * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package com.sun.org.apache.xerces.internal.impl;
29
30 import java.util.HashMap JavaDoc;
31 import javax.xml.stream.XMLInputFactory;
32 import javax.xml.stream.XMLOutputFactory;
33 import javax.xml.stream.XMLResolver;
34
35 import com.sun.xml.internal.stream.StaxEntityResolverWrapper;
36
37 /**
38  * This class manages different properties related to Stax specification and its implementation.
39  * This class constructor also takes itself (PropertyManager object) as parameter and initializes the
40  * object with the property taken from the object passed.
41  *
42  * @author Neeraj Bajaj, neeraj.bajaj@sun.com
43  * @author K.Venugopal@sun.com
44  * @author Sunitha Reddy, sunitha.reddy@sun.com
45  */

46
47 public class PropertyManager {
48     
49     
50     protected static final String JavaDoc STAX_NOTATIONS = "javax.xml.stream.notations";
51     protected static final String JavaDoc STAX_ENTITIES = "javax.xml.stream.entities";
52     
53     private static final String JavaDoc STRING_INTERNING = "http://xml.org/sax/features/string-interning";
54     
55             
56     HashMap JavaDoc supportedProps = new HashMap JavaDoc();
57     
58     public static final int CONTEXT_READER = 1;
59     public static final int CONTEXT_WRITER = 2;
60     
61     /** Creates a new instance of PropertyManager */
62     public PropertyManager(int context) {
63         switch(context){
64             case CONTEXT_READER:{
65                 initConfigurableReaderProperties();
66                 break;
67             }
68             case CONTEXT_WRITER:{
69                 initWriterProps();
70                 break;
71             }
72         }
73     }
74     
75     /**
76      * Initialize this object with the properties taken from passed PropertyManager object.
77      */

78     public PropertyManager(PropertyManager propertyManager){
79         
80         HashMap JavaDoc properties = propertyManager.getProperties();
81         supportedProps.putAll(properties);
82     }
83     
84     private HashMap JavaDoc getProperties(){
85         return supportedProps ;
86     }
87     
88     
89     /**
90      * Important point:
91      * 1. We are not exposing Xerces namespace property. Application should configure namespace through
92      * Stax specific property.
93      *
94      */

95     private void initConfigurableReaderProperties(){
96         //spec default values
97
supportedProps.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
98         supportedProps.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
99         supportedProps.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
100         supportedProps.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
101         supportedProps.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
102         supportedProps.put(XMLInputFactory.SUPPORT_DTD, Boolean.TRUE);
103         supportedProps.put(XMLInputFactory.REPORTER, null);
104         supportedProps.put(XMLInputFactory.RESOLVER, null);
105         supportedProps.put(XMLInputFactory.ALLOCATOR, null);
106         supportedProps.put(STAX_NOTATIONS,null );
107         
108         //zephyr (implementation) specific properties which can be set by the application.
109
//interning is always done
110
supportedProps.put(Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE , new Boolean JavaDoc(true));
111         //recognizing java encoding names by default
112
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE, new Boolean JavaDoc(true)) ;
113         //in stax mode, namespace declarations are not added as attributes
114
supportedProps.put(Constants.ADD_NAMESPACE_DECL_AS_ATTRIBUTE , Boolean.FALSE) ;
115         supportedProps.put(Constants.READER_IN_DEFINED_STATE, new Boolean JavaDoc(true));
116         supportedProps.put(Constants.REUSE_INSTANCE, new Boolean JavaDoc(true));
117         supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT , new Boolean JavaDoc(false));
118         supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE, new Boolean JavaDoc(false));
119         supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE, new Boolean JavaDoc(false));
120         supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE, new Boolean JavaDoc(false));
121     }
122     
123     private void initWriterProps(){
124         supportedProps.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE);
125         //default value of escaping characters is 'true'
126
supportedProps.put(Constants.ESCAPE_CHARACTERS , Boolean.TRUE);
127         supportedProps.put(Constants.REUSE_INSTANCE, new Boolean JavaDoc(true));
128     }
129     
130     /**
131      * public void reset(){
132      * supportedProps.clear() ;
133      * }
134      */

135     public boolean containsProperty(String JavaDoc property){
136         return supportedProps.containsKey(property) ;
137     }
138     
139     public Object JavaDoc getProperty(String JavaDoc property){
140         return supportedProps.get(property);
141     }
142     
143     public void setProperty(String JavaDoc property, Object JavaDoc value){
144         String JavaDoc equivalentProperty = null ;
145         if(property == XMLInputFactory.IS_NAMESPACE_AWARE || property.equals(XMLInputFactory.IS_NAMESPACE_AWARE)){
146             equivalentProperty = Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE ;
147         }
148         else if(property == XMLInputFactory.IS_VALIDATING || property.equals(XMLInputFactory.IS_VALIDATING)){
149             if( (value instanceof Boolean JavaDoc) && ((Boolean JavaDoc)value).booleanValue()){
150                 throw new java.lang.IllegalArgumentException JavaDoc("true value of isValidating not supported") ;
151             }
152         }
153         else if(property == STRING_INTERNING || property.equals(STRING_INTERNING)){
154             if( (value instanceof Boolean JavaDoc) && !((Boolean JavaDoc)value).booleanValue()){
155                 throw new java.lang.IllegalArgumentException JavaDoc("false value of " + STRING_INTERNING + "feature is not supported") ;
156             }
157         }
158         else if(property == XMLInputFactory.RESOLVER || property.equals(XMLInputFactory.RESOLVER)){
159             //add internal stax property
160
supportedProps.put( Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY , new StaxEntityResolverWrapper((XMLResolver)value)) ;
161         }
162         supportedProps.put(property, value ) ;
163         if(equivalentProperty != null){
164             supportedProps.put(equivalentProperty, value ) ;
165         }
166     }
167     
168     public String JavaDoc toString(){
169         return supportedProps.toString();
170     }
171     
172 }//PropertyManager
173
Popular Tags