Examples of SearchParameter


Examples of org.apache.directory.studio.ldapbrowser.core.model.SearchParameter


    private static SearchParameter readSearch( Element searchParameterElement, IBrowserConnection browserConnection )
        throws ConnectionIOException
    {
        SearchParameter searchParameter = new SearchParameter();

        // Name
        Attribute nameAttribute = searchParameterElement.attribute( NAME_TAG );
        if ( nameAttribute != null )
        {
            searchParameter.setName( nameAttribute.getValue() );
        }

        // Search base
        Attribute searchBaseAttribute = searchParameterElement.attribute( SEARCH_BASE_TAG );
        if ( searchBaseAttribute != null )
        {
            try
            {
                searchParameter.setSearchBase( new Dn( searchBaseAttribute.getValue() ) );
            }
            catch ( LdapInvalidDnException e )
            {
                throw new ConnectionIOException( NLS.bind(
                    BrowserCoreMessages.BrowserConnectionIO_UnableToParseSearchBase,
                    new String[]
                        { searchParameter.getName(), searchBaseAttribute.getValue() } ) );
            }
        }

        // Filter
        Attribute filterAttribute = searchParameterElement.attribute( FILTER_TAG );
        if ( filterAttribute != null )
        {
            searchParameter.setFilter( filterAttribute.getValue() );
        }

        // Returning Attributes
        Element returningAttributesElement = searchParameterElement.element( RETURNING_ATTRIBUTES_TAG );
        if ( returningAttributesElement != null )
        {
            List<String> returningAttributes = new ArrayList<String>();
            for ( Iterator<?> i = returningAttributesElement.elementIterator( RETURNING_ATTRIBUTE_TAG ); i.hasNext(); )
            {
                Element returningAttributeElement = ( Element ) i.next();

                Attribute valueAttribute = returningAttributeElement.attribute( VALUE_TAG );
                if ( valueAttribute != null )
                {
                    returningAttributes.add( valueAttribute.getValue() );
                }
            }
            searchParameter.setReturningAttributes( returningAttributes
                .toArray( new String[returningAttributes.size()] ) );
        }

        // Scope
        Attribute scopeAttribute = searchParameterElement.attribute( SCOPE_TAG );
        if ( scopeAttribute != null )
        {
            try
            {
                searchParameter.setScope( convertSearchScope( scopeAttribute.getValue() ) );
            }
            catch ( IllegalArgumentException e )
            {
                throw new ConnectionIOException( NLS.bind(
                    BrowserCoreMessages.BrowserConnectionIO_UnableToParseScope, new String[]
                        { searchParameter.getName(), scopeAttribute.getValue() } ) );
            }
        }

        // Time limit
        Attribute timeLimitAttribute = searchParameterElement.attribute( TIME_LIMIT_TAG );
        if ( timeLimitAttribute != null )
        {
            try
            {
                searchParameter.setTimeLimit( Integer.parseInt( timeLimitAttribute.getValue() ) );
            }
            catch ( NumberFormatException e )
            {
                throw new ConnectionIOException( NLS.bind(
                    BrowserCoreMessages.BrowserConnectionIO_UnableToParseTimeLimit,
                    new String[]
                        { searchParameter.getName(), timeLimitAttribute.getValue() } ) );
            }
        }

        // Count limit
        Attribute countLimitAttribute = searchParameterElement.attribute( COUNT_LIMIT_TAG );
        if ( countLimitAttribute != null )
        {
            try
            {
                searchParameter.setCountLimit( Integer.parseInt( countLimitAttribute.getValue() ) );
            }
            catch ( NumberFormatException e )
            {
                throw new ConnectionIOException( NLS.bind(
                    BrowserCoreMessages.BrowserConnectionIO_UnableToParseCountLimit,
                    new String[]
                        { searchParameter.getName(), countLimitAttribute.getValue() } ) );
            }
        }

        // Alias dereferencing method
        Attribute aliasesDereferencingMethodAttribute = searchParameterElement
            .attribute( ALIASES_DEREFERENCING_METHOD_TAG );
        if ( aliasesDereferencingMethodAttribute != null )
        {
            try
            {
                searchParameter.setAliasesDereferencingMethod( Connection.AliasDereferencingMethod
                    .valueOf( aliasesDereferencingMethodAttribute.getValue() ) );
            }
            catch ( IllegalArgumentException e )
            {
                throw new ConnectionIOException(
                    NLS.bind(
                        BrowserCoreMessages.BrowserConnectionIO_UnableToParseAliasesDereferencingMethod,
                        new String[]
                            { searchParameter.getName(), aliasesDereferencingMethodAttribute.getValue() } ) );
            }
        }

        // Referrals handling method
        Attribute referralsHandlingMethodAttribute = searchParameterElement.attribute( REFERRALS_HANDLING_METHOD_TAG );
        if ( referralsHandlingMethodAttribute != null )
        {
            try
            {
                searchParameter.setReferralsHandlingMethod( Connection.ReferralHandlingMethod
                    .valueOf( referralsHandlingMethodAttribute.getValue() ) );
            }
            catch ( IllegalArgumentException e )
            {
                throw new ConnectionIOException(
                    NLS.bind(
                        BrowserCoreMessages.BrowserConnectionIO_UnableToParseReferralsHandlingMethod,
                        new String[]
                            { searchParameter.getName(), referralsHandlingMethodAttribute.getValue() } ) );
            }
        }

        // Controls
        Element controlsElement = searchParameterElement.element( CONTROLS_TAG );
        if ( controlsElement != null )
        {
            for ( Iterator<?> i = controlsElement.elementIterator( CONTROL_TAG ); i.hasNext(); )
            {
                Element controlElement = ( Element ) i.next();

                Attribute valueAttribute = controlElement.attribute( VALUE_TAG );
                if ( valueAttribute != null )
                {
                    byte[] bytes = Base64.decode( valueAttribute.getValue().toCharArray() );
                    ByteArrayInputStream bais = null;
                    ObjectInputStream ois = null;
                    try
                    {
                        bais = new ByteArrayInputStream( bytes );
                        ois = new ObjectInputStream( bais );
                        StudioControl control = ( StudioControl ) ois.readObject();
                        searchParameter.getControls().add( control );
                        ois.close();
                    }
                    catch ( Exception e )
                    {
                        throw new ConnectionIOException( NLS.bind(
                            BrowserCoreMessages.BrowserConnectionIO_UnableToParseControl, new String[]
                                { searchParameter.getName(), valueAttribute.getValue() } ) );
                    }
                }
            }
        }
View Full Code Here

Examples of org.apache.directory.studio.ldapbrowser.core.model.SearchParameter

        if ( browserConnection != null )
        {
            ISearch clone = null;
            for ( ISearch search : searches )
            {
                SearchParameter searchParameter = ( SearchParameter ) search.getSearchParameter().clone();
                clone = new Search( browserConnection, searchParameter );
                browserConnection.getSearchManager().addSearch( clone );
            }

            if ( searches.length == 1 )
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.