--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+abstract class AbstractEffectiveContainerSchemaNode<D extends DeclaredStatement<QName>> extends
+ AbstractEffectiveSimpleDataNodeContainer<D> implements ContainerSchemaNode {
+
+ private final boolean presence;
+
+ public AbstractEffectiveContainerSchemaNode(StmtContext<QName, D, ?> ctx) {
+ super(ctx);
+ this.presence = firstEffective(PresenceEffectiveStatementImpl.class) != null;
+ }
+
+ @Override
+ public boolean isPresenceContainer() {
+ return presence;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
+abstract class AbstractEffectiveDataSchemaNode<D extends DeclaredStatement<QName>> extends
+ AbstractEffectiveSchemaNode<D> implements DataSchemaNode {
+
+ // :FIXME should be private and final
+ boolean augmenting;
+ private final boolean addedByUses;
+ private final boolean configuration;
+ private final ConstraintDefinition constraints;
+
+ public AbstractEffectiveDataSchemaNode(StmtContext<QName, D, ?> ctx) {
+ super(ctx);
+ this.constraints = new EffectiveConstraintDefinitionImpl(this);
+
+ ConfigEffectiveStatementImpl configStmt = firstEffective(ConfigEffectiveStatementImpl.class);
+ this.configuration = (configStmt == null) ? true : configStmt.argument();
+
+ // initCopyType
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
+ if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
+ this.addedByUses = this.augmenting = true;
+ } else {
+ this.augmenting = copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION);
+ this.addedByUses = copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES);
+ }
+ }
+
+ @Override
+ public boolean isAugmenting() {
+ return augmenting;
+ }
+
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public boolean isConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ public ConstraintDefinition getConstraints() {
+ return constraints;
+ }
+}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-
-import java.util.LinkedHashSet;
-import java.util.LinkedHashMap;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.Map;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
+abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
extends AbstractEffectiveDocumentedNode<A, D> implements
DataNodeContainer {
- private final ImmutableMap<QName, DataSchemaNode> childNodes;
- private final ImmutableSet<GroupingDefinition> groupings;
- private final ImmutableSet<UsesNode> uses;
- private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
- private final ImmutableSet<DataSchemaNode> publicChildNodes;
+ private final Map<QName, DataSchemaNode> childNodes;
+ private final Set<GroupingDefinition> groupings;
+ private final Set<UsesNode> uses;
+ private final Set<TypeDefinition<?>> typeDefinitions;
+ private final Set<DataSchemaNode> publicChildNodes;
protected AbstractEffectiveDocumentedDataNodeContainer(
final StmtContext<A, D, ?> ctx) {
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public abstract class AbstractEffectiveDocumentedNode<A, D extends DeclaredStatement<A>>
+abstract class AbstractEffectiveDocumentedNode<A, D extends DeclaredStatement<A>>
extends EffectiveStatementBase<A, D> implements DocumentedNode {
private final String description;
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.net.URI;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+
+abstract class AbstractEffectiveModule<D extends DeclaredStatement<String>> extends
+ AbstractEffectiveDocumentedNode<String, D> implements Module, Immutable {
+
+ private final String name;
+ private final String sourcePath;
+ private final String prefix;
+ private final String yangVersion;
+ private final String organization;
+ private final String contact;
+ private final Set<ModuleImport> imports;
+ private final Set<Module> submodules;
+ private final Set<FeatureDefinition> features;
+ private final Set<NotificationDefinition> notifications;
+ private final Set<AugmentationSchema> augmentations;
+ private final Set<RpcDefinition> rpcs;
+ private final Set<Deviation> deviations;
+ private final List<ExtensionDefinition> extensionNodes;
+ private final Set<IdentitySchemaNode> identities;
+ private final List<UnknownSchemaNode> unknownNodes;
+ private final Map<QName, DataSchemaNode> childNodes;
+ private final Set<GroupingDefinition> groupings;
+ private final Set<UsesNode> uses;
+ private final Set<TypeDefinition<?>> typeDefinitions;
+ private final Set<DataSchemaNode> publicChildNodes;
+
+ AbstractEffectiveModule(final StmtContext<String, D, ? extends EffectiveStatement<String, ?>> ctx) {
+ super(ctx);
+
+ this.name = argument();
+
+ PrefixEffectiveStatementImpl prefixStmt = firstEffective(PrefixEffectiveStatementImpl.class);
+ this.prefix = (prefixStmt == null) ? null : prefixStmt.argument();
+
+ YangVersionEffectiveStatementImpl yangVersionStmt = firstEffective(YangVersionEffectiveStatementImpl.class);
+ this.yangVersion = (yangVersionStmt == null) ? "1" : yangVersionStmt.argument();
+
+ OrganizationEffectiveStatementImpl organizationStmt = firstEffective(OrganizationEffectiveStatementImpl.class);
+ this.organization = (organizationStmt == null) ? null : organizationStmt.argument();
+
+ ContactEffectiveStatementImpl contactStmt = firstEffective(ContactEffectiveStatementImpl.class);
+ this.contact = (contactStmt == null) ? null : contactStmt.argument();
+
+ if (ctx.getStatementSourceReference() instanceof DeclarationInTextSource) {
+ this.sourcePath = ((DeclarationInTextSource) ctx.getStatementSourceReference()).getSourceName();
+ } else {
+ this.sourcePath = null;
+ }
+
+ // init submodules and substatements of submodules
+ final List<EffectiveStatement<?, ?>> substatementsOfSubmodules;
+ final Map<String, ModuleIdentifier> includedSubmodulesMap = ctx
+ .getAllFromCurrentStmtCtxNamespace(IncludedSubmoduleNameToIdentifier.class);
+
+ if (includedSubmodulesMap == null || includedSubmodulesMap.isEmpty()) {
+ this.submodules = ImmutableSet.of();
+ substatementsOfSubmodules = ImmutableList.of();
+ } else {
+ Collection<ModuleIdentifier> includedSubmodules = includedSubmodulesMap.values();
+ Set<Module> submodulesInit = new HashSet<>();
+ List<EffectiveStatement<?, ?>> substatementsOfSubmodulesInit = new LinkedList<>();
+ for (ModuleIdentifier submoduleIdentifier : includedSubmodules) {
+ @SuppressWarnings("unchecked")
+ Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> submoduleCtx = (Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>) ctx
+ .getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
+ SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx
+ .buildEffective();
+ submodulesInit.add(submodule);
+ substatementsOfSubmodulesInit.addAll(submodule.effectiveSubstatements());
+ }
+
+ this.submodules = ImmutableSet.copyOf(submodulesInit);
+ substatementsOfSubmodules = ImmutableList.copyOf(substatementsOfSubmodulesInit);
+ }
+
+ // init substatements collections
+ List<EffectiveStatement<?, ?>> effectiveSubstatements = new LinkedList<>();
+
+ effectiveSubstatements.addAll(effectiveSubstatements());
+ effectiveSubstatements.addAll(substatementsOfSubmodules);
+
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
+ Set<ModuleImport> importsInit = new HashSet<>();
+ Set<NotificationDefinition> notificationsInit = new HashSet<>();
+ Set<RpcDefinition> rpcsInit = new HashSet<>();
+ Set<Deviation> deviationsInit = new HashSet<>();
+ Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
+ Set<FeatureDefinition> featuresInit = new HashSet<>();
+ List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
+
+ Map<QName, DataSchemaNode> mutableChildNodes = new LinkedHashMap<>();
+ Set<GroupingDefinition> mutableGroupings = new HashSet<>();
+ Set<UsesNode> mutableUses = new HashSet<>();
+ Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
+ Set<DataSchemaNode> mutablePublicChildNodes = new LinkedHashSet<>();
+
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
+ }
+ if (effectiveStatement instanceof AugmentationSchema) {
+ augmentationsInit.add((AugmentationSchema) effectiveStatement);
+ }
+ if (effectiveStatement instanceof ModuleImport) {
+ importsInit.add((ModuleImport) effectiveStatement);
+ }
+ if (effectiveStatement instanceof NotificationDefinition) {
+ notificationsInit.add((NotificationDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof RpcDefinition) {
+ rpcsInit.add((RpcDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof Deviation) {
+ deviationsInit.add((Deviation) effectiveStatement);
+ }
+ if (effectiveStatement instanceof IdentitySchemaNode) {
+ identitiesInit.add((IdentitySchemaNode) effectiveStatement);
+ }
+ if (effectiveStatement instanceof FeatureDefinition) {
+ featuresInit.add((FeatureDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof ExtensionDefinition) {
+ extensionNodesInit.add((ExtensionDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof DataSchemaNode) {
+ DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
+ if (!mutableChildNodes.containsKey(dataSchemaNode.getQName())) {
+ mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
+ mutablePublicChildNodes.add(dataSchemaNode);
+ } else {
+ throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ }
+ }
+ if (effectiveStatement instanceof UsesNode) {
+ UsesNode usesNode = (UsesNode) effectiveStatement;
+ if (!mutableUses.contains(usesNode)) {
+ mutableUses.add(usesNode);
+ } else {
+ throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ }
+ }
+ if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
+ TypeDefEffectiveStatementImpl typeDef = (TypeDefEffectiveStatementImpl) effectiveStatement;
+ ExtendedType extendedType = typeDef.buildType();
+ if (!mutableTypeDefinitions.contains(extendedType)) {
+ mutableTypeDefinitions.add(extendedType);
+ } else {
+ throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ }
+ }
+ if (effectiveStatement instanceof GroupingDefinition) {
+ GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
+ if (!mutableGroupings.contains(grp)) {
+ mutableGroupings.add(grp);
+ } else {
+ throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ }
+ }
+ }
+
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
+ this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit, ctx));
+ this.notifications = ImmutableSet.copyOf(notificationsInit);
+ this.rpcs = ImmutableSet.copyOf(rpcsInit);
+ this.deviations = ImmutableSet.copyOf(deviationsInit);
+ this.identities = ImmutableSet.copyOf(identitiesInit);
+ this.features = ImmutableSet.copyOf(featuresInit);
+ this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
+
+ this.childNodes = ImmutableMap.copyOf(mutableChildNodes);
+ this.groupings = ImmutableSet.copyOf(mutableGroupings);
+ this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes);
+ this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
+ this.uses = ImmutableSet.copyOf(mutableUses);
+
+ }
+
+ private static Set<ModuleImport> resolveModuleImports(final Set<ModuleImport> importsInit,
+ final StmtContext<String, ? extends DeclaredStatement<String>, ? extends EffectiveStatement<String, ?>> ctx) {
+ Set<ModuleImport> resolvedModuleImports = new LinkedHashSet<>();
+ for (ModuleImport moduleImport : importsInit) {
+ if (moduleImport.getRevision().equals(SimpleDateFormatUtil.DEFAULT_DATE_IMP)) {
+ QNameModule impModuleQName = Utils.getModuleQNameByPrefix(ctx, moduleImport.getPrefix());
+ if (!impModuleQName.getRevision().equals(SimpleDateFormatUtil.DEFAULT_DATE_REV)) {
+ ModuleImport resolvedModuleImport = new ModuleImportImpl(moduleImport.getModuleName(),
+ impModuleQName.getRevision(), moduleImport.getPrefix());
+ resolvedModuleImports.add(resolvedModuleImport);
+ }
+ } else {
+ resolvedModuleImports.add(moduleImport);
+ }
+ }
+ return resolvedModuleImports;
+ }
+
+ @Override
+ public String getModuleSourcePath() {
+ return sourcePath;
+ }
+
+ @Override
+ public String getSource() {
+ return null;
+ }
+
+ @Override
+ public URI getNamespace() {
+ return getQNameModule().getNamespace();
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Date getRevision() {
+ return getQNameModule().getRevision();
+ }
+
+ @Override
+ public String getPrefix() {
+ return prefix;
+ }
+
+ @Override
+ public String getYangVersion() {
+ return yangVersion;
+ }
+
+ @Override
+ public String getOrganization() {
+ return organization;
+ }
+
+ @Override
+ public String getContact() {
+ return contact;
+ }
+
+ @Override
+ public Set<ModuleImport> getImports() {
+ return imports;
+ }
+
+ @Override
+ public Set<Module> getSubmodules() {
+ return submodules;
+ }
+
+ @Override
+ public Set<FeatureDefinition> getFeatures() {
+ return features;
+ }
+
+ @Override
+ public Set<NotificationDefinition> getNotifications() {
+ return notifications;
+ }
+
+ @Override
+ public Set<AugmentationSchema> getAugmentations() {
+ return augmentations;
+ }
+
+ @Override
+ public Set<RpcDefinition> getRpcs() {
+ return rpcs;
+ }
+
+ @Override
+ public Set<Deviation> getDeviations() {
+ return deviations;
+ }
+
+ @Override
+ public List<ExtensionDefinition> getExtensionSchemaNodes() {
+ return extensionNodes;
+ }
+
+ @Override
+ public Set<IdentitySchemaNode> getIdentities() {
+ return identities;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ @Override
+ public final Set<TypeDefinition<?>> getTypeDefinitions() {
+ return typeDefinitions;
+ }
+
+ @Override
+ public final Set<DataSchemaNode> getChildNodes() {
+ return publicChildNodes;
+ }
+
+ @Override
+ public final Set<GroupingDefinition> getGroupings() {
+ return groupings;
+ }
+
+ @Override
+ public final DataSchemaNode getDataChildByName(final QName name) {
+ // Child nodes are keyed by their container name, so we can do a direct
+ // lookup
+ return childNodes.get(name);
+ }
+
+ @Override
+ public final DataSchemaNode getDataChildByName(final String name) {
+ for (DataSchemaNode node : childNodes.values()) {
+ if (node.getQName().getLocalName().equals(name)) {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Set<UsesNode> getUses() {
+ return uses;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(this.getClass().getSimpleName());
+ sb.append("[");
+ sb.append("name=").append(name);
+ sb.append(", namespace=").append(getNamespace());
+ sb.append(", revision=").append(getRevision());
+ sb.append(", prefix=").append(prefix);
+ sb.append(", yangVersion=").append(yangVersion);
+ sb.append("]");
+ return sb.toString();
+ }
+
+}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
-public abstract class AbstractEffectiveSchemaContext implements SchemaContext {
+abstract class AbstractEffectiveSchemaContext implements SchemaContext {
protected static final Supplier<NavigableSet<Module>> MODULE_SET_SUPPLIER = new Supplier<NavigableSet<Module>>() {
@Override
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+
+abstract class AbstractEffectiveSchemaNode<D extends DeclaredStatement<QName>> extends
+ AbstractEffectiveDocumentedNode<QName, D> implements SchemaNode {
+
+ private final QName qname;
+ private final SchemaPath path;
+ private final List<UnknownSchemaNode> unknownNodes;
+
+ AbstractEffectiveSchemaNode(StmtContext<QName, D, ?> ctx) {
+ super(ctx);
+ this.qname = ctx.getStatementArgument();
+ this.path = Utils.getSchemaPath(ctx);
+
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+ ImmutableList.Builder<UnknownSchemaNode> listBuilder = new ImmutableList.Builder<>();
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ listBuilder.add((UnknownSchemaNode) effectiveStatement);
+ }
+ }
+ this.unknownNodes = listBuilder.build();
+ }
+
+ @Override
+ public QName getQName() {
+ return qname;
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return path;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+
+abstract class AbstractEffectiveSimpleDataNodeContainer<D extends DeclaredStatement<QName>> extends
+ AbstractEffectiveDocumentedDataNodeContainer<QName, D> implements DataNodeContainer, AugmentationTarget,
+ DataSchemaNode {
+
+ private final QName qname;
+ private final SchemaPath path;
+
+ // :FIXME should be private and final
+ boolean augmenting;
+ private final boolean addedByUses;
+ private final boolean configuration;
+ private final ConstraintDefinition constraints;
+
+ private final Set<AugmentationSchema> augmentations;
+ private final List<UnknownSchemaNode> unknownNodes;
+
+ public AbstractEffectiveSimpleDataNodeContainer(StmtContext<QName, D, ?> ctx) {
+ super(ctx);
+
+ this.qname = ctx.getStatementArgument();
+ this.path = Utils.getSchemaPath(ctx);
+ this.constraints = new EffectiveConstraintDefinitionImpl(this);
+
+ ConfigEffectiveStatementImpl configStmt = firstEffective(ConfigEffectiveStatementImpl.class);
+ this.configuration = (configStmt == null) ? true : configStmt.argument();
+
+ // initSubstatementCollectionsAndFields
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
+ unknownNodesInit.add(unknownNode);
+ }
+ if (effectiveStatement instanceof AugmentationSchema) {
+ AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
+ augmentationsInit.add(augmentationSchema);
+ }
+ }
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
+
+ // initCopyType
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
+ if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
+ this.addedByUses = this.augmenting = true;
+ } else {
+ this.augmenting = copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION);
+ this.addedByUses = copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES);
+ }
+ }
+
+ @Override
+ public QName getQName() {
+ return qname;
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return path;
+ }
+
+ @Override
+ public boolean isAugmenting() {
+ return augmenting;
+ }
+
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public boolean isConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ public ConstraintDefinition getConstraints() {
+ return constraints;
+ }
+
+ @Override
+ public Set<AugmentationSchema> getAvailableAugmentations() {
+ return augmentations;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class AnyXmlEffectiveStatementImpl extends
- AbstractEffectiveDocumentedNode<QName, AnyxmlStatement> implements
+public final class AnyXmlEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode<AnyxmlStatement> implements
AnyXmlSchemaNode, DerivableSchemaNode {
- private final QName qname;
- private final SchemaPath path;
- boolean configuration = true;
- AnyXmlSchemaNode original;
- ConstraintDefinition constraintsDef;
- boolean augmenting;
- private boolean addedByUses;
-
- ImmutableList<UnknownSchemaNode> unknownNodes;
+ private final AnyXmlSchemaNode original;
public AnyXmlEffectiveStatementImpl(
final StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx) {
super(ctx);
- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
- this.constraintsDef = new EffectiveConstraintDefinitionImpl(this);
-
- initSubstatementCollectionsAndFields();
- initCopyType(ctx);
- }
-
- private void initCopyType(
- final StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
- }
-
- if (ctx.getOriginalCtx() != null) {
- original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
- }
-
- private void initSubstatementCollectionsAndFields() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
- boolean configurationInit = false;
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
- if (!configurationInit
- && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
- ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
- this.configuration = configStmt.argument();
- configurationInit = true;
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
+ this.original = ctx.getOriginalCtx() == null ? null : (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
}
@Override
return Optional.fromNullable(original);
}
- @Override
- public boolean isConfiguration() {
- return configuration;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraintsDef;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
}
AnyXmlEffectiveStatementImpl other = (AnyXmlEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(AnyXmlEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
- sb.append("qname=").append(qname);
- sb.append(", path=").append(path);
+ sb.append("qname=").append(getQName());
+ sb.append(", path=").append(getPath());
sb.append("]");
return sb.toString();
}
import org.opendaylight.yangtools.yang.model.api.stmt.ArgumentStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class ArgumentEffectiveStatementImpl extends EffectiveStatementBase<QName, ArgumentStatement> {
+public final class ArgumentEffectiveStatementImpl extends EffectiveStatementBase<QName, ArgumentStatement> {
public ArgumentEffectiveStatementImpl(final StmtContext<QName, ArgumentStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import java.net.URI;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class AugmentEffectiveStatementImpl
- extends AbstractEffectiveDocumentedDataNodeContainer<SchemaNodeIdentifier, AugmentStatement>
- implements AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentEffectiveStatementImpl> {
+public final class AugmentEffectiveStatementImpl extends
+ AbstractEffectiveDocumentedDataNodeContainer<SchemaNodeIdentifier, AugmentStatement> implements
+ AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentEffectiveStatementImpl> {
private final SchemaPath targetPath;
private final URI namespace;
private final Date revision;
private final int order;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
- private RevisionAwareXPath whenCondition;
- private AugmentationSchema copyOf;
+ private final List<UnknownSchemaNode> unknownNodes;
+ private final RevisionAwareXPath whenCondition;
+ private final AugmentationSchema copyOf;
public AugmentEffectiveStatementImpl(
final StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
super(ctx);
this.targetPath = ctx.getStatementArgument().asSchemaPath();
+
QNameModule rootModuleQName = Utils.getRootModuleQName(ctx);
this.namespace = rootModuleQName.getNamespace();
this.revision = rootModuleQName.getRevision();
this.order = ctx.getOrder();
+ this.copyOf = ctx.getOriginalCtx() == null ? null : (AugmentationSchema) ctx.getOriginalCtx().buildEffective();
- initCopyOf(ctx);
- initSubstatementCollections();
- }
-
- private void initCopyOf(
- final StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
- StatementContextBase<?, ?, ?> originalCtx = ctx.getOriginalCtx();
- if (originalCtx != null) {
- this.copyOf = (AugmentationSchema) originalCtx.buildEffective();
- }
- }
+ WhenEffectiveStatementImpl whenStmt = firstEffective(WhenEffectiveStatementImpl.class);
+ this.whenCondition = (whenStmt == null) ? null : whenStmt.argument();
- private void initSubstatementCollections() {
+ // initSubstatementCollections
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
- boolean initWhen = false;
+ ImmutableList.Builder<UnknownSchemaNode> listBuilder = new ImmutableList.Builder<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
- if(!initWhen && effectiveStatement instanceof WhenEffectiveStatementImpl) {
- WhenEffectiveStatementImpl whenStmt = (WhenEffectiveStatementImpl) effectiveStatement;
- whenCondition = whenStmt.argument();
- initWhen = true;
+ listBuilder.add((UnknownSchemaNode) effectiveStatement);
}
}
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- }
-
- public void setCopyOf(final AugmentationSchema build) {
- this.copyOf = build;
+ this.unknownNodes = listBuilder.build();
}
@Override
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
public class BaseEffectiveStatementImpl extends EffectiveStatementBase<QName, BaseStatement> {
-
public BaseEffectiveStatementImpl(final StmtContext<QName, BaseStatement, ?> ctx) {
super(ctx);
}
-
}
\ No newline at end of file
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class BelongsEffectiveToStatementImpl extends EffectiveStatementBase<String, BelongsToStatement> {
+public final class BelongsEffectiveToStatementImpl extends EffectiveStatementBase<String, BelongsToStatement> {
public BelongsEffectiveToStatementImpl(final StmtContext<String, BelongsToStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
-import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class CaseEffectiveStatementImpl extends AbstractEffectiveDocumentedDataNodeContainer<QName, CaseStatement>
- implements ChoiceCaseNode, DerivableSchemaNode {
- private final QName qname;
- private final SchemaPath path;
- private final ConstraintDefinition constraints;
+public final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer<CaseStatement> implements
+ ChoiceCaseNode, DerivableSchemaNode {
- private boolean augmenting;
- private boolean addedByUses;
- private ChoiceCaseNode original;
- private ImmutableSet<AugmentationSchema> augmentations;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
+ private final ChoiceCaseNode original;
public CaseEffectiveStatementImpl(
final StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
super(ctx);
- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
- this.constraints = new EffectiveConstraintDefinitionImpl(this);
-
- initSubstatementCollections();
- initCopyType(ctx);
- }
-
- private void initCopyType(
- final StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
- }
-
- if (ctx.getOriginalCtx() != null) {
- original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
- }
- }
-
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
- Set<AugmentationSchema> augmentationsInit = new HashSet<>();
-
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
- if (effectiveStatement instanceof AugmentationSchema) {
- AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentationsInit.add(augmentationSchema);
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public boolean isConfiguration() {
- return false;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraints;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
+ this.original = ctx.getOriginalCtx() == null ? null : (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
}
@Override
}
@Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
- @Override
- public Set<AugmentationSchema> getAvailableAugmentations() {
- return augmentations;
+ public boolean isConfiguration() {
+ return false;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
CaseEffectiveStatementImpl other = (CaseEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
StringBuilder sb = new StringBuilder(CaseEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=");
- sb.append(qname);
+ sb.append(getQName());
sb.append("]");
return sb.toString();
}
private final DataSchemaNode caseShorthandNode;
private final QName qName;
private final SchemaPath path;
-
private final String description;
private final String reference;
private final Status status;
-
private final boolean augmenting;
private final boolean addedByUses;
private final ConstraintDefinition constraints;
private final List<UnknownSchemaNode> unknownNodes;
- private ChoiceCaseNode original;
public CaseShorthandImpl(final DataSchemaNode caseShorthandNode) {
this.caseShorthandNode = caseShorthandNode;
@Override
public Optional<? extends SchemaNode> getOriginal() {
- return Optional.fromNullable(original);
+ return Optional.absent();
}
@Override
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceStatement;
import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class ChoiceEffectiveStatementImpl extends
- AbstractEffectiveDocumentedNode<QName, ChoiceStatement> implements
+public final class ChoiceEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode<ChoiceStatement> implements
ChoiceSchemaNode, DerivableSchemaNode {
- private final QName qname;
- private final SchemaPath path;
- private boolean augmenting;
- private boolean addedByUses;
- private ChoiceSchemaNode original;
- private boolean configuration = true;
- private final ConstraintDefinition constraints;
- private String defaultCase;
+ private final ChoiceSchemaNode original;
+ private final String defaultCase;
- private ImmutableSet<ChoiceCaseNode> cases;
- private ImmutableSet<AugmentationSchema> augmentations;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
+ private final Set<ChoiceCaseNode> cases;
+ private final Set<AugmentationSchema> augmentations;
public ChoiceEffectiveStatementImpl(
final StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
super(ctx);
+ this.original = ctx.getOriginalCtx() == null ? null : (ChoiceSchemaNode) ctx.getOriginalCtx().buildEffective();
- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
- this.constraints = new EffectiveConstraintDefinitionImpl(this);
+ DefaultEffectiveStatementImpl defaultStmt = firstEffective(DefaultEffectiveStatementImpl.class);
+ this.defaultCase = (defaultStmt == null) ? null : defaultStmt.argument();
- initCopyType(ctx);
- initSubstatementCollectionsAndFields();
- }
-
- private void initCopyType(
- final StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
- }
-
- if (ctx.getOriginalCtx() != null) {
- original = (ChoiceSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
- }
-
- private void initSubstatementCollectionsAndFields() {
+ // initSubstatementCollectionsAndFields
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
Set<AugmentationSchema> augmentationsInit = new HashSet<>();
SortedSet<ChoiceCaseNode> casesInit = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
- boolean configurationInit = false;
- boolean defaultInit = false;
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
augmentationsInit.add(augmentationSchema);
ChoiceCaseNode choiceCaseNode = (ChoiceCaseNode) effectiveStatement;
casesInit.add(choiceCaseNode);
}
- if (effectiveStatement instanceof AnyXmlSchemaNode
- || effectiveStatement instanceof ContainerSchemaNode
- || effectiveStatement instanceof ListSchemaNode
- || effectiveStatement instanceof LeafListSchemaNode
+ if (effectiveStatement instanceof AnyXmlSchemaNode || effectiveStatement instanceof ContainerSchemaNode
+ || effectiveStatement instanceof ListSchemaNode || effectiveStatement instanceof LeafListSchemaNode
|| effectiveStatement instanceof LeafSchemaNode) {
DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
resetAugmenting(dataSchemaNode);
}
}
- if (!configurationInit && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
- ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
- this.configuration = configStmt.argument();
- configurationInit = true;
- }
- if (!defaultInit && effectiveStatement instanceof DefaultEffectiveStatementImpl) {
- DefaultEffectiveStatementImpl defaultCaseStmt = (DefaultEffectiveStatementImpl) effectiveStatement;
- this.defaultCase = defaultCaseStmt.argument();
- defaultInit = true;
- }
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.augmentations = ImmutableSet.copyOf(augmentationsInit);
this.cases = ImmutableSet.copyOf(casesInit);
}
}
}
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
- }
-
@Override
public Optional<ChoiceSchemaNode> getOriginal() {
return Optional.fromNullable(original);
}
- @Override
- public boolean isConfiguration() {
- return configuration;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraints;
- }
-
@Override
public Set<AugmentationSchema> getAvailableAugmentations() {
return augmentations;
}
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
@Override
public Set<ChoiceCaseNode> getCases() {
return cases;
Preconditions.checkArgument(name != null, "Choice Case string Name cannot be NULL!");
for (final ChoiceCaseNode caseNode : cases) {
- if (caseNode != null && (caseNode.getQName() != null)
- && name.equals(caseNode.getQName().getLocalName())) {
+ if (caseNode != null && (caseNode.getQName() != null) && name.equals(caseNode.getQName().getLocalName())) {
return caseNode;
}
}
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
ChoiceEffectiveStatementImpl other = (ChoiceEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(ChoiceEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
- sb.append("qname=").append(qname);
+ sb.append("qname=").append(getQName());
sb.append("]");
return sb.toString();
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class ConfigEffectiveStatementImpl extends EffectiveStatementBase<Boolean, ConfigStatement> {
+public final class ConfigEffectiveStatementImpl extends EffectiveStatementBase<Boolean, ConfigStatement> {
public ConfigEffectiveStatementImpl(final StmtContext<Boolean, ConfigStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.ContactStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class ContactEffectiveStatementImpl extends EffectiveStatementBase<String, ContactStatement> {
+public final class ContactEffectiveStatementImpl extends EffectiveStatementBase<String, ContactStatement> {
public ContactEffectiveStatementImpl(final StmtContext<String, ContactStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
-import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class ContainerEffectiveStatementImpl extends
- AbstractEffectiveDocumentedDataNodeContainer<QName, ContainerStatement>
- implements ContainerSchemaNode, DerivableSchemaNode {
+public final class ContainerEffectiveStatementImpl extends AbstractEffectiveContainerSchemaNode<ContainerStatement>
+ implements
+ DerivableSchemaNode {
- private final QName qname;
- private final SchemaPath path;
-
- private boolean presence;
-
- // FIXME: should be private
- boolean augmenting;
- private boolean addedByUses;
- private boolean configuration = true;
- private ContainerSchemaNode original;
- private final ConstraintDefinition constraints;
-
- private ImmutableSet<AugmentationSchema> augmentations;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
+ private final ContainerSchemaNode original;
public ContainerEffectiveStatementImpl(
final StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
super(ctx);
-
- qname = ctx.getStatementArgument();
- path = Utils.getSchemaPath(ctx);
- this.constraints = new EffectiveConstraintDefinitionImpl(this);
-
- initCopyType(ctx);
- initSubstatementCollectionsAndFields();
- }
-
- private void initCopyType(
- final StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
- }
-
- if (ctx.getOriginalCtx() != null) {
- original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
- }
-
- private void initSubstatementCollectionsAndFields() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
- Set<AugmentationSchema> augmentationsInit = new HashSet<>();
-
- boolean configurationInit = false;
- for (EffectiveStatement<?, ?> effectiveSubstatement : effectiveSubstatements) {
- if (effectiveSubstatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveSubstatement;
- unknownNodesInit.add(unknownNode);
- }
- if (effectiveSubstatement instanceof AugmentationSchema) {
- AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveSubstatement;
- augmentationsInit.add(augmentationSchema);
- }
- if (effectiveSubstatement instanceof PresenceEffectiveStatementImpl) {
- presence = true;
- }
- if (!configurationInit && effectiveSubstatement instanceof ConfigEffectiveStatementImpl) {
- ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveSubstatement;
- this.configuration = configStmt.argument();
- configurationInit = true;
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
+ this.original = ctx.getOriginalCtx() == null ? null : (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
}
@Override
return Optional.fromNullable(original);
}
- @Override
- public boolean isConfiguration() {
- return configuration;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraints;
- }
-
- @Override
- public Set<AugmentationSchema> getAvailableAugmentations() {
- return augmentations;
- }
-
- @Override
- public boolean isPresenceContainer() {
- return presence;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
- return "container " + qname.getLocalName();
+ return "container " + getQName().getLocalName();
}
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.DefaultStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class DefaultEffectiveStatementImpl extends EffectiveStatementBase<String, DefaultStatement> {
+public final class DefaultEffectiveStatementImpl extends EffectiveStatementBase<String, DefaultStatement> {
public DefaultEffectiveStatementImpl(final StmtContext<String, DefaultStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class DescriptionEffectiveStatementImpl extends EffectiveStatementBase<String, DescriptionStatement> {
+public final class DescriptionEffectiveStatementImpl extends EffectiveStatementBase<String, DescriptionStatement> {
public DescriptionEffectiveStatementImpl(final StmtContext<String, DescriptionStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class DeviateEffectiveStatementImpl extends EffectiveStatementBase<Deviation.Deviate, DeviateStatement> {
+public final class DeviateEffectiveStatementImpl extends EffectiveStatementBase<Deviation.Deviate, DeviateStatement> {
public DeviateEffectiveStatementImpl(final StmtContext<Deviation.Deviate, DeviateStatement, ?> ctx) {
super(ctx);
}
public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
implements Deviation, Immutable {
-
private final SchemaPath targetPath;
- private Deviate deviate;
- private String reference;
- private final ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
+ private final Deviate deviate;
+ private final String reference;
+ private final List<UnknownSchemaNode> unknownSchemaNodes;
public DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
super(ctx);
+ this.targetPath = ctx.getStatementArgument().asSchemaPath();
- List<UnknownSchemaNode> unknownSchemaNodesInit = new LinkedList<>();
+ DeviateEffectiveStatementImpl deviateStmt = firstEffective(DeviateEffectiveStatementImpl.class);
+ this.deviate = (deviateStmt == null) ? null : deviateStmt.argument();
- targetPath = ctx.getStatementArgument().asSchemaPath();
+ ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
+ this.reference = (referenceStmt == null) ? null : referenceStmt.argument();
+ List<UnknownSchemaNode> unknownSchemaNodesInit = new LinkedList<>();
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof DeviateEffectiveStatementImpl) {
- deviate = ((DeviateEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
- reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
- }
if (effectiveStatement instanceof UnknownSchemaNode) {
unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
}
}
-
unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
}
import org.opendaylight.yangtools.yang.model.api.MustDefinition;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
-public class EffectiveConstraintDefinitionImpl implements ConstraintDefinition {
+public final class EffectiveConstraintDefinitionImpl implements ConstraintDefinition {
private final RevisionAwareXPath whenCondition;
private final Set<MustDefinition> mustConstraints;
private final Boolean mandatory;
import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
-public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
+public final class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
private final SetMultimap<URI, Module> namespaceToModules;
private final SetMultimap<String, Module> nameToModules;
private final Set<Module> modules;
- private final ImmutableList<DeclaredStatement<?>> rootDeclaredStatements;
- private final ImmutableList<EffectiveStatement<?, ?>> rootEffectiveStatements;
+ private final List<DeclaredStatement<?>> rootDeclaredStatements;
+ private final List<EffectiveStatement<?, ?>> rootEffectiveStatements;
private final Set<ModuleIdentifier> moduleIdentifiers;
public EffectiveSchemaContext(final List<DeclaredStatement<?>> rootDeclaredStatements,
return new EffectiveSchemaContext(modules);
}
- public ImmutableList<DeclaredStatement<?>> getRootDeclaredStatements() {
+ public List<DeclaredStatement<?>> getRootDeclaredStatements() {
return rootDeclaredStatements;
}
- public ImmutableList<EffectiveStatement<?, ?>> getRootEffectiveStatements() {
+ public List<EffectiveStatement<?, ?>> getRootEffectiveStatements() {
return rootEffectiveStatements;
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import com.google.common.collect.Iterables;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
-abstract public class EffectiveStatementBase<A, D extends DeclaredStatement<A>> implements EffectiveStatement<A, D> {
+public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>> implements EffectiveStatement<A, D> {
- private final ImmutableList<? extends EffectiveStatement<?, ?>> substatements;
+ private final List<? extends EffectiveStatement<?, ?>> substatements;
private final StatementSource statementSource;
private final StatementDefinition statementDefinition;
private final A argument;
Collection<StatementContextBase<?, ?, ?>> substatementsInit = new LinkedList<>();
for(StatementContextBase<?, ?, ?> declaredSubstatement : declaredSubstatements) {
- if (declaredSubstatement.getPublicDefinition() == Rfc6020Mapping.USES) {
+ if (declaredSubstatement.getPublicDefinition().equals(Rfc6020Mapping.USES)) {
substatementsInit.add(declaredSubstatement);
substatementsInit.addAll(declaredSubstatement.getEffectOfStatement());
((StatementContextBase<?, ?, ?>)ctx).removeStatementsFromEffectiveSubstatements(declaredSubstatement
Predicates.and(Predicates.instanceOf(type), Predicates.instanceOf(returnType)));
return possible.isPresent() ? returnType.cast(possible.get()) : null;
}
+
+ protected final EffectiveStatement<?, ?> firstEffectiveSubstatementOfType(final Class<?> type) {
+ Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
+ Predicates.instanceOf(type));
+ return possible.isPresent() ? possible.get() : null;
+ }
}
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class EffectiveStmtUtils {
+public final class EffectiveStmtUtils {
private EffectiveStmtUtils() {
throw new UnsupportedOperationException("Utility class");
}
- public static final SourceException createNameCollisionSourceException(final StmtContext<?, ?, ?> ctx,
+ public static SourceException createNameCollisionSourceException(final StmtContext<?, ?, ?> ctx,
final EffectiveStatement<?, ?> effectiveStatement) {
return new SourceException("Error in module '"
+ ctx.getRoot().getStatementArgument()
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class ErrorAppTagEffectiveStatementImpl extends EffectiveStatementBase<String, ErrorAppTagStatement> {
+public final class ErrorAppTagEffectiveStatementImpl extends EffectiveStatementBase<String, ErrorAppTagStatement> {
public ErrorAppTagEffectiveStatementImpl(final StmtContext<String, ErrorAppTagStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class ErrorMessageEffectiveStatementImpl extends EffectiveStatementBase<String, ErrorMessageStatement> {
+public final class ErrorMessageEffectiveStatementImpl extends EffectiveStatementBase<String, ErrorMessageStatement> {
public ErrorMessageEffectiveStatementImpl(final StmtContext<String, ErrorMessageStatement, ?> ctx) {
super(ctx);
}
import java.util.List;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.TypeDefinitionEffectiveBuilder;
import org.opendaylight.yangtools.yang.parser.util.TypeConstraints;
-public class ExtendedTypeEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement> implements
+public final class ExtendedTypeEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<String, TypeStatement>
+implements
TypeDefinition<TypeDefinition<?>>, TypeDefinitionEffectiveBuilder {
private static final Splitter COLON_SPLITTER = Splitter.on(':').trimResults();
private final QName qName;
private final SchemaPath path;
-
private final TypeDefinition<?> baseType;
-
- private final String defaultValue = null;
- private final String units = null;
-
- private final String description = null;
- private final String reference = null;
-
- private final Status status = null;
-
+ private final String defaultValue;
+ private final String units;
private final List<RangeConstraint> ranges;
private final List<LengthConstraint> lengths;
private final List<PatternConstraint> patterns;
path = Utils.getSchemaPath(ctx.getFromNamespace(TypeNamespace.class, qName));
}
+ UnitsEffectiveStatementImpl unitsStmt = firstEffective(UnitsEffectiveStatementImpl.class);
+ this.units = (unitsStmt == null) ? null : unitsStmt.argument();
+ DefaultEffectiveStatementImpl defaultStmt = firstEffective(DefaultEffectiveStatementImpl.class);
+ this.defaultValue = (defaultStmt == null) ? null : defaultStmt.argument();
+
ranges = initRanges();
lengths = initLengths();
patterns = initPatterns();
typeConstraints.addPatterns(((TypeDefEffectiveStatementImpl) baseType).getPatternConstraints());
typeConstraints.addFractionDigits(((TypeDefEffectiveStatementImpl) baseType).getFractionDigits());
}
-// else if (baseType instanceof DecimalTypeDefinition) {
-// final DecimalTypeDefinition decimalType = (DecimalTypeDefinition) TypeUtils
-// .getYangBaseTypeFromString(baseTypeName);
-// typeConstraints.addRanges(decimalType.getRangeConstraints());
-// typeConstraints.addFractionDigits(decimalType.getFractionDigits());
-// }
-// else if (baseType instanceof ExtendedTypeEffectiveStatementImpl) {
-// typeConstraints.addRanges(((ExtendedTypeEffectiveStatementImpl) baseType).getRangeConstraints());
-// typeConstraints.addLengths(((ExtendedTypeEffectiveStatementImpl) baseType).getLengthConstraints());
-// typeConstraints.addPatterns(((ExtendedTypeEffectiveStatementImpl) baseType).getPatternConstraints());
-// typeConstraints.addFractionDigits(((ExtendedTypeEffectiveStatementImpl) baseType).getFractionDigits());
-// }
return typeConstraints;
}
- protected Integer initFractionDigits() {
+ protected final Integer initFractionDigits() {
final FractionDigitsEffectiveStatementImpl fractionDigitsEffStmt = firstEffective(FractionDigitsEffectiveStatementImpl.class);
return fractionDigitsEffStmt != null ? fractionDigitsEffStmt.argument() : null;
}
- protected List<RangeConstraint> initRanges() {
+ protected final List<RangeConstraint> initRanges() {
final RangeEffectiveStatementImpl rangeConstraints = firstEffective(RangeEffectiveStatementImpl.class);
return rangeConstraints != null ? rangeConstraints.argument() : Collections.<RangeConstraint> emptyList();
}
- protected List<LengthConstraint> initLengths() {
+ protected final List<LengthConstraint> initLengths() {
final LengthEffectiveStatementImpl lengthConstraints = firstEffective(LengthEffectiveStatementImpl.class);
return lengthConstraints != null ? lengthConstraints.argument() : Collections.<LengthConstraint> emptyList();
}
- protected List<PatternConstraint> initPatterns() {
+ protected final List<PatternConstraint> initPatterns() {
final List<PatternConstraint> patternConstraints = new ArrayList<>();
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
return Collections.emptyList();
}
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
public List<RangeConstraint> getRangeConstraints() {
return ranges;
}
if (baseType instanceof TypeDefEffectiveStatementImpl) {
TypeDefEffectiveStatementImpl typeDefBaseType = (TypeDefEffectiveStatementImpl) baseType;
extendedTypeBuilder = ExtendedType.builder(qName, typeDefBaseType.buildType(),
- Optional.fromNullable(description), Optional.fromNullable(reference), path);
+ Optional.fromNullable(getDescription()), Optional.fromNullable(getReference()), path);
} else {
- extendedTypeBuilder = ExtendedType.builder(qName, baseType, Optional.fromNullable(description),
- Optional.fromNullable(reference), path);
+ extendedTypeBuilder = ExtendedType.builder(qName, baseType, Optional.fromNullable(getDescription()),
+ Optional.fromNullable(getReference()), path);
}
extendedTypeBuilder.fractionDigits(fractionDigits);
public class ExtensionEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, ExtensionStatement>
implements ExtensionDefinition {
private final QName qname;
- private String argument;
+ private final String argument;
private final SchemaPath schemaPath;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
- private boolean yin;
+ private final List<UnknownSchemaNode> unknownNodes;
+ private final boolean yin;
public ExtensionEffectiveStatementImpl(
final StmtContext<QName, ExtensionStatement, EffectiveStatement<QName, ExtensionStatement>> ctx) {
super(ctx);
-
this.qname = ctx.getStatementArgument();
this.schemaPath = Utils.getSchemaPath(ctx);
- initSubstatementCollections();
- initFields();
- }
-
- private void initFields() {
+ // initSubstatementCollections
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
+ unknownNodesInit.add(unknownNode);
+ }
+ }
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ // initFields
ArgumentEffectiveStatementImpl argumentSubstatement = firstEffective(ArgumentEffectiveStatementImpl.class);
-
if (argumentSubstatement != null) {
this.argument = argumentSubstatement.argument().getLocalName();
} else {
this.yin = false;
}
+ } else {
+ this.argument = null;
+ this.yin = false;
}
}
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- }
-
@Override
public QName getQName() {
return qname;
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import com.google.common.collect.ImmutableList;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class FeatureEffectiveStatementImpl extends EffectiveStatementBase<QName, FeatureStatement> implements
+public final class FeatureEffectiveStatementImpl extends AbstractEffectiveSchemaNode<FeatureStatement> implements
FeatureDefinition {
- private final QName qName;
- private final SchemaPath path;
- private List<UnknownSchemaNode> unknownSchemaNodes;
- private String description;
- private String reference;
- private Status status;
-
public FeatureEffectiveStatementImpl(final StmtContext<QName, FeatureStatement, ?> ctx) {
super(ctx);
-
- this.qName = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
-
- initFields();
- }
-
- private void initFields() {
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
- for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
- description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
- reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
- status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
- }
-
- if (effectiveStatement instanceof UnknownSchemaNode) {
- unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
- }
- }
-
- this.unknownSchemaNodes = ImmutableList.copyOf(unknownNodesInit);
- }
-
- @Override
- public QName getQName() {
- return qName;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownSchemaNodes;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qName);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
FeatureEffectiveStatementImpl other = (FeatureEffectiveStatementImpl) obj;
- return Objects.equals(qName, other.qName) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(FeatureEffectiveStatementImpl.class.getSimpleName());
- sb.append("[name=").append(qName).append("]");
+ sb.append("[name=").append(getQName()).append("]");
return sb.toString();
}
}
import org.opendaylight.yangtools.yang.model.api.stmt.FractionDigitsStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class FractionDigitsEffectiveStatementImpl extends EffectiveStatementBase<Integer, FractionDigitsStatement> {
+public final class FractionDigitsEffectiveStatementImpl extends EffectiveStatementBase<Integer, FractionDigitsStatement> {
public FractionDigitsEffectiveStatementImpl(final StmtContext<Integer, FractionDigitsStatement, ?> ctx) {
super(ctx);
}
AbstractEffectiveDocumentedDataNodeContainer<QName, GroupingStatement> implements GroupingDefinition {
private final QName qname;
private final SchemaPath path;
-
- private boolean addedByUses;
- private List<UnknownSchemaNode> unknownNodes;
+ private final boolean addedByUses;
+ private final List<UnknownSchemaNode> unknownNodes;
public GroupingEffectiveStatementImpl(
final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
qname = ctx.getStatementArgument();
path = Utils.getSchemaPath(ctx);
- initCopyType(ctx);
- initSubstatementCollections();
- }
-
- private void initCopyType(
- final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
-
+ // initCopyType
List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
addedByUses = true;
+ } else {
+ addedByUses = false;
}
- }
- private void initSubstatementCollections() {
+ // initSubstatementCollections
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
unknownNodes = new LinkedList<>();
-
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class IdentityEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, IdentityStatement>
+public final class IdentityEffectiveStatementImpl extends AbstractEffectiveSchemaNode<IdentityStatement>
implements IdentitySchemaNode {
- private final QName qname;
- private final SchemaPath path;
private IdentitySchemaNode baseIdentity;
- private ImmutableSet<IdentitySchemaNode> derivedIdentities;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
+ private final Set<IdentitySchemaNode> derivedIdentities;
public IdentityEffectiveStatementImpl(
final StmtContext<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> ctx) {
super(ctx);
- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
-
- initSubstatementCollections();
- initDerivedIdentities(ctx);
- }
-
- private void initDerivedIdentities(
- final StmtContext<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> ctx) {
-
+ // initDerivedIdentities
Set<IdentitySchemaNode> derivedIdentitiesInit = new HashSet<IdentitySchemaNode>();
List<StmtContext<?, ?, ?>> derivedIdentitiesCtxList = ctx.getFromNamespace(
DerivedIdentitiesNamespace.class, ctx.getStatementArgument());
-
if (derivedIdentitiesCtxList == null) {
this.derivedIdentities = ImmutableSet.of();
return;
}
-
for (StmtContext<?, ?, ?> derivedIdentityCtx : derivedIdentitiesCtxList) {
IdentityEffectiveStatementImpl derivedIdentity = (IdentityEffectiveStatementImpl) derivedIdentityCtx
.buildEffective();
this.baseIdentity = baseIdentity;
}
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
@Override
public IdentitySchemaNode getBaseIdentity() {
return baseIdentity;
return Collections.unmodifiableSet(derivedIdentities);
}
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
IdentityEffectiveStatementImpl other = (IdentityEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
IdentityEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
sb.append("base=").append(baseIdentity);
- sb.append(", qname=").append(qname);
+ sb.append(", qname=").append(getQName());
sb.append("]");
return sb.toString();
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class IfFeatureEffectiveStatementImpl extends EffectiveStatementBase<QName, IfFeatureStatement> {
+public final class IfFeatureEffectiveStatementImpl extends EffectiveStatementBase<QName, IfFeatureStatement> {
public IfFeatureEffectiveStatementImpl(final StmtContext<QName, IfFeatureStatement, ?> ctx) {
super(ctx);
}
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
ModuleImport {
private final String moduleName;
- private Date revision;
- private String prefix;
+ private final Date revision;
+ private final String prefix;
public ImportEffectiveStatementImpl(final StmtContext<String, ImportStatement, ?> ctx) {
super(ctx);
moduleName = ctx.getStatementArgument();
- revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
- for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof RevisionDateEffectiveStatementImpl) {
- revision = ((RevisionDateEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
- prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
- }
+ RevisionDateEffectiveStatementImpl revisionDateStmt = firstEffective(RevisionDateEffectiveStatementImpl.class);
+ this.revision = (revisionDateStmt == null) ? SimpleDateFormatUtil.DEFAULT_DATE_IMP : revisionDateStmt.argument();
+
+ PrefixEffectiveStatementImpl prefixStmt = firstEffective(PrefixEffectiveStatementImpl.class);
+ if (prefixStmt != null ) {
+ this.prefix = prefixStmt.argument();
+ } else {
+ throw new IllegalStateException("Prefix is mandatory substatement of import statement");
}
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class IncludeEffectiveStatementImpl extends EffectiveStatementBase<String, IncludeStatement> {
+public final class IncludeEffectiveStatementImpl extends EffectiveStatementBase<String, IncludeStatement> {
public IncludeEffectiveStatementImpl(final StmtContext<String, IncludeStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
-import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class InputEffectiveStatementImpl extends
- AbstractEffectiveDocumentedDataNodeContainer<QName, InputStatement>
- implements ContainerSchemaNode {
-
- private final QName qname;
- private final SchemaPath path;
- private final boolean presence;
-
- private boolean augmenting;
- private boolean addedByUses;
- private boolean configuration = true;
- private ContainerSchemaNode original;
- private final ConstraintDefinition constraints;
-
- private ImmutableSet<AugmentationSchema> augmentations;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
+public final class InputEffectiveStatementImpl extends AbstractEffectiveContainerSchemaNode<InputStatement> {
public InputEffectiveStatementImpl(
final StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
super(ctx);
-
- qname = ctx.getStatementArgument();
- path = Utils.getSchemaPath(ctx);
- presence = firstEffective(PresenceEffectiveStatementImpl.class) != null;
- this.constraints = new EffectiveConstraintDefinitionImpl(this);
-
- initSubstatementCollectionsAndFields();
- initCopyType(ctx);
- }
-
- private void initCopyType(final StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
- }
-
- if (ctx.getOriginalCtx() != null) {
- original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
- }
-
- private void initSubstatementCollectionsAndFields() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
- Set<AugmentationSchema> augmentationsInit = new HashSet<>();
-
- boolean configurationInit = false;
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
- if (effectiveStatement instanceof AugmentationSchema) {
- AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentationsInit.add(augmentationSchema);
- }
- if (!configurationInit && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
- ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
- this.configuration = configStmt.argument();
- configurationInit = true;
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
- }
-
- @Override
- public boolean isConfiguration() {
- return configuration;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraints;
- }
-
- @Override
- public Set<AugmentationSchema> getAvailableAugmentations() {
- return augmentations;
- }
-
- @Override
- public boolean isPresenceContainer() {
- return presence;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
InputEffectiveStatementImpl other = (InputEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
- return "RPC input " + qname.getLocalName();
+ return "RPC input " + getQName().getLocalName();
}
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class KeyEffectiveStatementImpl extends EffectiveStatementBase<Collection<SchemaNodeIdentifier>, KeyStatement> {
+public final class KeyEffectiveStatementImpl extends EffectiveStatementBase<Collection<SchemaNodeIdentifier>,
+ KeyStatement> {
public KeyEffectiveStatementImpl(final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class LeafEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, LeafStatement> implements
+public final class LeafEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode<LeafStatement> implements
LeafSchemaNode, DerivableSchemaNode {
- private final QName qname;
- private final SchemaPath path;
-
- // FIXME: should be private
- boolean augmenting;
- private boolean addedByUses;
- private LeafSchemaNode original;
- private boolean configuration = true;
- private final ConstraintDefinition constraintsDef;
- private TypeDefinition<?> type;
- private String defaultStr;
- private String unitsStr;
-
- private ImmutableList<UnknownSchemaNode> unknownNodes;
+ private final LeafSchemaNode original;
+ private final TypeDefinition<?> type;
+ private final String defaultStr;
+ private final String unitsStr;
public LeafEffectiveStatementImpl(final StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
super(ctx);
- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
- this.constraintsDef = new EffectiveConstraintDefinitionImpl(this);
-
- initSubstatementCollections(ctx);
- initCopyType(ctx);
- }
-
- private void initCopyType(
- final StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
- }
- if (ctx.getOriginalCtx() != null) {
- original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
- }
+ this.original = ctx.getOriginalCtx() == null ? null : (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
- private void initSubstatementCollections(
- final StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+ DefaultEffectiveStatementImpl defaultStmt = firstEffective(DefaultEffectiveStatementImpl.class);
+ this.defaultStr = (defaultStmt == null) ? null : defaultStmt.argument();
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
- boolean configurationInit = false;
- boolean defaultInit = false;
- boolean unitsInit = false;
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
- }
- if (effectiveStatement instanceof TypeDefinition) {
- type = TypeUtils.getTypeFromEffectiveStatement(effectiveStatement);
- }
- if (!configurationInit && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
- ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
- this.configuration = configStmt.argument();
- configurationInit = true;
- }
- if (!defaultInit && effectiveStatement instanceof DefaultEffectiveStatementImpl) {
- DefaultEffectiveStatementImpl defStmt = (DefaultEffectiveStatementImpl) effectiveStatement;
- this.defaultStr = defStmt.argument();
- defaultInit = true;
- }
- if (!unitsInit && effectiveStatement instanceof UnitsEffectiveStatementImpl) {
- UnitsEffectiveStatementImpl unitStmt = (UnitsEffectiveStatementImpl) effectiveStatement;
- this.unitsStr = unitStmt.argument();
- unitsInit = true;
- }
- }
+ UnitsEffectiveStatementImpl unitsStmt = firstEffective(UnitsEffectiveStatementImpl.class);
+ this.unitsStr = (unitsStmt == null) ? null : unitsStmt.argument();
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
+ EffectiveStatement<?,?> typeEffectiveSubstatement = firstEffectiveSubstatementOfType(TypeDefinition.class);
+ this.type = TypeUtils.getTypeFromEffectiveStatement(typeEffectiveSubstatement);
}
@Override
return Optional.fromNullable(original);
}
- @Override
- public boolean isConfiguration() {
- return configuration;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraintsDef;
- }
-
@Override
public TypeDefinition<?> getType() {
return type;
}
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
@Override
public String getDefault() {
return defaultStr;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
LeafEffectiveStatementImpl other = (LeafEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(LeafEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
- sb.append("qname=").append(qname);
- sb.append(", path=").append(path);
+ sb.append("qname=").append(getQName());
+ sb.append(", path=").append(getPath());
sb.append("]");
return sb.toString();
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafListStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, LeafListStatement> implements
+public final class LeafListEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode<LeafListStatement> implements
LeafListSchemaNode, DerivableSchemaNode {
- private final QName qname;
- private final SchemaPath path;
- // FIXME: should be private
- boolean augmenting;
- private boolean addedByUses;
- private LeafListSchemaNode original;
- private boolean configuration = true;
- private final ConstraintDefinition constraintsDef;
- private TypeDefinition<?> type;
- private boolean userOrdered;
-
- private ImmutableList<UnknownSchemaNode> unknownNodes;
+ private final LeafListSchemaNode original;
+ private final TypeDefinition<?> type;
+ private final boolean userOrdered;
+ private static final String ORDER_BY_USER_KEYWORD = "user";
public LeafListEffectiveStatementImpl(
final StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
super(ctx);
- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
- this.constraintsDef = new EffectiveConstraintDefinitionImpl(this);
-
- // :TODO init TypeDefinition
-
- initSubstatementCollections();
- initCopyType(ctx);
- }
-
- private void initCopyType(
- final StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
+ this.original = ctx.getOriginalCtx() == null ? null : (LeafListSchemaNode) ctx.getOriginalCtx()
+ .buildEffective();
+
+ OrderedByEffectiveStatementImpl orderedByStmt = firstEffective(OrderedByEffectiveStatementImpl.class);
+ if (orderedByStmt != null && orderedByStmt.argument().equals(ORDER_BY_USER_KEYWORD)) {
+ this.userOrdered = true;
+ } else {
+ this.userOrdered = false;
}
- if (ctx.getOriginalCtx() != null) {
- original = (LeafListSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
- }
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
- boolean configurationInit = false;
- boolean userOrderedInit = false;
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
- }
- if (effectiveStatement instanceof TypeDefinition) {
- type = TypeUtils.getTypeFromEffectiveStatement(effectiveStatement);
- }
- if (!configurationInit && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
- ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
- this.configuration = configStmt.argument();
- configurationInit = true;
- }
- if (!userOrderedInit && effectiveStatement instanceof OrderedByEffectiveStatementImpl) {
- OrderedByEffectiveStatementImpl orderedByStmt = (OrderedByEffectiveStatementImpl) effectiveStatement;
- this.userOrdered = orderedByStmt.argument().equals("user") ? true : false;
- userOrderedInit = true;
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
+ EffectiveStatement<?, ?> typeEffectiveSubstatement = firstEffectiveSubstatementOfType(TypeDefinition.class);
+ this.type = TypeUtils.getTypeFromEffectiveStatement(typeEffectiveSubstatement);
}
@Override
return Optional.fromNullable(original);
}
- @Override
- public boolean isConfiguration() {
- return configuration;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraintsDef;
- }
-
@Override
public TypeDefinition<?> getType() {
return type;
return userOrdered;
}
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
LeafListEffectiveStatementImpl other = (LeafListEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(LeafListEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
- sb.append(qname);
+ sb.append(getQName());
sb.append("]");
return sb.toString();
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ListStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
-public class ListEffectiveStatementImpl extends AbstractEffectiveDocumentedDataNodeContainer<QName, ListStatement>
- implements ListSchemaNode, DerivableSchemaNode {
- private final QName qname;
- private final SchemaPath path;
-
- // FIXME: should be private
- boolean augmenting;
- private boolean addedByUses;
- private ListSchemaNode original;
- private boolean configuration = true;
- private final ConstraintDefinition constraints;
- private boolean userOrdered;
-
- private ImmutableList<QName> keyDefinition;
- private ImmutableSet<AugmentationSchema> augmentations;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
-
- public ListEffectiveStatementImpl(final StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
- super(ctx);
- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
- this.constraints = new EffectiveConstraintDefinitionImpl(this);
- initSubstatementCollectionsAndFields();
- initCopyType(ctx);
+public final class ListEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer<ListStatement> implements
+ ListSchemaNode, DerivableSchemaNode {
- // should be after initSubstatementCollectionsAndFields()
- initKeyDefinition(ctx);
- }
+ private final boolean userOrdered;
+ private final List<QName> keyDefinition;
+ private static final String ORDER_BY_USER_KEYWORD = "user";
+ private final ListSchemaNode original;
- private void initCopyType(final StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
+ public ListEffectiveStatementImpl(
+ final StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
+ super(ctx);
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
+ this.original = ctx.getOriginalCtx() == null ? null : (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
+ OrderedByEffectiveStatementImpl orderedByStmt = firstEffective(OrderedByEffectiveStatementImpl.class);
+ if (orderedByStmt != null && orderedByStmt.argument().equals(ORDER_BY_USER_KEYWORD)) {
+ this.userOrdered = true;
+ } else {
+ this.userOrdered = false;
}
- if (ctx.getOriginalCtx() != null) {
- original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
- }
- private void initKeyDefinition(final StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
+ // initKeyDefinition
List<QName> keyDefinitionInit = new LinkedList<>();
KeyEffectiveStatementImpl keyEffectiveSubstatement = firstEffective(KeyEffectiveStatementImpl.class);
if (!possibleLeafQNamesForKey.contains(keyQName)) {
throw new IllegalArgumentException(String.format("Key '%s' misses node '%s' in list '%s', file %s",
- keyEffectiveSubstatement.getDeclared().rawArgument(), keyQName.getLocalName(), ctx.getStatementArgument(),
- ctx.getStatementSourceReference()));
+ keyEffectiveSubstatement.getDeclared().rawArgument(), keyQName.getLocalName(),
+ ctx.getStatementArgument(), ctx.getStatementSourceReference()));
}
keyDefinitionInit.add(keyQName);
this.keyDefinition = ImmutableList.copyOf(keyDefinitionInit);
}
- private void initSubstatementCollectionsAndFields() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
- Set<AugmentationSchema> augmentationsInit = new HashSet<>();
-
- boolean configurationInit = false;
- boolean userOrderedInit = false;
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
- if (effectiveStatement instanceof AugmentationSchema) {
- AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentationsInit.add(augmentationSchema);
- }
- if (!configurationInit && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
- ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
- this.configuration = configStmt.argument();
- configurationInit = true;
- }
- if (!userOrderedInit && effectiveStatement instanceof OrderedByEffectiveStatementImpl) {
- OrderedByEffectiveStatementImpl orderedByStmt = (OrderedByEffectiveStatementImpl) effectiveStatement;
- this.userOrdered = orderedByStmt.argument().equals("user") ? true : false;
- userOrderedInit = true;
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public List<QName> getKeyDefinition() {
- return keyDefinition;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
- }
-
@Override
public Optional<ListSchemaNode> getOriginal() {
return Optional.fromNullable(original);
}
@Override
- public boolean isConfiguration() {
- return configuration;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraints;
- }
-
- @Override
- public Set<AugmentationSchema> getAvailableAugmentations() {
- return augmentations;
+ public List<QName> getKeyDefinition() {
+ return keyDefinition;
}
@Override
return userOrdered;
}
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
final ListEffectiveStatementImpl other = (ListEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
- return "list " + qname.getLocalName();
+ return "list " + getQName().getLocalName();
}
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class MandatoryEffectiveStatementImpl extends EffectiveStatementBase<Boolean, MandatoryStatement> {
+public final class MandatoryEffectiveStatementImpl extends EffectiveStatementBase<Boolean, MandatoryStatement> {
public MandatoryEffectiveStatementImpl(final StmtContext<Boolean, MandatoryStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.MaxElementsStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class MaxElementsEffectiveStatementImpl extends EffectiveStatementBase<String, MaxElementsStatement> {
+public final class MaxElementsEffectiveStatementImpl extends EffectiveStatementBase<String, MaxElementsStatement> {
public MaxElementsEffectiveStatementImpl(final StmtContext<String, MaxElementsStatement, ?> ctx) {
super(ctx);
-
}
}
\ No newline at end of file
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.MinElementsStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class MinElementsEffectiveStatementImpl extends EffectiveStatementBase<Integer, MinElementsStatement> {
+public final class MinElementsEffectiveStatementImpl extends EffectiveStatementBase<Integer, MinElementsStatement> {
public MinElementsEffectiveStatementImpl(final StmtContext<Integer, MinElementsStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import java.net.URI;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
import java.util.Objects;
-import java.util.Set;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Deviation;
-import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
-import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
-import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
-public class ModuleEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<String, ModuleStatement> implements
- Module, Immutable {
+public final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleStatement> {
private final QNameModule qNameModule;
- private final String name;
- private final String sourcePath;
- private String prefix;
- private String yangVersion;
- private String organization;
- private String contact;
- private ImmutableSet<ModuleImport> imports;
- private ImmutableSet<Module> submodules;
- private ImmutableSet<FeatureDefinition> features;
- private ImmutableSet<NotificationDefinition> notifications;
- private ImmutableSet<AugmentationSchema> augmentations;
- private ImmutableSet<RpcDefinition> rpcs;
- private ImmutableSet<Deviation> deviations;
- private ImmutableList<ExtensionDefinition> extensionNodes;
- private ImmutableSet<IdentitySchemaNode> identities;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
- private ImmutableList<EffectiveStatement<?, ?>> substatementsOfSubmodules;
-
- private ImmutableMap<QName, DataSchemaNode> childNodes;
- private ImmutableSet<GroupingDefinition> groupings;
- private ImmutableSet<UsesNode> uses;
- private ImmutableSet<TypeDefinition<?>> typeDefinitions;
- private ImmutableSet<DataSchemaNode> publicChildNodes;
public ModuleEffectiveStatementImpl(
final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
super(ctx);
- name = argument();
- QNameModule qNameModuleInit = ctx.getFromNamespace( ModuleCtxToModuleQName.class, ctx);
- qNameModule = qNameModuleInit.getRevision() == null
- ? QNameModule.create(qNameModuleInit.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV)
- : qNameModuleInit;
-
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
- prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) {
- yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) {
- organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ContactEffectiveStatementImpl) {
- contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument();
- }
- }
-
- if (yangVersion == null) {
- yangVersion = "1";
- }
- if(ctx.getStatementSourceReference() instanceof DeclarationInTextSource) {
- sourcePath = ((DeclarationInTextSource) ctx.getStatementSourceReference()).getSourceName();
- } else {
- sourcePath = null;
- }
-
-
- initSubmodules(ctx);
- initSubstatementCollections(ctx);
- }
-
- private void initSubmodules(
- final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
- Map<String, ModuleIdentifier> includedSubmodulesMap = ctx
- .getAllFromCurrentStmtCtxNamespace(IncludedSubmoduleNameToIdentifier.class);
-
- if (includedSubmodulesMap == null || includedSubmodulesMap.isEmpty()) {
- this.submodules = ImmutableSet.of();
- this.substatementsOfSubmodules = ImmutableList.of();
- return;
- }
-
- Collection<ModuleIdentifier> includedSubmodules = includedSubmodulesMap.values();
-
- Set<Module> submodulesInit = new HashSet<>();
- List<EffectiveStatement<?, ?>> substatementsOfSubmodulesInit = new LinkedList<>();
- for (ModuleIdentifier submoduleIdentifier : includedSubmodules) {
- @SuppressWarnings("unchecked")
- Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> submoduleCtx =
- (Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>)
- ctx.getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
- SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx
- .buildEffective();
- submodulesInit.add(submodule);
- substatementsOfSubmodulesInit.addAll(submodule.effectiveSubstatements());
- }
-
- this.submodules = ImmutableSet.copyOf(submodulesInit);
- this.substatementsOfSubmodules = ImmutableList
- .copyOf(substatementsOfSubmodulesInit);
- }
-
- private void initSubstatementCollections(
- final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
- List<EffectiveStatement<?, ?>> effectiveSubstatements = new LinkedList<>();
-
- effectiveSubstatements.addAll(effectiveSubstatements());
- effectiveSubstatements.addAll(substatementsOfSubmodules);
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
- Set<AugmentationSchema> augmentationsInit = new HashSet<>();
- Set<ModuleImport> importsInit = new HashSet<>();
- Set<NotificationDefinition> notificationsInit = new HashSet<>();
- Set<RpcDefinition> rpcsInit = new HashSet<>();
- Set<Deviation> deviationsInit = new HashSet<>();
- Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
- Set<FeatureDefinition> featuresInit = new HashSet<>();
- List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
-
- Map<QName, DataSchemaNode> mutableChildNodes = new LinkedHashMap<>();
- Set<GroupingDefinition> mutableGroupings = new HashSet<>();
- Set<UsesNode> mutableUses = new HashSet<>();
- Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
- Set<DataSchemaNode> mutablePublicChildNodes = new LinkedHashSet<>();
-
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
- }
- if (effectiveStatement instanceof AugmentationSchema) {
- augmentationsInit.add((AugmentationSchema) effectiveStatement);
- }
- if (effectiveStatement instanceof ModuleImport) {
- importsInit.add((ModuleImport) effectiveStatement);
- }
- if (effectiveStatement instanceof NotificationDefinition) {
- notificationsInit.add((NotificationDefinition) effectiveStatement);
- }
- if (effectiveStatement instanceof RpcDefinition) {
- rpcsInit.add((RpcDefinition) effectiveStatement);
- }
- if (effectiveStatement instanceof Deviation) {
- deviationsInit.add((Deviation) effectiveStatement);
- }
- if (effectiveStatement instanceof IdentitySchemaNode) {
- identitiesInit.add((IdentitySchemaNode) effectiveStatement);
- }
- if (effectiveStatement instanceof FeatureDefinition) {
- featuresInit.add((FeatureDefinition) effectiveStatement);
- }
- if (effectiveStatement instanceof ExtensionDefinition) {
- extensionNodesInit.add((ExtensionDefinition) effectiveStatement);
- }
- if (effectiveStatement instanceof DataSchemaNode) {
- DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
- if (!mutableChildNodes.containsKey(dataSchemaNode.getQName())) {
- mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
- mutablePublicChildNodes.add(dataSchemaNode);
- } else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
- }
- }
- if (effectiveStatement instanceof UsesNode) {
- UsesNode usesNode = (UsesNode) effectiveStatement;
- if (!mutableUses.contains(usesNode)) {
- mutableUses.add(usesNode);
- } else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
- }
- }
- if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
- TypeDefEffectiveStatementImpl typeDef = (TypeDefEffectiveStatementImpl) effectiveStatement;
- ExtendedType extendedType = typeDef.buildType();
- if (!mutableTypeDefinitions.contains(extendedType)) {
- mutableTypeDefinitions.add(extendedType);
- } else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
- }
- }
- if (effectiveStatement instanceof GroupingDefinition) {
- GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
- if (!mutableGroupings.contains(grp)) {
- mutableGroupings.add(grp);
- } else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
- }
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit, ctx));
- this.notifications = ImmutableSet.copyOf(notificationsInit);
- this.rpcs = ImmutableSet.copyOf(rpcsInit);
- this.deviations = ImmutableSet.copyOf(deviationsInit);
- this.identities = ImmutableSet.copyOf(identitiesInit);
- this.features = ImmutableSet.copyOf(featuresInit);
- this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
-
- this.childNodes = ImmutableMap.copyOf(mutableChildNodes);
- this.groupings = ImmutableSet.copyOf(mutableGroupings);
- this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes);
- this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
- this.uses = ImmutableSet.copyOf(mutableUses);
- }
-
- private static Set<ModuleImport> resolveModuleImports(final Set<ModuleImport> importsInit,
- final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
- Set<ModuleImport> resolvedModuleImports = new LinkedHashSet<>();
- for (ModuleImport moduleImport : importsInit) {
- if (moduleImport.getRevision().equals(
- SimpleDateFormatUtil.DEFAULT_DATE_IMP)) {
- QNameModule impModuleQName = Utils.getModuleQNameByPrefix(ctx,
- moduleImport.getPrefix());
- if (!impModuleQName.getRevision().equals(
- SimpleDateFormatUtil.DEFAULT_DATE_REV)) {
- ModuleImport resolvedModuleImport = new ModuleImportImpl(
- moduleImport.getModuleName(),
- impModuleQName.getRevision(),
- moduleImport.getPrefix());
- resolvedModuleImports.add(resolvedModuleImport);
- }
- } else {
- resolvedModuleImports.add(moduleImport);
- }
- }
- return resolvedModuleImports;
- }
-
- @Override
- public String getModuleSourcePath() {
- return sourcePath;
- }
-
- @Override
- public URI getNamespace() {
- return qNameModule.getNamespace();
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Date getRevision() {
- return qNameModule.getRevision();
+ QNameModule qNameModuleInit = ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx);
+ this.qNameModule = qNameModuleInit.getRevision() == null ? QNameModule.create(qNameModuleInit.getNamespace(),
+ SimpleDateFormatUtil.DEFAULT_DATE_REV) : qNameModuleInit;
}
@Override
- public String getPrefix() {
- return prefix;
- }
-
- @Override
- public String getYangVersion() {
- return yangVersion;
- }
-
- @Override
- public String getOrganization() {
- return organization;
- }
-
- @Override
- public String getContact() {
- return contact;
- }
-
- @Override
- public Set<ModuleImport> getImports() {
- return imports;
- }
-
- @Override
- public Set<Module> getSubmodules() {
- return submodules;
- }
-
- @Override
- public Set<FeatureDefinition> getFeatures() {
- return features;
- }
-
- @Override
- public Set<NotificationDefinition> getNotifications() {
- return notifications;
- }
-
- @Override
- public Set<AugmentationSchema> getAugmentations() {
- return augmentations;
- }
-
- @Override
- public Set<RpcDefinition> getRpcs() {
- return rpcs;
- }
-
- @Override
- public Set<Deviation> getDeviations() {
- return deviations;
- }
-
- @Override
- public List<ExtensionDefinition> getExtensionSchemaNodes() {
- return extensionNodes;
- }
-
- @Override
- public Set<IdentitySchemaNode> getIdentities() {
- return identities;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
- @Override
- public final Set<TypeDefinition<?>> getTypeDefinitions() {
- return typeDefinitions;
- }
-
- @Override
- public final Set<DataSchemaNode> getChildNodes() {
- return publicChildNodes;
- }
-
- @Override
- public final Set<GroupingDefinition> getGroupings() {
- return groupings;
- }
-
- @Override
- public final DataSchemaNode getDataChildByName(final QName name) {
- // Child nodes are keyed by their container name, so we can do a direct
- // lookup
- return childNodes.get(name);
- }
-
- @Override
- public final DataSchemaNode getDataChildByName(final String name) {
- for (DataSchemaNode node : childNodes.values()) {
- if (node.getQName().getLocalName().equals(name)) {
- return node;
- }
- }
- return null;
- }
-
- @Override
- public Set<UsesNode> getUses() {
- return uses;
- }
-
- @Override
- public String getSource() {
- return null;
+ public QNameModule getQNameModule() {
+ return qNameModule;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(name);
- result = prime * result + Objects.hashCode(yangVersion);
- result = prime * result + qNameModule.hashCode();
+ result = prime * result + Objects.hashCode(getName());
+ result = prime * result + Objects.hashCode(getYangVersion());
+ result = prime * result + Objects.hashCode(qNameModule);
return result;
}
return false;
}
ModuleEffectiveStatementImpl other = (ModuleEffectiveStatementImpl) obj;
- if (!Objects.equals(name, other.name)) {
+ if (!Objects.equals(getName(), other.getName())) {
return false;
}
if (!qNameModule.equals(other.qNameModule)) {
return false;
}
- if (!Objects.equals(yangVersion, other.yangVersion)) {
+ if (!Objects.equals(getYangVersion(), other.getYangVersion())) {
return false;
}
return true;
}
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(ModuleEffectiveStatementImpl.class.getSimpleName());
- sb.append("[");
- sb.append("name=").append(name);
- sb.append(", namespace=").append(getNamespace());
- sb.append(", revision=").append(getRevision());
- sb.append(", prefix=").append(prefix);
- sb.append(", yangVersion=").append(yangVersion);
- sb.append("]");
- return sb.toString();
- }
-
- @Override
- public QNameModule getQNameModule() {
- return qNameModule;
- }
-
}
import java.util.Objects;
import org.opendaylight.yangtools.yang.model.api.MustDefinition;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
MustDefinition {
private final RevisionAwareXPath xPath;
- private String description;
- private String errorAppTag;
- private String errorMessage;
- private String reference;
+ private final String description;
+ private final String errorAppTag;
+ private final String errorMessage;
+ private final String reference;
public MustEffectiveStatementImpl(final StmtContext<RevisionAwareXPath, MustStatement, ?> ctx) {
super(ctx);
+ this.xPath = ctx.getStatementArgument();
- initFields();
+ DescriptionEffectiveStatementImpl descriptionStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
+ this.description = (descriptionStmt == null) ? null : descriptionStmt.argument();
- xPath = ctx.getStatementArgument();
- }
+ ErrorAppTagEffectiveStatementImpl errorAppTagStmt = firstEffective(ErrorAppTagEffectiveStatementImpl.class);
+ this.errorAppTag = (errorAppTagStmt == null) ? null : errorAppTagStmt.argument();
- private void initFields() {
-
- for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
-
- if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
- description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ErrorAppTagEffectiveStatementImpl) {
- errorAppTag = ((ErrorAppTagEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ErrorMessageEffectiveStatementImpl) {
- errorMessage = ((ErrorMessageEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
- reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
- }
- }
+ ErrorMessageEffectiveStatementImpl errorMessageStmt = firstEffective(ErrorMessageEffectiveStatementImpl.class);
+ this.errorMessage = (errorMessageStmt == null) ? null : errorMessageStmt.argument();
+
+ ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
+ this.reference = (referenceStmt == null) ? null : referenceStmt.argument();
}
@Override
if (!Objects.equals(description, other.description)) {
return false;
}
- if (!Objects.equals(reference,other.reference)) {
+ if (!Objects.equals(reference, other.reference)) {
return false;
}
return true;
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class NamespaceEffectiveStatementImpl extends EffectiveStatementBase<URI, NamespaceStatement> {
+public final class NamespaceEffectiveStatementImpl extends EffectiveStatementBase<URI, NamespaceStatement> {
public NamespaceEffectiveStatementImpl(final StmtContext<URI, NamespaceStatement, ?> ctx) {
super(ctx);
}
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class NotificationEffectiveStatementImpl
- extends AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement>
- implements NotificationDefinition {
+public class NotificationEffectiveStatementImpl extends
+ AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement> implements NotificationDefinition {
private final QName qname;
private final SchemaPath path;
- private Set<AugmentationSchema> augmentations;
- private List<UnknownSchemaNode> unknownNodes;
+ private final Set<AugmentationSchema> augmentations;
+ private final List<UnknownSchemaNode> unknownNodes;
public NotificationEffectiveStatementImpl(
final StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
this.qname = ctx.getStatementArgument();
this.path = Utils.getSchemaPath(ctx);
- initSubstatementCollections();
- }
-
- private void initSubstatementCollections() {
+ // initSubstatementCollections
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
Set<AugmentationSchema> augmentationsInit = new HashSet<>();
-
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
augmentationsInit.add(augmentationSchema);
}
}
-
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.augmentations = ImmutableSet.copyOf(augmentationsInit);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.OrderedByStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class OrderedByEffectiveStatementImpl extends EffectiveStatementBase<String, OrderedByStatement> {
+public final class OrderedByEffectiveStatementImpl extends EffectiveStatementBase<String, OrderedByStatement> {
public OrderedByEffectiveStatementImpl(final StmtContext<String, OrderedByStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.OrganizationStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class OrganizationEffectiveStatementImpl extends EffectiveStatementBase<String, OrganizationStatement> {
+public final class OrganizationEffectiveStatementImpl extends EffectiveStatementBase<String, OrganizationStatement> {
public OrganizationEffectiveStatementImpl(final StmtContext<String, OrganizationStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
-import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class OutputEffectiveStatementImpl extends AbstractEffectiveDocumentedDataNodeContainer<QName, OutputStatement>
- implements ContainerSchemaNode {
-
- private final QName qname;
- private final SchemaPath path;
- private final boolean presence;
-
- private boolean augmenting;
- private boolean addedByUses;
- private boolean configuration = true;
- private ContainerSchemaNode original;
- private final ConstraintDefinition constraints;
-
- private Set<AugmentationSchema> augmentations;
- private List<UnknownSchemaNode> unknownNodes;
+public final class OutputEffectiveStatementImpl extends AbstractEffectiveContainerSchemaNode<OutputStatement> {
public OutputEffectiveStatementImpl(
final StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
super(ctx);
-
- qname = ctx.getStatementArgument();
- path = Utils.getSchemaPath(ctx);
- presence = firstEffective(PresenceEffectiveStatementImpl.class) != null;
- this.constraints = new EffectiveConstraintDefinitionImpl(this);
-
- initSubstatementCollections();
- initCopyType(ctx);
- }
-
- private void initCopyType(
- final StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
- }
- if (ctx.getOriginalCtx() != null) {
- original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
- }
-
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
- Set<AugmentationSchema> augmentationsInit = new HashSet<>();
-
- boolean configurationInit = false;
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
- if (effectiveStatement instanceof AugmentationSchema) {
- AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentationsInit.add(augmentationSchema);
- }
- if (!configurationInit && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
- ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
- this.configuration = configStmt.argument();
- configurationInit = true;
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public boolean isAugmenting() {
- return augmenting;
- }
-
- @Override
- public boolean isAddedByUses() {
- return addedByUses;
- }
-
- @Override
- public boolean isConfiguration() {
- return configuration;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- return constraints;
- }
-
- @Override
- public Set<AugmentationSchema> getAvailableAugmentations() {
- return augmentations;
- }
-
- @Override
- public boolean isPresenceContainer() {
- return presence;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
OutputEffectiveStatementImpl other = (OutputEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
public String toString() {
- return "RPC Output " + qname.getLocalName();
+ return "RPC Output " + getQName().getLocalName();
}
}
import org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class PathEffectiveStatementImpl extends EffectiveStatementBase<RevisionAwareXPath, PathStatement> {
+public final class PathEffectiveStatementImpl extends EffectiveStatementBase<RevisionAwareXPath, PathStatement> {
public PathEffectiveStatementImpl(final StmtContext<RevisionAwareXPath, PathStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class PositionEffectiveStatementImpl extends EffectiveStatementBase<Long, PositionStatement> {
+public final class PositionEffectiveStatementImpl extends EffectiveStatementBase<Long, PositionStatement> {
public PositionEffectiveStatementImpl(final StmtContext<Long, PositionStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class PrefixEffectiveStatementImpl extends EffectiveStatementBase<String, PrefixStatement> {
+public final class PrefixEffectiveStatementImpl extends EffectiveStatementBase<String, PrefixStatement> {
public PrefixEffectiveStatementImpl(final StmtContext<String, PrefixStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class PresenceEffectiveStatementImpl extends EffectiveStatementBase<String, PresenceStatement> {
+public final class PresenceEffectiveStatementImpl extends EffectiveStatementBase<String, PresenceStatement> {
public PresenceEffectiveStatementImpl(final StmtContext<String, PresenceStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class ReferenceEffectiveStatementImpl extends EffectiveStatementBase<String, ReferenceStatement> {
+public final class ReferenceEffectiveStatementImpl extends EffectiveStatementBase<String, ReferenceStatement> {
public ReferenceEffectiveStatementImpl(final StmtContext<String, ReferenceStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class RefineEffectiveStatementImpl extends
- AbstractEffectiveDocumentedNode<SchemaNodeIdentifier, RefineStatement>
- implements SchemaNode {
+public final class RefineEffectiveStatementImpl extends
+ AbstractEffectiveDocumentedNode<SchemaNodeIdentifier, RefineStatement> implements SchemaNode {
private final QName qname;
private final SchemaPath path;
- private List<UnknownSchemaNode> unknownNodes;
+ private final List<UnknownSchemaNode> unknownNodes;
private final SchemaNode refineTargetNode;
- public RefineEffectiveStatementImpl(
- final StmtContext<SchemaNodeIdentifier, RefineStatement, ?> ctx) {
+ public RefineEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, RefineStatement, ?> ctx) {
super(ctx);
-
qname = ctx.getStatementArgument().getLastComponent();
path = Utils.getSchemaPath(ctx);
refineTargetNode = (SchemaNode) ctx.getEffectOfStatement().iterator().next().buildEffective();
- initSubstatementCollectionsAndFields();
- }
-
- public SchemaNode getRefineTargetNode() {
- return refineTargetNode;
- }
-
- private void initSubstatementCollectionsAndFields() {
+ // initSubstatementCollectionsAndFields
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
for (EffectiveStatement<?, ?> effectiveSubstatement : effectiveSubstatements) {
if (effectiveSubstatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveSubstatement;
unknownNodesInit.add(unknownNode);
}
}
-
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
}
+ public SchemaNode getRefineTargetNode() {
+ return refineTargetNode;
+ }
+
@Override
public QName getQName() {
return qname;
import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class RequireInstanceEffectiveStatementImpl extends EffectiveStatementBase<Boolean, RequireInstanceStatement> {
+public final class RequireInstanceEffectiveStatementImpl extends EffectiveStatementBase<Boolean,
+ RequireInstanceStatement> {
public RequireInstanceEffectiveStatementImpl(final StmtContext<Boolean, RequireInstanceStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class RevisionDateEffectiveStatementImpl extends EffectiveStatementBase<Date, RevisionDateStatement> {
+public final class RevisionDateEffectiveStatementImpl extends EffectiveStatementBase<Date, RevisionDateStatement> {
public RevisionDateEffectiveStatementImpl(final StmtContext<Date, RevisionDateStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class RevisionEffectiveStatementImpl extends EffectiveStatementBase<Date, RevisionStatement> {
+public final class RevisionEffectiveStatementImpl extends EffectiveStatementBase<Date, RevisionStatement> {
private final String reference;
private final String description;
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class RpcEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, RpcStatement> implements RpcDefinition {
- private final QName qname;
- private final SchemaPath path;
-
- private ContainerSchemaNode input;
- private ContainerSchemaNode output;
-
- private Set<TypeDefinition<?>> typeDefinitions;
- private Set<GroupingDefinition> groupings;
- private List<UnknownSchemaNode> unknownNodes;
+public class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcStatement> implements RpcDefinition {
+ private final ContainerSchemaNode input;
+ private final ContainerSchemaNode output;
+ private final Set<TypeDefinition<?>> typeDefinitions;
+ private final Set<GroupingDefinition> groupings;
public RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> ctx) {
super(ctx);
- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
-
- initSubstatements();
- }
+ this.input = firstEffective(InputEffectiveStatementImpl.class);
+ this.output = firstEffective(OutputEffectiveStatementImpl.class);
- private void initSubstatements() {
+ // initSubstatements
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
Set<GroupingDefinition> groupingsInit = new HashSet<>();
Set<TypeDefinition<?>> typeDefinitionsInit = new HashSet<>();
-
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
- }
if (effectiveStatement instanceof GroupingDefinition) {
GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
groupingsInit.add(groupingDefinition);
TypeDefinition<?> typeDefinition = (TypeDefinition<?>) effectiveStatement;
typeDefinitionsInit.add(typeDefinition);
}
- if (this.input == null && effectiveStatement instanceof InputEffectiveStatementImpl) {
- this.input = (InputEffectiveStatementImpl) effectiveStatement;
- }
- if (this.output == null && effectiveStatement instanceof OutputEffectiveStatementImpl) {
- this.output = (OutputEffectiveStatementImpl) effectiveStatement;
- }
}
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.groupings = ImmutableSet.copyOf(groupingsInit);
this.typeDefinitions = ImmutableSet.copyOf(typeDefinitionsInit);
}
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
@Override
public ContainerSchemaNode getInput() {
return input;
}
- void setInput(final ContainerSchemaNode input) {
- this.input = input;
- }
-
@Override
public ContainerSchemaNode getOutput() {
return output;
}
- void setOutput(final ContainerSchemaNode output) {
- this.output = output;
- }
-
@Override
public Set<TypeDefinition<?>> getTypeDefinitions() {
return typeDefinitions;
return groupings;
}
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
- result = prime * result + Objects.hashCode(path);
+ result = prime * result + Objects.hashCode(getQName());
+ result = prime * result + Objects.hashCode(getPath());
return result;
}
return false;
}
final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
}
@Override
StringBuilder sb = new StringBuilder(RpcEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=");
- sb.append(qname);
+ sb.append(getQName());
sb.append(", path=");
- sb.append(path);
+ sb.append(getPath());
sb.append(", input=");
sb.append(input);
sb.append(", output=");
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class StatusEffectiveStatementImpl extends EffectiveStatementBase<Status, StatusStatement> {
+public final class StatusEffectiveStatementImpl extends EffectiveStatementBase<Status, StatusStatement> {
public StatusEffectiveStatementImpl(final StmtContext<Status, StatusStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import java.net.URI;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+
import java.util.Objects;
-import java.util.Set;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Deviation;
-import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
-import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
-import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class SubmoduleEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<String, SubmoduleStatement>
- implements Module, Immutable {
+public final class SubmoduleEffectiveStatementImpl extends AbstractEffectiveModule<SubmoduleStatement> {
private final QNameModule qNameModule;
- private final String name;
- private final String sourcePath;
- private String prefix;
- private String yangVersion;
- private String organization;
- private String contact;
- private ImmutableSet<ModuleImport> imports;
- private ImmutableSet<Module> submodules;
- private ImmutableSet<FeatureDefinition> features;
- private ImmutableSet<NotificationDefinition> notifications;
- private ImmutableSet<AugmentationSchema> augmentations;
- private ImmutableSet<RpcDefinition> rpcs;
- private ImmutableSet<Deviation> deviations;
- private ImmutableList<ExtensionDefinition> extensionNodes;
- private ImmutableSet<IdentitySchemaNode> identities;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
- private String source;
- private ImmutableList<EffectiveStatement<?,?>> substatementsOfSubmodules;
-
- private ImmutableMap<QName, DataSchemaNode> childNodes;
- private ImmutableSet<GroupingDefinition> groupings;
- private ImmutableSet<UsesNode> uses;
- private ImmutableSet<TypeDefinition<?>> typeDefinitions;
- private ImmutableSet<DataSchemaNode> publicChildNodes;
public SubmoduleEffectiveStatementImpl(
final StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
super(ctx);
- name = argument();
-
String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
- final QNameModule belongsToModuleQName = ctx.getFromNamespace(
- ModuleNameToModuleQName.class, belongsToModuleName);
+ final QNameModule belongsToModuleQName = ctx.getFromNamespace(ModuleNameToModuleQName.class,
+ belongsToModuleName);
RevisionEffectiveStatementImpl submoduleRevision = firstEffective(RevisionEffectiveStatementImpl.class);
- qNameModule = submoduleRevision == null
- ? QNameModule.create(belongsToModuleQName.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV)
- : QNameModule.create(belongsToModuleQName.getNamespace(), submoduleRevision.argument());
-
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
- prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) {
- yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) {
- organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ContactEffectiveStatementImpl) {
- contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument();
- }
- }
-
- //:TODO init source
-// source = ctx.getStatementSource().name();
- sourcePath = ((DeclarationInTextSource) ctx.getStatementSourceReference()).getSourceName();
-
- initSubmodules(ctx);
- initSubstatementCollections(ctx);
- }
-
- private void initSubmodules(
- final StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
- Map<String, ModuleIdentifier> includedSubmodulesMap = ctx
- .getAllFromCurrentStmtCtxNamespace(IncludedSubmoduleNameToIdentifier.class);
-
- if (includedSubmodulesMap == null || includedSubmodulesMap.isEmpty()) {
- this.submodules = ImmutableSet.of();
- this.substatementsOfSubmodules = ImmutableList.of();
- return;
- }
-
- Collection<ModuleIdentifier> includedSubmodules = includedSubmodulesMap
- .values();
-
- Set<Module> submodulesInit = new HashSet<>();
- List<EffectiveStatement<?,?>> substatementsOfSubmodulesInit = new LinkedList<>();
- for (ModuleIdentifier submoduleIdentifier : includedSubmodules) {
- Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> submoduleCtx = (Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>) ctx
- .getFromNamespace(SubmoduleNamespace.class,
- submoduleIdentifier);
- SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx.buildEffective();
- submodulesInit.add(submodule);
- substatementsOfSubmodulesInit.addAll(submodule.effectiveSubstatements());
- }
-
- this.submodules = ImmutableSet.copyOf(submodulesInit);
- this.substatementsOfSubmodules = ImmutableList.copyOf(substatementsOfSubmodulesInit);
- }
-
- private void initSubstatementCollections(final StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
- List<EffectiveStatement<?, ?>> effectiveSubstatements = new LinkedList<>();
-
- effectiveSubstatements.addAll(effectiveSubstatements());
- effectiveSubstatements.addAll(this.substatementsOfSubmodules);
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
- Set<AugmentationSchema> augmentationsInit = new HashSet<>();
- Set<ModuleImport> importsInit = new HashSet<>();
- Set<NotificationDefinition> notificationsInit = new HashSet<>();
- Set<RpcDefinition> rpcsInit = new HashSet<>();
- Set<Deviation> deviationsInit = new HashSet<>();
- Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
- Set<FeatureDefinition> featuresInit = new HashSet<>();
- List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
-
- Map<QName, DataSchemaNode> mutableChildNodes = new LinkedHashMap<>();
- Set<GroupingDefinition> mutableGroupings = new HashSet<>();
- Set<UsesNode> mutableUses = new HashSet<>();
- Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
- Set<DataSchemaNode> mutablePublicChildNodes = new LinkedHashSet<>();
-
- //:TODO add validation also for other node types
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
- }
- if (effectiveStatement instanceof AugmentationSchema) {
- augmentationsInit.add((AugmentationSchema) effectiveStatement);
- }
- if (effectiveStatement instanceof ModuleImport) {
- importsInit.add((ModuleImport) effectiveStatement);
- }
- if (effectiveStatement instanceof NotificationDefinition) {
- notificationsInit
- .add((NotificationDefinition) effectiveStatement);
- }
- if (effectiveStatement instanceof RpcDefinition) {
- rpcsInit.add((RpcDefinition) effectiveStatement);
- }
- if (effectiveStatement instanceof Deviation) {
- deviationsInit.add((Deviation) effectiveStatement);
- }
- if (effectiveStatement instanceof IdentitySchemaNode) {
- identitiesInit.add((IdentitySchemaNode) effectiveStatement);
- }
- if (effectiveStatement instanceof FeatureDefinition) {
- featuresInit.add((FeatureDefinition) effectiveStatement);
- }
- if (effectiveStatement instanceof ExtensionDefinition) {
- extensionNodesInit
- .add((ExtensionDefinition) effectiveStatement);
- }
- if (effectiveStatement instanceof DataSchemaNode) {
- DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
- if (!mutableChildNodes.containsKey(dataSchemaNode.getQName())) {
- mutableChildNodes.put(dataSchemaNode.getQName(),
- dataSchemaNode);
- mutablePublicChildNodes.add(dataSchemaNode);
- } else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
- }
- }
- if (effectiveStatement instanceof UsesNode) {
- UsesNode usesNode = (UsesNode) effectiveStatement;
- if (!mutableUses.contains(usesNode)) {
- mutableUses.add(usesNode);
- } else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
- }
- }
- if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
- TypeDefEffectiveStatementImpl typeDef = (TypeDefEffectiveStatementImpl) effectiveStatement;
- ExtendedType extendedType = typeDef.buildType();
- if (!mutableTypeDefinitions.contains(extendedType)) {
- mutableTypeDefinitions.add(extendedType);
- } else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
- }
- }
- if (effectiveStatement instanceof GroupingDefinition) {
- GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
- if (!mutableGroupings.contains(grp)) {
- mutableGroupings.add(grp);
- } else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
- }
- }
- }
-
- this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
- this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit,ctx));
- this.notifications = ImmutableSet.copyOf(notificationsInit);
- this.rpcs = ImmutableSet.copyOf(rpcsInit);
- this.deviations = ImmutableSet.copyOf(deviationsInit);
- this.identities = ImmutableSet.copyOf(identitiesInit);
- this.features = ImmutableSet.copyOf(featuresInit);
- this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
-
- this.childNodes = ImmutableMap.copyOf(mutableChildNodes);
- this.groupings = ImmutableSet.copyOf(mutableGroupings);
- this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes);
- this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
- this.uses = ImmutableSet.copyOf(mutableUses);
- }
-
- private static Set<ModuleImport> resolveModuleImports(
- final Set<ModuleImport> importsInit,
- final StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
- Set<ModuleImport> resolvedModuleImports = new LinkedHashSet<>();
- for (ModuleImport moduleImport : importsInit) {
- if (moduleImport.getRevision().equals(
- SimpleDateFormatUtil.DEFAULT_DATE_IMP)) {
- QNameModule impModuleQName = Utils.getModuleQNameByPrefix(ctx,
- moduleImport.getPrefix());
- if (!impModuleQName.getRevision().equals(
- SimpleDateFormatUtil.DEFAULT_DATE_REV)) {
- ModuleImport resolvedModuleImport = new ModuleImportImpl(
- moduleImport.getModuleName(),
- impModuleQName.getRevision(),
- moduleImport.getPrefix());
- resolvedModuleImports.add(resolvedModuleImport);
- }
- } else {
- resolvedModuleImports.add(moduleImport);
- }
- }
- return resolvedModuleImports;
- }
-
- @Override
- public String getModuleSourcePath() {
- return sourcePath;
- }
-
- @Override
- public URI getNamespace() {
- return qNameModule.getNamespace();
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Date getRevision() {
- return qNameModule.getRevision();
- }
-
- @Override
- public String getPrefix() {
- return prefix;
- }
-
- @Override
- public String getYangVersion() {
- return yangVersion;
- }
-
- @Override
- public String getOrganization() {
- return organization;
- }
-
- @Override
- public String getContact() {
- return contact;
- }
-
- @Override
- public Set<ModuleImport> getImports() {
- return imports;
- }
-
- @Override
- public Set<Module> getSubmodules() {
- return submodules;
- }
-
- @Override
- public Set<FeatureDefinition> getFeatures() {
- return features;
- }
-
- @Override
- public Set<NotificationDefinition> getNotifications() {
- return notifications;
- }
-
- @Override
- public Set<AugmentationSchema> getAugmentations() {
- return augmentations;
- }
-
- @Override
- public Set<RpcDefinition> getRpcs() {
- return rpcs;
- }
-
- @Override
- public Set<Deviation> getDeviations() {
- return deviations;
- }
-
- @Override
- public List<ExtensionDefinition> getExtensionSchemaNodes() {
- return extensionNodes;
- }
-
- @Override
- public Set<IdentitySchemaNode> getIdentities() {
- return identities;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownNodes;
- }
-
- @Override
- public final Set<TypeDefinition<?>> getTypeDefinitions() {
- return typeDefinitions;
- }
-
- @Override
- public final Set<DataSchemaNode> getChildNodes() {
- return publicChildNodes;
- }
-
- @Override
- public final Set<GroupingDefinition> getGroupings() {
- return groupings;
- }
-
- @Override
- public final DataSchemaNode getDataChildByName(final QName name) {
- // Child nodes are keyed by their container name, so we can do a direct
- // lookup
- return childNodes.get(name);
- }
-
- @Override
- public final DataSchemaNode getDataChildByName(final String name) {
- for (DataSchemaNode node : childNodes.values()) {
- if (node.getQName().getLocalName().equals(name)) {
- return node;
- }
- }
- return null;
- }
-
- @Override
- public Set<UsesNode> getUses() {
- return uses;
+ this.qNameModule = submoduleRevision == null ? QNameModule.create(belongsToModuleQName.getNamespace(),
+ SimpleDateFormatUtil.DEFAULT_DATE_REV) : QNameModule.create(belongsToModuleQName.getNamespace(),
+ submoduleRevision.argument());
}
@Override
- public String getSource() {
- return source;
+ public QNameModule getQNameModule() {
+ return qNameModule;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(name);
- result = prime * result + Objects.hashCode(yangVersion);
- result = prime * result + qNameModule.hashCode();
+ result = prime * result + Objects.hashCode(getName());
+ result = prime * result + Objects.hashCode(getYangVersion());
+ result = prime * result + Objects.hashCode(qNameModule);
return result;
}
return false;
}
SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj;
- if (!Objects.equals(name, other.name)) {
+ if (!Objects.equals(getName(), other.getName())) {
return false;
}
if (!qNameModule.equals(other.qNameModule)) {
return false;
}
- if (!Objects.equals(yangVersion, other.yangVersion)) {
+ if (!Objects.equals(getYangVersion(), other.getYangVersion())) {
return false;
}
return true;
}
- @Override
- public String toString() {
-
- StringBuilder sb = new StringBuilder(SubmoduleEffectiveStatementImpl.class.getSimpleName());
- sb.append("[");
- sb.append("name=").append(name);
- sb.append(", namespace=").append(getNamespace());
- sb.append(", revision=").append(getRevision());
- sb.append(", prefix=").append(prefix);
- sb.append(", yangVersion=").append(yangVersion);
- sb.append("]");
- return sb.toString();
- }
-
- @Override
- public QNameModule getQNameModule() {
- return qNameModule;
- }
}
import java.util.Collections;
import java.util.List;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.RangeEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.TypeDefinitionEffectiveBuilder;
-public class TypeDefEffectiveStatementImpl extends EffectiveStatementBase<QName, TypedefStatement>
- implements TypeDefinition<TypeDefinition<?>>, TypeDefinitionEffectiveBuilder {
-
- private final QName qName;
- private final SchemaPath path;
-
+public final class TypeDefEffectiveStatementImpl extends AbstractEffectiveSchemaNode<TypedefStatement> implements
+ TypeDefinition<TypeDefinition<?>>, TypeDefinitionEffectiveBuilder {
private final TypeDefinition<?> baseType;
-
- private String defaultValue;
- private String units;
-
- private String description;
- private String reference;
-
- private Status status;
-
+ private final String defaultValue;
+ private final String units;
private final List<RangeConstraint> ranges;
private final List<LengthConstraint> lengths;
private final List<PatternConstraint> patterns;
private final Integer fractionDigits;
-
private ExtendedType extendedType = null;
public TypeDefEffectiveStatementImpl(final StmtContext<QName, TypedefStatement, ?> ctx) {
super(ctx);
-
- qName = ctx.getStatementArgument();
- path = Utils.getSchemaPath(ctx);
baseType = parseBaseTypeFromCtx(ctx);
- EffectiveStatementBase<?, ?> typeEffectiveStmt = firstSubstatementOfType(
- TypeDefinition.class, EffectiveStatementBase.class);
+ UnitsEffectiveStatementImpl unitsStmt = firstEffective(UnitsEffectiveStatementImpl.class);
+ this.units = (unitsStmt == null) ? null : unitsStmt.argument();
+ DefaultEffectiveStatementImpl defaultStmt = firstEffective(DefaultEffectiveStatementImpl.class);
+ this.defaultValue = (defaultStmt == null) ? null : defaultStmt.argument();
+ EffectiveStatementBase<?, ?> typeEffectiveStmt = firstSubstatementOfType(TypeDefinition.class,
+ EffectiveStatementBase.class);
ranges = initRanges(typeEffectiveStmt);
lengths = initLengths(typeEffectiveStmt);
patterns = initPatterns(typeEffectiveStmt);
- //due to compatibility problems with original yang parser
- //:FIXME try to find out better solution
- if (typeEffectiveStmt.argument().equals(TypeUtils.DECIMAL64)
- && ranges.isEmpty()) {
+ // due to compatibility problems with original yang parser
+ // :FIXME try to find out better solution
+ if (typeEffectiveStmt.argument().equals(TypeUtils.DECIMAL64) && ranges.isEmpty()) {
fractionDigits = null;
} else {
fractionDigits = initFractionDigits(typeEffectiveStmt);
}
-
- for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof DefaultEffectiveStatementImpl) {
- defaultValue = ((DefaultEffectiveStatementImpl) effectiveStatement)
- .argument();
- }
- if (effectiveStatement instanceof UnitsEffectiveStatementImpl) {
- units = ((UnitsEffectiveStatementImpl) effectiveStatement)
- .argument();
- }
- if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
- description = ((DescriptionEffectiveStatementImpl) effectiveStatement)
- .argument();
- }
- if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
- reference = ((ReferenceEffectiveStatementImpl) effectiveStatement)
- .argument();
- }
- if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
- status = ((StatusEffectiveStatementImpl) effectiveStatement)
- .argument();
- }
- }
}
private TypeDefinition<?> parseBaseTypeFromCtx(final StmtContext<QName, TypedefStatement, ?> ctx) {
- TypeDefinition<?> baseType;
+ TypeDefinition<?> baseTypeInit;
- QName baseTypeQName = Utils.qNameFromArgument(ctx, StmtContextUtils
- .firstAttributeOf(ctx.declaredSubstatements(),
- TypeStatement.class));
+ QName baseTypeQName = Utils.qNameFromArgument(ctx,
+ StmtContextUtils.firstAttributeOf(ctx.declaredSubstatements(), TypeStatement.class));
if (TypeUtils.isYangBuiltInTypeString(baseTypeQName.getLocalName())) {
- baseType = TypeUtils.getYangPrimitiveTypeFromString(baseTypeQName
- .getLocalName());
- if (baseType == null) {
- baseType = firstSubstatementOfType(TypeDefinition.class);
-
- //due to compatibility problems with original yang parser
- //:FIXME try to find out better solution
- if(baseType instanceof Decimal64SpecificationEffectiveStatementImpl) {
- Decimal64SpecificationEffectiveStatementImpl decimal64 = (Decimal64SpecificationEffectiveStatementImpl) baseType;
- if(decimal64.isExtended()) {
- baseType = decimal64.getBaseType();
+ baseTypeInit = TypeUtils.getYangPrimitiveTypeFromString(baseTypeQName.getLocalName());
+ if (baseTypeInit == null) {
+ baseTypeInit = firstSubstatementOfType(TypeDefinition.class);
+
+ // due to compatibility problems with original yang parser
+ // :FIXME try to find out better solution
+ if (baseTypeInit instanceof Decimal64SpecificationEffectiveStatementImpl) {
+ Decimal64SpecificationEffectiveStatementImpl decimal64 = (Decimal64SpecificationEffectiveStatementImpl) baseTypeInit;
+ if (decimal64.isExtended()) {
+ baseTypeInit = decimal64.getBaseType();
}
}
}
} else {
StmtContext<?, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> baseTypeCtx = ctx
.getParentContext().getFromNamespace(TypeNamespace.class, baseTypeQName);
- baseType = (TypeDefEffectiveStatementImpl) baseTypeCtx.buildEffective();
+ baseTypeInit = (TypeDefEffectiveStatementImpl) baseTypeCtx.buildEffective();
}
- return baseType;
+ return baseTypeInit;
}
protected Integer initFractionDigits(final EffectiveStatementBase<?, ?> typeEffectiveStmt) {
protected List<RangeConstraint> initRanges(final EffectiveStatementBase<?, ?> typeEffectiveStmt) {
final RangeEffectiveStatementImpl rangeConstraints = typeEffectiveStmt
.firstEffective(RangeEffectiveStatementImpl.class);
- return rangeConstraints != null ? rangeConstraints.argument(): Collections.<RangeConstraint> emptyList();
+ return rangeConstraints != null ? rangeConstraints.argument() : Collections.<RangeConstraint> emptyList();
}
protected List<LengthConstraint> initLengths(final EffectiveStatementBase<?, ?> typeEffectiveStmt) {
final LengthEffectiveStatementImpl lengthConstraints = typeEffectiveStmt
.firstEffective(LengthEffectiveStatementImpl.class);
- return lengthConstraints != null ? lengthConstraints.argument(): Collections.<LengthConstraint> emptyList();
+ return lengthConstraints != null ? lengthConstraints.argument() : Collections.<LengthConstraint> emptyList();
}
protected List<PatternConstraint> initPatterns(final EffectiveStatementBase<?, ?> typeEffectiveStmt) {
return defaultValue;
}
- @Override
- public QName getQName() {
- return qName;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return Collections.emptyList();
}
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
public List<RangeConstraint> getRangeConstraints() {
return ranges;
}
Builder extendedTypeBuilder;
if (baseType instanceof TypeDefinitionEffectiveBuilder) {
TypeDefinitionEffectiveBuilder typeDefBaseType = (TypeDefinitionEffectiveBuilder) baseType;
- extendedTypeBuilder = ExtendedType.builder(qName,
- typeDefBaseType.buildType(),
- Optional.fromNullable(description),
- Optional.fromNullable(reference), path);
+ extendedTypeBuilder = ExtendedType.builder(getQName(), typeDefBaseType.buildType(),
+ Optional.fromNullable(getDescription()), Optional.fromNullable(getReference()), getPath());
} else {
- extendedTypeBuilder = ExtendedType.builder(qName, baseType,
- Optional.fromNullable(description),
- Optional.fromNullable(reference), path);
+ extendedTypeBuilder = ExtendedType.builder(getQName(), baseType, Optional.fromNullable(getDescription()),
+ Optional.fromNullable(getReference()), getPath());
}
extendedTypeBuilder.defaultValue(defaultValue);
import org.opendaylight.yangtools.yang.model.api.stmt.UniqueStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class UniqueEffectiveStatementImpl extends
+public final class UniqueEffectiveStatementImpl extends
EffectiveStatementBase<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement> {
-
- public UniqueEffectiveStatementImpl(
- StmtContext<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement, ?> ctx) {
+ public UniqueEffectiveStatementImpl(StmtContext<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement, ?> ctx) {
super(ctx);
}
-
}
import org.opendaylight.yangtools.yang.model.api.stmt.UnitsStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class UnitsEffectiveStatementImpl extends EffectiveStatementBase<String, UnitsStatement> {
+public final class UnitsEffectiveStatementImpl extends EffectiveStatementBase<String, UnitsStatement> {
public UnitsEffectiveStatementImpl(final StmtContext<String, UnitsStatement, ?> ctx) {
super(ctx);
}
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class UnknownEffectiveStatementImpl extends EffectiveStatementBase<String, UnknownStatement<String>> implements
- UnknownSchemaNode {
+public final class UnknownEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<String, UnknownStatement<String>>
+ implements UnknownSchemaNode {
- private boolean augmenting;
- private boolean addedByUses;
- private UnknownSchemaNode original;
-
- private QName maybeQNameArgument;
+ private final boolean addedByUses;
+ private final QName maybeQNameArgument;
private final SchemaPath path;
- private ExtensionDefinition extension;
- private String description;
- private String reference;
- private final Status status = Status.CURRENT;
+ private final ExtensionDefinition extension;
private final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
- private QName nodeType;
+ private final QName nodeType;
private final String nodeParameter;
public UnknownEffectiveStatementImpl(final StmtContext<String, UnknownStatement<String>, ?> ctx) {
extension = (ExtensionEffectiveStatementImpl) extensionInit.buildEffective();
nodeType = extension.getQName();
}
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
- augmenting = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
- addedByUses = augmenting = true;
+ // initCopyType
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
+ if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)
+ || copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
+ this.addedByUses = true;
+ } else {
+ this.addedByUses = false;
}
- if (ctx.getOriginalCtx() != null) {
- original = (UnknownSchemaNode) ctx.getOriginalCtx().buildEffective();
- }
-
// FIXME: Remove following section after fixing 4380
- if(original != null) {
- maybeQNameArgument = original.getQName();
+ final UnknownSchemaNode original = ctx.getOriginalCtx() == null ? null : (UnknownSchemaNode) ctx
+ .getOriginalCtx().buildEffective();
+ if (original != null) {
+ this.maybeQNameArgument = original.getQName();
} else {
+ QName maybeQNameArgumentInit = null;
try {
- maybeQNameArgument = Utils.qNameFromArgument(ctx, argument());
+ maybeQNameArgumentInit = Utils.qNameFromArgument(ctx, argument());
} catch (IllegalArgumentException e) {
- maybeQNameArgument = nodeType;
+ maybeQNameArgumentInit = nodeType;
}
+ this.maybeQNameArgument = maybeQNameArgumentInit;
}
path = Utils.getSchemaPath(ctx.getParentContext()).createChild(maybeQNameArgument);
nodeParameter = (ctx.rawStatementArgument() == null) ? "" : ctx.rawStatementArgument();
// TODO init other fields (see Bug1412Test)
-
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
- description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
- reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
- }
if (effectiveStatement instanceof UnknownEffectiveStatementImpl) {
unknownNodes.add((UnknownEffectiveStatementImpl) effectiveStatement);
}
}
}
-
@Override
public QName getNodeType() {
return nodeType;
return unknownNodes;
}
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
@Override
public int hashCode() {
final int prime = 31;
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class UsesEffectiveStatementImpl extends EffectiveStatementBase<QName, UsesStatement> implements UsesNode {
- private SchemaPath groupingPath;
- private boolean addedByUses;
- private ImmutableMap<SchemaPath, SchemaNode> refines;
- private ImmutableSet<AugmentationSchema> augmentations;
- private ImmutableList<UnknownSchemaNode> unknownNodes;
+public final class UsesEffectiveStatementImpl extends EffectiveStatementBase<QName, UsesStatement> implements UsesNode {
+ private final SchemaPath groupingPath;
+ private final boolean addedByUses;
+ private final Map<SchemaPath, SchemaNode> refines;
+ private final Set<AugmentationSchema> augmentations;
+ private final List<UnknownSchemaNode> unknownNodes;
- public UsesEffectiveStatementImpl(final StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
+ public UsesEffectiveStatementImpl(
+ final StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
super(ctx);
- initGroupingPath(ctx);
- initCopyType(ctx);
- initSubstatementCollections();
- }
-
- private void initGroupingPath(final StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
+ // initGroupingPath
StmtContext<?, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> grpCtx = ctx.getFromNamespace(
GroupingNamespace.class, ctx.getStatementArgument());
this.groupingPath = Utils.getSchemaPath(grpCtx);
- }
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+ // initCopyType
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
+ if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
+ addedByUses = true;
+ } else {
+ addedByUses = false;
+ }
+ // initSubstatementCollections
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
Set<AugmentationSchema> augmentationsInit = new HashSet<>();
Map<SchemaPath, SchemaNode> refinesInit = new HashMap<>();
-
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
refinesInit.put(identifier.asSchemaPath(), refineStmt.getRefineTargetNode());
}
}
-
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.augmentations = ImmutableSet.copyOf(augmentationsInit);
this.refines = ImmutableMap.copyOf(refinesInit);
}
- private void initCopyType(
- final StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- }
-
@Override
public SchemaPath getGroupingPath() {
return groupingPath;
return addedByUses;
}
- void setAddedByUses(final boolean addedByUses) {
- this.addedByUses = addedByUses;
- }
-
@Override
public Map<SchemaPath, SchemaNode> getRefines() {
return refines;
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class ValueEffectiveStatementImpl extends EffectiveStatementBase<Integer, ValueStatement> {
+public final class ValueEffectiveStatementImpl extends EffectiveStatementBase<Integer, ValueStatement> {
public ValueEffectiveStatementImpl(final StmtContext<Integer, ValueStatement, ?> ctx) {
super(ctx);
}
import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class WhenEffectiveStatementImpl extends EffectiveStatementBase<RevisionAwareXPath, WhenStatement> {
+public final class WhenEffectiveStatementImpl extends EffectiveStatementBase<RevisionAwareXPath, WhenStatement> {
public WhenEffectiveStatementImpl(final StmtContext<RevisionAwareXPath, WhenStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class YangVersionEffectiveStatementImpl extends EffectiveStatementBase<String, YangVersionStatement> {
+public final class YangVersionEffectiveStatementImpl extends EffectiveStatementBase<String, YangVersionStatement> {
public YangVersionEffectiveStatementImpl(final StmtContext<String, YangVersionStatement, ?> ctx) {
super(ctx);
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import org.opendaylight.yangtools.yang.model.api.stmt.YinElementStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class YinElementEffectiveStatementImpl extends EffectiveStatementBase<Boolean, YinElementStatement> {
+public final class YinElementEffectiveStatementImpl extends EffectiveStatementBase<Boolean, YinElementStatement> {
public YinElementEffectiveStatementImpl(final StmtContext<Boolean, YinElementStatement, ?> ctx) {
super(ctx);
}
}
private List<RangeConstraint> initRanges() {
- final RangeEffectiveStatementImpl rangeConstraints = firstEffective(RangeEffectiveStatementImpl.class);
- return rangeConstraints != null ? rangeConstraints.argument() : Collections.<RangeConstraint> emptyList();
+ final RangeEffectiveStatementImpl rangeConstraintsStmt = firstEffective(RangeEffectiveStatementImpl.class);
+ return rangeConstraintsStmt != null ? rangeConstraintsStmt.argument() : Collections.<RangeConstraint> emptyList();
}
public boolean isExtended() {
public static final String LOCAL_NAME = "leafref";
private static final QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, LOCAL_NAME);
- private static final SchemaPath PATH = SchemaPath.create(true, QNAME);
private static final String DESCRIPTION = "The leafref type is used to reference a particular leaf instance in the data tree.";
private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.9";
private static final String UNITS = "";