Class MaapiSchemas

Object
com.tailf.maapi.MaapiSchemas

public class MaapiSchemas extends Object

Handles the schema information from the data models loaded.

It holds an offline tree structure where each node is represented by an instance of MaapiSchemas.CSNode which in turn contains connections to other nodes.

Methods exist to retrieve a specified schema MaapiSchemas.CSSchema or a specified schema node findCSNode(String,String,Object...), findCSNode(MaapiSchemas.CSNode,String,String).

All entities, including Schemas, Nodes, Types, Choices etc are represented as inner classes of MaapiSchemas and are stored in its offline tree hierarchy.

These inner classes have methods to retrieve all information about the entity.

Note that this class is self-contained in the sense that it does not use any locally compiled schemas i.e. ConfNamespace classes.

There are methods for converting between hashes and strings: stringToHash(String) and hashToString(long)

Example:


 // int port = Conf.PORT for ConfD or Conf.NCS_PORT for NCS
 // Setup socket to server
 Socket s = new Socket("localhost", port);
 // Start MAAPI session for admin user, originating from localhost
 Maapi maapi = new Maapi(s);
 s.close();
 Iterator<MaapiSchemas.CSSchema> iter =
     Maapi.getSchemas().getLoadedSchemas().iterator();
 while (iter.hasNext()) {
     MaapiSchemas.CSSchema sch = iter.next();
     System.out.println(sch);
     System.out.println("--- Named Types ---");
     Enumeration<MaapiSchemas.CSNamedType> typenum =
         sch.getNamedTypes().elements();
     while (typenum.hasMoreElements()) {
         MaapiSchemas.CSNamedType namedType = typenum.nextElement();
         System.out.println(namedType);
     }

     MaapiSchemas.CSNode root = sch.getRootNode();
     System.out.println("--- Root Node ---");
     System.out.println(root);
     if (root != null) {
         System.out.println("--- Node Tree ---");
         Iterator<MaapiSchemas.CSNode> iter2 =
             root.getSiblings().iterator();
         int offset = 0;
         while (iter2.hasNext()) {
             MaapiSchemas.CSNode n = iter2.next();
             System.out.print(n.getTag());
             MaapiSchemasUtil.printNodeInfo(offset, n);
             MaapiSchemasUtil.printChildren(offset, n);
         }
     }
 }
  • Method Details

    • getLoadedSchemas

      public Collection<MaapiSchemas.CSSchema> getLoadedSchemas()
      get all loaded schemas as a Collection of CSSchema objects
      Returns:
      Collection of CSSchema objects
    • getLoadedMNsMaps

      public Collection<MaapiSchemas.CSMNsMap> getLoadedMNsMaps()
    • getRootMountId

      public static List<String> getRootMountId()
    • findCSMNsMap

      public MaapiSchemas.CSMNsMap findCSMNsMap(List<String> mountId)
    • findCSSchema

      public MaapiSchemas.CSSchema findCSSchema(int nshash)
      Retrieve a specified schema identified by an hash value
      Parameters:
      nshash - integer hash value representing the namespace
      Returns:
      CSSchemaobject for the identified Namespace of null if not found
    • findCSSchema

      @Deprecated public MaapiSchemas.CSSchema findCSSchema(long nshash)
      Deprecated.
      Use findCSSchema(int) instead.
    • findCSSchema

      public MaapiSchemas.CSSchema findCSSchema(String nsName)
      Retrieve a specific schema identified by an namespace string
      Parameters:
      nsName - a string contain the full namespace name
      Returns:
      CSSchema object for the identified namespace or null if not found.
    • findCSSchemaByPrefix

      public MaapiSchemas.CSSchema findCSSchemaByPrefix(String prefix)
    • findCSSchemaFromUniqueRoot

      public MaapiSchemas.CSSchema findCSSchemaFromUniqueRoot(String rootTagName)
      Returns schema for root node. This requires the root node to be unique in all known schemas. Otherwise null is returned.
      Parameters:
      rootTagName - root tagname as string
      Returns:
      CSSchema the schema having the tag as root
    • findCSSchemaFromUniqueRoot

      public MaapiSchemas.CSSchema findCSSchemaFromUniqueRoot(int rootHash)
      Returns schema for root node. This requires the root node to be unique in all known schemas. Otherwise null is returned.
      Parameters:
      rootHash - hash for root node
      Returns:
      CSSchema the schema having the tag as root
    • findCSSchemaFromUniqueRoot

      @Deprecated public MaapiSchemas.CSSchema findCSSchemaFromUniqueRoot(long rootHash)
      Deprecated.
    • findCSRoot

      public MaapiSchemas.CSNode findCSRoot(int nshash)
      Retrieve a specific root node identified by an hash value
      Parameters:
      nshash - integer hash value representing the root node
      Returns:
      CSNode root node or null if not found
    • findCSRoot

      @Deprecated public MaapiSchemas.CSNode findCSRoot(long nshash)
      Deprecated.
      Use findCSRoot(int) instead.
    • findCSRoot

      public MaapiSchemas.CSNode findCSRoot(String nsName)
      Retrieve a specific root node identified by an namespace string
      Parameters:
      nsName - a string contain the full namespace name
      Returns:
      CSNode root node or null if not found
    • findCSNode

      public MaapiSchemas.CSNode findCSNode(MaapiSchemas.CSNode parent, String xmltagNSName, String xmltagName)
      Retrieve a specific node with a given parent node identified by xmltag namespace and tagname
      Parameters:
      parent - parent node
      xmltagNSName -
      xmltagName -
      Returns:
      CSNode or null if not found
    • findCSNode

      public MaapiSchemas.CSNode findCSNode(MaapiSchemas.CSNode parent, int xmltagNShash, int xmltaghash)

      Find and retrieves specific node in the schema information tree.

      Retrieve a specific node with a given parent node identified by xmltag namespace hash and tagname hash
      Parameters:
      parent - parent node
      xmltagNShash - namespace hash value
      xmltaghash - tag hash which value
      Returns:
      CSNode or null if not found
    • findCSNode

      public MaapiSchemas.CSNode findCSNode(MaapiSchemas.CSNode parent, MaapiSchemas.CSMNsMap mnsMap, String xmltagName)
      Retrieve a specific node with a given parent node identified by xmltag all namespaces in a mnsmap and tagname
      Parameters:
      parent - parent node
      mnsMap -
      xmltagName -
      Returns:
      CSNode or null if not found
    • findCSNode

      @Deprecated public MaapiSchemas.CSNode findCSNode(MaapiSchemas.CSNode parent, long xmltagNShash, long xmltaghash)
      Deprecated.
    • findCSNode

      public MaapiSchemas.CSNode findCSNode(String nsName, String fmt, Object... arguments) throws MaapiException
      Throws:
      MaapiException
    • findCSNode

      public MaapiSchemas.CSNode findCSNode(MountIdInterface mountGetter, String nsName, String fmt, Object... arguments) throws MaapiException

      Find and retrieves specific node in the schema information tree.

      Get a node identified by an namespace string which is the string that appears in the yang models namespace statement.

      If a yang model extends another yang model, through the augment statement then then the namespace string should be the string present in the the top yang model, (the yang model which contains the augment statement).

      The fmt is either a keypath or tagpath (path not containing keys).

      Parameters:
      mountGetter - if such exists or else null
      nsName - namespace string that appears in a yang model.
      fmt - keypath or tagpath that leads to the node
      arguments - for % substitution in fmt
      Returns:
      MaapiSchemas.CSNode the node identified by the path or null if not found
      Throws:
      MaapiException
    • findCSNode

      public MaapiSchemas.CSNode findCSNode(MountIdInterface mountGetter, String nsName, List<com.tailf.conf.gen.PathParser.PathElement> pl) throws MaapiException
      Internally used method to find a node defined by an internal path format
      Parameters:
      mountGetter - if such exists or else null
      nsName -
      pl -
      Returns:
      CSNode the found schema node or null if not found
      Throws:
      MaapiException
    • stringToHash

      public int stringToHash(String tagString)
      Convert from String value to hash value for a specified tag.
      Parameters:
      tagString -
      Returns:
      integer hash value or zero if not found.
    • hashToString

      public String hashToString(int tagHash)
      Convert from hash value to String value for a specified tag.
      Parameters:
      tagHash - hash value for tag
      Returns:
      String value or null if not found
    • hashToString

      @Deprecated public String hashToString(long tagHash)
      Deprecated.
      Use hashToString(int) instead.
    • stringToValue

      public ConfValue stringToValue(MaapiSchemas.CSType type, String str) throws MaapiException
      parse value located in str and convert to ConfValue, the value is validated.
      Parameters:
      type - - type for the converted value
      str - - string representation of the value
      Returns:
      ConfValue for the corresponding type
      Throws:
      MaapiException
    • valueToString

      public String valueToString(MaapiSchemas.CSType type, ConfValue val)
      convert to string representation for the corresponding ConfValue
      Parameters:
      type - - type for the converted value
      val - - ConfValue
      Returns:
      String representation of the value
    • convertMountId

      public String convertMountId(ConfEObject eObj)
    • setThreadDefaultMountId

      public static void setThreadDefaultMountId(List<String> mountId)
    • getThreadDefaultMountId

      public static List<String> getThreadDefaultMountId()
    • getMountId

      public List<String> getMountId(MountIdInterface midif, ConfPath path) throws IOException, ConfException
      Throws:
      IOException
      ConfException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clearMountIdCache

      public void clearMountIdCache()
    • removeMountIdCachePath

      public void removeMountIdCachePath(ConfPath path)
    • currentMountIdCacheSize

      public int currentMountIdCacheSize()