- private final class AugmentationSchemaImpl implements AugmentationSchema {
- private SchemaPath targetPath;
- private RevisionAwareXPath whenCondition;
- private final Map<QName, DataSchemaNode> childNodes = new HashMap<>();
- private final Set<UsesNode> uses = new HashSet<>();
- private String description;
- private String reference;
- private Status status;
- private final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
-
- private AugmentationSchemaImpl(SchemaPath targetPath) {
- this.targetPath = targetPath;
- }
-
- @Override
- public SchemaPath getTargetPath() {
- return targetPath;
- }
-
- private void setTargetPath(SchemaPath path) {
- this.targetPath = path;
- }
-
- @Override
- public RevisionAwareXPath getWhenCondition() {
- return whenCondition;
- }
-
- private void setWhenCondition(RevisionAwareXPath whenCondition) {
- this.whenCondition = whenCondition;
- }
-
- @Override
- public Set<DataSchemaNode> getChildNodes() {
- final Set<DataSchemaNode> result = new TreeSet<DataSchemaNode>(Comparators.SCHEMA_NODE_COMP);
- result.addAll(childNodes.values());
- return Collections.unmodifiableSet(result);
- }
-
- private void addChildNodes(Map<QName, DataSchemaNode> childNodes) {
- if (childNodes != null) {
- this.childNodes.putAll(childNodes);
- }
- }
-
- /**
- * Always returns an empty set, because augment can not contains
- * grouping statement.
- */
- @Override
- public Set<GroupingDefinition> getGroupings() {
- return Collections.emptySet();
- }
-
- @Override
- public Set<UsesNode> getUses() {
- return Collections.unmodifiableSet(uses);
- }
-
- private void addUses(Set<UsesNode> uses) {
- if (uses != null) {
- this.uses.addAll(uses);
- }
- }
-
- /**
- * Always returns an empty set, because augment can not contains type
- * definitions.
- */
- @Override
- public Set<TypeDefinition<?>> getTypeDefinitions() {
- return Collections.emptySet();
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.unmodifiableList(unknownNodes);
- }
-
- private void addUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
- if (unknownSchemaNodes != null) {
- this.unknownNodes.addAll(unknownSchemaNodes);
- }
- }
-
- @Override
- public DataSchemaNode getDataChildByName(QName name) {
- return childNodes.get(name);
- }
-
- @Override
- public DataSchemaNode getDataChildByName(String name) {
- DataSchemaNode result = null;
- for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
- if (entry.getKey().getLocalName().equals(name)) {
- result = entry.getValue();
- break;
- }
- }
- return result;
- }
-
- @Override
- public int hashCode() {
- final int prime = 17;
- int result = 1;
- result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
- result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
- result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj;
- if (targetPath == null) {
- if (other.targetPath != null) {
- return false;
- }
- } else if (!targetPath.equals(other.targetPath)) {
- return false;
- }
- if (whenCondition == null) {
- if (other.whenCondition != null) {
- return false;
- }
- } else if (!whenCondition.equals(other.whenCondition)) {
- return false;
- }
- if (childNodes == null) {
- if (other.childNodes != null) {
- return false;
- }
- } else if (!childNodes.equals(other.childNodes)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
- sb.append("[");
- sb.append("targetPath=" + targetPath);
- sb.append(", when=" + whenCondition);
- sb.append("]");
- return sb.toString();
- }