1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.bind.v2.runtime.output;
27
28 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
29 import com.sun.xml.internal.bind.v2.runtime.Name;
30 import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
31 import javax.xml.stream.XMLStreamException;
32
33 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data;
34 import com.sun.xml.internal.fastinfoset.EncodingConstants;
35 import com.sun.xml.internal.fastinfoset.stax.StAXDocumentSerializer;
36 import java.io.IOException;
37 import java.util.Collection;
38 import java.util.Map;
39 import java.util.WeakHashMap;
40 import javax.xml.bind.JAXBContext;
41 import com.sun.xml.internal.org.jvnet.fastinfoset.VocabularyApplicationData;
42 import org.xml.sax.SAXException;
43
44 /**
45 * {@link XmlOutput} for {@link StAXDocumentSerializer}.
46 * <p>
47 * This class is responsible for managing the indexing of elements, attributes
48 * and local names that are known to JAXB by way of the JAXBContext (generated
49 * from JAXB beans or schema). The pre-encoded UTF-8 representations of known
50 * local names are also utilized.
51 * <p>
52 * The lookup of elements, attributes and local names with respect to a context
53 * is very efficient. It relies on an incrementing base line so that look up is
54 * performed in O(1) time and only uses static memory. When the base line reaches
55 * a point where integer overflow will occur the arrays and base line are reset
56 * (such an event is rare and will have little impact on performance).
57 * <p>
58 * A weak map of JAXB contexts to optimized tables for attributes, elements and
59 * local names is utilized and stored on the LowLevel StAX serializer. Thus,
60 * optimized serializing can work other multiple serializing of JAXB beans using
61 * the same LowLevel StAX serializer instance. This approach works best when JAXB
62 * contexts are only created once per schema or JAXB beans (which is the recommended
203 * <p>
204 * An instance will be registered with the
205 * {@link StAXDocumentSerializer}.
206 */
207 final static class AppData implements VocabularyApplicationData {
208 final Map<JAXBContext, TablesPerJAXBContext> contexts =
209 new WeakHashMap<JAXBContext, TablesPerJAXBContext>();
210 final Collection<TablesPerJAXBContext> collectionOfContexts = contexts.values();
211
212 /**
213 * Clear all the tables.
214 */
215 public void clear() {
216 for(TablesPerJAXBContext c : collectionOfContexts)
217 c.requireClearTables();
218 }
219 }
220
221 public FastInfosetStreamWriterOutput(StAXDocumentSerializer out,
222 JAXBContextImpl context) {
223 super(out);
224
225 this.fiout = out;
226 this.localNames = context.getUTF8NameTable();
227
228 final VocabularyApplicationData vocabAppData = fiout.getVocabularyApplicationData();
229 AppData appData = null;
230 if (vocabAppData == null || !(vocabAppData instanceof AppData)) {
231 appData = new AppData();
232 fiout.setVocabularyApplicationData(appData);
233 } else {
234 appData = (AppData)vocabAppData;
235 }
236
237 final TablesPerJAXBContext tablesPerContext = appData.contexts.get(context);
238 if (tablesPerContext != null) {
239 tables = tablesPerContext;
240 /**
241 * Obtain the current local name index. Thus will be used to
242 * calculate the maximum index value when serializing for this context
243 */
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.bind.v2.runtime.output;
27
28 import com.sun.xml.internal.bind.marshaller.NoEscapeHandler;
29 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
30 import com.sun.xml.internal.bind.v2.runtime.Name;
31 import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
32 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data;
33 import com.sun.xml.internal.fastinfoset.EncodingConstants;
34 import com.sun.xml.internal.fastinfoset.stax.StAXDocumentSerializer;
35 import com.sun.xml.internal.org.jvnet.fastinfoset.VocabularyApplicationData;
36 import org.xml.sax.SAXException;
37
38 import javax.xml.bind.JAXBContext;
39 import javax.xml.stream.XMLStreamException;
40 import java.io.IOException;
41 import java.util.Collection;
42 import java.util.Map;
43 import java.util.WeakHashMap;
44
45 /**
46 * {@link XmlOutput} for {@link StAXDocumentSerializer}.
47 * <p>
48 * This class is responsible for managing the indexing of elements, attributes
49 * and local names that are known to JAXB by way of the JAXBContext (generated
50 * from JAXB beans or schema). The pre-encoded UTF-8 representations of known
51 * local names are also utilized.
52 * <p>
53 * The lookup of elements, attributes and local names with respect to a context
54 * is very efficient. It relies on an incrementing base line so that look up is
55 * performed in O(1) time and only uses static memory. When the base line reaches
56 * a point where integer overflow will occur the arrays and base line are reset
57 * (such an event is rare and will have little impact on performance).
58 * <p>
59 * A weak map of JAXB contexts to optimized tables for attributes, elements and
60 * local names is utilized and stored on the LowLevel StAX serializer. Thus,
61 * optimized serializing can work other multiple serializing of JAXB beans using
62 * the same LowLevel StAX serializer instance. This approach works best when JAXB
63 * contexts are only created once per schema or JAXB beans (which is the recommended
204 * <p>
205 * An instance will be registered with the
206 * {@link StAXDocumentSerializer}.
207 */
208 final static class AppData implements VocabularyApplicationData {
209 final Map<JAXBContext, TablesPerJAXBContext> contexts =
210 new WeakHashMap<JAXBContext, TablesPerJAXBContext>();
211 final Collection<TablesPerJAXBContext> collectionOfContexts = contexts.values();
212
213 /**
214 * Clear all the tables.
215 */
216 public void clear() {
217 for(TablesPerJAXBContext c : collectionOfContexts)
218 c.requireClearTables();
219 }
220 }
221
222 public FastInfosetStreamWriterOutput(StAXDocumentSerializer out,
223 JAXBContextImpl context) {
224 super(out, NoEscapeHandler.theInstance);
225
226 this.fiout = out;
227 this.localNames = context.getUTF8NameTable();
228
229 final VocabularyApplicationData vocabAppData = fiout.getVocabularyApplicationData();
230 AppData appData = null;
231 if (vocabAppData == null || !(vocabAppData instanceof AppData)) {
232 appData = new AppData();
233 fiout.setVocabularyApplicationData(appData);
234 } else {
235 appData = (AppData)vocabAppData;
236 }
237
238 final TablesPerJAXBContext tablesPerContext = appData.contexts.get(context);
239 if (tablesPerContext != null) {
240 tables = tablesPerContext;
241 /**
242 * Obtain the current local name index. Thus will be used to
243 * calculate the maximum index value when serializing for this context
244 */
|