}
protected final <V> V runOnClassLoader(final ClassLoader cls, final Callable<V> function) throws Exception {
- final Lock lock = javAssist.getLock();
-
- lock.lock();
- try {
- synchronized (javAssist) {
- javAssist.appendClassLoaderIfMissing(cls);
- return ClassLoaderUtils.withClassLoader(cls, function);
- }
- } finally {
- lock.unlock();
+ synchronized (javAssist) {
+ javAssist.appendClassLoaderIfMissing(cls);
+ return ClassLoaderUtils.withClassLoader(cls, function);
}
}
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
+
import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
import org.opendaylight.yangtools.binding.generator.util.BindingTypes;
import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
notification.getChildNodes());
listenerInterface.addMethod("on" + notificationInterface.getName())
- .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification")
- .setComment(notification.getDescription()).setReturnType(Types.VOID);
+ .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification")
+ .setComment(notification.getDescription()).setReturnType(Types.VOID);
}
}
.getQNameModule());
final String returnTypeName = BindingMapping.getClassName(baseIdentity.getQName());
final GeneratedTransferObject gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName)
- .toInstance();
+ .toInstance();
newType.setExtendsType(gto);
}
newType.setAbstract(true);
private void groupingsToGenTypes(final Module module, final Collection<GroupingDefinition> groupings) {
final String basePackageName = BindingMapping.getRootPackageName(module.getQNameModule());
final List<GroupingDefinition> groupingsSortedByDependencies = new GroupingDefinitionDependencySort()
- .sort(groupings);
+ .sort(groupings);
for (GroupingDefinition grouping : groupingsSortedByDependencies) {
groupingToGenType(basePackageName, grouping, module);
}
* added to it.
*/
private GeneratedTypeBuilder resolveDataSchemaNodes(final Module module, final String basePackageName,
- final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final Set<DataSchemaNode> schemaNodes) {
- if ((schemaNodes != null) && (parent != null)) {
+ final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final Iterable<DataSchemaNode> schemaNodes) {
+ if (schemaNodes != null && parent != null) {
for (DataSchemaNode schemaNode : schemaNodes) {
if (!schemaNode.isAugmenting() && !schemaNode.isAddedByUses()) {
addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, parent, childOf, module);
*/
private GeneratedTypeBuilder augSchemaNodeToMethods(final Module module, final String basePackageName,
final GeneratedTypeBuilder typeBuilder, final GeneratedTypeBuilder childOf,
- final Set<DataSchemaNode> schemaNodes) {
+ final Iterable<DataSchemaNode> schemaNodes) {
if ((schemaNodes != null) && (typeBuilder != null)) {
for (DataSchemaNode schemaNode : schemaNodes) {
if (!schemaNode.isAugmenting()) {
caseTypeBuilder.addImplementsType(refChoiceType);
genCtx.get(module).addCaseType(caseNode.getPath(), caseTypeBuilder);
genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
- final Set<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
+ final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
if (caseChildNodes != null) {
Object parentNode = null;
final SchemaPath nodeSp = choiceNode.getPath();
if (targetSchemaNode == null) {
throw new IllegalStateException(
"Failed to find target node from grouping for augmentation " + augSchema
- + " in module " + module.getName());
+ + " in module " + module.getName());
}
}
parent = targetSchemaNode;
* </ul>
*/
private void generateTypesFromAugmentedChoiceCases(final Module module, final String basePackageName,
- final Type targetType, final ChoiceNode targetNode, final Set<DataSchemaNode> augmentedNodes) {
+ final Type targetType, final ChoiceNode targetNode, final Iterable<DataSchemaNode> augmentedNodes) {
checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
checkArgument(targetType != null, "Referenced Choice Type cannot be NULL.");
checkArgument(augmentedNodes != null, "Set of Choice Case Nodes cannot be NULL.");
} else {
node = targetNode.getCaseNodeByName(caseNode.getQName().getLocalName());
}
- final Set<DataSchemaNode> childNodes = node.getChildNodes();
+ final Iterable<DataSchemaNode> childNodes = node.getChildNodes();
if (childNodes != null) {
resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
}
}
private DataSchemaNode searchInChoices(final DataNodeContainer node, final QName arg) {
- Set<DataSchemaNode> children = node.getChildNodes();
- for (DataSchemaNode child : children) {
+ for (DataSchemaNode child : node.getChildNodes()) {
if (child instanceof ChoiceNode) {
ChoiceNode choiceNode = (ChoiceNode) child;
DataSchemaNode potential = searchInCases(choiceNode, arg);
for (Map.Entry<Type, AugmentationSchema> entry : bimap.entrySet()) {
Type key = entry.getKey();
AugmentationSchema value = entry.getValue();
- Set<DataSchemaNode> augmentedNodes = value.getChildNodes();
- if (augmentedNodes != null && !(augmentedNodes.isEmpty())) {
+ Collection<DataSchemaNode> augmentedNodes = value.getChildNodes();
+ if (augmentedNodes != null && !augmentedNodes.isEmpty()) {
typeToAugment.put(key, value);
}
}
import java.util.Collection;
import java.util.Map;
import java.util.WeakHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
import javassist.CannotCompileException;
import javassist.ClassClassPath;
import javassist.LoaderClassPath;
import javassist.Modifier;
import javassist.NotFoundException;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Users of this utility class are expected to synchronize on this instance
+ * it they need to ensure atomic operations on it.
+ */
public final class JavassistUtils {
private static final Logger LOG = LoggerFactory.getLogger(JavassistUtils.class);
private static final Map<ClassPool, JavassistUtils> INSTANCES = new WeakHashMap<>();
private final Map<ClassLoader, ClassPath> loaderClassPaths = new WeakHashMap<>();
- private final Lock lock = new ReentrantLock();
private final ClassPool classPool;
- /**
- * @deprecated Use {@link #forClassPool(ClassPool)} instead.
- *
- * This class provides auto-loading into the classpool. Unfortunately reusing
- * the same class pool with multiple instances can lead the same classpath
- * being added multiple times, which lowers performance and leaks memory.
- */
- @Deprecated
- public JavassistUtils(final ClassPool pool) {
- this(pool, null);
- }
-
- private JavassistUtils(final ClassPool pool, final Object dummy) {
- // FIXME: Remove 'dummy' once deprecated constructor is removed
+ private JavassistUtils(final ClassPool pool) {
classPool = Preconditions.checkNotNull(pool);
}
public static synchronized JavassistUtils forClassPool(final ClassPool pool) {
JavassistUtils ret = INSTANCES.get(Preconditions.checkNotNull(pool));
if (ret == null) {
- ret = new JavassistUtils(pool, null);
+ ret = new JavassistUtils(pool);
INSTANCES.put(pool, ret);
}
return ret;
}
- /**
- * Get reference to the internal lock.
- *
- * @return Lock object
- *
- * @deprecated Synchronize on an instance of this class instead.
- */
- @Deprecated
- public Lock getLock() {
- return lock;
- }
-
public void method(final CtClass it, final Class<? extends Object> returnType, final String name,
final Class<? extends Object> parameter, final MethodGenerator function1) throws CannotCompileException {
final CtClass[] pa = new CtClass[] { asCtClass(parameter) };
}
public CtField staticField(final CtClass it, final String name,
- final Class<? extends Object> returnValue,
- SourceCodeGenerator sourceGenerator) throws CannotCompileException {
+ final Class<? extends Object> returnValue,
+ final SourceCodeGenerator sourceGenerator) throws CannotCompileException {
final CtField field = new CtField(asCtClass(returnValue), name, it);
field.setModifiers(Modifier.PUBLIC + Modifier.STATIC);
it.addField(field);
*/
package org.opendaylight.yangtools.sal.binding.yang.types;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import org.opendaylight.yangtools.yang.parser.util.TopologicalSort;
import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
public class GroupingDefinitionDependencySort {
/**
* data node container which can contain some uses of grouping
* @return set of uses nodes which were find in <code>container</code>.
*/
- private Set<UsesNode> getAllUsesNodes(DataNodeContainer container) {
+ private Set<UsesNode> getAllUsesNodes(final DataNodeContainer container) {
Set<UsesNode> ret = new HashSet<>();
Set<UsesNode> usesNodes = container.getUses();
ret.addAll(usesNodes);
for (GroupingDefinition groupingDefinition : groupings) {
ret.addAll(getAllUsesNodes(groupingDefinition));
}
- Set<DataSchemaNode> childNodes = container.getChildNodes();
- for (DataSchemaNode childNode : childNodes) {
+ for (DataSchemaNode childNode : container.getChildNodes()) {
if (childNode instanceof DataNodeContainer) {
ret.addAll(getAllUsesNodes((DataNodeContainer) childNode));
} else if (childNode instanceof ChoiceNode) {
return targetPathNodes
}
- private def DataSchemaNode findNodeInChildNodes(QName findingNode, Set<DataSchemaNode> childNodes) {
+ private def DataSchemaNode findNodeInChildNodes(QName findingNode, Iterable<DataSchemaNode> childNodes) {
for(child : childNodes) {
if (child.QName.equals(findingNode))
return child;
'''
}
- def CharSequence printChildren(Set<DataSchemaNode> nodes, int level, InstanceIdentifier path) {
+ def CharSequence printChildren(Iterable<DataSchemaNode> nodes, int level, InstanceIdentifier path) {
val anyxmlNodes = nodes.filter(AnyXmlSchemaNode)
val leafNodes = nodes.filter(LeafSchemaNode)
val leafListNodes = nodes.filter(LeafListSchemaNode)
'''
}
- def CharSequence xmlExample(Set<DataSchemaNode> nodes, QName name,InstanceIdentifier path) '''
+ def CharSequence xmlExample(Iterable<DataSchemaNode> nodes, QName name,InstanceIdentifier path) '''
<pre>
«xmlExampleTag(name,nodes.xmplExampleTags(path))»
</pre>
'''
- def CharSequence xmplExampleTags(Set<DataSchemaNode> nodes, InstanceIdentifier identifier) '''
+ def CharSequence xmplExampleTags(Iterable<DataSchemaNode> nodes, InstanceIdentifier identifier) '''
<!-- Child nodes -->
«FOR node : nodes»
<!-- «node.QName.localName» -->
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.ImmutableSet;
+
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.common.collect.ImmutableSet;
-
public class MultipleRevisionsSupportTest {
public static final YangModuleInfo TOPOLOGY_OLD_MODULE = org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.$YangModuleInfoImpl
verifyBindingDifference(schemaContext, TOPOLOGY_OLD_MODULE, TOPOLOGY_NEW_MODULE);
}
- private SchemaContext contextVerified(List<InputStream> streams) {
+ private SchemaContext contextVerified(final List<InputStream> streams) {
YangParserImpl parser = new YangParserImpl();
Set<Module> modules = parser.parseYangModelsFromStreams(streams);
assertNotNull(modules);
return context;
}
- private void verifyBindingDifference(SchemaContext schemaContext, YangModuleInfo oldModule, YangModuleInfo newModule) {
+ private void verifyBindingDifference(final SchemaContext schemaContext, final YangModuleInfo oldModule, final YangModuleInfo newModule) {
generatedTypesVerified(schemaContext, oldModule, newModule);
}
- private Map<Module, ModuleContext> generatedTypesVerified(SchemaContext schemaContext, YangModuleInfo oldModule,
- YangModuleInfo newModule) {
+ private Map<Module, ModuleContext> generatedTypesVerified(final SchemaContext schemaContext, final YangModuleInfo oldModule,
+ final YangModuleInfo newModule) {
BindingGeneratorImpl generator = new BindingGeneratorImpl();
generator.generateTypes(schemaContext);
return generator.getModuleContexts();
}
- private void verifySchemaDifference(SchemaContext context, YangModuleInfo topologyOldModule,
- YangModuleInfo topologyNewModule) {
+ private void verifySchemaDifference(final SchemaContext context, final YangModuleInfo topologyOldModule,
+ final YangModuleInfo topologyNewModule) {
Module oldModel = context.findModuleByNamespaceAndRevision(//
URI.create(TOPOLOGY_OLD_MODULE.getNamespace()), QName.parseRevision(TOPOLOGY_OLD_MODULE.getRevision()));
assertDeepRevision(TOPOLOGY_NEW_MODULE.getRevision(), newNode);
}
- private static void assertDeepRevision(String revision, SchemaNode node) {
+ private static void assertDeepRevision(final String revision, final SchemaNode node) {
assertEquals("Wrong revision: " + node.getPath(), revision, node.getQName().getFormattedRevision());
if (node instanceof DataNodeContainer) {
for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
}
}
- private static final SchemaNode findSchemaNode(DataNodeContainer container, String... pathArgs) {
+ private static final SchemaNode findSchemaNode(final DataNodeContainer container, final String... pathArgs) {
DataNodeContainer previous = container;
SchemaNode result = (container instanceof SchemaNode) ? (SchemaNode) container : null;
if (previous == null) {
return null;
}
- Set<DataSchemaNode> childs = previous.getChildNodes();
- for (DataSchemaNode child : childs) {
+ for (DataSchemaNode child : previous.getChildNodes()) {
if (child.getQName().getLocalName().equals(arg)) {
if (child instanceof DataNodeContainer) {
previous = (DataNodeContainer) child;
return result;
}
- private static final Iterable<? extends InputStream> toInputStreams(Set<YangModuleInfo> moduleInfos)
+ private static final Iterable<? extends InputStream> toInputStreams(final Set<YangModuleInfo> moduleInfos)
throws Exception {
Builder<InputStream> streams = ImmutableList.<InputStream> builder();
for (YangModuleInfo yangModuleInfo : moduleInfos) {
import java.util.ArrayList;
import java.util.List;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
-**/
-public class HostBuilder {
- private static final Pattern ipv4Pattern = Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?");
- private static final Pattern ipv6Pattern1 = Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
- private static final Pattern ipv6Pattern2 = Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
- private static final Pattern domainPattern = Pattern.compile("((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)|\\.");
+ **/
+public final class HostBuilder {
+ private static final Pattern IPV4_PATTERN = Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?");
+ private static final Pattern IPV6_PATTERN1 = Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
+ private static final Pattern IPV6_PATTERN2 = Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
+ private static final Pattern DOMAIN_PATTERN = Pattern.compile("((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)|\\.");
- public static Host getDefaultInstance(String defaultValue) {
+ private HostBuilder() {
- List<String> matchers = new ArrayList<>();
- if (ipv6Pattern1.matcher(defaultValue).matches() || ipv6Pattern2.matcher(defaultValue).matches()) {
+ }
+
+ public static Host getDefaultInstance(final String defaultValue) {
+ final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
+ final Matcher ipv6Matcher1 = IPV6_PATTERN1.matcher(defaultValue);
+ final Matcher ipv6Matcher2 = IPV6_PATTERN2.matcher(defaultValue);
+ final Matcher domainMatcher = DOMAIN_PATTERN.matcher(defaultValue);
+
+ List<String> matchers = new ArrayList<>(3);
+ if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) {
matchers.add(Ipv6Address.class.getSimpleName());
}
// Ipv4 and Domain Name patterns are not exclusive
// Address 127.0.0.1 matches both patterns
// This way Ipv4 address is preferred to domain name
- if (ipv4Pattern.matcher(defaultValue).matches()) {
+ if (ipv4Matcher.matches()) {
matchers.add(Ipv4Address.class.getSimpleName());
- } else if (domainPattern.matcher(defaultValue).matches()) {
+ } else if (domainMatcher.matches()) {
matchers.add(DomainName.class.getSimpleName());
}
+ matchers);
}
- if (ipv4Pattern.matcher(defaultValue).matches()) {
+ if (ipv4Matcher.matches()) {
Ipv4Address ipv4 = new Ipv4Address(defaultValue);
IpAddress ipAddress = new IpAddress(ipv4);
return new Host(ipAddress);
}
- if (ipv6Pattern1.matcher(defaultValue).matches() || ipv6Pattern2.matcher(defaultValue).matches()) {
+ if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) {
Ipv6Address ipv6 = new Ipv6Address(defaultValue);
IpAddress ipAddress = new IpAddress(ipv6);
return new Host(ipAddress);
}
- if (domainPattern.matcher(defaultValue).matches()) {
+ if (domainMatcher.matches()) {
DomainName domainName = new DomainName(defaultValue);
return new Host(domainName);
}
*/
package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
-**/
-public class IpAddressBuilder {
+ **/
+public final class IpAddressBuilder {
+ private static final Pattern IPV4_PATTERN =
+ Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?");
+ private static final Pattern IPV6_PATTERN1 =
+ Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
+ private static final Pattern IPV6_PATTERN2 =
+ Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
- public static IpAddress getDefaultInstance(String defaultValue) {
- String ipv4Pattern = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?";
- String ipv6Pattern1 = "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?";
- String ipv6Pattern2 = "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?";
+ private IpAddressBuilder() {
- List<String> matchers = new ArrayList<>();
- if (defaultValue.matches(ipv4Pattern)) {
- matchers.add(Ipv4Address.class.getSimpleName());
- }
- if (defaultValue.matches(ipv6Pattern1) && defaultValue.matches(ipv6Pattern2)) {
- matchers.add(Ipv6Address.class.getSimpleName());
- }
- if (matchers.size() > 1) {
- throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue
- + ". Value is ambigious for " + matchers);
- }
+ }
- if (defaultValue.matches(ipv4Pattern)) {
- Ipv4Address ipv4 = new Ipv4Address(defaultValue);
- return new IpAddress(ipv4);
- }
- if (defaultValue.matches(ipv6Pattern1) && defaultValue.matches(ipv6Pattern2)) {
- Ipv6Address ipv6 = new Ipv6Address(defaultValue);
- return new IpAddress(ipv6);
+ public static IpAddress getDefaultInstance(final String defaultValue) {
+ final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
+
+ if (ipv4Matcher.matches()) {
+ if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+ throw new IllegalArgumentException(
+ String.format("Cannot create IpAddress from \"%s\", matches both %s and %s",
+ defaultValue, Ipv4Address.class.getSimpleName(), Ipv6Address.class.getSimpleName()));
+
+ }
+ return new IpAddress(new Ipv4Address(defaultValue));
+ } else if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+ return new IpAddress(new Ipv6Address(defaultValue));
+ } else {
+ throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue);
}
- throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue);
}
}
*/
package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
-**/
-public class IpPrefixBuilder {
+ **/
+public final class IpPrefixBuilder {
+ private static final Pattern IPV4_PATTERN = Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/(([0-9])|([1-2][0-9])|(3[0-2]))");
+ private static final Pattern IPV6_PATTERN1 = Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))");
+ private static final Pattern IPV6_PATTERN2 = Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(/.+)");
- public static IpPrefix getDefaultInstance(String defaultValue) {
- String ipv4Pattern = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/(([0-9])|([1-2][0-9])|(3[0-2]))";
- String ipv6Pattern1 = "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))";
- String ipv6Pattern2 = "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(/.+)";
+ private IpPrefixBuilder() {
- List<String> matchers = new ArrayList<>();
- if (defaultValue.matches(ipv4Pattern)) {
- matchers.add(Ipv4Address.class.getSimpleName());
- }
- if (defaultValue.matches(ipv6Pattern1) && defaultValue.matches(ipv6Pattern2)) {
- matchers.add(Ipv6Address.class.getSimpleName());
- }
- if (matchers.size() > 1) {
- throw new IllegalArgumentException("Cannot create IpPrefix from " + defaultValue
- + ". Value is ambigious for " + matchers);
- }
+ }
- if (defaultValue.matches(ipv4Pattern)) {
- Ipv4Prefix ipv4 = new Ipv4Prefix(defaultValue);
- return new IpPrefix(ipv4);
- }
- if (defaultValue.matches(ipv6Pattern1) && defaultValue.matches(ipv6Pattern2)) {
- Ipv6Prefix ipv6 = new Ipv6Prefix(defaultValue);
- return new IpPrefix(ipv6);
+ public static IpPrefix getDefaultInstance(final String defaultValue) {
+ final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
+
+ if (ipv4Matcher.matches()) {
+ if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+ throw new IllegalArgumentException(
+ String.format("Cannot create IpPrefix from \"%s\", matches both %s and %s",
+ defaultValue, Ipv4Address.class.getSimpleName(), Ipv6Address.class.getSimpleName()));
+
+ }
+ return new IpPrefix(new Ipv4Prefix(defaultValue));
+ } else if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+ return new IpPrefix(new Ipv6Prefix(defaultValue));
+ } else {
+ throw new IllegalArgumentException("Cannot create IpPrefix from " + defaultValue);
}
- throw new IllegalArgumentException("Cannot create IpPrefix from " + defaultValue);
}
}
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
+import java.io.IOException;
+import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
* This would be the same as using a path like so, "/nodes/node/openflow:1" to refer to the openflow:1 node
*
*/
-public class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<? extends DataObject>>, Immutable {
+public class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<? extends DataObject>>, Immutable, Serializable {
+ private static final long serialVersionUID = 1L;
/*
* Protected to differentiate internal and external access. Internal
* access is required never to modify the contents. References passed
Class<? extends DataObject> getType();
}
- private static abstract class AbstractPathArgument<T extends DataObject> implements PathArgument {
+ private static abstract class AbstractPathArgument<T extends DataObject> implements PathArgument, Serializable {
+ private static final long serialVersionUID = 1L;
private final Class<T> type;
protected AbstractPathArgument(final Class<T> type) {
* @param <T>
*/
public static final class Item<T extends DataObject> extends AbstractPathArgument<T> {
+ private static final long serialVersionUID = 1L;
+
public Item(final Class<T> type) {
super(type);
}
* @param <T> The identifier of the object
*/
public static final class IdentifiableItem<I extends Identifiable<T> & DataObject, T extends Identifier<I>> extends AbstractPathArgument<I> {
+ private static final long serialVersionUID = 1L;
private final T key;
public IdentifiableItem(final Class<I> type, final T key) {
*/
InstanceIdentifier<T> build();
}
+
+ private void writeObject(final java.io.ObjectOutputStream out) throws IOException {
+ out.writeObject(targetType);
+ out.writeBoolean(wildcarded);
+ out.writeInt(hash);
+ out.write(Iterables.size(pathArguments));
+ for (Object o : pathArguments) {
+ out.writeObject(o);
+ }
+ }
+
+ private void readObject(final java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+ // TODO Auto-generated method stub
+ }
}
* @param <K> Target key type
*/
public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K extends Identifier<T>> extends InstanceIdentifier<T> {
+ private static final long serialVersionUID = 1L;
private final K key;
KeyedInstanceIdentifier(final Class<T> type, final Iterable<PathArgument> pathArguments, final boolean wildcarded, final int hash, final K key) {
import static com.google.common.base.Preconditions.checkState;
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
-
public class XmlDocumentUtils {
private static class ElementWithSchemaContext {
Element element;
checkState(qName.getLocalName().equals(xmlElement.getLocalName()), "Not equal: %s to: %s for: %s and: %s", qName.getLocalName(), xmlElement.getLocalName(), qName, xmlElement);
}
- public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Set<DataSchemaNode> dataSchemaNode) {
- if (dataSchemaNode != null && !dataSchemaNode.isEmpty() && qname != null) {
+ public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Iterable<DataSchemaNode> dataSchemaNode) {
+ if (dataSchemaNode != null && qname != null) {
for (DataSchemaNode dsn : dataSchemaNode) {
if (qname.isEqualWithoutRevision(dsn.getQName())) {
return Optional.<DataSchemaNode> of(dsn);
return ImmutableCompositeNode.create(qname, values.build());
}
- public static List<Node<?>> toDomNodes(final Element element, final Optional<Set<DataSchemaNode>> context,final SchemaContext schemaCtx) {
+ public static List<Node<?>> toDomNodes(final Element element, final Optional<? extends Iterable<DataSchemaNode>> context, final SchemaContext schemaCtx) {
return forEachChild(element.getChildNodes(),schemaCtx, new Function<ElementWithSchemaContext, Optional<Node<?>>>() {
@Override
QName partialQName = qNameFromElement(input.getElement());
Optional<DataSchemaNode> schemaNode = findFirstSchema(partialQName, context.get());
if (schemaNode.isPresent()) {
- return Optional.<Node<?>> fromNullable(//
+ return Optional.<Node<?>> fromNullable(
toNodeWithSchema(input.getElement(), schemaNode.get(), XmlUtils.DEFAULT_XML_CODEC_PROVIDER, input.getSchemaContext()));
}
}
}
- public static List<Node<?>> toDomNodes(final Element element, final Optional<Set<DataSchemaNode>> context) {
- return toDomNodes(element,context,null);
+ public static List<Node<?>> toDomNodes(final Element element, final Optional<? extends Iterable<DataSchemaNode>> context) {
+ return toDomNodes(element, context, null);
}
/**
final Optional<NotificationDefinition> notificationDef = findNotification(partialQName,
notifications.get());
if (notificationDef.isPresent()) {
- final Set<DataSchemaNode> dataNodes = notificationDef.get().getChildNodes();
+ final Iterable<DataSchemaNode> dataNodes = notificationDef.get().getChildNodes();
final List<Node<?>> domNodes = toDomNodes(childElement,
- Optional.<Set<DataSchemaNode>> fromNullable(dataNodes),schemaCtx);
+ Optional.<Iterable<DataSchemaNode>> fromNullable(dataNodes),schemaCtx);
return ImmutableCompositeNode.create(notificationDef.get().getQName(), domNodes);
}
}
private SchemaUtils() {
}
- public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Set<DataSchemaNode> dataSchemaNode) {
- if (dataSchemaNode != null && !dataSchemaNode.isEmpty() && qname != null) {
+ public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Iterable<DataSchemaNode> dataSchemaNode) {
+ if (dataSchemaNode != null && qname != null) {
for (DataSchemaNode dsn : dataSchemaNode) {
if (qname.isEqualWithoutRevision(dsn.getQName())) {
return Optional.<DataSchemaNode> of(dsn);
}
public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname) {
- Set<DataSchemaNode> childNodes = schema.getChildNodes();
- return findSchemaForChild(schema, qname, childNodes);
+ return findSchemaForChild(schema, qname, schema.getChildNodes());
}
- public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final Set<DataSchemaNode> childNodes) {
+ public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final Iterable<DataSchemaNode> childNodes) {
Optional<DataSchemaNode> childSchema = findFirstSchema(qname, childNodes);
Preconditions.checkState(childSchema.isPresent(),
"Unknown child(ren) node(s) detected, identified by: %s, in: %s", qname, schema);
* @return Map with all child nodes, to their most top augmentation
*/
public static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema) {
- Set<DataSchemaNode> childNodes = schema.getChildNodes();
-
- return mapChildElementsFromChoices(schema, childNodes);
+ return mapChildElementsFromChoices(schema, schema.getChildNodes());
}
- private static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema, final Set<DataSchemaNode> childNodes) {
+ private static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema, final Iterable<DataSchemaNode> childNodes) {
Map<QName, ChoiceNode> mappedChoices = Maps.newLinkedHashMap();
for (final DataSchemaNode childSchema : childNodes) {
*/
package org.opendaylight.yangtools.yang.data.impl.schema;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
import java.io.InputStream;
import java.net.URI;
import java.util.Collections;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
public class NormalizedDataBuilderTest {
private ContainerSchemaNode containerNode;
private SchemaContext schema;
- SchemaContext parseTestSchema(String... yangPath) {
+ SchemaContext parseTestSchema(final String... yangPath) {
YangParserImpl yangParserImpl = new YangParserImpl();
Set<Module> modules = yangParserImpl.parseYangModelsFromStreams(getTestYangs(yangPath));
return yangParserImpl.resolveSchemaContext(modules);
}
- List<InputStream> getTestYangs(String... yangPaths) {
+ List<InputStream> getTestYangs(final String... yangPaths) {
return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths),
new Function<String, InputStream>() {
- @Override
- public InputStream apply(String input) {
- InputStream resourceAsStream = getClass().getResourceAsStream(input);
- Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
- return resourceAsStream;
- }
- }));
+ @Override
+ public InputStream apply(final String input) {
+ InputStream resourceAsStream = getClass().getResourceAsStream(input);
+ Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
+ return resourceAsStream;
+ }
+ }));
}
@Before
.withChildValue(1)
.withChild(
Builders.<Integer> leafSetEntryBuilder()
- .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
- .build();
+ .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
+ .build();
builder.withChild(leafList);
// list
.mapEntryBuilder()
.withChild(
Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList"))
- .withValue(1).build())
- .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build())
- .withNodeIdentifier(
- new InstanceIdentifier.NodeIdentifierWithPredicates(getNodeIdentifier("list").getNodeType(),
- Collections.singletonMap(getNodeIdentifier("uint32InList").getNodeType(), (Object) 1)))
- .build();
+ .withValue(1).build())
+ .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build())
+ .withNodeIdentifier(
+ new InstanceIdentifier.NodeIdentifierWithPredicates(getNodeIdentifier("list").getNodeType(),
+ Collections.singletonMap(getNodeIdentifier("uint32InList").getNodeType(), (Object) 1)))
+ .build();
MapNode list = Builders.mapBuilder().withChild(listChild1).withNodeIdentifier(getNodeIdentifier("list"))
.build();
.augmentationBuilder()
.withNodeIdentifier(
new InstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(getQName("augmentUint32"))))
- .withChild(
- Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
+ .withChild(
+ Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
.withValue(11).build()).build();
builder.withChild(augmentation);
// .build());
}
- private AugmentationSchema getAugmentationSchemaForChild(ContainerSchemaNode containerNode, QName qName) {
+ private AugmentationSchema getAugmentationSchemaForChild(final ContainerSchemaNode containerNode, final QName qName) {
for (AugmentationSchema augmentationSchema : containerNode.getAvailableAugmentations()) {
if (augmentationSchema.getDataChildByName(qName) != null) {
return augmentationSchema;
throw new IllegalStateException("Unable to find child augmentation in " + containerNode);
}
- private InstanceIdentifier.NodeWithValue getNodeWithValueIdentifier(String localName, Object value) {
+ private InstanceIdentifier.NodeWithValue getNodeWithValueIdentifier(final String localName, final Object value) {
return new InstanceIdentifier.NodeWithValue(getQName(localName), value);
}
- private QName getQName(String localName) {
+ private QName getQName(final String localName) {
String namespace = "namespace";
return new QName(URI.create(namespace), localName);
}
- private InstanceIdentifier.NodeIdentifier getNodeIdentifier(String localName) {
+ private InstanceIdentifier.NodeIdentifier getNodeIdentifier(final String localName) {
return new InstanceIdentifier.NodeIdentifier(getQName(localName));
}
- public static DataSchemaNode getSchemaNode(SchemaContext context, String moduleName, String childNodeName) {
+ public static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName, final String childNodeName) {
for (Module module : context.getModules()) {
if (module.getName().equals(moduleName)) {
DataSchemaNode found = findChildNode(module.getChildNodes(), childNodeName);
throw new IllegalStateException("Unable to find child node " + childNodeName);
}
- static DataSchemaNode findChildNode(Set<DataSchemaNode> children, String name) {
+ private static DataSchemaNode findChildNode(final Iterable<DataSchemaNode> children, final String name) {
List<DataNodeContainer> containers = Lists.newArrayList();
for (DataSchemaNode dataSchemaNode : children) {
- if (dataSchemaNode.getQName().getLocalName().equals(name))
+ if (dataSchemaNode.getQName().getLocalName().equals(name)) {
return dataSchemaNode;
+ }
if (dataSchemaNode instanceof DataNodeContainer) {
containers.add((DataNodeContainer) dataSchemaNode);
} else if (dataSchemaNode instanceof ChoiceNode) {
*/
package org.opendaylight.yangtools.yang.model.api;
+import java.util.Collection;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
/**
* Returns set of all child nodes defined within this DataNodeContainer.
+ * Although the return type is a collection, each node is guaranteed to
+ * be present at most once.
*
* @return child nodes in lexicographical order
*/
- Set<DataSchemaNode> getChildNodes();
+ Collection<DataSchemaNode> getChildNodes();
/**
* Returns set of all groupings defined within this DataNodeContainer.
package org.opendaylight.yangtools.yang.model.util;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
return;
}
- final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
+ final Iterable<DataSchemaNode> childNodes = dataNode.getChildNodes();
if (childNodes != null) {
for (DataSchemaNode childNode : childNodes) {
if (childNode.isAugmenting()) {
@Override
public boolean hasNext() {
if (container.getChildNodes() != null) {
- final Set<DataSchemaNode> childNodes = container.getChildNodes();
+ final Collection<DataSchemaNode> childNodes = container.getChildNodes();
if ((childNodes != null) && !childNodes.isEmpty()) {
return childNodes.iterator().hasNext();
identity_stmt : IDENTITY_KEYWORD string (SEMICOLON | (LEFT_BRACE (identifier_stmt | base_stmt | status_stmt | description_stmt | reference_stmt )* RIGHT_BRACE));
yin_element_arg : string; // TRUE_KEYWORD | FALSE_KEYWORD;
yin_element_stmt : YIN_ELEMENT_KEYWORD yin_element_arg stmtend;
-argument_stmt : ARGUMENT_KEYWORD string (SEMICOLON | (LEFT_BRACE (unknown_statement2)? (yin_element_stmt)? RIGHT_BRACE));
+argument_stmt : ARGUMENT_KEYWORD string (SEMICOLON | (LEFT_BRACE (unknown_statement2)* (yin_element_stmt)? (unknown_statement2)* RIGHT_BRACE));
extension_stmt : EXTENSION_KEYWORD string (SEMICOLON | (LEFT_BRACE (unknown_statement | argument_stmt | status_stmt | description_stmt | reference_stmt )* RIGHT_BRACE));
revision_date_stmt : REVISION_DATE_KEYWORD string stmtend;
revision_stmt : REVISION_KEYWORD string (SEMICOLON | (LEFT_BRACE (description_stmt )? (reference_stmt )? RIGHT_BRACE));
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+
import org.apache.commons.io.IOUtils;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
}
public static Set<DataSchemaNodeBuilder> wrapChildNodes(final String moduleName, final int line,
- final Set<DataSchemaNode> nodes, final SchemaPath parentPath, final QName parentQName) {
- Set<DataSchemaNodeBuilder> result = new LinkedHashSet<>();
+ final Collection<DataSchemaNode> nodes, final SchemaPath parentPath, final QName parentQName) {
+ Set<DataSchemaNodeBuilder> result = new LinkedHashSet<>(nodes.size());
for (DataSchemaNode node : nodes) {
QName qname = QName.create(parentQName, node.getQName().getLocalName());
*/
package org.opendaylight.yangtools.yang.parser.impl;
+import com.google.common.base.Optional;
+import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
-import com.google.common.base.Optional;
-import com.google.common.base.Supplier;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.SetMultimap;
-
@Immutable
final class SchemaContextImpl implements SchemaContext {
private static final Supplier<HashSet<Module>> URI_SET_SUPPLIER = new Supplier<HashSet<Module>>() {
}
};
+ private static final Supplier<ArrayList<Module>> MODULE_LIST_SUPPLIER = new Supplier<ArrayList<Module>>() {
+ @Override
+ public ArrayList<Module> get() {
+ return new ArrayList<>();
+ }
+ };
+
+ private static final Comparator<Module> REVISION_COMPARATOR = new Comparator<Module>() {
+ @Override
+ public int compare(final Module o1, final Module o2) {
+ return o1.getRevision().compareTo(o2.getRevision());
+ }
+ };
+
private final ImmutableMap<ModuleIdentifier, String> identifiersToSources;
private final ImmutableSetMultimap<URI, Module> namespaceToModules;
+ private final ImmutableListMultimap<String, Module> nameToModules;
private final ImmutableSet<Module> modules;
SchemaContextImpl(final Set<Module> modules, final Map<ModuleIdentifier, String> identifiersToSources) {
this.modules = ImmutableSet.copyOf(ModuleDependencySort.sort(modules.toArray(new Module[modules.size()])));
/*
- * The most common lookup is from Namespace->Module. Invest some quality time in
- * building that up.
+ * The most common lookup is from Namespace->Module.
+ *
+ * RESTCONF performs lookups based on module name only, where it wants
+ * to receive the latest revision
+ *
+ * Invest some quality time in building up lookup tables for both.
*/
- final SetMultimap<URI, Module> multimap = Multimaps.newSetMultimap(
+ final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
new TreeMap<URI, Collection<Module>>(), URI_SET_SUPPLIER);
+ final ListMultimap<String, Module> nameMap = Multimaps.newListMultimap(
+ new TreeMap<String, Collection<Module>>(), MODULE_LIST_SUPPLIER);
for (Module m : modules) {
- multimap.put(m.getNamespace(), m);
+ nameMap.put(m.getName(), m);
+ nsMap.put(m.getNamespace(), m);
+ }
+ for (String key : nameMap.keySet()) {
+ Collections.sort(nameMap.get(key), REVISION_COMPARATOR);
}
- namespaceToModules = ImmutableSetMultimap.copyOf(multimap);
+ namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
+ nameToModules = ImmutableListMultimap.copyOf(nameMap);
}
@Override
@Override
public Module findModuleByName(final String name, final Date revision) {
- if (name != null) {
- for (final Module module : modules) {
- if (revision == null) {
- if (module.getName().equals(name)) {
- return module;
- }
- } else if (module.getName().equals(name) && module.getRevision().equals(revision)) {
+ final List<Module> mods = nameToModules.get(name);
+ if (mods != null) {
+ for (final Module module : mods) {
+ if (revision == null || module.getRevision().equals(revision)) {
return module;
}
}
}
+
return null;
}
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
+
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
+import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.NodeImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Date DEFAULT_REVISION = new Date(0);
private static final Logger LOGGER = LoggerFactory.getLogger(ModuleDependencySort.class);
+ private static final Function<Node, Module> TOPOLOGY_FUNCTION = new Function<TopologicalSort.Node, Module>() {
+ @Override
+ public Module apply(final TopologicalSort.Node input) {
+ ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
+ return moduleOrModuleBuilder.getModule();
+ }
+ };
/**
* It is not desirable to instance this class
List<TopologicalSort.Node> sorted = sortInternal(ModuleOrModuleBuilder.fromAll(asList(modules),
Collections.<ModuleBuilder>emptyList()));
// Cast to Module from Node and return
- return Lists.transform(sorted, new Function<TopologicalSort.Node, Module>() {
-
- @Override
- public Module apply(final TopologicalSort.Node input) {
- ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
- return moduleOrModuleBuilder.getModule();
- }
- });
+ return Lists.transform(sorted, TOPOLOGY_FUNCTION);
}
private static List<TopologicalSort.Node> sortInternal(final Iterable<ModuleOrModuleBuilder> modules) {
private final Optional<Module> maybeModule;
private final Optional<ModuleBuilder> maybeModuleBuilder;
- ModuleOrModuleBuilder(Module module) {
+ ModuleOrModuleBuilder(final Module module) {
maybeModule = Optional.of(module);
maybeModuleBuilder = Optional.absent();
}
- ModuleOrModuleBuilder(ModuleBuilder moduleBuilder) {
+ ModuleOrModuleBuilder(final ModuleBuilder moduleBuilder) {
maybeModule = Optional.absent();
maybeModuleBuilder = Optional.of(moduleBuilder);
}
return maybeModuleBuilder.get();
}
- static List<ModuleOrModuleBuilder> fromAll(Collection<Module> modules, Collection<ModuleBuilder> moduleBuilders) {
+ static List<ModuleOrModuleBuilder> fromAll(final Collection<Module> modules, final Collection<ModuleBuilder> moduleBuilders) {
List<ModuleOrModuleBuilder> result = new ArrayList<>(modules.size() + moduleBuilders.size());
for(Module m: modules){
result.add(new ModuleOrModuleBuilder(m));
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
+
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
expectedSchemaPath = SchemaPath.create(qnames, true);
assertEquals(expectedSchemaPath, augment.getTargetPath());
- Set<DataSchemaNode> augmentChildren = augment.getChildNodes();
+ Collection<DataSchemaNode> augmentChildren = augment.getChildNodes();
assertEquals(4, augmentChildren.size());
for (DataSchemaNode dsn : augmentChildren) {
TestUtils.checkIsAugmenting(dsn, false);
qnames.add(qname);
expectedPath = SchemaPath.create(qnames, true);
assertEquals(expectedPath, id.getPath());
- Set<DataSchemaNode> idChildren = id.getChildNodes();
+ Collection<DataSchemaNode> idChildren = id.getChildNodes();
assertEquals(1, idChildren.size());
// case node1
qnames.set(4, qname);
expectedPath = SchemaPath.create(qnames, true);
assertEquals(expectedPath, node1.getPath());
- Set<DataSchemaNode> node1Children = node1.getChildNodes();
+ Collection<DataSchemaNode> node1Children = node1.getChildNodes();
assertTrue(node1Children.isEmpty());
// case node2
qnames.set(4, qname);
expectedPath = SchemaPath.create(qnames, true);
assertEquals(expectedPath, node2.getPath());
- Set<DataSchemaNode> node2Children = node2.getChildNodes();
+ Collection<DataSchemaNode> node2Children = node2.getChildNodes();
assertTrue(node2Children.isEmpty());
// case node3
qnames.set(4, qname);
expectedPath = SchemaPath.create(qnames, true);
assertEquals(expectedPath, node3.getPath());
- Set<DataSchemaNode> node3Children = node3.getChildNodes();
+ Collection<DataSchemaNode> node3Children = node3.getChildNodes();
assertEquals(1, node3Children.size());
// test cases
assertEquals(qnames[3], attach.getQName());
expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
assertEquals(expectedPath, attach.getPath());
- Set<DataSchemaNode> attachChildren = attach.getChildNodes();
+ Collection<DataSchemaNode> attachChildren = attach.getChildNodes();
assertEquals(1, attachChildren.size());
// case create
assertEquals(qnames[3], create.getQName());
expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
assertEquals(expectedPath, create.getPath());
- Set<DataSchemaNode> createChildren = create.getChildNodes();
+ Collection<DataSchemaNode> createChildren = create.getChildNodes();
assertEquals(1, createChildren.size());
// case attach
assertEquals(qnames[3], destroy.getQName());
expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
assertEquals(expectedPath, destroy.getPath());
- Set<DataSchemaNode> destroyChildren = destroy.getChildNodes();
+ Collection<DataSchemaNode> destroyChildren = destroy.getChildNodes();
assertEquals(1, destroyChildren.size());
}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.Module;
+
+/**
+ * Test antlr grammar capability to parse unknown node in extension argument
+ * declaration.
+ *
+ * Not that everything under unknown node is unknown node.
+ */
+public class Bug1413Test {
+
+ @Test
+ public void test() throws Exception {
+ Set<Module> modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI());
+ Module bug1413 = TestUtils.findModule(modules, "bug1413");
+ assertNotNull(bug1413);
+
+ List<ExtensionDefinition> extensions = bug1413.getExtensionSchemaNodes();
+ assertEquals(1, extensions.size());
+
+ ExtensionDefinition info = extensions.get(0);
+ assertEquals("text", info.getArgument());
+ assertTrue(info.isYinElement());
+ }
+
+}
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
Set<GroupingDefinition> groupings = testModule.getGroupings();
assertEquals(1, groupings.size());
GroupingDefinition grouping = groupings.iterator().next();
- Set<DataSchemaNode> children = grouping.getChildNodes();
+ Collection<DataSchemaNode> children = grouping.getChildNodes();
assertEquals(5, children.size());
}
assertEquals(1, usesAugments.size());
AugmentationSchema augment = usesAugments.iterator().next();
assertEquals("inner augment", augment.getDescription());
- Set<DataSchemaNode> children = augment.getChildNodes();
+ Collection<DataSchemaNode> children = augment.getChildNodes();
assertEquals(1, children.size());
DataSchemaNode leaf = children.iterator().next();
assertTrue(leaf instanceof LeafSchemaNode);
SchemaPath expectedPath;
// grouping-U
- Set<DataSchemaNode> childNodes = gu.getChildNodes();
+ Collection<DataSchemaNode> childNodes = gu.getChildNodes();
assertEquals(7, childNodes.size());
LeafSchemaNode leafGroupingU = (LeafSchemaNode) gu.getDataChildByName("leaf-grouping-U");
import java.io.IOException;
import java.net.URISyntaxException;
+import java.util.Collection;
import java.util.Set;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
Set<Module> modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
Module foo = TestUtils.findModule(modules, "foo");
- Set<DataSchemaNode> childNodes = foo.getChildNodes();
+ Collection<DataSchemaNode> childNodes = foo.getChildNodes();
String[] expectedOrder = new String[] { "int32-leaf", "string-leaf", "length-leaf", "decimal-leaf",
"decimal-leaf2", "ext", "union-leaf", "custom-union-leaf", "transfer", "datas", "mycont", "data",
"how", "address", "port", "addresses", "peer" };
assertEquals(1, groupings.size());
GroupingDefinition target = groupings.iterator().next();
- Set<DataSchemaNode> childNodes = target.getChildNodes();
+ Collection<DataSchemaNode> childNodes = target.getChildNodes();
String[] expectedOrder = new String[] { "data", "how", "address", "port", "addresses" };
String[] actualOrder = new String[childNodes.size()];
public void testOrderingNestedChildNodes3() throws Exception {
Module baz = TestUtils.loadModule(getClass().getResourceAsStream("/ordering/foo.yang"));
ContainerSchemaNode x = (ContainerSchemaNode) baz.getDataChildByName("x");
- Set<DataSchemaNode> childNodes = x.getChildNodes();
+ Collection<DataSchemaNode> childNodes = x.getChildNodes();
- String[] expectedOrder = new String[] { "x15", "x10", "x5", "x1", "a5", "a1", "x2", "b5", "b1", "x3", "ax15",
- "ax5" };
+ String[] expectedOrder = new String[] { "x15", "x10", "x5", "x1", "a5", "a1", "x2", "b5", "b1", "x3", "ax15", "ax5" };
String[] actualOrder = new String[childNodes.size()];
int i = 0;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.Lists;
+
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
path.offer(expectedQName);
SchemaPath expectedPath = SchemaPath.create(path, true);
assertEquals(expectedPath, pcreq.getPath());
- Set<DataSchemaNode> childNodes = pcreq.getChildNodes();
+ Collection<DataSchemaNode> childNodes = pcreq.getChildNodes();
assertEquals(4, childNodes.size());
// * |-- leaf version
LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName("version");
--- /dev/null
+module bug1413 {
+ yang-version 1;
+ namespace "odl:test:bug1413";
+ prefix "b1413";
+
+ revision "2014-07-25" {
+ }
+
+
+ extension info {
+ argument text {
+ yin-element true;
+ ext:arg-type {
+ type string;
+ }
+ }
+ }
+
+}