⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 offlinebroker.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    */
    
    public boolean deleteTree(DN nodeDN)                      // may be a single node.
    {
        log.fine("offline cache deleting " + nodeDN.toString());
        Node N = (Node)nodes.get(nodeDN.toString());
        
        if (N==null) return false;
        
        Enumeration children = N.getChildNodes();
        while (children.hasMoreElements())
            deleteTree(((Node)children.nextElement()).getDN());
            
        nodes.remove(nodeDN.toString());
        Node parent = N.getParent();                 // this node tells its parent to remove this        
        if (parent != null) parent.removeChild(N);  // node from the parent's child list...
        return true;    
    }
    
   /**
    *    Moves a DN to a new DN, including all subordinate entries.
    *    (nb it is up to the implementer how this is done; e.g. if it is an
    *     ldap broker, it may choose rename, or copy-and-delete, as appropriate)
    *     
    *    @param oldNodeDN the original DN of the sub tree root (may be a single
    *           entry).
    *    @param newNodeDN the target DN for the tree to be moved to.
    */
    
    public void move(DN oldNodeDN, DN newNodeDN)       // may be a single node.
        throws NamingException
    {
        unthreadedCopy(oldNodeDN, newNodeDN);            // brutal...
        deleteTree(oldNodeDN);                           // ... but it works.
    }
    

    
    
   /**
    *    Checks whether the current data source is modifiable.  (Nb., 
    *    a directory may have different access controls defined on 
    *    different parts of the directory: if this is the case, the
    *    directory may return true to isModifiable(), however a 
    *    particular modify attempt may still fail.
    *
    *    @return whether the directory is modifiable
    */
    
    public boolean isModifiable() { return true; }
    


    /**
     *    We don't actually have an underlying DirContext, so return null...
     */
     
     public DirContext getDirContext() { return null; }
     
     
     
    /**
     *    Method for the Broker interface - chains to 
     *    children().
     */
     
    public DataQuery doListQuery(DataQuery request)
    {
        request.setEnum(children(request.requestDN()));
        return request;
    }
                
    /**
     *    Method for the Broker interface - chains to 
     *    search().
     */
     
    public DataQuery doSearchQuery(DataQuery request)
    {
        request.setException(new Exception("offline searches not allowed"));
        return request;
    }
                
                
    /**
     *    Method for the Broker interface - chains to 
     *    getObjectClasses().
     */
     
    public DataQuery doGetAllOCsQuery(DataQuery request)
    {
        request.setException(new Exception("offline object class list not implemented"));
        return request;
    }
                
    /**
     *    Method for the Broker interface - chains to 
     *    getRecommendedObjectClasses.
     */
     
    public DataQuery doGetRecOCsQuery(DataQuery request)
    {
        request.setException(new Exception("offline object class list not implemented"));
        return request;
    }  
    
    /**
     *   returns the next level of a directory tree, returning
     *   a Enumeration of the results
     *
     *   @param searchbase the node in the tree to expand
     *   @return list of results (NameClassPair); the next layer of the tree... 
     */
     
    public  DXNamingEnumeration unthreadedList(DN searchbase)
    {
        return children(searchbase);
    }
        
    /**
     *   Not Implemented.
     *
     *   @param dn the distinguished name (relative to initial context in ldap) to seach from.
     *   @param filter the non-null filter to use for the search 
     *   @param search_level whether to search the base object, the next level or the whole subtree.
     *   @param returnAttributes a vector of string names of attributes to return in the search.  (Currently inoperative)
     *   @return list of results ('SearchResult's); the next layer of the tree... 
     */
     
    public  DXNamingEnumeration unthreadedSearch(DN dn, String filter, int search_level, String[] returnAttributes)
    {
        return null; 
    }
    
   /**
    *    Copies a DN representing a subtree to a new subtree, including 
    *    copying all subordinate entries.
    *     
    *    @param oldNodeDN the original DN of the sub tree root 
    *           to be copied (may be a single entry).
    *    @param newNodeDN the target DN for the tree to be moved to.
    */
    
    public  void unthreadedCopy(DN oldNodeDN, DN newNodeDN)
        throws NamingException
    {
        Node Old = (Node)nodes.get(oldNodeDN.toString());         // get the Node to copy
        if (Old==null)
            throw new NamingException("null old dn passed to unthreaded copy");                              // sanity check
        
        addNode(new DXEntry(Old.getEntry(), newNodeDN));      // create a copy of Old
        Node New = (Node)nodes.get(newNodeDN.toString());         // get the newly created copy  
        Enumeration children = Old.getChildNodes();               // get the old nodes children...
        while (children.hasMoreElements())                        // ...and for each child
        {
            Node child = (Node)children.nextElement();            // identify the child node
            DN NewChildDN = new DN(New.getDN());                  // get the 'New' nodes DN...
            NewChildDN.addChildRDN(child.getDN().getLowestRDN().toString());  // ... and add to it the child rdn that is being copied
            unthreadedCopy(child.getDN(),NewChildDN);                   // copy (and therefore create) the child node copy
        }
    }
    


   /**
    *    Checks the existence of a particular DN, without (necessarily)
    *    reading any attributes.
    *    @param nodeDN the DN to check.
    *    @return the existence of the nodeDN (or false if an error occurs).
    */
    
    public boolean unthreadedExists(DN nodeDN)   
    {   
        return nodes.containsKey(nodeDN.toString());
    }
    
    /**
     *    Not implemented.
     */

    public  Vector unthreadedGetAllOCs() { return null; }

    /**
     *    Reads an entry with all its attributes from
     *    the directory.
     *    @param entryDN the DN of the object to read.
     *    @param returnAttributes a vector of string names of attributes to return in the search.
     *          (null means 'return all entries', a zero length array means 'return no attributes'.)
     */
     
    public DXEntry unthreadedReadEntry(DN entryDN, String[] returnAttributes)
    {
        if (returnAttributes != null)
            log.info("warning: att list read entries not implemented in offline broker");
            
        Node N = (Node)nodes.get(entryDN.toString());
        return (N==null)?  new DXEntry(entryDN) : N.getEntry();
    }  
        
        
   /**
    *    Update an entry with the designated DN.
    *    @param oldEntry the old set of attributes of the object.
    *    @param newEntry the replacement set of attributes..
    */
    
    public  void unthreadedModify(DXEntry oldEntry, DXEntry newEntry)
        throws NamingException
    {
        if (oldEntry == null && newEntry == null)
        {
             // nothing to do.
        }
        else if (oldEntry == null) // add
        {
            addNode(newEntry);
        }
        else if (newEntry == null) // delete
        {
            deleteTree(oldEntry.getDN());
        }
        else
        {

            // remove naming attributes to avoid name/dn conflicts...
            // XXX work to do here supporting multi-valued naming atts...

            RDN singleValRDN = oldEntry.getDN().getLowestRDN();
            String namingAtt = singleValRDN.getAtt();
            String namingVal = singleValRDN.getRawVal();
            oldEntry.remove(namingAtt);
            newEntry.remove(namingAtt);
            newEntry.put(new DXAttribute(namingAtt, namingVal));

            if (oldEntry.getDN().equals(newEntry.getDN()) == false)
            {
                move(oldEntry.getDN(), newEntry.getDN());
                oldEntry.putDN(newEntry.getDN());
            }

            // check for change of attributes done in modify()

            updateNode(oldEntry, newEntry);
        }
    }

    /**
     *    Not implemented.
     *    @param dn the dn of the parent to determine likely
     *              child object classes for
     *    @return list of recommended object classes...             
     */
    
    public  ArrayList unthreadedGetRecOCs(DN dn) { return null; }
     
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -