| 1 |
package com.thaiopensource.relaxng.output.xsd.basic; |
| 2 |
|
| 3 |
import com.thaiopensource.xml.util.Name; |
| 4 |
import com.thaiopensource.relaxng.edit.SourceLocation; |
| 5 |
import com.thaiopensource.util.Equal; |
| 6 |
|
| 7 |
public class Attribute extends SingleAttributeUse implements Structure { |
| 8 |
private final Name name; |
| 9 |
private final SimpleType type; |
| 10 |
|
| 11 |
/** |
| 12 |
* type may be null, indicating any type |
| 13 |
*/ |
| 14 |
|
| 15 |
public Attribute(SourceLocation location, Annotation annotation, Name name, SimpleType type) { |
| 16 |
super(location, annotation); |
| 17 |
this.name = name; |
| 18 |
this.type = type; |
| 19 |
} |
| 20 |
|
| 21 |
public Name getName() { |
| 22 |
return name; |
| 23 |
} |
| 24 |
|
| 25 |
public SimpleType getType() { |
| 26 |
return type; |
| 27 |
} |
| 28 |
|
| 29 |
public <T> T accept(AttributeUseVisitor<T> visitor) { |
| 30 |
return visitor.visitAttribute(this); |
| 31 |
} |
| 32 |
|
| 33 |
public <T> T accept(StructureVisitor<T> visitor) { |
| 34 |
return visitor.visitAttribute(this); |
| 35 |
} |
| 36 |
|
| 37 |
public boolean equals(Object obj) { |
| 38 |
if (!super.equals(obj)) |
| 39 |
return false; |
| 40 |
Attribute other = (Attribute)obj; |
| 41 |
return Equal.equal(this.type, other.type) && this.name.equals(other.name); |
| 42 |
} |
| 43 |
|
| 44 |
public int hashCode() { |
| 45 |
int hc = super.hashCode() ^ name.hashCode(); |
| 46 |
if (type != null) |
| 47 |
hc ^= type.hashCode(); |
| 48 |
return hc; |
| 49 |
} |
| 50 |
|
| 51 |
public boolean isOptional() { |
| 52 |
return false; |
| 53 |
} |
| 54 |
} |