1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.bea.xml.stream;
17
18 import java.io.Writer;
19 import javax.xml.stream.events.XMLEvent;
20 import javax.xml.stream.Location;
21 import javax.xml.stream.events.StartElement;
22 import javax.xml.stream.events.Characters;
23 import javax.xml.stream.events.EndElement;
24 import javax.xml.namespace.QName;
25
26 /***
27 * <p> An implementation of the Attribute class. </p>
28 *
29 */
30
31 public class AttributeBase implements javax.xml.stream.events.Attribute, Location {
32 private String value;
33 private QName name;
34 private QName attributeType;
35 private String locationURI;
36 private int eventType = -1;
37 private int line = -1;
38 private int column = -1;
39 private int characterOffset = 0;
40
41 public AttributeBase(String prefix,
42 String namespaceURI,
43 String localName,
44 String value,
45 String attributeType) {
46 if (prefix == null) prefix = "";
47
48 name = new QName(namespaceURI, localName,prefix);
49 this.value = value;
50 this.attributeType = new QName(attributeType);
51 }
52
53 public AttributeBase(String prefix,
54 String localName,
55 String value) {
56
57 if (prefix == null) prefix = "";
58 name = new QName("",localName,prefix);
59 this.value = value;
60 }
61
62 public AttributeBase(QName name,
63 String value) {
64 this.name = name;
65 this.value = value;
66 }
67
68 public String toString() {
69 if (name.getPrefix()!=null &&
70 !name.getPrefix().equals(""))
71 return "['"+name.getNamespaceURI()+"']:"+name.getPrefix()+":"+name.getLocalPart()+"='"+value+"'";
72 return name.getLocalPart()+"='"+value+"'";
73 }
74 public int getLineNumber() { return line; }
75 public void setLineNumber(int line) { this.line = line; }
76 public int getColumnNumber() { return column; }
77 public void setColumnNumber(int col) { this.column = col; }
78 public int getCharacterOffset() { return characterOffset; }
79 public void setCharacterOffset(int c) { characterOffset = c; }
80 public String getLocationURI() { return locationURI; }
81 public void setLocationURI(String uri) { locationURI = uri; }
82
83 public int getEventType() { return XMLEvent.ATTRIBUTE; }
84 public boolean hasName() { return name != null; }
85 public QName getName() { return name; }
86 public boolean isNamespaceDeclaration() { return false; }
87 public String getLocalName() { return name.getLocalPart(); }
88 public String getValue() { return value; }
89 public String getDTDType() { return "CDATA"; }
90 public String getNamespaceURI() { return name.getNamespaceURI();}
91 public void setNamespaceURI(String uri) { name = new QName(uri,name.getLocalPart()); }
92 public boolean isSpecified() { return false;}
93 public boolean isStartElement() { return false; }
94 public boolean isEndElement() { return false; }
95 public boolean isEntityReference() { return false; }
96 public boolean isProcessingInstruction() { return false; }
97 public boolean isCharacters() { return false; }
98 public boolean isAttribute() { return true; }
99 public boolean isNamespace() { return false; }
100 public boolean isStartDocument() { return false; }
101 public boolean isEndDocument() { return false; }
102 public boolean isEndEntity() { return false; }
103 public boolean isStartEntity() { return false; }
104 public String getPublicId() { return null; }
105 public String getSystemId() { return null; }
106
107 public Location getLocation() { return this; }
108 public StartElement asStartElement() { throw new ClassCastException("cannnot cast AttributeBase to StartElement"); }
109 public EndElement asEndElement() { throw new ClassCastException("cannnot cast AttributeBase to EndElement"); }
110 public Characters asCharacters() { throw new ClassCastException("cannnot cast AttributeBase to Characters"); }
111 public void recycle(){}
112 public boolean isDefault() { return true; }
113 public String getSourceName() { return null ; }
114 public QName getSchemaType() { return null; }
115 public void writeAsEncodedUnicode(Writer writer)
116 throws javax.xml.stream.XMLStreamException {}
117
118 }
119
120