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