Show TOC

Step 2: Creating a Navigation ConnectorLocate this document in the navigation structure

Context

The navigation connector implements methods that define the following:

  • The initial (top-level) nodes of the connector. Once the navigation connector returns the initial nodes, the navigation service can query the nodes themselves for each one's children and related nodes.

  • The mapping between a navigation URL and the nodes defined by the connector.

    For example, if the connector prefix is myPrefix , a navigation URL for the connector could be myPrefix://myParentNode2/myChildNode5 . The connector must determine what INavigationConnectorNode object to return for this URL.

Procedure


  1. Create a new class that extends AbstractNavigationConnector .

  2. Implement the method getInitialNodes() , which returns a javax.naming.NamingEnumeration of the initial nodes. The method could return the nodes only if a condition is true, for example, the user is part of specific role.

    The following returns the initial nodes if the user is part of the Java developer role:

    public NamingEnumeration getInitialNodes(Hashtable environment) {
        if (isUserInJavaDeveloperRole(environment))
            return new NavigationEnum(initialNodes);
        else
            return NavigationEnum.EMPTY_ENUM;
    }
    
                         
  3. Implement the method getNode() , which returns a INavigationConnectorNode based on a navigation URL passed into the method.

    You can implement any logic for returning the INavigationConnectorNode object. One method is to store all the nodes in a Map with the navigation URL as the key. To implement this, you could do the following:

    1. Store the nodes in a Map . You can add code for this in an initialization method.

      One implementation is to create a method that recursively traverses the navigation nodes that you created and store them in a map with the fully qualified name (navigation URL) as the key for each one, as follows:

      private void recursivelyFillNamesToNodesMap(NamingEnumeration enum)
                  throws NamingException {
          while (enum.hasMoreElements()) {
              Binding b = (Binding) enum.nextElement();
              myConnectorNode node = (myConnectorNode) b.getObject();
              String nodeName = node.getName();
              namesToNodes.put(nodeName, node);
              atomicNamesToNames.put(node.getAtomicName(),nodeName);
              recursivelyFillNamesToNodesMap(node.listBindings(
                  "", INavigationConnectorNode.NAVIGATION_GET_CHILDREN));
          }
      }
      
                                 

      You could then call recursivelyFillNamesToNodesMap from the initialization method, passing in the initial nodes.

    2. Look up the node in the Map based on the navigation URL. The following returns a node in the namesToNodes Map if the user is a member of the Java developer role:

      public INavigationConnectorNode getNode(
                  Hashtable environment, String connectorNodeURL) {
          boolean memberOfRole = isUserInJavaDeveloperRole(environment);
          if (memberOfRole)
              return (myConnectorNode) namesToNodes.get(connectorNodeURL);
          else
              return null;
      }
      
                                 
  4. Implement the method getNodes() , which returns a javax.naming.NamingEnumeration of INavigationConnectorNode objects based on a set of navigation URLs passed into the method, as follows:

    public NamingEnumeration getNodes(
                Hashtable environment, Vector connectorNodeURLs) {
        myConnectorNode node;
     
        int size = connectorNodeURLs.size();
        List nodeBindings = new ArrayList(size);
     
        for (int i = 0; i < size; i++) {
            node = (myConnectorNode) getNode(
                            environment, (String) connectorNodeURLs.get(i));
            if (node != null) nodeBindings.add(
                            new Binding(node.getName(), node));
        }
     
        return new NavigationEnum(nodeBindings);
    }
    
                         
  5. Implement the method getNodeByQuickLink() in order to map quick links strings to specific navigation nodes.

    For more information, see Quick Links .

  6. Implement getConnectorCacheDiscriminators() , which returns a set of keys, with each key representing a different entry point. The method enables caching of navigation nodes, improving performance.

    For more information, see Navigation Cache .

    Note

    If your navigation connector does not support caching, implement getConnectorProfile() , and return a NavigationConnectorProfile object on which you called setCachable() and turned caching off.