286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.util;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.impl.Constants;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLAttributes;
286N/Aimport org.xml.sax.AttributeList;
286N/Aimport org.xml.sax.ext.Attributes2;
286N/A
286N/A/**
286N/A * Wraps {@link XMLAttributes} and makes it look like
286N/A * {@link AttributeList} and {@link Attributes}.
286N/A *
286N/A * @author Arnaud Le Hors, IBM
286N/A * @author Andy Clark, IBM
286N/A *
286N/A */
286N/Apublic final class AttributesProxy
286N/A implements AttributeList, Attributes2 {
286N/A
286N/A //
286N/A // Data
286N/A //
286N/A
286N/A /** XML attributes. */
286N/A private XMLAttributes fAttributes;
286N/A
286N/A //
286N/A // Constructors
286N/A //
286N/A
286N/A public AttributesProxy(XMLAttributes attributes) {
286N/A fAttributes = attributes;
286N/A }
286N/A
286N/A //
286N/A // Public methods
286N/A //
286N/A
286N/A /** Sets the XML attributes to be wrapped. */
286N/A public void setAttributes(XMLAttributes attributes) {
286N/A fAttributes = attributes;
286N/A } // setAttributes(XMLAttributes)
286N/A
286N/A public XMLAttributes getAttributes() {
286N/A return fAttributes;
286N/A }
286N/A
286N/A /*
286N/A * Attributes methods
286N/A */
286N/A
286N/A public int getLength() {
286N/A return fAttributes.getLength();
286N/A }
286N/A
286N/A public String getQName(int index) {
286N/A return fAttributes.getQName(index);
286N/A }
286N/A
286N/A public String getURI(int index) {
286N/A // This hides the fact that internally we use null instead of empty string
286N/A // SAX requires the URI to be a string or an empty string
286N/A String uri = fAttributes.getURI(index);
286N/A return uri != null ? uri : XMLSymbols.EMPTY_STRING;
286N/A }
286N/A
286N/A public String getLocalName(int index) {
286N/A return fAttributes.getLocalName(index);
286N/A }
286N/A
286N/A public String getType(int i) {
286N/A return fAttributes.getType(i);
286N/A }
286N/A
286N/A public String getType(String name) {
286N/A return fAttributes.getType(name);
286N/A }
286N/A
286N/A public String getType(String uri, String localName) {
286N/A return uri.equals(XMLSymbols.EMPTY_STRING) ?
286N/A fAttributes.getType(null, localName) :
286N/A fAttributes.getType(uri, localName);
286N/A }
286N/A
286N/A public String getValue(int i) {
286N/A return fAttributes.getValue(i);
286N/A }
286N/A
286N/A public String getValue(String name) {
286N/A return fAttributes.getValue(name);
286N/A }
286N/A
286N/A public String getValue(String uri, String localName) {
286N/A return uri.equals(XMLSymbols.EMPTY_STRING) ?
286N/A fAttributes.getValue(null, localName) :
286N/A fAttributes.getValue(uri, localName);
286N/A }
286N/A
286N/A public int getIndex(String qName) {
286N/A return fAttributes.getIndex(qName);
286N/A }
286N/A
286N/A public int getIndex(String uri, String localPart) {
286N/A return uri.equals(XMLSymbols.EMPTY_STRING) ?
286N/A fAttributes.getIndex(null, localPart) :
286N/A fAttributes.getIndex(uri, localPart);
286N/A }
286N/A
286N/A /*
286N/A * Attributes2 methods
286N/A */
286N/A
286N/A public boolean isDeclared(int index) {
286N/A if (index < 0 || index >= fAttributes.getLength()) {
286N/A throw new ArrayIndexOutOfBoundsException(index);
286N/A }
286N/A return Boolean.TRUE.equals(
286N/A fAttributes.getAugmentations(index).getItem(
286N/A Constants.ATTRIBUTE_DECLARED));
286N/A }
286N/A
286N/A public boolean isDeclared(String qName) {
286N/A int index = getIndex(qName);
286N/A if (index == -1) {
286N/A throw new IllegalArgumentException(qName);
286N/A }
286N/A return Boolean.TRUE.equals(
286N/A fAttributes.getAugmentations(index).getItem(
286N/A Constants.ATTRIBUTE_DECLARED));
286N/A }
286N/A
286N/A public boolean isDeclared(String uri, String localName) {
286N/A int index = getIndex(uri, localName);
286N/A if (index == -1) {
286N/A throw new IllegalArgumentException(localName);
286N/A }
286N/A return Boolean.TRUE.equals(
286N/A fAttributes.getAugmentations(index).getItem(
286N/A Constants.ATTRIBUTE_DECLARED));
286N/A }
286N/A
286N/A public boolean isSpecified(int index) {
286N/A if (index < 0 || index >= fAttributes.getLength()) {
286N/A throw new ArrayIndexOutOfBoundsException(index);
286N/A }
286N/A return fAttributes.isSpecified(index);
286N/A }
286N/A
286N/A public boolean isSpecified(String qName) {
286N/A int index = getIndex(qName);
286N/A if (index == -1) {
286N/A throw new IllegalArgumentException(qName);
286N/A }
286N/A return fAttributes.isSpecified(index);
286N/A }
286N/A
286N/A public boolean isSpecified(String uri, String localName) {
286N/A int index = getIndex(uri, localName);
286N/A if (index == -1) {
286N/A throw new IllegalArgumentException(localName);
286N/A }
286N/A return fAttributes.isSpecified(index);
286N/A }
286N/A
286N/A /*
286N/A * AttributeList methods
286N/A */
286N/A
286N/A public String getName(int i) {
286N/A return fAttributes.getQName(i);
286N/A }
286N/A
286N/A}