Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/com/sun/xml/internal/stream/events/AttributeImpl.java
86414 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.xml.internal.stream.events;2627import javax.xml.namespace.QName;28import javax.xml.stream.events.Attribute;29import java.io.Writer;30import javax.xml.stream.events.XMLEvent;313233//xxx: AttributeEvent is not really a first order event. Should we be renaming the class to AttributeImpl for consistent34//naming convention.3536/**37* Implementation of Attribute Event.38*39*@author Neeraj Bajaj, Sun Microsystems40*@author K.Venugopal, Sun Microsystems41*42*/4344public class AttributeImpl extends DummyEvent implements Attribute4546{47//attribute value48private String fValue;49private String fNonNormalizedvalue;5051//name of the attribute52private QName fQName;53//attribute type54private String fAttributeType = "CDATA";555657//A flag indicating whether this attribute was actually specified in the start-tag58//of its element or was defaulted from the schema.59private boolean fIsSpecified;6061public AttributeImpl(){62init();63}64public AttributeImpl(String name, String value) {65init();66fQName = new QName(name);67fValue = value;68}6970public AttributeImpl(String prefix, String name, String value) {71this(prefix, null,name, value, null,null,false );72}7374public AttributeImpl(String prefix, String uri, String localPart, String value, String type) {75this(prefix, uri, localPart, value, null, type, false);76}7778public AttributeImpl(String prefix, String uri, String localPart, String value, String nonNormalizedvalue, String type, boolean isSpecified) {79this(new QName(uri, localPart, prefix), value, nonNormalizedvalue, type, isSpecified);80}818283public AttributeImpl(QName qname, String value, String nonNormalizedvalue, String type, boolean isSpecified) {84init();85fQName = qname ;86fValue = value ;87if(type != null && !type.equals(""))88fAttributeType = type;8990fNonNormalizedvalue = nonNormalizedvalue;91fIsSpecified = isSpecified ;9293}9495public String toString() {96if( fQName.getPrefix() != null && fQName.getPrefix().length() > 0 )97return fQName.getPrefix() + ":" + fQName.getLocalPart() + "='" + fValue + "'";98else99return fQName.getLocalPart() + "='" + fValue + "'";100}101102public void setName(QName name){103fQName = name ;104}105106public QName getName() {107return fQName;108}109110public void setValue(String value){111fValue = value;112}113114public String getValue() {115return fValue;116}117118public void setNonNormalizedValue(String nonNormalizedvalue){119fNonNormalizedvalue = nonNormalizedvalue;120}121122public String getNonNormalizedValue(){123return fNonNormalizedvalue ;124}125126public void setAttributeType(String attributeType){127fAttributeType = attributeType ;128}129130/** Gets the type of this attribute, default is "CDATA */131// We dont need to take care of default value.. implementation takes care of it.132public String getDTDType() {133return fAttributeType;134}135136/** is this attribute is specified in the instance document */137138public void setSpecified(boolean isSpecified){139fIsSpecified = isSpecified ;140}141142public boolean isSpecified() {143return fIsSpecified ;144}145146protected void writeAsEncodedUnicodeEx(java.io.Writer writer)147throws java.io.IOException148{149writer.write(toString());150}151152153protected void init(){154setEventType(XMLEvent.ATTRIBUTE);155}156157158159160}//AttributeImpl161162163