From: Giovanni Meo Date: Wed, 24 Apr 2013 16:02:49 +0000 (+0000) Subject: Merge "Fixed validation bug of YANG import statement" X-Git-Tag: releasepom-0.1.0~535 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=fc7a2ae9b5c6b82d463fe612509a157e3f261653;hp=332270f5969239c0aceeca36b9c238735e2bc49f Merge "Fixed validation bug of YANG import statement" --- diff --git a/opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java b/opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java index d4c1fd3045..3730a71f1e 100644 --- a/opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java +++ b/opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java @@ -130,9 +130,11 @@ public class ArpHandler implements IHostFinder, IListenDataPacket { protected void handleARPPacket(Ethernet eHeader, ARP pkt, NodeConnector p) { if (pkt.getOpCode() == 0x1) { - logger.debug("Received ARP REQUEST Packet from NodeConnector:" + p); + logger.debug("Received ARP REQUEST Packet from NodeConnector: {}", + p); } else { - logger.debug("Received ARP REPLY Packet from NodeConnector:" + p); + logger.debug("Received ARP REPLY Packet from NodeConnector: {}", + p); } InetAddress targetIP = null; try { @@ -328,13 +330,13 @@ public class ArpHandler implements IHostFinder, IListenDataPacket { Node n = host.getnodeconnectorNode(); if (n == null) { logger.error("cannot send UcastARP because cannot extract node " - + "from HostNodeConnector:" + host); + + "from HostNodeConnector: {}", host); return; } NodeConnector outPort = host.getnodeConnector(); if (outPort == null) { logger.error("cannot send UcastARP because cannot extract " - + "outPort from HostNodeConnector:" + host); + + "outPort from HostNodeConnector: {}", host); return; } @@ -489,8 +491,8 @@ public class ArpHandler implements IHostFinder, IListenDataPacket { return PacketResult.IGNORED; } logger - .trace("Received a frame of size:" - + inPkt.getPacketData().length); + .trace("Received a frame of size: {}", + inPkt.getPacketData().length); Packet formattedPak = this.dataPacketService.decodeDataPacket(inPkt); if (formattedPak instanceof Ethernet) { Object nextPak = formattedPak.getPayload(); diff --git a/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java b/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java index 031434f8e8..68960baa07 100644 --- a/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java +++ b/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java @@ -118,7 +118,7 @@ public interface IClusterServices { * * @return ConcurrentHashMap to be used to modify the data structure */ - ConcurrentMap getCache(String containerName, String cacheName); + ConcurrentMap getCache(String containerName, String cacheName); /** * Destroy a cachename given containerName/cachename, if doesn't exist diff --git a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java index 476b1b12f5..3034d3ca6d 100644 --- a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java +++ b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java @@ -113,15 +113,15 @@ public class ClusterManager implements IClusterServices { } while (supernodes.hasMoreTokens()) { String curr_supernode = supernodes.nextToken(); - logger.debug("Examining supernode " + curr_supernode); + logger.debug("Examining supernode {}", curr_supernode); StringTokenizer host_port = new StringTokenizer(curr_supernode, "[]"); String host; String port; Integer port_num = gossipRouterPortDefault; if (host_port.countTokens() > 2) { - logger.error("Error parsing supernode " + curr_supernode - + " proceed to the next one"); + logger.error("Error parsing supernode {} proceed to the next one", + curr_supernode); continue; } host = host_port.nextToken(); @@ -184,13 +184,13 @@ public class ClusterManager implements IClusterServices { for (InetAddress myAddr : myAddresses) { if (myAddr.isLoopbackAddress() || myAddr.isLinkLocalAddress()) { - logger.debug("Skipping local address " - + myAddr.getHostAddress()); + logger.debug("Skipping local address {}", + myAddr.getHostAddress()); continue; } else { // First non-local address myBind = myAddr.getHostAddress(); - logger.debug("First non-local address " + myBind); + logger.debug("First non-local address {}", myBind); break; } } @@ -199,7 +199,7 @@ public class ClusterManager implements IClusterServices { .getProperty("jgroups.tcp.address"); if (jgroupAddress == null) { if (myBind != null) { - logger.debug("Set bind address to be " + myBind); + logger.debug("Set bind address to be {}", myBind); System.setProperty("jgroups.tcp.address", myBind); } else { logger @@ -207,8 +207,8 @@ public class ClusterManager implements IClusterServices { System.setProperty("jgroups.tcp.address", "127.0.0.1"); } } else { - logger.debug("jgroup.tcp.address already set to be " - + jgroupAddress); + logger.debug("jgroup.tcp.address already set to be {}", + jgroupAddress); } } catch (UnknownHostException uhe) { logger @@ -220,14 +220,14 @@ public class ClusterManager implements IClusterServices { // host list System.setProperty("jgroups.tcpgossip.initial_hosts", sanitized_supernodes_list.toString()); - logger.debug("jgroups.tcp.address set to " - + System.getProperty("jgroups.tcp.address")); - logger.debug("jgroups.tcpgossip.initial_hosts set to " - + System.getProperty("jgroups.tcpgossip.initial_hosts")); + logger.debug("jgroups.tcp.address set to {}", + System.getProperty("jgroups.tcp.address")); + logger.debug("jgroups.tcpgossip.initial_hosts set to {}", + System.getProperty("jgroups.tcpgossip.initial_hosts")); GossipRouter res = null; if (amIGossipRouter) { - logger.info("I'm a GossipRouter will listen on port " - + gossipRouterPort); + logger.info("I'm a GossipRouter will listen on port {}", + gossipRouterPort); res = new GossipRouter(gossipRouterPort); } return res; @@ -241,10 +241,8 @@ public class ClusterManager implements IClusterServices { this.gossiper.start(); logger.info("Started GossipRouter"); } catch (Exception e) { - logger.error("GossipRouter didn't start exception " + e - + " met"); - logger.error("Stack Trace that raised the exception"); - logger.error("",e); + logger.error("GossipRouter didn't start. Exception Stack Trace", + e); } } logger.info("Starting the ClusterManager"); @@ -264,7 +262,7 @@ public class ClusterManager implements IClusterServices { this.cm = null; this.stop(); } - logger.debug("Cache Manager has value " + this.cm); + logger.debug("Cache Manager has value {}", this.cm); } public void stop() { diff --git a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java index 2afbabe87f..7bf495426f 100644 --- a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java +++ b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java @@ -116,7 +116,7 @@ abstract public class ClusterManagerCommon implements IClusterServicesCommon { Dictionary props = c.getServiceProperties(); if (props != null) { this.containerName = (String) props.get("containerName"); - logger.debug("Running containerName:" + this.containerName); + logger.debug("Running containerName: {}", this.containerName); } else { // In the Global instance case the containerName is empty this.containerName = ""; diff --git a/opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java b/opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java index 13d05bb7be..035b0d3433 100644 --- a/opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java +++ b/opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java @@ -65,7 +65,7 @@ abstract public class ClusterManagerCommon implements IClusterServicesCommon { Dictionary props = c.getServiceProperties(); if (props != null) { this.containerName = (String) props.get("containerName"); - logger.debug("Running containerName:" + this.containerName); + logger.debug("Running containerName: {}", this.containerName); } else { // In the Global instance case the containerName is empty this.containerName = ""; @@ -88,7 +88,7 @@ abstract public class ClusterManagerCommon implements IClusterServicesCommon { CacheConfigException { ConcurrentMap res = this.caches.get(cacheName); if (res == null) { - res = new ConcurrentHashMap(); + res = new ConcurrentHashMap(); this.caches.put(cacheName, res); return res; } diff --git a/opendaylight/clustering/test/src/main/java/org/opendaylight/controller/clustering/test/internal/SimpleClient.java b/opendaylight/clustering/test/src/main/java/org/opendaylight/controller/clustering/test/internal/SimpleClient.java index 3e9717fa62..b6ab95db33 100644 --- a/opendaylight/clustering/test/src/main/java/org/opendaylight/controller/clustering/test/internal/SimpleClient.java +++ b/opendaylight/clustering/test/src/main/java/org/opendaylight/controller/clustering/test/internal/SimpleClient.java @@ -243,6 +243,7 @@ public class SimpleClient implements CommandProvider { } } + @SuppressWarnings("deprecation") //IGetUpdates intentionally deprecated public void _unlisten(CommandInterpreter ci) { if (this.icluster == null) { ci.println("\nNo Clustering services available"); @@ -370,7 +371,7 @@ public class SimpleClient implements CommandProvider { } public void _dumper(CommandInterpreter ci) { - ConcurrentMap c; + ConcurrentMap c; String containerName = ci.nextArgument(); if (containerName == null) { ci.println("containerName not supplied"); @@ -381,10 +382,10 @@ public class SimpleClient implements CommandProvider { ci.println("Cache not supplied"); return; } - c = (ConcurrentMap) this.icluster.getCache(containerName, cacheName); + c = (ConcurrentMap) this.icluster.getCache(containerName, cacheName); if (c != null) { - for (Object e : c.entrySet()) { - Map.Entry entry = (Map.Entry) e; + for (Map.Entry e : c.entrySet()) { + Map.Entry entry = e; Object v = entry.getValue(); String res = ""; if (v != null) { @@ -437,6 +438,7 @@ public class SimpleClient implements CommandProvider { } } + @SuppressWarnings("deprecation") //TODO: remove call to deprecated amIStandby public void _getRole(CommandInterpreter ci) { if (this.icluster == null) { ci.println("\nNo Clustering services available"); @@ -449,6 +451,7 @@ public class SimpleClient implements CommandProvider { ci.println("My role is: " + role); } + @SuppressWarnings("deprecation") //TODO: remove call to deprecated getActiveAddres public void _getActive(CommandInterpreter ci) { if (this.icluster == null) { ci.println("\nNo Clustering services available"); @@ -458,6 +461,7 @@ public class SimpleClient implements CommandProvider { + this.icluster.getActiveAddress()); } + @SuppressWarnings("deprecation") //TODO: remove use of deprecated listenRoleChange public void _listenActive(CommandInterpreter ci) { if (this.icluster == null) { ci.println("\nNo Clustering services available"); @@ -473,6 +477,7 @@ public class SimpleClient implements CommandProvider { ci.println("Register listenRoleChanges"); } + @SuppressWarnings("deprecation") //TODO: remove deprecated call to unlistenRoleChange public void _unlistenActive(CommandInterpreter ci) { if (this.icluster == null) { ci.println("\nNo Clustering services available"); diff --git a/opendaylight/configuration/implementation/src/main/java/org/opendaylight/controller/configuration/internal/ConfigurationContainerImpl.java b/opendaylight/configuration/implementation/src/main/java/org/opendaylight/controller/configuration/internal/ConfigurationContainerImpl.java index efe966b719..3d0c5659d6 100644 --- a/opendaylight/configuration/implementation/src/main/java/org/opendaylight/controller/configuration/internal/ConfigurationContainerImpl.java +++ b/opendaylight/configuration/implementation/src/main/java/org/opendaylight/controller/configuration/internal/ConfigurationContainerImpl.java @@ -83,14 +83,14 @@ public class ConfigurationContainerImpl implements public Status saveConfiguration() { boolean success = true; for (IConfigurationContainerAware configurationAware : configurationAwareList) { - logger.info("Save Config triggered for " - + configurationAware.getClass().getSimpleName()); + logger.info("Save Config triggered for {}", + configurationAware.getClass().getSimpleName()); Status status = configurationAware.saveConfiguration(); if (!status.isSuccess()) { success = false; - logger.info("Failed to save config for " - + configurationAware.getClass().getSimpleName()); + logger.info("Failed to save config for {}", + configurationAware.getClass().getSimpleName()); } } if (success) { diff --git a/opendaylight/configuration/implementation/src/main/java/org/opendaylight/controller/configuration/internal/ConfigurationImpl.java b/opendaylight/configuration/implementation/src/main/java/org/opendaylight/controller/configuration/internal/ConfigurationImpl.java index a8f7da69a0..ee15b4a9c2 100644 --- a/opendaylight/configuration/implementation/src/main/java/org/opendaylight/controller/configuration/internal/ConfigurationImpl.java +++ b/opendaylight/configuration/implementation/src/main/java/org/opendaylight/controller/configuration/internal/ConfigurationImpl.java @@ -84,8 +84,8 @@ public class ConfigurationImpl implements IConfigurationService { Status status = configurationAware.saveConfiguration(); if (!status.isSuccess()) { success = false; - logger.info("Failed to save config for " - + configurationAware.getClass().getName()); + logger.info("Failed to save config for {}", + configurationAware.getClass().getName()); } } if (success) { diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index 8a74689398..f05c95bb8c 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -40,7 +40,8 @@ ../../configuration/implementation ../../routing/dijkstra_implementation ../../arphandler - ../../forwardingrulesmanager + ../../forwardingrulesmanager/api + ../../forwardingrulesmanager/implementation ../../hosttracker ../../containermanager/api ../../containermanager/implementation diff --git a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java index 4c2ea7313a..ad6ea6bc10 100644 --- a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java +++ b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java @@ -451,8 +451,8 @@ public class StaticRoutingImplementation implements IfNewHostNotify, staticRoutesFileName = ROOT + "staticRouting_" + containerName + ".conf"; - log.debug("forwarding.staticrouting starting on container " - + containerName); + log.debug("forwarding.staticrouting starting on container {}", + containerName); //staticRoutes = new ConcurrentHashMap(); allocateCaches(); retrieveCaches(); diff --git a/opendaylight/forwardingrulesmanager/pom.xml b/opendaylight/forwardingrulesmanager/api/pom.xml similarity index 92% rename from opendaylight/forwardingrulesmanager/pom.xml rename to opendaylight/forwardingrulesmanager/api/pom.xml index 27c3b1ecc1..6b639e3c63 100644 --- a/opendaylight/forwardingrulesmanager/pom.xml +++ b/opendaylight/forwardingrulesmanager/api/pom.xml @@ -6,7 +6,7 @@ org.opendaylight.controller commons.opendaylight 1.4.0-SNAPSHOT - ../commons/opendaylight + ../../commons/opendaylight org.opendaylight.controller @@ -49,12 +49,9 @@ org.eclipse.osgi.framework.console, org.osgi.framework - - org.opendaylight.controller.forwardingrulesmanager.internal.Activator - - + org.opendaylight.controller.hosttracker - + diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java similarity index 94% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java index bf5062985d..f3429e62b1 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -76,8 +75,8 @@ public class FlowConfig implements Serializable { private String status; /* - * The order of the object data defined below is used directly in the UI built using JSP. - * Hence try to keep the order in a more logical way. + * The order of the object data defined below is used directly in the UI + * built using JSP. Hence try to keep the order in a more logical way. */ @XmlElement private String installInHw; @@ -216,14 +215,14 @@ public class FlowConfig implements Serializable { public void setInstallInHw(boolean inHw) { installInHw = inHw ? "true" : "false"; } - + public String getInstallInHw() { - return installInHw; + return installInHw; } public boolean isInternalFlow() { // Controller generated static flows have name starting with "**" - return (this.name != null && this.name.startsWith("**")); + return (this.name != null && this.name.startsWith("**")); } public String getName() { @@ -608,14 +607,15 @@ public class FlowConfig implements Serializable { } } - log.debug("Get Nexthop address = {} Type = {}", address, setNHType.toString()); + log.debug("Get Nexthop address = {} Type = {}", address, + setNHType.toString()); if (setNHType == SetNextHopType.RESOLVE_L2RW) { try { return InetAddress.getByName(address); } catch (Exception e) { - log - .debug("Exception during nextHopAddress resolution : ", - e); + log.debug( + "Exception during nextHopAddress resolution : ", + e); } } } @@ -641,10 +641,9 @@ public class FlowConfig implements Serializable { .compile("([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}"); Matcher mm = macPattern.matcher(mac); if (!mm.matches()) { - log - .debug( - "Ethernet address {} is not valid. Example: 00:05:b9:7c:81:5f", - mac); + log.debug( + "Ethernet address {} is not valid. Example: 00:05:b9:7c:81:5f", + mac); return false; } return true; @@ -657,8 +656,7 @@ public class FlowConfig implements Serializable { } if (sw == null) { - log - .debug("switch info is not available. Skip checking if port is part of a switch or not."); + log.debug("switch info is not available. Skip checking if port is part of a switch or not."); return true; } @@ -713,11 +711,11 @@ public class FlowConfig implements Serializable { // Check against each container's flow Flow flow = this.getFlow(); - // Configuration is rejected if it conflicts with _all_ the container flows + // Configuration is rejected if it conflicts with _all_ the container + // flows for (ContainerFlow cFlow : cFlowList) { if (cFlow.allowsFlow(flow)) { - log - .trace("Config is congruent with at least one container flow"); + log.trace("Config is congruent with at least one container flow"); return false; } } @@ -756,8 +754,7 @@ public class FlowConfig implements Serializable { } } if (sw == null) { - resultStr - .append(String.format("Node %s not found", node)); + resultStr.append(String.format("Node %s not found", node)); return false; } } else { @@ -783,8 +780,7 @@ public class FlowConfig implements Serializable { if (isPortValid(sw, port) == false) { resultStr .append(String - .format( - "Ingress port %d is not valid for the Switch", + .format("Ingress port %d is not valid for the Switch", port)); if ((container != null) && !container.getName().equals( @@ -843,8 +839,7 @@ public class FlowConfig implements Serializable { if ((dlSrc != null) && !isL2AddressValid(dlSrc)) { resultStr .append(String - .format( - "Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f", + .format("Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f", dlSrc)); return false; } @@ -852,8 +847,7 @@ public class FlowConfig implements Serializable { if ((dlDst != null) && !isL2AddressValid(dlDst)) { resultStr .append(String - .format( - "Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f", + .format("Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f", dlDst)); return false; } @@ -929,8 +923,7 @@ public class FlowConfig implements Serializable { if (isPortValid(sw, port) == false) { resultStr .append(String - .format( - "Output port %d is not valid for this switch", + .format("Output port %d is not valid for this switch", port)); if ((container != null) && !container.getName().equals( @@ -965,8 +958,8 @@ public class FlowConfig implements Serializable { if (sstr.matches()) { if (!NetUtils.isIPv4AddressValid(sstr.group(1))) { resultStr.append(String.format( - "IP source address %s is not valid", sstr - .group(1))); + "IP source address %s is not valid", + sstr.group(1))); return false; } continue; @@ -1007,8 +1000,7 @@ public class FlowConfig implements Serializable { && !isVlanPriorityValid(sstr.group(1))) { resultStr .append(String - .format( - "Vlan priority %s is not in the range 0 - 7", + .format("Vlan priority %s is not in the range 0 - 7", sstr.group(1))); return false; } @@ -1023,8 +1015,7 @@ public class FlowConfig implements Serializable { && !isL2AddressValid(sstr.group(1))) { resultStr .append(String - .format( - "Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f", + .format("Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f", sstr.group(1))); return false; } @@ -1039,8 +1030,7 @@ public class FlowConfig implements Serializable { && !isL2AddressValid(sstr.group(1))) { resultStr .append(String - .format( - "Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f", + .format("Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f", sstr.group(1))); return false; } @@ -1055,8 +1045,7 @@ public class FlowConfig implements Serializable { && !isTOSBitsValid(sstr.group(1))) { resultStr .append(String - .format( - "IP ToS bits %s is not in the range 0 - 63", + .format("IP ToS bits %s is not in the range 0 - 63", sstr.group(1))); return false; } @@ -1085,8 +1074,7 @@ public class FlowConfig implements Serializable { && !isTpPortValid(sstr.group(1))) { resultStr .append(String - .format( - "Transport destination port %s is not valid", + .format("Transport destination port %s is not valid", sstr.group(1))); return false; } @@ -1115,8 +1103,8 @@ public class FlowConfig implements Serializable { return false; } } catch (NumberFormatException e) { - resultStr.append(String.format("Invalid number format %s", e - .getMessage())); + resultStr.append(String.format("Invalid number format %s", + e.getMessage())); return false; } @@ -1124,25 +1112,26 @@ public class FlowConfig implements Serializable { } public FlowEntry getFlowEntry() { - return new FlowEntry(FlowConfig.staticFlowsGroup, this.name, this - .getFlow(), this.getNode()); + return new FlowEntry(FlowConfig.staticFlowsGroup, this.name, + this.getFlow(), this.getNode()); } public Flow getFlow() { Match match = new Match(); if (this.ingressPort != null) { - match.setField(MatchType.IN_PORT, NodeConnectorCreator - .createOFNodeConnector(Short.parseShort(ingressPort), - getNode())); + match.setField( + MatchType.IN_PORT, + NodeConnectorCreator.createOFNodeConnector( + Short.parseShort(ingressPort), getNode())); } if (this.dlSrc != null) { - match.setField(MatchType.DL_SRC, HexEncode - .bytesFromHexString(this.dlSrc)); + match.setField(MatchType.DL_SRC, + HexEncode.bytesFromHexString(this.dlSrc)); } if (this.dlDst != null) { - match.setField(MatchType.DL_DST, HexEncode - .bytesFromHexString(this.dlDst)); + match.setField(MatchType.DL_DST, + HexEncode.bytesFromHexString(this.dlDst)); } if (this.etherType != null) { match.setField(MatchType.DL_TYPE, Integer.decode(etherType) @@ -1152,8 +1141,8 @@ public class FlowConfig implements Serializable { match.setField(MatchType.DL_VLAN, Short.parseShort(this.vlanId)); } if (this.vlanPriority != null) { - match.setField(MatchType.DL_VLAN_PR, Byte - .parseByte(this.vlanPriority)); + match.setField(MatchType.DL_VLAN_PR, + Byte.parseByte(this.vlanPriority)); } if (this.nwSrc != null) { String parts[] = this.nwSrc.split("/"); @@ -1178,8 +1167,8 @@ public class FlowConfig implements Serializable { match.setField(MatchType.NW_DST, ip, mask); } if (this.protocol != null) { - match.setField(MatchType.NW_PROTO, IPProtocols - .getProtocolNumberByte(this.protocol)); + match.setField(MatchType.NW_PROTO, + IPProtocols.getProtocolNumberByte(this.protocol)); } if (this.tosBits != null) { match.setField(MatchType.NW_TOS, Byte.parseByte(this.tosBits)); @@ -1246,9 +1235,9 @@ public class FlowConfig implements Serializable { } /* - * Parses the actions string and return the List of SAL Action - * No syntax check run, as this function will be called when the - * config validation check has already been performed + * Parses the actions string and return the List of SAL Action No syntax + * check run, as this function will be called when the config validation + * check has already been performed */ private List getActionList() { List actionList = new ArrayList(); @@ -1265,8 +1254,8 @@ public class FlowConfig implements Serializable { if (n.group(1) != null) { short ofPort = Short.parseShort(n.group(1)); actionList.add(new Output(NodeConnectorCreator - .createOFNodeConnector(ofPort, this - .getNode()))); + .createOFNodeConnector(ofPort, + this.getNode()))); } } } @@ -1319,8 +1308,8 @@ public class FlowConfig implements Serializable { ActionType.SET_VLAN_ID.toString() + "=(.*)").matcher( actiongrp); if (sstr.matches()) { - actionList.add(new SetVlanId(Short - .parseShort(sstr.group(1)))); + actionList.add(new SetVlanId( + Short.parseShort(sstr.group(1)))); continue; } diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntry.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntry.java similarity index 87% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntry.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntry.java index aaf34a6a3f..2e174d25e2 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntry.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntry.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -22,14 +21,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Represents a flow applications request Forwarding Rules Manager to install - * on a network node. A FlowEntry is constituted of a flow (match + actions), - * the target network node, and the flow name. It also includes a group name. - * For instance the flows constituting a policy all share the same group name. + * Represents a flow applications request Forwarding Rules Manager to install on + * a network node. A FlowEntry is constituted of a flow (match + actions), the + * target network node, and the flow name. It also includes a group name. For + * instance the flows constituting a policy all share the same group name. */ public class FlowEntry implements Cloneable, Serializable { protected static final Logger logger = LoggerFactory - .getLogger(FlowEntry.class); + .getLogger(FlowEntry.class); private static final long serialVersionUID = 1L; private static final Logger log = LoggerFactory.getLogger(FlowEntry.class); private String groupName; // group name @@ -54,7 +53,7 @@ public class FlowEntry implements Cloneable, Serializable { /** * Return the actual Flow contained in this entry - * + * * @return the flow */ public Flow getFlow() { @@ -84,7 +83,7 @@ public class FlowEntry implements Cloneable, Serializable { cloned = (FlowEntry) super.clone(); cloned.flow = this.flow.clone(); } catch (CloneNotSupportedException e) { - log.warn("exception in clone", e); + log.warn("exception in clone", e); } return cloned; } @@ -115,13 +114,12 @@ public class FlowEntry implements Cloneable, Serializable { /** * Merges the current Flow with the passed Container Flow - * - * Note: Container Flow merging is not an injective function. - * Be m1 and m2 two different matches, and be f() the flow merge - * function, such that y1 = f(m1) and y2 = f(m2) are the two merged - * matches, we may have: y1 = y2 - * - * + * + * Note: Container Flow merging is not an injective function. Be m1 and m2 + * two different matches, and be f() the flow merge function, such that y1 = + * f(m1) and y2 = f(m2) are the two merged matches, we may have: y1 = y2 + * + * * @param containerFlow * @return this merged FlowEntry */ diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntryInstall.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntryInstall.java similarity index 88% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntryInstall.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntryInstall.java index ac0a4cccd4..dfe331ad5f 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntryInstall.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntryInstall.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -15,15 +14,15 @@ import org.opendaylight.controller.sal.core.ContainerFlow; import org.opendaylight.controller.sal.core.Node; /** - * The flow database object representing the flow entry to install on - * the network node. It contains the original flow entry FRM was - * requested to install, the container flow with which that entry had - * to be merged and the resultant merged flow entry, which is the - * one that was eventually installed on the network node - * - * Note: If the container flow is null, the install entry will be a clone - * of the original entry - * + * The flow database object representing the flow entry to install on the + * network node. It contains the original flow entry FRM was requested to + * install, the container flow with which that entry had to be merged and the + * resultant merged flow entry, which is the one that was eventually installed + * on the network node + * + * Note: If the container flow is null, the install entry will be a clone of the + * original entry + * */ public class FlowEntryInstall { private FlowEntry original; diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManager.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManager.java similarity index 57% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManager.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManager.java index 60d74295ee..d0efe4a83f 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManager.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManager.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -19,42 +18,46 @@ import org.opendaylight.controller.sal.utils.Status; /** * Interface that describes methods for installing or removing forwarding rules * and to access to the flows database. - * + * */ public interface IForwardingRulesManager { /** - * It requests FRM to install the passed Flow Entry. FRM will request - * the SDN protocol plugin to install the flow on the network node. - * Based on the result of this operation FRM will update its database - * accordingly and will return the proper {@code Status} code. + * It requests FRM to install the passed Flow Entry. FRM will request the + * SDN protocol plugin to install the flow on the network node. Based on the + * result of this operation FRM will update its database accordingly and + * will return the proper {@code Status} code. * - * @param flow the flow entry to install - * @return the {@code Status} object indicating the result of this action. - */ + * @param flow + * the flow entry to install + * @return the {@code Status} object indicating the result of this action. + */ public Status installFlowEntry(FlowEntry flow); /** - * It requests FRM to remove the passed Flow Entry. FRM will request - * the SDN protocol plugin to uninstall the flow from the network node. - * Based on the result of this operation FRM will update its database - * accordingly and will return the proper {@code Status} code. + * It requests FRM to remove the passed Flow Entry. FRM will request the SDN + * protocol plugin to uninstall the flow from the network node. Based on the + * result of this operation FRM will update its database accordingly and + * will return the proper {@code Status} code. * - * @param flow the flow entry to uninstall + * @param flow + * the flow entry to uninstall * @return the {@code Status} object indicating the result of this action */ public Status uninstallFlowEntry(FlowEntry flow); /** * It requests FRM to replace the currently installed Flow Entry with the - * new one. It is up to the SDN protocol plugin to decide how to convey - * this message to the network node. It could be a delete + add or a single - * modify message depending on the SDN protocol specifications - * If the current flow is equal to the new one it will be a no op and - * success code is returned. + * new one. It is up to the SDN protocol plugin to decide how to convey this + * message to the network node. It could be a delete + add or a single + * modify message depending on the SDN protocol specifications If the + * current flow is equal to the new one it will be a no op and success code + * is returned. * - * @param current the current flow entry to modify - * @param newone the new flow entry which will replace the current one + * @param current + * the current flow entry to modify + * @param newone + * the new flow entry which will replace the current one * @return the {@code Status} object indicating the result of this action */ public Status modifyFlowEntry(FlowEntry current, FlowEntry newone); @@ -63,15 +66,15 @@ public interface IForwardingRulesManager { * It requests the FRM to replace the currently installed Flow Entry with * the new one. The currently installed entry is derived by the Match * portion of the passed Flow. FRM looks in its database for a previously - * installed FlowEntry which Match equals the Match of the passed Flow. - * If it finds it, it will request the SDN protocol plugin to replace the - * existing flow with the new one on the network node. If it does not - * find it, it will request plugin to add the new flow. If the passed entry - * is not valid an error code is returned. - * If the existing flow is equal to the passed one it will be a no op and - * success code is returned. + * installed FlowEntry which Match equals the Match of the passed Flow. If + * it finds it, it will request the SDN protocol plugin to replace the + * existing flow with the new one on the network node. If it does not find + * it, it will request plugin to add the new flow. If the passed entry is + * not valid an error code is returned. If the existing flow is equal to the + * passed one it will be a no op and success code is returned. * - * @param newone the new flow entry to install + * @param newone + * the new flow entry to install * @return the {@code Status} object indicating the result of this action */ public Status modifyOrAddFlowEntry(FlowEntry newone); @@ -79,64 +82,81 @@ public interface IForwardingRulesManager { /** * Check whether the passed flow entry conflicts with the Container flows * - * @param flow the flow entry to test + * @param flow + * the flow entry to test * @return true if conflicts, false otherwise */ public boolean checkFlowEntryConflict(FlowEntry flow); /** - * Returns the list of Flow entries across network nodes which are part of the - * same flow group, policy - * - * @param group the group name + * Returns the list of Flow entries across network nodes which are part of + * the same flow group, policy + * + * @param group + * the group name * @return the list of flow entries belonging to the specified group */ public List getFlowEntriesForGroup(String group); /** - * Add a list of output port to the flow with the specified name on the specified network node - * - * @param node the network node - * @param flowName the flow name - * @param dstPort the list of ports to be added to the flow output actions + * Add a list of output port to the flow with the specified name on the + * specified network node + * + * @param node + * the network node + * @param flowName + * the flow name + * @param dstPort + * the list of ports to be added to the flow output actions */ public void addOutputPort(Node node, String flowName, List dstPort); /** - * Remove a list of output port from the flow with the specified name on the specified network node - * - * @param node the network node - * @param flowName the flow name - * @param dstPortthe list of ports to be removed from the flow output actions + * Remove a list of output port from the flow with the specified name on the + * specified network node + * + * @param node + * the network node + * @param flowName + * the flow name + * @param dstPortthe + * list of ports to be removed from the flow output actions */ public void removeOutputPort(Node node, String flowName, List dstPort); /** - * Replace the current output port in the specified flow with the specified one - * - * @param node the network node - * @param groupName the group name - * @param flowName the flow name - * @param dstPort the new output action port + * Replace the current output port in the specified flow with the specified + * one + * + * @param node + * the network node + * @param groupName + * the group name + * @param flowName + * the flow name + * @param dstPort + * the new output action port */ public void replaceOutputPort(Node node, String flowName, NodeConnector outPort); /** * Returns the output port configured on the specified flow - * - * @param node the network node - * @param flowName the flow name + * + * @param node + * the network node + * @param flowName + * the flow name * @return the output action port for the specified flow */ public NodeConnector getOutputPort(Node node, String flowName); /** - * Returns all the troubleshooting information that applications - * have set along with the policy they have configured through - * forwarding rules manger. + * Returns all the troubleshooting information that applications have set + * along with the policy they have configured through forwarding rules + * manger. * * @return the collection of troubleshooting objects */ @@ -144,60 +164,69 @@ public interface IForwardingRulesManager { /** * Set the troubleshooting information for the policy - * - * @param policyname the flow group name - * @param o the object containing the troubleshooting information - * @param add true for adding, false for removing + * + * @param policyname + * the flow group name + * @param o + * the object containing the troubleshooting information + * @param add + * true for adding, false for removing */ public void setTSPolicyData(String policyName, Object o, boolean add); /** - * Returns the troubleshooting information that was set for the specified policy + * Returns the troubleshooting information that was set for the specified + * policy * - * @param groupName the flows group name + * @param groupName + * the flows group name * @return the troubleshooting info object */ public Object getTSPolicyData(String policyName); /** - * Returns the specifications of all the flows configured for all the + * Returns the specifications of all the flows configured for all the * switches on the current container - * + * * @return the list of flow configurations present in the database */ public List getStaticFlows(); /** - * Returns the specifications of all the flows configured for - * the given switch on the current container - * - * @param node the network node identifier - * @return the list of {@code FlowConfig} objects + * Returns the specifications of all the flows configured for the given + * switch on the current container + * + * @param node + * the network node identifier + * @return the list of {@code FlowConfig} objects */ public List getStaticFlows(Node node); /** - * Returns the specification of the flow configured for the given - * network node on the current container - * - * @param name the flow name - * @param n the netwrok node identifier + * Returns the specification of the flow configured for the given network + * node on the current container + * + * @param name + * the flow name + * @param n + * the netwrok node identifier * @return the {@code FlowConfig} object */ public FlowConfig getStaticFlow(String name, Node n); /** - * Returns the list of names of flows configured for the given - * Network node on the current container - * - * @param node the network node identifier + * Returns the list of names of flows configured for the given Network node + * on the current container + * + * @param node + * the network node identifier * @return the list of flow names */ public List getStaticFlowNamesForNode(Node node); /** * Returns the list of Node(s) for which a static flow has been configured - * + * * @return the list of network nodes */ public List getListNodeWithConfiguredFlows(); @@ -210,59 +239,70 @@ public interface IForwardingRulesManager { public Status saveConfig(); /** - * Add a flow specified by the {@code FlowConfig} object on the current container + * Add a flow specified by the {@code FlowConfig} object on the current + * container * - * @param config the {@code FlowConfig} object representing the static flow - * @param restore if set to true, the config object validation will be skipped. - * Used only internally, always set it to false. + * @param config + * the {@code FlowConfig} object representing the static flow + * @param restore + * if set to true, the config object validation will be skipped. + * Used only internally, always set it to false. * @return the {@code Status} object indicating the result of this action. */ public Status addStaticFlow(FlowConfig config, boolean restore); /** - * Remove a flow specified by the {@code FlowConfig} object on the current container + * Remove a flow specified by the {@code FlowConfig} object on the current + * container * - * @param config the {@code FlowConfig} object representing the static flow + * @param config + * the {@code FlowConfig} object representing the static flow * @return the {@code Status} object indicating the result of this action */ public Status removeStaticFlow(FlowConfig config); /** - * Replace the flow identified by the {@code FlowConfig.name} name for - * the {@code FlowConfig.node} network node with the new flow specified - * by {@code FlowConfig} object - * - * @param config the {@code FlowConfig} object + * Replace the flow identified by the {@code FlowConfig.name} name for the + * {@code FlowConfig.node} network node with the new flow specified by + * {@code FlowConfig} object + * + * @param config + * the {@code FlowConfig} object * @returnthe {@code Status} object indicating the result of this action */ public Status modifyStaticFlow(FlowConfig config); /** * Remove the flow specified by name on the passed network node - * - * @param name for the static flow - * @param node on which the flow is attached + * + * @param name + * for the static flow + * @param node + * on which the flow is attached * @return the {@code Status} object indicating the result of this action */ public Status removeStaticFlow(String name, Node node); /** - * Toggle the installation status of the specified configured flow - * If the flow configuration status is active, this call will - * change the flow status to inactive and vice-versa - * - * @param configObject the {@code FlowConfig} object + * Toggle the installation status of the specified configured flow If the + * flow configuration status is active, this call will change the flow + * status to inactive and vice-versa + * + * @param configObject + * the {@code FlowConfig} object * @return the {@code Status} object indicating the result of this action */ public Status toggleStaticFlowStatus(FlowConfig configObject); - + /** - * Toggle the installation status of the specified configured flow - * If the flow configuration status is active, this call will - * change the flow status to inactive and vice-versa - * - * @param name for the static flow - * @param node on which the flow is attached + * Toggle the installation status of the specified configured flow If the + * flow configuration status is active, this call will change the flow + * status to inactive and vice-versa + * + * @param name + * for the static flow + * @param node + * on which the flow is attached * @return the {@code Status} object indicating the result of this action */ public Status toggleStaticFlowStatus(String name, Node node); diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManagerAware.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManagerAware.java similarity index 57% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManagerAware.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManagerAware.java index df37063218..e2ccdd60c3 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManagerAware.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManagerAware.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -9,20 +8,22 @@ package org.opendaylight.controller.forwardingrulesmanager; - /** - * The interface which describes the methods forwarding rules manager - * will call for notifying the listeners of policy installation updates. - * + * The interface which describes the methods forwarding rules manager will call + * for notifying the listeners of policy installation updates. + * */ public interface IForwardingRulesManagerAware { - /** - * Inform the listeners that a troubleshooting information was - * added or removed for the specified policy. - * - * @param policyName the policy affected - * @param add true if the troubleshooting information was added, false otherwise - */ + /** + * Inform the listeners that a troubleshooting information was added or + * removed for the specified policy. + * + * @param policyName + * the policy affected + * @param add + * true if the troubleshooting information was added, false + * otherwise + */ public void policyUpdate(String policyName, boolean add); } diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroup.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroup.java similarity index 73% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroup.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroup.java index 1e457beef4..5acd3e2ebc 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroup.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroup.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -13,13 +12,13 @@ import java.util.HashSet; import java.util.Set; /** - * PortGroup is a simple data-structure to represent any arbitrary group of ports - * on a Switch (that is represented using its switch-ID). - * - * PortGroup is used by PortGroupProvider application to signal a set of ports that - * represent a configured PortGroupConfig. - * - * + * PortGroup is a simple data-structure to represent any arbitrary group of + * ports on a Switch (that is represented using its switch-ID). + * + * PortGroup is used by PortGroupProvider application to signal a set of ports + * that represent a configured PortGroupConfig. + * + * */ public class PortGroup { private long matrixSwitchId; @@ -27,9 +26,11 @@ public class PortGroup { /** * PortGroup Constructor using Switch and Ports. - * - * @param matrixSwitchId Switch Id that represents an openflow Switch - * @param ports Set of short values representing openflow port-ids. + * + * @param matrixSwitchId + * Switch Id that represents an openflow Switch + * @param ports + * Set of short values representing openflow port-ids. */ public PortGroup(long matrixSwitchId, Set ports) { super(); @@ -39,8 +40,9 @@ public class PortGroup { /** * PortGroup Constructor using Switch. - * - * @param matrixSwitchId Switch-Id that represents an openflow Switch + * + * @param matrixSwitchId + * Switch-Id that represents an openflow Switch */ public PortGroup(long matrixSwitchId) { this.matrixSwitchId = matrixSwitchId; @@ -49,7 +51,7 @@ public class PortGroup { /** * Returns the switchId representing the Switch that makes this PortGroup. - * + * * @return long switchId */ public long getMatrixSwitchId() { @@ -58,8 +60,9 @@ public class PortGroup { /** * Assigns a Switch to this PortGroup - * - * @param matrixSwitchId Switch-Id that represents an openflow Switch + * + * @param matrixSwitchId + * Switch-Id that represents an openflow Switch */ public void setMatrixSwitchId(long matrixSwitchId) { this.matrixSwitchId = matrixSwitchId; @@ -67,7 +70,7 @@ public class PortGroup { /** * Returns the Set of Ports that makes this PortGroup. - * + * * @return Set of short values representing openflow port-ids. */ public Set getPorts() { @@ -76,8 +79,9 @@ public class PortGroup { /** * Assigns a set of openflow ports to this PortGroup - * - * @param ports Set of short values representing openflow port-ids. + * + * @param ports + * Set of short values representing openflow port-ids. */ public void setPorts(Set ports) { this.ports = ports; @@ -85,8 +89,9 @@ public class PortGroup { /** * Adds a port to this PortGroup - * - * @param port Short value of a openflow port. + * + * @param port + * Short value of a openflow port. */ public void addPort(short port) { ports.add(port); diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupChangeListener.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupChangeListener.java similarity index 60% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupChangeListener.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupChangeListener.java index 3479f29b67..7c8ade5b89 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupChangeListener.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupChangeListener.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -14,18 +13,24 @@ import java.util.Map; import org.opendaylight.controller.sal.core.Node; /** - * PortGroupChangeListener listens to the PortGroup updates provided by the PortGroupProvider. - * - * + * PortGroupChangeListener listens to the PortGroup updates provided by the + * PortGroupProvider. + * + * */ public interface PortGroupChangeListener { /** - * This method is invoked by PortGroupProvider whenever it detects a change in PortGroup - * membership for a given PortGroupConfig. - * - * @param config Port Group Configuration - * @param portGroupData HashMap of Node id to PortGroup that represents the updated ports as detected by PortGroupProvider. - * @param add true indicates that the PortGroup is added. False indicates that the PortGroup is removed. + * This method is invoked by PortGroupProvider whenever it detects a change + * in PortGroup membership for a given PortGroupConfig. + * + * @param config + * Port Group Configuration + * @param portGroupData + * HashMap of Node id to PortGroup that represents the updated + * ports as detected by PortGroupProvider. + * @param add + * true indicates that the PortGroup is added. False indicates + * that the PortGroup is removed. */ void portGroupChanged(PortGroupConfig config, Map portGroupData, boolean add); diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupConfig.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupConfig.java similarity index 80% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupConfig.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupConfig.java index 39683d4dfe..164f26484e 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupConfig.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupConfig.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -15,14 +14,14 @@ import java.util.ArrayList; import java.util.List; /** - * PortGroupConfig class represents the User's Configuration with a Opaque Regular Expression - * String that is parsed and handled by PortGroupProvider. - * - * Typically, the opaque matchString will be a Regular Expression String supported by a particular - * PortGroupProvider based on Customer requirements. - * - * - * + * PortGroupConfig class represents the User's Configuration with a Opaque + * Regular Expression String that is parsed and handled by PortGroupProvider. + * + * Typically, the opaque matchString will be a Regular Expression String + * supported by a particular PortGroupProvider based on Customer requirements. + * + * + * */ public class PortGroupConfig implements Serializable { private static final long serialVersionUID = 1L; @@ -40,11 +39,13 @@ public class PortGroupConfig implements Serializable { } /** - * Constructor to create a Port Group Configuration using a Group Name and an Opaque - * String that is managed by PortGroupProvider. - * - * @param name Group Name representing a Port Group configuration - * @param matchString An Opaque String managed by PortGroupProvider + * Constructor to create a Port Group Configuration using a Group Name and + * an Opaque String that is managed by PortGroupProvider. + * + * @param name + * Group Name representing a Port Group configuration + * @param matchString + * An Opaque String managed by PortGroupProvider */ public PortGroupConfig(String name, String matchString) { super(); @@ -54,7 +55,7 @@ public class PortGroupConfig implements Serializable { /** * Returns the user configured PortGroup Configuration name. - * + * * @return Configuration Name */ public String getName() { @@ -63,7 +64,9 @@ public class PortGroupConfig implements Serializable { /** * Assigns a name to the configuration - * @param name configuration name + * + * @param name + * configuration name */ public void setName(String name) { this.name = name; @@ -71,6 +74,7 @@ public class PortGroupConfig implements Serializable { /** * Returns the Opaque string + * * @return */ public String getMatchString() { @@ -79,17 +83,18 @@ public class PortGroupConfig implements Serializable { /** * Assigns an opaque String to the Configuration. - * - * @param matchString Opaque string handled by PortGroupProvider + * + * @param matchString + * Opaque string handled by PortGroupProvider */ public void setMatchString(String matchString) { this.matchString = matchString; } /** - * Returns the names of all the configurable fields in PortGroupConfig. - * This method is typically used by NorthBound apis. - * + * Returns the names of all the configurable fields in PortGroupConfig. This + * method is typically used by NorthBound apis. + * * @return List of Field names that can be configured. */ public static List getFieldsNames() { @@ -97,7 +102,7 @@ public class PortGroupConfig implements Serializable { for (Field fld : PortGroupConfig.class.getDeclaredFields()) { fieldList.add(fld.getName()); } - //remove static field(s) + // remove static field(s) fieldList.remove(0); fieldList.remove(0); @@ -105,10 +110,12 @@ public class PortGroupConfig implements Serializable { } /** - * Returns the names of all the configurable fields in PortGroupConfig in human readable format for UI purposes. - * This method is typically used by Web/UI apis. - * - * @return List of Human readable Strings that corresponds to the configurable field names. + * Returns the names of all the configurable fields in PortGroupConfig in + * human readable format for UI purposes. This method is typically used by + * Web/UI apis. + * + * @return List of Human readable Strings that corresponds to the + * configurable field names. */ public static List getPrettyFieldsNames() { List fieldList = new ArrayList(); diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupProvider.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupProvider.java similarity index 52% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupProvider.java rename to opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupProvider.java index df6618c6fd..37cbcd17e6 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupProvider.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/PortGroupProvider.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -14,48 +13,59 @@ import java.util.Map; import org.opendaylight.controller.sal.core.Node; /** - * PortGroupProvider interface provides all the necessary blueprint for a custom application to implement - * in order to provide Port Grouping Service. Custom Application that implements this interface will have - * to handle the opaque match criteria passed to it via PortGroupConfig. - * - * - * + * PortGroupProvider interface provides all the necessary blueprint for a custom + * application to implement in order to provide Port Grouping Service. Custom + * Application that implements this interface will have to handle the opaque + * match criteria passed to it via PortGroupConfig. + * + * + * */ public interface PortGroupProvider { /** - * This method is invoked by the Controller towards the Provider when a new port group is configured. - * - * @param config New PortGroupConfig object created by user Configuration. + * This method is invoked by the Controller towards the Provider when a new + * port group is configured. + * + * @param config + * New PortGroupConfig object created by user Configuration. * @return true if successful. false otherwise. */ public boolean createPortGroupConfig(PortGroupConfig config); /** - * This method is invoked by the Controller towards the Provider when an existing port group is deleted. - * - * @param config Existing Port Group Configuration deleted by the user. + * This method is invoked by the Controller towards the Provider when an + * existing port group is deleted. + * + * @param config + * Existing Port Group Configuration deleted by the user. * @return true if successful. false otherwise. */ public boolean deletePortGroupConfig(PortGroupConfig config); /** - * Returns the complete mapping database corresponds to a PortGroup Configuration. - * Its the PortGroupProvider Application's responsibility to manage the Switches & the Set of its Ports that - * correspond to each of the Configuration and return it to the Controller when requested. - * - * @param config User Configuration + * Returns the complete mapping database corresponds to a PortGroup + * Configuration. Its the PortGroupProvider Application's responsibility to + * manage the Switches & the Set of its Ports that correspond to each of the + * Configuration and return it to the Controller when requested. + * + * @param config + * User Configuration * @see PortGroupConfig - * @return Database of Switch-Id to PortGroup mapping that corresponds to the Port Group User Configuration. + * @return Database of Switch-Id to PortGroup mapping that corresponds to + * the Port Group User Configuration. */ public Map getPortGroupData(PortGroupConfig config); /** - * Returns PortGroup data for a given Switch and user Configuration. - * Its the PortGroupProvider Application's responsibility to manage the Switches & the Set of its Ports that - * correspond to each of the Configuration and return it to the Controller when requested. - * - * @param config User Configuration - * @param matrixSwitchId Switch Id that represents an openflow Switch + * Returns PortGroup data for a given Switch and user Configuration. Its the + * PortGroupProvider Application's responsibility to manage the Switches & + * the Set of its Ports that correspond to each of the Configuration and + * return it to the Controller when requested. + * + * @param config + * User Configuration + * @param matrixSwitchId + * Switch Id that represents an openflow Switch * @see PortGroupConfig * @return PortGroup data for a given Openflow switch. * @see PortGroup @@ -64,33 +74,41 @@ public interface PortGroupProvider { long matrixSwitchId); /** - * Registers a Listener for Port Group membership changes based on Custom application algorithm. - * @param listener A Controller module that listens to events from the Custom Port Grouping Application. + * Registers a Listener for Port Group membership changes based on Custom + * application algorithm. + * + * @param listener + * A Controller module that listens to events from the Custom + * Port Grouping Application. */ public void registerPortGroupChange(PortGroupChangeListener listener); /** - * Application returns an Usage string for the Match Criteria User Configuration. - * Controller provides an opportunity for application to implement Custom Algorithm for Port Grouping. - * This method exposes the custom algorithm to the user so that the user can configure the matchString - * regular expression in PortGroupConfig appropriately. - * + * Application returns an Usage string for the Match Criteria User + * Configuration. Controller provides an opportunity for application to + * implement Custom Algorithm for Port Grouping. This method exposes the + * custom algorithm to the user so that the user can configure the + * matchString regular expression in PortGroupConfig appropriately. + * * @return Usage string. */ public String getApplicationDrivenMatchCriteriaUsage(); /** - * Returns the name of the Custom Application that implements PortGroupProvider interface. - * + * Returns the name of the Custom Application that implements + * PortGroupProvider interface. + * * @return Provider Name */ public String getProviderName(); /** - * Controller uses this method to check with the Provider supports the matchCriteria String configured by the User. - * + * Controller uses this method to check with the Provider supports the + * matchCriteria String configured by the User. + * * @param matchCriteria - * @return true if the Provider supports the matchCriteria String. false otherwise. + * @return true if the Provider supports the matchCriteria String. false + * otherwise. */ public boolean isMatchCriteriaSupported(String matchCriteria); } diff --git a/opendaylight/forwardingrulesmanager/src/test/java/org/opendaylight/controller/forwardingrulesmanager/frmTest.java b/opendaylight/forwardingrulesmanager/api/src/test/java/org/opendaylight/controller/forwardingrulesmanager/frmTest.java similarity index 80% rename from opendaylight/forwardingrulesmanager/src/test/java/org/opendaylight/controller/forwardingrulesmanager/frmTest.java rename to opendaylight/forwardingrulesmanager/api/src/test/java/org/opendaylight/controller/forwardingrulesmanager/frmTest.java index dd2fd229bd..0b11d13f3c 100644 --- a/opendaylight/forwardingrulesmanager/src/test/java/org/opendaylight/controller/forwardingrulesmanager/frmTest.java +++ b/opendaylight/forwardingrulesmanager/api/src/test/java/org/opendaylight/controller/forwardingrulesmanager/frmTest.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -41,33 +40,35 @@ import org.opendaylight.controller.sal.utils.NodeCreator; public class frmTest { - @Test - public void testFlowEntryInstall() throws UnknownHostException{ - Node node = NodeCreator.createOFNode(1L); - FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), - node); - FlowEntry pol2 = new FlowEntry("polTest2", null, getSampleFlowV6(node), - node); - FlowEntryInstall fei = new FlowEntryInstall(pol, null); - FlowEntryInstall fei2 = new FlowEntryInstall(pol, null); - FlowEntryInstall fei3 = new FlowEntryInstall(pol2, null); - Assert.assertTrue(fei.getOriginal().equals(pol)); - Assert.assertTrue(fei.getInstall().equals(pol)); - Assert.assertTrue(fei.getFlowName().equals(pol.getFlowName())); - Assert.assertTrue(fei.getGroupName().equals(pol.getGroupName())); - Assert.assertTrue(fei.getNode().equals(pol.getNode())); - Assert.assertFalse(fei.isDeletePending()); - fei.toBeDeleted(); - Assert.assertTrue(fei.isDeletePending()); - Assert.assertNull(fei.getContainerFlow()); - Assert.assertTrue(fei.equalsByNodeAndName(pol.getNode(), pol.getFlowName())); - - Assert.assertTrue(fei.equals(fei2)); - fei2.getOriginal().setFlowName("polTest2"); - Assert.assertFalse(fei.equals(null)); - Assert.assertFalse(fei.equals(fei3)); - - } + @Test + public void testFlowEntryInstall() throws UnknownHostException { + Node node = NodeCreator.createOFNode(1L); + FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), + node); + FlowEntry pol2 = new FlowEntry("polTest2", null, getSampleFlowV6(node), + node); + FlowEntryInstall fei = new FlowEntryInstall(pol, null); + FlowEntryInstall fei2 = new FlowEntryInstall(pol, null); + FlowEntryInstall fei3 = new FlowEntryInstall(pol2, null); + Assert.assertTrue(fei.getOriginal().equals(pol)); + Assert.assertTrue(fei.getInstall().equals(pol)); + Assert.assertTrue(fei.getFlowName().equals(pol.getFlowName())); + Assert.assertTrue(fei.getGroupName().equals(pol.getGroupName())); + Assert.assertTrue(fei.getNode().equals(pol.getNode())); + Assert.assertFalse(fei.isDeletePending()); + fei.toBeDeleted(); + Assert.assertTrue(fei.isDeletePending()); + Assert.assertNull(fei.getContainerFlow()); + Assert.assertTrue(fei.equalsByNodeAndName(pol.getNode(), + pol.getFlowName())); + + Assert.assertTrue(fei.equals(fei2)); + fei2.getOriginal().setFlowName("polTest2"); + Assert.assertFalse(fei.equals(null)); + Assert.assertFalse(fei.equals(fei3)); + + } + @Test public void testFlowEntryCreation() throws UnknownHostException { Node node = NodeCreator.createOFNode(1L); @@ -102,7 +103,6 @@ public class frmTest { Assert.assertTrue(pol.equals(pol2)); } - @Test public void testFlowEntryCloning() throws UnknownHostException { Node node = NodeCreator.createOFNode(1L); @@ -126,7 +126,7 @@ public class frmTest { match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue()); List actionList = new ArrayList(); - //actionList.add(new Drop()); + // actionList.add(new Drop()); Flow flow = new Flow(match, actionList); FlowEntry pol1 = new FlowEntry("m1", "same", flow, node1); @@ -165,21 +165,21 @@ public class frmTest { FlowEntry entry = new FlowEntry("polTest", null, getSampleFlowV6(node), node); - //testing equal function + // testing equal function Assert.assertFalse(frmC.equals(null)); Assert.assertTrue(frmC.equals(frmC)); Assert.assertTrue(frmC.equals(frmC3)); Assert.assertFalse(frmC.equals(entry)); FlowConfig flowC = createSampleFlowConfig(); Assert.assertFalse(frmC.equals(flowC)); - //testing installInHW + // testing installInHW Assert.assertTrue(frmC.installInHw()); frmC.setInstallInHw(false); Assert.assertFalse(frmC.installInHw()); frmC.setInstallInHw(true); Assert.assertTrue(frmC.installInHw()); - //testing general set and get methods + // testing general set and get methods ArrayList actions = createSampleActionList(); frmC.setActions(actions); Assert.assertFalse(frmC.equals(frmC3)); @@ -256,20 +256,16 @@ public class frmTest { Assert.assertFalse(frmC.equals(flowC)); frmC.setProtocol(IPProtocols.TCP.toString()); - Assert.assertTrue(frmC.getProtocol().equals( - IPProtocols.TCP.toString())); + Assert.assertTrue(frmC.getProtocol().equals(IPProtocols.TCP.toString())); Assert.assertFalse(frmC.equals(frmC3)); frmC3.setProtocol(IPProtocols.TCP.toString()); Assert.assertFalse(frmC.equals(flowC)); - frmC.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, - "1")); - Assert.assertTrue(frmC.getNode() - .equals(Node.fromString(Node.NodeIDType.OPENFLOW, - "1"))); + frmC.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1")); + Assert.assertTrue(frmC.getNode().equals( + Node.fromString(Node.NodeIDType.OPENFLOW, "1"))); Assert.assertFalse(frmC.equals(frmC3)); - frmC3.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, - "1")); + frmC3.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1")); Assert.assertFalse(frmC.equals(flowC)); frmC.setTosBits("0"); @@ -313,7 +309,7 @@ public class frmTest { Assert.assertFalse(frmC.equals(frmC3)); frmC3.setHardTimeout("1000"); - // Assert.assertFalse(frmC.equals(flowC)); + // Assert.assertFalse(frmC.equals(flowC)); Assert.assertTrue(actions.equals(frmC.getActions())); FlowConfig frmC2 = new FlowConfig(frmC); @@ -323,7 +319,7 @@ public class frmTest { Assert.assertFalse(frmC2.equals(frmC)); frmC2.setDynamic(true); Assert.assertTrue(frmC2.equals(frmC)); - //Assert.assertFalse(frmC2.equals(frmC3)); + // Assert.assertFalse(frmC2.equals(frmC3)); flowC.setDynamic(true); Assert.assertTrue(flowC.equals(frmC)); Assert.assertTrue(flowC.isStatusSuccessful()); @@ -342,65 +338,61 @@ public class frmTest { Assert.assertTrue(id.toString().equals("1")); } - + @Test - public void testFlowConfigNextHopValidity() throws UnknownHostException{ - FlowConfig fc = new FlowConfig(); - Assert.assertFalse(fc.isOutputNextHopValid(null)); - Assert.assertFalse(fc.isOutputNextHopValid("abc")); - Assert.assertFalse(fc.isOutputNextHopValid("1.1.1")); - Assert.assertFalse(fc.isOutputNextHopValid("1.1.1.1/49")); - - Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1")); - Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1/32")); - Assert.assertTrue(fc.isOutputNextHopValid("2001:420:281:1004:407a:57f4:4d15:c355")); - + public void testFlowConfigNextHopValidity() throws UnknownHostException { + FlowConfig fc = new FlowConfig(); + Assert.assertFalse(fc.isOutputNextHopValid(null)); + Assert.assertFalse(fc.isOutputNextHopValid("abc")); + Assert.assertFalse(fc.isOutputNextHopValid("1.1.1")); + Assert.assertFalse(fc.isOutputNextHopValid("1.1.1.1/49")); + + Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1")); + Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1/32")); + Assert.assertTrue(fc + .isOutputNextHopValid("2001:420:281:1004:407a:57f4:4d15:c355")); + } - + @Test - public void testFlowConfigEqualities() throws UnknownHostException{ - FlowConfig fc = new FlowConfig(); - FlowConfig fc2 = new FlowConfig(); - fc.setName("flow1"); - fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, - "1")); - Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW, - "0"))); - Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW, - "1"))); - - Assert.assertTrue(fc.isByNameAndNodeIdEqual( - "flow1", - Node.fromString(Node.NodeIDType.OPENFLOW, "1"))); - Assert.assertFalse(fc.isByNameAndNodeIdEqual( - "flow1", - Node.fromString(Node.NodeIDType.OPENFLOW, "0"))); - Assert.assertFalse(fc.isByNameAndNodeIdEqual( - "flow2", - Node.fromString(Node.NodeIDType.OPENFLOW, "1"))); - - Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2)); - fc2.setName("flow1"); - Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2)); - fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, - "0")); - Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2)); - fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, - "1")); - Assert.assertTrue(fc.isByNameAndNodeIdEqual(fc2)); + public void testFlowConfigEqualities() throws UnknownHostException { + FlowConfig fc = new FlowConfig(); + FlowConfig fc2 = new FlowConfig(); + fc.setName("flow1"); + fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1")); + Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW, + "0"))); + Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW, + "1"))); + + Assert.assertTrue(fc.isByNameAndNodeIdEqual("flow1", + Node.fromString(Node.NodeIDType.OPENFLOW, "1"))); + Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow1", + Node.fromString(Node.NodeIDType.OPENFLOW, "0"))); + Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow2", + Node.fromString(Node.NodeIDType.OPENFLOW, "1"))); + + Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2)); + fc2.setName("flow1"); + Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2)); + fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "0")); + Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2)); + fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1")); + Assert.assertTrue(fc.isByNameAndNodeIdEqual(fc2)); } - + @Test - public void testStatusToggle() throws UnknownHostException{ - FlowConfig fc = new FlowConfig(); - fc.toggleStatus(); - Assert.assertTrue(fc.installInHw()); - fc.toggleStatus(); - Assert.assertFalse(fc.installInHw()); - fc.toggleStatus(); - Assert.assertTrue(fc.installInHw()); - + public void testStatusToggle() throws UnknownHostException { + FlowConfig fc = new FlowConfig(); + fc.toggleStatus(); + Assert.assertTrue(fc.installInHw()); + fc.toggleStatus(); + Assert.assertFalse(fc.installInHw()); + fc.toggleStatus(); + Assert.assertTrue(fc.installInHw()); + } + @Test public void testGetFlowEntry() throws UnknownHostException { FlowConfig fc2 = createSampleFlowConfig(); @@ -442,8 +434,7 @@ public class frmTest { Assert.assertFalse(fc.isValid(null, sb)); Assert.assertTrue(sb.toString().contains("Node is null")); - fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, - "1")); + fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1")); Assert.assertTrue(fc.isValid(null, sb)); fc.setPriority("-1"); @@ -463,9 +454,7 @@ public class frmTest { fc.setCookie("100"); fc.setIngressPort("-1"); Assert.assertFalse(fc.isValid(null, sb)); - Assert - .assertTrue(sb.toString().contains( - "is not valid for the Switch")); + Assert.assertTrue(sb.toString().contains("is not valid for the Switch")); fc.setIngressPort("100"); Assert.assertTrue(fc.isValid(null, sb)); @@ -613,15 +602,12 @@ public class frmTest { private FlowConfig createSampleFlowConfig() throws UnknownHostException { ArrayList actions; actions = createSampleActionList(); - //actions.add(ActionType.CONTROLLER.toString()); - FlowConfig flowConfig = - new FlowConfig("true", "Config1", - Node.fromString(Node.NodeIDType.OPENFLOW, - "1"), "100", "0", "60", "2", "100", - "0", "0x0800", "00:A0:C9:14:C8:29", - "00:A0:C9:22:AB:11", IPProtocols.TCP.toString(), "0", - "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000", - actions); + // actions.add(ActionType.CONTROLLER.toString()); + FlowConfig flowConfig = new FlowConfig("true", "Config1", + Node.fromString(Node.NodeIDType.OPENFLOW, "1"), "100", "0", + "60", "2", "100", "0", "0x0800", "00:A0:C9:14:C8:29", + "00:A0:C9:22:AB:11", IPProtocols.TCP.toString(), "0", + "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000", actions); return flowConfig; } @@ -633,19 +619,19 @@ public class frmTest { actions.add(ActionType.FLOOD.toString()); actions.add(ActionType.SW_PATH.toString()); actions.add(ActionType.HW_PATH.toString()); - actions.add(ActionType.SET_VLAN_PCP.toString()+"=1"); - actions.add(ActionType.SET_VLAN_ID.toString()+"=1"); + actions.add(ActionType.SET_VLAN_PCP.toString() + "=1"); + actions.add(ActionType.SET_VLAN_ID.toString() + "=1"); actions.add(ActionType.POP_VLAN.toString()); - actions.add(ActionType.SET_DL_SRC.toString()+"=00:A0:C1:AB:22:11"); - actions.add(ActionType.SET_DL_DST.toString()+"=00:B1:C1:00:AA:BB"); - actions.add(ActionType.SET_NW_SRC.toString()+"=1.1.1.1"); - actions.add(ActionType.SET_NW_DST.toString()+"=2.2.2.2"); + actions.add(ActionType.SET_DL_SRC.toString() + "=00:A0:C1:AB:22:11"); + actions.add(ActionType.SET_DL_DST.toString() + "=00:B1:C1:00:AA:BB"); + actions.add(ActionType.SET_NW_SRC.toString() + "=1.1.1.1"); + actions.add(ActionType.SET_NW_DST.toString() + "=2.2.2.2"); actions.add(ActionType.CONTROLLER.toString()); - actions.add(ActionType.SET_NW_TOS.toString()+"1"); - actions.add(ActionType.SET_TP_SRC.toString()+"60"); - actions.add(ActionType.SET_TP_DST.toString()+"8080"); - actions.add(ActionType.SET_NEXT_HOP.toString()+"=1.1.1.1"); - + actions.add(ActionType.SET_NW_TOS.toString() + "1"); + actions.add(ActionType.SET_TP_SRC.toString() + "60"); + actions.add(ActionType.SET_TP_DST.toString() + "8080"); + actions.add(ActionType.SET_NEXT_HOP.toString() + "=1.1.1.1"); + return actions; } diff --git a/opendaylight/forwardingrulesmanager/implementation/pom.xml b/opendaylight/forwardingrulesmanager/implementation/pom.xml new file mode 100644 index 0000000000..2c0bc9319c --- /dev/null +++ b/opendaylight/forwardingrulesmanager/implementation/pom.xml @@ -0,0 +1,103 @@ + + + 4.0.0 + + org.opendaylight.controller + commons.opendaylight + 1.4.0-SNAPSHOT + ../../commons/opendaylight + + + org.opendaylight.controller + forwardingrulesmanager.implementation + 0.4.0-SNAPSHOT + bundle + + + + + org.apache.felix + maven-bundle-plugin + 2.3.6 + true + + + + + + + + org.opendaylight.controller.clustering.services, + org.opendaylight.controller.configuration, + org.opendaylight.controller.hosttracker, + org.opendaylight.controller.hosttracker.hostAware, + org.opendaylight.controller.switchmanager, + org.opendaylight.controller.sal.action, + org.opendaylight.controller.sal.core, + org.opendaylight.controller.sal.flowprogrammer, + org.opendaylight.controller.sal.match, + org.opendaylight.controller.sal.utils, + org.opendaylight.controller.sal.packet, + org.opendaylight.controller.forwardingrulesmanager, + javax.xml.bind.annotation, + javax.xml.bind, + org.apache.felix.dm, + org.apache.commons.lang3.builder, + org.osgi.service.component, + org.slf4j, + org.eclipse.osgi.framework.console, + org.osgi.framework + + + org.opendaylight.controller.forwardingrulesmanager.internal.Activator + + + org.opendaylight.controller.hosttracker + + + + + + + + + + + org.opendaylight.controller + hosttracker + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + configuration + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + clustering.services + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + switchmanager + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + sal + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + forwardingrulesmanager + 0.4.0-SNAPSHOT + + + junit + junit + 4.8.1 + test + + + diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/Activator.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/Activator.java similarity index 65% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/Activator.java rename to opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/Activator.java index 8578e8492e..d0a370276f 100644 --- a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/Activator.java +++ b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/Activator.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -39,32 +38,31 @@ public class Activator extends ComponentActivatorAbstractBase { .getLogger(Activator.class); /** - * Function called when the activator starts just after some - * initializations are done by the - * ComponentActivatorAbstractBase. - * + * Function called when the activator starts just after some initializations + * are done by the ComponentActivatorAbstractBase. + * */ public void init() { } /** - * Function called when the activator stops just before the - * cleanup done by ComponentActivatorAbstractBase - * + * Function called when the activator stops just before the cleanup done by + * ComponentActivatorAbstractBase + * */ public void destroy() { } /** - * Function that is used to communicate to dependency manager the - * list of known implementations for services inside a container - * - * + * Function that is used to communicate to dependency manager the list of + * known implementations for services inside a container + * + * * @return An array containing all the CLASS objects that will be - * instantiated in order to get an fully working implementation - * Object + * instantiated in order to get an fully working implementation + * Object */ public Object[] getImplementations() { Object[] res = { ForwardingRulesManagerImpl.class }; @@ -72,17 +70,19 @@ public class Activator extends ComponentActivatorAbstractBase { } /** - * Function that is called when configuration of the dependencies - * is required. - * - * @param c dependency manager Component object, used for - * configuring the dependencies exported and imported - * @param imp Implementation class that is being configured, - * needed as long as the same routine can configure multiple - * implementations - * @param containerName The containerName being configured, this allow - * also optional per-container different behavior if needed, usually - * should not be the case though. + * Function that is called when configuration of the dependencies is + * required. + * + * @param c + * dependency manager Component object, used for configuring the + * dependencies exported and imported + * @param imp + * Implementation class that is being configured, needed as long + * as the same routine can configure multiple implementations + * @param containerName + * The containerName being configured, this allow also optional + * per-container different behavior if needed, usually should not + * be the case though. */ public void configureInstance(Component c, Object imp, String containerName) { if (imp.equals(ForwardingRulesManagerImpl.class)) { @@ -100,7 +100,7 @@ public class Activator extends ComponentActivatorAbstractBase { IInventoryListener.class.getName(), ICacheUpdateAware.class.getName(), IConfigurationContainerAware.class.getName(), - IFlowProgrammerListener.class.getName()}; + IFlowProgrammerListener.class.getName() }; } else { interfaces = new String[] { ISwitchManagerAware.class.getName(), @@ -108,32 +108,36 @@ public class Activator extends ComponentActivatorAbstractBase { IInventoryListener.class.getName(), ICacheUpdateAware.class.getName(), IConfigurationContainerAware.class.getName(), - IFlowProgrammerListener.class.getName()}; + IFlowProgrammerListener.class.getName() }; } c.setInterface(interfaces, props); - c.add(createContainerServiceDependency(containerName).setService( - IFlowProgrammerService.class).setCallbacks( - "setFlowProgrammerService", "unsetFlowProgrammerService") + c.add(createContainerServiceDependency(containerName) + .setService(IFlowProgrammerService.class) + .setCallbacks("setFlowProgrammerService", + "unsetFlowProgrammerService").setRequired(true)); + + c.add(createContainerServiceDependency(containerName) + .setService(IClusterContainerServices.class) + .setCallbacks("setClusterContainerService", + "unsetClusterContainerService").setRequired(true)); + c.add(createContainerServiceDependency(containerName) + .setService(ISwitchManager.class) + .setCallbacks("setSwitchManager", "unsetSwitchManager") + .setRequired(true)); + c.add(createContainerServiceDependency(containerName) + .setService(IForwardingRulesManagerAware.class) + .setCallbacks("setFrmAware", "unsetFrmAware") + .setRequired(false)); + c.add(createContainerServiceDependency(containerName) + .setService(IfIptoHost.class) + .setCallbacks("setHostFinder", "unsetHostFinder") + .setRequired(true)); + c.add(createContainerServiceDependency(containerName) + .setService(IContainer.class) + .setCallbacks("setIContainer", "unsetIContainer") .setRequired(true)); - - c.add(createContainerServiceDependency(containerName).setService( - IClusterContainerServices.class).setCallbacks( - "setClusterContainerService", - "unsetClusterContainerService").setRequired(true)); - c.add(createContainerServiceDependency(containerName).setService( - ISwitchManager.class).setCallbacks("setSwitchManager", - "unsetSwitchManager").setRequired(true)); - c.add(createContainerServiceDependency(containerName).setService( - IForwardingRulesManagerAware.class).setCallbacks( - "setFrmAware", "unsetFrmAware").setRequired(false)); - c.add(createContainerServiceDependency(containerName).setService( - IfIptoHost.class).setCallbacks("setHostFinder", - "unsetHostFinder").setRequired(true)); - c.add(createContainerServiceDependency(containerName).setService( - IContainer.class).setCallbacks("setIContainer", - "unsetIContainer").setRequired(true)); } } } diff --git a/opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManagerImpl.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManagerImpl.java similarity index 100% rename from opendaylight/forwardingrulesmanager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManagerImpl.java rename to opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManagerImpl.java diff --git a/opendaylight/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/HostTracker.java b/opendaylight/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/HostTracker.java index 96b6c05934..45f3cedacb 100644 --- a/opendaylight/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/HostTracker.java +++ b/opendaylight/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/HostTracker.java @@ -639,7 +639,6 @@ public class HostTracker implements IfIptoHost, IfHostListener, if (switchNeedsTieringUpdate(dstNode, currentTier + 1)) { Tier t = new Tier(currentTier + 1); switchManager.setNodeProp(dstNode, t); - //logger.info("Updating Switch Tier "+ (currentTier+1) +" for "+String.format("%x", dstSw.getId())); needsVisiting.add(dstNode); } } @@ -684,7 +683,6 @@ public class HostTracker implements IfIptoHost, IfHostListener, return true; else if (t.getValue() > tier) return true; - //logger.info(getContainerName()+" -> "+ "Switch "+String.format("%x", sw.getId())+ " is in better Tier "+sw.getTier()+" ... skipping "+tier); return false; } @@ -956,6 +954,7 @@ public class HostTracker implements IfIptoHost, IfHostListener, } private class ARPRefreshHandler extends TimerTask { + @SuppressWarnings("deprecation") public void run() { if ((clusterContainerService != null) && !clusterContainerService.amICoordinator()) { @@ -992,8 +991,6 @@ public class HostTracker implements IfIptoHost, IfHostListener, notifyHostLearnedOrRemoved(host, false); } else if (arp_cntdown <= switchManager.getHostRetryCount()) { /* Use the services of arphandler to check if host is still there */ - // logger.info("Probe for Host:{}", host); - //logger.info("ARP Probing ("+arp_cntdown+") for "+host.toString()); logger.trace("ARP Probing ({}) for {}({})", new Object[] { arp_cntdown, host.getNetworkAddress().getHostAddress(), diff --git a/opendaylight/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/hostAware/HostNodeConnector.java b/opendaylight/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/hostAware/HostNodeConnector.java index d18070d222..c83dc3d408 100644 --- a/opendaylight/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/hostAware/HostNodeConnector.java +++ b/opendaylight/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/hostAware/HostNodeConnector.java @@ -43,6 +43,7 @@ public class HostNodeConnector extends Host { /** * Private constructor used for JAXB mapping */ + @SuppressWarnings("unused") private HostNodeConnector() { } diff --git a/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java b/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java index 75c5ca9cbb..d455a0ae20 100644 --- a/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java +++ b/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java @@ -44,7 +44,7 @@ public class Activator implements BundleActivator { .getService(service); if (reader == null) { this.log.error("Cannot register the LogListener because " - + "cannot retrive LogReaderService"); + + "cannot retrieve LogReaderService"); } reader.addLogListener(this.listener); // Now lets walk all the exiting messages @@ -66,7 +66,7 @@ public class Activator implements BundleActivator { controller.logging.bridge.internal.UncaughtExceptionHandler()); } else { this.log.error("Cannot register the LogListener because " - + "cannot retrive LogReaderService"); + + "cannot retrieve LogReaderService"); } } else { System.err diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerServiceDependency.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerServiceDependency.java index 29e9dfabb1..f37d0133e1 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerServiceDependency.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerServiceDependency.java @@ -46,6 +46,7 @@ public class ContainerServiceDependency implements ServiceDependency, this.containerName = containerName; } + @SuppressWarnings("rawtypes") // can't change org.apache.felix.dm.ServiceDependency @Override public ServiceDependency setService(Class serviceName) { this.m_dep.setService(serviceName, "(containerName=" @@ -53,6 +54,7 @@ public class ContainerServiceDependency implements ServiceDependency, return this; } + @SuppressWarnings("rawtypes") // can't change org.apache.felix.dm.ServiceDependency @Override public ServiceDependency setService(Class serviceName, String serviceFilter) { this.m_dep.setService(serviceName, "(&(containerName=" @@ -67,6 +69,7 @@ public class ContainerServiceDependency implements ServiceDependency, return this; } + @SuppressWarnings("rawtypes") // can't change org.apache.felix.dm.ServiceDependency @Override public ServiceDependency setService(Class serviceName, ServiceReference serviceReference) { @@ -163,6 +166,7 @@ public class ContainerServiceDependency implements ServiceDependency, .createCopy(), this.containerName); } + @SuppressWarnings("rawtypes") // can't change org.apache.felix.dm.ServiceDependency @Override public Dictionary getProperties() { return this.m_dep.getProperties(); @@ -193,6 +197,7 @@ public class ContainerServiceDependency implements ServiceDependency, return this.m_dep.isAutoConfig(); } + @SuppressWarnings("rawtypes") // can't change org.apache.felix.dm.ServiceDependency @Override public Class getAutoConfigType() { return this.m_dep.getAutoConfigType(); diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java index 206b3928ea..5c21294f46 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java @@ -53,8 +53,8 @@ public class Node implements Serializable { * surround. */ public static final class NodeIDType { - private static final ConcurrentHashMap compatibleType = - new ConcurrentHashMap(); + private static final ConcurrentHashMap> compatibleType = + new ConcurrentHashMap>(); /** * Identifier for an OpenFlow node */ @@ -113,7 +113,7 @@ public class Node implements Serializable { * @return true if registered, false otherwise */ public static boolean registerIDType(String type, - Class compatibleID) { + Class compatibleID) { if (compatibleType.get(type) != null) { return false; } else { diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java index 86baaade02..59a184e573 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java @@ -50,8 +50,8 @@ public class NodeConnector implements Serializable { */ public static class NodeConnectorIDType { private static final - ConcurrentHashMap> compatibleType = - new ConcurrentHashMap>(); + ConcurrentHashMap, String>> compatibleType = + new ConcurrentHashMap, String>>(); /** * Represent a special port pointing toward the controller, * this is to send data packets toward the controller from @@ -175,7 +175,7 @@ public class NodeConnector implements Serializable { * @return true if registered, false otherwise */ public static boolean registerIDType(String type, - Class compatibleID, + Class compatibleID, String compatibleNode) { if (compatibleType.get(type) != null) { return false; diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/ServiceHelper.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/ServiceHelper.java index 0555860696..ef9f2f4bad 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/ServiceHelper.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/ServiceHelper.java @@ -82,7 +82,8 @@ public class ServiceHelper { } return true; } catch (Exception e) { - logger.error("Exception "+e.getMessage() +" while registering the service "+instance.toString()); + logger.error("Exception {} while registering the service {}", + e.getMessage(), instance.toString()); } return false; } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/yang/types/test/GeneratedTypesTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/yang/types/test/GeneratedTypesTest.java index bd7fcb9ce6..bed4ef347e 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/yang/types/test/GeneratedTypesTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/yang/types/test/GeneratedTypesTest.java @@ -7,13 +7,12 @@ */ package org.opendaylight.controller.sal.binding.yang.types.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.List; import java.util.Set; +import org.junit.Ignore; import org.junit.Test; import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator; import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl; @@ -248,6 +247,7 @@ public class GeneratedTypesTest { assertEquals(10, resolvedLeafrefCount); } + @Ignore @Test public void testContainerResolving() { final String filePath = getClass().getResource( @@ -326,6 +326,7 @@ public class GeneratedTypesTest { assertEquals(4, methodsCount); } + @Ignore @Test public void testLeafListResolving() { final String filePath = getClass().getResource( @@ -399,6 +400,7 @@ public class GeneratedTypesTest { assertEquals(3, methodsCount); } + @Ignore @Test public void testListResolving() { final String filePath = getClass() diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java index 9df281fcd3..4ab054d663 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java @@ -10,34 +10,55 @@ package org.opendaylight.controller.sal.java.api.generator.test; import static org.junit.Assert.*; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator; +import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl; import org.opendaylight.controller.sal.binding.generator.impl.GeneratedTypeBuilderImpl; +import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.controller.sal.binding.model.api.GeneratedType; +import org.opendaylight.controller.sal.binding.model.api.Type; import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder; import org.opendaylight.controller.sal.java.api.generator.GeneratorJavaFile; import org.opendaylight.controller.sal.java.api.generator.InterfaceGenerator; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.SchemaContext; +import org.opendaylight.controller.yang.model.parser.impl.YangModelParserImpl; public class GeneratorJavaFileTest { - private static final String FS = File.separator; private static final String PATH = "test-dir"; private final File testDir = new File(PATH); + private static final String GENERATOR_OUTPUT_PATH = "src/test/resources/src"; + private static final File GENERATOR_OUTPUT = new File(GENERATOR_OUTPUT_PATH); + private static final String COMPILER_OUTPUT_PATH = "src/test/resources/bin"; + private static final File COMPILER_OUTPUT = new File(COMPILER_OUTPUT_PATH); + @Before public void init() { assertTrue(testDir.mkdir()); + assertTrue(COMPILER_OUTPUT.mkdirs()); + assertTrue(GENERATOR_OUTPUT.mkdirs()); } @After public void cleanUp() { deleteTestDir(testDir); + deleteTestDir(COMPILER_OUTPUT); + deleteTestDir(GENERATOR_OUTPUT); } @Test @@ -66,6 +87,54 @@ public class GeneratorJavaFileTest { assertTrue(filesList.contains("Type3.java")); } + @Test + public void compilationTest() throws Exception { + final YangModelParserImpl parser = new YangModelParserImpl(); + final BindingGenerator bindingGenerator = new BindingGeneratorImpl(); + + File sourcesDir = new File("src/test/resources/yang"); + File[] sourceFiles = sourcesDir.listFiles(); + String[] sourcesDirPaths = new String[sourceFiles.length]; + for (int i = 0; i < sourceFiles.length; i++) { + sourcesDirPaths[i] = sourceFiles[i].getAbsolutePath(); + } + final Set modulesToBuild = parser + .parseYangModels(sourcesDirPaths); + + final SchemaContext context = parser + .resolveSchemaContext(modulesToBuild); + final List types = bindingGenerator.generateTypes(context); + final Set typesToGenerate = new HashSet(); + final Set tosToGenerate = new HashSet(); + for (Type type : types) { + if (type instanceof GeneratedType) { + typesToGenerate.add((GeneratedType) type); + } + + if (type instanceof GeneratedTransferObject) { + tosToGenerate.add((GeneratedTransferObject) type); + } + } + + final GeneratorJavaFile generator = new GeneratorJavaFile( + typesToGenerate, tosToGenerate); + generator.generateToFile(GENERATOR_OUTPUT_PATH); + + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fileManager = compiler.getStandardFileManager( + null, null, null); + + List filesList = getJavaFiles(new File(GENERATOR_OUTPUT_PATH)); + + Iterable compilationUnits = fileManager + .getJavaFileObjectsFromFiles(filesList); + Iterable options = Arrays.asList(new String[] { "-d", + COMPILER_OUTPUT_PATH }); + boolean compiled = compiler.getTask(null, null, null, options, null, + compilationUnits).call(); + assertTrue(compiled); + } + private GeneratedType createGeneratedType(String pkgName, String name) { GeneratedTypeBuilder builder = new GeneratedTypeBuilderImpl(pkgName, name); @@ -83,4 +152,26 @@ public class GeneratorJavaFileTest { } } + /** + * Search recursively given directory for *.java files. + * + * @param directory + * directory to search + * @return List of java files found + */ + private List getJavaFiles(File directory) { + List result = new ArrayList(); + for (File file : directory.listFiles()) { + if (file.isDirectory()) { + result.addAll(getJavaFiles(file)); + } else { + String absPath = file.getAbsolutePath(); + if (absPath.endsWith(".java")) { + result.add(file); + } + } + } + return result; + } + } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/abstract-topology@2013-02-08.yang b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/abstract-topology@2013-02-08.yang new file mode 100644 index 0000000000..7ed1f99503 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/abstract-topology@2013-02-08.yang @@ -0,0 +1,141 @@ +module abstract-topology { + yang-version 1; + namespace "urn:model:abstract:topology"; + prefix "tp"; + + import ietf-inet-types { + prefix "inet"; + revision-date 2010-09-24; + } + + import ietf-interfaces { + prefix "if"; + revision-date 2012-11-15; + } + + organization "Cisco"; + contact "WILL-BE-DEFINED-LATER"; + + description + "This module contains the definitions of elements that creates network + topology i.e. definition of network nodes and links. This module is not designed to be used solely for network representation. This module SHOULD be used as base module in defining the network topology."; + + revision "2013-02-08" { + reference "~~~ WILL BE DEFINED LATER"; + } + + revision "2013-01-01" { + reference "~~~ WILL BE DEFINED LATER"; + } + + typedef node-id-ref { + type leafref { + path "/tp:topology/tp:network-nodes/tp:network-node/tp:node-id"; + } + description "This type is used for leafs that reference network node instance."; + } + + typedef link-id-ref { + type leafref { + path "/tp:topology/tp:network-links/tp:network-link/tp:link-id"; + } + description "This type is used for leafs that reference network link instance."; + } + + typedef interface-id-ref { + type leafref { + path "/tp:topology/tp:interfaces/tp:interface/tp:interface-id"; + } + } + + container topology { + description "This is the model of abstract topology which contains only Network Nodes and Network Links. Each topology MUST be identified by unique topology-id for reason that the store could contain many topologies."; + + leaf topology-id { + type inet:uri; + description "It is presumed that datastore will contain many topologies. To distinguish between topologies it is vital to have + UNIQUE topology identifier."; + } + + container network-nodes { + list network-node { + key "node-id"; + + leaf node-id { + type inet:uri; + description "The Topology identifier of network-node."; + } + + container attributes { + description "Aditional attributes that can Network Node contains."; + } + description "The list of network nodes defined for topology."; + } + } + + container interfaces { + list interface { + key "interface-id"; + + leaf interface-id { + type leafref { + path "/if:interfaces/if:interface/if:name"; + } + } + + leaf-list higher-layer-if { + type leafref { + path "/if:interfaces/if:interface/if:higher-layer-if"; + } + } + } + } + + container network-links { + list network-link { + key "link-id"; + + leaf link-id { + type inet:uri; + description ""; + } + + container source-node { + leaf id { + type node-id-ref; + description "Source node identifier."; + } + } + + container destination-node { + leaf id { + type node-id-ref; + description "Destination node identifier."; + } + } + + container tunnels { + list tunnel { + key "tunnel-id"; + + leaf tunnel-id { + type leafref { + path "../../../link-id"; + } + } + } + } + + leaf interface { + type interface-id-ref; + } + + container attributes { + description "Aditional attributes that can Network Link contains."; + } + description "The Network Link which is defined by Local (Source) and Remote (Destination) Network Nodes. Every link MUST be defined either by identifier and + his local and remote Network Nodes (In real applications it is common that many links are originated from one node and end up in same remote node). To ensure that we would always know to distinguish between links, every link SHOULD have identifier."; + } + } + } +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/iana-if-type@2012-06-05.yang b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/iana-if-type@2012-06-05.yang new file mode 100644 index 0000000000..a7fa137a7e --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/iana-if-type@2012-06-05.yang @@ -0,0 +1,1516 @@ +module iana-if-type { + namespace "urn:ietf:params:xml:ns:yang:iana-if-type"; + prefix ianaift; + + organization "IANA"; + contact + " Internet Assigned Numbers Authority + + Postal: ICANN + 4676 Admiralty Way, Suite 330 + Marina del Rey, CA 90292 + + Tel: +1 310 823 9358 + E-Mail: iana&iana.org"; + description + "This YANG module defines the iana-if-type typedef, which + contains YANG definitions for IANA-registered interface types. + + This YANG module is maintained by IANA, and reflects the + 'ifType definitions' registry. + + The latest revision of this YANG module can be obtained from + the IANA web site. + + Copyright (c) 2011 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, is permitted pursuant to, and subject + to the license terms contained in, the Simplified BSD License + set forth in Section 4.c of the IETF Trust's Legal Provisions + Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC XXXX; see + the RFC itself for full legal notices."; + // RFC Ed.: replace XXXX with actual RFC number and remove this + // note. + + // RFC Ed.: update the date below with the date of RFC publication + // and remove this note. + revision 2012-06-05 { + description + "Initial revision."; + reference + "RFC XXXX: TITLE"; + } + + typedef iana-if-type { + type enumeration { + enum "other" { + value 1; + description + "None of the following"; + } + enum "regular1822" { + value 2; + } + enum "hdh1822" { + value 3; + } + enum "ddnX25" { + value 4; + } + enum "rfc877x25" { + value 5; + reference + "RFC 1382 - SNMP MIB Extension for the X.25 Packet Layer"; + } + enum "ethernetCsmacd" { + value 6; + description + "For all ethernet-like interfaces, regardless of speed, + as per RFC3635."; + reference + "RFC 3635 - Definitions of Managed Objects for the + Ethernet-like Interface Types."; + } + enum "iso88023Csmacd" { + value 7; + status deprecated; + description + "Deprecated via RFC3635. + Use ethernetCsmacd(6) instead."; + reference + "RFC 3635 - Definitions of Managed Objects for the + Ethernet-like Interface Types."; + } + enum "iso88024TokenBus" { + value 8; + } + enum "iso88025TokenRing" { + value 9; + } + enum "iso88026Man" { + value 10; + } + enum "starLan" { + value 11; + status deprecated; + description + "Deprecated via RFC3635. + Use ethernetCsmacd(6) instead."; + reference + "RFC 3635 - Definitions of Managed Objects for the + Ethernet-like Interface Types."; + } + enum "proteon10Mbit" { + value 12; + } + enum "proteon80Mbit" { + value 13; + } + enum "hyperchannel" { + value 14; + } + enum "fddi" { + value 15; + reference + "RFC 1512 - FDDI Management Information Base"; + } + enum "lapb" { + value 16; + reference + "RFC 1381 - SNMP MIB Extension for X.25 LAPB"; + } + enum "sdlc" { + value 17; + } + enum "ds1" { + value 18; + description + "DS1-MIB"; + reference + "RFC 4805 - Definitions of Managed Objects for the + DS1, J1, E1, DS2, and E2 Interface Types"; + } + enum "e1" { + value 19; + status obsolete; + description + "Obsolete see DS1-MIB"; + reference + "RFC 4805 - Definitions of Managed Objects for the + DS1, J1, E1, DS2, and E2 Interface Types"; + } + enum "basicISDN" { + value 20; + description + "see also RFC2127"; + } + enum "primaryISDN" { + value 21; + } + enum "propPointToPointSerial" { + value 22; + description + "proprietary serial"; + } + enum "ppp" { + value 23; + } + enum "softwareLoopback" { + value 24; + } + enum "eon" { + value 25; + description + "CLNP over IP"; + } + enum "ethernet3Mbit" { + value 26; + } + enum "nsip" { + value 27; + description + "XNS over IP"; + } + enum "slip" { + value 28; + description + "generic SLIP"; + } + enum "ultra" { + value 29; + description + "ULTRA technologies"; + } + enum "ds3" { + value 30; + description + "DS3-MIB"; + reference + "RFC 3896 - Definitions of Managed Objects for the + DS3/E3 Interface Type"; + } + enum "sip" { + value 31; + description + "SMDS, coffee"; + reference + "RFC 1694 - Definitions of Managed Objects for SMDS + Interfaces using SMIv2"; + } + enum "frameRelay" { + value 32; + description + "DTE only."; + reference + "RFC 2115 - Management Information Base for Frame Relay + DTEs Using SMIv2"; + } + enum "rs232" { + value 33; + reference + "RFC 1659 - Definitions of Managed Objects for RS-232-like + Hardware Devices using SMIv2"; + } + enum "para" { + value 34; + description + "parallel-port"; + reference + "RFC 1660 - Definitions of Managed Objects for + Parallel-printer-like Hardware Devices using + SMIv2"; + } + enum "arcnet" { + value 35; + description + "arcnet"; + } + enum "arcnetPlus" { + value 36; + description + "arcnet plus"; + } + enum "atm" { + value 37; + description + "ATM cells"; + } + enum "miox25" { + value 38; + reference + "RFC 1461 - SNMP MIB extension for Multiprotocol + Interconnect over X.25"; + } + enum "sonet" { + value 39; + description + "SONET or SDH"; + } + enum "x25ple" { + value 40; + reference + "RFC 2127 - ISDN Management Information Base using SMIv2"; + } + enum "iso88022llc" { + value 41; + } + enum "localTalk" { + value 42; + } + enum "smdsDxi" { + value 43; + } + enum "frameRelayService" { + value 44; + description + "FRNETSERV-MIB"; + reference + "RFC 2954 - Definitions of Managed Objects for Frame + Relay Service"; + } + enum "v35" { + value 45; + } + enum "hssi" { + value 46; + } + enum "hippi" { + value 47; + } + enum "modem" { + value 48; + description + "Generic modem"; + } + enum "aal5" { + value 49; + description + "AAL5 over ATM"; + } + enum "sonetPath" { + value 50; + } + enum "sonetVT" { + value 51; + } + enum "smdsIcip" { + value 52; + description + "SMDS InterCarrier Interface"; + } + enum "propVirtual" { + value 53; + description + "proprietary virtual/internal"; + reference + "RFC 2863 - The Interfaces Group MIB"; + } + enum "propMultiplexor" { + value 54; + description + "proprietary multiplexing"; + reference + "RFC 2863 - The Interfaces Group MIB"; + } + enum "ieee80212" { + value 55; + description + "100BaseVG"; + } + enum "fibreChannel" { + value 56; + description + "Fibre Channel"; + } + enum "hippiInterface" { + value 57; + description + "HIPPI interfaces"; + } + enum "frameRelayInterconnect" { + value 58; + status obsolete; + description + "Obsolete use either + frameRelay(32) or frameRelayService(44)."; + } + enum "aflane8023" { + value 59; + description + "ATM Emulated LAN for 802.3"; + } + enum "aflane8025" { + value 60; + description + "ATM Emulated LAN for 802.5"; + } + enum "cctEmul" { + value 61; + description + "ATM Emulated circuit"; + } + enum "fastEther" { + value 62; + status deprecated; + description + "Obsoleted via RFC3635. + ethernetCsmacd(6) should be used instead"; + reference + "RFC 3635 - Definitions of Managed Objects for the + Ethernet-like Interface Types."; + } + enum "isdn" { + value 63; + description + "ISDN and X.25"; + reference + "RFC 1356 - Multiprotocol Interconnect on X.25 and ISDN + in the Packet Mode"; + } + enum "v11" { + value 64; + description + "CCITT V.11/X.21"; + } + enum "v36" { + value 65; + description + "CCITT V.36"; + } + enum "g703at64k" { + value 66; + description + "CCITT G703 at 64Kbps"; + } + enum "g703at2mb" { + value 67; + status obsolete; + description + "Obsolete see DS1-MIB"; + } + enum "qllc" { + value 68; + description + "SNA QLLC"; + } + enum "fastEtherFX" { + value 69; + status deprecated; + description + "Obsoleted via RFC3635 + ethernetCsmacd(6) should be used instead"; + reference + "RFC 3635 - Definitions of Managed Objects for the + Ethernet-like Interface Types."; + } + enum "channel" { + value 70; + description + "channel"; + } + enum "ieee80211" { + value 71; + description + "radio spread spectrum"; + } + enum "ibm370parChan" { + value 72; + description + "IBM System 360/370 OEMI Channel"; + } + enum "escon" { + value 73; + description + "IBM Enterprise Systems Connection"; + } + enum "dlsw" { + value 74; + description + "Data Link Switching"; + } + enum "isdns" { + value 75; + description + "ISDN S/T interface"; + } + enum "isdnu" { + value 76; + description + "ISDN U interface"; + } + enum "lapd" { + value 77; + description + "Link Access Protocol D"; + } + enum "ipSwitch" { + value 78; + description + "IP Switching Objects"; + } + enum "rsrb" { + value 79; + description + "Remote Source Route Bridging"; + } + enum "atmLogical" { + value 80; + description + "ATM Logical Port"; + reference + "RFC 3606 - Definitions of Supplemental Managed Objects + for ATM Interface"; + } + enum "ds0" { + value 81; + description + "Digital Signal Level 0"; + reference + "RFC 2494 - Definitions of Managed Objects for the DS0 + and DS0 Bundle Interface Type"; + } + enum "ds0Bundle" { + value 82; + description + "group of ds0s on the same ds1"; + reference + "RFC 2494 - Definitions of Managed Objects for the DS0 + and DS0 Bundle Interface Type"; + } + enum "bsc" { + value 83; + description + "Bisynchronous Protocol"; + } + enum "async" { + value 84; + description + "Asynchronous Protocol"; + } + enum "cnr" { + value 85; + description + "Combat Net Radio"; + } + enum "iso88025Dtr" { + value 86; + description + "ISO 802.5r DTR"; + } + enum "eplrs" { + value 87; + description + "Ext Pos Loc Report Sys"; + } + enum "arap" { + value 88; + description + "Appletalk Remote Access Protocol"; + } + enum "propCnls" { + value 89; + description + "Proprietary Connectionless Protocol"; + } + enum "hostPad" { + value 90; + description + "CCITT-ITU X.29 PAD Protocol"; + } + enum "termPad" { + value 91; + description + "CCITT-ITU X.3 PAD Facility"; + } + enum "frameRelayMPI" { + value 92; + description + "Multiproto Interconnect over FR"; + } + enum "x213" { + value 93; + description + "CCITT-ITU X213"; + } + enum "adsl" { + value 94; + description + "Asymmetric Digital Subscriber Loop"; + } + enum "radsl" { + value 95; + description + "Rate-Adapt. Digital Subscriber Loop"; + } + enum "sdsl" { + value 96; + description + "Symmetric Digital Subscriber Loop"; + } + enum "vdsl" { + value 97; + description + "Very H-Speed Digital Subscrib. Loop"; + } + enum "iso88025CRFPInt" { + value 98; + description + "ISO 802.5 CRFP"; + } + enum "myrinet" { + value 99; + description + "Myricom Myrinet"; + } + enum "voiceEM" { + value 100; + description + "voice recEive and transMit"; + } + enum "voiceFXO" { + value 101; + description + "voice Foreign Exchange Office"; + } + enum "voiceFXS" { + value 102; + description + "voice Foreign Exchange Station"; + } + enum "voiceEncap" { + value 103; + description + "voice encapsulation"; + } + enum "voiceOverIp" { + value 104; + description + "voice over IP encapsulation"; + } + enum "atmDxi" { + value 105; + description + "ATM DXI"; + } + enum "atmFuni" { + value 106; + description + "ATM FUNI"; + } + enum "atmIma" { + value 107; + description + "ATM IMA"; + } + enum "pppMultilinkBundle" { + value 108; + description + "PPP Multilink Bundle"; + } + enum "ipOverCdlc" { + value 109; + description + "IBM ipOverCdlc"; + } + enum "ipOverClaw" { + value 110; + description + "IBM Common Link Access to Workstn"; + } + enum "stackToStack" { + value 111; + description + "IBM stackToStack"; + } + enum "virtualIpAddress" { + value 112; + description + "IBM VIPA"; + } + enum "mpc" { + value 113; + description + "IBM multi-protocol channel support"; + } + enum "ipOverAtm" { + value 114; + description + "IBM ipOverAtm"; + reference + "RFC 2320 - Definitions of Managed Objects for Classical IP + and ARP Over ATM Using SMIv2 (IPOA-MIB)"; + } + enum "iso88025Fiber" { + value 115; + description + "ISO 802.5j Fiber Token Ring"; + } + enum "tdlc" { + value 116; + description + "IBM twinaxial data link control"; + } + enum "gigabitEthernet" { + value 117; + status deprecated; + description + "Obsoleted via RFC3635 + ethernetCsmacd(6) should be used instead"; + reference + "RFC 3635 - Definitions of Managed Objects for the + Ethernet-like Interface Types."; + } + enum "hdlc" { + value 118; + description + "HDLC"; + } + enum "lapf" { + value 119; + description + "LAP F"; + } + enum "v37" { + value 120; + description + "V.37"; + } + enum "x25mlp" { + value 121; + description + "Multi-Link Protocol"; + } + enum "x25huntGroup" { + value 122; + description + "X25 Hunt Group"; + } + enum "transpHdlc" { + value 123; + description + "Transp HDLC"; + } + enum "interleave" { + value 124; + description + "Interleave channel"; + } + enum "fast" { + value 125; + description + "Fast channel"; + } + enum "ip" { + value 126; + description + "IP (for APPN HPR in IP networks)"; + } + enum "docsCableMaclayer" { + value 127; + description + "CATV Mac Layer"; + } + enum "docsCableDownstream" { + value 128; + description + "CATV Downstream interface"; + } + enum "docsCableUpstream" { + value 129; + description + "CATV Upstream interface"; + } + enum "a12MppSwitch" { + value 130; + description + "Avalon Parallel Processor"; + } + enum "tunnel" { + value 131; + description + "Encapsulation interface"; + } + enum "coffee" { + value 132; + description + "coffee pot"; + reference + "RFC 2325 - Coffee MIB"; + } + enum "ces" { + value 133; + description + "Circuit Emulation Service"; + } + enum "atmSubInterface" { + value 134; + description + "ATM Sub Interface"; + } + enum "l2vlan" { + value 135; + description + "Layer 2 Virtual LAN using 802.1Q"; + } + enum "l3ipvlan" { + value 136; + description + "Layer 3 Virtual LAN using IP"; + } + enum "l3ipxvlan" { + value 137; + description + "Layer 3 Virtual LAN using IPX"; + } + enum "digitalPowerline" { + value 138; + description + "IP over Power Lines"; + } + enum "mediaMailOverIp" { + value 139; + description + "Multimedia Mail over IP"; + } + enum "dtm" { + value 140; + description + "Dynamic syncronous Transfer Mode"; + } + enum "dcn" { + value 141; + description + "Data Communications Network"; + } + enum "ipForward" { + value 142; + description + "IP Forwarding Interface"; + } + enum "msdsl" { + value 143; + description + "Multi-rate Symmetric DSL"; + } + enum "ieee1394" { + value 144; + description + "IEEE1394 High Performance Serial Bus"; + } + enum "if-gsn" { + value 145; + description + "HIPPI-6400"; + } + enum "dvbRccMacLayer" { + value 146; + description + "DVB-RCC MAC Layer"; + } + enum "dvbRccDownstream" { + value 147; + description + "DVB-RCC Downstream Channel"; + } + enum "dvbRccUpstream" { + value 148; + description + "DVB-RCC Upstream Channel"; + } + enum "atmVirtual" { + value 149; + description + "ATM Virtual Interface"; + } + enum "mplsTunnel" { + value 150; + description + "MPLS Tunnel Virtual Interface"; + } + enum "srp" { + value 151; + description + "Spatial Reuse Protocol "; + } + enum "voiceOverAtm" { + value 152; + description + "Voice Over ATM"; + } + enum "voiceOverFrameRelay" { + value 153; + description + "Voice Over Frame Relay"; + } + enum "idsl" { + value 154; + description + "Digital Subscriber Loop over ISDN"; + } + enum "compositeLink" { + value 155; + description + "Avici Composite Link Interface"; + } + enum "ss7SigLink" { + value 156; + description + "SS7 Signaling Link"; + } + enum "propWirelessP2P" { + value 157; + description + "Prop. P2P wireless interface"; + } + enum "frForward" { + value 158; + description + "Frame Forward Interface"; + } + enum "rfc1483" { + value 159; + description + "Multiprotocol over ATM AAL5"; + reference + "RFC 1483 - Multiprotocol Encapsulation over ATM + Adaptation Layer 5"; + } + enum "usb" { + value 160; + description + "USB Interface"; + } + enum "ieee8023adLag" { + value 161; + description + "IEEE 802.3ad Link Aggregate"; + } + enum "bgppolicyaccounting" { + value 162; + description + "BGP Policy Accounting"; + } + enum "frf16MfrBundle" { + value 163; + description + "FRF .16 Multilink Frame Relay"; + } + enum "h323Gatekeeper" { + value 164; + description + "H323 Gatekeeper"; + } + enum "h323Proxy" { + value 165; + description + "H323 Voice and Video Proxy"; + } + enum "mpls" { + value 166; + description + "MPLS"; + } + enum "mfSigLink" { + value 167; + description + "Multi-frequency signaling link"; + } + enum "hdsl2" { + value 168; + description + "High Bit-Rate DSL - 2nd generation"; + } + enum "shdsl" { + value 169; + description + "Multirate HDSL2"; + } + enum "ds1FDL" { + value 170; + description + "Facility Data Link 4Kbps on a DS1"; + } + enum "pos" { + value 171; + description + "Packet over SONET/SDH Interface"; + } + enum "dvbAsiIn" { + value 172; + description + "DVB-ASI Input"; + } + enum "dvbAsiOut" { + value 173; + description + "DVB-ASI Output"; + } + enum "plc" { + value 174; + description + "Power Line Communtications"; + } + enum "nfas" { + value 175; + description + "Non Facility Associated Signaling"; + } + enum "tr008" { + value 176; + description + "TR008"; + } + enum "gr303RDT" { + value 177; + description + "Remote Digital Terminal"; + } + enum "gr303IDT" { + value 178; + description + "Integrated Digital Terminal"; + } + enum "isup" { + value 179; + description + "ISUP"; + } + enum "propDocsWirelessMaclayer" { + value 180; + description + "Cisco proprietary Maclayer"; + } + enum "propDocsWirelessDownstream" { + value 181; + description + "Cisco proprietary Downstream"; + } + enum "propDocsWirelessUpstream" { + value 182; + description + "Cisco proprietary Upstream"; + } + enum "hiperlan2" { + value 183; + description + "HIPERLAN Type 2 Radio Interface"; + } + enum "propBWAp2Mp" { + value 184; + description + "PropBroadbandWirelessAccesspt2multipt use of this value + for IEEE 802.16 WMAN interfaces as per IEEE Std 802.16f + is deprecated and ieee80216WMAN(237) should be used + instead."; + } + enum "sonetOverheadChannel" { + value 185; + description + "SONET Overhead Channel"; + } + enum "digitalWrapperOverheadChannel" { + value 186; + description + "Digital Wrapper"; + } + enum "aal2" { + value 187; + description + "ATM adaptation layer 2"; + } + enum "radioMAC" { + value 188; + description + "MAC layer over radio links"; + } + enum "atmRadio" { + value 189; + description + "ATM over radio links"; + } + enum "imt" { + value 190; + description + "Inter Machine Trunks"; + } + enum "mvl" { + value 191; + description + "Multiple Virtual Lines DSL"; + } + enum "reachDSL" { + value 192; + description + "Long Reach DSL"; + } + enum "frDlciEndPt" { + value 193; + description + "Frame Relay DLCI End Point"; + } + enum "atmVciEndPt" { + value 194; + description + "ATM VCI End Point"; + } + enum "opticalChannel" { + value 195; + description + "Optical Channel"; + } + enum "opticalTransport" { + value 196; + description + "Optical Transport"; + } + enum "propAtm" { + value 197; + description + "Proprietary ATM"; + } + enum "voiceOverCable" { + value 198; + description + "Voice Over Cable Interface"; + } + enum "infiniband" { + value 199; + description + "Infiniband"; + } + enum "teLink" { + value 200; + description + "TE Link"; + } + enum "q2931" { + value 201; + description + "Q.2931"; + } + enum "virtualTg" { + value 202; + description + "Virtual Trunk Group"; + } + enum "sipTg" { + value 203; + description + "SIP Trunk Group"; + } + enum "sipSig" { + value 204; + description + "SIP Signaling"; + } + enum "docsCableUpstreamChannel" { + value 205; + description + "CATV Upstream Channel"; + } + enum "econet" { + value 206; + description + "Acorn Econet"; + } + enum "pon155" { + value 207; + description + "FSAN 155Mb Symetrical PON interface"; + } + enum "pon622" { + value 208; + description + "FSAN622Mb Symetrical PON interface"; + } + enum "bridge" { + value 209; + description + "Transparent bridge interface"; + } + enum "linegroup" { + value 210; + description + "Interface common to multiple lines"; + } + enum "voiceEMFGD" { + value 211; + description + "voice E&M Feature Group D"; + } + enum "voiceFGDEANA" { + value 212; + description + "voice FGD Exchange Access North American"; + } + enum "voiceDID" { + value 213; + description + "voice Direct Inward Dialing"; + } + enum "mpegTransport" { + value 214; + description + "MPEG transport interface"; + } + enum "sixToFour" { + value 215; + status deprecated; + description + "6to4 interface (DEPRECATED)"; + reference + "RFC 4087 - IP Tunnel MIB"; + } + enum "gtp" { + value 216; + description + "GTP (GPRS Tunneling Protocol)"; + } + enum "pdnEtherLoop1" { + value 217; + description + "Paradyne EtherLoop 1"; + } + enum "pdnEtherLoop2" { + value 218; + description + "Paradyne EtherLoop 2"; + } + enum "opticalChannelGroup" { + value 219; + description + "Optical Channel Group"; + } + enum "homepna" { + value 220; + description + "HomePNA ITU-T G.989"; + } + enum "gfp" { + value 221; + description + "Generic Framing Procedure (GFP)"; + } + enum "ciscoISLvlan" { + value 222; + description + "Layer 2 Virtual LAN using Cisco ISL"; + } + enum "actelisMetaLOOP" { + value 223; + description + "Acteleis proprietary MetaLOOP High Speed Link"; + } + enum "fcipLink" { + value 224; + description + "FCIP Link"; + } + enum "rpr" { + value 225; + description + "Resilient Packet Ring Interface Type"; + } + enum "qam" { + value 226; + description + "RF Qam Interface"; + } + enum "lmp" { + value 227; + description + "Link Management Protocol"; + reference + "RFC 4327 - Link Management Protocol (LMP) Management + Information Base (MIB)"; + } + enum "cblVectaStar" { + value 228; + description + "Cambridge Broadband Networks Limited VectaStar"; + } + enum "docsCableMCmtsDownstream" { + value 229; + description + "CATV Modular CMTS Downstream Interface"; + } + enum "adsl2" { + value 230; + status deprecated; + description + "Asymmetric Digital Subscriber Loop Version 2 + (DEPRECATED/OBSOLETED - please use adsl2plus(238) + instead)"; + reference + "RFC 4706 - Definitions of Managed Objects for Asymmetric + Digital Subscriber Line 2 (ADSL2)"; + } + enum "macSecControlledIF" { + value 231; + description + "MACSecControlled"; + } + enum "macSecUncontrolledIF" { + value 232; + description + "MACSecUncontrolled"; + } + enum "aviciOpticalEther" { + value 233; + description + "Avici Optical Ethernet Aggregate"; + } + enum "atmbond" { + value 234; + description + "atmbond"; + } + enum "voiceFGDOS" { + value 235; + description + "voice FGD Operator Services"; + } + enum "mocaVersion1" { + value 236; + description + "MultiMedia over Coax Alliance (MoCA) Interface + as documented in information provided privately to IANA"; + } + enum "ieee80216WMAN" { + value 237; + description + "IEEE 802.16 WMAN interface"; + } + enum "adsl2plus" { + value 238; + description + "Asymmetric Digital Subscriber Loop Version 2, + Version 2 Plus and all variants"; + } + enum "dvbRcsMacLayer" { + value 239; + description + "DVB-RCS MAC Layer"; + reference + "RFC 5728 - The SatLabs Group DVB-RCS MIB"; + } + enum "dvbTdm" { + value 240; + description + "DVB Satellite TDM"; + reference + "RFC 5728 - The SatLabs Group DVB-RCS MIB"; + } + enum "dvbRcsTdma" { + value 241; + description + "DVB-RCS TDMA"; + reference + "RFC 5728 - The SatLabs Group DVB-RCS MIB"; + } + enum "x86Laps" { + value 242; + description + "LAPS based on ITU-T X.86/Y.1323"; + } + enum "wwanPP" { + value 243; + description + "3GPP WWAN"; + } + enum "wwanPP2" { + value 244; + description + "3GPP2 WWAN"; + } + enum "voiceEBS" { + value 245; + description + "voice P-phone EBS physical interface"; + } + enum "ifPwType" { + value 246; + description + "Pseudowire interface type"; + reference + "RFC 5601 - Pseudowire (PW) Management Information Base"; + } + enum "ilan" { + value 247; + description + "Internal LAN on a bridge per IEEE 802.1ap"; + } + enum "pip" { + value 248; + description + "Provider Instance Port on a bridge per IEEE 802.1ah PBB"; + } + enum "aluELP" { + value 249; + description + "Alcatel-Lucent Ethernet Link Protection"; + } + enum "gpon" { + value 250; + description + "Gigabit-capable passive optical networks (G-PON) as per + ITU-T G.948"; + } + enum "vdsl2" { + value 251; + description + "Very high speed digital subscriber line Version 2 + (as per ITU-T Recommendation G.993.2)"; + reference + "RFC 5650 - Definitions of Managed Objects for Very High + Speed Digital Subscriber Line 2 (VDSL2)"; + } + enum "capwapDot11Profile" { + value 252; + description + "WLAN Profile Interface"; + reference + "RFC 5834 - Control and Provisioning of Wireless Access + Points (CAPWAP) Protocol Binding MIB for + IEEE 802.11"; + } + enum "capwapDot11Bss" { + value 253; + description + "WLAN BSS Interface"; + reference + "RFC 5834 - Control and Provisioning of Wireless Access + Points (CAPWAP) Protocol Binding MIB for + IEEE 802.11"; + } + enum "capwapWtpVirtualRadio" { + value 254; + description + "WTP Virtual Radio Interface"; + reference + "RFC 5833 - Control and Provisioning of Wireless Access + Points (CAPWAP) Protocol Base MIB"; + } + enum "bits" { + value 255; + description + "bitsport"; + } + enum "docsCableUpstreamRfPort" { + value 256; + description + "DOCSIS CATV Upstream RF Port"; + } + enum "cableDownstreamRfPort" { + value 257; + description + "CATV downstream RF port"; + } + enum "vmwareVirtualNic" { + value 258; + description + "VMware Virtual Network Interface"; + } + enum "ieee802154" { + value 259; + description + "IEEE 802.15.4 WPAN interface"; + reference + "IEEE 802.15.4-2006"; + } + enum "otnOdu" { + value 260; + description + "OTN Optical Data Unit"; + } + enum "otnOtu" { + value 261; + description + "OTN Optical channel Transport Unit"; + } + enum "ifVfiType" { + value 262; + description + "VPLS Forwarding Instance Interface Type"; + } + enum "g9981" { + value 263; + description + "G.998.1 bonded interface"; + } + enum "g9982" { + value 264; + description + "G.998.2 bonded interface"; + } + enum "g9983" { + value 265; + description + "G.998.3 bonded interface"; + } + enum "aluEpon" { + value 266; + description + "Ethernet Passive Optical Networks (E-PON)"; + } + enum "aluEponOnu" { + value 267; + description + "EPON Optical Network Unit"; + } + enum "aluEponPhysicalUni" { + value 268; + description + "EPON physical User to Network interface"; + } + enum "aluEponLogicalLink" { + value 269; + description + "The emulation of a point-to-point link over the EPON + layer"; + } + enum "aluGponOnu" { + value 270; + description + "GPON Optical Network Unit"; + reference + "ITU-T G.984.2"; + } + enum "aluGponPhysicalUni" { + value 271; + description + "GPON physical User to Network interface"; + reference + "ITU-T G.984.2"; + } + enum "vmwareNicTeam" { + value 272; + description + "VMware NIC Team"; + } + } + description + "This data type is used as the syntax of the 'type' + leaf in the 'interface' list in the YANG module + ietf-interface. + + The definition of this typedef with the + addition of newly assigned values is published + periodically by the IANA, in either the Assigned + Numbers RFC, or some derivative of it specific to + Internet Network Management number assignments. (The + latest arrangements can be obtained by contacting the + IANA.) + + Requests for new values should be made to IANA via + email (iana&iana.org)."; + reference + "ifType definitions registry. + "; + } +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-inet-types@2010-09-24.yang b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-inet-types@2010-09-24.yang new file mode 100644 index 0000000000..6a6c7483ec --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-inet-types@2010-09-24.yang @@ -0,0 +1,418 @@ + module ietf-inet-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types"; + prefix "inet"; + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: David Partain + + + WG Chair: David Kessens + + + Editor: Juergen Schoenwaelder + "; + + description + "This module contains a collection of generally useful derived + YANG data types for Internet addresses and related things. + + Copyright (c) 2010 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, is permitted pursuant to, and subject to the license + terms contained in, the Simplified BSD License set forth in Section + 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC 6021; see + the RFC itself for full legal notices."; + + revision 2010-09-24 { + description + "Initial revision."; + reference + "RFC 6021: Common YANG Data Types"; + } + + /*** collection of protocol field related types ***/ + + typedef ip-version { + type enumeration { + enum unknown { + value "0"; + description + "An unknown or unspecified version of the Internet protocol."; + } + enum ipv4 { + value "1"; + description + "The IPv4 protocol as defined in RFC 791."; + } + enum ipv6 { + value "2"; + description + "The IPv6 protocol as defined in RFC 2460."; + } + } + description + "This value represents the version of the IP protocol. + + In the value set and its semantics, this type is equivalent + to the InetVersion textual convention of the SMIv2."; + reference + "RFC 791: Internet Protocol + RFC 2460: Internet Protocol, Version 6 (IPv6) Specification + RFC 4001: Textual Conventions for Internet Network Addresses"; + } + + typedef dscp { + type uint8 { + range "0..63"; + } + description + "The dscp type represents a Differentiated Services Code-Point + that may be used for marking packets in a traffic stream. + + In the value set and its semantics, this type is equivalent + to the Dscp textual convention of the SMIv2."; + reference + "RFC 3289: Management Information Base for the Differentiated + Services Architecture + RFC 2474: Definition of the Differentiated Services Field + (DS Field) in the IPv4 and IPv6 Headers + RFC 2780: IANA Allocation Guidelines For Values In + the Internet Protocol and Related Headers"; + } + + typedef ipv6-flow-label { + type uint32 { + range "0..1048575"; + } + description + "The flow-label type represents flow identifier or Flow Label + in an IPv6 packet header that may be used to discriminate + traffic flows. + + In the value set and its semantics, this type is equivalent + to the IPv6FlowLabel textual convention of the SMIv2."; + reference + "RFC 3595: Textual Conventions for IPv6 Flow Label + RFC 2460: Internet Protocol, Version 6 (IPv6) Specification"; + } + + typedef port-number { + type uint16 { + range "0..65535"; + } + description + "The port-number type represents a 16-bit port number of an + Internet transport layer protocol such as UDP, TCP, DCCP, or + SCTP. Port numbers are assigned by IANA. A current list of + all assignments is available from . + + Note that the port number value zero is reserved by IANA. In + situations where the value zero does not make sense, it can + be excluded by subtyping the port-number type. + + In the value set and its semantics, this type is equivalent + to the InetPortNumber textual convention of the SMIv2."; + reference + "RFC 768: User Datagram Protocol + RFC 793: Transmission Control Protocol + RFC 4960: Stream Control Transmission Protocol + RFC 4340: Datagram Congestion Control Protocol (DCCP) + RFC 4001: Textual Conventions for Internet Network Addresses"; + } + + /*** collection of autonomous system related types ***/ + + typedef as-number { + type uint32; + description + "The as-number type represents autonomous system numbers + which identify an Autonomous System (AS). An AS is a set + of routers under a single technical administration, using + an interior gateway protocol and common metrics to route + packets within the AS, and using an exterior gateway + protocol to route packets to other ASs'. IANA maintains + the AS number space and has delegated large parts to the + regional registries. + + Autonomous system numbers were originally limited to 16 + bits. BGP extensions have enlarged the autonomous system + number space to 32 bits. This type therefore uses an uint32 + base type without a range restriction in order to support + a larger autonomous system number space. + + In the value set and its semantics, this type is equivalent + to the InetAutonomousSystemNumber textual convention of + the SMIv2."; + reference + "RFC 1930: Guidelines for creation, selection, and registration + of an Autonomous System (AS) + RFC 4271: A Border Gateway Protocol 4 (BGP-4) + RFC 4893: BGP Support for Four-octet AS Number Space + RFC 4001: Textual Conventions for Internet Network Addresses"; + } + + /*** collection of IP address and hostname related types ***/ + + typedef ip-address { + type union { + type inet:ipv4-address; + type inet:ipv6-address; + } + description + "The ip-address type represents an IP address and is IP + version neutral. The format of the textual representations + implies the IP version."; + } + + typedef ipv4-address { + type string { + pattern + '(([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}]+)?'; + } + description + "The ipv4-address type represents an IPv4 address in + dotted-quad notation. The IPv4 address may include a zone + index, separated by a % sign. + + The zone index is used to disambiguate identical address + values. For link-local addresses, the zone index will + typically be the interface index number or the name of an + interface. If the zone index is not present, the default + zone of the device will be used. + + The canonical format for the zone index is the numerical + format"; + } + + typedef ipv6-address { + type string { + pattern '((:|[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}]+)?'; + pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|' + + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)' + + '(%.+)?'; + } + description + "The ipv6-address type represents an IPv6 address in full, + mixed, shortened, and shortened-mixed notation. The IPv6 + address may include a zone index, separated by a % sign. + + The zone index is used to disambiguate identical address + values. For link-local addresses, the zone index will + typically be the interface index number or the name of an + interface. If the zone index is not present, the default + zone of the device will be used. + + The canonical format of IPv6 addresses uses the compressed + format described in RFC 4291, Section 2.2, item 2 with the + following additional rules: the :: substitution must be + applied to the longest sequence of all-zero 16-bit chunks + in an IPv6 address. If there is a tie, the first sequence + of all-zero 16-bit chunks is replaced by ::. Single + all-zero 16-bit chunks are not compressed. The canonical + format uses lowercase characters and leading zeros are + not allowed. The canonical format for the zone index is + the numerical format as described in RFC 4007, Section + 11.2."; + reference + "RFC 4291: IP Version 6 Addressing Architecture + RFC 4007: IPv6 Scoped Address Architecture + RFC 5952: A Recommendation for IPv6 Address Text Representation"; + } + + typedef ip-prefix { + type union { + type inet:ipv4-prefix; + type inet:ipv6-prefix; + } + description + "The ip-prefix type represents an IP prefix and is IP + version neutral. The format of the textual representations + implies the IP version."; + } + + typedef ipv4-prefix { + type string { + pattern + '(([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]))'; + } + description + "The ipv4-prefix type represents an IPv4 address prefix. + The prefix length is given by the number following the + slash character and must be less than or equal to 32. + + A prefix length value of n corresponds to an IP address + mask that has n contiguous 1-bits from the most + significant bit (MSB) and all other bits set to 0. + + The canonical format of an IPv4 prefix has all bits of + the IPv4 address set to zero that are not part of the + IPv4 prefix."; + } + + typedef ipv6-prefix { + type string { + pattern '((:|[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])))'; + pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|' + + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)' + + '(/.+)'; + } + description + "The ipv6-prefix type represents an IPv6 address prefix. + The prefix length is given by the number following the + slash character and must be less than or equal 128. + + A prefix length value of n corresponds to an IP address + mask that has n contiguous 1-bits from the most + significant bit (MSB) and all other bits set to 0. + + The IPv6 address should have all bits that do not belong + to the prefix set to zero. + + The canonical format of an IPv6 prefix has all bits of + the IPv6 address set to zero that are not part of the + IPv6 prefix. Furthermore, IPv6 address is represented + in the compressed format described in RFC 4291, Section + 2.2, item 2 with the following additional rules: the :: + substitution must be applied to the longest sequence of + all-zero 16-bit chunks in an IPv6 address. If there is + a tie, the first sequence of all-zero 16-bit chunks is + replaced by ::. Single all-zero 16-bit chunks are not + compressed. The canonical format uses lowercase + characters and leading zeros are not allowed."; + reference + "RFC 4291: IP Version 6 Addressing Architecture"; + } + + /*** collection of domain name and URI types ***/ + + typedef domain-name { + type string { + pattern '((([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]\.?)' + + '|\.'; + length "1..253"; + } + description + "The domain-name type represents a DNS domain name. The + name SHOULD be fully qualified whenever possible. + + Internet domain names are only loosely specified. Section + 3.5 of RFC 1034 recommends a syntax (modified in Section + 2.1 of RFC 1123). The pattern above is intended to allow + for current practice in domain name use, and some possible + future expansion. It is designed to hold various types of + domain names, including names used for A or AAAA records + (host names) and other records, such as SRV records. Note + that Internet host names have a stricter syntax (described + in RFC 952) than the DNS recommendations in RFCs 1034 and + 1123, and that systems that want to store host names in + schema nodes using the domain-name type are recommended to + adhere to this stricter standard to ensure interoperability. + + The encoding of DNS names in the DNS protocol is limited + to 255 characters. Since the encoding consists of labels + prefixed by a length bytes and there is a trailing NULL + byte, only 253 characters can appear in the textual dotted + notation. + + The description clause of schema nodes using the domain-name + type MUST describe when and how these names are resolved to + IP addresses. Note that the resolution of a domain-name value + may require to query multiple DNS records (e.g., A for IPv4 + and AAAA for IPv6). The order of the resolution process and + which DNS record takes precedence can either be defined + explicitely or it may depend on the configuration of the + resolver. + + Domain-name values use the US-ASCII encoding. Their canonical + format uses lowercase US-ASCII characters. Internationalized + domain names MUST be encoded in punycode as described in RFC + 3492"; + reference + "RFC 952: DoD Internet Host Table Specification + RFC 1034: Domain Names - Concepts and Facilities + RFC 1123: Requirements for Internet Hosts -- Application + and Support + RFC 2782: A DNS RR for specifying the location of services + (DNS SRV) + RFC 3492: Punycode: A Bootstring encoding of Unicode for + Internationalized Domain Names in Applications + (IDNA) + RFC 5891: Internationalizing Domain Names in Applications + (IDNA): Protocol"; + } + + typedef host { + type union { + type inet:ip-address; + type inet:domain-name; + } + description + "The host type represents either an IP address or a DNS + domain name."; + } + + typedef uri { + type string; + description + "The uri type represents a Uniform Resource Identifier + (URI) as defined by STD 66. + + Objects using the uri type MUST be in US-ASCII encoding, + and MUST be normalized as described by RFC 3986 Sections + 6.2.1, 6.2.2.1, and 6.2.2.2. All unnecessary + percent-encoding is removed, and all case-insensitive + characters are set to lowercase except for hexadecimal + digits, which are normalized to uppercase as described in + Section 6.2.2.1. + + The purpose of this normalization is to help provide + unique URIs. Note that this normalization is not + sufficient to provide uniqueness. Two URIs that are + textually distinct after this normalization may still be + equivalent. + + Objects using the uri type may restrict the schemes that + they permit. For example, 'data:' and 'urn:' schemes + might not be appropriate. + + A zero-length URI is not a valid URI. This can be used to + express 'URI absent' where required. + + In the value set and its semantics, this type is equivalent + to the Uri SMIv2 textual convention defined in RFC 5017."; + reference + "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax + RFC 3305: Report from the Joint W3C/IETF URI Planning Interest + Group: Uniform Resource Identifiers (URIs), URLs, + and Uniform Resource Names (URNs): Clarifications + and Recommendations + RFC 5017: MIB Textual Conventions for Uniform Resource + Identifiers (URIs)"; + } + + } \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-interfaces@2012-11-15.yang b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-interfaces@2012-11-15.yang new file mode 100644 index 0000000000..481a5d2ed1 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-interfaces@2012-11-15.yang @@ -0,0 +1,469 @@ +module ietf-interfaces { + + namespace "urn:ietf:params:xml:ns:yang:ietf-interfaces"; + prefix if; + + import ietf-yang-types { + prefix yang; + revision-date 2010-09-24; + } + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: David Kessens + + + WG Chair: Juergen Schoenwaelder + + + Editor: Martin Bjorklund + "; + + description + "This module contains a collection of YANG definitions for + managing network interfaces. + + Copyright (c) 2012 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, is permitted pursuant to, and subject + to the license terms contained in, the Simplified BSD License + set forth in Section 4.c of the IETF Trust's Legal Provisions + Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC XXXX; see + the RFC itself for full legal notices."; + + // RFC Ed.: replace XXXX with actual RFC number and remove this + // note. + + // RFC Ed.: update the date below with the date of RFC publication + // and remove this note. + revision 2012-11-15 { + description + "Initial revision."; + reference + "RFC XXXX: A YANG Data Model for Interface Management"; + } + + /* Typedefs */ + + typedef interface-ref { + type leafref { + path "/if:interfaces/if:interface/if:name"; + } + description + "This type is used by data models that need to reference + interfaces."; + } + + /* Features */ + + feature arbitrary-names { + description + "This feature indicates that the server allows interfaces to + be named arbitrarily."; + } + + feature if-mib { + description + "This feature indicates that the server implements IF-MIB."; + reference + "RFC 2863: The Interfaces Group MIB"; + } + + /* Data nodes */ + + container interfaces { + description + "Interface parameters."; + + list interface { + key "name"; + unique "type location"; + + description + "The list of interfaces on the device."; + + leaf name { + type string; + description + "The name of the interface. + + A device MAY restrict the allowed values for this leaf, + possibly depending on the type and location. + + If the device allows arbitrarily named interfaces, the + feature 'arbitrary-names' is advertised. + + This leaf MAY be mapped to ifName by an implementation. + Such an implementation MAY restrict the allowed values for + this leaf so that it matches the restrictions of ifName. + If a NETCONF server that implements this restriction is + sent a value that doesn't match the restriction, it MUST + reply with an rpc-error with the error-tag + 'invalid-value'."; + reference + "RFC 2863: The Interfaces Group MIB - ifName"; + } + + leaf description { + type string; + description + "A textual description of the interface. + + This leaf MAY be mapped to ifAlias by an implementation. + Such an implementation MAY restrict the allowed values for + this leaf so that it matches the restrictions of ifAlias. + If a NETCONF server that implements this restriction is + sent a value that doesn't match the restriction, it MUST + reply with an rpc-error with the error-tag + 'invalid-value'."; + reference + "RFC 2863: The Interfaces Group MIB - ifAlias"; + } + + leaf location { + type string; + description + "The device-specific location of the interface of a + particular type. The format of the location string + depends on the interface type and the device. + + If the interface's type represents a physical interface, + this leaf MUST be set. + + When an interface entry is created, a server MAY + initialize the location leaf with a valid value, e.g., if + it is possible to derive the location from the name of + the interface."; + } + + leaf enabled { + type boolean; + default "true"; + description + "The desired state of the interface. + + This leaf contains the configured, desired state of the + interface. Systems that implement the IF-MIB use the + value of this leaf to set IF-MIB.ifAdminStatus to 'up' or + 'down' after an ifEntry has been initialized, as described + in RFC 2863."; + reference + "RFC 2863: The Interfaces Group MIB - ifAdminStatus"; + } + + leaf last-change { + type yang:date-and-time; + config false; + description + "The time the interface entered its current operational + state. If the current state was entered prior to the + last re-initialization of the local network management + subsystem, then this node is not present."; + reference + "RFC 2863: The Interfaces Group MIB - ifLastChange"; + } + + leaf if-index { + if-feature if-mib; + type int32 { + range "1..2147483647"; + } + config false; + description + "The ifIndex value for the ifEntry represented by this + interface. + + Media-specific modules must specify how the type is + mapped to entries in the ifTable."; + reference + "RFC 2863: The Interfaces Group MIB - ifIndex"; + } + + leaf phys-address { + type yang:phys-address; + config false; + description + "The interface's address at its protocol sub-layer. For + example, for an 802.x interface, this object normally + contains a MAC address. The interface's media-specific + modules must define the bit and byte ordering and the + format of the value of this object. For interfaces that do + not have such an address (e.g., a serial line), this node + is not present."; + reference + "RFC 2863: The Interfaces Group MIB - ifPhysAddress"; + } + + leaf-list higher-layer-if { + type interface-ref; + config false; + description + "A list of references to interfaces layered on top of this + interface."; + reference + "RFC 2863: The Interfaces Group MIB - ifStackTable"; + } + + leaf-list lower-layer-if { + type interface-ref; + config false; + description + "A list of references to interfaces layered underneath this + interface."; + reference + "RFC 2863: The Interfaces Group MIB - ifStackTable"; + } + + leaf speed { + type yang:gauge64; + units "bits / second"; + config false; + description + "An estimate of the interface's current bandwidth in bits + per second. For interfaces which do not vary in + bandwidth or for those where no accurate estimation can + be made, this node should contain the nominal bandwidth. + For interfaces that has no concept of bandwidth, this + node is not present."; + reference + "RFC 2863: The Interfaces Group MIB - + ifSpeed, ifHighSpeed"; + } + + container statistics { + config false; + description + "A collection of interface-related statistics objects."; + + leaf discontinuity-time { + type yang:date-and-time; + description + "The time on the most recent occasion at which any one or + more of this interface's counters suffered a + discontinuity. If no such discontinuities have occurred + since the last re-initialization of the local management + subsystem, then this node contains the time the local + management subsystem re-initialized itself."; + } + + leaf in-octets { + type yang:counter64; + description + "The total number of octets received on the interface, + including framing characters. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifHCInOctets"; + } + leaf in-unicast-pkts { + type yang:counter64; + description + "The number of packets, delivered by this sub-layer to a + higher (sub-)layer, which were not addressed to a + multicast or broadcast address at this sub-layer. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifHCInUcastPkts"; + } + leaf in-broadcast-pkts { + type yang:counter64; + description + "The number of packets, delivered by this sub-layer to a + higher (sub-)layer, which were addressed to a broadcast + address at this sub-layer. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - + ifHCInBroadcastPkts"; + } + leaf in-multicast-pkts { + type yang:counter64; + description + "The number of packets, delivered by this sub-layer to a + higher (sub-)layer, which were addressed to a multicast + address at this sub-layer. For a MAC layer protocol, + this includes both Group and Functional addresses. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - + ifHCInMulticastPkts"; + } + leaf in-discards { + type yang:counter32; + description + "The number of inbound packets which were chosen to be + discarded even though no errors had been detected to + prevent their being deliverable to a higher-layer + protocol. One possible reason for discarding such a + packet could be to free up buffer space. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifInDiscards"; + } + leaf in-errors { + type yang:counter32; + description + "For packet-oriented interfaces, the number of inbound + packets that contained errors preventing them from being + deliverable to a higher-layer protocol. For character- + oriented or fixed-length interfaces, the number of + inbound transmission units that contained errors + preventing them from being deliverable to a higher-layer + protocol. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifInErrors"; + } + leaf in-unknown-protos { + type yang:counter32; + description + "For packet-oriented interfaces, the number of packets + received via the interface which were discarded because + of an unknown or unsupported protocol. For + character-oriented or fixed-length interfaces that + support protocol multiplexing the number of transmission + units received via the interface which were discarded + because of an unknown or unsupported protocol. For any + interface that does not support protocol multiplexing, + this counter is not present. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifInUnknownProtos"; + } + + leaf out-octets { + type yang:counter64; + description + "The total number of octets transmitted out of the + interface, including framing characters. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifHCOutOctets"; + } + leaf out-unicast-pkts { + type yang:counter64; + description + "The total number of packets that higher-level protocols + requested be transmitted, and which were not addressed + to a multicast or broadcast address at this sub-layer, + including those that were discarded or not sent. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifHCOutUcastPkts"; + } + leaf out-broadcast-pkts { + type yang:counter64; + description + "The total number of packets that higher-level protocols + requested be transmitted, and which were addressed to a + broadcast address at this sub-layer, including those + that were discarded or not sent. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - + ifHCOutBroadcastPkts"; + } + leaf out-multicast-pkts { + type yang:counter64; + description + "The total number of packets that higher-level protocols + requested be transmitted, and which were addressed to a + multicast address at this sub-layer, including those + that were discarded or not sent. For a MAC layer + protocol, this includes both Group and Functional + addresses. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - + ifHCOutMulticastPkts"; + } + leaf out-discards { + type yang:counter32; + description + "The number of outbound packets which were chosen to be + discarded even though no errors had been detected to + prevent their being transmitted. One possible reason + for discarding such a packet could be to free up buffer + space. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifOutDiscards"; + } + leaf out-errors { + type yang:counter32; + description + "For packet-oriented interfaces, the number of outbound + packets that could not be transmitted because of errors. + For character-oriented or fixed-length interfaces, the + number of outbound transmission units that could not be + transmitted because of errors. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifOutErrors"; + } + } + } + } +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-yang-types@2010-09-24.yang b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-yang-types@2010-09-24.yang new file mode 100644 index 0000000000..e9d88ab781 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/resources/yang/ietf-yang-types@2010-09-24.yang @@ -0,0 +1,396 @@ + module ietf-yang-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + prefix "yang"; + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: David Partain + + + WG Chair: David Kessens + + + Editor: Juergen Schoenwaelder + "; + + description + "This module contains a collection of generally useful derived + YANG data types. + + Copyright (c) 2010 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, is permitted pursuant to, and subject to the license + terms contained in, the Simplified BSD License set forth in Section + 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC 6021; see + the RFC itself for full legal notices."; + + revision 2010-09-24 { + description + "Initial revision."; + reference + "RFC 6021: Common YANG Data Types"; + } + + /*** collection of counter and gauge types ***/ + + typedef counter32 { + type uint32; + description + "The counter32 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter32 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter32 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter32. + + In the value set and its semantics, this type is equivalent + to the Counter32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef zero-based-counter32 { + type yang:counter32; + default "0"; + description + "The zero-based-counter32 type represents a counter32 + that has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter32 textual convention of the SMIv2."; + reference + "RFC 4502: Remote Network Monitoring Management Information + Base Version 2"; + } + + typedef counter64 { + type uint64; + description + "The counter64 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter64 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter64 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter64. + + In the value set and its semantics, this type is equivalent + to the Counter64 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef zero-based-counter64 { + type yang:counter64; + default "0"; + description + "The zero-based-counter64 type represents a counter64 that + has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter64 textual convention of the SMIv2."; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + typedef gauge32 { + type uint32; + description + "The gauge32 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^32-1 (4294967295 decimal), and + the minimum value cannot be smaller than 0. The value of + a gauge32 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge32 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the Gauge32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef gauge64 { + type uint64; + description + "The gauge64 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^64-1 (18446744073709551615), and + the minimum value cannot be smaller than 0. The value of + a gauge64 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge64 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the CounterBasedGauge64 SMIv2 textual convention defined + in RFC 2856"; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + /*** collection of identifier related types ***/ + + typedef object-identifier { + type string { + pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))' + + '(\.(0|([1-9]\d*)))*'; + } + description + "The object-identifier type represents administratively + assigned names in a registration-hierarchical-name tree. + + Values of this type are denoted as a sequence of numerical + non-negative sub-identifier values. Each sub-identifier + value MUST NOT exceed 2^32-1 (4294967295). Sub-identifiers + are separated by single dots and without any intermediate + whitespace. + + The ASN.1 standard restricts the value space of the first + sub-identifier to 0, 1, or 2. Furthermore, the value space + of the second sub-identifier is restricted to the range + 0 to 39 if the first sub-identifier is 0 or 1. Finally, + the ASN.1 standard requires that an object identifier + has always at least two sub-identifier. The pattern + captures these restrictions. + + Although the number of sub-identifiers is not limited, + module designers should realize that there may be + implementations that stick with the SMIv2 limit of 128 + sub-identifiers. + + This type is a superset of the SMIv2 OBJECT IDENTIFIER type + since it is not restricted to 128 sub-identifiers. Hence, + this type SHOULD NOT be used to represent the SMIv2 OBJECT + IDENTIFIER type, the object-identifier-128 type SHOULD be + used instead."; + reference + "ISO9834-1: Information technology -- Open Systems + Interconnection -- Procedures for the operation of OSI + Registration Authorities: General procedures and top + arcs of the ASN.1 Object Identifier tree"; + } + + + + + typedef object-identifier-128 { + type object-identifier { + pattern '\d*(\.\d*){1,127}'; + } + description + "This type represents object-identifiers restricted to 128 + sub-identifiers. + + In the value set and its semantics, this type is equivalent + to the OBJECT IDENTIFIER type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + /*** collection of date and time related types ***/ + + typedef date-and-time { + type string { + pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?' + + '(Z|[\+\-]\d{2}:\d{2})'; + } + description + "The date-and-time type is a profile of the ISO 8601 + standard for representation of dates and times using the + Gregorian calendar. The profile is defined by the + date-time production in Section 5.6 of RFC 3339. + + The date-and-time type is compatible with the dateTime XML + schema type with the following notable exceptions: + + (a) The date-and-time type does not allow negative years. + + (b) The date-and-time time-offset -00:00 indicates an unknown + time zone (see RFC 3339) while -00:00 and +00:00 and Z all + represent the same time zone in dateTime. + + (c) The canonical format (see below) of data-and-time values + differs from the canonical format used by the dateTime XML + schema type, which requires all times to be in UTC using the + time-offset 'Z'. + + This type is not equivalent to the DateAndTime textual + convention of the SMIv2 since RFC 3339 uses a different + separator between full-date and full-time and provides + higher resolution of time-secfrac. + + The canonical format for date-and-time values with a known time + zone uses a numeric time zone offset that is calculated using + the device's configured known offset to UTC time. A change of + the device's offset to UTC time will cause date-and-time values + to change accordingly. Such changes might happen periodically + in case a server follows automatically daylight saving time + (DST) time zone offset changes. The canonical format for + date-and-time values with an unknown time zone (usually referring + to the notion of local time) uses the time-offset -00:00."; + reference + "RFC 3339: Date and Time on the Internet: Timestamps + RFC 2579: Textual Conventions for SMIv2 + XSD-TYPES: XML Schema Part 2: Datatypes Second Edition"; + } + + typedef timeticks { + type uint32; + description + "The timeticks type represents a non-negative integer that + represents the time, modulo 2^32 (4294967296 decimal), in + hundredths of a second between two epochs. When a schema + node is defined that uses this type, the description of + the schema node identifies both of the reference epochs. + + In the value set and its semantics, this type is equivalent + to the TimeTicks type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef timestamp { + type yang:timeticks; + description + "The timestamp type represents the value of an associated + timeticks schema node at which a specific occurrence happened. + The specific occurrence must be defined in the description + of any schema node defined using this type. When the specific + occurrence occurred prior to the last time the associated + timeticks attribute was zero, then the timestamp value is + zero. Note that this requires all timestamp values to be + reset to zero when the value of the associated timeticks + attribute reaches 497+ days and wraps around to zero. + + The associated timeticks schema node must be specified + in the description of any schema node using this type. + + In the value set and its semantics, this type is equivalent + to the TimeStamp textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of generic address types ***/ + + typedef phys-address { + type string { + pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?'; + } + description + "Represents media- or physical-level addresses represented + as a sequence octets, each octet represented by two hexadecimal + numbers. Octets are separated by colons. The canonical + representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the PhysAddress textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + typedef mac-address { + type string { + pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}'; + } + description + "The mac-address type represents an IEEE 802 MAC address. + The canonical representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the MacAddress textual convention of the SMIv2."; + reference + "IEEE 802: IEEE Standard for Local and Metropolitan Area + Networks: Overview and Architecture + RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of XML specific types ***/ + + typedef xpath1.0 { + type string; + description + "This type represents an XPATH 1.0 expression. + + When a schema node is defined that uses this type, the + description of the schema node MUST specify the XPath + context in which the XPath expression is evaluated."; + reference + "XPATH: XML Path Language (XPath) Version 1.0"; + } + + } \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractChildNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractChildNodeBuilder.java index 71e24bcf82..ff845944da 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractChildNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractChildNodeBuilder.java @@ -27,11 +27,19 @@ public abstract class AbstractChildNodeBuilder implements ChildNodeBuilder { return qname; } + public Set getChildNodes() { + return childNodes; + } + @Override public void addChildNode(DataSchemaNodeBuilder childNode) { childNodes.add(childNode); } + public Set getGroupings() { + return groupings; + } + @Override public void addGrouping(GroupingBuilder grouping) { groupings.add(grouping); diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractTypeAwareBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractTypeAwareBuilder.java index 35446ced15..02b4d7ff6c 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractTypeAwareBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractTypeAwareBuilder.java @@ -1,7 +1,17 @@ +/* + * 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.controller.yang.model.parser.builder.api; import org.opendaylight.controller.yang.model.api.TypeDefinition; +/** + * Basic implementation for TypeAwareBuilder builders. + */ public class AbstractTypeAwareBuilder implements TypeAwareBuilder { protected TypeDefinition type; diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationSchemaBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationSchemaBuilder.java index 71cf7a19e9..ef54c0bc6b 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationSchemaBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationSchemaBuilder.java @@ -16,12 +16,13 @@ import org.opendaylight.controller.yang.model.api.Status; /** * Interface for builders of 'augment' statement. */ -public interface AugmentationSchemaBuilder extends ChildNodeBuilder, TypeDefinitionAwareBuilder { +public interface AugmentationSchemaBuilder extends ChildNodeBuilder { void setDescription(String description); void setReference(String reference); void setStatus(Status status); + String getTargetPathAsString(); SchemaPath getTargetPath(); Set getChildNodes(); diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationTargetBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationTargetBuilder.java index 7b4a191865..0b435c15e1 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationTargetBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationTargetBuilder.java @@ -7,17 +7,17 @@ */ package org.opendaylight.controller.yang.model.parser.builder.api; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; - /** * Interface for builders of those nodes, which can be augmentation targets. */ public interface AugmentationTargetBuilder { - /** - * Add augment, which points to this node. - * @param augment augment which points to this node - */ - void addAugmentation(AugmentationSchema augment); + /** + * Add augment, which points to this node. + * + * @param augment + * augment which points to this node + */ + void addAugmentation(AugmentationSchemaBuilder augment); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/ChildNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/ChildNodeBuilder.java index 7dc716a775..dc29c8ffae 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/ChildNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/ChildNodeBuilder.java @@ -10,14 +10,19 @@ package org.opendaylight.controller.yang.model.parser.builder.api; import org.opendaylight.controller.yang.common.QName; /** - * Interface for all yang data-node containers [augment, case, container, grouping, list, module, notification]. + * Interface for all yang data-node containers [augment, case, container, + * grouping, list, module, notification]. */ public interface ChildNodeBuilder extends Builder { - QName getQName(); - void addChildNode(DataSchemaNodeBuilder childNode); - void addGrouping(GroupingBuilder groupingBuilder); - void addUsesNode(UsesNodeBuilder usesBuilder); - void addTypedef(TypeDefinitionBuilder typedefBuilder); + QName getQName(); + + void addChildNode(DataSchemaNodeBuilder childNode); + + void addGrouping(GroupingBuilder groupingBuilder); + + void addUsesNode(UsesNodeBuilder usesBuilder); + + void addTypedef(TypeDefinitionBuilder typedefBuilder); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/DataSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/DataSchemaNodeBuilder.java index eb17e4ee5a..0974a448f9 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/DataSchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/DataSchemaNodeBuilder.java @@ -22,6 +22,6 @@ public interface DataSchemaNodeBuilder extends SchemaNodeBuilder { void setConfiguration(boolean configuration); - ConstraintsBuilder getConstraintsBuilder(); + ConstraintsBuilder getConstraints(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/GroupingBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/GroupingBuilder.java index 3db0a5ce32..94355c8784 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/GroupingBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/GroupingBuilder.java @@ -12,8 +12,11 @@ import org.opendaylight.controller.yang.model.api.GroupingDefinition; /** * Interface for builders of 'grouping' statement. */ -public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder, TypeDefinitionAwareBuilder { +public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder, + TypeDefinitionAwareBuilder { - GroupingDefinition build(); + DataSchemaNodeBuilder getChildNode(String name); + + GroupingDefinition build(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/SchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/SchemaNodeBuilder.java index b96347ef18..533e79df26 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/SchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/SchemaNodeBuilder.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.yang.model.parser.builder.api; import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaNode; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder; @@ -19,6 +20,8 @@ public interface SchemaNodeBuilder extends Builder { QName getQName(); + SchemaPath getPath(); + void setPath(SchemaPath schemaPath); void setDescription(String description); @@ -27,6 +30,8 @@ public interface SchemaNodeBuilder extends Builder { void setStatus(Status status); - void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder); + void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode); + + SchemaNode build(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java index 1f808eb722..99add7c334 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java @@ -7,15 +7,23 @@ */ package org.opendaylight.controller.yang.model.parser.builder.api; +import java.util.List; + +import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.util.RefineHolder; /** * Interface for builders of 'uses' statement. */ public interface UsesNodeBuilder extends Builder { + SchemaPath getGroupingPath(); void addAugment(AugmentationSchemaBuilder builder); void setAugmenting(boolean augmenting); + List getRefines(); + void setRefines(List refines); + void addRefineNode(SchemaNodeBuilder refineNode); UsesNode build(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AnyXmlBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AnyXmlBuilder.java new file mode 100644 index 0000000000..212e2f8d4f --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AnyXmlBuilder.java @@ -0,0 +1,271 @@ +/* + * 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.controller.yang.model.parser.builder.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; + +public class AnyXmlBuilder implements DataSchemaNodeBuilder { + private final QName qname; + private SchemaPath path; + private final AnyXmlSchemaNodeImpl instance; + private final ConstraintsBuilder constraints = new ConstraintsBuilder(); + private final List addedUnknownNodes = new ArrayList(); + + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean configuration; + + public AnyXmlBuilder(final QName qname) { + this.qname = qname; + instance = new AnyXmlSchemaNodeImpl(qname); + } + + @Override + public AnyXmlSchemaNode build() { + instance.setPath(path); + instance.setConstraints(constraints.build()); + instance.setDescription(description); + instance.setReference(reference); + instance.setStatus(status); + + // UNKNOWN NODES + final List unknownNodes = new ArrayList(); + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { + unknownNodes.add(b.build()); + } + instance.setUnknownSchemaNodes(unknownNodes); + + instance.setConfiguration(configuration); + return instance; + } + + @Override + public QName getQName() { + return qname; + } + + public SchemaPath getPath() { + return path; + } + + @Override + public void setPath(final SchemaPath path) { + this.path = path; + } + + @Override + public ConstraintsBuilder getConstraints() { + return constraints; + } + + @Override + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); + } + + public List getUnknownNodes() { + return addedUnknownNodes; + } + + public String getDescription() { + return description; + } + + @Override + public void setDescription(final String description) { + this.description = description; + } + + public String getReference() { + return reference; + } + + @Override + public void setReference(final String reference) { + this.reference = reference; + } + + public Status getStatus() { + return status; + } + + @Override + public void setStatus(final Status status) { + if (status != null) { + this.status = status; + } + } + + @Override + public void setAugmenting(final boolean augmenting) { + throw new UnsupportedOperationException( + "An anyxml node cannot be augmented."); + } + + public boolean isConfiguration() { + return configuration; + } + + @Override + public void setConfiguration(final boolean configuration) { + instance.setConfiguration(configuration); + } + + private static class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean configuration; + private ConstraintDefinition constraintsDef; + private List unknownNodes = Collections.emptyList(); + + private AnyXmlSchemaNodeImpl(final QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(final SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + if (status != null) { + this.status = status; + } + } + + @Override + public boolean isAugmenting() { + return false; + } + + @Override + public boolean isConfiguration() { + return configuration; + } + + private void setConfiguration(boolean configuration) { + this.configuration = configuration; + } + + @Override + public ConstraintDefinition getConstraints() { + return constraintsDef; + } + + private void setConstraints(ConstraintDefinition constraintsDef) { + this.constraintsDef = constraintsDef; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownNodes; + } + + private void setUnknownSchemaNodes(List unknownNodes) { + if (unknownNodes != null) { + this.unknownNodes = unknownNodes; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AnyXmlSchemaNodeImpl other = (AnyXmlSchemaNodeImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + AnyXmlSchemaNodeImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append(", path=" + path); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AugmentationSchemaBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AugmentationSchemaBuilderImpl.java index 1027cb1fc3..12f0a15028 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AugmentationSchemaBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AugmentationSchemaBuilderImpl.java @@ -31,17 +31,20 @@ import org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil; public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder { private final AugmentationSchemaImpl instance; + private final String augmentTargetStr; private final SchemaPath augmentTarget; - final Set childNodes = new HashSet(); - final Set groupings = new HashSet(); + private final Set childNodes = new HashSet(); + private final Set groupings = new HashSet(); private final Set usesNodes = new HashSet(); - AugmentationSchemaBuilderImpl(String augmentPath) { - SchemaPath targetPath = YangModelBuilderUtil.parseAugmentPath(augmentPath); + AugmentationSchemaBuilderImpl(final String augmentTargetStr) { + this.augmentTargetStr = augmentTargetStr; + final SchemaPath targetPath = YangModelBuilderUtil.parseAugmentPath(augmentTargetStr); augmentTarget = targetPath; instance = new AugmentationSchemaImpl(targetPath); } + @Override public void addChildNode(DataSchemaNodeBuilder childNode) { childNodes.add(childNode); @@ -72,23 +75,22 @@ public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder @Override public AugmentationSchema build() { - // CHILD NODES - Map childs = new HashMap(); + final Map childs = new HashMap(); for (DataSchemaNodeBuilder node : childNodes) { childs.put(node.getQName(), node.build()); } instance.setChildNodes(childs); // GROUPINGS - Set groupingDefinitions = new HashSet(); + final Set groupingDefinitions = new HashSet(); for (GroupingBuilder builder : groupings) { groupingDefinitions.add(builder.build()); } instance.setGroupings(groupingDefinitions); // USES - Set usesNodeDefinitions = new HashSet(); + final Set usesNodeDefinitions = new HashSet(); for (UsesNodeBuilder builder : usesNodes) { usesNodeDefinitions.add(builder.build()); } @@ -123,12 +125,16 @@ public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder return augmentTarget; } - private static class AugmentationSchemaImpl implements AugmentationSchema { + @Override + public String getTargetPathAsString() { + return augmentTargetStr; + } + private static class AugmentationSchemaImpl implements AugmentationSchema { private final SchemaPath targetPath; - private Map childNodes; - private Set groupings; - private Set uses; + private Map childNodes = Collections.emptyMap(); + private Set groupings = Collections.emptySet(); + private Set uses = Collections.emptySet(); private String description; private String reference; @@ -149,7 +155,9 @@ public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder } private void setChildNodes(Map childNodes) { - this.childNodes = childNodes; + if(childNodes != null) { + this.childNodes = childNodes; + } } @Override @@ -158,7 +166,9 @@ public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder } private void setGroupings(Set groupings) { - this.groupings = groupings; + if(groupings != null) { + this.groupings = groupings; + } } @Override @@ -167,7 +177,9 @@ public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder } private void setUses(Set uses) { - this.uses = uses; + if(uses != null) { + this.uses = uses; + } } /** @@ -234,12 +246,6 @@ public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder result = prime * result + ((groupings == null) ? 0 : groupings.hashCode()); result = prime * result + ((uses == null) ? 0 : uses.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result - + ((status == null) ? 0 : status.hashCode()); return result; } @@ -283,27 +289,6 @@ public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder } else if (!uses.equals(other.uses)) { return false; } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - if (status == null) { - if (other.status != null) { - return false; - } - } else if (!status.equals(other.status)) { - return false; - } return true; } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ChoiceBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ChoiceBuilder.java new file mode 100644 index 0000000000..b5ceaedffa --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ChoiceBuilder.java @@ -0,0 +1,414 @@ +/* + * 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.controller.yang.model.parser.builder.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.ChoiceCaseNode; +import org.opendaylight.controller.yang.model.api.ChoiceNode; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class ChoiceBuilder implements DataSchemaNodeBuilder, ChildNodeBuilder, + AugmentationTargetBuilder { + private final QName qname; + private SchemaPath schemaPath; + private final ConstraintsBuilder constraints; + private final ChoiceNodeImpl instance; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private boolean configuration; + private String defaultCase; + + private final Set cases = new HashSet(); + private final Set addedTypedefs = new HashSet(); + private final Set addedUsesNodes = new HashSet(); + private final Set addedAugmentations = new HashSet(); + private final List addedUnknownNodes = new ArrayList(); + + public ChoiceBuilder(QName qname) { + this.qname = qname; + instance = new ChoiceNodeImpl(qname); + constraints = new ConstraintsBuilder(); + } + + @Override + public ChoiceNode build() { + instance.setPath(schemaPath); + instance.setDescription(description); + instance.setReference(reference); + instance.setStatus(status); + instance.setAugmenting(augmenting); + instance.setConfiguration(configuration); + instance.setDefaultCase(defaultCase); + + // CASES + final Set choiceCases = new HashSet(); + for (ChoiceCaseBuilder caseBuilder : cases) { + choiceCases.add(caseBuilder.build()); + } + instance.setCases(choiceCases); + + // AUGMENTATIONS + final Set augmentations = new HashSet(); + for (AugmentationSchemaBuilder builder : addedAugmentations) { + augmentations.add(builder.build()); + } + instance.setAvailableAugmentations(augmentations); + + // UNKNOWN NODES + final List unknownNodes = new ArrayList(); + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { + unknownNodes.add(b.build()); + } + instance.setUnknownSchemaNodes(unknownNodes); + + instance.setConstraints(constraints.build()); + + return instance; + } + + public Set getCases() { + return cases; + } + + @Override + public void addChildNode(DataSchemaNodeBuilder childNode) { + if (!(childNode instanceof ChoiceCaseBuilder)) { + ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(childNode.getQName()); + caseBuilder.addChildNode(childNode); + cases.add(caseBuilder); + } else { + cases.add((ChoiceCaseBuilder) childNode); + } + } + + @Override + public QName getQName() { + return qname; + } + + /** + * Choice can not contains grouping statements, so this method always + * returns an empty set. + * + * @return + */ + public Set getGroupings() { + return Collections.emptySet(); + } + + @Override + public void addGrouping(GroupingBuilder groupingBuilder) { + throw new IllegalStateException( + "Can not add grouping to 'choice' node."); + } + + public Set getTypedefs() { + return addedTypedefs; + } + + @Override + public void addTypedef(final TypeDefinitionBuilder type) { + addedTypedefs.add(type); + } + + public SchemaPath getPath() { + return schemaPath; + } + + @Override + public void setPath(final SchemaPath schemaPath) { + this.schemaPath = schemaPath; + } + + public String getDescription() { + return description; + } + + @Override + public void setDescription(final String description) { + this.description = description; + } + + public String getReference() { + return reference; + } + + @Override + public void setReference(String reference) { + this.reference = reference; + } + + public Status getStatus() { + return status; + } + + @Override + public void setStatus(Status status) { + if (status != null) { + this.status = status; + } + } + + public boolean isAugmenting() { + return augmenting; + } + + @Override + public void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + public boolean isConfiguration() { + return configuration; + } + + @Override + public void setConfiguration(boolean configuration) { + this.configuration = configuration; + } + + @Override + public ConstraintsBuilder getConstraints() { + return constraints; + } + + public Set getUsesNodes() { + return addedUsesNodes; + } + + @Override + public void addUsesNode(UsesNodeBuilder usesNodeBuilder) { + addedUsesNodes.add(usesNodeBuilder); + } + + public List getUnknownNodes() { + return addedUnknownNodes; + } + + public Set getAugmentations() { + return addedAugmentations; + } + + @Override + public void addAugmentation(AugmentationSchemaBuilder augment) { + addedAugmentations.add(augment); + } + + @Override + public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); + } + + public String getDefaultCase() { + return defaultCase; + } + + public void setDefaultCase(String defaultCase) { + this.defaultCase = defaultCase; + } + + private static class ChoiceNodeImpl implements ChoiceNode { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private boolean configuration; + private ConstraintDefinition constraints; + private Set cases = Collections.emptySet(); + private Set augmentations = Collections.emptySet(); + private List unknownNodes = Collections.emptyList(); + private String defaultCase; + + private ChoiceNodeImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + if (status != null) { + this.status = status; + } + } + + @Override + public boolean isAugmenting() { + return augmenting; + } + + private void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + @Override + public boolean isConfiguration() { + return configuration; + } + + private void setConfiguration(boolean configuration) { + this.configuration = configuration; + } + + @Override + public ConstraintDefinition getConstraints() { + return constraints; + } + + private void setConstraints(ConstraintDefinition constraints) { + this.constraints = constraints; + } + + @Override + public Set getAvailableAugmentations() { + return augmentations; + } + + private void setAvailableAugmentations( + Set availableAugmentations) { + if (availableAugmentations != null) { + this.augmentations = availableAugmentations; + } + } + + @Override + public List getUnknownSchemaNodes() { + return unknownNodes; + } + + private void setUnknownSchemaNodes( + List unknownSchemaNodes) { + if (unknownSchemaNodes != null) { + this.unknownNodes = unknownSchemaNodes; + } + } + + @Override + public Set getCases() { + return cases; + } + + private void setCases(Set cases) { + if (cases != null) { + this.cases = cases; + } + } + + public String getDefaultCase() { + return defaultCase; + } + + private void setDefaultCase(String defaultCase) { + this.defaultCase = defaultCase; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ChoiceNodeImpl other = (ChoiceNodeImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + ChoiceNodeImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ChoiceCaseBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ChoiceCaseBuilder.java new file mode 100644 index 0000000000..73d7e3dc0c --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ChoiceCaseBuilder.java @@ -0,0 +1,371 @@ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.ChoiceCaseNode; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class ChoiceCaseBuilder extends AbstractChildNodeBuilder implements DataSchemaNodeBuilder { + + private final ChoiceCaseNodeImpl instance; + private final ConstraintsBuilder constraints; + private SchemaPath schemaPath; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private final Set addedUsesNodes = new HashSet(); + private final Set augmentations = new HashSet(); + private final List addedUnknownNodes = new ArrayList(); + + ChoiceCaseBuilder(QName qname) { + super(qname); + instance = new ChoiceCaseNodeImpl(qname); + constraints = new ConstraintsBuilder(); + } + + @Override + public ChoiceCaseNode build() { + instance.setConstraints(constraints.build()); + instance.setPath(schemaPath); + instance.setDescription(description); + instance.setReference(reference); + instance.setStatus(status); + instance.setAugmenting(augmenting); + instance.setAvailableAugmentations(augmentations); + + // CHILD NODES + final Map childs = new HashMap(); + for (DataSchemaNodeBuilder node : childNodes) { + childs.put(node.getQName(), node.build()); + } + instance.setChildNodes(childs); + + // USES + final Set uses = new HashSet(); + for (UsesNodeBuilder builder : addedUsesNodes) { + uses.add(builder.build()); + } + instance.setUses(uses); + + // UNKNOWN NODES + final List unknownNodes = new ArrayList(); + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { + unknownNodes.add(b.build()); + } + instance.setUnknownSchemaNodes(unknownNodes); + + return instance; + } + + public SchemaPath getPath() { + return schemaPath; + } + + @Override + public void setPath(final SchemaPath schemaPath) { + this.schemaPath = schemaPath; + } + + public String getDescription() { + return description; + } + + @Override + public void setDescription(final String description) { + this.description = description; + } + + public String getReference() { + return reference; + } + + @Override + public void setReference(String reference) { + this.reference = reference; + } + + public Status getStatus() { + return status; + } + + @Override + public void setStatus(Status status) { + if(status != null) { + this.status = status; + } + } + + public boolean isAugmenting() { + return augmenting; + } + + @Override + public void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + public List getUnknownNodes() { + return addedUnknownNodes; + } + + @Override + public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); + } + + public Set getUsesNodes() { + return addedUsesNodes; + } + + @Override + public void addUsesNode(UsesNodeBuilder usesNodeBuilder) { + addedUsesNodes.add(usesNodeBuilder); + } + + @Override + public void addTypedef(TypeDefinitionBuilder typedefBuilder) { + throw new UnsupportedOperationException("Can not add type definition to choice case."); + } + + @Override + public void setConfiguration(boolean configuration) { + throw new UnsupportedOperationException("Can not add config definition to choice case."); + } + + @Override + public ConstraintsBuilder getConstraints() { + return constraints; + } + + public Set getAugmentations() { + return augmentations; + } + + + private static class ChoiceCaseNodeImpl implements ChoiceCaseNode { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private ConstraintDefinition constraints; + private Map childNodes = Collections.emptyMap(); + private Set augmentations = Collections.emptySet(); + private Set uses = Collections.emptySet(); + private List unknownNodes = Collections.emptyList(); + + private ChoiceCaseNodeImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + if(status != null) { + this.status = status; + } + } + + @Override + public boolean isConfiguration() { + return false; + } + + @Override + public ConstraintDefinition getConstraints() { + return constraints; + } + + private void setConstraints(ConstraintDefinition constraints) { + this.constraints = constraints; + } + + @Override + public boolean isAugmenting() { + return augmenting; + } + + private void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownNodes; + } + + private void setUnknownSchemaNodes(List unknownNodes) { + if(unknownNodes != null) { + this.unknownNodes = unknownNodes; + } + } + + @Override + public Set> getTypeDefinitions() { + return Collections.emptySet(); + } + + @Override + public Set getChildNodes() { + return new HashSet(childNodes.values()); + } + + private void setChildNodes(Map childNodes) { + if (childNodes != null) { + this.childNodes = childNodes; + } + } + + @Override + public Set getGroupings() { + return Collections.emptySet(); + } + + @Override + public DataSchemaNode getDataChildByName(QName name) { + return childNodes.get(name); + } + + @Override + public DataSchemaNode getDataChildByName(String name) { + DataSchemaNode result = null; + for (Map.Entry entry : childNodes.entrySet()) { + if (entry.getKey().getLocalName().equals(name)) { + result = entry.getValue(); + break; + } + } + return result; + } + + @Override + public Set getUses() { + return uses; + } + + private void setUses(Set uses) { + if (uses != null) { + this.uses = uses; + } + } + + @Override + public Set getAvailableAugmentations() { + return augmentations; + } + + private void setAvailableAugmentations( + Set augmentations) { + if (augmentations != null) { + this.augmentations = augmentations; + } + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ChoiceCaseNodeImpl other = (ChoiceCaseNodeImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + ChoiceCaseNodeImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append("]"); + return sb.toString(); + } + + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ConstraintsBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ConstraintsBuilder.java index 387c46dd83..905a107f31 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ConstraintsBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ConstraintsBuilder.java @@ -23,6 +23,9 @@ public class ConstraintsBuilder implements Builder { private final ConstraintDefinitionImpl instance; private final Set mustDefinitions; private String whenCondition; + private boolean mandatory; + private Integer min; + private Integer max; ConstraintsBuilder() { instance = new ConstraintDefinitionImpl(); @@ -31,39 +34,62 @@ public class ConstraintsBuilder implements Builder { @Override public ConstraintDefinition build() { - RevisionAwareXPath whenStmt = new RevisionAwareXPathImpl(whenCondition, - false); + RevisionAwareXPath whenStmt; + if (whenCondition == null) { + whenStmt = null; + } else { + whenStmt = new RevisionAwareXPathImpl(whenCondition, false); + } instance.setWhenCondition(whenStmt); instance.setMustConstraints(mustDefinitions); + instance.setMandatory(mandatory); + instance.setMinElements(min); + instance.setMaxElements(max); return instance; } + public Integer getMinElements() { + return min; + } + public void setMinElements(Integer minElements) { - instance.setMinElements(minElements); + this.min = minElements; + } + + public Integer getMaxElements() { + return max; } public void setMaxElements(Integer maxElements) { - instance.setMaxElements(maxElements); + this.max = maxElements; + } + + public Set getMustDefinitions() { + return mustDefinitions; } - public void addMustDefinition(String mustStr, String description, - String reference) { - MustDefinition must = new MustDefinitionImpl(mustStr, description, - reference); + public void addMustDefinition(MustDefinition must) { mustDefinitions.add(must); } + public String getWhenCondition() { + return whenCondition; + } + public void addWhenCondition(String whenCondition) { this.whenCondition = whenCondition; } + public boolean isMandatory() { + return mandatory; + } + public void setMandatory(boolean mandatory) { - instance.setMandatory(mandatory); + this.mandatory = mandatory; } private static class ConstraintDefinitionImpl implements ConstraintDefinition { - private DataSchemaNode parent; private RevisionAwareXPath whenCondition; private Set mustConstraints; @@ -217,101 +243,4 @@ public class ConstraintsBuilder implements Builder { } - private static class MustDefinitionImpl implements MustDefinition { - - private final String mustStr; - private final String description; - private final String reference; - - private MustDefinitionImpl(String mustStr, String description, - String reference) { - this.mustStr = mustStr; - this.description = description; - this.reference = reference; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public String getErrorAppTag() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getErrorMessage() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getReference() { - return reference; - } - - @Override - public RevisionAwareXPath getXpath() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((mustStr == null) ? 0 : mustStr.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - MustDefinitionImpl other = (MustDefinitionImpl) obj; - if (mustStr == null) { - if (other.mustStr != null) { - return false; - } - } else if (!mustStr.equals(other.mustStr)) { - return false; - } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - return true; - } - - @Override - public String toString() { - return MustDefinitionImpl.class.getSimpleName() + "[mustStr=" - + mustStr + "]"; - } - } - } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java index eed8437fdd..8d82bda60a 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java @@ -27,6 +27,7 @@ import org.opendaylight.controller.yang.model.api.TypeDefinition; import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; import org.opendaylight.controller.yang.model.api.UsesNode; import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; @@ -39,21 +40,36 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder DataSchemaNodeBuilder { private final ContainerSchemaNodeImpl instance; - private final ConstraintsBuilder constraintsBuilder; + private final ConstraintsBuilder constraints; + private SchemaPath schemaPath; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean presence; + private boolean augmenting; + private boolean configuration; private final Set addedTypedefs = new HashSet(); - private final Set augmentations = new HashSet(); private final Set addedUsesNodes = new HashSet(); + private final Set addedAugmentations = new HashSet(); private final List addedUnknownNodes = new ArrayList(); - ContainerSchemaNodeBuilder(QName qname) { + public ContainerSchemaNodeBuilder(QName qname) { super(qname); instance = new ContainerSchemaNodeImpl(qname); - constraintsBuilder = new ConstraintsBuilder(); + constraints = new ConstraintsBuilder(); } @Override public ContainerSchemaNode build() { + instance.setPath(schemaPath); + instance.setDescription(description); + instance.setReference(reference); + instance.setStatus(status); + instance.setPresenceContainer(presence); + instance.setAugmenting(augmenting); + instance.setConfiguration(configuration); + // CHILD NODES final Map childs = new HashMap(); for (DataSchemaNodeBuilder node : childNodes) { @@ -62,11 +78,11 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder instance.setChildNodes(childs); // GROUPINGS - final Set groupingDefinitions = new HashSet(); + final Set groupingDefs = new HashSet(); for (GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); + groupingDefs.add(builder.build()); } - instance.setGroupings(groupingDefinitions); + instance.setGroupings(groupingDefs); // TYPEDEFS final Set> typedefs = new HashSet>(); @@ -82,6 +98,13 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder } instance.setUses(uses); + // AUGMENTATIONS + final Set augmentations = new HashSet(); + for(AugmentationSchemaBuilder builder : addedAugmentations) { + augmentations.add(builder.build()); + } + instance.setAvailableAugmentations(augmentations); + // UNKNOWN NODES final List unknownNodes = new ArrayList(); for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { @@ -89,55 +112,93 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder } instance.setUnknownSchemaNodes(unknownNodes); - instance.setConstraints(constraintsBuilder.build()); + instance.setConstraints(constraints.build()); instance.setAvailableAugmentations(augmentations); return instance; } + public Set getTypedefs() { + return addedTypedefs; + } + @Override - public void addTypedef(TypeDefinitionBuilder type) { + public void addTypedef(final TypeDefinitionBuilder type) { addedTypedefs.add(type); } + public Set getAugmentations() { + return addedAugmentations; + } + @Override - public void addAugmentation(AugmentationSchema augment) { - augmentations.add(augment); + public void addAugmentation(AugmentationSchemaBuilder augment) { + addedAugmentations.add(augment); + } + + public SchemaPath getPath() { + return schemaPath; } @Override - public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); + public void setPath(final SchemaPath schemaPath) { + this.schemaPath = schemaPath; + } + + public String getDescription() { + return description; } @Override - public void setDescription(String description) { - instance.setDescription(description); + public void setDescription(final String description) { + this.description = description; + } + + public String getReference() { + return reference; } @Override public void setReference(String reference) { - instance.setReference(reference); + this.reference = reference; + } + + public Status getStatus() { + return status; } @Override public void setStatus(Status status) { - instance.setStatus(status); + if(status != null) { + this.status = status; + } + } + + public boolean isAugmenting() { + return augmenting; } @Override public void setAugmenting(boolean augmenting) { - instance.setAugmenting(augmenting); + this.augmenting = augmenting; + } + + public boolean isConfiguration() { + return configuration; } @Override public void setConfiguration(boolean configuration) { - instance.setConfiguration(configuration); + this.configuration = configuration; } @Override - public ConstraintsBuilder getConstraintsBuilder() { - return constraintsBuilder; + public ConstraintsBuilder getConstraints() { + return constraints; + } + + public Set getUsesNodes() { + return addedUsesNodes; } @Override @@ -145,17 +206,24 @@ public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder addedUsesNodes.add(usesNodeBuilder); } - public void setPresenceContainer(boolean presence) { - instance.setPresenceContainer(presence); + public boolean isPresence() { + return presence; + } + + public void setPresence(boolean presence) { + this.presence = presence; + } + + public List getUnknownNodes() { + return addedUnknownNodes; } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } private class ContainerSchemaNodeImpl implements ContainerSchemaNode { - private final QName qname; private SchemaPath path; private String description; diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/DeviationBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/DeviationBuilder.java index 6e1bb6424e..0888811853 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/DeviationBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/DeviationBuilder.java @@ -17,8 +17,8 @@ public class DeviationBuilder implements Builder { private final DeviationImpl instance; - DeviationBuilder(String targetPathStr) { - SchemaPath targetPath = YangModelBuilderUtil + DeviationBuilder(final String targetPathStr) { + final SchemaPath targetPath = YangModelBuilderUtil .parseAugmentPath(targetPathStr); instance = new DeviationImpl(targetPath); } @@ -28,14 +28,14 @@ public class DeviationBuilder implements Builder { return instance; } - public void setDeviate(String deviate) { - if (deviate.equals("not-supported")) { + public void setDeviate(final String deviate) { + if ("not-supported".equals(deviate)) { instance.setDeviate(Deviate.NOT_SUPPORTED); - } else if (deviate.equals("add")) { + } else if ("add".equals(deviate)) { instance.setDeviate(Deviate.ADD); - } else if (deviate.equals("replace")) { + } else if ("replace".equals(deviate)) { instance.setDeviate(Deviate.REPLACE); - } else if (deviate.equals("delete")) { + } else if ("delete".equals(deviate)) { instance.setDeviate(Deviate.DELETE); } else { throw new IllegalArgumentException( @@ -43,17 +43,16 @@ public class DeviationBuilder implements Builder { } } - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } private static class DeviationImpl implements Deviation { - - private SchemaPath targetPath; + private final SchemaPath targetPath; private Deviate deviate; private String reference; - private DeviationImpl(SchemaPath targetPath) { + private DeviationImpl(final SchemaPath targetPath) { this.targetPath = targetPath; } @@ -67,7 +66,7 @@ public class DeviationBuilder implements Builder { return deviate; } - private void setDeviate(Deviate deviate) { + private void setDeviate(final Deviate deviate) { this.deviate = deviate; } @@ -76,7 +75,7 @@ public class DeviationBuilder implements Builder { return reference; } - private void setReference(String reference) { + private void setReference(final String reference) { this.reference = reference; } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java index 28a2330075..5828a33df9 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java @@ -22,21 +22,26 @@ public class ExtensionBuilder implements SchemaNodeBuilder { private final ExtensionDefinitionImpl instance; private final QName qname; + private SchemaPath schemaPath; private final List addedExtensions = new ArrayList(); private final List addedUnknownNodes = new ArrayList(); - ExtensionBuilder(QName qname) { + ExtensionBuilder(final QName qname) { this.qname = qname; instance = new ExtensionDefinitionImpl(qname); } @Override public ExtensionDefinition build() { - List extensions = new ArrayList(); + instance.setPath(schemaPath); + + // UNKNOWN NODES + final List extensions = new ArrayList(); for (UnknownSchemaNodeBuilder e : addedExtensions) { extensions.add(e.build()); } instance.setUnknownSchemaNodes(extensions); + return instance; } @@ -57,9 +62,14 @@ public class ExtensionBuilder implements SchemaNodeBuilder { return qname; } + @Override + public SchemaPath getPath() { + return schemaPath; + } + @Override public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); + this.schemaPath = schemaPath; } @Override @@ -78,8 +88,8 @@ public class ExtensionBuilder implements SchemaNodeBuilder { } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } private static class ExtensionDefinitionImpl implements ExtensionDefinition { @@ -89,7 +99,7 @@ public class ExtensionBuilder implements SchemaNodeBuilder { private String description; private String reference; private Status status = Status.CURRENT; - private List unknownSchemaNodes = Collections + private List unknownNodes = Collections .emptyList(); private boolean yin; @@ -142,13 +152,13 @@ public class ExtensionBuilder implements SchemaNodeBuilder { @Override public List getUnknownSchemaNodes() { - return unknownSchemaNodes; + return unknownNodes; } private void setUnknownSchemaNodes( - List unknownSchemaNodes) { - if(unknownSchemaNodes != null) { - this.unknownSchemaNodes = unknownSchemaNodes; + List unknownNodes) { + if(unknownNodes != null) { + this.unknownNodes = unknownNodes; } } @@ -177,16 +187,10 @@ public class ExtensionBuilder implements SchemaNodeBuilder { result = prime * result + ((qname == null) ? 0 : qname.hashCode()); result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result - + ((status == null) ? 0 : status.hashCode()); result = prime * result - + ((unknownSchemaNodes == null) ? 0 - : unknownSchemaNodes.hashCode()); + + ((unknownNodes == null) ? 0 + : unknownNodes.hashCode()); result = prime * result + (yin ? 1231 : 1237); return result; } @@ -217,32 +221,11 @@ public class ExtensionBuilder implements SchemaNodeBuilder { } else if (!schemaPath.equals(other.schemaPath)) { return false; } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - if (status == null) { - if (other.status != null) { - return false; - } - } else if (!status.equals(other.status)) { - return false; - } - if (unknownSchemaNodes == null) { - if (other.unknownSchemaNodes != null) { + if (unknownNodes == null) { + if (other.unknownNodes != null) { return false; } - } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) { + } else if (!unknownNodes.equals(other.unknownNodes)) { return false; } if (yin != other.yin) { @@ -259,10 +242,7 @@ public class ExtensionBuilder implements SchemaNodeBuilder { sb.append("argument="+ argument); sb.append(", qname=" + qname); sb.append(", schemaPath=" + schemaPath); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); - sb.append(", extensionSchemaNodes=" + unknownSchemaNodes); + sb.append(", extensionSchemaNodes=" + unknownNodes); sb.append(", yin=" + yin); sb.append("]"); return sb.toString(); diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java index b861700350..ec5bcd7f4b 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java @@ -22,18 +22,21 @@ public class FeatureBuilder implements SchemaNodeBuilder { private final FeatureDefinitionImpl instance; private final QName qname; + private SchemaPath schemaPath; private final List addedUnknownNodes = new ArrayList(); - FeatureBuilder(QName qname) { + FeatureBuilder(final QName qname) { this.qname = qname; instance = new FeatureDefinitionImpl(qname); } @Override public FeatureDefinitionImpl build() { + instance.setPath(schemaPath); + // UNKNOWN NODES final List unknownNodes = new ArrayList(); - for(UnknownSchemaNodeBuilder b : addedUnknownNodes) { + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { unknownNodes.add(b.build()); } instance.setUnknownSchemaNodes(unknownNodes); @@ -47,28 +50,33 @@ public class FeatureBuilder implements SchemaNodeBuilder { } @Override - public void setPath(SchemaPath path) { - instance.setPath(path); + public SchemaPath getPath() { + return schemaPath; } @Override - public void setDescription(String description) { + public void setPath(SchemaPath schemaPath) { + this.schemaPath = schemaPath; + } + + @Override + public void setDescription(final String description) { instance.setDescription(description); } @Override - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } @Override - public void setStatus(Status status) { + public void setStatus(final Status status) { instance.setStatus(status); } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } private static class FeatureDefinitionImpl implements FeatureDefinition { @@ -76,11 +84,10 @@ public class FeatureBuilder implements SchemaNodeBuilder { private SchemaPath path; private String description; private String reference; - private Status status; - private List unknownSchemaNodes = Collections - .emptyList(); + private Status status = Status.CURRENT; + private List unknownNodes = Collections.emptyList(); - private FeatureDefinitionImpl(QName qname) { + private FeatureDefinitionImpl(final QName qname) { this.qname = qname; } @@ -94,9 +101,8 @@ public class FeatureBuilder implements SchemaNodeBuilder { return path; } - private void setPath(SchemaPath path) { + private void setPath(final SchemaPath path) { this.path = path; - ; } @Override @@ -104,7 +110,7 @@ public class FeatureBuilder implements SchemaNodeBuilder { return description; } - private void setDescription(String description) { + private void setDescription(final String description) { this.description = description; } @@ -113,7 +119,7 @@ public class FeatureBuilder implements SchemaNodeBuilder { return reference; } - private void setReference(String reference) { + private void setReference(final String reference) { this.reference = reference; } @@ -123,17 +129,20 @@ public class FeatureBuilder implements SchemaNodeBuilder { } private void setStatus(Status status) { - this.status = status; + if (status != null) { + this.status = status; + } } @Override public List getUnknownSchemaNodes() { - return unknownSchemaNodes; + return unknownNodes; } - private void setUnknownSchemaNodes(List unknownSchemaNodes) { - if(unknownSchemaNodes != null) { - this.unknownSchemaNodes = unknownSchemaNodes; + private void setUnknownSchemaNodes( + final List unknownNodes) { + if (unknownNodes != null) { + this.unknownNodes = unknownNodes; } } @@ -179,8 +188,7 @@ public class FeatureBuilder implements SchemaNodeBuilder { public String toString() { StringBuilder sb = new StringBuilder( FeatureDefinitionImpl.class.getSimpleName()); - sb.append("[name=" + qname); - sb.append(", path=" + path + "]"); + sb.append("[name=" + qname + "]"); return sb.toString(); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java index 03dd15b504..08d8b35207 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java @@ -31,45 +31,48 @@ import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder public class GroupingBuilderImpl implements GroupingBuilder { private final GroupingDefinitionImpl instance; + private SchemaPath schemaPath; private final Set childNodes = new HashSet(); private final Set groupings = new HashSet(); private final Set addedTypedefs = new HashSet(); private final Set usesNodes = new HashSet(); private final List addedUnknownNodes = new ArrayList(); - GroupingBuilderImpl(QName qname) { + GroupingBuilderImpl(final QName qname) { this.instance = new GroupingDefinitionImpl(qname); } @Override public GroupingDefinition build() { + instance.setPath(schemaPath); + // CHILD NODES - Map childs = new HashMap(); + final Map childs = new HashMap(); for (DataSchemaNodeBuilder node : childNodes) { childs.put(node.getQName(), node.build()); } instance.setChildNodes(childs); // GROUPINGS - Set groupingDefinitions = new HashSet(); + final Set groupingDefs = new HashSet(); for (GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); + groupingDefs.add(builder.build()); } - instance.setGroupings(groupingDefinitions); + instance.setGroupings(groupingDefs); // TYPEDEFS - Set> typedefs = new HashSet>(); + final Set> typedefs = new HashSet>(); for (TypeDefinitionBuilder entry : addedTypedefs) { typedefs.add(entry.build()); } instance.setTypeDefinitions(typedefs); // USES - Set usesNodeDefinitions = new HashSet(); + final Set usesNodeDefs = new HashSet(); for (UsesNodeBuilder builder : usesNodes) { - usesNodeDefinitions.add(builder.build()); + usesNodeDefs.add(builder.build()); } - instance.setUses(usesNodeDefinitions); + instance.setUses(usesNodeDefs); // UNKNOWN NODES final List unknownNodes = new ArrayList(); @@ -90,48 +93,65 @@ public class GroupingBuilderImpl implements GroupingBuilder { } @Override - public void addTypedef(TypeDefinitionBuilder type) { + public void addTypedef(final TypeDefinitionBuilder type) { addedTypedefs.add(type); } + @Override + public SchemaPath getPath() { + return schemaPath; + } + @Override public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); + this.schemaPath = schemaPath; } @Override - public void setDescription(String description) { + public void setDescription(final String description) { instance.setDescription(description); } @Override - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } @Override - public void setStatus(Status status) { + public void setStatus(final Status status) { instance.setStatus(status); } @Override - public void addChildNode(DataSchemaNodeBuilder childNode) { + public DataSchemaNodeBuilder getChildNode(String name) { + DataSchemaNodeBuilder result = null; + for(DataSchemaNodeBuilder node : childNodes) { + if(node.getQName().getLocalName().equals(name)) { + result = node; + break; + } + } + return result; + } + + @Override + public void addChildNode(final DataSchemaNodeBuilder childNode) { childNodes.add(childNode); } @Override - public void addGrouping(GroupingBuilder grouping) { + public void addGrouping(final GroupingBuilder grouping) { groupings.add(grouping); } @Override - public void addUsesNode(UsesNodeBuilder usesBuilder) { + public void addUsesNode(final UsesNodeBuilder usesBuilder) { usesNodes.add(usesBuilder); } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } private static class GroupingDefinitionImpl implements GroupingDefinition { @@ -144,9 +164,9 @@ public class GroupingBuilderImpl implements GroupingBuilder { private Set groupings = Collections.emptySet(); private Set> typeDefinitions = Collections.emptySet(); private Set uses = Collections.emptySet(); - private List unknownSchemaNodes = Collections.emptyList(); + private List unknownNodes = Collections.emptyList(); - private GroupingDefinitionImpl(QName qname) { + private GroupingDefinitionImpl(final QName qname) { this.qname = qname; } @@ -229,12 +249,12 @@ public class GroupingBuilderImpl implements GroupingBuilder { @Override public List getUnknownSchemaNodes() { - return unknownSchemaNodes; + return unknownNodes; } - private void setUnknownSchemaNodes(List unknownSchemaNodes) { - if(unknownSchemaNodes != null) { - this.unknownSchemaNodes = unknownSchemaNodes; + private void setUnknownSchemaNodes(List unknownNodes) { + if(unknownNodes != null) { + this.unknownNodes = unknownNodes; } } @@ -275,7 +295,7 @@ public class GroupingBuilderImpl implements GroupingBuilder { if (getClass() != obj.getClass()) { return false; } - GroupingDefinitionImpl other = (GroupingDefinitionImpl) obj; + final GroupingDefinitionImpl other = (GroupingDefinitionImpl) obj; if (qname == null) { if (other.qname != null) { return false; diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentitySchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentitySchemaNodeBuilder.java index 0abc9598dc..906afd97a0 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentitySchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentitySchemaNodeBuilder.java @@ -20,19 +20,22 @@ import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuild public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { private final QName qname; + private SchemaPath schemaPath; private final IdentitySchemaNodeImpl instance; private IdentitySchemaNodeBuilder baseIdentity; private String baseIdentityName; - IdentitySchemaNodeBuilder(QName qname) { + IdentitySchemaNodeBuilder(final QName qname) { this.qname = qname; instance = new IdentitySchemaNodeImpl(qname); } @Override public IdentitySchemaNode build() { - if(baseIdentity != null) { - IdentitySchemaNode base = baseIdentity.build(); + instance.setPath(schemaPath); + + if (baseIdentity != null) { + final IdentitySchemaNode base = baseIdentity.build(); instance.setBaseIdentity(base); } return instance; @@ -44,30 +47,34 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { } @Override - public void setPath(SchemaPath path) { - instance.setPath(path); + public SchemaPath getPath() { + return schemaPath; + } + + @Override + public void setPath(SchemaPath schemaPath) { + this.schemaPath = schemaPath; } @Override - public void setDescription(String description) { + public void setDescription(final String description) { instance.setDescription(description); } @Override - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } @Override - public void setStatus(Status status) { + public void setStatus(final Status status) { if (status != null) { instance.setStatus(status); } } @Override - public void addUnknownSchemaNode( - UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { throw new IllegalStateException( "Can not add schema node to identity statement"); } @@ -76,11 +83,11 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { return baseIdentityName; } - public void setBaseIdentityName(String baseIdentityName) { + public void setBaseIdentityName(final String baseIdentityName) { this.baseIdentityName = baseIdentityName; } - public void setBaseIdentity(IdentitySchemaNodeBuilder baseType) { + public void setBaseIdentity(final IdentitySchemaNodeBuilder baseType) { this.baseIdentity = baseType; } @@ -92,7 +99,7 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { private Status status = Status.CURRENT; private SchemaPath path; - private IdentitySchemaNodeImpl(QName qname) { + private IdentitySchemaNodeImpl(final QName qname) { this.qname = qname; } @@ -106,7 +113,7 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { return baseIdentity; } - private void setBaseIdentity(IdentitySchemaNode baseIdentity) { + private void setBaseIdentity(final IdentitySchemaNode baseIdentity) { this.baseIdentity = baseIdentity; } @@ -115,7 +122,7 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { return description; } - private void setDescription(String description) { + private void setDescription(final String description) { this.description = description; } @@ -124,7 +131,7 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { return reference; } - private void setReference(String reference) { + private void setReference(final String reference) { this.reference = reference; } @@ -133,7 +140,7 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { return status; } - private void setStatus(Status status) { + private void setStatus(final Status status) { if (status != null) { this.status = status; } @@ -144,7 +151,7 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { return path; } - private void setPath(SchemaPath path) { + private void setPath(final SchemaPath path) { this.path = path; } @@ -190,9 +197,6 @@ public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder { sb.append("["); sb.append("base=" + baseIdentity); sb.append(", qname=" + qname); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); sb.append("]"); return sb.toString(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java index 12c976b774..3884311e8e 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java @@ -22,15 +22,22 @@ import org.opendaylight.controller.yang.model.parser.builder.api.AbstractTypeAwa import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; -public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements SchemaNodeBuilder, - DataSchemaNodeBuilder { - +public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder + implements SchemaNodeBuilder, DataSchemaNodeBuilder { private final LeafListSchemaNodeImpl instance; private final QName qname; private final ConstraintsBuilder constraints = new ConstraintsBuilder(); + private SchemaPath schemaPath; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private boolean configuration; + private boolean userOrdered; + private final List addedUnknownNodes = new ArrayList(); - LeafListSchemaNodeBuilder(QName qname) { + public LeafListSchemaNodeBuilder(final QName qname) { this.qname = qname; instance = new LeafListSchemaNodeImpl(qname); } @@ -38,8 +45,15 @@ public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implemen @Override public LeafListSchemaNode build() { instance.setConstraints(constraints.build()); + instance.setPath(schemaPath); + instance.setDescription(description); + instance.setReference(reference); + instance.setStatus(status); + instance.setAugmenting(augmenting); + instance.setConfiguration(configuration); + instance.setUserOrdered(userOrdered); - if(type == null) { + if (type == null) { instance.setType(typedef.build()); } else { instance.setType(type); @@ -60,50 +74,82 @@ public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implemen return qname; } + public SchemaPath getPath() { + return schemaPath; + } + @Override - public void setPath(SchemaPath path) { - instance.setPath(path); + public void setPath(final SchemaPath schemaPath) { + this.schemaPath = schemaPath; + } + + public String getDescription() { + return description; } @Override - public void setDescription(String description) { - instance.setDescription(description); + public void setDescription(final String description) { + this.description = description; + } + + public String getReference() { + return reference; } @Override public void setReference(String reference) { - instance.setReference(reference); + this.reference = reference; + } + + public Status getStatus() { + return status; } @Override public void setStatus(Status status) { if(status != null) { - instance.setStatus(status); + this.status = status; } } + public boolean isAugmenting() { + return augmenting; + } + @Override public void setAugmenting(boolean augmenting) { - instance.setAugmenting(augmenting); + this.augmenting = augmenting; + } + + public boolean isConfiguration() { + return configuration; } @Override public void setConfiguration(boolean configuration) { - instance.setConfiguration(configuration); + this.configuration = configuration; } @Override - public ConstraintsBuilder getConstraintsBuilder() { + public ConstraintsBuilder getConstraints() { return constraints; } - public void setUserOrdered(boolean userOrdered) { - instance.setUserOrdered(userOrdered); + public boolean isUserOrdered() { + return userOrdered; + } + + public void setUserOrdered(final boolean userOrdered) { + this.userOrdered = userOrdered; + } + + public List getUnknownNodes() { + return addedUnknownNodes; } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } private class LeafListSchemaNodeImpl implements LeafListSchemaNode { @@ -117,10 +163,9 @@ public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implemen private ConstraintDefinition constraintsDef; private TypeDefinition type; private boolean userOrdered; - private List unknownNodes = Collections - .emptyList(); + private List unknownNodes = Collections.emptyList(); - private LeafListSchemaNodeImpl(QName qname) { + private LeafListSchemaNodeImpl(final QName qname) { this.qname = qname; } @@ -134,7 +179,7 @@ public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implemen return path; } - private void setPath(SchemaPath path) { + private void setPath(final SchemaPath path) { this.path = path; } @@ -215,8 +260,7 @@ public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implemen return unknownNodes; } - private void setUnknownSchemaNodes( - List unknownNodes) { + private void setUnknownSchemaNodes(List unknownNodes) { if (unknownNodes != null) { this.unknownNodes = unknownNodes; } @@ -267,9 +311,6 @@ public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implemen sb.append("["); sb.append("qname=" + qname); sb.append(", path=" + path); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); sb.append(", augmenting=" + augmenting); sb.append(", configuration=" + configuration); sb.append(", constraints=" + constraintsDef); diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java index 6146550257..fe039b2394 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java @@ -22,21 +22,37 @@ import org.opendaylight.controller.yang.model.parser.builder.api.AbstractTypeAwa import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; -public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder, - SchemaNodeBuilder { +public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements + DataSchemaNodeBuilder, SchemaNodeBuilder { private final QName qname; + private SchemaPath path; private final LeafSchemaNodeImpl instance; private final ConstraintsBuilder constraints = new ConstraintsBuilder(); private final List addedUnknownNodes = new ArrayList(); - LeafSchemaNodeBuilder(QName qname) { + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private boolean configuration; + private String defaultStr; + private String unitsStr; + + public LeafSchemaNodeBuilder(final QName qname) { this.qname = qname; instance = new LeafSchemaNodeImpl(qname); } @Override public LeafSchemaNode build() { - if(type == null) { + instance.setPath(path); + instance.setConstraints(constraints.build()); + instance.setDescription(description); + instance.setReference(reference); + instance.setStatus(status); + + // TYPE + if (type == null) { instance.setType(typedef.build()); } else { instance.setType(type); @@ -44,12 +60,15 @@ public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements D // UNKNOWN NODES final List unknownNodes = new ArrayList(); - for(UnknownSchemaNodeBuilder b : addedUnknownNodes) { + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { unknownNodes.add(b.build()); } instance.setUnknownSchemaNodes(unknownNodes); - instance.setConstraints(constraints.build()); + instance.setAugmenting(augmenting); + instance.setConfiguration(configuration); + instance.setDefault(defaultStr); + instance.setUnits(unitsStr); return instance; } @@ -58,46 +77,90 @@ public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements D return qname; } + public SchemaPath getPath() { + return path; + } + @Override - public void setPath(SchemaPath path) { - instance.setPath(path); + public void setPath(final SchemaPath path) { + this.path = path; } @Override - public void setDescription(String description) { - instance.setDescription(description); + public ConstraintsBuilder getConstraints() { + return constraints; } @Override - public void setReference(String reference) { - instance.setReference(reference); + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); + } + + public List getUnknownNodes() { + return addedUnknownNodes; + } + + public String getDescription() { + return description; } @Override - public void setStatus(Status status) { - if(status != null) { - instance.setStatus(status); - } + public void setDescription(final String description) { + this.description = description; + } + + public String getReference() { + return reference; } @Override - public void setAugmenting(boolean augmenting) { - instance.setAugmenting(augmenting); + public void setReference(final String reference) { + this.reference = reference; + } + + public Status getStatus() { + return status; } @Override - public void setConfiguration(boolean configuration) { - instance.setConfiguration(configuration); + public void setStatus(final Status status) { + if (status != null) { + this.status = status; + } + } + + public boolean isAugmenting() { + return augmenting; } @Override - public ConstraintsBuilder getConstraintsBuilder() { - return constraints; + public void setAugmenting(final boolean augmenting) { + this.augmenting = augmenting; + } + + public boolean isConfiguration() { + return configuration; } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) { - addedUnknownNodes.add(unknownNode); + public void setConfiguration(final boolean configuration) { + instance.setConfiguration(configuration); + } + + public String getDefaultStr() { + return defaultStr; + } + + public void setDefaultStr(String defaultStr) { + this.defaultStr = defaultStr; + } + + public String getUnits() { + return unitsStr; + } + + public void setUnits(String unitsStr) { + this.unitsStr = unitsStr; } private class LeafSchemaNodeImpl implements LeafSchemaNode { @@ -111,8 +174,10 @@ public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements D private ConstraintDefinition constraintsDef; private TypeDefinition type; private List unknownNodes = Collections.emptyList(); + private String defaultStr; + private String unitsStr; - private LeafSchemaNodeImpl(QName qname) { + private LeafSchemaNodeImpl(final QName qname) { this.qname = qname; } @@ -126,7 +191,7 @@ public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements D return path; } - private void setPath(SchemaPath path) { + private void setPath(final SchemaPath path) { this.path = path; } @@ -201,11 +266,27 @@ public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements D } private void setUnknownSchemaNodes(List unknownNodes) { - if(unknownNodes != null) { + if (unknownNodes != null) { this.unknownNodes = unknownNodes; } } + public String getDefault() { + return defaultStr; + } + + private void setDefault(String defaultStr) { + this.defaultStr = defaultStr; + } + + public String getUnits() { + return unitsStr; + } + + public void setUnits(String unitsStr) { + this.unitsStr = unitsStr; + } + @Override public int hashCode() { final int prime = 31; @@ -251,14 +332,6 @@ public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements D sb.append("["); sb.append("qname=" + qname); sb.append(", path=" + path); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); - sb.append(", augmenting=" + augmenting); - sb.append(", configuration=" + configuration); - sb.append(", constraints=" + constraintsDef); - sb.append(", type=" + type); - sb.append(", constraints=" + constraintsDef); sb.append("]"); return sb.toString(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java index ccca99c2bc..b032b32804 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java @@ -27,6 +27,7 @@ import org.opendaylight.controller.yang.model.api.TypeDefinition; import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; import org.opendaylight.controller.yang.model.api.UsesNode; import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; @@ -38,127 +39,198 @@ import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements DataSchemaNodeBuilder, SchemaNodeBuilder, AugmentationTargetBuilder, TypeDefinitionAwareBuilder { - private final ListSchemaNodeImpl instance; - private final ConstraintsBuilder constraintsBuilder; + private List keyDefinition; + private final ConstraintsBuilder constraints; + private SchemaPath schemaPath; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private boolean configuration; + private boolean userOrdered; private final Set addedTypedefs = new HashSet(); - private final Set augmentations = new HashSet(); - private final Set usesNodes = new HashSet(); + private final Set addedUsesNodes = new HashSet(); + private final Set addedAugmentations = new HashSet(); private final List addedUnknownNodes = new ArrayList(); - ListSchemaNodeBuilder(QName qname) { + public ListSchemaNodeBuilder(final QName qname) { super(qname); instance = new ListSchemaNodeImpl(qname); - constraintsBuilder = new ConstraintsBuilder(); + constraints = new ConstraintsBuilder(); } @Override public ListSchemaNode build() { + instance.setKeyDefinition(keyDefinition); + instance.setPath(schemaPath); + instance.setDescription(description); + instance.setReference(reference); + instance.setStatus(status); + instance.setAugmenting(augmenting); + instance.setConfiguration(configuration); + instance.setUserOrdered(userOrdered); + // CHILD NODES - Map childs = new HashMap(); + final Map childs = new HashMap(); for (DataSchemaNodeBuilder node : childNodes) { childs.put(node.getQName(), node.build()); } instance.setChildNodes(childs); // TYPEDEFS - Set> typedefs = new HashSet>(); + final Set> typedefs = new HashSet>(); for (TypeDefinitionBuilder entry : addedTypedefs) { typedefs.add(entry.build()); } instance.setTypeDefinitions(typedefs); // USES - Set usesNodeDefinitions = new HashSet(); - for (UsesNodeBuilder builder : usesNodes) { - usesNodeDefinitions.add(builder.build()); + final Set usesNodeDefs = new HashSet(); + for (UsesNodeBuilder builder : addedUsesNodes) { + usesNodeDefs.add(builder.build()); } - instance.setUses(usesNodeDefinitions); + instance.setUses(usesNodeDefs); // GROUPINGS - Set groupingDefinitions = new HashSet(); + final Set groupingDefs = new HashSet(); for (GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); + groupingDefs.add(builder.build()); } - instance.setGroupings(groupingDefinitions); + instance.setGroupings(groupingDefs); + + // AUGMENTATIONS + final Set augmentations = new HashSet(); + for(AugmentationSchemaBuilder builder : addedAugmentations) { + augmentations.add(builder.build()); + } + instance.setAvailableAugmentations(augmentations); // UNKNOWN NODES final List unknownNodes = new ArrayList(); - for(UnknownSchemaNodeBuilder b : addedUnknownNodes) { + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { unknownNodes.add(b.build()); } instance.setUnknownSchemaNodes(unknownNodes); - instance.setConstraints(constraintsBuilder.build()); + instance.setConstraints(constraints.build()); instance.setAvailableAugmentations(augmentations); return instance; } + public Set getTypedefs() { + return addedTypedefs; + } + @Override - public void addTypedef(TypeDefinitionBuilder type) { + public void addTypedef(final TypeDefinitionBuilder type) { addedTypedefs.add(type); } + public SchemaPath getPath() { + return schemaPath; + } + @Override - public void setPath(SchemaPath path) { - instance.setPath(path); + public void setPath(final SchemaPath schemaPath) { + this.schemaPath = schemaPath; + } + + public String getDescription() { + return description; } @Override - public void setDescription(String description) { - instance.setDescription(description); + public void setDescription(final String description) { + this.description = description; + } + + public String getReference() { + return reference; } @Override public void setReference(String reference) { - instance.setReference(reference); + this.reference = reference; + } + + public Status getStatus() { + return status; } @Override public void setStatus(Status status) { if(status != null) { - instance.setStatus(status); + this.status = status; } } + public Set getUsesNodes() { + return addedUsesNodes; + } + @Override - public void addUsesNode(UsesNodeBuilder usesBuilder) { - usesNodes.add(usesBuilder); + public void addUsesNode(final UsesNodeBuilder usesBuilder) { + addedUsesNodes.add(usesBuilder); + } + + public Set getAugmentations() { + return addedAugmentations; } @Override - public void addAugmentation(AugmentationSchema augmentationSchema) { - augmentations.add(augmentationSchema); + public void addAugmentation(AugmentationSchemaBuilder augment) { + addedAugmentations.add(augment); } - public void setKeyDefinition(List keyDefinition) { - instance.setKeyDefinition(keyDefinition); + public List getKeyDefinition() { + return keyDefinition; + } + + public void setKeyDefinition(final List keyDefinition) { + this.keyDefinition = keyDefinition; + } + + public boolean isAugmenting() { + return augmenting; } @Override public void setAugmenting(boolean augmenting) { - instance.setAugmenting(augmenting); + this.augmenting = augmenting; + } + + public boolean isConfiguration() { + return configuration; } @Override public void setConfiguration(boolean configuration) { - instance.setConfiguration(configuration); + this.configuration = configuration; } @Override - public ConstraintsBuilder getConstraintsBuilder() { - return constraintsBuilder; + public ConstraintsBuilder getConstraints() { + return constraints; } - public void setUserOrdered(boolean userOrdered) { - instance.setUserOrdered(userOrdered); + public boolean isUserOrdered() { + return userOrdered; + } + + public void setUserOrdered(final boolean userOrdered) { + this.userOrdered = userOrdered; + } + + public List getUnknownNodes() { + return addedUnknownNodes; } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } private class ListSchemaNodeImpl implements ListSchemaNode { @@ -177,9 +249,9 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements private Set groupings = Collections.emptySet(); private Set uses = Collections.emptySet(); private boolean userOrdered; - private List unknownSchemaNodes = Collections.emptyList(); + private List unknownNodes = Collections.emptyList(); - private ListSchemaNodeImpl(QName qname) { + private ListSchemaNodeImpl(final QName qname) { this.qname = qname; } @@ -193,7 +265,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements return path; } - private void setPath(SchemaPath path) { + private void setPath(final SchemaPath path) { this.path = path; } @@ -202,7 +274,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements return description; } - private void setDescription(String description) { + private void setDescription(final String description) { this.description = description; } @@ -211,7 +283,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements return reference; } - private void setReference(String reference) { + private void setReference(final String reference) { this.reference = reference; } @@ -226,15 +298,11 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements @Override public List getKeyDefinition() { - if(keyDefinition == null) { - return Collections.emptyList(); - } else { - return keyDefinition; - } + return keyDefinition; } private void setKeyDefinition(List keyDefinition) { - if(keyDefinition != null) { + if (keyDefinition != null) { this.keyDefinition = keyDefinition; } } @@ -273,7 +341,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements private void setAvailableAugmentations( Set augmentations) { - if(augmentations != null) { + if (augmentations != null) { this.augmentations = augmentations; } } @@ -284,7 +352,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements } private void setChildNodes(Map childNodes) { - if(childNodes != null) { + if (childNodes != null) { this.childNodes = childNodes; } } @@ -295,7 +363,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements } private void setGroupings(Set groupings) { - if(groupings != null) { + if (groupings != null) { this.groupings = groupings; } } @@ -306,7 +374,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements } private void setTypeDefinitions(Set> typeDefinitions) { - if(typeDefinitions != null) { + if (typeDefinitions != null) { this.typeDefinitions = typeDefinitions; } } @@ -317,7 +385,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements } private void setUses(Set uses) { - if(uses != null) { + if (uses != null) { this.uses = uses; } } @@ -350,12 +418,12 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements @Override public List getUnknownSchemaNodes() { - return unknownSchemaNodes; + return unknownNodes; } - private void setUnknownSchemaNodes(List unknownSchemaNodes) { - if(unknownSchemaNodes != null) { - this.unknownSchemaNodes = unknownSchemaNodes; + private void setUnknownSchemaNodes(List unknownNodes) { + if (unknownNodes != null) { + this.unknownNodes = unknownNodes; } } @@ -379,7 +447,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements if (getClass() != obj.getClass()) { return false; } - ListSchemaNodeImpl other = (ListSchemaNodeImpl) obj; + final ListSchemaNodeImpl other = (ListSchemaNodeImpl) obj; if (qname == null) { if (other.qname != null) { return false; @@ -404,19 +472,7 @@ public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements sb.append("["); sb.append("qname=" + qname); sb.append(", path=" + path); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); sb.append(", keyDefinition=" + keyDefinition); - sb.append(", augmenting=" + augmenting); - sb.append(", configuration=" + configuration); - sb.append(", constraints=" + constraints); - sb.append(", augmentations=" + augmentations); - sb.append(", childNodes=" + childNodes.values()); - sb.append(", typedefinitions=" + typeDefinitions); - sb.append(", groupings=" + groupings); - sb.append(", uses=" + uses); - sb.append(", userOrdered=" + userOrdered); sb.append("]"); return sb.toString(); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java index 86adcdd71d..f364ad45b1 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java @@ -36,6 +36,7 @@ import org.opendaylight.controller.yang.model.parser.builder.api.Builder; import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; @@ -48,14 +49,12 @@ import org.opendaylight.controller.yang.model.parser.util.YangParseException; * otherwise result may not be valid. */ public class ModuleBuilder implements Builder { - private final ModuleImpl instance; private final String name; private String prefix; private Date revision; private final Set imports = new HashSet(); - private Set augmentations; /** * All nodes, that can contain other nodes @@ -81,12 +80,11 @@ public class ModuleBuilder implements Builder { private final Map, TypeAwareBuilder> dirtyNodes = new HashMap, TypeAwareBuilder>(); - public ModuleBuilder(String name) { + public ModuleBuilder(final String name) { this.name = name; instance = new ModuleImpl(name); } - /** * Build new Module object based on this builder. */ @@ -122,6 +120,11 @@ public class ModuleBuilder implements Builder { instance.setNotifications(notifications); // AUGMENTATIONS + // instance.setAugmentations(augmentations); + final Set augmentations = new HashSet(); + for (AugmentationSchemaBuilder builder : addedAugments) { + augmentations.add(builder.build()); + } instance.setAugmentations(augmentations); // RPCs @@ -138,14 +141,14 @@ public class ModuleBuilder implements Builder { // EXTENSIONS final List extensions = new ArrayList(); - for(ExtensionBuilder b : addedExtensions) { + for (ExtensionBuilder b : addedExtensions) { extensions.add(b.build()); } instance.setExtensionSchemaNodes(extensions); // IDENTITIES final Set identities = new HashSet(); - for(IdentitySchemaNodeBuilder idBuilder : addedIdentities) { + for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) { identities.add(idBuilder.build()); } instance.setIdentities(identities); @@ -153,7 +156,7 @@ public class ModuleBuilder implements Builder { return instance; } - public Builder getNode(List path) { + public Builder getNode(final List path) { return moduleNodes.get(path); } @@ -169,6 +172,21 @@ public class ModuleBuilder implements Builder { return addedIdentities; } + public Map, UsesNodeBuilder> getAddedUsesNodes() { + return addedUsesNodes; + } + + public Set getModuleTypedefs() { + Set typedefs = new HashSet(); + for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs + .entrySet()) { + if (entry.getKey().size() == 2) { + typedefs.add(entry.getValue()); + } + } + return typedefs; + } + public String getName() { return name; } @@ -181,55 +199,51 @@ public class ModuleBuilder implements Builder { return revision; } - public void addDirtyNode(List path) { - List dirtyNodePath = new ArrayList(path); - TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes + public void addDirtyNode(final List path) { + final List dirtyNodePath = new ArrayList(path); + final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes .get(dirtyNodePath); dirtyNodes.put(dirtyNodePath, nodeBuilder); } - public void setNamespace(URI namespace) { + public void setNamespace(final URI namespace) { instance.setNamespace(namespace); } - public void setRevision(Date revision) { + public void setRevision(final Date revision) { this.revision = revision; instance.setRevision(revision); } - public void setPrefix(String prefix) { + public void setPrefix(final String prefix) { this.prefix = prefix; instance.setPrefix(prefix); } - public void setYangVersion(String yangVersion) { + public void setYangVersion(final String yangVersion) { instance.setYangVersion(yangVersion); } - public void setDescription(String description) { + public void setDescription(final String description) { instance.setDescription(description); } - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } - public void setOrganization(String organization) { + public void setOrganization(final String organization) { instance.setOrganization(organization); } - public void setContact(String contact) { + public void setContact(final String contact) { instance.setContact(contact); } - public void setAugmentations(Set augmentations) { - this.augmentations = augmentations; - } - public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) { - ModuleImport moduleImport = createModuleImport(moduleName, revision, - prefix); + final ModuleImport moduleImport = createModuleImport(moduleName, + revision, prefix); return imports.add(moduleImport); } @@ -237,21 +251,23 @@ public class ModuleBuilder implements Builder { return imports; } - public ExtensionBuilder addExtension(QName qname) { - return new ExtensionBuilder(qname); + public ExtensionBuilder addExtension(final QName qname) { + final ExtensionBuilder builder = new ExtensionBuilder(qname); + addedExtensions.add(builder); + return builder; } - public ContainerSchemaNodeBuilder addContainerNode(QName containerName, - List parentPath) { - List pathToNode = new ArrayList(parentPath); + public ContainerSchemaNodeBuilder addContainerNode( + final QName containerName, final List parentPath) { + final List pathToNode = new ArrayList(parentPath); - ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder( + final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder( containerName); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes .get(pathToNode); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { + if (parent instanceof AugmentationSchemaBuilder) { containerBuilder.setAugmenting(true); } parent.addChildNode(containerBuilder); @@ -264,16 +280,17 @@ public class ModuleBuilder implements Builder { return containerBuilder; } - public ListSchemaNodeBuilder addListNode(QName listName, - List parentPath) { - List pathToNode = new ArrayList(parentPath); + public ListSchemaNodeBuilder addListNode(final QName listName, + final List parentPath) { + final List pathToNode = new ArrayList(parentPath); - ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName); + final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder( + listName); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes .get(pathToNode); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { + if (parent instanceof AugmentationSchemaBuilder) { listBuilder.setAugmenting(true); } parent.addChildNode(listBuilder); @@ -286,15 +303,17 @@ public class ModuleBuilder implements Builder { return listBuilder; } - public LeafSchemaNodeBuilder addLeafNode(QName leafName, - List parentPath) { - List pathToNode = new ArrayList(parentPath); + public LeafSchemaNodeBuilder addLeafNode(final QName leafName, + final List parentPath) { + final List pathToNode = new ArrayList(parentPath); - LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName); + final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder( + leafName); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode); + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToNode); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { + if (parent instanceof AugmentationSchemaBuilder) { leafBuilder.setAugmenting(true); } parent.addChildNode(leafBuilder); @@ -307,15 +326,16 @@ public class ModuleBuilder implements Builder { return leafBuilder; } - public LeafListSchemaNodeBuilder addLeafListNode(QName leafListName, - List parentPath) { - List pathToNode = new ArrayList(parentPath); + public LeafListSchemaNodeBuilder addLeafListNode(final QName leafListName, + final List parentPath) { + final List pathToNode = new ArrayList(parentPath); - LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder( + final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder( leafListName); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode); + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToNode); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { + if (parent instanceof AugmentationSchemaBuilder) { leafListBuilder.setAugmenting(true); } parent.addChildNode(leafListBuilder); @@ -328,15 +348,18 @@ public class ModuleBuilder implements Builder { return leafListBuilder; } - public GroupingBuilder addGrouping(QName qname, List parentPath) { - List pathToGroup = new ArrayList(parentPath); + public GroupingBuilder addGrouping(final QName qname, + final List parentPath) { + final List pathToGroup = new ArrayList(parentPath); - GroupingBuilder builder = new GroupingBuilderImpl(qname); - ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes.get(pathToGroup); + final GroupingBuilder builder = new GroupingBuilderImpl(qname); + final ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes + .get(pathToGroup); if (parentNodeBuilder != null) { parentNodeBuilder.addGrouping(builder); } + pathToGroup.add("grouping"); pathToGroup.add(qname.getLocalName()); moduleNodes.put(pathToGroup, builder); addedGroupings.put(pathToGroup, builder); @@ -344,14 +367,15 @@ public class ModuleBuilder implements Builder { return builder; } - public AugmentationSchemaBuilder addAugment(String name, - List parentPath) { - List pathToAugment = new ArrayList(parentPath); + public AugmentationSchemaBuilder addAugment(final String name, + final List parentPath) { + final List pathToAugment = new ArrayList(parentPath); - AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name); + final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl( + name); // augment can only be in 'module' or 'uses' statement - UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment); + final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment); if (parent != null) { parent.addAugment(builder); } @@ -363,13 +387,14 @@ public class ModuleBuilder implements Builder { return builder; } - public UsesNodeBuilder addUsesNode(String groupingPathStr, - List parentPath) { - List pathToUses = new ArrayList(parentPath); + public UsesNodeBuilder addUsesNode(final String groupingPathStr, + final List parentPath) { + final List pathToUses = new ArrayList(parentPath); UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToUses); + ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToUses); if (parent != null) { parent.addUsesNode(usesBuilder); } @@ -380,7 +405,8 @@ public class ModuleBuilder implements Builder { return usesBuilder; } - public RpcDefinitionBuilder addRpc(QName qname, List parentPath) { + public RpcDefinitionBuilder addRpc(final QName qname, + final List parentPath) { List pathToRpc = new ArrayList(parentPath); RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname); @@ -390,7 +416,8 @@ public class ModuleBuilder implements Builder { QName inputQName = new QName(qname.getNamespace(), qname.getRevision(), qname.getPrefix(), "input"); - ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName); + ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder( + inputQName); List pathToInput = new ArrayList(pathToRpc); pathToInput.add("input"); moduleNodes.put(pathToInput, inputBuilder); @@ -398,7 +425,8 @@ public class ModuleBuilder implements Builder { QName outputQName = new QName(qname.getNamespace(), qname.getRevision(), qname.getPrefix(), "output"); - ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName); + ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder( + outputQName); List pathToOutput = new ArrayList(pathToRpc); pathToOutput.add("output"); moduleNodes.put(pathToOutput, outputBuilder); @@ -407,12 +435,12 @@ public class ModuleBuilder implements Builder { return rpcBuilder; } - public NotificationBuilder addNotification(QName notificationName, - List parentPath) { - List pathToNotification = new ArrayList(parentPath); + public NotificationBuilder addNotification(final QName notificationName, + final List parentPath) { + final List pathToNotification = new ArrayList( + parentPath); - NotificationBuilder builder = new NotificationBuilder( - notificationName); + NotificationBuilder builder = new NotificationBuilder(notificationName); pathToNotification.add(notificationName.getLocalName()); moduleNodes.put(pathToNotification, builder); @@ -421,7 +449,8 @@ public class ModuleBuilder implements Builder { return builder; } - public FeatureBuilder addFeature(QName featureName, List parentPath) { + public FeatureBuilder addFeature(final QName featureName, + final List parentPath) { List pathToFeature = new ArrayList(parentPath); pathToFeature.add(featureName.getLocalName()); @@ -430,10 +459,76 @@ public class ModuleBuilder implements Builder { return builder; } - public TypedefBuilder addTypedef(QName typeDefName, List parentPath) { + public ChoiceBuilder addChoice(final QName choiceName, + final List parentPath) { + List pathToChoice = new ArrayList(parentPath); + ChoiceBuilder builder = new ChoiceBuilder(choiceName); + + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToChoice); + if (parent != null) { + if (parent instanceof AugmentationSchemaBuilder) { + builder.setAugmenting(true); + } + parent.addChildNode(builder); + } + + pathToChoice.add(choiceName.getLocalName()); + addedChilds.put(pathToChoice, builder); + moduleNodes.put(pathToChoice, builder); + + return builder; + } + + public ChoiceCaseBuilder addCase(final QName caseName, + final List parentPath) { + List pathToCase = new ArrayList(parentPath); + ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName); + + final ChoiceBuilder parent = (ChoiceBuilder) moduleNodes + .get(pathToCase); + if (parent != null) { + if (parent instanceof AugmentationSchemaBuilder) { + builder.setAugmenting(true); + } + parent.addChildNode(builder); + } + + pathToCase.add(caseName.getLocalName()); + addedChilds.put(pathToCase, builder); + moduleNodes.put(pathToCase, builder); + + return builder; + } + + public AnyXmlBuilder addAnyXml(final QName anyXmlName, + final List parentPath) { + List pathToAnyXml = new ArrayList(parentPath); + AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName); + + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToAnyXml); + if (parent != null) { + if (parent instanceof AugmentationSchemaBuilder) { + throw new UnsupportedOperationException( + "An anyxml node cannot be augmented."); + } + parent.addChildNode(builder); + } + + pathToAnyXml.add(anyXmlName.getLocalName()); + addedChilds.put(pathToAnyXml, builder); + moduleNodes.put(pathToAnyXml, builder); + + return builder; + } + + public TypedefBuilder addTypedef(final QName typeDefName, + final List parentPath) { List pathToType = new ArrayList(parentPath); TypedefBuilder builder = new TypedefBuilder(typeDefName); - TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes.get(pathToType); + TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes + .get(pathToType); if (parent != null) { parent.addTypedef(builder); } @@ -443,26 +538,20 @@ public class ModuleBuilder implements Builder { return builder; } - public Set getModuleTypedefs() { - Set typedefs = new HashSet(); - for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) { - if (entry.getKey().size() == 2) { - typedefs.add(entry.getValue()); - } - } - return typedefs; - } - public void setType(TypeDefinition type, List parentPath) { - TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath); - if(parent == null) { - throw new YangParseException("Failed to set type '"+ type.getQName().getLocalName() +"'. Parent node not found."); + TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes + .get(parentPath); + if (parent == null) { + throw new YangParseException("Failed to set type '" + + type.getQName().getLocalName() + + "'. Parent node not found."); } parent.setType(type); } public void addUnionType(List parentPath) { - TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath); + TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes + .get(parentPath); UnionTypeBuilder union = new UnionTypeBuilder(); parent.setType(union); @@ -472,9 +561,13 @@ public class ModuleBuilder implements Builder { moduleNodes.put(path, union); } - public DeviationBuilder addDeviation(String targetPath) { + public DeviationBuilder addDeviation(String targetPath, + List parentPath) { + final List pathToDeviation = new ArrayList(parentPath); + pathToDeviation.add(targetPath); DeviationBuilder builder = new DeviationBuilder(targetPath); addedDeviations.put(targetPath, builder); + moduleNodes.put(pathToDeviation, builder); return builder; } @@ -486,20 +579,29 @@ public class ModuleBuilder implements Builder { public void addConfiguration(boolean configuration, List parentPath) { Builder builder = moduleNodes.get(parentPath); - if (builder instanceof DeviationBuilder) { - // skip - // TODO - } else { - DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes.get(parentPath); + // current api did not support adding config to deviate + if (!(builder instanceof DeviationBuilder)) { + DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes + .get(parentPath); configBuilder.setConfiguration(configuration); } } - public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname, List parentPath) { + public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname, + List parentPath) { + final List pathToUnknown = new ArrayList(parentPath); + final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder( + qname); + + final SchemaNodeBuilder parent = (SchemaNodeBuilder) moduleNodes + .get(pathToUnknown); + if (parent != null) { + parent.addUnknownSchemaNode(builder); + } + return new UnknownSchemaNodeBuilder(qname); } - private class ModuleImpl implements Module { private URI namespace; private final String name; @@ -513,14 +615,16 @@ public class ModuleBuilder implements Builder { private Set imports = Collections.emptySet(); private Set features = Collections.emptySet(); private Set> typeDefinitions = Collections.emptySet(); - private Set notifications = Collections.emptySet(); + private Set notifications = Collections + .emptySet(); private Set augmentations = Collections.emptySet(); private Set rpcs = Collections.emptySet(); private Set deviations = Collections.emptySet(); private Map childNodes = Collections.emptyMap(); private Set groupings = Collections.emptySet(); private Set uses = Collections.emptySet(); - private List extensionNodes = Collections.emptyList(); + private List extensionNodes = Collections + .emptyList(); private Set identities = Collections.emptySet(); private ModuleImpl(String name) { @@ -610,7 +714,7 @@ public class ModuleBuilder implements Builder { } private void setImports(Set imports) { - if(imports != null) { + if (imports != null) { this.imports = imports; } } @@ -621,7 +725,7 @@ public class ModuleBuilder implements Builder { } private void setFeatures(Set features) { - if(features != null) { + if (features != null) { this.features = features; } } @@ -632,7 +736,7 @@ public class ModuleBuilder implements Builder { } private void setTypeDefinitions(Set> typeDefinitions) { - if(typeDefinitions != null) { + if (typeDefinitions != null) { this.typeDefinitions = typeDefinitions; } } @@ -643,7 +747,7 @@ public class ModuleBuilder implements Builder { } private void setNotifications(Set notifications) { - if(notifications != null) { + if (notifications != null) { this.notifications = notifications; } } @@ -654,7 +758,7 @@ public class ModuleBuilder implements Builder { } private void setAugmentations(Set augmentations) { - if(augmentations != null) { + if (augmentations != null) { this.augmentations = augmentations; } } @@ -665,7 +769,7 @@ public class ModuleBuilder implements Builder { } private void setRpcs(Set rpcs) { - if(rpcs != null) { + if (rpcs != null) { this.rpcs = rpcs; } } @@ -676,7 +780,7 @@ public class ModuleBuilder implements Builder { } private void setDeviations(Set deviations) { - if(deviations != null) { + if (deviations != null) { this.deviations = deviations; } } @@ -687,7 +791,7 @@ public class ModuleBuilder implements Builder { } private void setChildNodes(Map childNodes) { - if(childNodes != null) { + if (childNodes != null) { this.childNodes = childNodes; } } @@ -698,7 +802,7 @@ public class ModuleBuilder implements Builder { } private void setGroupings(Set groupings) { - if(groupings != null) { + if (groupings != null) { this.groupings = groupings; } } @@ -709,7 +813,7 @@ public class ModuleBuilder implements Builder { } private void setUses(Set uses) { - if(uses != null) { + if (uses != null) { this.uses = uses; } } @@ -719,9 +823,10 @@ public class ModuleBuilder implements Builder { return extensionNodes; } - private void setExtensionSchemaNodes(List extensionSchemaNodes) { - if(extensionSchemaNodes != null) { - this.extensionNodes = extensionSchemaNodes; + private void setExtensionSchemaNodes( + List extensionNodes) { + if (extensionNodes != null) { + this.extensionNodes = extensionNodes; } } @@ -731,7 +836,7 @@ public class ModuleBuilder implements Builder { } private void setIdentities(Set identities) { - if(identities != null) { + if (identities != null) { this.identities = identities; } } @@ -757,11 +862,15 @@ public class ModuleBuilder implements Builder { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((namespace == null) ? 0 : namespace.hashCode()); + result = prime * result + + ((namespace == null) ? 0 : namespace.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((revision == null) ? 0 : revision.hashCode()); - result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); - result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode()); + result = prime * result + + ((revision == null) ? 0 : revision.hashCode()); + result = prime * result + + ((prefix == null) ? 0 : prefix.hashCode()); + result = prime * result + + ((yangVersion == null) ? 0 : yangVersion.hashCode()); return result; } @@ -931,7 +1040,8 @@ public class ModuleBuilder implements Builder { private Map buildModuleChildNodes( Map, DataSchemaNodeBuilder> addedChilds) { final Map childNodes = new HashMap(); - for (Map.Entry, DataSchemaNodeBuilder> entry : addedChilds.entrySet()) { + for (Map.Entry, DataSchemaNodeBuilder> entry : addedChilds + .entrySet()) { List path = entry.getKey(); DataSchemaNodeBuilder child = entry.getValue(); if (path.size() == 2) { @@ -993,11 +1103,13 @@ public class ModuleBuilder implements Builder { private Set> buildModuleTypedefs( Map, TypeDefinitionBuilder> addedTypedefs) { Set> typedefs = new HashSet>(); - for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) { + for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs + .entrySet()) { List key = entry.getKey(); TypeDefinitionBuilder typedefBuilder = entry.getValue(); if (key.size() == 2) { - TypeDefinition> node = typedefBuilder.build(); + TypeDefinition> node = typedefBuilder + .build(); typedefs.add(node); } } @@ -1014,14 +1126,14 @@ public class ModuleBuilder implements Builder { */ private Set buildUsesNodes( Map, UsesNodeBuilder> addedUsesNodes) { - final Set usesNodeDefinitions = new HashSet(); + final Set usesNodeDefs = new HashSet(); for (Map.Entry, UsesNodeBuilder> entry : addedUsesNodes .entrySet()) { if (entry.getKey().size() == 2) { - usesNodeDefinitions.add(entry.getValue().build()); + usesNodeDefs.add(entry.getValue().build()); } } - return usesNodeDefinitions; + return usesNodeDefs; } /** diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java index d2010c6578..3931b80ae9 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java @@ -37,6 +37,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements TypeDefinitionAwareBuilder, SchemaNodeBuilder { private final NotificationDefinitionImpl instance; + private SchemaPath schemaPath; private final Set addedTypedefs = new HashSet(); private final Set addedUsesNodes = new HashSet(); private final List addedUnknownNodes = new ArrayList(); @@ -48,29 +49,31 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements @Override public SchemaNode build() { + instance.setPath(schemaPath); + // CHILD NODES - Map childs = new HashMap(); + final Map childs = new HashMap(); for (DataSchemaNodeBuilder node : childNodes) { childs.put(node.getQName(), node.build()); } instance.setChildNodes(childs); // GROUPINGS - Set groupingDefinitions = new HashSet(); + final Set groupingDefs = new HashSet(); for (GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); + groupingDefs.add(builder.build()); } - instance.setGroupings(groupingDefinitions); + instance.setGroupings(groupingDefs); // TYPEDEFS - Set> typedefs = new HashSet>(); + final Set> typedefs = new HashSet>(); for (TypeDefinitionBuilder entry : addedTypedefs) { typedefs.add(entry.build()); } instance.setTypeDefinitions(typedefs); // USES - Set uses = new HashSet(); + final Set uses = new HashSet(); for (UsesNodeBuilder builder : addedUsesNodes) { uses.add(builder.build()); } @@ -78,7 +81,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements // UNKNOWN NODES final List unknownNodes = new ArrayList(); - for(UnknownSchemaNodeBuilder b : addedUnknownNodes) { + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { unknownNodes.add(b.build()); } instance.setUnknownSchemaNodes(unknownNodes); @@ -87,54 +90,58 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements } @Override - public void addTypedef(TypeDefinitionBuilder type) { + public void addTypedef(final TypeDefinitionBuilder type) { addedTypedefs.add(type); } @Override - public void addUsesNode(UsesNodeBuilder usesNodeBuilder) { + public void addUsesNode(final UsesNodeBuilder usesNodeBuilder) { addedUsesNodes.add(usesNodeBuilder); } + @Override + public SchemaPath getPath() { + return schemaPath; + } + @Override public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); + this.schemaPath = schemaPath; } @Override - public void setDescription(String description) { + public void setDescription(final String description) { instance.setDescription(description); } @Override - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } @Override - public void setStatus(Status status) { + public void setStatus(final Status status) { instance.setStatus(status); } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } private class NotificationDefinitionImpl implements NotificationDefinition { - private final QName qname; private SchemaPath path; private String description; private String reference; - private Status status; + private Status status = Status.CURRENT; private Map childNodes = Collections.emptyMap(); private Set groupings = Collections.emptySet(); private Set> typeDefinitions = Collections.emptySet(); private Set uses = Collections.emptySet(); - private List unknownSchemaNodes = Collections.emptyList(); + private List unknownNodes = Collections.emptyList(); - private NotificationDefinitionImpl(QName qname) { + private NotificationDefinitionImpl(final QName qname) { this.qname = qname; } @@ -148,7 +155,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements return path; } - private void setPath(SchemaPath path) { + private void setPath(final SchemaPath path) { this.path = path; } @@ -157,7 +164,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements return description; } - private void setDescription(String description) { + private void setDescription(final String description) { this.description = description; } @@ -176,7 +183,9 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements } private void setStatus(Status status) { - this.status = status; + if (status != null) { + this.status = status; + } } @Override @@ -185,7 +194,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements } private void setChildNodes(Map childNodes) { - if(childNodes != null) { + if (childNodes != null) { this.childNodes = childNodes; } } @@ -196,7 +205,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements } private void setGroupings(Set groupings) { - if(groupings != null) { + if (groupings != null) { this.groupings = groupings; } } @@ -207,7 +216,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements } private void setUses(Set uses) { - if(uses != null) { + if (uses != null) { this.uses = uses; } } @@ -217,20 +226,22 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements return typeDefinitions; } - private void setTypeDefinitions(Set> typeDefinitions) { - if(typeDefinitions != null) { + private void setTypeDefinitions( + final Set> typeDefinitions) { + if (typeDefinitions != null) { this.typeDefinitions = typeDefinitions; } } @Override public List getUnknownSchemaNodes() { - return unknownSchemaNodes; + return unknownNodes; } - private void setUnknownSchemaNodes(List unknownSchemaNodes) { - if(unknownSchemaNodes != null) { - this.unknownSchemaNodes = unknownSchemaNodes; + private void setUnknownSchemaNodes( + final List unknownNodes) { + if (unknownNodes != null) { + this.unknownNodes = unknownNodes; } } @@ -271,7 +282,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements if (getClass() != obj.getClass()) { return false; } - NotificationDefinitionImpl other = (NotificationDefinitionImpl) obj; + final NotificationDefinitionImpl other = (NotificationDefinitionImpl) obj; if (qname == null) { if (other.qname != null) { return false; @@ -293,7 +304,7 @@ public class NotificationBuilder extends AbstractChildNodeBuilder implements public String toString() { StringBuilder sb = new StringBuilder( NotificationDefinitionImpl.class.getSimpleName()); - sb.append("[qname=" + qname + ", path="+ path +"]"); + sb.append("[qname=" + qname + ", path=" + path + "]"); return sb.toString(); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/RpcDefinitionBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/RpcDefinitionBuilder.java index 28ee66751e..83ae031288 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/RpcDefinitionBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/RpcDefinitionBuilder.java @@ -31,16 +31,16 @@ import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder public class RpcDefinitionBuilder implements ChildNodeBuilder, SchemaNodeBuilder, TypeDefinitionAwareBuilder { - private final RpcDefinitionImpl instance; private final QName qname; + private SchemaPath schemaPath; private ContainerSchemaNodeBuilder inputBuilder; private ContainerSchemaNodeBuilder outputBuilder; private final Set addedTypedefs = new HashSet(); private final Set addedGroupings = new HashSet(); private final List addedUnknownNodes = new ArrayList(); - RpcDefinitionBuilder(QName qname) { + RpcDefinitionBuilder(final QName qname) { this.qname = qname; this.instance = new RpcDefinitionImpl(qname); } @@ -52,8 +52,10 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, instance.setInput(input); instance.setOutput(output); + instance.setPath(schemaPath); + // TYPEDEFS - Set> typedefs = new HashSet>(); + final Set> typedefs = new HashSet>(); for (TypeDefinitionBuilder entry : addedTypedefs) { typedefs.add(entry.build()); } @@ -68,7 +70,7 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, // UNKNOWN NODES final List unknownNodes = new ArrayList(); - for(UnknownSchemaNodeBuilder b : addedUnknownNodes) { + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { unknownNodes.add(b.build()); } instance.setUnknownSchemaNodes(unknownNodes); @@ -76,36 +78,41 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, return instance; } - void setInput(ContainerSchemaNodeBuilder inputBuilder) { + void setInput(final ContainerSchemaNodeBuilder inputBuilder) { this.inputBuilder = inputBuilder; } - void setOutput(ContainerSchemaNodeBuilder outputBuilder) { + void setOutput(final ContainerSchemaNodeBuilder outputBuilder) { this.outputBuilder = outputBuilder; } @Override - public void addTypedef(TypeDefinitionBuilder type) { + public void addTypedef(final TypeDefinitionBuilder type) { addedTypedefs.add(type); } + @Override + public SchemaPath getPath() { + return schemaPath; + } + @Override public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); + this.schemaPath = schemaPath; } @Override - public void setDescription(String description) { + public void setDescription(final String description) { instance.setDescription(description); } @Override - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } @Override - public void setStatus(Status status) { + public void setStatus(final Status status) { instance.setStatus(status); } @@ -115,25 +122,25 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, } @Override - public void addChildNode(DataSchemaNodeBuilder childNode) { + public void addChildNode(final DataSchemaNodeBuilder childNode) { throw new UnsupportedOperationException( "Can not add child node to rpc definition: rpc can not contains child nodes."); } @Override - public void addGrouping(GroupingBuilder grouping) { + public void addGrouping(final GroupingBuilder grouping) { addedGroupings.add(grouping); } @Override - public void addUsesNode(UsesNodeBuilder usesBuilder) { + public void addUsesNode(final UsesNodeBuilder usesBuilder) { throw new UnsupportedOperationException( "Can not add uses node to rpc definition: rpc can not contains uses nodes."); } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } @Override @@ -149,7 +156,7 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, if (!(obj instanceof RpcDefinitionBuilder)) { return false; } - RpcDefinitionBuilder other = (RpcDefinitionBuilder) obj; + final RpcDefinitionBuilder other = (RpcDefinitionBuilder) obj; if (other.qname == null) { if (this.qname != null) { return false; @@ -171,9 +178,9 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, private ContainerSchemaNode output; private Set> typeDefinitions; private Set groupings; - private List unknownSchemaNodes = Collections.emptyList(); + private List unknownNodes = Collections.emptyList(); - private RpcDefinitionImpl(QName qname) { + private RpcDefinitionImpl(final QName qname) { this.qname = qname; } @@ -256,12 +263,12 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, @Override public List getUnknownSchemaNodes() { - return unknownSchemaNodes; + return unknownNodes; } - private void setUnknownSchemaNodes(List unknownSchemaNodes) { - if(unknownSchemaNodes != null) { - this.unknownSchemaNodes = unknownSchemaNodes; + private void setUnknownSchemaNodes(List unknownNodes) { + if (unknownNodes != null) { + this.unknownNodes = unknownNodes; } } @@ -284,7 +291,7 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, if (getClass() != obj.getClass()) { return false; } - RpcDefinitionImpl other = (RpcDefinitionImpl) obj; + final RpcDefinitionImpl other = (RpcDefinitionImpl) obj; if (qname == null) { if (other.qname != null) { return false; @@ -301,9 +308,6 @@ public class RpcDefinitionBuilder implements ChildNodeBuilder, RpcDefinitionImpl.class.getSimpleName() + "["); sb.append("qname=" + qname); sb.append(", path=" + path); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); sb.append(", input=" + input); sb.append(", output=" + output + "]"); return sb.toString(); diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java index 64df8c265a..e4b1be5d75 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java @@ -38,11 +38,11 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements private String description; private String reference; - private Status status; + private Status status = Status.CURRENT; private String units; private Object defaultValue; - public TypedefBuilder(QName qname) { + public TypedefBuilder(final QName qname) { this.qname = qname; } @@ -55,12 +55,12 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements + qname.getLocalName() + "'."); } if (type == null || type instanceof UnknownType) { - typeBuilder = new ExtendedType.Builder(qname, typedef.build(), - description, reference); - } else { - typeBuilder = new ExtendedType.Builder(qname, type, description, - reference); + type = typedef.build(); } + + typeBuilder = new ExtendedType.Builder(qname, type, description, + reference); + typeBuilder.status(status); typeBuilder.units(units); typeBuilder.defaultValue(defaultValue); @@ -68,6 +68,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements typeBuilder.ranges(ranges); typeBuilder.lengths(lengths); typeBuilder.patterns(patterns); + typeBuilder.fractionDigits(fractionDigits); // UNKNOWN NODES final List unknownNodes = new ArrayList(); @@ -132,7 +133,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements } @Override - public void setUnits(String units) { + public void setUnits(final String units) { this.units = units; } @@ -142,7 +143,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements } @Override - public void setDefaultValue(Object defaultValue) { + public void setDefaultValue(final Object defaultValue) { this.defaultValue = defaultValue; } @@ -152,7 +153,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) { + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { addedUnknownNodes.add(unknownNode); } @@ -162,7 +163,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements } @Override - public void setRanges(List ranges) { + public void setRanges(final List ranges) { if (ranges != null) { this.ranges = ranges; } @@ -174,7 +175,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements } @Override - public void setLengths(List lengths) { + public void setLengths(final List lengths) { if (lengths != null) { this.lengths = lengths; } @@ -186,7 +187,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements } @Override - public void setPatterns(List patterns) { + public void setPatterns(final List patterns) { if (patterns != null) { this.patterns = patterns; } @@ -198,21 +199,22 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements } @Override - public void setFractionDigits(Integer fractionDigits) { + public void setFractionDigits(final Integer fractionDigits) { this.fractionDigits = fractionDigits; } @Override public String toString() { - String result = "TypedefBuilder[" + qname.getLocalName(); - result += ", type="; + final StringBuilder result = new StringBuilder("TypedefBuilder[" + + qname.getLocalName()); + result.append(", type="); if (type == null) { - result += typedef; + result.append(typedef); } else { - result += type; + result.append(type); } - result += "]"; - return result; + result.append("]"); + return result.toString(); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java index 697fb399b0..50a7a3a1f0 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java @@ -26,8 +26,8 @@ import org.opendaylight.controller.yang.model.util.UnionType; /** * Builder for YANG union type. User can add type to this union as * TypeDefinition object (resolved type) or in form of TypeDefinitionBuilder. - * When build is called, types in builder form will be transformed to - * TypeDefinition objects and add to resolved types. + * When build is called, types in builder form will be built and add to resolved + * types. */ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder, Builder { @@ -60,12 +60,12 @@ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements } @Override - public void setType(TypeDefinition type) { + public void setType(final TypeDefinition type) { types.add(type); } @Override - public void setType(TypeDefinitionBuilder tdb) { + public void setType(final TypeDefinitionBuilder tdb) { typedefs.add(tdb); } @@ -78,140 +78,139 @@ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements } @Override - public void setPath(SchemaPath schemaPath) { - // TODO Auto-generated method stub + public void setPath(final SchemaPath schemaPath) { + throw new IllegalStateException("Can not set path to " + + UnionTypeBuilder.class.getSimpleName()); } @Override - public void setDescription(String description) { - // TODO Auto-generated method stub + public void setDescription(final String description) { + throw new IllegalStateException("Can not set description to " + + UnionTypeBuilder.class.getSimpleName()); } @Override - public void setReference(String reference) { - // TODO Auto-generated method stub + public void setReference(final String reference) { + throw new IllegalStateException("Can not set reference to " + + UnionTypeBuilder.class.getSimpleName()); } @Override - public void setStatus(Status status) { - // TODO Auto-generated method stub + public void setStatus(final Status status) { + throw new IllegalStateException("Can not set status to " + + UnionTypeBuilder.class.getSimpleName()); } @Override - public void addUnknownSchemaNode( - UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - // TODO Auto-generated method stub + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + throw new IllegalStateException("Can not add unknown node to " + + UnionTypeBuilder.class.getSimpleName()); } @Override public QName getQName() { - // TODO Auto-generated method stub return null; } @Override public SchemaPath getPath() { - // TODO Auto-generated method stub return null; } @Override public String getDescription() { - // TODO Auto-generated method stub return null; } @Override public String getReference() { - // TODO Auto-generated method stub return null; } @Override public Status getStatus() { - // TODO Auto-generated method stub return null; } @Override public List getRanges() { - // TODO Auto-generated method stub - return null; + return Collections.emptyList(); } @Override public void setRanges(List ranges) { - // TODO Auto-generated method stub + throw new IllegalStateException("Can not set ranges to " + + UnionTypeBuilder.class.getSimpleName()); } @Override public List getLengths() { - // TODO Auto-generated method stub - return null; + return Collections.emptyList(); } @Override public void setLengths(List lengths) { - // TODO Auto-generated method stub + throw new IllegalStateException("Can not set lengths to " + + UnionTypeBuilder.class.getSimpleName()); } @Override public List getPatterns() { - // TODO Auto-generated method stub - return null; + return Collections.emptyList(); } @Override public void setPatterns(List patterns) { - // TODO Auto-generated method stub + throw new IllegalStateException("Can not set patterns to " + + UnionTypeBuilder.class.getSimpleName()); } @Override public Integer getFractionDigits() { - // TODO Auto-generated method stub return null; } @Override public void setFractionDigits(Integer fractionDigits) { - // TODO Auto-generated method stub + throw new IllegalStateException("Can not set fraction digits to " + + UnionTypeBuilder.class.getSimpleName()); } @Override public List getUnknownNodes() { - // TODO Auto-generated method stub - return null; + return Collections.emptyList(); } @Override public Object getDefaultValue() { - // TODO Auto-generated method stub return null; } @Override public void setDefaultValue(Object defaultValue) { - // TODO Auto-generated method stub + throw new IllegalStateException("Can not set default value to " + + UnionTypeBuilder.class.getSimpleName()); } @Override public String getUnits() { - // TODO Auto-generated method stub return null; } @Override public void setUnits(String units) { - // TODO Auto-generated method stub + throw new IllegalStateException("Can not set units to " + + UnionTypeBuilder.class.getSimpleName()); } @Override public String toString() { - String result = "UnionTypeBuilder["; - result += ", types=" + types; - result += ", typedefs=" + typedefs; - result += "]"; - return result; + final StringBuilder result = new StringBuilder( + UnionTypeBuilder.class.getSimpleName() + "["); + result.append(", types=" + types); + result.append(", typedefs=" + typedefs); + result.append("]"); + return result.toString(); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java index 91c6ed197e..ddbc927e51 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java @@ -20,6 +20,7 @@ import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuild public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { private final QName qname; + private SchemaPath schemaPath; private final UnknownSchemaNodeImpl instance; private final List addedUnknownNodes = new ArrayList(); @@ -28,12 +29,13 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { instance = new UnknownSchemaNodeImpl(qname); } - @Override public UnknownSchemaNode build() { + instance.setPath(schemaPath); + // UNKNOWN NODES final List unknownNodes = new ArrayList(); - for(UnknownSchemaNodeBuilder b : addedUnknownNodes) { + for (UnknownSchemaNodeBuilder b : addedUnknownNodes) { unknownNodes.add(b.build()); } instance.setUnknownSchemaNodes(unknownNodes); @@ -45,29 +47,34 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { return qname; } + @Override + public SchemaPath getPath() { + return schemaPath; + } + @Override public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); + this.schemaPath = schemaPath; } @Override - public void setDescription(String description) { + public void setDescription(final String description) { instance.setDescription(description); } @Override - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } @Override - public void setStatus(Status status) { + public void setStatus(final Status status) { instance.setStatus(status); } @Override - public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) { - addedUnknownNodes.add(unknownSchemaNodeBuilder); + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); } private static class UnknownSchemaNodeImpl implements UnknownSchemaNode { @@ -76,9 +83,9 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { private String description; private String reference; private Status status = Status.CURRENT; - private List unknownSchemaNodes = Collections.emptyList(); + private List unknownNodes = Collections.emptyList(); - private UnknownSchemaNodeImpl(QName qname) { + private UnknownSchemaNodeImpl(final QName qname) { this.qname = qname; } @@ -91,7 +98,8 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { public SchemaPath getPath() { return path; } - private void setPath(SchemaPath path) { + + private void setPath(final SchemaPath path) { this.path = path; } @@ -100,7 +108,7 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { return description; } - private void setDescription(String description) { + private void setDescription(final String description) { this.description = description; } @@ -109,7 +117,7 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { return reference; } - private void setReference(String reference) { + private void setReference(final String reference) { this.reference = reference; } @@ -118,20 +126,21 @@ public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { return status; } - private void setStatus(Status status) { - if(status != null) { + private void setStatus(final Status status) { + if (status != null) { this.status = status; } } @Override public List getUnknownSchemaNodes() { - return unknownSchemaNodes; + return unknownNodes; } - private void setUnknownSchemaNodes(List unknownSchemaNodes) { - if(unknownSchemaNodes != null) { - this.unknownSchemaNodes = unknownSchemaNodes; + private void setUnknownSchemaNodes( + final List unknownNodes) { + if (unknownNodes != null) { + this.unknownNodes = unknownNodes; } } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java index 9490e7f0a4..5fb4c99ff6 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.yang.model.parser.builder.impl; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -21,15 +22,20 @@ import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.UsesNode; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.Builder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.controller.yang.model.parser.util.RefineHolder; public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { private final UsesNodeImpl instance; + private final SchemaPath groupingPath; private final Set addedAugments = new HashSet(); + private List refineBuilders = new ArrayList(); + private List refines = Collections.emptyList(); - UsesNodeBuilderImpl(String groupingPathStr) { - SchemaPath groupingPath = parseUsesPath(groupingPathStr); + UsesNodeBuilderImpl(final String groupingPathStr) { + this.groupingPath = parseUsesPath(groupingPathStr); instance = new UsesNodeImpl(groupingPath); } @@ -42,25 +48,54 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { } instance.setAugmentations(augments); + // REFINES + final Map refineNodes = new HashMap(); + for(SchemaNodeBuilder refineBuilder : refineBuilders) { + SchemaNode refineNode = refineBuilder.build(); + refineNodes.put(refineNode.getPath(), refineNode); + } + instance.setRefines(refineNodes); + return instance; } @Override - public void addAugment(AugmentationSchemaBuilder augmentBuilder) { + public SchemaPath getGroupingPath() { + return groupingPath; + } + + @Override + public void addAugment(final AugmentationSchemaBuilder augmentBuilder) { addedAugments.add(augmentBuilder); } @Override - public void setAugmenting(boolean augmenting) { + public void setAugmenting(final boolean augmenting) { instance.setAugmenting(augmenting); } - private SchemaPath parseUsesPath(String augmentPath) { - String[] splittedPath = augmentPath.split("/"); - List path = new ArrayList(); + @Override + public void addRefineNode(SchemaNodeBuilder refineNode) { + refineBuilders.add(refineNode); + } + + public List getRefines() { + return refines; + } + + @Override + public void setRefines(List refines) { + if(refines != null) { + this.refines = refines; + } + } + + private SchemaPath parseUsesPath(final String augmentPath) { + final String[] splittedPath = augmentPath.split("/"); + final List path = new ArrayList(); QName name; for (String pathElement : splittedPath) { - String[] splittedElement = pathElement.split(":"); + final String[] splittedElement = pathElement.split(":"); if (splittedElement.length == 1) { name = new QName(null, null, null, splittedElement[0]); } else { @@ -74,12 +109,12 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { } private static class UsesNodeImpl implements UsesNode { - private final SchemaPath groupingPath; private Set augmentations = Collections.emptySet(); private boolean augmenting; + private Map refines = Collections.emptyMap(); - private UsesNodeImpl(SchemaPath groupingPath) { + private UsesNodeImpl(final SchemaPath groupingPath) { this.groupingPath = groupingPath; } @@ -93,7 +128,7 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { return augmentations; } - private void setAugmentations(Set augmentations) { + private void setAugmentations(final Set augmentations) { if (augmentations != null) { this.augmentations = augmentations; } @@ -103,24 +138,30 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { public boolean isAugmenting() { return augmenting; } - - private void setAugmenting(boolean augmenting) { + + private void setAugmenting(final boolean augmenting) { this.augmenting = augmenting; } - @Override public Map getRefines() { - // TODO Auto-generated method stub - return null; + return refines; } - + + private void setRefines(Map refines) { + if(refines != null) { + this.refines = refines; + } + } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode()); - result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode()); + result = prime * result + + ((groupingPath == null) ? 0 : groupingPath.hashCode()); + result = prime * result + + ((augmentations == null) ? 0 : augmentations.hashCode()); result = prime * result + (augmenting ? 1231 : 1237); return result; } @@ -136,7 +177,7 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { if (getClass() != obj.getClass()) { return false; } - UsesNodeImpl other = (UsesNodeImpl) obj; + final UsesNodeImpl other = (UsesNodeImpl) obj; if (groupingPath == null) { if (other.groupingPath != null) { return false; @@ -161,7 +202,7 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { public String toString() { StringBuilder sb = new StringBuilder( UsesNodeImpl.class.getSimpleName()); - sb.append("[groupingPath=" + groupingPath +"]"); + sb.append("[groupingPath=" + groupingPath + "]"); return sb.toString(); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java index acde37953b..946bfb4296 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java @@ -14,7 +14,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.ArrayList; -import java.util.Calendar; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -30,11 +30,11 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker; import org.opendaylight.controller.antlrv4.code.gen.YangLexer; import org.opendaylight.controller.antlrv4.code.gen.YangParser; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; import org.opendaylight.controller.yang.model.api.DataSchemaNode; import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.Module; import org.opendaylight.controller.yang.model.api.ModuleImport; +import org.opendaylight.controller.yang.model.api.MustDefinition; import org.opendaylight.controller.yang.model.api.NotificationDefinition; import org.opendaylight.controller.yang.model.api.RpcDefinition; import org.opendaylight.controller.yang.model.api.SchemaContext; @@ -50,14 +50,26 @@ import org.opendaylight.controller.yang.model.api.type.StringTypeDefinition; import org.opendaylight.controller.yang.model.parser.api.YangModelParser; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.Builder; import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.AnyXmlBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ContainerSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.IdentitySchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.LeafListSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.LeafSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ListSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.TypedefBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.UnionTypeBuilder; +import org.opendaylight.controller.yang.model.parser.util.ParserUtils; +import org.opendaylight.controller.yang.model.parser.util.RefineHolder; +import org.opendaylight.controller.yang.model.parser.util.RefineHolder.Refine; import org.opendaylight.controller.yang.model.parser.util.TypeConstraints; import org.opendaylight.controller.yang.model.parser.util.YangParseException; import org.opendaylight.controller.yang.model.util.ExtendedType; @@ -72,21 +84,21 @@ public class YangModelParserImpl implements YangModelParser { @Override public Module parseYangModel(final String yangFile) { - final Map> modules = resolveModuleBuildersFromStreams(yangFile); + final Map> modules = resolveModuleBuilders(yangFile); final Set result = build(modules); return result.iterator().next(); } @Override public Set parseYangModels(final String... yangFiles) { - final Map> modules = resolveModuleBuildersFromStreams(yangFiles); + final Map> modules = resolveModuleBuilders(yangFiles); return build(modules); } @Override public Set parseYangModelsFromStreams( final InputStream... yangModelStreams) { - final Map> modules = resolveModuleBuildersFromStreams(yangModelStreams); + final Map> modules = resolveModuleBuilders(yangModelStreams); return build(modules); } @@ -95,19 +107,17 @@ public class YangModelParserImpl implements YangModelParser { return new SchemaContextImpl(modules); } - private Map> resolveModuleBuildersFromStreams( - String... yangFiles) { + private Map> resolveModuleBuilders( + final String... yangFiles) { final InputStream[] streams = loadStreams(yangFiles); + Map> result = Collections + .emptyMap(); if (streams != null) { - final Map> result = resolveModuleBuildersFromStreams(streams); - cloaseStreams(streams); - - if (result != null) { - return result; - } + result = resolveModuleBuilders(streams); + closeStreams(streams); } - return new HashMap>(); + return result; } private InputStream[] loadStreams(final String... yangFiles) { @@ -125,9 +135,9 @@ public class YangModelParserImpl implements YangModelParser { return streams; } - private void cloaseStreams(final InputStream[] streams) { + private void closeStreams(final InputStream[] streams) { if (streams != null) { - for (int i = 0; i < streams.length; ++i) { + for (int i = 0; i < streams.length; i++) { try { if (streams[i] != null) { streams[i].close(); @@ -140,8 +150,8 @@ public class YangModelParserImpl implements YangModelParser { } } - private Map> resolveModuleBuildersFromStreams( - InputStream... yangFiles) { + private Map> resolveModuleBuilders( + final InputStream... yangFiles) { final Map> modules = new HashMap>(); final ParseTreeWalker walker = new ParseTreeWalker(); final List trees = parseStreams(yangFiles); @@ -173,7 +183,7 @@ public class YangModelParserImpl implements YangModelParser { final String builderName = builder.getName(); Date builderRevision = builder.getRevision(); if (builderRevision == null) { - builderRevision = createEpochTime(); + builderRevision = new Date(0L); } TreeMap builderByRevision = modules .get(builderName); @@ -186,7 +196,7 @@ public class YangModelParserImpl implements YangModelParser { return modules; } - private List parseStreams(InputStream... yangStreams) { + private List parseStreams(final InputStream... yangStreams) { final List trees = new ArrayList(); for (InputStream yangStream : yangStreams) { trees.add(parseStream(yangStream)); @@ -194,7 +204,7 @@ public class YangModelParserImpl implements YangModelParser { return trees; } - private ParseTree parseStream(InputStream yangStream) { + private ParseTree parseStream(final InputStream yangStream) { ParseTree result = null; try { final ANTLRInputStream input = new ANTLRInputStream(yangStream); @@ -208,13 +218,13 @@ public class YangModelParserImpl implements YangModelParser { return result; } - private Set build(Map> modules) { + private Set build(final Map> modules) { // validate for (Map.Entry> entry : modules .entrySet()) { for (Map.Entry childEntry : entry.getValue() .entrySet()) { - ModuleBuilder moduleBuilder = childEntry.getValue(); + final ModuleBuilder moduleBuilder = childEntry.getValue(); validateModule(modules, moduleBuilder); } } @@ -226,8 +236,8 @@ public class YangModelParserImpl implements YangModelParser { final Map modulesByRevision = new HashMap(); for (Map.Entry childEntry : entry.getValue() .entrySet()) { - ModuleBuilder moduleBuilder = childEntry.getValue(); - Module module = moduleBuilder.build(); + final ModuleBuilder moduleBuilder = childEntry.getValue(); + final Module module = moduleBuilder.build(); modulesByRevision.put(childEntry.getKey(), module); result.add(module); } @@ -241,12 +251,13 @@ public class YangModelParserImpl implements YangModelParser { resolveDirtyNodes(modules, builder); resolveAugments(modules, builder); resolveIdentities(modules, builder); + resolveUses(modules, builder); } /** * Search for dirty nodes (node which contains UnknownType) and resolve * unknown types. - * + * * @param modules * all available modules * @param module @@ -261,38 +272,38 @@ public class YangModelParserImpl implements YangModelParser { for (Map.Entry, TypeAwareBuilder> entry : dirtyNodes .entrySet()) { - TypeAwareBuilder typeToResolve = entry.getValue(); - if (typeToResolve instanceof UnionTypeBuilder) { - UnionTypeBuilder union = (UnionTypeBuilder) typeToResolve; + final TypeAwareBuilder nodeToResolve = entry.getValue(); + // different handling for union types + if (nodeToResolve instanceof UnionTypeBuilder) { + final UnionTypeBuilder union = (UnionTypeBuilder) nodeToResolve; List> unionTypes = union.getTypes(); List toRemove = new ArrayList(); for (TypeDefinition td : unionTypes) { if (td instanceof UnknownType) { UnknownType unknownType = (UnknownType) td; - TypeDefinitionBuilder resolvedType = findTargetTypeUnion( - typeToResolve, unknownType, modules, module); + TypeDefinitionBuilder resolvedType = resolveTypeUnion( + nodeToResolve, unknownType, modules, module); union.setType(resolvedType); toRemove.add(unknownType); } } unionTypes.removeAll(toRemove); } else { - TypeDefinitionBuilder resolvedType = findTargetType( - typeToResolve, modules, module); - typeToResolve.setType(resolvedType); + TypeDefinitionBuilder resolvedType = resolveType( + nodeToResolve, modules, module); + nodeToResolve.setType(resolvedType); } } } } - private TypeDefinitionBuilder findTargetType( - TypeAwareBuilder typeToResolve, + private TypeDefinitionBuilder resolveType(TypeAwareBuilder typeToResolve, Map> modules, ModuleBuilder builder) { TypeConstraints constraints = new TypeConstraints(); - TypeDefinitionBuilder targetType = findTypedef(typeToResolve, modules, - builder); + TypeDefinitionBuilder targetType = getTypedefBuilder(typeToResolve, + modules, builder); TypeConstraints tConstraints = findConstraints(typeToResolve, constraints, modules, builder); targetType.setRanges(tConstraints.getRange()); @@ -303,13 +314,13 @@ public class YangModelParserImpl implements YangModelParser { return targetType; } - private TypeDefinitionBuilder findTargetTypeUnion( + private TypeDefinitionBuilder resolveTypeUnion( TypeAwareBuilder typeToResolve, UnknownType unknownType, Map> modules, ModuleBuilder builder) { TypeConstraints constraints = new TypeConstraints(); - TypeDefinitionBuilder targetType = findTypedefUnion(typeToResolve, + TypeDefinitionBuilder targetType = getUnionBuilder(typeToResolve, unknownType, modules, builder); TypeConstraints tConstraints = findConstraints(typeToResolve, constraints, modules, builder); @@ -321,17 +332,18 @@ public class YangModelParserImpl implements YangModelParser { return targetType; } - private TypeDefinitionBuilder findTypedef(TypeAwareBuilder typeToResolve, + private TypeDefinitionBuilder getTypedefBuilder( + TypeAwareBuilder nodeToResolve, Map> modules, ModuleBuilder builder) { - TypeDefinition baseTypeToResolve = typeToResolve.getType(); - if (baseTypeToResolve != null - && !(baseTypeToResolve instanceof UnknownType)) { - return (TypeDefinitionBuilder) typeToResolve; + TypeDefinition nodeToResolveBase = nodeToResolve.getType(); + if (nodeToResolveBase != null + && !(nodeToResolveBase instanceof UnknownType)) { + return (TypeDefinitionBuilder) nodeToResolve; } - UnknownType unknownType = (UnknownType) typeToResolve.getType(); + UnknownType unknownType = (UnknownType) nodeToResolve.getType(); QName unknownTypeQName = unknownType.getQName(); String unknownTypeName = unknownTypeQName.getLocalName(); @@ -340,25 +352,25 @@ public class YangModelParserImpl implements YangModelParser { // search for module which contains referenced typedef ModuleBuilder dependentModule = findDependentModule(modules, builder, unknownTypePrefix); - TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilder( - dependentModule.getModuleTypedefs(), unknownTypeName); + TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName( + dependentModule, unknownTypeName); TypeDefinitionBuilder lookedUpBuilderCopy = copyTypedefBuilder( - lookedUpBuilder, typeToResolve instanceof TypeDefinitionBuilder); + lookedUpBuilder, nodeToResolve instanceof TypeDefinitionBuilder); TypeDefinitionBuilder resolvedCopy = resolveCopiedBuilder( lookedUpBuilderCopy, modules, dependentModule); return resolvedCopy; } - private TypeDefinitionBuilder findTypedefUnion( - TypeAwareBuilder typeToResolve, UnknownType unknownType, + private TypeDefinitionBuilder getUnionBuilder( + TypeAwareBuilder nodeToResolve, UnknownType unknownType, Map> modules, - ModuleBuilder builder) { + ModuleBuilder module) { - TypeDefinition baseTypeToResolve = typeToResolve.getType(); + TypeDefinition baseTypeToResolve = nodeToResolve.getType(); if (baseTypeToResolve != null && !(baseTypeToResolve instanceof UnknownType)) { - return (TypeDefinitionBuilder) typeToResolve; + return (TypeDefinitionBuilder) nodeToResolve; } QName unknownTypeQName = unknownType.getQName(); @@ -366,13 +378,13 @@ public class YangModelParserImpl implements YangModelParser { String unknownTypePrefix = unknownTypeQName.getPrefix(); // search for module which contains referenced typedef - ModuleBuilder dependentModule = findDependentModule(modules, builder, + ModuleBuilder dependentModule = findDependentModule(modules, module, unknownTypePrefix); - TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilder( - dependentModule.getModuleTypedefs(), unknownTypeName); + TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName( + dependentModule, unknownTypeName); TypeDefinitionBuilder lookedUpBuilderCopy = copyTypedefBuilder( - lookedUpBuilder, typeToResolve instanceof TypeDefinitionBuilder); + lookedUpBuilder, nodeToResolve instanceof TypeDefinitionBuilder); TypeDefinitionBuilder resolvedCopy = resolveCopiedBuilder( lookedUpBuilderCopy, modules, dependentModule); return resolvedCopy; @@ -392,15 +404,16 @@ public class YangModelParserImpl implements YangModelParser { return newUnion; } - QName oldQName = old.getQName(); - QName newQName = new QName(oldQName.getNamespace(), - oldQName.getRevision(), oldQName.getPrefix(), - oldQName.getLocalName()); - TypeDefinitionBuilder tdb = new TypedefBuilder(newQName); + QName oldName = old.getQName(); + QName newName = new QName(oldName.getNamespace(), + oldName.getRevision(), oldName.getPrefix(), + oldName.getLocalName()); + TypeDefinitionBuilder tdb = new TypedefBuilder(newName); tdb.setRanges(old.getRanges()); tdb.setLengths(old.getLengths()); tdb.setPatterns(old.getPatterns()); + tdb.setFractionDigits(old.getFractionDigits()); TypeDefinition oldType = old.getType(); if (oldType == null) { @@ -420,18 +433,18 @@ public class YangModelParserImpl implements YangModelParser { } private TypeDefinitionBuilder resolveCopiedBuilder( - TypeDefinitionBuilder copied, + TypeDefinitionBuilder copy, Map> modules, ModuleBuilder builder) { - if (copied instanceof UnionTypeBuilder) { - UnionTypeBuilder union = (UnionTypeBuilder) copied; + if (copy instanceof UnionTypeBuilder) { + UnionTypeBuilder union = (UnionTypeBuilder) copy; List> unionTypes = union.getTypes(); List toRemove = new ArrayList(); for (TypeDefinition td : unionTypes) { if (td instanceof UnknownType) { UnknownType unknownType = (UnknownType) td; - TypeDefinitionBuilder resolvedType = findTargetTypeUnion( + TypeDefinitionBuilder resolvedType = resolveTypeUnion( union, unknownType, modules, builder); union.setType(resolvedType); toRemove.add(unknownType); @@ -442,35 +455,35 @@ public class YangModelParserImpl implements YangModelParser { return union; } - TypeDefinition base = copied.getType(); - TypeDefinitionBuilder baseTdb = copied.getTypedef(); + TypeDefinition base = copy.getType(); + TypeDefinitionBuilder baseTdb = copy.getTypedef(); if (base != null && !(base instanceof UnknownType)) { - return copied; + return copy; } else if (base instanceof UnknownType) { UnknownType unknownType = (UnknownType) base; QName unknownTypeQName = unknownType.getQName(); String unknownTypePrefix = unknownTypeQName.getPrefix(); ModuleBuilder dependentModule = findDependentModule(modules, builder, unknownTypePrefix); - TypeDefinitionBuilder unknownTypeBuilder = findTypedef(copied, + TypeDefinitionBuilder unknownTypeBuilder = getTypedefBuilder(copy, modules, dependentModule); - copied.setType(unknownTypeBuilder); - return copied; + copy.setType(unknownTypeBuilder); + return copy; } else if (base == null && baseTdb != null) { // make a copy of baseTypeDef and call again TypeDefinitionBuilder baseTdbCopy = copyTypedefBuilder(baseTdb, true); TypeDefinitionBuilder baseTdbCopyResolved = resolveCopiedBuilder( baseTdbCopy, modules, builder); - copied.setType(baseTdbCopyResolved); - return copied; + copy.setType(baseTdbCopyResolved); + return copy; } else { throw new IllegalStateException( "TypeDefinitionBuilder in unexpected state"); } } - private TypeDefinitionBuilder findTypedef(QName unknownTypeQName, + private TypeDefinitionBuilder findTypedefBuilder(QName unknownTypeQName, Map> modules, ModuleBuilder builder) { @@ -481,61 +494,64 @@ public class YangModelParserImpl implements YangModelParser { ModuleBuilder dependentModule = findDependentModule(modules, builder, unknownTypePrefix); - TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilder( - dependentModule.getModuleTypedefs(), unknownTypeName); + TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName( + dependentModule, unknownTypeName); TypeDefinitionBuilder copied = copyTypedefBuilder(lookedUpBuilder, true); return copied; } - private TypeConstraints findConstraints(TypeAwareBuilder typeToResolve, + private TypeConstraints findConstraints(TypeAwareBuilder nodeToResolve, TypeConstraints constraints, Map> modules, ModuleBuilder builder) { // union type cannot be restricted - if (typeToResolve instanceof UnionTypeBuilder) { + if (nodeToResolve instanceof UnionTypeBuilder) { return constraints; } // if referenced type is UnknownType again, search recursively with // current constraints - TypeDefinition referencedType = typeToResolve.getType(); + TypeDefinition referencedType = nodeToResolve.getType(); + List ranges = Collections.emptyList(); + List lengths = Collections.emptyList(); + List patterns = Collections.emptyList(); + Integer fractionDigits = null; if (referencedType == null) { - TypeDefinitionBuilder tdb = (TypeDefinitionBuilder) typeToResolve; - final List ranges = tdb.getRanges(); + TypeDefinitionBuilder tdb = (TypeDefinitionBuilder) nodeToResolve; + ranges = tdb.getRanges(); constraints.addRanges(ranges); - final List lengths = tdb.getLengths(); + lengths = tdb.getLengths(); constraints.addLengths(lengths); - final List patterns = tdb.getPatterns(); + patterns = tdb.getPatterns(); constraints.addPatterns(patterns); - final Integer fractionDigits = tdb.getFractionDigits(); + fractionDigits = tdb.getFractionDigits(); constraints.setFractionDigits(fractionDigits); return constraints; } else if (referencedType instanceof ExtendedType) { ExtendedType ext = (ExtendedType) referencedType; - final List ranges = ext.getRanges(); + ranges = ext.getRanges(); constraints.addRanges(ranges); - final List lengths = ext.getLengths(); + lengths = ext.getLengths(); constraints.addLengths(lengths); - final List patterns = ext.getPatterns(); + patterns = ext.getPatterns(); constraints.addPatterns(patterns); - final Integer fractionDigits = ext.getFractionDigits(); + fractionDigits = ext.getFractionDigits(); constraints.setFractionDigits(fractionDigits); return findConstraints( - findTypedef(ext.getQName(), modules, builder), constraints, - modules, builder); + findTypedefBuilder(ext.getQName(), modules, builder), + constraints, modules, builder); } else if (referencedType instanceof UnknownType) { UnknownType unknown = (UnknownType) referencedType; - final List ranges = unknown.getRangeStatements(); + ranges = unknown.getRangeStatements(); constraints.addRanges(ranges); - final List lengths = unknown - .getLengthStatements(); + lengths = unknown.getLengthStatements(); constraints.addLengths(lengths); - final List patterns = unknown.getPatterns(); + patterns = unknown.getPatterns(); constraints.addPatterns(patterns); - final Integer fractionDigits = unknown.getFractionDigits(); + fractionDigits = unknown.getFractionDigits(); constraints.setFractionDigits(fractionDigits); String unknownTypePrefix = unknown.getQName().getPrefix(); @@ -544,7 +560,7 @@ public class YangModelParserImpl implements YangModelParser { } ModuleBuilder dependentModule = findDependentModule(modules, builder, unknown.getQName().getPrefix()); - TypeDefinitionBuilder unknownTypeBuilder = findTypedef( + TypeDefinitionBuilder unknownTypeBuilder = findTypedefBuilder( unknown.getQName(), modules, builder); return findConstraints(unknownTypeBuilder, constraints, modules, dependentModule); @@ -559,16 +575,18 @@ public class YangModelParserImpl implements YangModelParser { /** * Go through all typedef statements from given module and search for one * with given name - * + * * @param typedefs * typedef statements to search * @param name * name of searched typedef * @return typedef with name equals to given name */ - private TypeDefinitionBuilder findTypedefBuilder( - Set typedefs, String name) { + private TypeDefinitionBuilder findTypedefBuilderByName( + ModuleBuilder dependentModule, String name) { TypeDefinitionBuilder result = null; + final Set typedefs = dependentModule + .getModuleTypedefs(); for (TypeDefinitionBuilder td : typedefs) { if (td.getQName().getLocalName().equals(name)) { result = td; @@ -576,15 +594,16 @@ public class YangModelParserImpl implements YangModelParser { } } if (result == null) { - throw new YangParseException( - "Target module does not contain typedef '" + name + "'."); + throw new YangParseException("Target module '" + + dependentModule.getName() + + "' does not contain typedef '" + name + "'."); } return result; } /** * Pull restriction from referenced type and add them to given constraints - * + * * @param referencedType * @param constraints */ @@ -614,45 +633,78 @@ public class YangModelParserImpl implements YangModelParser { /** * Go through all augmentation definitions and resolve them. This means find * referenced node and add child nodes to it. - * + * * @param modules * all available modules * @param module * current module */ - private void resolveAugments( + public void resolveAugments( Map> modules, ModuleBuilder module) { Set augmentBuilders = module .getAddedAugments(); - Set augments = new HashSet(); for (AugmentationSchemaBuilder augmentBuilder : augmentBuilders) { SchemaPath augmentTargetSchemaPath = augmentBuilder.getTargetPath(); - String prefix = null; + List path = augmentTargetSchemaPath.getPath(); + + String prefix = path.get(path.size() - 1).getPrefix(); List augmentTargetPath = new ArrayList(); - for (QName pathPart : augmentTargetSchemaPath.getPath()) { - prefix = pathPart.getPrefix(); - augmentTargetPath.add(pathPart.getLocalName()); + for (QName pathPart : path) { + if (pathPart.getPrefix().equals(prefix)) { + augmentTargetPath.add(pathPart.getLocalName()); + } + } + if (prefix == null) { + prefix = module.getPrefix(); } + ModuleBuilder dependentModule = findDependentModule(modules, module, prefix); augmentTargetPath.add(0, dependentModule.getName()); AugmentationTargetBuilder augmentTarget = (AugmentationTargetBuilder) dependentModule .getNode(augmentTargetPath); - AugmentationSchema result = augmentBuilder.build(); - augmentTarget.addAugmentation(result); - fillAugmentTarget(augmentBuilder, (ChildNodeBuilder) augmentTarget); - augments.add(result); + + // augment target could be another augment, so if target is not + // found, get augments in target module and search for target node + if (augmentTarget == null) { + for (AugmentationSchemaBuilder builder : dependentModule + .getAddedAugments()) { + for (DataSchemaNodeBuilder dataBuilder : builder + .getChildNodes()) { + SchemaPath dataBuilderPath = dataBuilder.getPath(); + List qnamePath = dataBuilderPath.getPath(); + List dataBuilderStringPath = new ArrayList(); + + // start from 1: augment name omitted + for (int i = 1; i < qnamePath.size(); i++) { + dataBuilderStringPath.add(qnamePath.get(i) + .getLocalName()); + } + // module name omitted + augmentTargetPath.remove(0); + if (augmentTargetPath.equals(dataBuilderStringPath)) { + augmentTarget = (AugmentationTargetBuilder) dataBuilder; + augmentTarget.addAugmentation(augmentBuilder); + fillAugmentTarget(augmentBuilder, + (ChildNodeBuilder) augmentTarget); + } + } + } + } else { + augmentTarget.addAugmentation(augmentBuilder); + fillAugmentTarget(augmentBuilder, + (ChildNodeBuilder) augmentTarget); + } } - module.setAugmentations(augments); } /** * Add all augment's child nodes to given target. - * + * * @param augment * @param target */ @@ -667,7 +719,7 @@ public class YangModelParserImpl implements YangModelParser { /** * Go through identity statements defined in current module and resolve * their 'base' statement if present. - * + * * @param modules * all modules * @param module @@ -705,9 +757,203 @@ public class YangModelParserImpl implements YangModelParser { } } + /** + * Go through uses statements defined in current module and resolve their + * refine statements. + * + * @param modules + * all modules + * @param module + * module being resolved + */ + private void resolveUses(Map> modules, + ModuleBuilder module) { + Map, UsesNodeBuilder> moduleUses = module + .getAddedUsesNodes(); + for (Map.Entry, UsesNodeBuilder> entry : moduleUses + .entrySet()) { + List key = entry.getKey(); + UsesNodeBuilder usesNode = entry.getValue(); + + String groupingName = key.get(key.size() - 1); + + List refines = usesNode.getRefines(); + for (RefineHolder refine : refines) { + Refine refineType = refine.getType(); + + // refine statements + String defaultStr = refine.getDefaultStr(); + Boolean mandatory = refine.isMandatory(); + MustDefinition must = refine.getMust(); + Boolean presence = refine.isPresence(); + Integer min = refine.getMinElements(); + Integer max = refine.getMaxElements(); + + switch (refineType) { + case LEAF: + LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) getRefineTargetBuilder( + groupingName, refine, modules, module); + if (defaultStr != null && !("".equals(defaultStr))) { + leaf.setDefaultStr(defaultStr); + } + if (mandatory != null) { + leaf.getConstraints().setMandatory(mandatory); + } + if (must != null) { + leaf.getConstraints().addMustDefinition(must); + } + usesNode.addRefineNode(leaf); + break; + case CONTAINER: + ContainerSchemaNodeBuilder container = (ContainerSchemaNodeBuilder) getRefineTargetBuilder( + groupingName, refine, modules, module); + if (presence != null) { + container.setPresence(presence); + } + if (must != null) { + container.getConstraints().addMustDefinition(must); + } + usesNode.addRefineNode(container); + break; + case LIST: + ListSchemaNodeBuilder list = (ListSchemaNodeBuilder) getRefineTargetBuilder( + groupingName, refine, modules, module); + if (must != null) { + list.getConstraints().addMustDefinition(must); + } + if (min != null) { + list.getConstraints().setMinElements(min); + } + if (max != null) { + list.getConstraints().setMaxElements(max); + } + break; + case LEAF_LIST: + LeafListSchemaNodeBuilder leafList = (LeafListSchemaNodeBuilder) getRefineTargetBuilder( + groupingName, refine, modules, module); + if (must != null) { + leafList.getConstraints().addMustDefinition(must); + } + if (min != null) { + leafList.getConstraints().setMinElements(min); + } + if (max != null) { + leafList.getConstraints().setMaxElements(max); + } + break; + case CHOICE: + ChoiceBuilder choice = (ChoiceBuilder) getRefineTargetBuilder( + groupingName, refine, modules, module); + if (defaultStr != null) { + choice.setDefaultCase(defaultStr); + } + if (mandatory != null) { + choice.getConstraints().setMandatory(mandatory); + } + break; + case ANYXML: + AnyXmlBuilder anyXml = (AnyXmlBuilder) getRefineTargetBuilder( + groupingName, refine, modules, module); + if (mandatory != null) { + anyXml.getConstraints().setMandatory(mandatory); + } + if (must != null) { + anyXml.getConstraints().addMustDefinition(must); + } + } + } + } + + } + + /** + * Find original builder of refine node and return copy of this builder. + * + * @param groupingPath + * path to grouping which contains node to refine + * @param refine + * refine object containing informations about refine + * @param modules + * all loaded modules + * @param module + * current module + * @return copy of Builder object of node to be refined if it is present in + * grouping, null otherwise + */ + private Builder getRefineTargetBuilder(String groupingPath, + RefineHolder refine, + Map> modules, + ModuleBuilder module) { + Builder result = null; + Builder lookedUpBuilder = findRefineTargetBuilder(groupingPath, + refine.getName(), modules, module); + if (lookedUpBuilder instanceof LeafSchemaNodeBuilder) { + result = ParserUtils + .copyLeafBuilder((LeafSchemaNodeBuilder) lookedUpBuilder); + } else if (lookedUpBuilder instanceof ContainerSchemaNodeBuilder) { + result = ParserUtils + .copyContainerBuilder((ContainerSchemaNodeBuilder) lookedUpBuilder); + } else if (lookedUpBuilder instanceof ListSchemaNodeBuilder) { + result = ParserUtils + .copyListBuilder((ListSchemaNodeBuilder) lookedUpBuilder); + } else if (lookedUpBuilder instanceof LeafListSchemaNodeBuilder) { + result = ParserUtils + .copyLeafListBuilder((LeafListSchemaNodeBuilder) lookedUpBuilder); + } else if (lookedUpBuilder instanceof ChoiceBuilder) { + result = ParserUtils + .copyChoiceBuilder((ChoiceBuilder) lookedUpBuilder); + } else if (lookedUpBuilder instanceof AnyXmlBuilder) { + result = ParserUtils + .copyAnyXmlBuilder((AnyXmlBuilder) lookedUpBuilder); + } else { + throw new YangParseException("Target '" + refine.getName() + + "' can not be refined"); + } + return result; + } + + /** + * Find builder of refine node. + * + * @param groupingPath + * path to grouping which contains node to refine + * @param refineNodeName + * name of node to be refined + * @param modules + * all loaded modules + * @param module + * current module + * @return Builder object of refine node if it is present in grouping, null + * otherwise + */ + private Builder findRefineTargetBuilder(String groupingPath, + String refineNodeName, + Map> modules, + ModuleBuilder module) { + SchemaPath path = ParserUtils.parseUsesPath(groupingPath); + List builderPath = new ArrayList(); + String prefix = null; + for (QName qname : path.getPath()) { + builderPath.add(qname.getLocalName()); + prefix = qname.getPrefix(); + } + if (prefix == null) { + prefix = module.getPrefix(); + } + + ModuleBuilder dependentModule = findDependentModule(modules, module, + prefix); + builderPath.add(0, "grouping"); + builderPath.add(0, dependentModule.getName()); + GroupingBuilder builder = (GroupingBuilder) dependentModule + .getNode(builderPath); + + return builder.getChildNode(refineNodeName); + } + /** * Find dependent module based on given prefix - * + * * @param modules * all available modules * @param module @@ -735,6 +981,12 @@ public class YangModelParserImpl implements YangModelParser { TreeMap moduleBuildersByRevision = modules .get(dependentModuleName); + if (moduleBuildersByRevision == null) { + throw new YangParseException( + "Failed to find dependent module '" + + dependentModuleName + "' needed by module '" + + module.getName() + "'."); + } if (dependentModuleRevision == null) { dependentModule = moduleBuildersByRevision.lastEntry() .getValue(); @@ -755,7 +1007,7 @@ public class YangModelParserImpl implements YangModelParser { /** * Get module import referenced by given prefix. - * + * * @param builder * module to search * @param prefix @@ -773,12 +1025,6 @@ public class YangModelParserImpl implements YangModelParser { return moduleImport; } - private Date createEpochTime() { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(0); - return calendar.getTime(); - } - private static class SchemaContextImpl implements SchemaContext { private final Set modules; diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java index 6675b8068d..acc1dea2d4 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java @@ -1,707 +1,797 @@ -/* - * 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.controller.yang.model.parser.impl; - -import static org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil.*; - -import java.net.URI; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Stack; - -import org.antlr.v4.runtime.tree.ParseTree; -import org.opendaylight.controller.antlrv4.code.gen.YangParser; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Contact_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Container_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Description_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_add_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_delete_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_not_supported_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_replace_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Import_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Key_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leaf_list_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leaf_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.List_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Module_header_stmtsContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Namespace_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Organization_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Prefix_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Presence_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Reference_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_date_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtsContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; -import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.ContainerSchemaNodeBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.DeviationBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.ExtensionBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.FeatureBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.IdentitySchemaNodeBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.LeafListSchemaNodeBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.LeafSchemaNodeBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.ListSchemaNodeBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.NotificationBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.RpcDefinitionBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.TypedefBuilder; -import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder; -import org.opendaylight.controller.yang.model.util.YangTypesConverter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -final class YangModelParserListenerImpl extends YangParserBaseListener { - - private static final Logger logger = LoggerFactory - .getLogger(YangModelParserListenerImpl.class); - - private ModuleBuilder moduleBuilder; - - private String moduleName; - private URI namespace; - private String yangModelPrefix; - private Date revision = new Date(0L); - - final static DateFormat simpleDateFormat = new SimpleDateFormat( - "yyyy-mm-dd"); - private final Stack actualPath = new Stack(); - - @Override - public void enterModule_stmt(YangParser.Module_stmtContext ctx) { - moduleName = stringFromNode(ctx); - actualPath.push(moduleName); - moduleBuilder = new ModuleBuilder(moduleName); - - String description = null; - String reference = null; - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Description_stmtContext) { - description = stringFromNode(child); - } else if (child instanceof Reference_stmtContext) { - reference = stringFromNode(child); - } else { - if (description != null && reference != null) { - break; - } - } - } - moduleBuilder.setDescription(description); - moduleBuilder.setReference(reference); - } - - @Override - public void exitModule_stmt(YangParser.Module_stmtContext ctx) { - final String moduleName = actualPath.pop(); - logger.debug("Exiting module " + moduleName); - } - - @Override - public void enterModule_header_stmts(final Module_header_stmtsContext ctx) { - super.enterModule_header_stmts(ctx); - - String yangVersion = null; - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree treeNode = ctx.getChild(i); - if (treeNode instanceof Namespace_stmtContext) { - final String namespaceStr = stringFromNode(treeNode); - namespace = URI.create(namespaceStr); - moduleBuilder.setNamespace(namespace); - } else if (treeNode instanceof Prefix_stmtContext) { - yangModelPrefix = stringFromNode(treeNode); - moduleBuilder.setPrefix(yangModelPrefix); - } else if (treeNode instanceof Yang_version_stmtContext) { - yangVersion = stringFromNode(treeNode); - } - } - - if (yangVersion == null) { - yangVersion = "1"; - } - moduleBuilder.setYangVersion(yangVersion); - } - - @Override - public void enterMeta_stmts(YangParser.Meta_stmtsContext ctx) { - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Organization_stmtContext) { - final String organization = stringFromNode(child); - moduleBuilder.setOrganization(organization); - } else if (child instanceof Contact_stmtContext) { - final String contact = stringFromNode(child); - moduleBuilder.setContact(contact); - } else if (child instanceof Description_stmtContext) { - final String description = stringFromNode(child); - moduleBuilder.setDescription(description); - } else if (child instanceof Reference_stmtContext) { - final String reference = stringFromNode(child); - moduleBuilder.setReference(reference); - } - } - } - - @Override - public void exitSubmodule_header_stmts( - YangParser.Submodule_header_stmtsContext ctx) { - final String submodule = actualPath.pop(); - logger.debug("exiting submodule " + submodule); - } - - @Override - public void enterRevision_stmts(Revision_stmtsContext ctx) { - if (ctx != null) { - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree treeNode = ctx.getChild(i); - if (treeNode instanceof Revision_stmtContext) { - updateRevisionForRevisionStatement(treeNode); - } - } - } - } - - private void updateRevisionForRevisionStatement(final ParseTree treeNode) { - final String revisionDateStr = stringFromNode(treeNode); - try { - final Date revision = simpleDateFormat.parse(revisionDateStr); - if ((revision != null) && (this.revision.compareTo(revision) < 0)) { - this.revision = revision; - moduleBuilder.setRevision(this.revision); - for (int i = 0; i < treeNode.getChildCount(); ++i) { - ParseTree child = treeNode.getChild(i); - if (child instanceof Reference_stmtContext) { - moduleBuilder.setReference(stringFromNode(child)); - } - } - } - } catch (ParseException e) { - final String message = "Failed to parse revision string: " - + revisionDateStr; - logger.warn(message); - } - } - - @Override - public void enterImport_stmt(Import_stmtContext ctx) { - super.enterImport_stmt(ctx); - - final String importName = stringFromNode(ctx); - String importPrefix = null; - Date importRevision = null; - - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree treeNode = ctx.getChild(i); - if (treeNode instanceof Prefix_stmtContext) { - importPrefix = stringFromNode(treeNode); - } - if (treeNode instanceof Revision_date_stmtContext) { - String importRevisionStr = stringFromNode(treeNode); - try { - importRevision = simpleDateFormat.parse(importRevisionStr); - } catch(ParseException e) { - logger.warn("Failed to parse import revision-date: "+ importRevisionStr); - } - } - } - moduleBuilder.addModuleImport(importName, importRevision, importPrefix); - } - - @Override - public void enterAugment_stmt(YangParser.Augment_stmtContext ctx) { - final String augmentPath = stringFromNode(ctx); - AugmentationSchemaBuilder builder = moduleBuilder.addAugment( - augmentPath, getActualPath()); - updatePath(augmentPath); - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Description_stmtContext) { - String desc = stringFromNode(child); - builder.setDescription(desc); - } else if (child instanceof Reference_stmtContext) { - String ref = stringFromNode(child); - builder.setReference(ref); - } else if (child instanceof Status_stmtContext) { - Status status = parseStatus((Status_stmtContext) child); - builder.setStatus(status); - } - } - } - - @Override - public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) { - final String augment = actualPath.pop(); - logger.debug("exiting augment " + augment); - } - - @Override - public void enterExtension_stmt(YangParser.Extension_stmtContext ctx) { - String extName = stringFromNode(ctx); - QName qname = new QName(namespace, revision, yangModelPrefix, extName); - ExtensionBuilder builder = moduleBuilder.addExtension(qname); - parseSchemaNodeArgs(ctx, builder); - - String argument = null; - boolean yin = false; - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Argument_stmtContext) { - argument = stringFromNode(child); - yin = parseYinValue((Argument_stmtContext) child); - break; - } - } - builder.setArgument(argument); - builder.setYinElement(yin); - } - - @Override - public void enterTypedef_stmt(YangParser.Typedef_stmtContext ctx) { - String typedefName = stringFromNode(ctx); - QName typedefQName = new QName(namespace, revision, yangModelPrefix, - typedefName); - TypedefBuilder builder = moduleBuilder.addTypedef(typedefQName, - getActualPath()); - updatePath(typedefName); - - builder.setPath(createActualSchemaPath(actualPath, namespace, revision, - yangModelPrefix)); - parseSchemaNodeArgs(ctx, builder); - builder.setUnits(parseUnits(ctx)); - } - - @Override - public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterType_stmt(YangParser.Type_stmtContext ctx) { - String typeName = stringFromNode(ctx); - QName typeQName = parseQName(typeName); - - TypeDefinition type = null; - Type_body_stmtsContext typeBody = null; - for (int i = 0; i < ctx.getChildCount(); i++) { - if (ctx.getChild(i) instanceof Type_body_stmtsContext) { - typeBody = (Type_body_stmtsContext) ctx.getChild(i); - break; - } - } - - // if this is base yang type... - if (YangTypesConverter.isBaseYangType(typeName)) { - if (typeBody == null) { - // if there are no constraints, just grab default base yang type - type = YangTypesConverter.javaTypeForBaseYangType(typeName); - moduleBuilder.setType(type, getActualPath()); - } else { - if ("union".equals(typeName)) { - moduleBuilder.addUnionType(getActualPath()); - } else { - List typePath = new ArrayList(actualPath); - typePath.remove(0); - type = parseTypeBody(typeName, typeBody, typePath, - namespace, revision, yangModelPrefix); - moduleBuilder.setType(type, getActualPath()); - } - } - } else { - type = parseUnknownTypeBody(typeQName, typeBody); - // mark parent node of this type statement as dirty - moduleBuilder.addDirtyNode(getActualPath()); - moduleBuilder.setType(type, getActualPath()); - } - - updatePath(typeName); - } - - private QName parseQName(String typeName) { - QName typeQName; - if (typeName.contains(":")) { - String[] splittedName = typeName.split(":"); - String prefix = splittedName[0]; - String name = splittedName[1]; - if (prefix.equals(yangModelPrefix)) { - typeQName = new QName(namespace, revision, prefix, name); - } else { - typeQName = new QName(null, null, prefix, name); - } - } else { - typeQName = new QName(namespace, revision, yangModelPrefix, - typeName); - } - return typeQName; - } - - @Override - public void exitType_stmt(YangParser.Type_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterGrouping_stmt(YangParser.Grouping_stmtContext ctx) { - final String groupName = stringFromNode(ctx); - QName groupQName = new QName(namespace, revision, yangModelPrefix, - groupName); - GroupingBuilder groupBuilder = moduleBuilder.addGrouping(groupQName, - actualPath); - updatePath("grouping"); - updatePath(groupName); - parseSchemaNodeArgs(ctx, groupBuilder); - } - - @Override - public void exitGrouping_stmt(YangParser.Grouping_stmtContext ctx) { - String actContainer = actualPath.pop(); - actContainer += "-" + actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterContainer_stmt(Container_stmtContext ctx) { - super.enterContainer_stmt(ctx); - String containerName = stringFromNode(ctx); - QName containerQName = new QName(namespace, revision, yangModelPrefix, - containerName); - ContainerSchemaNodeBuilder containerBuilder = moduleBuilder - .addContainerNode(containerQName, actualPath); - updatePath(containerName); - - containerBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, containerBuilder); - parseConstraints(ctx, containerBuilder.getConstraintsBuilder()); - - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree childNode = ctx.getChild(i); - if (childNode instanceof Presence_stmtContext) { - containerBuilder.setPresenceContainer(true); - break; - } - } - } - - @Override - public void exitContainer_stmt(Container_stmtContext ctx) { - super.exitContainer_stmt(ctx); - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterLeaf_stmt(Leaf_stmtContext ctx) { - super.enterLeaf_stmt(ctx); - - final String leafName = stringFromNode(ctx); - QName leafQName = new QName(namespace, revision, yangModelPrefix, - leafName); - LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode( - leafQName, actualPath); - updatePath(leafName); - - leafBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, leafBuilder); - parseConstraints(ctx, leafBuilder.getConstraintsBuilder()); - } - - @Override - public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) { - final String actLeaf = actualPath.pop(); - logger.debug("exiting " + actLeaf); - } - - @Override - public void enterUses_stmt(YangParser.Uses_stmtContext ctx) { - final String groupingPathStr = stringFromNode(ctx); - moduleBuilder.addUsesNode(groupingPathStr, actualPath); - updatePath(groupingPathStr); - } - - @Override - public void exitUses_stmt(YangParser.Uses_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) { - super.enterLeaf_list_stmt(ctx); - - final String leafListName = stringFromNode(ctx); - QName leafListQName = new QName(namespace, revision, yangModelPrefix, - leafListName); - LeafListSchemaNodeBuilder leafListBuilder = moduleBuilder - .addLeafListNode(leafListQName, actualPath); - updatePath(leafListName); - - parseSchemaNodeArgs(ctx, leafListBuilder); - parseConstraints(ctx, leafListBuilder.getConstraintsBuilder()); - - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree childNode = ctx.getChild(i); - if (childNode instanceof Ordered_by_stmtContext) { - final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode; - final boolean userOrdered = parseUserOrdered(orderedBy); - leafListBuilder.setUserOrdered(userOrdered); - break; - } - } - } - - @Override - public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterList_stmt(List_stmtContext ctx) { - super.enterList_stmt(ctx); - - final String containerName = stringFromNode(ctx); - QName containerQName = new QName(namespace, revision, yangModelPrefix, - containerName); - ListSchemaNodeBuilder listBuilder = moduleBuilder.addListNode( - containerQName, actualPath); - updatePath(containerName); - - listBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, listBuilder); - parseConstraints(ctx, listBuilder.getConstraintsBuilder()); - - String keyDefinition = ""; - for (int i = 0; i < ctx.getChildCount(); ++i) { - ParseTree childNode = ctx.getChild(i); - if (childNode instanceof Ordered_by_stmtContext) { - final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode; - final boolean userOrdered = parseUserOrdered(orderedBy); - listBuilder.setUserOrdered(userOrdered); - } else if (childNode instanceof Key_stmtContext) { - keyDefinition = stringFromNode(childNode); - List key = createListKey(keyDefinition, namespace, - revision, yangModelPrefix); - listBuilder.setKeyDefinition(key); - } - } - } - - @Override - public void exitList_stmt(List_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterNotification_stmt(YangParser.Notification_stmtContext ctx) { - final String notificationName = stringFromNode(ctx); - QName notificationQName = new QName(namespace, revision, - yangModelPrefix, notificationName); - NotificationBuilder notificationBuilder = moduleBuilder - .addNotification(notificationQName, actualPath); - updatePath(notificationName); - - notificationBuilder.setPath(createActualSchemaPath(actualPath, namespace, - revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, notificationBuilder); - } - - @Override - public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - // Unknown types - @Override - public void enterIdentifier_stmt(YangParser.Identifier_stmtContext ctx) { - String name = stringFromNode(ctx); - - QName qname; - if(name != null) { - String[] splittedName = name.split(":"); - if(splittedName.length == 2) { - qname = new QName(null, null, splittedName[0], splittedName[1]); - } else { - qname = new QName(namespace, revision, yangModelPrefix, splittedName[0]); - } - } else { - qname = new QName(namespace, revision, yangModelPrefix, name); - } - - UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode(qname, getActualPath()); - updatePath(name); - - builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, builder); - } - - @Override - public void exitIdentifier_stmt(YangParser.Identifier_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterRpc_stmt(YangParser.Rpc_stmtContext ctx) { - final String rpcName = stringFromNode(ctx); - QName rpcQName = new QName(namespace, revision, yangModelPrefix, - rpcName); - RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName, - actualPath); - updatePath(rpcName); - - rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, - yangModelPrefix)); - parseSchemaNodeArgs(ctx, rpcBuilder); - } - - @Override - public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterInput_stmt(YangParser.Input_stmtContext ctx) { - updatePath("input"); - } - - @Override - public void exitInput_stmt(YangParser.Input_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterOutput_stmt(YangParser.Output_stmtContext ctx) { - updatePath("output"); - } - - @Override - public void exitOutput_stmt(YangParser.Output_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterFeature_stmt(YangParser.Feature_stmtContext ctx) { - final String featureName = stringFromNode(ctx); - QName featureQName = new QName(namespace, revision, yangModelPrefix, - featureName); - FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName, - actualPath); - updatePath(featureName); - - featureBuilder.setPath(createActualSchemaPath(actualPath, namespace, - revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, featureBuilder); - } - - @Override - public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterDeviation_stmt(YangParser.Deviation_stmtContext ctx) { - final String targetPath = stringFromNode(ctx); - String reference = null; - String deviate = null; - DeviationBuilder builder = moduleBuilder.addDeviation(targetPath); - updatePath(targetPath); - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Reference_stmtContext) { - reference = stringFromNode(child); - } else if (child instanceof Deviate_not_supported_stmtContext) { - deviate = stringFromNode(child); - } else if (child instanceof Deviate_add_stmtContext) { - deviate = stringFromNode(child); - } else if (child instanceof Deviate_replace_stmtContext) { - deviate = stringFromNode(child); - } else if (child instanceof Deviate_delete_stmtContext) { - deviate = stringFromNode(child); - } - } - builder.setReference(reference); - builder.setDeviate(deviate); - } - - @Override - public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterConfig_stmt(YangParser.Config_stmtContext ctx) { - boolean configuration = parseConfig(ctx); - moduleBuilder.addConfiguration(configuration, actualPath); - } - - @Override - public void enterIdentity_stmt(YangParser.Identity_stmtContext ctx) { - final String identityName = stringFromNode(ctx); - final QName identityQName = new QName(namespace, revision, - yangModelPrefix, identityName); - IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(identityQName); - updatePath(identityName); - - builder.setPath(createActualSchemaPath(actualPath, namespace, - revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, builder); - - for(int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if(child instanceof Base_stmtContext) { - String baseIdentityName = stringFromNode(child); - builder.setBaseIdentityName(baseIdentityName); - } - } - } - - @Override - public void exitIdentity_stmt(YangParser.Identity_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - public ModuleBuilder getModuleBuilder() { - return moduleBuilder; - } - - private void updatePath(String containerName) { - actualPath.push(containerName); - } - - private List getActualPath() { - return Collections.unmodifiableList(actualPath); - } - -} +/* + * 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.controller.yang.model.parser.impl; + +import static org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil.*; + +import java.net.URI; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Stack; + +import org.antlr.v4.runtime.tree.ParseTree; +import org.opendaylight.controller.antlrv4.code.gen.YangParser; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Contact_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Container_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Default_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Description_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_add_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_delete_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_not_supported_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_replace_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Import_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Key_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leaf_list_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leaf_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.List_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Module_header_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Namespace_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Organization_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Prefix_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Presence_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Reference_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_date_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.AnyXmlBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceCaseBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ContainerSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.DeviationBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ExtensionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.FeatureBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.IdentitySchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.LeafListSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.LeafSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ListSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.NotificationBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.RpcDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.TypedefBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.util.RefineHolder; +import org.opendaylight.controller.yang.model.util.YangTypesConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class YangModelParserListenerImpl extends YangParserBaseListener { + + private static final Logger logger = LoggerFactory + .getLogger(YangModelParserListenerImpl.class); + + private ModuleBuilder moduleBuilder; + + private String moduleName; + private URI namespace; + private String yangModelPrefix; + private Date revision = new Date(0L); + + final static DateFormat simpleDateFormat = new SimpleDateFormat( + "yyyy-MM-dd"); + private final Stack actualPath = new Stack(); + + @Override + public void enterModule_stmt(YangParser.Module_stmtContext ctx) { + moduleName = stringFromNode(ctx); + actualPath.push(moduleName); + moduleBuilder = new ModuleBuilder(moduleName); + + String description = null; + String reference = null; + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + description = stringFromNode(child); + } else if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } else { + if (description != null && reference != null) { + break; + } + } + } + moduleBuilder.setDescription(description); + moduleBuilder.setReference(reference); + } + + @Override + public void exitModule_stmt(YangParser.Module_stmtContext ctx) { + final String moduleName = actualPath.pop(); + logger.debug("Exiting module " + moduleName); + } + + @Override + public void enterModule_header_stmts(final Module_header_stmtsContext ctx) { + super.enterModule_header_stmts(ctx); + + String yangVersion = null; + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree treeNode = ctx.getChild(i); + if (treeNode instanceof Namespace_stmtContext) { + final String namespaceStr = stringFromNode(treeNode); + namespace = URI.create(namespaceStr); + moduleBuilder.setNamespace(namespace); + } else if (treeNode instanceof Prefix_stmtContext) { + yangModelPrefix = stringFromNode(treeNode); + moduleBuilder.setPrefix(yangModelPrefix); + } else if (treeNode instanceof Yang_version_stmtContext) { + yangVersion = stringFromNode(treeNode); + } + } + + if (yangVersion == null) { + yangVersion = "1"; + } + moduleBuilder.setYangVersion(yangVersion); + } + + @Override + public void enterMeta_stmts(YangParser.Meta_stmtsContext ctx) { + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Organization_stmtContext) { + final String organization = stringFromNode(child); + moduleBuilder.setOrganization(organization); + } else if (child instanceof Contact_stmtContext) { + final String contact = stringFromNode(child); + moduleBuilder.setContact(contact); + } else if (child instanceof Description_stmtContext) { + final String description = stringFromNode(child); + moduleBuilder.setDescription(description); + } else if (child instanceof Reference_stmtContext) { + final String reference = stringFromNode(child); + moduleBuilder.setReference(reference); + } + } + } + + @Override + public void exitSubmodule_header_stmts( + YangParser.Submodule_header_stmtsContext ctx) { + final String submodule = actualPath.pop(); + logger.debug("exiting submodule " + submodule); + } + + @Override + public void enterRevision_stmts(Revision_stmtsContext ctx) { + if (ctx != null) { + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree treeNode = ctx.getChild(i); + if (treeNode instanceof Revision_stmtContext) { + updateRevisionForRevisionStatement(treeNode); + } + } + } + } + + private void updateRevisionForRevisionStatement(final ParseTree treeNode) { + final String revisionDateStr = stringFromNode(treeNode); + try { + final Date revision = simpleDateFormat.parse(revisionDateStr); + if ((revision != null) && (this.revision.compareTo(revision) < 0)) { + this.revision = revision; + moduleBuilder.setRevision(this.revision); + for (int i = 0; i < treeNode.getChildCount(); ++i) { + ParseTree child = treeNode.getChild(i); + if (child instanceof Reference_stmtContext) { + moduleBuilder.setReference(stringFromNode(child)); + } + } + } + } catch (ParseException e) { + final String message = "Failed to parse revision string: " + + revisionDateStr; + logger.warn(message); + } + } + + @Override + public void enterImport_stmt(Import_stmtContext ctx) { + final String importName = stringFromNode(ctx); + String importPrefix = null; + Date importRevision = null; + + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree treeNode = ctx.getChild(i); + if (treeNode instanceof Prefix_stmtContext) { + importPrefix = stringFromNode(treeNode); + } + if (treeNode instanceof Revision_date_stmtContext) { + String importRevisionStr = stringFromNode(treeNode); + try { + importRevision = simpleDateFormat.parse(importRevisionStr); + } catch (ParseException e) { + logger.warn("Failed to parse import revision-date: " + + importRevisionStr); + } + } + } + moduleBuilder.addModuleImport(importName, importRevision, importPrefix); + } + + @Override + public void enterAugment_stmt(YangParser.Augment_stmtContext ctx) { + final String augmentPath = stringFromNode(ctx); + AugmentationSchemaBuilder builder = moduleBuilder.addAugment( + augmentPath, actualPath); + updatePath(augmentPath); + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + String desc = stringFromNode(child); + builder.setDescription(desc); + } else if (child instanceof Reference_stmtContext) { + String ref = stringFromNode(child); + builder.setReference(ref); + } else if (child instanceof Status_stmtContext) { + Status status = parseStatus((Status_stmtContext) child); + builder.setStatus(status); + } + } + } + + @Override + public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) { + final String augment = actualPath.pop(); + logger.debug("exiting augment " + augment); + } + + @Override + public void enterExtension_stmt(YangParser.Extension_stmtContext ctx) { + final String extName = stringFromNode(ctx); + QName qname = new QName(namespace, revision, yangModelPrefix, extName); + ExtensionBuilder builder = moduleBuilder.addExtension(qname); + parseSchemaNodeArgs(ctx, builder); + + String argument = null; + boolean yin = false; + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Argument_stmtContext) { + argument = stringFromNode(child); + yin = parseYinValue((Argument_stmtContext) child); + break; + } + } + builder.setArgument(argument); + builder.setYinElement(yin); + } + + @Override + public void enterTypedef_stmt(YangParser.Typedef_stmtContext ctx) { + final String typedefName = stringFromNode(ctx); + QName typedefQName = new QName(namespace, revision, yangModelPrefix, + typedefName); + TypedefBuilder builder = moduleBuilder.addTypedef(typedefQName, + actualPath); + updatePath(typedefName); + + builder.setPath(createActualSchemaPath(actualPath, namespace, revision, + yangModelPrefix)); + parseSchemaNodeArgs(ctx, builder); + builder.setUnits(parseUnits(ctx)); + } + + @Override + public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterType_stmt(YangParser.Type_stmtContext ctx) { + final String typeName = stringFromNode(ctx); + QName typeQName = parseQName(typeName); + + TypeDefinition type = null; + Type_body_stmtsContext typeBody = null; + for (int i = 0; i < ctx.getChildCount(); i++) { + if (ctx.getChild(i) instanceof Type_body_stmtsContext) { + typeBody = (Type_body_stmtsContext) ctx.getChild(i); + break; + } + } + + // if this is base yang type... + if (YangTypesConverter.isBaseYangType(typeName)) { + if (typeBody == null) { + // if there are no constraints, just grab default base yang type + type = YangTypesConverter.javaTypeForBaseYangType(typeName); + moduleBuilder.setType(type, actualPath); + } else { + if ("union".equals(typeName)) { + moduleBuilder.addUnionType(actualPath); + } else { + List typePath = new ArrayList(actualPath); + typePath.remove(0); + type = parseTypeBody(typeName, typeBody, typePath, + namespace, revision, yangModelPrefix); + moduleBuilder.setType(type, actualPath); + } + } + } else { + type = parseUnknownTypeBody(typeQName, typeBody); + // mark parent node of this type statement as dirty + moduleBuilder.addDirtyNode(actualPath); + moduleBuilder.setType(type, actualPath); + } + + updatePath(typeName); + } + + private QName parseQName(String typeName) { + QName typeQName; + if (typeName.contains(":")) { + String[] splittedName = typeName.split(":"); + String prefix = splittedName[0]; + String name = splittedName[1]; + if (prefix.equals(yangModelPrefix)) { + typeQName = new QName(namespace, revision, prefix, name); + } else { + typeQName = new QName(null, null, prefix, name); + } + } else { + typeQName = new QName(namespace, revision, yangModelPrefix, + typeName); + } + return typeQName; + } + + @Override + public void exitType_stmt(YangParser.Type_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterGrouping_stmt(YangParser.Grouping_stmtContext ctx) { + final String groupName = stringFromNode(ctx); + QName groupQName = new QName(namespace, revision, yangModelPrefix, + groupName); + GroupingBuilder groupBuilder = moduleBuilder.addGrouping(groupQName, + actualPath); + updatePath("grouping"); + updatePath(groupName); + parseSchemaNodeArgs(ctx, groupBuilder); + } + + @Override + public void exitGrouping_stmt(YangParser.Grouping_stmtContext ctx) { + String actContainer = actualPath.pop(); + actContainer += "-" + actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterContainer_stmt(Container_stmtContext ctx) { + final String containerName = stringFromNode(ctx); + QName containerQName = new QName(namespace, revision, yangModelPrefix, + containerName); + ContainerSchemaNodeBuilder containerBuilder = moduleBuilder + .addContainerNode(containerQName, actualPath); + updatePath(containerName); + + containerBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, containerBuilder); + parseConstraints(ctx, containerBuilder.getConstraints()); + + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree childNode = ctx.getChild(i); + if (childNode instanceof Presence_stmtContext) { + containerBuilder.setPresence(true); + break; + } + } + } + + @Override + public void exitContainer_stmt(Container_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterLeaf_stmt(Leaf_stmtContext ctx) { + final String leafName = stringFromNode(ctx); + QName leafQName = new QName(namespace, revision, yangModelPrefix, + leafName); + LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode( + leafQName, actualPath); + updatePath(leafName); + + leafBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, leafBuilder); + parseConstraints(ctx, leafBuilder.getConstraints()); + + String defaultStr = null; + String unitsStr = null; + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Default_stmtContext) { + defaultStr = stringFromNode(child); + } else if (child instanceof Units_stmtContext) { + unitsStr = stringFromNode(child); + } + } + leafBuilder.setDefaultStr(defaultStr); + leafBuilder.setUnits(unitsStr); + } + + @Override + public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) { + final String actLeaf = actualPath.pop(); + logger.debug("exiting " + actLeaf); + } + + @Override + public void enterUses_stmt(YangParser.Uses_stmtContext ctx) { + final String groupingPathStr = stringFromNode(ctx); + UsesNodeBuilder builder = moduleBuilder.addUsesNode(groupingPathStr, + actualPath); + updatePath(groupingPathStr); + + final List refines = parseRefines(ctx); + builder.setRefines(refines); + } + + @Override + public void exitUses_stmt(YangParser.Uses_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) { + final String leafListName = stringFromNode(ctx); + QName leafListQName = new QName(namespace, revision, yangModelPrefix, + leafListName); + LeafListSchemaNodeBuilder leafListBuilder = moduleBuilder + .addLeafListNode(leafListQName, actualPath); + updatePath(leafListName); + + parseSchemaNodeArgs(ctx, leafListBuilder); + parseConstraints(ctx, leafListBuilder.getConstraints()); + + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree childNode = ctx.getChild(i); + if (childNode instanceof Ordered_by_stmtContext) { + final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode; + final boolean userOrdered = parseUserOrdered(orderedBy); + leafListBuilder.setUserOrdered(userOrdered); + break; + } + } + } + + @Override + public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterList_stmt(List_stmtContext ctx) { + final String containerName = stringFromNode(ctx); + QName containerQName = new QName(namespace, revision, yangModelPrefix, + containerName); + ListSchemaNodeBuilder listBuilder = moduleBuilder.addListNode( + containerQName, actualPath); + updatePath(containerName); + + listBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, listBuilder); + parseConstraints(ctx, listBuilder.getConstraints()); + + String keyDefinition = ""; + for (int i = 0; i < ctx.getChildCount(); ++i) { + ParseTree childNode = ctx.getChild(i); + if (childNode instanceof Ordered_by_stmtContext) { + final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode; + final boolean userOrdered = parseUserOrdered(orderedBy); + listBuilder.setUserOrdered(userOrdered); + } else if (childNode instanceof Key_stmtContext) { + keyDefinition = stringFromNode(childNode); + List key = createListKey(keyDefinition, namespace, + revision, yangModelPrefix); + listBuilder.setKeyDefinition(key); + } + } + } + + @Override + public void exitList_stmt(List_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) { + final String anyXmlName = stringFromNode(ctx); + QName anyXmlQName = new QName(namespace, revision, yangModelPrefix, + anyXmlName); + AnyXmlBuilder anyXmlBuilder = moduleBuilder.addAnyXml(anyXmlQName, + actualPath); + updatePath(anyXmlName); + + anyXmlBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, anyXmlBuilder); + parseConstraints(ctx, anyXmlBuilder.getConstraints()); + } + + @Override + public void exitAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterChoice_stmt(YangParser.Choice_stmtContext ctx) { + final String choiceName = stringFromNode(ctx); + QName choiceQName = new QName(namespace, revision, yangModelPrefix, + choiceName); + ChoiceBuilder choiceBuilder = moduleBuilder.addChoice(choiceQName, + actualPath); + + updatePath(choiceName); + choiceBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, choiceBuilder); + parseConstraints(ctx, choiceBuilder.getConstraints()); + + // set 'default' case + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Default_stmtContext) { + String defaultCase = stringFromNode(child); + choiceBuilder.setDefaultCase(defaultCase); + break; + } + } + } + + @Override + public void exitChoice_stmt(YangParser.Choice_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterCase_stmt(YangParser.Case_stmtContext ctx) { + final String caseName = stringFromNode(ctx); + QName choiceQName = new QName(namespace, revision, yangModelPrefix, + caseName); + ChoiceCaseBuilder caseBuilder = moduleBuilder.addCase(choiceQName, + actualPath); + + updatePath(caseName); + caseBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, caseBuilder); + parseConstraints(ctx, caseBuilder.getConstraints()); + } + + @Override + public void exitCase_stmt(YangParser.Case_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterNotification_stmt(YangParser.Notification_stmtContext ctx) { + final String notificationName = stringFromNode(ctx); + QName notificationQName = new QName(namespace, revision, + yangModelPrefix, notificationName); + NotificationBuilder notificationBuilder = moduleBuilder + .addNotification(notificationQName, actualPath); + updatePath(notificationName); + + notificationBuilder.setPath(createActualSchemaPath(actualPath, + namespace, revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, notificationBuilder); + } + + @Override + public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + // Unknown types + @Override + public void enterIdentifier_stmt(YangParser.Identifier_stmtContext ctx) { + final String name = stringFromNode(ctx); + + QName qname; + if (name != null) { + String[] splittedName = name.split(":"); + if (splittedName.length == 2) { + qname = new QName(null, null, splittedName[0], splittedName[1]); + } else { + qname = new QName(namespace, revision, yangModelPrefix, + splittedName[0]); + } + } else { + qname = new QName(namespace, revision, yangModelPrefix, name); + } + + UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode( + qname, actualPath); + updatePath(name); + + builder.setPath(createActualSchemaPath(actualPath, namespace, revision, + yangModelPrefix)); + parseSchemaNodeArgs(ctx, builder); + } + + @Override + public void exitIdentifier_stmt(YangParser.Identifier_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterRpc_stmt(YangParser.Rpc_stmtContext ctx) { + final String rpcName = stringFromNode(ctx); + QName rpcQName = new QName(namespace, revision, yangModelPrefix, + rpcName); + RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName, + actualPath); + updatePath(rpcName); + + rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, rpcBuilder); + } + + @Override + public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterInput_stmt(YangParser.Input_stmtContext ctx) { + updatePath("input"); + } + + @Override + public void exitInput_stmt(YangParser.Input_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterOutput_stmt(YangParser.Output_stmtContext ctx) { + updatePath("output"); + } + + @Override + public void exitOutput_stmt(YangParser.Output_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterFeature_stmt(YangParser.Feature_stmtContext ctx) { + final String featureName = stringFromNode(ctx); + QName featureQName = new QName(namespace, revision, yangModelPrefix, + featureName); + FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName, + actualPath); + updatePath(featureName); + + featureBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, featureBuilder); + } + + @Override + public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterDeviation_stmt(YangParser.Deviation_stmtContext ctx) { + final String targetPath = stringFromNode(ctx); + String reference = null; + String deviate = null; + DeviationBuilder builder = moduleBuilder.addDeviation(targetPath, actualPath); + updatePath(targetPath); + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } else if (child instanceof Deviate_not_supported_stmtContext) { + deviate = stringFromNode(child); + } else if (child instanceof Deviate_add_stmtContext) { + deviate = stringFromNode(child); + } else if (child instanceof Deviate_replace_stmtContext) { + deviate = stringFromNode(child); + } else if (child instanceof Deviate_delete_stmtContext) { + deviate = stringFromNode(child); + } + } + builder.setReference(reference); + builder.setDeviate(deviate); + } + + @Override + public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterConfig_stmt(YangParser.Config_stmtContext ctx) { + boolean configuration = parseConfig(ctx); + moduleBuilder.addConfiguration(configuration, actualPath); + } + + @Override + public void enterIdentity_stmt(YangParser.Identity_stmtContext ctx) { + final String identityName = stringFromNode(ctx); + final QName identityQName = new QName(namespace, revision, + yangModelPrefix, identityName); + IdentitySchemaNodeBuilder builder = moduleBuilder + .addIdentity(identityQName); + updatePath(identityName); + + builder.setPath(createActualSchemaPath(actualPath, namespace, revision, + yangModelPrefix)); + parseSchemaNodeArgs(ctx, builder); + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Base_stmtContext) { + String baseIdentityName = stringFromNode(child); + builder.setBaseIdentityName(baseIdentityName); + } + } + } + + @Override + public void exitIdentity_stmt(YangParser.Identity_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + public ModuleBuilder getModuleBuilder() { + return moduleBuilder; + } + + private void updatePath(String containerName) { + actualPath.push(containerName); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/BitImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/BitImpl.java new file mode 100644 index 0000000000..7a4756b4e4 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/BitImpl.java @@ -0,0 +1,135 @@ +/* + * 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.controller.yang.model.parser.util; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition; +import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition.Bit; + +public final class BitImpl implements BitsTypeDefinition.Bit { + private final Long position; + private final QName qname; + private final SchemaPath schemaPath; + private final String description; + private final String reference; + private final Status status; + private List unknownNodes = Collections.emptyList(); + + BitImpl(final Long position, final QName qname, + final SchemaPath schemaPath, final String description, + final String reference, final Status status, + final List unknownNodes) { + this.position = position; + this.qname = qname; + this.schemaPath = schemaPath; + this.description = description; + this.reference = reference; + this.status = status; + if(unknownNodes != null) { + this.unknownNodes = unknownNodes; + } + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return schemaPath; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public Status getStatus() { + return status; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownNodes; + } + + @Override + public Long getPosition() { + return position; + } + + @Override + public String getName() { + return qname.getLocalName(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + + ((schemaPath == null) ? 0 : schemaPath.hashCode()); + result = prime * result + + ((position == null) ? 0 : position.hashCode()); + result = prime + * result + + ((unknownNodes == null) ? 0 : unknownNodes.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Bit other = (Bit) obj; + if (qname == null) { + if (other.getQName() != null) { + return false; + } + } else if (!qname.equals(other.getQName())) { + return false; + } + if (schemaPath == null) { + if (other.getPath() != null) { + return false; + } + } else if (!schemaPath.equals(other.getPath())) { + return false; + } + return true; + } + + @Override + public String toString() { + return Bit.class.getSimpleName() + "[name=" + + qname.getLocalName() + ", position=" + position + "]"; + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/MustDefinitionImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/MustDefinitionImpl.java new file mode 100644 index 0000000000..9758aa5a9d --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/MustDefinitionImpl.java @@ -0,0 +1,107 @@ +/* + * 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.controller.yang.model.parser.util; + +import org.opendaylight.controller.yang.model.api.MustDefinition; +import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; + +public final class MustDefinitionImpl implements MustDefinition { + private final String mustStr; + private final String description; + private final String reference; + private final String errorAppTag; + private final String errorMessage; + + public MustDefinitionImpl(String mustStr, String description, + String reference, String errorAppTag, String errorMessage) { + this.mustStr = mustStr; + this.description = description; + this.reference = reference; + this.errorAppTag = errorAppTag; + this.errorMessage = errorMessage; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getErrorAppTag() { + return errorAppTag; + } + + @Override + public String getErrorMessage() { + return errorMessage; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public RevisionAwareXPath getXpath() { + return null; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((mustStr == null) ? 0 : mustStr.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final MustDefinitionImpl other = (MustDefinitionImpl) obj; + if (mustStr == null) { + if (other.mustStr != null) { + return false; + } + } else if (!mustStr.equals(other.mustStr)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + return true; + } + + @Override + public String toString() { + return mustStr; + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/ParserUtils.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/ParserUtils.java new file mode 100644 index 0000000000..f533b8e6d7 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/ParserUtils.java @@ -0,0 +1,237 @@ +/* + * 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.controller.yang.model.parser.util; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.MustDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.AnyXmlBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceCaseBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ConstraintsBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ContainerSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.LeafListSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.LeafSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ListSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder; + +public final class ParserUtils { + + private ParserUtils() { + } + + public static SchemaPath parseUsesPath(final String usesPath) { + final boolean absolute = usesPath.startsWith("/"); + final String[] splittedPath = usesPath.split("/"); + final List path = new ArrayList(); + QName name; + for (String pathElement : splittedPath) { + if (pathElement.length() > 0) { + final String[] splittedElement = pathElement.split(":"); + if (splittedElement.length == 1) { + name = new QName(null, null, null, splittedElement[0]); + } else { + name = new QName(null, null, splittedElement[0], + splittedElement[1]); + } + path.add(name); + } + } + return new SchemaPath(path, absolute); + } + + public static LeafSchemaNodeBuilder copyLeafBuilder( + final LeafSchemaNodeBuilder old) { + final LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder( + old.getQName()); + final TypeDefinition type = old.getType(); + + if (type == null) { + copy.setType(old.getTypedef()); + } else { + copy.setType(type); + } + copy.setPath(old.getPath()); + copyConstraints(old, copy); + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + copy.setDescription(old.getDescription()); + copy.setReference(old.getReference()); + copy.setStatus(old.getStatus()); + copy.setAugmenting(old.isAugmenting()); + copy.setConfiguration(old.isConfiguration()); + copy.setDefaultStr(old.getDefaultStr()); + copy.setUnits(old.getUnits()); + return copy; + } + + public static ContainerSchemaNodeBuilder copyContainerBuilder( + final ContainerSchemaNodeBuilder old) { + final ContainerSchemaNodeBuilder copy = new ContainerSchemaNodeBuilder( + old.getQName()); + copy.setPath(old.getPath()); + copyConstraints(old, copy); + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + for (DataSchemaNodeBuilder child : old.getChildNodes()) { + copy.addChildNode(child); + } + for (GroupingBuilder grouping : old.getGroupings()) { + copy.addGrouping(grouping); + } + for (TypeDefinitionBuilder typedef : old.getTypedefs()) { + copy.addTypedef(typedef); + } + for (AugmentationSchemaBuilder augment : old.getAugmentations()) { + copy.addAugmentation(augment); + } + for (UsesNodeBuilder use : old.getUsesNodes()) { + copy.addUsesNode(use); + } + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + copy.setDescription(old.getDescription()); + copy.setReference(old.getReference()); + copy.setStatus(old.getStatus()); + copy.setAugmenting(old.isAugmenting()); + copy.setConfiguration(old.isConfiguration()); + copy.setPresence(old.isPresence()); + return copy; + } + + public static ListSchemaNodeBuilder copyListBuilder( + final ListSchemaNodeBuilder old) { + final ListSchemaNodeBuilder copy = new ListSchemaNodeBuilder( + old.getQName()); + copy.setPath(old.getPath()); + copyConstraints(old, copy); + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + for (DataSchemaNodeBuilder child : old.getChildNodes()) { + copy.addChildNode(child); + } + for (GroupingBuilder grouping : old.getGroupings()) { + copy.addGrouping(grouping); + } + for (TypeDefinitionBuilder typedef : old.getTypedefs()) { + copy.addTypedef(typedef); + } + for (AugmentationSchemaBuilder augment : old.getAugmentations()) { + copy.addAugmentation(augment); + } + for (UsesNodeBuilder use : old.getUsesNodes()) { + copy.addUsesNode(use); + } + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + copy.setDescription(old.getDescription()); + copy.setReference(old.getReference()); + copy.setStatus(old.getStatus()); + copy.setAugmenting(old.isAugmenting()); + copy.setConfiguration(old.isConfiguration()); + copy.setUserOrdered(old.isUserOrdered()); + return copy; + } + + public static LeafListSchemaNodeBuilder copyLeafListBuilder( + final LeafListSchemaNodeBuilder old) { + final LeafListSchemaNodeBuilder copy = new LeafListSchemaNodeBuilder( + old.getQName()); + copy.setPath(old.getPath()); + copyConstraints(old, copy); + final TypeDefinition type = old.getType(); + if (type == null) { + copy.setType(old.getTypedef()); + } else { + copy.setType(type); + } + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + copy.setDescription(old.getDescription()); + copy.setReference(old.getReference()); + copy.setStatus(old.getStatus()); + copy.setAugmenting(old.isAugmenting()); + copy.setConfiguration(old.isConfiguration()); + copy.setUserOrdered(old.isUserOrdered()); + return copy; + } + + public static ChoiceBuilder copyChoiceBuilder(final ChoiceBuilder old) { + final ChoiceBuilder copy = new ChoiceBuilder(old.getQName()); + copy.setPath(old.getPath()); + copyConstraints(old, copy); + for (ChoiceCaseBuilder caseBuilder : old.getCases()) { + copy.addChildNode(caseBuilder); + } + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + for (TypeDefinitionBuilder typedef : old.getTypedefs()) { + copy.addTypedef(typedef); + } + for (UsesNodeBuilder use : old.getUsesNodes()) { + copy.addUsesNode(use); + } + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + copy.setDefaultCase(old.getDefaultCase()); + copy.setDescription(old.getDescription()); + copy.setReference(old.getReference()); + copy.setStatus(old.getStatus()); + copy.setAugmenting(old.isAugmenting()); + copy.setConfiguration(old.isConfiguration()); + return copy; + } + + public static AnyXmlBuilder copyAnyXmlBuilder(final AnyXmlBuilder old) { + final AnyXmlBuilder copy = new AnyXmlBuilder(old.getQName()); + copy.setPath(old.getPath()); + copyConstraints(old, copy); + for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) { + copy.addUnknownSchemaNode(unknown); + } + copy.setDescription(old.getDescription()); + copy.setReference(old.getReference()); + copy.setStatus(old.getStatus()); + copy.setConfiguration(old.isConfiguration()); + return copy; + } + + private static void copyConstraints(final DataSchemaNodeBuilder oldBuilder, + final DataSchemaNodeBuilder newBuilder) { + final ConstraintsBuilder oldConstraints = oldBuilder.getConstraints(); + final ConstraintsBuilder newConstraints = newBuilder.getConstraints(); + newConstraints.addWhenCondition(oldConstraints.getWhenCondition()); + for (MustDefinition must : oldConstraints.getMustDefinitions()) { + newConstraints.addMustDefinition(must); + } + newConstraints.setMandatory(oldConstraints.isMandatory()); + newConstraints.setMinElements(oldConstraints.getMinElements()); + newConstraints.setMaxElements(oldConstraints.getMaxElements()); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/RefineHolder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/RefineHolder.java new file mode 100644 index 0000000000..19b6764e0a --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/RefineHolder.java @@ -0,0 +1,117 @@ +/* + * 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.controller.yang.model.parser.util; + +import org.opendaylight.controller.yang.model.api.MustDefinition; + +public final class RefineHolder { + private final String name; + private Refine type; + private String defaultStr; + private String description; + private String reference; + private Boolean config; + private Boolean mandatory; + private Boolean presence; + private MustDefinition must; + private Integer minElements; + private Integer maxElements; + + public RefineHolder(final String name) { + this.name = name; + } + + public Refine getType() { + return type; + } + + public void setType(final Refine type) { + this.type = type; + } + + public String getDefaultStr() { + return defaultStr; + } + + public void setDefaultStr(final String defaultStr) { + this.defaultStr = defaultStr; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public String getReference() { + return reference; + } + + public void setReference(final String reference) { + this.reference = reference; + } + + public Boolean isConfig() { + return config; + } + + public void setConfig(final Boolean config) { + this.config = config; + } + + public Boolean isMandatory() { + return mandatory; + } + + public void setMandatory(Boolean mandatory) { + this.mandatory = mandatory; + } + + public Boolean isPresence() { + return presence; + } + + public void setPresence(Boolean presence) { + this.presence = presence; + } + + public MustDefinition getMust() { + return must; + } + + public void setMust(MustDefinition must) { + this.must = must; + } + + public Integer getMinElements() { + return minElements; + } + + public void setMinElements(Integer minElements) { + this.minElements = minElements; + } + + public Integer getMaxElements() { + return maxElements; + } + + public void setMaxElements(Integer maxElements) { + this.maxElements = maxElements; + } + + public String getName() { + return name; + } + + public enum Refine { + CONTAINER, LEAF, LIST, LEAF_LIST, CHOICE, ANYXML + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/TypeConstraints.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/TypeConstraints.java index 0f26da886b..360d8ea897 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/TypeConstraints.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/TypeConstraints.java @@ -31,11 +31,10 @@ public final class TypeConstraints { public List getRange() { if(ranges.isEmpty()) { - List result = Collections.emptyList(); - return result; + return Collections.emptyList(); } - List resolved = ranges.get(0); + final List resolved = ranges.get(0); RangeConstraint firstRange = resolved.get(0); RangeConstraint lastRange = resolved.get(resolved.size() - 1); Number min = firstRange.getMin(); @@ -46,7 +45,7 @@ public final class TypeConstraints { return resolved; } - if (firstRange == lastRange) { + if (firstRange.equals(lastRange)) { if (min instanceof UnknownBoundaryNumber) { min = resolveMinRange(min); } @@ -81,7 +80,7 @@ public final class TypeConstraints { private Number resolveMinRange(Number min) { int i = 1; while (min instanceof UnknownBoundaryNumber) { - List act = ranges.get(i); + final List act = ranges.get(i); min = act.get(0).getMin(); i++; } @@ -91,15 +90,15 @@ public final class TypeConstraints { private Number resolveMaxRange(Number max) { int i = 1; while (max instanceof UnknownBoundaryNumber) { - List act = ranges.get(i); + final List act = ranges.get(i); max = act.get(act.size() - 1).getMax(); i++; } return max; } - public void addRanges(List ranges) { - if (ranges != null && ranges.size() > 0) { + public void addRanges(final List ranges) { + if (ranges != null && !(ranges.isEmpty())) { this.ranges.add(ranges); } } @@ -110,11 +109,10 @@ public final class TypeConstraints { public List getLength() { if(lengths.isEmpty()) { - List result = Collections.emptyList(); - return result; + return Collections.emptyList(); } - List resolved = lengths.get(0); + final List resolved = lengths.get(0); LengthConstraint firstLength = resolved.get(0); LengthConstraint lastLength = resolved.get(resolved.size() - 1); Number min = firstLength.getMin(); @@ -125,7 +123,7 @@ public final class TypeConstraints { return resolved; } - if (firstLength == lastLength) { + if (firstLength.equals(lastLength)) { if (min instanceof UnknownBoundaryNumber) { min = resolveMinLength(min); } @@ -160,7 +158,7 @@ public final class TypeConstraints { private Number resolveMinLength(Number min) { int i = 1; while (min instanceof UnknownBoundaryNumber) { - List act = lengths.get(i); + final List act = lengths.get(i); min = act.get(0).getMin(); i++; } @@ -170,15 +168,15 @@ public final class TypeConstraints { private Number resolveMaxLength(Number max) { int i = 1; while (max instanceof UnknownBoundaryNumber) { - List act = lengths.get(i); + final List act = lengths.get(i); max = act.get(act.size() - 1).getMax(); i++; } return max; } - public void addLengths(List lengths) { - if (lengths != null && lengths.size() > 0) { + public void addLengths(final List lengths) { + if (lengths != null && !(lengths.isEmpty())) { this.lengths.add(lengths); } } @@ -187,7 +185,7 @@ public final class TypeConstraints { return patterns; } - public void addPatterns(List patterns) { + public void addPatterns(final List patterns) { this.patterns.addAll(patterns); } @@ -195,7 +193,7 @@ public final class TypeConstraints { return fractionDigits; } - public void setFractionDigits(Integer fractionDigits) { + public void setFractionDigits(final Integer fractionDigits) { if (this.fractionDigits == null) { this.fractionDigits = fractionDigits; } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/UnknownBoundaryNumber.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/UnknownBoundaryNumber.java index 27127f00ba..14884d2302 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/UnknownBoundaryNumber.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/UnknownBoundaryNumber.java @@ -15,7 +15,7 @@ public final class UnknownBoundaryNumber extends Number { private final String value; - UnknownBoundaryNumber(String value) { + UnknownBoundaryNumber(final String value) { this.value = value; } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java index c802d3bf74..a01565fd6b 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java @@ -22,9 +22,12 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bits_specificatio import org.opendaylight.controller.antlrv4.code.gen.YangParser.Config_argContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Config_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Decimal64_specificationContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Default_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Description_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Enum_specificationContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Enum_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Error_app_tag_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Error_message_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Fraction_digits_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leafref_specificationContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Length_stmtContext; @@ -39,8 +42,17 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_stmtCo import org.opendaylight.controller.antlrv4.code.gen.YangParser.Path_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Pattern_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Position_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Presence_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Range_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Reference_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Refine_anyxml_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Refine_choice_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Refine_container_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Refine_leaf_list_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Refine_leaf_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Refine_list_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Refine_pomContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Refine_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Require_instance_argContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Require_instance_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_argContext; @@ -49,10 +61,13 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.StringContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.String_restrictionsContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Uses_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Value_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yin_element_argContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yin_element_stmtContext; import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.MustDefinition; import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; @@ -61,11 +76,13 @@ import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition; import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition.Bit; import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition; +import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair; import org.opendaylight.controller.yang.model.api.type.LengthConstraint; import org.opendaylight.controller.yang.model.api.type.PatternConstraint; import org.opendaylight.controller.yang.model.api.type.RangeConstraint; import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.ConstraintsBuilder; +import org.opendaylight.controller.yang.model.parser.util.RefineHolder.Refine; import org.opendaylight.controller.yang.model.util.BaseConstraints; import org.opendaylight.controller.yang.model.util.BinaryType; import org.opendaylight.controller.yang.model.util.BitsType; @@ -84,6 +101,9 @@ public final class YangModelBuilderUtil { private static final Logger logger = LoggerFactory .getLogger(YangModelBuilderUtil.class); + private YangModelBuilderUtil() { + } + /** * Parse given tree and get first string value. * @@ -193,7 +213,7 @@ public final class YangModelBuilderUtil { URI namespace, Date revision, String prefix) { final List path = new ArrayList(); QName qname; - // start from index 1 - module name omitted + // start from index 1 - module name omited for (int i = 1; i < actualPath.size(); i++) { qname = new QName(namespace, revision, prefix, actualPath.get(i)); path.add(qname); @@ -257,23 +277,37 @@ public final class YangModelBuilderUtil { return key; } + /** + * Parse given type body of enumeration statement. + * + * @param ctx + * type body context to parse + * @param path + * actual position in YANG model + * @param namespace + * @param revision + * @param prefix + * @return List of EnumPair object parsed from given context + */ private static List getEnumConstants( Type_body_stmtsContext ctx, List path, URI namespace, Date revision, String prefix) { List enumConstants = new ArrayList(); - out: for (int j = 0; j < ctx.getChildCount(); j++) { + for (int j = 0; j < ctx.getChildCount(); j++) { ParseTree enumSpecChild = ctx.getChild(j); if (enumSpecChild instanceof Enum_specificationContext) { + int highestValue = -1; for (int k = 0; k < enumSpecChild.getChildCount(); k++) { ParseTree enumChild = enumSpecChild.getChild(k); if (enumChild instanceof Enum_stmtContext) { - enumConstants.add(createEnumPair( - (Enum_stmtContext) enumChild, k, path, - namespace, revision, prefix)); - if (k == enumSpecChild.getChildCount() - 1) { - break out; + EnumPair enumPair = createEnumPair( + (Enum_stmtContext) enumChild, highestValue, + path, namespace, revision, prefix); + if (enumPair.getValue() > highestValue) { + highestValue = enumPair.getValue(); } + enumConstants.add(enumPair); } } } @@ -281,20 +315,40 @@ public final class YangModelBuilderUtil { return enumConstants; } + /** + * Parse enum statement context + * + * @param ctx + * enum statement context + * @param highestValue + * current highest value in enumeration + * @param path + * actual position in YANG model + * @param namespace + * @param revision + * @param prefix + * @return EnumPair object parsed from given context + */ private static EnumTypeDefinition.EnumPair createEnumPair( - Enum_stmtContext ctx, final int value, List path, + Enum_stmtContext ctx, final int highestValue, List path, final URI namespace, final Date revision, final String prefix) { final String name = stringFromNode(ctx); final QName qname = new QName(namespace, revision, prefix, name); + Integer value = null; + String description = null; String reference = null; Status status = null; + List enumPairPath = new ArrayList(path); enumPairPath.add(name); for (int i = 0; i < ctx.getChildCount(); i++) { ParseTree child = ctx.getChild(i); - if (child instanceof Description_stmtContext) { + if (child instanceof Value_stmtContext) { + String valueStr = stringFromNode(child); + value = Integer.valueOf(valueStr); + } else if (child instanceof Description_stmtContext) { description = stringFromNode(child); } else if (child instanceof Reference_stmtContext) { reference = stringFromNode(child); @@ -303,6 +357,17 @@ public final class YangModelBuilderUtil { } } + if (value == null) { + value = highestValue + 1; + } + if (value < -2147483648 || value > 2147483647) { + throw new YangParseException( + "Error on enum '" + + name + + "': the enum value MUST be in the range from -2147483648 to 2147483647, but was: " + + value); + } + EnumPairImpl result = new EnumPairImpl(); result.qname = qname; result.path = createActualSchemaPath(enumPairPath, namespace, revision, @@ -315,6 +380,9 @@ public final class YangModelBuilderUtil { return result; } + /** + * Internal implementation of EnumPair. + */ private static class EnumPairImpl implements EnumTypeDefinition.EnumPair { private QName qname; private SchemaPath path; @@ -436,20 +504,26 @@ public final class YangModelBuilderUtil { return EnumTypeDefinition.EnumPair.class.getSimpleName() + "[name=" + name + ", value=" + value + "]"; } - }; + } + /** + * Get and parse range from given type body context. + * + * @param ctx + * type body context to parse + * @return List of RangeConstraint created from this context + */ private static List getRangeConstraints( Type_body_stmtsContext ctx) { - final List rangeConstraints = new ArrayList(); - for (int j = 0; j < ctx.getChildCount(); j++) { + List rangeConstraints = Collections.emptyList(); + outer: for (int j = 0; j < ctx.getChildCount(); j++) { ParseTree numRestrChild = ctx.getChild(j); if (numRestrChild instanceof Numerical_restrictionsContext) { for (int k = 0; k < numRestrChild.getChildCount(); k++) { ParseTree rangeChild = numRestrChild.getChild(k); if (rangeChild instanceof Range_stmtContext) { - rangeConstraints - .addAll(parseRangeConstraints((Range_stmtContext) rangeChild)); - break; + rangeConstraints = parseRangeConstraints((Range_stmtContext) rangeChild); + break outer; } } } @@ -457,6 +531,13 @@ public final class YangModelBuilderUtil { return rangeConstraints; } + /** + * Parse given range context. + * + * @param ctx + * range context to parse + * @return List of RangeConstraints parsed from this context + */ private static List parseRangeConstraints( Range_stmtContext ctx) { List rangeConstraints = new ArrayList(); @@ -480,10 +561,10 @@ public final class YangModelBuilderUtil { Number min; Number max; if (splittedRangeDef.length == 1) { - min = max = parseRangeValue(splittedRangeDef[0]); + min = max = parseNumberConstraintValue(splittedRangeDef[0]); } else { - min = parseRangeValue(splittedRangeDef[0]); - max = parseRangeValue(splittedRangeDef[1]); + min = parseNumberConstraintValue(splittedRangeDef[0]); + max = parseNumberConstraintValue(splittedRangeDef[1]); } RangeConstraint range = BaseConstraints.rangeConstraint(min, max, description, reference); @@ -493,17 +574,24 @@ public final class YangModelBuilderUtil { return rangeConstraints; } + /** + * Get and parse length from given type body context. + * + * @param ctx + * type body context to parse + * @return List of LengthConstraint created from this context + */ private static List getLengthConstraints( Type_body_stmtsContext ctx) { - List lengthConstraints = new ArrayList(); - for (int j = 0; j < ctx.getChildCount(); j++) { + List lengthConstraints = Collections.emptyList(); + outer: for (int j = 0; j < ctx.getChildCount(); j++) { ParseTree stringRestrChild = ctx.getChild(j); if (stringRestrChild instanceof String_restrictionsContext) { for (int k = 0; k < stringRestrChild.getChildCount(); k++) { ParseTree lengthChild = stringRestrChild.getChild(k); if (lengthChild instanceof Length_stmtContext) { - lengthConstraints - .addAll(parseLengthConstraints((Length_stmtContext) lengthChild)); + lengthConstraints = parseLengthConstraints((Length_stmtContext) lengthChild); + break outer; } } } @@ -511,6 +599,13 @@ public final class YangModelBuilderUtil { return lengthConstraints; } + /** + * Parse given length context. + * + * @param ctx + * length context to parse + * @return List of LengthConstraints parsed from this context + */ private static List parseLengthConstraints( Length_stmtContext ctx) { List lengthConstraints = new ArrayList(); @@ -534,10 +629,10 @@ public final class YangModelBuilderUtil { Number min; Number max; if (splittedRangeDef.length == 1) { - min = max = parseRangeValue(splittedRangeDef[0]); + min = max = parseNumberConstraintValue(splittedRangeDef[0]); } else { - min = parseRangeValue(splittedRangeDef[0]); - max = parseRangeValue(splittedRangeDef[1]); + min = parseNumberConstraintValue(splittedRangeDef[0]); + max = parseNumberConstraintValue(splittedRangeDef[1]); } LengthConstraint range = BaseConstraints.lengthConstraint(min, max, description, reference); @@ -547,7 +642,13 @@ public final class YangModelBuilderUtil { return lengthConstraints; } - private static Number parseRangeValue(String value) { + /** + * @param value + * value to parse + * @return wrapper object of primitive java type or UnknownBoundaryNumber if + * type is one of special YANG values 'min' or 'max' + */ + private static Number parseNumberConstraintValue(String value) { Number result = null; if ("min".equals(value) || "max".equals(value)) { result = new UnknownBoundaryNumber(value); @@ -566,7 +667,7 @@ public final class YangModelBuilderUtil { Type_body_stmtsContext ctx) { List patterns = new ArrayList(); - out: for (int j = 0; j < ctx.getChildCount(); j++) { + outer: for (int j = 0; j < ctx.getChildCount(); j++) { ParseTree stringRestrChild = ctx.getChild(j); if (stringRestrChild instanceof String_restrictionsContext) { for (int k = 0; k < stringRestrChild.getChildCount(); k++) { @@ -574,7 +675,7 @@ public final class YangModelBuilderUtil { if (lengthChild instanceof Pattern_stmtContext) { patterns.add(parsePatternConstraint((Pattern_stmtContext) lengthChild)); if (k == lengthChild.getChildCount() - 1) { - break out; + break outer; } } } @@ -631,6 +732,14 @@ public final class YangModelBuilderUtil { return result.toString(); } + /** + * Get fraction digits value from context. + * + * @param ctx + * type body context to parse + * @return 'fraction-digits' value if present in given context, null + * otherwise + */ private static Integer getFractionDigits(Type_body_stmtsContext ctx) { Integer result = null; for (int j = 0; j < ctx.getChildCount(); j++) { @@ -661,10 +770,22 @@ public final class YangModelBuilderUtil { return result; } + /** + * Internal helper method for parsing bit statements from given type body context. + * + * @param ctx + * type body context to parse + * @param actualPath + * current position in YANG model + * @param namespace + * @param revision + * @param prefix + * @return List of Bit objects created from this context + */ private static List getBits( Type_body_stmtsContext ctx, List actualPath, URI namespace, Date revision, String prefix) { - List bits = new ArrayList(); + final List bits = new ArrayList(); for (int j = 0; j < ctx.getChildCount(); j++) { ParseTree bitsSpecChild = ctx.getChild(j); if (bitsSpecChild instanceof Bits_specificationContext) { @@ -686,6 +807,20 @@ public final class YangModelBuilderUtil { return bits; } + /** + * Internal helper method for parsing bit context. + * + * @param ctx + * bit statement context to parse + * @param highestPosition + * current highest position in bits type + * @param actualPath + * current position in YANG model + * @param namespace + * @param revision + * @param prefix + * @return Bit object parsed from this context + */ private static BitsTypeDefinition.Bit parseBit(final Bit_stmtContext ctx, long highestPosition, List actualPath, final URI namespace, final Date revision, final String prefix) { @@ -728,122 +863,8 @@ public final class YangModelBuilderUtil { + "': the position value MUST be in the range 0 to 4294967295"); } - final List extensionNodes = Collections.emptyList(); - return createBit(qname, schemaPath, description, reference, status, - extensionNodes, position); - } - - private static BitsTypeDefinition.Bit createBit(final QName qname, - final SchemaPath schemaPath, final String description, - final String reference, final Status status, - final List unknownNodes, final Long position) { - return new BitsTypeDefinition.Bit() { - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return schemaPath; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public String getReference() { - return reference; - } - - @Override - public Status getStatus() { - return status; - } - - @Override - public List getUnknownSchemaNodes() { - return unknownNodes; - } - - @Override - public Long getPosition() { - return position; - } - - @Override - public String getName() { - return qname.getLocalName(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((qname == null) ? 0 : qname.hashCode()); - result = prime * result - + ((schemaPath == null) ? 0 : schemaPath.hashCode()); - result = prime * result - + ((position == null) ? 0 : position.hashCode()); - result = prime - * result - + ((unknownNodes == null) ? 0 : unknownNodes.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Bit other = (Bit) obj; - if (qname == null) { - if (other.getQName() != null) { - return false; - } - } else if (!qname.equals(other.getQName())) { - return false; - } - if (schemaPath == null) { - if (other.getPath() != null) { - return false; - } - } else if (!schemaPath.equals(other.getPath())) { - return false; - } - if (unknownNodes == null) { - if (other.getUnknownSchemaNodes() != null) { - return false; - } - } else if (!unknownNodes.equals(other.getUnknownSchemaNodes())) { - return false; - } - if (position == null) { - if (other.getPosition() != null) { - return false; - } - } else if (!position.equals(other.getPosition())) { - return false; - } - return true; - } - - @Override - public String toString() { - return Bit.class.getSimpleName() + "[name=" - + qname.getLocalName() + ", position=" + position + "]"; - } - }; + final List unknownNodes = Collections.emptyList(); + return new BitImpl(position, qname, schemaPath, description, reference, status, unknownNodes); } /** @@ -1020,50 +1041,58 @@ public final class YangModelBuilderUtil { * * @param ctx * Must_stmtContext - * @return an array of strings with following fields: [0] must text [1] - * description [2] reference + * @return MustDefinition object based on parsed context */ - public static String[] parseMust(YangParser.Must_stmtContext ctx) { - String[] params = new String[3]; - + public static MustDefinition parseMust(YangParser.Must_stmtContext ctx) { StringBuilder mustText = new StringBuilder(); String description = null; String reference = null; + String errorAppTag = null; + String errorMessage = null; for (int i = 0; i < ctx.getChildCount(); ++i) { ParseTree child = ctx.getChild(i); if (child instanceof StringContext) { final StringContext context = (StringContext) child; - for (int j = 0; j < context.getChildCount(); j++) { - String mustPart = context.getChild(j).getText(); - if (j == 0) { - mustText.append(mustPart.substring(0, - mustPart.length() - 1)); - continue; - } - if (j % 2 == 0) { - mustText.append(mustPart.substring(1)); + if (context.getChildCount() == 1) { + String mustPart = context.getChild(0).getText(); + // trim start and end quotation + mustText.append(mustPart.substring(1, mustPart.length() - 1)); + } else { + for (int j = 0; j < context.getChildCount(); j++) { + String mustPart = context.getChild(j).getText(); + if (j == 0) { + mustText.append(mustPart.substring(0, + mustPart.length() - 1)); + continue; + } + if (j % 2 == 0) { + mustText.append(mustPart.substring(1)); + } } } } else if (child instanceof Description_stmtContext) { description = stringFromNode(child); } else if (child instanceof Reference_stmtContext) { reference = stringFromNode(child); + } else if (child instanceof Error_app_tag_stmtContext) { + errorAppTag = stringFromNode(child); + } else if (child instanceof Error_message_stmtContext) { + errorMessage = stringFromNode(child); } } - params[0] = mustText.toString(); - params[1] = description; - params[2] = reference; - return params; + MustDefinition must = new MustDefinitionImpl(mustText.toString(), + description, reference, errorAppTag, errorMessage); + return must; } /** * Parse given tree and set constraints to given builder. * * @param ctx - * Context to search. + * context to search * @param constraintsBuilder - * ConstraintsBuilder to fill. + * ConstraintsBuilder to fill */ public static void parseConstraints(ParseTree ctx, ConstraintsBuilder constraintsBuilder) { @@ -1076,9 +1105,8 @@ public final class YangModelBuilderUtil { Integer min = Integer.valueOf(stringFromNode(childNode)); constraintsBuilder.setMinElements(min); } else if (childNode instanceof Must_stmtContext) { - String[] mustParams = parseMust((Must_stmtContext) childNode); - constraintsBuilder.addMustDefinition(mustParams[0], - mustParams[1], mustParams[2]); + MustDefinition must = parseMust((Must_stmtContext) childNode); + constraintsBuilder.addMustDefinition(must); } else if (childNode instanceof Mandatory_stmtContext) { for (int j = 0; j < childNode.getChildCount(); j++) { ParseTree mandatoryTree = ctx.getChild(j); @@ -1121,4 +1149,170 @@ public final class YangModelBuilderUtil { return yinValue; } + public static List parseRefines(Uses_stmtContext ctx) { + List refines = new ArrayList(); + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Refine_stmtContext) { + String refineTarget = stringFromNode(child); + RefineHolder refine = new RefineHolder(refineTarget); + for (int j = 0; j < child.getChildCount(); j++) { + ParseTree refinePom = child.getChild(j); + if (refinePom instanceof Refine_pomContext) { + for (int k = 0; k < refinePom.getChildCount(); k++) { + ParseTree refineStmt = refinePom.getChild(k); + if (refineStmt instanceof Refine_leaf_stmtsContext) { + parseRefine(refine, + (Refine_leaf_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_container_stmtsContext) { + parseRefine( + refine, + (Refine_container_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_list_stmtsContext) { + parseRefine(refine, + (Refine_list_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) { + parseRefine( + refine, + (Refine_leaf_list_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_choice_stmtsContext) { + parseRefine(refine, + (Refine_choice_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_anyxml_stmtsContext) { + parseRefine(refine, + (Refine_anyxml_stmtsContext) refineStmt); + } + } + } + } + refines.add(refine); + } + } + return refines; + } + + private static RefineHolder parseRefine(RefineHolder refine, + Refine_leaf_stmtsContext refineStmt) { + refine.setType(Refine.LEAF); + for (int i = 0; i < refineStmt.getChildCount(); i++) { + ParseTree refineArg = refineStmt.getChild(i); + if (refineArg instanceof Default_stmtContext) { + String defaultStr = stringFromNode(refineArg); + refine.setDefaultStr(defaultStr); + } else if (refineArg instanceof Mandatory_stmtContext) { + for (int j = 0; j < refineArg.getChildCount(); j++) { + ParseTree mandatoryTree = refineArg.getChild(j); + if (mandatoryTree instanceof Mandatory_argContext) { + Boolean mandatory = Boolean + .valueOf(stringFromNode(mandatoryTree)); + refine.setMandatory(mandatory); + } + } + } else if (refineArg instanceof Must_stmtContext) { + MustDefinition must = parseMust((Must_stmtContext) refineArg); + refine.setMust(must); + + } + } + return refine; + } + + private static RefineHolder parseRefine(RefineHolder refine, + Refine_container_stmtsContext refineStmt) { + refine.setType(Refine.CONTAINER); + for (int m = 0; m < refineStmt.getChildCount(); m++) { + ParseTree refineArg = refineStmt.getChild(m); + if (refineArg instanceof Must_stmtContext) { + MustDefinition must = parseMust((Must_stmtContext) refineArg); + refine.setMust(must); + } else if (refineArg instanceof Presence_stmtContext) { + refine.setPresence(true); + } + } + return refine; + } + + private static RefineHolder parseRefine(RefineHolder refine, + Refine_list_stmtsContext refineStmt) { + refine.setType(Refine.LIST); + for (int m = 0; m < refineStmt.getChildCount(); m++) { + ParseTree refineArg = refineStmt.getChild(m); + if (refineArg instanceof Must_stmtContext) { + MustDefinition must = parseMust((Must_stmtContext) refineArg); + refine.setMust(must); + } else if (refineArg instanceof Max_elements_stmtContext) { + Integer max = Integer.valueOf(stringFromNode(refineArg)); + refine.setMinElements(max); + } else if (refineArg instanceof Min_elements_stmtContext) { + Integer min = Integer.valueOf(stringFromNode(refineArg)); + refine.setMinElements(min); + } + } + return refine; + } + + private static RefineHolder parseRefine(RefineHolder refine, + Refine_leaf_list_stmtsContext refineStmt) { + refine.setType(Refine.LEAF_LIST); + for (int m = 0; m < refineStmt.getChildCount(); m++) { + ParseTree refineArg = refineStmt.getChild(m); + if (refineArg instanceof Must_stmtContext) { + MustDefinition must = parseMust((Must_stmtContext) refineArg); + refine.setMust(must); + } else if (refineArg instanceof Max_elements_stmtContext) { + Integer max = Integer.valueOf(stringFromNode(refineArg)); + refine.setMinElements(max); + } else if (refineArg instanceof Min_elements_stmtContext) { + Integer min = Integer.valueOf(stringFromNode(refineArg)); + refine.setMinElements(min); + } + } + return refine; + } + + private static RefineHolder parseRefine(RefineHolder refine, + Refine_choice_stmtsContext refineStmt) { + refine.setType(Refine.CHOICE); + for (int i = 0; i < refineStmt.getChildCount(); i++) { + ParseTree refineArg = refineStmt.getChild(i); + if (refineArg instanceof Default_stmtContext) { + String defaultStr = stringFromNode(refineArg); + refine.setDefaultStr(defaultStr); + } else if (refineArg instanceof Mandatory_stmtContext) { + for (int j = 0; j < refineArg.getChildCount(); j++) { + ParseTree mandatoryTree = refineArg.getChild(j); + if (mandatoryTree instanceof Mandatory_argContext) { + Boolean mandatory = Boolean + .valueOf(stringFromNode(mandatoryTree)); + refine.setMandatory(mandatory); + } + } + } + } + return refine; + } + + private static RefineHolder parseRefine(RefineHolder refine, + Refine_anyxml_stmtsContext refineStmt) { + refine.setType(Refine.ANYXML); + for (int i = 0; i < refineStmt.getChildCount(); i++) { + ParseTree refineArg = refineStmt.getChild(i); + if (refineArg instanceof Must_stmtContext) { + MustDefinition must = parseMust((Must_stmtContext) refineArg); + refine.setMust(must); + } else if (refineArg instanceof Mandatory_stmtContext) { + for (int j = 0; j < refineArg.getChildCount(); j++) { + ParseTree mandatoryTree = refineArg.getChild(j); + if (mandatoryTree instanceof Mandatory_argContext) { + Boolean mandatory = Boolean + .valueOf(stringFromNode(mandatoryTree)); + refine.setMandatory(mandatory); + } + } + } + } + return refine; + } + } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangParseException.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangParseException.java index 331869a0f7..2c1b9b80d5 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangParseException.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangParseException.java @@ -11,11 +11,11 @@ public class YangParseException extends RuntimeException { private static final long serialVersionUID = 1239548963471793178L; - public YangParseException(String errorMsg) { + public YangParseException(final String errorMsg) { super(errorMsg); } - public YangParseException(String errorMsg, Exception exception) { + public YangParseException(final String errorMsg, final Exception exception) { super(errorMsg, exception); } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/TestUtils.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/TestUtils.java deleted file mode 100644 index f8627b2188..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/TestUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.controller.yang.model.parser.builder.impl; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.SchemaPath; - -public class TestUtils { - - private TestUtils() { - } - - public static SchemaPath createSchemaPath(boolean absolute, URI namespace, - String... path) { - List names = new ArrayList(); - QName qname; - for (String pathPart : path) { - qname = new QName(namespace, pathPart); - names.add(qname); - } - return new SchemaPath(names, absolute); - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/YangModelBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/YangModelBuilderTest.java deleted file mode 100644 index 2a1129399c..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/YangModelBuilderTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.controller.yang.model.parser.builder.impl; - -import static org.junit.Assert.*; - -import java.io.File; -import java.text.ParseException; -import java.util.Set; - -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.DataNodeContainer; -import org.opendaylight.controller.yang.model.api.LeafSchemaNode; -import org.opendaylight.controller.yang.model.api.Module; -import org.opendaylight.controller.yang.model.parser.impl.YangModelParserImpl; - -public class YangModelBuilderTest { - - private Set builtModules; - - @Before - public void init() { - builtModules = parseModules(); - } - - @Test - public void testAugment() throws ParseException { - for(Module module : builtModules) { - if(module.getName().equals("types2")) { - Set augmentations = module.getAugmentations(); - assertEquals(1, augmentations.size()); - AugmentationSchema augment = augmentations.iterator().next(); - LeafSchemaNode augmentedLeaf = (LeafSchemaNode)augment.getDataChildByName("ds0ChannelNumber"); - assertNotNull(augmentedLeaf); - assertTrue(augmentedLeaf.isAugmenting()); - } else if(module.getName().equals("types1")) { - DataNodeContainer interfaces = (DataNodeContainer)module.getDataChildByName("interfaces"); - DataNodeContainer ifEntry = (DataNodeContainer)interfaces.getDataChildByName("ifEntry"); - assertNotNull(ifEntry); - } else { - fail("unexpected module"); - } - } - } - - private Set parseModules() { - String yangFilesDir = "src/test/resources/model"; - File resourceDir = new File(yangFilesDir); - - String[] dirList = resourceDir.list(); - String[] absFiles = new String[dirList.length]; - - int i = 0; - for (String fileName : dirList) { - File abs = new File(resourceDir, fileName); - absFiles[i] = abs.getAbsolutePath(); - i++; - } - - YangModelParserImpl parser = new YangModelParserImpl(); - Set modules = parser.parseYangModels(absFiles); - - return modules; - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TestUtils.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TestUtils.java new file mode 100644 index 0000000000..8038bd858b --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TestUtils.java @@ -0,0 +1,100 @@ +/* + * 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.controller.yang.model.parser.impl; + +import java.io.File; +import java.net.URI; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.ModuleImport; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.parser.api.YangModelParser; + +final class TestUtils { + + private TestUtils() { + } + + public static Set loadModules(String resourceDirectory) { + YangModelParser parser = new YangModelParserImpl(); + File testDir = new File(resourceDirectory); + String[] fileList = testDir.list(); + String[] testFiles = new String[fileList.length]; + for (int i = 0; i < fileList.length; i++) { + String fileName = fileList[i]; + File file = new File(testDir, fileName); + testFiles[i] = file.getAbsolutePath(); + } + return parser.parseYangModels(testFiles); + } + + public static Module findModule(Set modules, String moduleName) { + Module result = null; + for (Module module : modules) { + if (module.getName().equals(moduleName)) { + result = module; + break; + } + } + return result; + } + + public static ModuleImport findImport(Set imports, + String prefix) { + ModuleImport result = null; + for (ModuleImport moduleImport : imports) { + if (moduleImport.getPrefix().equals(prefix)) { + result = moduleImport; + break; + } + } + return result; + } + + public static TypeDefinition findTypedef( + Set> typedefs, String name) { + TypeDefinition result = null; + for (TypeDefinition td : typedefs) { + if (td.getQName().getLocalName().equals(name)) { + result = td; + break; + } + } + return result; + } + + public static SchemaPath createPath(boolean absolute, URI namespace, + Date revision, String prefix, String... names) { + List path = new ArrayList(); + for (String name : names) { + path.add(new QName(namespace, revision, prefix, name)); + } + return new SchemaPath(path, absolute); + } + + public static Date createDate(String date) { + Date result; + final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + try { + result = simpleDateFormat.parse(date); + } catch (ParseException e) { + result = null; + } + return result; + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java index de9142e592..ea79e5d04b 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java @@ -9,21 +9,22 @@ package org.opendaylight.controller.yang.model.parser.impl; import static org.junit.Assert.*; -import java.io.File; +import java.net.URI; import java.util.List; import java.util.Set; import org.junit.Before; import org.junit.Test; +import org.opendaylight.controller.yang.common.QName; import org.opendaylight.controller.yang.model.api.IdentitySchemaNode; import org.opendaylight.controller.yang.model.api.LeafSchemaNode; import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.Status; import org.opendaylight.controller.yang.model.api.TypeDefinition; import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition.Bit; import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair; import org.opendaylight.controller.yang.model.api.type.LengthConstraint; import org.opendaylight.controller.yang.model.api.type.PatternConstraint; -import org.opendaylight.controller.yang.model.parser.api.YangModelParser; import org.opendaylight.controller.yang.model.util.BitsType; import org.opendaylight.controller.yang.model.util.EnumerationType; import org.opendaylight.controller.yang.model.util.ExtendedType; @@ -37,26 +38,16 @@ public class TypesResolutionTest { @Before public void init() { - YangModelParser parser = new YangModelParserImpl(); - File testDir = new File("src/test/resources/types"); - String[] fileList = testDir.list(); - String[] testFiles = new String[fileList.length]; - for (int i = 0; i < fileList.length; i++) { - String fileName = fileList[i]; - File file = new File(testDir, fileName); - testFiles[i] = file.getAbsolutePath(); - } - testedModules = parser.parseYangModels(testFiles); - assertEquals(fileList.length, testedModules.size()); + testedModules = TestUtils.loadModules("src/test/resources/types"); } @Test public void testIPVersion() { - Module tested = findModule(testedModules, "ietf-inet-types"); + Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); Set> typedefs = tested.getTypeDefinitions(); assertEquals(14, typedefs.size()); - TypeDefinition type = findTypedef(typedefs, "ip-version"); + TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-version"); assertTrue(type.getDescription().contains( "This value represents the version of the IP protocol.")); assertTrue(type.getReference().contains( @@ -86,15 +77,51 @@ public class TypesResolutionTest { value2.getDescription()); } + @Test + public void testEnumeration() { + Module tested = TestUtils.findModule(testedModules, "custom-types-test"); + Set> typedefs = tested.getTypeDefinitions(); + + TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-version"); + EnumerationType enumType = (EnumerationType) type.getBaseType(); + List values = enumType.getValues(); + assertEquals(4, values.size()); + + EnumPair value0 = values.get(0); + assertEquals("unknown", value0.getName()); + assertEquals(0, (int) value0.getValue()); + assertEquals( + "An unknown or unspecified version of the Internet protocol.", + value0.getDescription()); + + EnumPair value1 = values.get(1); + assertEquals("ipv4", value1.getName()); + assertEquals(19, (int) value1.getValue()); + assertEquals("The IPv4 protocol as defined in RFC 791.", + value1.getDescription()); + + EnumPair value2 = values.get(2); + assertEquals("ipv6", value2.getName()); + assertEquals(7, (int) value2.getValue()); + assertEquals("The IPv6 protocol as defined in RFC 2460.", + value2.getDescription()); + + EnumPair value3 = values.get(3); + assertEquals("default", value3.getName()); + assertEquals(20, (int) value3.getValue()); + assertEquals("default ip", + value3.getDescription()); + } + @Test public void testIpAddress() { - Module tested = findModule(testedModules, "ietf-inet-types"); + Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); Set> typedefs = tested.getTypeDefinitions(); - TypeDefinition type = findTypedef(typedefs, "ip-address"); + TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-address"); UnionType baseType = (UnionType) type.getBaseType(); List> unionTypes = baseType.getTypes(); - ExtendedType ipv4 = (ExtendedType)unionTypes.get(0); + ExtendedType ipv4 = (ExtendedType) unionTypes.get(0); StringType ipv4Base = (StringType) ipv4.getBaseType(); String expectedPattern = "(([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])" @@ -102,7 +129,7 @@ public class TypesResolutionTest { assertEquals(expectedPattern, ipv4Base.getPatterns().get(0) .getRegularExpression()); - ExtendedType ipv6 = (ExtendedType)unionTypes.get(1); + ExtendedType ipv6 = (ExtendedType) unionTypes.get(1); StringType ipv6Base = (StringType) ipv6.getBaseType(); List ipv6Patterns = ipv6Base.getPatterns(); expectedPattern = "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}" @@ -121,9 +148,9 @@ public class TypesResolutionTest { @Test public void testDomainName() { - Module tested = findModule(testedModules, "ietf-inet-types"); + Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); Set> typedefs = tested.getTypeDefinitions(); - TypeDefinition type = findTypedef(typedefs, "domain-name"); + TypeDefinition type = TestUtils.findTypedef(typedefs, "domain-name"); StringType baseType = (StringType) type.getBaseType(); List patterns = baseType.getPatterns(); assertEquals(1, patterns.size()); @@ -141,7 +168,8 @@ public class TypesResolutionTest { @Test public void testInstanceIdentifier1() { - Module tested = findModule(testedModules, "custom-types-test"); + Module tested = TestUtils + .findModule(testedModules, "custom-types-test"); LeafSchemaNode leaf = (LeafSchemaNode) tested .getDataChildByName("inst-id-leaf1"); InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType(); @@ -150,7 +178,8 @@ public class TypesResolutionTest { @Test public void testInstanceIdentifier2() { - Module tested = findModule(testedModules, "custom-types-test"); + Module tested = TestUtils + .findModule(testedModules, "custom-types-test"); LeafSchemaNode leaf = (LeafSchemaNode) tested .getDataChildByName("inst-id-leaf2"); InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType(); @@ -159,7 +188,8 @@ public class TypesResolutionTest { @Test public void testIdentity() { - Module tested = findModule(testedModules, "custom-types-test"); + Module tested = TestUtils + .findModule(testedModules, "custom-types-test"); Set identities = tested.getIdentities(); IdentitySchemaNode testedIdentity = null; for (IdentitySchemaNode id : identities) { @@ -176,7 +206,8 @@ public class TypesResolutionTest { @Test public void testBitsType1() { - Module tested = findModule(testedModules, "custom-types-test"); + Module tested = TestUtils + .findModule(testedModules, "custom-types-test"); LeafSchemaNode leaf = (LeafSchemaNode) tested .getDataChildByName("mybits"); BitsType leafType = (BitsType) leaf.getType(); @@ -198,9 +229,10 @@ public class TypesResolutionTest { @Test public void testBitsType2() { - Module tested = findModule(testedModules, "custom-types-test"); + Module tested = TestUtils + .findModule(testedModules, "custom-types-test"); Set> typedefs = tested.getTypeDefinitions(); - TypeDefinition testedType = findTypedef(typedefs, + TypeDefinition testedType = TestUtils.findTypedef(typedefs, "access-operations-type"); BitsType bitsType = (BitsType) testedType.getBaseType(); @@ -223,27 +255,76 @@ public class TypesResolutionTest { assertEquals(502L, (long) bit4.getPosition()); } - private Module findModule(Set modules, String name) { - Module result = null; - for (Module module : modules) { - if (module.getName().equals(name)) { - result = module; - break; - } - } - return result; + @Test + public void testIanaTimezones() { + Module tested = TestUtils.findModule(testedModules, "iana-timezones"); + Set> typedefs = tested.getTypeDefinitions(); + TypeDefinition testedType = TestUtils.findTypedef(typedefs, + "iana-timezone"); + + String expectedDesc = "A timezone location as defined by the IANA timezone\n database (http://www.iana.org/time-zones)"; + assertEquals(expectedDesc, testedType.getDescription()); + assertNull(testedType.getReference()); + assertEquals(Status.CURRENT, testedType.getStatus()); + + QName testedTypeQName = testedType.getQName(); + assertEquals(URI.create("urn:ietf:params:xml:ns:yang:iana-timezones"), + testedTypeQName.getNamespace()); + assertEquals(TestUtils.createDate("2012-07-09"), + testedTypeQName.getRevision()); + assertEquals("ianatz", testedTypeQName.getPrefix()); + assertEquals("iana-timezone", testedTypeQName.getLocalName()); + + EnumerationType enumType = (EnumerationType) testedType.getBaseType(); + List values = enumType.getValues(); + assertEquals(415, values.size()); // 0-414 + + EnumPair enum168 = values.get(168); + assertEquals("America/Danmarkshavn", enum168.getName()); + assertEquals(168, (int) enum168.getValue()); + assertEquals("east coast, north of Scoresbysund", + enum168.getDescription()); + + EnumPair enum374 = values.get(374); + assertEquals("America/Indiana/Winamac", enum374.getName()); + assertEquals(374, (int) enum374.getValue()); + assertEquals("Eastern Time - Indiana - Pulaski County", + enum374.getDescription()); } - private TypeDefinition findTypedef(Set> typedefs, - String name) { - TypeDefinition result = null; - for (TypeDefinition td : typedefs) { - if (td.getQName().getLocalName().equals(name)) { - result = td; - break; - } - } - return result; + @Test + public void testObjectId128() { + Module tested = TestUtils.findModule(testedModules, "ietf-yang-types"); + Set> typedefs = tested.getTypeDefinitions(); + ExtendedType testedType = (ExtendedType) TestUtils.findTypedef( + typedefs, "object-identifier-128"); + + QName testedTypeQName = testedType.getQName(); + assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), + testedTypeQName.getNamespace()); + assertEquals(TestUtils.createDate("2010-09-24"), + testedTypeQName.getRevision()); + assertEquals("yang", testedTypeQName.getPrefix()); + assertEquals("object-identifier-128", testedTypeQName.getLocalName()); + + ExtendedType testedTypeBase = (ExtendedType) testedType.getBaseType(); + + List patterns = testedTypeBase.getPatterns(); + assertEquals(2, patterns.size()); + PatternConstraint pattern1 = patterns.get(0); + assertEquals("\\d*(\\.\\d*){1,127}", pattern1.getRegularExpression()); + PatternConstraint pattern2 = patterns.get(1); + assertEquals( + "(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*", + pattern2.getRegularExpression()); + + QName testedTypeBaseQName = testedTypeBase.getQName(); + assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), + testedTypeBaseQName.getNamespace()); + assertEquals(TestUtils.createDate("2010-09-24"), + testedTypeBaseQName.getRevision()); + assertEquals("yang", testedTypeBaseQName.getPrefix()); + assertEquals("object-identifier", testedTypeBaseQName.getLocalName()); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.java index 650eaeab82..81ca4879df 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.java @@ -9,85 +9,278 @@ package org.opendaylight.controller.yang.model.parser.impl; import static org.junit.Assert.*; +import java.net.URI; +import java.util.ArrayList; +import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode; import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.ChoiceCaseNode; +import org.opendaylight.controller.yang.model.api.ChoiceNode; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; +import org.opendaylight.controller.yang.model.api.Deviation; +import org.opendaylight.controller.yang.model.api.Deviation.Deviate; +import org.opendaylight.controller.yang.model.api.ExtensionDefinition; +import org.opendaylight.controller.yang.model.api.FeatureDefinition; import org.opendaylight.controller.yang.model.api.LeafSchemaNode; import org.opendaylight.controller.yang.model.api.ListSchemaNode; import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.ModuleImport; +import org.opendaylight.controller.yang.model.api.MustDefinition; +import org.opendaylight.controller.yang.model.api.NotificationDefinition; +import org.opendaylight.controller.yang.model.api.RpcDefinition; +import org.opendaylight.controller.yang.model.api.SchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.api.UsesNode; import org.opendaylight.controller.yang.model.api.type.LengthConstraint; import org.opendaylight.controller.yang.model.api.type.PatternConstraint; import org.opendaylight.controller.yang.model.api.type.RangeConstraint; -import org.opendaylight.controller.yang.model.parser.api.YangModelParser; import org.opendaylight.controller.yang.model.util.Decimal64; import org.opendaylight.controller.yang.model.util.ExtendedType; import org.opendaylight.controller.yang.model.util.Int16; import org.opendaylight.controller.yang.model.util.Int32; import org.opendaylight.controller.yang.model.util.StringType; +import org.opendaylight.controller.yang.model.util.Uint32; import org.opendaylight.controller.yang.model.util.UnionType; public class YangModelParserTest { - - private static final String TEST_FILE1 = "src/test/resources/model/testfile1.yang"; - private static final String TEST_FILE2 = "src/test/resources/model/testfile2.yang"; - private YangModelParser tested; + private Set modules; @Before public void init() { - tested = new YangModelParserImpl(); + modules = TestUtils.loadModules("src/test/resources/model"); + assertEquals(3, modules.size()); } @Test - public void testAugment() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); - - Module testModule = findModule(modules, "types2"); - assertNotNull(testModule); - - AugmentationSchema augment = testModule.getAugmentations().iterator().next(); - assertNotNull(augment); + public void testHeaders() { + Module test = TestUtils.findModule(modules, "types1"); + + assertEquals("types1", test.getName()); + assertEquals("1", test.getYangVersion()); + URI expectedNamespace = URI.create("urn:simple.container.demo"); + assertEquals(expectedNamespace, test.getNamespace()); + assertEquals("t1", test.getPrefix()); + + Set imports = test.getImports(); + assertEquals(2, imports.size()); + + ModuleImport import2 = TestUtils.findImport(imports, "data"); + assertEquals("types2", import2.getModuleName()); + assertEquals(TestUtils.createDate("2013-02-27"), import2.getRevision()); + + ModuleImport import3 = TestUtils.findImport(imports, "t3"); + assertEquals("types3", import3.getModuleName()); + assertEquals(TestUtils.createDate("2013-02-27"), import3.getRevision()); + + assertEquals("opendaylight", test.getOrganization()); + assertEquals("http://www.opendaylight.org/", test.getContact()); + Date expectedRevision = TestUtils.createDate("2013-02-27"); + assertEquals(expectedRevision, test.getRevision()); + assertEquals(" WILL BE DEFINED LATER", test.getReference()); } @Test - public void testAugmentTarget() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); - - Module testModule = findModule(modules, "types1"); - assertNotNull(testModule); + public void testParseContainer() { + Module test = TestUtils.findModule(modules, "types2"); + URI expectedNamespace = URI.create("urn:simple.types.data.demo"); + String expectedPrefix = "t2"; + Date expectedRevision = TestUtils.createDate("2013-02-27"); + + ContainerSchemaNode interfaces = (ContainerSchemaNode) test + .getDataChildByName("interfaces"); + // test SchemaNode args + QName expectedQName = new QName(expectedNamespace, expectedRevision, + expectedPrefix, "interfaces"); + assertEquals(expectedQName, interfaces.getQName()); + SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, + expectedRevision, expectedPrefix, "interfaces"); + assertEquals(expectedPath, interfaces.getPath()); + assertNull(interfaces.getDescription()); + assertNull(interfaces.getReference()); + assertEquals(Status.CURRENT, interfaces.getStatus()); + assertEquals(0, interfaces.getUnknownSchemaNodes().size()); + // test DataSchemaNode args + assertFalse(interfaces.isAugmenting()); + assertFalse(interfaces.isConfiguration()); + ConstraintDefinition constraints = interfaces.getConstraints(); + assertNull(constraints.getWhenCondition()); + assertEquals(0, constraints.getMustConstraints().size()); + assertFalse(constraints.isMandatory()); + assertNull(constraints.getMinElements()); + assertNull(constraints.getMaxElements()); + // test AugmentationTarget args + assertEquals(0, interfaces.getAvailableAugmentations().size()); + // test ContainerSchemaNode args + assertFalse(interfaces.isPresenceContainer()); + // test DataNodeContainer args + assertEquals(0, interfaces.getTypeDefinitions().size()); + assertEquals(1, interfaces.getChildNodes().size()); + assertEquals(0, interfaces.getGroupings().size()); + assertEquals(0, interfaces.getUses().size()); + + ListSchemaNode ifEntry = (ListSchemaNode) interfaces + .getDataChildByName("ifEntry"); + assertNotNull(ifEntry); + } - ContainerSchemaNode container = (ContainerSchemaNode)testModule.getDataChildByName("interfaces"); - assertNotNull(container); + @Test + public void testParseList() { + Module test = TestUtils.findModule(modules, "types2"); + URI expectedNamespace = URI.create("urn:simple.types.data.demo"); + String expectedPrefix = "t2"; + Date expectedRevision = TestUtils.createDate("2013-02-27"); + + ContainerSchemaNode interfaces = (ContainerSchemaNode) test + .getDataChildByName("interfaces"); + + ListSchemaNode ifEntry = (ListSchemaNode) interfaces + .getDataChildByName("ifEntry"); + // test SchemaNode args + QName expectedQName = new QName(expectedNamespace, expectedRevision, + expectedPrefix, "ifEntry"); + assertEquals(expectedQName, ifEntry.getQName()); + SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, + expectedRevision, expectedPrefix, "interfaces", "ifEntry"); + assertEquals(expectedPath, ifEntry.getPath()); + assertNull(ifEntry.getDescription()); + assertNull(ifEntry.getReference()); + assertEquals(Status.CURRENT, ifEntry.getStatus()); + assertEquals(0, ifEntry.getUnknownSchemaNodes().size()); + // test DataSchemaNode args + assertFalse(ifEntry.isAugmenting()); + assertFalse(ifEntry.isConfiguration()); + ConstraintDefinition constraints = ifEntry.getConstraints(); + assertNull(constraints.getWhenCondition()); + assertEquals(0, constraints.getMustConstraints().size()); + assertFalse(constraints.isMandatory()); + assertNull(constraints.getMinElements()); + assertNull(constraints.getMaxElements()); + // test AugmentationTarget args + Set availableAugmentations = ifEntry + .getAvailableAugmentations(); + assertEquals(1, availableAugmentations.size()); + AugmentationSchema augment = availableAugmentations.iterator().next(); + ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment + .getDataChildByName("augment-holder"); + assertNotNull(augmentHolder); + // test ListSchemaNode args + List expectedKey = new ArrayList(); + expectedKey.add(new QName(expectedNamespace, expectedRevision, + expectedPrefix, "ifIndex")); + assertEquals(expectedKey, ifEntry.getKeyDefinition()); + assertFalse(ifEntry.isUserOrdered()); + // test DataNodeContainer args + assertEquals(0, ifEntry.getTypeDefinitions().size()); + assertEquals(3, ifEntry.getChildNodes().size()); + assertEquals(0, ifEntry.getGroupings().size()); + assertEquals(0, ifEntry.getUses().size()); + + LeafSchemaNode ifIndex = (LeafSchemaNode) ifEntry + .getDataChildByName("ifIndex"); + assertEquals(new Uint32(), ifIndex.getType()); + LeafSchemaNode ifMtu = (LeafSchemaNode) ifEntry + .getDataChildByName("ifMtu"); + assertEquals(new Int32(), ifMtu.getType()); + } - ListSchemaNode list = (ListSchemaNode)container.getDataChildByName("ifEntry"); - assertNotNull(list); - assertEquals(1, list.getAvailableAugmentations().size()); + @Test + public void testAugmentResolving() { + // testfile1 + Module module1 = TestUtils.findModule(modules, "types1"); + + Set module1Augmentations = module1 + .getAugmentations(); + AugmentationSchema augment1 = module1Augmentations.iterator().next(); + LeafSchemaNode augmentedLeafDefinition = (LeafSchemaNode) augment1 + .getDataChildByName("ds0ChannelNumber"); + assertTrue(augmentedLeafDefinition.isAugmenting()); + + // testfile2 + Module module2 = TestUtils.findModule(modules, "types2"); + + ContainerSchemaNode interfaces = (ContainerSchemaNode) module2 + .getDataChildByName("interfaces"); + ListSchemaNode ifEntry = (ListSchemaNode) interfaces + .getDataChildByName("ifEntry"); + ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry + .getDataChildByName("augment-holder"); + Set augmentedContainerAugments = augmentedContainer + .getAvailableAugmentations(); + LeafSchemaNode augmentedLeaf = (LeafSchemaNode) augmentedContainer + .getDataChildByName("ds0ChannelNumber"); + assertTrue(augmentedLeaf.isAugmenting()); + assertEquals(augmentedLeafDefinition, augmentedLeaf); + + Set ifEntryAugments = ifEntry + .getAvailableAugmentations(); + assertEquals(1, ifEntryAugments.size()); + + // testfile3 + Module module3 = TestUtils.findModule(modules, "types3"); + + Set module3Augmentations = module3 + .getAugmentations(); + assertEquals(1, module3Augmentations.size()); + AugmentationSchema augment3 = module3Augmentations.iterator().next(); + ContainerSchemaNode augmentedContainerDefinition = (ContainerSchemaNode) augment3 + .getDataChildByName("augment-holder"); + assertTrue(augmentedContainerDefinition.isAugmenting()); + + // check + assertEquals(augmentedContainer, augmentedContainerDefinition); + assertEquals(augmentedContainerAugments.iterator().next(), augment1); + + assertEquals(augmentedLeaf, augmentedLeafDefinition); + assertEquals(ifEntryAugments.iterator().next(), augment3); + } - LeafSchemaNode leaf = (LeafSchemaNode)list.getDataChildByName("ds0ChannelNumber"); - assertNotNull(leaf); + @Test + public void testAugmentTarget() { + Module test = TestUtils.findModule(modules, "types2"); + + ContainerSchemaNode interfaces = (ContainerSchemaNode) test + .getDataChildByName("interfaces"); + ListSchemaNode ifEntry = (ListSchemaNode) interfaces + .getDataChildByName("ifEntry"); + Set augmentations = ifEntry + .getAvailableAugmentations(); + assertEquals(1, augmentations.size()); + + AugmentationSchema augment = augmentations.iterator().next(); + + ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment + .getDataChildByName("augment-holder"); + assertNotNull(augmentHolder); + assertTrue(augmentHolder.isAugmenting()); + QName augmentHolderQName = augmentHolder.getQName(); + assertEquals("augment-holder", augmentHolderQName.getLocalName()); + assertEquals("t3", augmentHolderQName.getPrefix()); + assertEquals("Description for augment holder", + augmentHolder.getDescription()); } @Test public void testTypedefRangesResolving() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); + Module testModule = TestUtils.findModule(modules, "types1"); - Module testModule = findModule(modules, "types1"); - assertNotNull(testModule); - - LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("testleaf"); - ExtendedType leafType = (ExtendedType)testleaf.getType(); + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("testleaf"); + ExtendedType leafType = (ExtendedType) testleaf.getType(); assertEquals("my-type1", leafType.getQName().getLocalName()); assertEquals("t2", leafType.getQName().getPrefix()); - ExtendedType baseType = (ExtendedType)leafType.getBaseType(); + ExtendedType baseType = (ExtendedType) leafType.getBaseType(); assertEquals("my-base-int32-type", baseType.getQName().getLocalName()); assertEquals("t2", baseType.getQName().getPrefix()); @@ -100,14 +293,11 @@ public class YangModelParserTest { @Test public void testTypedefPatternsResolving() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); - - Module testModule = findModule(modules, "types1"); - assertNotNull(testModule); + Module testModule = TestUtils.findModule(modules, "types1"); - LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("test-string-leaf"); - ExtendedType testleafType = (ExtendedType)testleaf.getType(); + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("test-string-leaf"); + ExtendedType testleafType = (ExtendedType) testleaf.getType(); QName testleafTypeQName = testleafType.getQName(); assertEquals("my-string-type-ext", testleafTypeQName.getLocalName()); assertEquals("t2", testleafTypeQName.getPrefix()); @@ -138,14 +328,11 @@ public class YangModelParserTest { @Test public void testTypedefLengthsResolving() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); + Module testModule = TestUtils.findModule(modules, "types1"); - Module testModule = findModule(modules, "types1"); - assertNotNull(testModule); - - LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("leaf-with-length"); - ExtendedType testleafType = (ExtendedType)testleaf.getType(); + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("leaf-with-length"); + ExtendedType testleafType = (ExtendedType) testleaf.getType(); assertEquals("my-string-type", testleafType.getQName().getLocalName()); List lengths = testleafType.getLengths(); @@ -158,20 +345,17 @@ public class YangModelParserTest { @Test public void testTypeDef() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); - - Module testModule = findModule(modules, "types2"); - assertNotNull(testModule); + Module testModule = TestUtils.findModule(modules, "types2"); - LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("nested-type-leaf"); - ExtendedType testleafType = (ExtendedType)testleaf.getType(); + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("nested-type-leaf"); + ExtendedType testleafType = (ExtendedType) testleaf.getType(); assertEquals("my-type1", testleafType.getQName().getLocalName()); - ExtendedType baseType = (ExtendedType)testleafType.getBaseType(); + ExtendedType baseType = (ExtendedType) testleafType.getBaseType(); assertEquals("my-base-int32-type", baseType.getQName().getLocalName()); - Int32 int32base = (Int32)baseType.getBaseType(); + Int32 int32base = (Int32) baseType.getBaseType(); List ranges = int32base.getRangeStatements(); assertEquals(1, ranges.size()); RangeConstraint range = ranges.get(0); @@ -181,55 +365,45 @@ public class YangModelParserTest { @Test public void testTypedefDecimal1() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); + Module testModule = TestUtils.findModule(modules, "types1"); - Module testModule = findModule(modules, "types1"); - assertNotNull(testModule); + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("test-decimal-leaf"); + ExtendedType type = (ExtendedType) testleaf.getType(); + assertEquals(4, (int)type.getFractionDigits()); - LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("test-decimal-leaf"); - ExtendedType type = (ExtendedType)testleaf.getType(); - - TypeDefinition baseType = type.getBaseType(); - assertTrue(baseType instanceof Decimal64); - Decimal64 baseTypeCast = (Decimal64)baseType; - assertEquals(6, (int)baseTypeCast.getFractionDigits()); + Decimal64 baseType = (Decimal64) type.getBaseType(); + assertEquals(6, (int) baseType.getFractionDigits()); } @Test public void testTypedefDecimal2() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); - - Module testModule = findModule(modules, "types1"); - assertNotNull(testModule); + Module testModule = TestUtils.findModule(modules, "types1"); - LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("test-decimal-leaf2"); + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("test-decimal-leaf2"); TypeDefinition baseType = testleaf.getType().getBaseType(); assertTrue(testleaf.getType().getBaseType() instanceof Decimal64); - Decimal64 baseTypeCast = (Decimal64)baseType; - assertEquals(5, (int)baseTypeCast.getFractionDigits()); + Decimal64 baseTypeCast = (Decimal64) baseType; + assertEquals(5, (int) baseTypeCast.getFractionDigits()); } @Test public void testTypedefUnion() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); + Module testModule = TestUtils.findModule(modules, "types1"); - Module testModule = findModule(modules, "types1"); - assertNotNull(testModule); - - LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("union-leaf"); - ExtendedType testleafType = (ExtendedType)testleaf.getType(); + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("union-leaf"); + ExtendedType testleafType = (ExtendedType) testleaf.getType(); assertEquals("my-union-ext", testleafType.getQName().getLocalName()); - ExtendedType baseType = (ExtendedType)testleafType.getBaseType(); + ExtendedType baseType = (ExtendedType) testleafType.getBaseType(); assertEquals("my-union", baseType.getQName().getLocalName()); UnionType unionBase = (UnionType) baseType.getBaseType(); List> unionTypes = unionBase.getTypes(); - Int16 unionType1 = (Int16)unionTypes.get(0); + Int16 unionType1 = (Int16) unionTypes.get(0); List ranges = unionType1.getRangeStatements(); assertEquals(1, ranges.size()); RangeConstraint range = ranges.get(0); @@ -241,33 +415,33 @@ public class YangModelParserTest { } @Test - public void testNestedUnionResolving() { - Set modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2); - assertEquals(2, modules.size()); - - Module testModule = findModule(modules, "types1"); - assertNotNull(testModule); + public void testNestedUnionResolving1() { + Module testModule = TestUtils.findModule(modules, "types1"); - LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("nested-union-leaf"); + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("nested-union-leaf"); - ExtendedType nestedUnion1 = (ExtendedType)testleaf.getType(); + ExtendedType nestedUnion1 = (ExtendedType) testleaf.getType(); assertEquals("nested-union1", nestedUnion1.getQName().getLocalName()); - ExtendedType nestedUnion2 = (ExtendedType)nestedUnion1.getBaseType(); + ExtendedType nestedUnion2 = (ExtendedType) nestedUnion1.getBaseType(); assertEquals("nested-union2", nestedUnion2.getQName().getLocalName()); - UnionType unionType1 = (UnionType)nestedUnion2.getBaseType(); + UnionType unionType1 = (UnionType) nestedUnion2.getBaseType(); List> unionTypes = unionType1.getTypes(); assertEquals(2, unionTypes.size()); assertTrue(unionTypes.get(0) instanceof StringType); assertTrue(unionTypes.get(1) instanceof ExtendedType); - ExtendedType extendedUnion = (ExtendedType)unionTypes.get(1); - ExtendedType extendedUnionBase = (ExtendedType)extendedUnion.getBaseType(); + ExtendedType extendedUnion = (ExtendedType) unionTypes.get(1); + ExtendedType extendedUnionBase = (ExtendedType) extendedUnion + .getBaseType(); assertEquals("my-union", extendedUnionBase.getQName().getLocalName()); - UnionType extendedTargetUnion = (UnionType)extendedUnionBase.getBaseType(); - List> extendedTargetTypes = extendedTargetUnion.getTypes(); + UnionType extendedTargetUnion = (UnionType) extendedUnionBase + .getBaseType(); + List> extendedTargetTypes = extendedTargetUnion + .getTypes(); assertTrue(extendedTargetTypes.get(0) instanceof Int16); assertTrue(extendedTargetTypes.get(1) instanceof Int32); @@ -279,15 +453,228 @@ public class YangModelParserTest { assertEquals(100L, range.getMax()); } - private Module findModule(Set modules, String moduleName) { - Module result = null; - for(Module module : modules) { - if(module.getName().equals(moduleName)) { - result = module; - break; + @Test + public void testNestedUnionResolving2() { + Module testModule = TestUtils.findModule(modules, "types1"); + + LeafSchemaNode testleaf = (LeafSchemaNode) testModule + .getDataChildByName("custom-union-leaf"); + + ExtendedType testleafType = (ExtendedType) testleaf.getType(); + QName testleafTypeQName = testleafType.getQName(); + assertEquals(URI.create("urn:simple.container.demo.test"), + testleafTypeQName.getNamespace()); + assertEquals(TestUtils.createDate("2013-02-27"), + testleafTypeQName.getRevision()); + assertEquals("t3", testleafTypeQName.getPrefix()); + assertEquals("union1", testleafTypeQName.getLocalName()); + + ExtendedType union2 = (ExtendedType) testleafType.getBaseType(); + QName union2QName = union2.getQName(); + assertEquals(URI.create("urn:simple.container.demo.test"), + union2QName.getNamespace()); + assertEquals(TestUtils.createDate("2013-02-27"), + union2QName.getRevision()); + assertEquals("t3", union2QName.getPrefix()); + assertEquals("union2", union2QName.getLocalName()); + + UnionType union2Base = (UnionType) union2.getBaseType(); + List> unionTypes = union2Base.getTypes(); + assertEquals(2, unionTypes.size()); + assertTrue(unionTypes.get(0) instanceof Int32); + assertTrue(unionTypes.get(1) instanceof ExtendedType); + + ExtendedType nestedUnion2 = (ExtendedType) unionTypes.get(1); + QName nestedUnion2QName = nestedUnion2.getQName(); + assertEquals(URI.create("urn:simple.types.data.demo"), + nestedUnion2QName.getNamespace()); + assertEquals(TestUtils.createDate("2013-02-27"), + nestedUnion2QName.getRevision()); + assertEquals("t2", nestedUnion2QName.getPrefix()); + assertEquals("nested-union2", nestedUnion2QName.getLocalName()); + + UnionType nestedUnion2Base = (UnionType) nestedUnion2.getBaseType(); + List> nestedUnion2Types = nestedUnion2Base.getTypes(); + assertEquals(2, nestedUnion2Types.size()); + assertTrue(nestedUnion2Types.get(0) instanceof StringType); + assertTrue(nestedUnion2Types.get(1) instanceof ExtendedType); + + ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1); + QName myUnionExtQName = myUnionExt.getQName(); + assertEquals(URI.create("urn:simple.types.data.demo"), + myUnionExtQName.getNamespace()); + assertEquals(TestUtils.createDate("2013-02-27"), + myUnionExtQName.getRevision()); + assertEquals("t2", myUnionExtQName.getPrefix()); + assertEquals("my-union-ext", myUnionExtQName.getLocalName()); + + ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType(); + QName myUnionQName = myUnion.getQName(); + assertEquals(URI.create("urn:simple.types.data.demo"), + myUnionQName.getNamespace()); + assertEquals(TestUtils.createDate("2013-02-27"), + myUnionQName.getRevision()); + assertEquals("t2", myUnionQName.getPrefix()); + assertEquals("my-union", myUnionQName.getLocalName()); + + UnionType myUnionBase = (UnionType) myUnion.getBaseType(); + List> myUnionBaseTypes = myUnionBase.getTypes(); + assertEquals(2, myUnionBaseTypes.size()); + assertTrue(myUnionBaseTypes.get(0) instanceof Int16); + assertTrue(myUnionBaseTypes.get(1) instanceof Int32); + Int16 int16 = (Int16) myUnionBaseTypes.get(0); + List ranges = int16.getRangeStatements(); + assertEquals(1, ranges.size()); + RangeConstraint range = ranges.get(0); + assertEquals(1L, range.getMin()); + assertEquals(100L, range.getMax()); + } + + @Test + public void testRefine() { + Module testModule = TestUtils.findModule(modules, "types2"); + + ContainerSchemaNode peer = (ContainerSchemaNode) testModule + .getDataChildByName("peer"); + ContainerSchemaNode destination = (ContainerSchemaNode) peer + .getDataChildByName("destination"); + Set usesNodes = destination.getUses(); + assertEquals(1, usesNodes.size()); + UsesNode usesNode = usesNodes.iterator().next(); + Map refines = usesNode.getRefines(); + assertEquals(2, refines.size()); + + for (Map.Entry entry : refines.entrySet()) { + SchemaNode value = entry.getValue(); + + if (value instanceof LeafSchemaNode) { + LeafSchemaNode refineLeaf = (LeafSchemaNode) value; + assertNotNull(refineLeaf); + } else { + ContainerSchemaNode refineContainer = (ContainerSchemaNode) value; + Set mustConstraints = refineContainer + .getConstraints().getMustConstraints(); + assertEquals(1, mustConstraints.size()); + MustDefinition must = mustConstraints.iterator().next(); + assertEquals("must-condition", must.toString()); + assertEquals("An error message test", must.getErrorMessage()); + assertEquals(("An error app tag test"), must.getErrorAppTag()); } } - return result; + } + + @Test + public void testChoice() { + Module testModule = TestUtils.findModule(modules, "types1"); + ContainerSchemaNode peer = (ContainerSchemaNode) testModule + .getDataChildByName("transfer"); + ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how"); + Set cases = how.getCases(); + assertEquals(3, cases.size()); + } + + @Test + public void testAnyXml() { + Module testModule = TestUtils.findModule(modules, "types1"); + AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule + .getDataChildByName("data"); + assertNotNull(data); + } + + @Test + public void testDeviation() { + Module testModule = TestUtils.findModule(modules, "types1"); + Set deviations = testModule.getDeviations(); + assertEquals(1, deviations.size()); + + Deviation dev = deviations.iterator().next(); + SchemaPath expectedPath = TestUtils.createPath(true, + null, null, "data", + "system", "user"); + assertEquals(expectedPath, dev.getTargetPath()); + assertEquals(Deviate.ADD, dev.getDeviate()); + } + + @Test + public void testUnknownNode() { + Module testModule = TestUtils.findModule(modules, "types3"); + ContainerSchemaNode network = (ContainerSchemaNode)testModule.getDataChildByName("network"); + List unknownNodes = network.getUnknownSchemaNodes(); + assertEquals(1, unknownNodes.size()); + } + + @Test + public void testFeature() { + Module testModule = TestUtils.findModule(modules, "types3"); + Set features = testModule.getFeatures(); + assertEquals(1, features.size()); + } + + @Test + public void testExtension() { + Module testModule = TestUtils.findModule(modules, "types3"); + List extensions = testModule.getExtensionSchemaNodes(); + assertEquals(1, extensions.size()); + ExtensionDefinition extension = extensions.get(0); + assertEquals("name", extension.getArgument()); + assertFalse(extension.isYinElement()); + } + + @Test + public void testNotification() { + Module testModule = TestUtils.findModule(modules, "types3"); + URI expectedNamespace = URI.create("urn:simple.container.demo.test"); + String expectedPrefix = "t3"; + Date expectedRevision = TestUtils.createDate("2013-02-27"); + + Set notifications = testModule.getNotifications(); + assertEquals(1, notifications.size()); + + NotificationDefinition notification = notifications.iterator().next(); + // test SchemaNode args + QName expectedQName = new QName(expectedNamespace, expectedRevision, + expectedPrefix, "event"); + assertEquals(expectedQName, notification.getQName()); + SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, + expectedRevision, expectedPrefix, "event"); + assertEquals(expectedPath, notification.getPath()); + assertNull(notification.getDescription()); + assertNull(notification.getReference()); + assertEquals(Status.CURRENT, notification.getStatus()); + assertEquals(0, notification.getUnknownSchemaNodes().size()); + // test DataNodeContainer args + assertEquals(0, notification.getTypeDefinitions().size()); + assertEquals(3, notification.getChildNodes().size()); + assertEquals(0, notification.getGroupings().size()); + assertEquals(0, notification.getUses().size()); + + LeafSchemaNode eventClass = (LeafSchemaNode) notification + .getDataChildByName("event-class"); + assertTrue(eventClass.getType() instanceof StringType); + AnyXmlSchemaNode reportingEntity = (AnyXmlSchemaNode) notification + .getDataChildByName("reporting-entity"); + assertNotNull(reportingEntity); + LeafSchemaNode severity = (LeafSchemaNode) notification + .getDataChildByName("severity"); + assertTrue(severity.getType() instanceof StringType); + } + + @Test + public void testRpc() { + Module testModule = TestUtils.findModule(modules, "types3"); + + Set rpcs = testModule.getRpcs(); + assertEquals(1, rpcs.size()); + + RpcDefinition rpc = rpcs.iterator().next(); + assertEquals("Retrieve all or part of a specified configuration.", rpc.getDescription()); + assertEquals("RFC 6241, Section 7.1", rpc.getReference()); + + ContainerSchemaNode input = rpc.getInput(); + assertNotNull(input.getDataChildByName("source")); + assertNotNull(input.getDataChildByName("filter")); + ContainerSchemaNode output = rpc.getOutput(); + assertNotNull(output.getDataChildByName("data")); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang index 3fc8e2152e..2f4355390b 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang @@ -2,80 +2,117 @@ module types1 { yang-version 1; namespace "urn:simple.container.demo"; prefix "t1"; - + import types2 { - prefix "data"; - revision-date 2013-02-27; - } - - organization "OPEN DAYLIGHT"; + prefix "data"; + revision-date 2013-02-27; + } + + import types3 { + prefix "t3"; + revision-date 2013-02-27; + } + + organization "opendaylight"; contact "http://www.opendaylight.org/"; - + revision "2013-02-27" { reference " WILL BE DEFINED LATER"; } - - container interfaces { - list ifEntry { - key "ifIndex"; - - leaf ifIndex { - type uint32; - units minutes; - } - - leaf ifMtu { - type int32; - } - } - } - + leaf testleaf { type data:my-type1 { range "min..max"; } } - + leaf test-string-leaf { type data:my-string-type-ext; } - + leaf leaf-with-length { type data:my-string-type { length "7..max"; } } - + leaf test-int-leaf { type data:my-int-type-ext; } - + leaf test-decimal-leaf { type data:my-decimal-type { fraction-digits 4; } } - + leaf test-decimal-leaf2 { type data:my-decimal-type-ext; } - + container ext { data:c-define "MY_INTERFACES"; } - + leaf union-leaf { type data:my-union-ext; } - + deviation /data:system/data:user { deviate add { default "admin"; // new users are 'admin' by default + config "true"; } } - + leaf nested-union-leaf { type data:nested-union1; } + leaf custom-union-leaf { + type t3:union1; + } + + container transfer { + choice how { + default interval; + case interval { + leaf interval { + type uint16; + default 30; + units minutes; + } + } + case daily { + leaf daily { + type empty; + } + leaf time-of-day { + type string; + units 24-hour-clock; + default 1am; + } + } + case manual { + leaf manual { + type empty; + } + } + } + } + + anyxml data { + description + "Copy of the source datastore subset that matched + the filter criteria (if any). An empty data container + indicates that the request did not produce any results."; + } + + augment "/data:interfaces/data:ifEntry/t3:augment-holder" { + when "if:ifType='ds0'"; + leaf ds0ChannelNumber { + type string; + } + } + } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang index 0126671b35..34afea6bda 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang @@ -8,7 +8,7 @@ module types2 { revision-date 2013-02-27; } - organization "OPEN DAYLIGHT"; + organization "opendaylight"; contact "http://www.opendaylight.org/"; description "This is types-data test description"; @@ -146,5 +146,46 @@ module types2 { type string; } } + + grouping target { + leaf address { + type string; + description "Target IP address"; + } + container port { + description "Target port container"; + } + } + + container peer { + container destination { + uses target { + refine address { + default "1.2.3.4"; + } + refine port { + must "must-condition" { + error-message "An error message test"; + error-app-tag "An error app tag test"; + } + } + } + } + } + + container interfaces { + list ifEntry { + key "ifIndex"; + + leaf ifIndex { + type uint32; + units minutes; + } + + leaf ifMtu { + type int32; + } + } + } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile3.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile3.yang new file mode 100644 index 0000000000..e67d9c7eed --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile3.yang @@ -0,0 +1,134 @@ +module types3 { + yang-version 1; + namespace "urn:simple.container.demo.test"; + prefix "t3"; + + import types2 { + prefix "data"; + revision-date 2013-02-27; + } + + organization "opendaylight"; + contact "http://www.opendaylight.org/"; + + revision "2013-02-27" { + reference " WILL BE DEFINED LATER"; + } + + typedef union1 { + type union2; + } + + typedef union2 { + type union { + type int32; + type data:nested-union2; + } + } + + augment "/data:interfaces/data:ifEntry" { + when "if:ifType='ds0'"; + container augment-holder { + description "Description for augment holder"; + } + } + + container network { + description "network-description"; + reference "network-reference"; + status obsolete; + config true; + presence "some presence text"; + + mnt:mountpoint point { + mnt:target-ref target; + } + } + + feature local-storage { + description + "This feature means the device supports local + storage (memory, flash or disk) that can be used to + store syslog messages."; + } + + extension c-define { + description + "Takes as argument a name string. + Makes the code generator use the given name in the + #define."; + argument "name"; + } + + notification event { + leaf event-class { + type string; + } + anyxml reporting-entity; + leaf severity { + type string; + } + } + + rpc get-config { + description + "Retrieve all or part of a specified configuration."; + + reference "RFC 6241, Section 7.1"; + + input { + container source { + description + "Particular configuration to retrieve."; + + choice config-source { + mandatory true; + description + "The configuration to retrieve."; + case a { + leaf candidate { + if-feature candidate; + type empty; + description + "The candidate configuration is the config source."; + } + } + case b { + leaf running { + type empty; + description + "The running configuration is the config source."; + } + } + case c { + leaf startup { + if-feature startup; + type empty; + description + "The startup configuration is the config source. + This is optional-to-implement on the server because + not all servers will support filtering for this + datastore."; + } + } + } + } + + anyxml filter { + description + "Subtree or XPath filter to use."; + nc:get-filter-element-attributes; + } + } + + output { + anyxml data { + description + "Copy of the source datastore subset that matched + the filter criteria (if any). An empty data container + indicates that the request did not produce any results."; + } + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/types/custom-types-test@2012-4-4.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/types/custom-types-test@2012-4-4.yang index 9f839b24a4..0a06a30875 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/types/custom-types-test@2012-4-4.yang +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/types/custom-types-test@2012-4-4.yang @@ -66,5 +66,28 @@ module custom-types-test { } default "auto-sense-speed"; } + + typedef ip-version { + type enumeration { + enum unknown { + description + "An unknown or unspecified version of the Internet protocol."; + } + enum ipv4 { + value "19"; + description + "The IPv4 protocol as defined in RFC 791."; + } + enum ipv6 { + value "7"; + description + "The IPv6 protocol as defined in RFC 2460."; + } + enum default { + description + "default ip"; + } + } + } } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ContainerSchemaNode.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ContainerSchemaNode.java index f8674176cf..62df36e28d 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ContainerSchemaNode.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ContainerSchemaNode.java @@ -7,13 +7,9 @@ */ package org.opendaylight.controller.yang.model.api; -import java.util.Set; - public interface ContainerSchemaNode extends DataNodeContainer, AugmentationTarget, DataSchemaNode { - Set getUses(); - boolean isPresenceContainer(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/NotificationDefinition.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/NotificationDefinition.java index ecb25fcf7d..4e805f0fa6 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/NotificationDefinition.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/NotificationDefinition.java @@ -7,8 +7,5 @@ */ package org.opendaylight.controller.yang.model.api; -import java.util.Set; - public interface NotificationDefinition extends SchemaNode, DataNodeContainer { - Set getUses(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java new file mode 100644 index 0000000000..9a7b13ddb3 --- /dev/null +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java @@ -0,0 +1,71 @@ +/* + * 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.controller.yang.model.util; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition; + +public class EmptyType implements EmptyTypeDefinition { + + private final QName name = BaseTypes.constructQName("empty"); + private final SchemaPath path = BaseTypes.schemaPath(name); + private final String description = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence."; + private final String reference = "https://tools.ietf.org/html/rfc6020#page-131"; + + @Override + public EmptyTypeDefinition getBaseType() { + return this; + } + + @Override + public String getUnits() { + return null; + } + + @Override + public Object getDefaultValue() { + return null; + } + + @Override + public QName getQName() { + return name; + } + + @Override + public SchemaPath getPath() { + return path; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public Status getStatus() { + return Status.CURRENT; + } + + @Override + public List getUnknownSchemaNodes() { + return Collections.emptyList(); + } + +} diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java index f20c6aae6e..f04ba66256 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java @@ -19,6 +19,7 @@ import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition; import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition; import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition; import org.opendaylight.controller.yang.model.api.type.DecimalTypeDefinition; +import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition; import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition; import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition; import org.opendaylight.controller.yang.model.api.type.RangeConstraint; @@ -33,6 +34,7 @@ public class YangTypesConverter { private static final TypeDefinition BINARY = new BinaryType(); private static final TypeDefinition BITS = new BitsType(); private static final TypeDefinition BOOLEAN_TYPE = new BooleanType(); + private static final TypeDefinition EMPTY_TYPE = new EmptyType(); private static final TypeDefinition INST_ID_TYPE = new InstanceIdentifier(null, true); private static final TypeDefinition INT8_TYPE = new Int8(); private static final TypeDefinition INT16_TYPE = new Int16(); @@ -48,6 +50,7 @@ public class YangTypesConverter { baseYangTypeMap.put("binary", BINARY); baseYangTypeMap.put("bits", BITS); baseYangTypeMap.put("boolean", BOOLEAN_TYPE); + baseYangTypeMap.put("empty", EMPTY_TYPE); baseYangTypeMap.put("instance-identifier", INST_ID_TYPE); baseYangTypeMap.put("int8", INT8_TYPE); baseYangTypeMap.put("int16", INT16_TYPE); diff --git a/opendaylight/statisticsmanager/integrationtest/pom.xml b/opendaylight/statisticsmanager/integrationtest/pom.xml index 592a3dd071..397480e1e6 100644 --- a/opendaylight/statisticsmanager/integrationtest/pom.xml +++ b/opendaylight/statisticsmanager/integrationtest/pom.xml @@ -33,6 +33,11 @@ containermanager 0.4.0-SNAPSHOT + + org.opendaylight.controller + containermanager.implementation + 0.4.0-SNAPSHOT + org.opendaylight.controller forwardingrulesmanager @@ -43,11 +48,41 @@ clustering.services 0.4.0-SNAPSHOT + + org.opendaylight.controller + clustering.stub + 0.4.0-SNAPSHOT + org.opendaylight.controller statisticsmanager 0.4.0-SNAPSHOT + + org.opendaylight.controller + statisticsmanager.implementation + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + configuration + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + configuration.implementation + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + hosttracker + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + topologymanager + 0.4.0-SNAPSHOT + diff --git a/opendaylight/statisticsmanager/integrationtest/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerIntegrationTest.java b/opendaylight/statisticsmanager/integrationtest/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerIntegrationTest.java index 24b96128e9..fa96d5304e 100644 --- a/opendaylight/statisticsmanager/integrationtest/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerIntegrationTest.java +++ b/opendaylight/statisticsmanager/integrationtest/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerIntegrationTest.java @@ -102,7 +102,7 @@ public class StatisticsManagerIntegrationTest { mavenBundle("org.opendaylight.controller", "clustering.services", "0.4.0-SNAPSHOT"), mavenBundle("org.opendaylight.controller", - "clustering.services-implementation", "0.4.0-SNAPSHOT"), + "clustering.stub", "0.4.0-SNAPSHOT"), // needed by forwardingrulesmanager mavenBundle("org.opendaylight.controller", "switchmanager", diff --git a/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/UserManagerImpl.java b/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/UserManagerImpl.java index 1b9c749163..0397cd4c47 100644 --- a/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/UserManagerImpl.java +++ b/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/UserManagerImpl.java @@ -275,14 +275,14 @@ public class UserManagerImpl implements IUserManager, IObjectReader, break; } else if (rcResponse.getStatus() == AuthResultEnum.AUTH_REJECT) { logger.info( - "Remote Authentication Rejected User: \"{}\", from Server: {}, Reason: " - + rcResponse.getStatus().toString(), - userName, aaaServer.getAddress()); + "Remote Authentication Rejected User: \"{}\", from Server: {}, Reason:{}", + new Object[] {userName, aaaServer.getAddress(), + rcResponse.getStatus().toString()}); } else { logger.info( - "Remote Authentication Failed for User: \"{}\", from Server: {}, Reason: " - + rcResponse.getStatus().toString(), - userName, aaaServer.getAddress()); + "Remote Authentication Failed for User: \"{}\", from Server: {}, Reason:{}", + new Object[] {userName, aaaServer.getAddress(), + rcResponse.getStatus().toString()}); } } } @@ -367,8 +367,8 @@ public class UserManagerImpl implements IUserManager, IObjectReader, */ putUserInActiveList(userName, result); if (authorized) { - logger.info("User \"{}\" authorized for the following role(s): " - + result.getUserRoles(), userName); + logger.info("User \"{}\" authorized for the following role(s): {}", + userName, result.getUserRoles()); } else { logger.info("User \"{}\" Not Authorized for any role ", userName); } diff --git a/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/security/SessionManager.java b/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/security/SessionManager.java index 7706fe2b1a..21d0137849 100644 --- a/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/security/SessionManager.java +++ b/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/security/SessionManager.java @@ -38,8 +38,9 @@ public class SessionManager implements ISessionManager { ServletContext ctx = se.getSession().getServletContext(); String path = ctx.getContextPath(); - logger.debug("Servlet Context Path created " + path); - logger.debug("Session Id created for ctxt path " + se.getSession().getId()); + logger.debug("Servlet Context Path created {}", path); + logger.debug("Session Id created for ctxt path {}", + se.getSession().getId()); synchronized (sessionMap) { Set set = sessionMap.get(ctx); @@ -55,8 +56,8 @@ public class SessionManager implements ISessionManager { public void sessionDestroyed(HttpSessionEvent se) { ServletContext ctx = se.getSession().getServletContext(); String path = ctx.getContextPath(); - logger.debug("Servlet Context Path of destroyed session - " + path); - logger.debug("Session Id destroyed " + se.getSession().getId()); + logger.debug("Servlet Context Path of destroyed session - {}", path); + logger.debug("Session Id destroyed {}", se.getSession().getId()); synchronized (sessionMap) { Set set = sessionMap.get(ctx); diff --git a/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java b/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java index 51cdcfb434..285e33f53b 100644 --- a/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java +++ b/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java @@ -259,7 +259,7 @@ public class Topology { } } - CircleLayout layout = new CircleLayout(graph); + CircleLayout layout = new CircleLayout(graph); layout.setSize(new Dimension(1200, 365)); for (Map.Entry> v : newNodes.entrySet()) { Double x = layout.transform(v.getKey()).getX();