*/
package org.opendaylight.yangtools.binding.generator.util;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {
super(rawType.getPackageName(), rawType.getName());
this.rawType = rawType;
- this.actualTypes = actTypes;
+ this.actualTypes = Arrays.copyOf(actTypes, actTypes.length);
}
}
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-parent</artifactId>
+ <version>0.6.2-SNAPSHOT</version>
+ <relativePath>parent</relativePath>
+ </parent>
<groupId>org.opendaylight.yangtools</groupId>
<version>0.6.2-SNAPSHOT</version>
long newTotal = currentTotal + 1;
// Calculate moving cumulative average.
- double newAve = currentAve * currentTotal / newTotal + duration / newTotal;
+ double newAve = currentAve * (double)currentTotal / (double)newTotal + (double)duration / (double)newTotal;
averageDuration.compareAndSet(currentAve, newAve);
totalDurations.compareAndSet(currentTotal, newTotal);
if( LOG.isTraceEnabled() ) {
LOG.trace( "{}: submitNotifications for listener {}: {}",
- name, listener.getClass(), notifications );
+ name, listener.toString(), notifications );
}
ListenerKey<L> key = new ListenerKey<>( listener );
// to the caller.
LOG.debug( "{}: Submitting NotificationTask for listener {}",
- name, listener.getClass() );
+ name, listener.toString() );
executor.execute( newNotificationTask );
break;
// telling us to quit.
LOG.debug( "{}: Interrupted trying to add to {} listener's queue",
- name, listener.getClass() );
+ name, listener.toString() );
}
if( LOG.isTraceEnabled() ) {
LOG.trace( "{}: submitNotifications dine for listener {}",
- name, listener.getClass() );
+ name, listener.toString() );
}
}
List<ListenerNotificationQueueStats> statsList = new ArrayList<>( listenerCache.size() );
for( NotificationTask task: listenerCache.values() ) {
statsList.add( new ListenerNotificationQueueStats(
- task.listenerKey.getListener().getClass().getName(),
- task.notificationQueue.size() ) );
+ task.listenerKey.toString(), task.notificationQueue.size() ) );
}
return statsList ;
ListenerKey<?> other = (ListenerKey<?>) obj;
return listener == other.listener;
}
+
+ @Override
+ public String toString() {
+ return listener.toString();
+ }
}
/**
if( LOG.isDebugEnabled() ) {
LOG.debug( "{}: Offering notification to the queue for listener {}: {}",
- name, listenerKey.getListener().getClass(), notification );
+ name, listenerKey.toString(), notification );
}
if( notificationQueue.offer( notification, 1, TimeUnit.MINUTES ) ) {
LOG.warn(
"{}: Timed out trying to offer a notification to the queue for listener {}." +
"The queue has reached its capacity of {}",
- name, listenerKey.getListener().getClass(), maxQueueCapacity );
+ name, listenerKey.toString(), maxQueueCapacity );
}
}
// The executor is probably shutting down so log as debug.
LOG.debug( "{}: Interrupted trying to remove from {} listener's queue",
- name, listenerKey.getListener().getClass() );
+ name, listenerKey.toString() );
} finally {
// We're exiting, gracefully or not - either way make sure we always remove
if( LOG.isDebugEnabled() ) {
LOG.debug( "{}: Invoking listener {} with notification: {}",
- name, listenerKey.getListener().getClass(), notification );
+ name, listenerKey.toString(), notification );
}
listenerInvoker.invokeListener( listenerKey.getListener(), notification );
// remaining notifications.
LOG.error( String.format( "%1$s: Error notifying listener %2$s", name,
- listenerKey.getListener().getClass() ), e );
+ listenerKey.toString() ), e );
} catch( Error e ) {
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-parent</artifactId>
+ <version>0.6.2-SNAPSHOT</version>
+ <relativePath>../common/parent</relativePath>
+ </parent>
+
<groupId>org.opendaylight.yangtools</groupId>
<version>0.6.2-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-parent</artifactId>
+ <version>0.6.2-SNAPSHOT</version>
+ <relativePath>common/parent</relativePath>
+ </parent>
+
<modelVersion>4.0.0</modelVersion>
<artifactId>yangtools-aggregator</artifactId>
<groupId>org.opendaylight.yangtools</groupId>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
-
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-parent</artifactId>
+ <version>0.6.2-SNAPSHOT</version>
+ <relativePath>../common/parent</relativePath>
+ </parent>
<groupId>org.opendaylight.yangtools</groupId>
<version>0.6.2-SNAPSHOT</version>
<artifactId>websocket-aggregator</artifactId>
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-parent</artifactId>
+ <version>0.6.2-SNAPSHOT</version>
+ <relativePath>../common/parent</relativePath>
+ </parent>
<groupId>org.opendaylight.yangtools</groupId>
<version>0.6.2-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
@Override
public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
- tracker.startListItem(name);
+ tracker.startList(name);
- stack.push(new TypeInfo(NodeType.LIST, name.getNodeType().getNamespace()));
separateElementFromPreviousElement();
+ stack.push(new TypeInfo(NodeType.LIST, name.getNodeType().getNamespace()));
writeJsonIdentifier(name);
writeStartList();
indentRight();
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
+
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
+
import javax.xml.stream.XMLStreamWriter;
+
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
return schema;
}
- public void startList(final NodeIdentifier name) {
+ public void startList(final PathArgument name) {
final SchemaNode schema = getSchema(name);
Preconditions.checkArgument(schema instanceof ListSchemaNode, "Node %s is not a list", schema.getPath());
schemaStack.push(schema);
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.NodeList;
public class XmlDocumentUtils {
- private final static String RPC_REPLY_LOCAL_NAME = "rpc-reply";
- private final static String RPC_REPLY_NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0";
- private final static QName RPC_REPLY_QNAME = QName.create(URI.create(RPC_REPLY_NAMESPACE), null, RPC_REPLY_LOCAL_NAME);
-
private static class ElementWithSchemaContext {
Element element;
SchemaContext schemaContext;
}
}
- public static final QName OPERATION_ATTRIBUTE_QNAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), null, "operation");
- private static final Logger logger = LoggerFactory.getLogger(XmlDocumentUtils.class);
+ public static final QName OPERATION_ATTRIBUTE_QNAME = QName.create(SchemaContext.NAME, "operation");
+ private static final QName RPC_REPLY_QNAME = QName.create(SchemaContext.NAME, "rpc-reply");
+ private static final Logger LOG = LoggerFactory.getLogger(XmlDocumentUtils.class);
private static final XMLOutputFactory FACTORY = XMLOutputFactory.newFactory();
/**
writer.close();
return (Document)result.getNode();
} catch (XMLStreamException e) {
- logger.error("Failed to serialize data {}", data, e);
+ LOG.error("Failed to serialize data {}", data, e);
return null;
}
}
writer.close();
return (Document)result.getNode();
} catch (XMLStreamException e) {
- logger.error("Failed to serialize data {}", data, e);
+ LOG.error("Failed to serialize data {}", data, e);
return null;
}
}
protected static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafSchemaNode schema,
final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
- TypeDefinitionAwareCodec<? extends Object, ? extends TypeDefinition<?>> codec = codecProvider.codecFor(schema.getType());
- String text = xmlElement.getTextContent();
- Object value = null;
- if (codec != null) {
- value = codec.deserialize(text);
- }
final TypeDefinition<?> baseType = XmlUtils.resolveBaseTypeFrom(schema.getType());
+ final String text = xmlElement.getTextContent();
+ final Object value;
- if (baseType instanceof org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType) {
- value = InstanceIdentifierForXmlCodec.deserialize(xmlElement,schemaCtx);
- } else if(baseType instanceof IdentityrefTypeDefinition){
- value = InstanceIdentifierForXmlCodec.toIdentity(xmlElement.getTextContent(), xmlElement, schemaCtx);
- }
-
- if (value == null) {
- value = xmlElement.getTextContent();
+ if (baseType instanceof InstanceIdentifierType) {
+ value = InstanceIdentifierForXmlCodec.deserialize(xmlElement, schemaCtx);
+ } else if (baseType instanceof IdentityrefTypeDefinition) {
+ value = InstanceIdentifierForXmlCodec.toIdentity(text, xmlElement, schemaCtx);
+ } else {
+ final TypeDefinitionAwareCodec<?, ?> codec = codecProvider.codecFor(schema.getType());
+ if (codec == null) {
+ LOG.info("No codec for schema {}, falling back to text", schema);
+ value = text;
+ } else {
+ value = codec.deserialize(text);
+ }
}
Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
private static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafListSchemaNode schema,
final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
- TypeDefinitionAwareCodec<? extends Object, ? extends TypeDefinition<?>> codec = codecProvider.codecFor(schema.getType());
- String text = xmlElement.getTextContent();
- Object value = null;
- if (codec != null) {
- value = codec.deserialize(text);
- }
- if (schema.getType() instanceof org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType) {
- value = InstanceIdentifierForXmlCodec.deserialize(xmlElement,schemaCtx);
- }
- if (value == null) {
- value = xmlElement.getTextContent();
+ final Object value;
+
+ if (schema.getType() instanceof InstanceIdentifierType) {
+ value = InstanceIdentifierForXmlCodec.deserialize(xmlElement, schemaCtx);
+ } else {
+ final TypeDefinitionAwareCodec<?, ?> codec = codecProvider.codecFor(schema.getType());
+ final String text = xmlElement.getTextContent();
+
+ if (codec == null) {
+ LOG.info("No codec for schema {}, falling back to text", schema);
+ value = text;
+ } else {
+ value = codec.deserialize(text);
+ }
}
Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
package org.opendaylight.yangtools.yang.model.api;
import com.google.common.base.Optional;
-import javax.annotation.concurrent.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
-
import java.net.URI;
import java.util.Date;
import java.util.Set;
+import javax.annotation.concurrent.Immutable;
+import org.opendaylight.yangtools.yang.common.QName;
/**
* The interface represents static view of compiled yang files,
*/
@Immutable
public interface SchemaContext extends ContainerSchemaNode {
-
+ /**
+ * QName of NETCONF top-level data node.
+ */
public static final QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), null, "data");
/**
--- /dev/null
+/*
+ * Copyright (c) 2014 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.model.util;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+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.type.BitsTypeDefinition;
+
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class BitsTypeTest {
+
+ @Mock
+ private BitsTypeDefinition.Bit bit;
+
+ @Test
+ public void canCreateBitsType(){
+ MockitoAnnotations.initMocks(this);
+
+ QName qName = QName.create("TestQName");
+ SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+ List<BitsTypeDefinition.Bit> listBit = Collections.singletonList(bit);
+ BitsType bitsType = BitsType.create(schemaPath, listBit);
+
+ assertNotEquals("Description is not null", null, bitsType.getDescription());
+ assertEquals("QName", BaseTypes.BITS_QNAME, bitsType.getQName());
+ assertEquals("Should be empty string", "", bitsType.getUnits());
+ assertNotEquals("Description should not be null", null, bitsType.toString());
+ assertNotEquals("Reference is not null", null, bitsType.getReference());
+ assertEquals("BaseType should be null", null, bitsType.getBaseType());
+ assertEquals("Default value should be list of bit", listBit, bitsType.getDefaultValue());
+ assertEquals("getPath should equal schemaPath", schemaPath, bitsType.getPath());
+ assertEquals("Status should be CURRENT", Status.CURRENT, bitsType.getStatus());
+ assertEquals("Should be empty list", Collections.EMPTY_LIST, bitsType.getUnknownSchemaNodes());
+ assertEquals("Values should be [enumPair]", listBit, bitsType.getBits());
+
+ assertEquals("Hash code of bitsType should be equal",
+ bitsType.hashCode(), bitsType.hashCode());
+ assertNotEquals("bitsType shouldn't equal to null", null, bitsType);
+ assertEquals("bitsType should equals to itself", bitsType, bitsType);
+ assertNotEquals("bitsType shouldn't equal to object of other type", "str", bitsType);
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2014 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.model.util;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+
+import java.util.Collections;
+import java.util.NoSuchElementException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.mock;
+
+public class DataNodeIteratorTest {
+
+ private DataNodeIterator dataNodeIterator;
+
+ @Before
+ public void setUp() {
+ DataNodeContainer dataNodeContainer = mock(DataNodeContainer.class);
+ this.dataNodeIterator = new DataNodeIterator(dataNodeContainer);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void createDataNodeIteratorWithNullArgument() {
+ new DataNodeIterator(null);
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void removeFromEmptyDataNodeContainer() {
+ dataNodeIterator.remove();
+ }
+
+ @Test(expected = NoSuchElementException.class)
+ public void tryNextOnEmptyDataContainer() {
+ dataNodeIterator.next();
+ }
+
+ @Test
+ public void createDataNodeIteratorWith() {
+ assertFalse("Has no next", dataNodeIterator.hasNext());
+ assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allChoices());
+ assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allContainers());
+ assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allTypedefs());
+ assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allGroupings());
+ assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allLists());
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2014 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.model.util;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+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.type.EnumTypeDefinition;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class EnumerationTypeTest {
+
+ @Mock private EnumTypeDefinition.EnumPair enumPair;
+
+ @Test
+ public void canCreateEnumerationType(){
+ MockitoAnnotations.initMocks(this);
+
+ QName qName = QName.create("TestQName");
+ SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+
+ List<EnumTypeDefinition.EnumPair> listEnumPair = Collections.singletonList(enumPair);
+ Optional<EnumTypeDefinition.EnumPair> defaultValue = Optional.of(enumPair);
+
+ EnumerationType enumerationType = EnumerationType.create(schemaPath, listEnumPair, defaultValue);
+
+ assertNotEquals("Description is not null", null, enumerationType.getDescription());
+ assertEquals("QName", BaseTypes.ENUMERATION_QNAME, enumerationType.getQName());
+ assertEquals("Should be empty string", "", enumerationType.getUnits());
+ assertNotEquals("Description should not be null", null, enumerationType.toString());
+ assertNotEquals("Reference is not null", null, enumerationType.getReference());
+ assertEquals("BaseType should be null", null, enumerationType.getBaseType());
+ assertEquals("Default value should be enumPair", enumPair, enumerationType.getDefaultValue());
+ assertEquals("getPath should equal schemaPath", schemaPath, enumerationType.getPath());
+ assertEquals("Status should be CURRENT", Status.CURRENT, enumerationType.getStatus());
+ assertEquals("Should be empty list", Collections.EMPTY_LIST, enumerationType.getUnknownSchemaNodes());
+ assertEquals("Values should be [enumPair]", listEnumPair, enumerationType.getValues());
+
+ assertEquals("Hash code of enumerationType should be equal",
+ enumerationType.hashCode(), enumerationType.hashCode());
+ assertNotEquals("EnumerationType shouldn't equal to null", null, enumerationType);
+ assertEquals("EnumerationType should equals to itself", enumerationType, enumerationType);
+ assertNotEquals("EnumerationType shouldn't equal to object of other type", "str", enumerationType);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2014 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.model.util;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+
+public class SchemaContextUtilTest {
+ @Mock private SchemaContext mockSchemaContext;
+ @Mock private Module mockModule;
+
+ @Test
+ public void testFindDummyData() {
+ MockitoAnnotations.initMocks(this);
+
+ QName qName = QName.create("TestQName");
+ SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+ assertEquals("Should be null. Module TestQName not found", null,
+ SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
+
+ RevisionAwareXPath xPath = new RevisionAwareXPathImpl("/bookstore/book/title", true);
+ assertEquals("Should be null. Module bookstore not found", null,
+ SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
+
+ SchemaNode schemaNode = Int32.getInstance();
+ RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
+ assertEquals("Should be null, Module prefix not found", null,
+ SchemaContextUtil.findDataSchemaNodeForRelativeXPath(
+ mockSchemaContext, mockModule, schemaNode, xPathRelative));
+
+ assertEquals("Should be null. Module TestQName not found", null,
+ SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qName)));
+
+ assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));
+ }
+}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import com.google.common.collect.Sets;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.Multimap;
-
/**
* Inter-module dependency resolved. Given a set of schema source identifiers and their
* corresponding dependency information, the {@link #create(Map)} method creates a
}
private static SourceIdentifier findWildcard(final Iterable<SourceIdentifier> haystack, final String needle) {
- for (SourceIdentifier r : haystack) {
+ for (final SourceIdentifier r : haystack) {
if (r.getName().equals(needle)) {
return r;
}
- public static final DependencyResolver create(final Map<SourceIdentifier, YangModelDependencyInfo> depInfo) {
+ public static DependencyResolver create(final Map<SourceIdentifier, YangModelDependencyInfo> depInfo) {
final Collection<SourceIdentifier> resolved = new ArrayList<>(depInfo.size());
final Collection<SourceIdentifier> pending = new ArrayList<>(depInfo.keySet());
+ final Map<SourceIdentifier, BelongsToDependency> submodules = Maps.newHashMap();
boolean progress;
do {
boolean okay = true;
- Set<ModuleImport> dependencies = dep.getDependencies();
+ final Set<ModuleImport> dependencies = dep.getDependencies();
- // in case of submodule, make its parent also a dependency
+ // in case of submodule, remember belongs to
if(dep instanceof YangModelDependencyInfo.SubmoduleDependencyInfo) {
final String parent = ((YangModelDependencyInfo.SubmoduleDependencyInfo) dep).getParentModule();
- dependencies = Sets.newHashSet(dependencies);
- dependencies.add(new BelongsToDependency(parent));
+ submodules.put(id, new BelongsToDependency(parent));
}
- for (ModuleImport mi : dependencies) {
+ for (final ModuleImport mi : dependencies) {
if (!isKnown(resolved, mi)) {
LOG.debug("Source {} is missing import {}", id, mi);
okay = false;
}
} while (progress);
+ /// Additional check only for belongs-to statement
+ for (final SourceIdentifier sourceIdentifier : submodules.keySet()) {
+ final BelongsToDependency belongs = submodules.get(sourceIdentifier);
+ if (!isKnown(resolved, belongs)) {
+ LOG.debug("Source {} is missing parent {}", sourceIdentifier, belongs);
+ pending.add(sourceIdentifier);
+ resolved.remove(sourceIdentifier);
+ }
+ }
+
if (!pending.isEmpty()) {
final Multimap<SourceIdentifier, ModuleImport> imports = ArrayListMultimap.create();
- for (SourceIdentifier id : pending) {
+ for (final SourceIdentifier id : pending) {
final YangModelDependencyInfo dep = depInfo.get(id);
- for (ModuleImport mi : dep.getDependencies()) {
+ for (final ModuleImport mi : dep.getDependencies()) {
if (!isKnown(pending, mi) && !isKnown(resolved, mi)) {
imports.put(id, mi);
}
public String getPrefix() {
return null;
}
+
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(this)
+ .add("parent", parent)
+ .toString();
+ }
}
}
public final class ASTSchemaSource implements SchemaSourceRepresentation {
public static final Function<ASTSchemaSource, SourceIdentifier> GET_IDENTIFIER = new Function<ASTSchemaSource, SourceIdentifier>() {
@Override
- public SourceIdentifier apply(final ASTSchemaSource input) {
+ public SourceIdentifier apply(@Nonnull final ASTSchemaSource input) {
+ Preconditions.checkNotNull(input);
return input.getIdentifier();
}
};
public static final Function<ASTSchemaSource, YangModelDependencyInfo> GET_DEPINFO = new Function<ASTSchemaSource, YangModelDependencyInfo>() {
@Override
- public YangModelDependencyInfo apply(final ASTSchemaSource input) {
+ public YangModelDependencyInfo apply(@Nonnull final ASTSchemaSource input) {
+ Preconditions.checkNotNull(input);
return input.getDependencyInformation();
}
};
public static final Function<ASTSchemaSource, ParserRuleContext> GET_AST = new Function<ASTSchemaSource, ParserRuleContext>() {
@Override
- public ParserRuleContext apply(final ASTSchemaSource input) {
+ public ParserRuleContext apply(@Nonnull final ASTSchemaSource input) {
+ Preconditions.checkNotNull(input);
return input.getAST();
}
};
private final SourceIdentifier id;
private final String text;
- private ASTSchemaSource(final @Nonnull SourceIdentifier id, @Nonnull final ParserRuleContext tree, final @Nonnull YangModelDependencyInfo depInfo, final @Nonnull String text) {
+ private ASTSchemaSource(final @Nonnull SourceIdentifier id, @Nonnull final ParserRuleContext tree, final @Nonnull YangModelDependencyInfo depInfo, final String text) {
this.depInfo = Preconditions.checkNotNull(depInfo);
this.tree = Preconditions.checkNotNull(tree);
this.id = Preconditions.checkNotNull(id);
- this.text = Preconditions.checkNotNull(text);
+ this.text = text;
}
/**
final DependencyResolver resolved = DependencyResolver.create(map);
+ assertEquals(2, resolved.getResolvedSources().size());
assertEquals(1, resolved.getUnresolvedSources().size());
assertEquals(0, resolved.getUnsatisfiedImports().size());
}
+ @Test
+ public void testSubmodule() throws Exception {
+ final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
+
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/subfoo.yang")));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/foo.yang")));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/bar.yang")));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/baz.yang")));
+
+ final DependencyResolver resolved = DependencyResolver.create(map);
+
+ assertEquals(4, resolved.getResolvedSources().size());
+ assertEquals(0, resolved.getUnresolvedSources().size());
+ assertEquals(0, resolved.getUnsatisfiedImports().size());
+ }
+
private void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map, final YangModelDependencyInfo yangModelDependencyInfo) {
map.put(getSourceId(yangModelDependencyInfo), yangModelDependencyInfo);
}