286N/A/*
286N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
286N/A *
286N/A * This code is free software; you can redistribute it and/or modify it
286N/A * under the terms of the GNU General Public License version 2 only, as
286N/A * published by the Free Software Foundation. Oracle designates this
286N/A * particular file as subject to the "Classpath" exception as provided
286N/A * by Oracle in the LICENSE file that accompanied this code.
286N/A *
286N/A * This code is distributed in the hope that it will be useful, but WITHOUT
286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
286N/A * version 2 for more details (a copy is included in the LICENSE file that
286N/A * accompanied this code).
286N/A *
286N/A * You should have received a copy of the GNU General Public License version
286N/A * 2 along with this work; if not, write to the Free Software Foundation,
286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
286N/A *
286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
286N/A * or visit www.oracle.com if you need additional information or have any
286N/A * questions.
286N/A */
286N/A
286N/Apackage com.sun.xml.internal.stream.events;
286N/A
286N/Aimport javax.xml.namespace.QName;
286N/Aimport javax.xml.stream.events.Attribute;
286N/Aimport java.io.Writer;
286N/Aimport javax.xml.stream.events.XMLEvent;
286N/A
286N/A
286N/A//xxx: AttributeEvent is not really a first order event. Should we be renaming the class to AttributeImpl for consistent
286N/A//naming convention.
286N/A
286N/A/**
286N/A * Implementation of Attribute Event.
286N/A *
286N/A *@author Neeraj Bajaj, Sun Microsystems
286N/A *@author K.Venugopal, Sun Microsystems
286N/A *
286N/A */
286N/A
286N/Apublic class AttributeImpl extends DummyEvent implements Attribute
286N/A
286N/A{
286N/A //attribute value
286N/A private String fValue;
286N/A private String fNonNormalizedvalue;
286N/A
286N/A //name of the attribute
286N/A private QName fQName;
286N/A //attribute type
286N/A private String fAttributeType = "CDATA";
286N/A
286N/A
286N/A //A flag indicating whether this attribute was actually specified in the start-tag
286N/A //of its element or was defaulted from the schema.
286N/A private boolean fIsSpecified;
286N/A
286N/A public AttributeImpl(){
286N/A init();
286N/A }
286N/A public AttributeImpl(String name, String value) {
286N/A init();
286N/A fQName = new QName(name);
286N/A fValue = value;
286N/A }
286N/A
286N/A public AttributeImpl(String prefix, String name, String value) {
286N/A this(prefix, null,name, value, null,null,false );
286N/A }
286N/A
286N/A public AttributeImpl(String prefix, String uri, String localPart, String value, String type) {
286N/A this(prefix, uri, localPart, value, null, type, false);
286N/A }
286N/A
286N/A public AttributeImpl(String prefix, String uri, String localPart, String value, String nonNormalizedvalue, String type, boolean isSpecified) {
286N/A this(new QName(uri, localPart, prefix), value, nonNormalizedvalue, type, isSpecified);
286N/A }
286N/A
286N/A
286N/A public AttributeImpl(QName qname, String value, String nonNormalizedvalue, String type, boolean isSpecified) {
286N/A init();
286N/A fQName = qname ;
286N/A fValue = value ;
286N/A if(type != null && !type.equals(""))
286N/A fAttributeType = type;
286N/A
286N/A fNonNormalizedvalue = nonNormalizedvalue;
286N/A fIsSpecified = isSpecified ;
286N/A
286N/A }
286N/A
286N/A public String toString() {
286N/A if( fQName.getPrefix() != null && fQName.getPrefix().length() > 0 )
286N/A return fQName.getPrefix() + ":" + fQName.getLocalPart() + "='" + fValue + "'";
286N/A else
286N/A return fQName.getLocalPart() + "='" + fValue + "'";
286N/A }
286N/A
286N/A public void setName(QName name){
286N/A fQName = name ;
286N/A }
286N/A
286N/A public QName getName() {
286N/A return fQName;
286N/A }
286N/A
286N/A public void setValue(String value){
286N/A fValue = value;
286N/A }
286N/A
286N/A public String getValue() {
286N/A return fValue;
286N/A }
286N/A
286N/A public void setNonNormalizedValue(String nonNormalizedvalue){
286N/A fNonNormalizedvalue = nonNormalizedvalue;
286N/A }
286N/A
286N/A public String getNonNormalizedValue(){
286N/A return fNonNormalizedvalue ;
286N/A }
286N/A
286N/A public void setAttributeType(String attributeType){
286N/A fAttributeType = attributeType ;
286N/A }
286N/A
286N/A /** Gets the type of this attribute, default is "CDATA */
286N/A // We dont need to take care of default value.. implementation takes care of it.
286N/A public String getDTDType() {
286N/A return fAttributeType;
286N/A }
286N/A
286N/A /** is this attribute is specified in the instance document */
286N/A
286N/A public void setSpecified(boolean isSpecified){
286N/A fIsSpecified = isSpecified ;
286N/A }
286N/A
286N/A public boolean isSpecified() {
286N/A return fIsSpecified ;
286N/A }
286N/A
286N/A protected void writeAsEncodedUnicodeEx(java.io.Writer writer)
286N/A throws java.io.IOException
286N/A {
286N/A writer.write(toString());
286N/A }
286N/A
286N/A
286N/A protected void init(){
286N/A setEventType(XMLEvent.ATTRIBUTE);
286N/A }
286N/A
286N/A
286N/A
286N/A
286N/A}//AttributeImpl