src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/AttributesHolder.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2010, 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 import org.xml.sax.Attributes;
  29 
  30 /**
  31  * Class for holding attributes.
  32  *
  33  * Since it implements {@link Attributes}, this class follows the SAX convention
  34  * of using "" instead of null.
  35  */
  36 @SuppressWarnings({"PointlessArithmeticExpression"})
  37 public final class AttributesHolder implements Attributes {
  38     protected static final int DEFAULT_CAPACITY = 8;
  39     protected static final int ITEM_SIZE = 1 << 3;
  40 
  41     protected static final int PREFIX     = 0;
  42     protected static final int URI        = 1;
  43     protected static final int LOCAL_NAME = 2;
  44     protected static final int QNAME      = 3;
  45     protected static final int TYPE       = 4;
  46     protected static final int VALUE      = 5;
  47 
  48     protected int _attributeCount;
  49 
  50     protected String[] _strings;
  51 
  52     public AttributesHolder() {
  53         _strings = new String[DEFAULT_CAPACITY * ITEM_SIZE];
  54     }
  55 
  56     public final int getLength() {
  57         return _attributeCount;
  58     }
  59 
  60     public final String getPrefix(int index) {
  61         return (index >= 0 && index < _attributeCount) ?
  62             _strings[(index << 3) + PREFIX] : null;
  63     }
  64 
  65     public final String getLocalName(int index) {
  66         return (index >= 0 && index < _attributeCount) ?
  67             _strings[(index << 3) + LOCAL_NAME] : null;
  68     }
  69 
  70     public final String getQName(int index) {


   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 import org.xml.sax.Attributes;
  29 
  30 /**
  31  * Class for holding attributes.
  32  *
  33  * Since it implements {@link Attributes}, this class follows the SAX convention
  34  * of using "" instead of null.
  35  */
  36 @SuppressWarnings({"PointlessArithmeticExpression"})
  37 public final class AttributesHolder implements Attributes {
  38     private static final int DEFAULT_CAPACITY = 8;
  39     private static final int ITEM_SIZE = 1 << 3;
  40 
  41     private static final int PREFIX     = 0;
  42     private static final int URI        = 1;
  43     private static final int LOCAL_NAME = 2;
  44     private static final int QNAME      = 3;
  45     private static final int TYPE       = 4;
  46     private static final int VALUE      = 5;
  47 
  48     private int _attributeCount;
  49 
  50     private String[] _strings;
  51 
  52     public AttributesHolder() {
  53         _strings = new String[DEFAULT_CAPACITY * ITEM_SIZE];
  54     }
  55 
  56     public final int getLength() {
  57         return _attributeCount;
  58     }
  59 
  60     public final String getPrefix(int index) {
  61         return (index >= 0 && index < _attributeCount) ?
  62             _strings[(index << 3) + PREFIX] : null;
  63     }
  64 
  65     public final String getLocalName(int index) {
  66         return (index >= 0 && index < _attributeCount) ?
  67             _strings[(index << 3) + LOCAL_NAME] : null;
  68     }
  69 
  70     public final String getQName(int index) {