1 /*
2  * Copyright (c) 2005, 2012, 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.stream.buffer;
27 
28 @SuppressWarnings("PointlessBitwiseExpression")
29 public abstract class AbstractCreatorProcessor {
30     /**
31      * Flag on a T_DOCUMENT to indicate if a fragment
32      */
33     protected static final int FLAG_DOCUMENT_FRAGMENT      = 1 << 0;
34 
35     /*
36      * Flags on T_ELEMENT, T_ATTRIBUTE, T_NAMESPACE_ATTRIBUTE
37      * to indicate namespace information is represent
38      */
39     protected static final int FLAG_PREFIX                 = 1 << 0;
40     protected static final int FLAG_URI                    = 1 << 1;
41     protected static final int FLAG_QUALIFIED_NAME         = 1 << 2;
42 
43     /*
44      * Types of content for T_TEXT and T_COMMENT
45      * <p>
46      * Highest 2 bits of lower nibble are used.
47      */
48     protected static final int CONTENT_TYPE_CHAR_ARRAY        = 0 << 2;
49     protected static final int CONTENT_TYPE_CHAR_ARRAY_COPY   = 1 << 2;
50     protected static final int CONTENT_TYPE_STRING            = 2 << 2;
51     protected static final int CONTENT_TYPE_OBJECT            = 3 << 2;
52 
53     /*
54      * Size of the length of character content for CONTENT_TYPE_CHAR_ARRAY
55      * <p>
56      * Last bit of lower nibble is used.
57      */
58     protected static final int CHAR_ARRAY_LENGTH_SMALL        = 0;
59     protected static final int CHAR_ARRAY_LENGTH_MEDIUM       = 1;
60     protected static final int CHAR_ARRAY_LENGTH_SMALL_SIZE   = 1 << 8;
61     protected static final int CHAR_ARRAY_LENGTH_MEDIUM_SIZE  = 1 << 16;
62 
63     /*
64      * Types of value for T_ATTRIBUTE
65      * <p>
66      * Highest bit of lower nibble is used.
67      */
68     protected static final int VALUE_TYPE_STRING              = 0;
69     protected static final int VALUE_TYPE_OBJECT              = 1 << 3;
70 
71     /*
72      * Mask for types.
73      * <p>
74      * Highest nibble is used.
75      */
76     protected static final int TYPE_MASK                     = 0xF0;
77     protected static final int T_DOCUMENT                    = 0x10;
78     protected static final int T_ELEMENT                     = 0x20;
79     protected static final int T_ATTRIBUTE                   = 0x30;
80     protected static final int T_NAMESPACE_ATTRIBUTE         = 0x40;
81     protected static final int T_TEXT                        = 0x50;
82     protected static final int T_COMMENT                     = 0x60;
83     protected static final int T_PROCESSING_INSTRUCTION      = 0x70;
84     protected static final int T_UNEXPANDED_ENTITY_REFERENCE = 0x80;
85     protected static final int T_END                         = 0x90;
86 
87     /*
88      * Composed types.
89      * <p>
90      * One octet is used.
91      */
92     protected static final int T_DOCUMENT_FRAGMENT           = T_DOCUMENT | FLAG_DOCUMENT_FRAGMENT;
93 
94     protected static final int T_ELEMENT_U_LN_QN             = T_ELEMENT | FLAG_URI | FLAG_QUALIFIED_NAME;
95     protected static final int T_ELEMENT_P_U_LN              = T_ELEMENT | FLAG_PREFIX | FLAG_URI;
96     protected static final int T_ELEMENT_U_LN                = T_ELEMENT | FLAG_URI;
97     protected static final int T_ELEMENT_LN                  = T_ELEMENT;
98 
99     protected static final int T_NAMESPACE_ATTRIBUTE_P       = T_NAMESPACE_ATTRIBUTE | FLAG_PREFIX;
100     protected static final int T_NAMESPACE_ATTRIBUTE_P_U     = T_NAMESPACE_ATTRIBUTE | FLAG_PREFIX | FLAG_URI;
101     protected static final int T_NAMESPACE_ATTRIBUTE_U       = T_NAMESPACE_ATTRIBUTE | FLAG_URI;
102 
103     protected static final int T_ATTRIBUTE_U_LN_QN           = T_ATTRIBUTE | FLAG_URI | FLAG_QUALIFIED_NAME;
104     protected static final int T_ATTRIBUTE_P_U_LN            = T_ATTRIBUTE | FLAG_PREFIX | FLAG_URI;
105     protected static final int T_ATTRIBUTE_U_LN              = T_ATTRIBUTE | FLAG_URI;
106     protected static final int T_ATTRIBUTE_LN                = T_ATTRIBUTE;
107     protected static final int T_ATTRIBUTE_U_LN_QN_OBJECT    = T_ATTRIBUTE_U_LN_QN | VALUE_TYPE_OBJECT;
108     protected static final int T_ATTRIBUTE_P_U_LN_OBJECT     = T_ATTRIBUTE_P_U_LN | VALUE_TYPE_OBJECT;
109     protected static final int T_ATTRIBUTE_U_LN_OBJECT       = T_ATTRIBUTE_U_LN | VALUE_TYPE_OBJECT;
110     protected static final int T_ATTRIBUTE_LN_OBJECT         = T_ATTRIBUTE_LN | VALUE_TYPE_OBJECT;
111 
112     protected static final int T_TEXT_AS_CHAR_ARRAY          = T_TEXT;
113     protected static final int T_TEXT_AS_CHAR_ARRAY_SMALL    = T_TEXT | CHAR_ARRAY_LENGTH_SMALL;
114     protected static final int T_TEXT_AS_CHAR_ARRAY_MEDIUM   = T_TEXT | CHAR_ARRAY_LENGTH_MEDIUM;
115     protected static final int T_TEXT_AS_CHAR_ARRAY_COPY     = T_TEXT | CONTENT_TYPE_CHAR_ARRAY_COPY;
116     protected static final int T_TEXT_AS_STRING              = T_TEXT | CONTENT_TYPE_STRING;
117     protected static final int T_TEXT_AS_OBJECT              = T_TEXT | CONTENT_TYPE_OBJECT;
118 
119     protected static final int T_COMMENT_AS_CHAR_ARRAY        = T_COMMENT;
120     protected static final int T_COMMENT_AS_CHAR_ARRAY_SMALL  = T_COMMENT | CHAR_ARRAY_LENGTH_SMALL;
121     protected static final int T_COMMENT_AS_CHAR_ARRAY_MEDIUM = T_COMMENT | CHAR_ARRAY_LENGTH_MEDIUM;
122     protected static final int T_COMMENT_AS_CHAR_ARRAY_COPY   = T_COMMENT | CONTENT_TYPE_CHAR_ARRAY_COPY;
123     protected static final int T_COMMENT_AS_STRING            = T_COMMENT | CONTENT_TYPE_STRING;
124 
125     protected static final int T_END_OF_BUFFER               = -1;
126 
127     protected FragmentedArray<byte[]> _currentStructureFragment;
128     protected byte[] _structure;
129     protected int _structurePtr;
130 
131     protected FragmentedArray<String[]> _currentStructureStringFragment;
132     protected String[] _structureStrings;
133     protected int _structureStringsPtr;
134 
135     protected FragmentedArray<char[]> _currentContentCharactersBufferFragment;
136     protected char[] _contentCharactersBuffer;
137     protected int _contentCharactersBufferPtr;
138 
139     protected FragmentedArray<Object[]> _currentContentObjectFragment;
140     protected Object[] _contentObjects;
141     protected int _contentObjectsPtr;
142 }
143