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

📄 dataquery.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                case UNKNOWN:   return "UNKNOWN";
                case EXISTS:    return new Boolean(getStatus());
                case READENTRY: return getEntry();
                case LIST:      return getEnumeration();
                case SEARCH:    return getEnumeration();
                case MODIFY:    return new Boolean(getStatus());
                case COPY:      return new Boolean(getStatus());
//                case GETALLOC:  return getObjectClasses();
//                case GETRECOC:  return getObjectClasses();
                case EXTENDED:  return getAllExtendedData();
            }
            return "UNDEFINED";
        }
        catch (NamingException e)
        {
            return e;
        }
    }

    /** Unsynchronized Methods to set data variables **/

    public DataQuery setArrayList(ArrayList v) { myArrayList = v; return this;}

    public DataQuery setStatus(boolean b) { myStatus = b; return this;}

    public DataQuery setEntry(DXEntry d) { myEntry = d; return this;}

    public DataQuery setEnum(DXNamingEnumeration d) { myEnum = d; return this;}

    public DataQuery setException(Exception e) { myEx = e; return this;}

    //public void setType(int t) { type = t; }


    /** DataQuery Interface **/

    /**
     *    Used by some thread-friendly applications that wish to
     *    poll the state of the DataResult.  Returns false
     *    until the data request has been completed (which
     *    includes an error occurring).
     *    @return true if the request has been completed.
     */
    public boolean ready() { return ready; }

    /**
     *    Used by thread-friendly application to register a
     *    listener that will be called when the request has
     *    been completed (or an error thrown).<p>
     *
     *    Note that this listener is somewhat unusual, as it
     *    will only ever trigger a maximum of one time.<p>
     *
     *    if this method is called on a DataResult that has
     *    already been completed, it will be triggered immediately.
     *    This may cause listener code to be triggered <i>before</i>
     *    any code subsequent to the addDataListener() call.<p>
     *
     *    @param l the listener to be notified when the data
     *    operation has been completed.
     */

    public synchronized void addDataListener(DataListener l)
    {
        if (ready)
            l.dataReady(this);  // if data ready, fire immediately
        else
            listeners.add(l);   //  otherwise add to listener list.
    }


    synchronized void keepWaiting()
        throws NamingException
    {
        // XXX BIG UGLY HACK
        // We need to make sure that thread is not waiting for itself.  This can happen if a pluggable editor
        // (run from jndiThread) tries to get the result from a DataQuery immediately.  Currently this is done
        // by checking the thread name string (yuck).  Maybe it would be better to do away with the facility
        // altogether, and disallow DataQueries to return anything unless they are 'ready()'.

        String current = Thread.currentThread().getName();

        if ("jndiBroker Thread searchBroker Thread schemaBroker Thread".indexOf(current)>-1)
        {
            System.err.println("ERROR - Thread " + current + " possibly blocking on self");
            throw new NamingException("Thread Blockage (?) during Naming operation - attempt to force immediate data read from: " + current + " thread.  Consider using unthreaded Broker classes rather than DataQuery.");
        }

        try
        {
            notifyAll();
            wait();
        } catch (InterruptedException e)
        {
            System.out.println("Thread: " + Thread.currentThread().getName() + " interrupted in DataQuery:keepWaiting() loop \n    " + e);
        };  // block until data is cooked
    }

    /**
     *    Returns the status of an operation.  This will
     *    block until the transaction has finished, so thread
     *    friendly applications should wait until the
     *    DataResult is 'ready' before calling this method.<p>
     *
     *    This method should be used to read the response from
     *    DataSource methods modifyEntry() and copyTree(),
     *    and DataSource operations such as exists() and isActive().
     *
     *    Throws a NamingException if called inapropriately
     *    (i.e. if no result of this type would be possible).
     *
     *    @return the success status of the operation.
     */

    public boolean getStatus()
        throws NamingException
    {
        while (!ready()) keepWaiting();

        if (type == MODIFY || type == COPY || type == EXISTS)
            return myStatus;
        else
            throw new NamingException("Improper call of getStatus for a DataQuery of Type " + getTypeString());
    }
    /**
     *    A list of Name-Class Pairs from a 'getChildren()'
     *    DataSource operation.  This will
     *    block until the transaction has finished, so thread
     *    friendly applications should wait until the
     *    DataResult is 'ready' before calling this method.<p>
     *
     *    Throws a NamingException if called inapropriately
     *    (i.e. if no result of this type would be possible).
     *
     *    This method should be used to read the response from
     *    DataSource getChildren() method.
     *    @return the NameClass pairs representing the children
     *    of a given entry, or of SearchResults representing the
     *    result of a search request.
     */
    public DXNamingEnumeration getEnumeration()
        throws NamingException
    {
        try
        {
	        while (!ready()) keepWaiting();

	        if (type == LIST || type == SEARCH)
	            return myEnum;
	        else
	            throw new NamingException("Improper call of getNameClassPairs for a DataQuery of Type " + getTypeString());

        }
        catch (NamingException e)
        {
            throw new NamingException(e.toString());
        }
    }

    /**
     *    A DXEntry from a 'getEntry()'
     *    DataSource operation.  This will
     *    block until the transaction has finished, so thread
     *    friendly applications should wait until the
     *    DataResult is 'ready' before calling this method.<p>
     *
     *    Throws a NamingException if called inapropriately
     *    (i.e. if no result of this type would be possible).
     *
     *    This method should be used to read the response from
     *    DataSource getEntry() method.
     */
    public DXEntry getEntry()
        throws NamingException
    {
        while (!ready()) keepWaiting();

        if (type == READENTRY)
            return myEntry;
        else
            throw new NamingException("Improper call of getEntry for a DataQuery of Type " + getTypeString());
    }
    /**
     *    A vector of strings representing ObjectClasses from either a
     *    DataSource getObjectClasses() or a getRecommendedObjectClasses()
     *    operation.  This will
     *    block until the transaction has finished, so thread
     *    friendly applications should wait until the
     *    DataResult is 'ready' before calling this method.<p>
     *
     *    Throws a NamingException if called inapropriately
     *    (i.e. if no result of this type would be possible).
     *
     *    This method should be used to read the response from
     *    DataSource getObjectClasses() or a getRecommendedObjectClasses() method.
     */

    public ArrayList getObjectClasses()
        throws NamingException
    {
        while (!ready()) keepWaiting();

//        if (type == GETALLOC || type == GETRECOC)
        if (type == GETRECOC)
            return myArrayList;
        else
            throw new NamingException("Improper call of getObjectClasses for a DataQuery of Type " + getTypeString());
    }

    /**
     *    Indicates that an error has occured.  This will
     *    block until the transaction has finished, so thread
     *    friendly applications should wait until the
     *    DataResult is 'ready' before calling this method.<p>
     *    It returns null if there is no exception.<p>
     *    @return the exception experienced by the directory
     *     operation, or null if no error found.
     */

    public Exception getException()
    {
        try
        {
            while (!ready()) keepWaiting();
        }
        catch (NamingException e) { return e; }

        return myEx;        // which is null, unless an exception occurred...
    }

    /**
     *    Returns whether an error has occured.  This will
     *    block until the transaction has finished, so thread
     *    friendly applications should wait until the
     *    DataResult is 'ready' before calling this method.<p>
     *    It returns false if there is no exception.<p>
     *    @return whether an exception occured in the execution of
     *    this query
     */

    public boolean hasException()
    {
        try
        {
            while (!ready()) keepWaiting();
        }
        catch (NamingException e)
        {
            myEx = e;
            return true;
        }

        return (myEx!=null);
    }


    /**
     *    This clears the exception status of a DataResult,
     *    indicating that the exception has been handled.
     *    It is not an error to call this method if no
     *    exception exists, and this method has no effect
     *    on exceptions that may occur later (e.g. if this
     *    method is called before the DataResult is ready()
     *    it may have no effect.)
     */
    public void clearException()
    {
        myEx = null;
    }



    public int getType() { return type; }



    // Read-only access methods to data variables.

    public DN requestDN() { return (requestDN==null)?null:new DN(requestDN); }

    public DN oldDN() { return (oldDN==null)?null:new DN(oldDN); }

    public DXEntry oldEntry() { return (oldEntry==null)?null:new DXEntry(oldEntry); }

    public DXEntry newEntry() { return (newEntry==null)?null:new DXEntry(newEntry); }

    public String filter() { return (filter==null)?null:filter; }
	
	public String[] returnAttributes() { return (returnAttrs==null)?null:returnAttrs; }

    public int searchLevel() { return searchLevel; }


    /**
     *    This provides a method of returning arbitrary information from
     *    an extended request.
     *    @return a hashtable of named objects (use addExtendedData to set these).
     */

    public Hashtable getAllExtendedData() { return extendedData; }

    /**
     *    Returns a named data object from the extended data queries object store.
     *    @param name case insensitive name of a previously added object.
     */

    public Object getExtendedData(String name) { return extendedData.get(name.toLowerCase()); }

    /**
     *    This provides a method for setting arbitrary information for
     *    the use of an extended request.
     */

    public void setExtendedData(String name, Object o) { if (extendedData != null) extendedData.put(name.toLowerCase(),o); }

    /**
     *    Users intending to make Extended requests should write (potentially anonymous)
     *    derived classes of DataQuery, extending this method.  Derived class writers
     *    should be carefull to only use the *unthreaded* methods of the Broker, in
     *    order to avoid possible thread problems.
     */

    public void doExtendedRequest(Broker b) { return; }

}


⌨️ 快捷键说明

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