Package org.apache.directory.studio.ldapbrowser.core.model

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


                                        { Integer.toString( searchResultList.size() ) } ) );
                    }
                }
                catch ( Exception e )
                {
                    ConnectionException ce = JNDIUtils.createConnectionException( searchParameter, e );

                    if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
                    {
                        search.setCountLimitExceeded( true );
                    }
                    else
                    {
View Full Code Here


                        numberInBatch++;
                    }
                }
                catch ( Throwable e )
                {
                    ConnectionException ce = JNDIUtils.createConnectionException( null, e );

                    if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
                    {
                        // continue with search
                    }
                    else
                    {
View Full Code Here

    static void importLdifRecord( IBrowserConnection browserConnection, LdifRecord record, StudioProgressMonitor monitor )
        throws ConnectionException
    {
        if ( !record.isValid() )
        {
            throw new ConnectionException( BrowserCoreMessages.model__invalid_record );
        }

        String dn = record.getDnLine().getValueAsString();

        if ( record instanceof LdifContentRecord )
        {
            LdifContentRecord attrValRecord = ( LdifContentRecord ) record;
            LdifAttrValLine[] attrVals = attrValRecord.getAttrVals();
            Attributes jndiAttributes = new BasicAttributes();
            for ( int ii = 0; ii < attrVals.length; ii++ )
            {
                String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
                Object realValue = attrVals[ii].getValueAsObject();

                if ( jndiAttributes.get( attributeName ) != null )
                {
                    jndiAttributes.get( attributeName ).add( realValue );
                }
                else
                {
                    jndiAttributes.put( attributeName, realValue );
                }
            }

            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
                ReferralHandlingMethod.IGNORE, getControls( attrValRecord ), monitor, null );
        }
        else if ( record instanceof LdifChangeAddRecord )
        {
            LdifChangeAddRecord changeAddRecord = ( LdifChangeAddRecord ) record;
            LdifAttrValLine[] attrVals = changeAddRecord.getAttrVals();
            Attributes jndiAttributes = new BasicAttributes();
            for ( int ii = 0; ii < attrVals.length; ii++ )
            {
                String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
                Object realValue = attrVals[ii].getValueAsObject();

                if ( jndiAttributes.get( attributeName ) != null )
                {
                    jndiAttributes.get( attributeName ).add( realValue );
                }
                else
                {
                    jndiAttributes.put( attributeName, realValue );
                }
            }

            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
                ReferralHandlingMethod.IGNORE, getControls( changeAddRecord ), monitor, null );
        }
        else if ( record instanceof LdifChangeDeleteRecord )
        {
            LdifChangeDeleteRecord changeDeleteRecord = ( LdifChangeDeleteRecord ) record;
            browserConnection.getConnection().getJNDIConnectionWrapper().deleteEntry( dn,
                ReferralHandlingMethod.IGNORE, getControls( changeDeleteRecord ), monitor, null );
        }
        else if ( record instanceof LdifChangeModifyRecord )
        {
            LdifChangeModifyRecord modifyRecord = ( LdifChangeModifyRecord ) record;
            LdifModSpec[] modSpecs = modifyRecord.getModSpecs();
            ModificationItem[] mis = new ModificationItem[modSpecs.length];
            for ( int ii = 0; ii < modSpecs.length; ii++ )
            {
                LdifModSpecTypeLine modSpecType = modSpecs[ii].getModSpecType();
                LdifAttrValLine[] attrVals = modSpecs[ii].getAttrVals();

                Attribute attribute = new BasicAttribute( modSpecType.getUnfoldedAttributeDescription() );
                for ( int x = 0; x < attrVals.length; x++ )
                {
                    attribute.add( attrVals[x].getValueAsObject() );
                }

                if ( modSpecType.isAdd() )
                {
                    mis[ii] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attribute );
                }
                else if ( modSpecType.isDelete() )
                {
                    mis[ii] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attribute );
                }
                else if ( modSpecType.isReplace() )
                {
                    mis[ii] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attribute );
                }
            }

            browserConnection.getConnection().getJNDIConnectionWrapper().modifyEntry( dn, mis,
                ReferralHandlingMethod.IGNORE, getControls( modifyRecord ), monitor, null );
        }
        else if ( record instanceof LdifChangeModDnRecord )
        {
            LdifChangeModDnRecord modDnRecord = ( LdifChangeModDnRecord ) record;
            if ( modDnRecord.getNewrdnLine() != null && modDnRecord.getDeloldrdnLine() != null )
            {
                String newRdn = modDnRecord.getNewrdnLine().getValueAsString();
                boolean deleteOldRdn = modDnRecord.getDeloldrdnLine().isDeleteOldRdn();

                try
                {
                    LdapDN newDn;
                    if ( modDnRecord.getNewsuperiorLine() != null )
                        newDn = DnUtils.composeDn( newRdn, modDnRecord.getNewsuperiorLine().getValueAsString() );
                    else
                    {
                        LdapDN dnObject = new LdapDN( dn );
                        LdapDN parent = DnUtils.getParent( dnObject );
                        newDn = DnUtils.composeDn( newRdn, parent.getUpName() );
                    }

                    browserConnection.getConnection().getJNDIConnectionWrapper().renameEntry( dn, newDn.toString(),
                        deleteOldRdn, ReferralHandlingMethod.IGNORE, getControls( modDnRecord ), monitor, null );
                }
                catch ( InvalidNameException ne )
                {
                    throw new ConnectionException( ne );
                }
            }
        }
    }
View Full Code Here

    static void importLdifRecord( IBrowserConnection browserConnection, LdifRecord record, StudioProgressMonitor monitor )
        throws ConnectionException
    {
        if ( !record.isValid() )
        {
            throw new ConnectionException( BrowserCoreMessages.model__invalid_record );
        }

        String dn = record.getDnLine().getValueAsString();

        if ( record instanceof LdifContentRecord )
        {
            LdifContentRecord attrValRecord = ( LdifContentRecord ) record;
            LdifAttrValLine[] attrVals = attrValRecord.getAttrVals();
            Attributes jndiAttributes = new BasicAttributes();
            for ( int ii = 0; ii < attrVals.length; ii++ )
            {
                String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
                Object realValue = attrVals[ii].getValueAsObject();

                if ( jndiAttributes.get( attributeName ) != null )
                {
                    jndiAttributes.get( attributeName ).add( realValue );
                }
                else
                {
                    jndiAttributes.put( attributeName, realValue );
                }
            }

            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
                ReferralHandlingMethod.IGNORE, getControls( attrValRecord ), monitor, null );
        }
        else if ( record instanceof LdifChangeAddRecord )
        {
            LdifChangeAddRecord changeAddRecord = ( LdifChangeAddRecord ) record;
            LdifAttrValLine[] attrVals = changeAddRecord.getAttrVals();
            Attributes jndiAttributes = new BasicAttributes();
            for ( int ii = 0; ii < attrVals.length; ii++ )
            {
                String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
                Object realValue = attrVals[ii].getValueAsObject();

                if ( jndiAttributes.get( attributeName ) != null )
                {
                    jndiAttributes.get( attributeName ).add( realValue );
                }
                else
                {
                    jndiAttributes.put( attributeName, realValue );
                }
            }

            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
                ReferralHandlingMethod.IGNORE, getControls( changeAddRecord ), monitor, null );
        }
        else if ( record instanceof LdifChangeDeleteRecord )
        {
            LdifChangeDeleteRecord changeDeleteRecord = ( LdifChangeDeleteRecord ) record;
            browserConnection.getConnection().getJNDIConnectionWrapper().deleteEntry( dn,
                ReferralHandlingMethod.IGNORE, getControls( changeDeleteRecord ), monitor, null );
        }
        else if ( record instanceof LdifChangeModifyRecord )
        {
            LdifChangeModifyRecord modifyRecord = ( LdifChangeModifyRecord ) record;
            LdifModSpec[] modSpecs = modifyRecord.getModSpecs();
            ModificationItem[] mis = new ModificationItem[modSpecs.length];
            for ( int ii = 0; ii < modSpecs.length; ii++ )
            {
                LdifModSpecTypeLine modSpecType = modSpecs[ii].getModSpecType();
                LdifAttrValLine[] attrVals = modSpecs[ii].getAttrVals();

                Attribute attribute = new BasicAttribute( modSpecType.getUnfoldedAttributeDescription() );
                for ( int x = 0; x < attrVals.length; x++ )
                {
                    attribute.add( attrVals[x].getValueAsObject() );
                }

                if ( modSpecType.isAdd() )
                {
                    mis[ii] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attribute );
                }
                else if ( modSpecType.isDelete() )
                {
                    mis[ii] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attribute );
                }
                else if ( modSpecType.isReplace() )
                {
                    mis[ii] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attribute );
                }
            }

            browserConnection.getConnection().getJNDIConnectionWrapper().modifyEntry( dn, mis,
                ReferralHandlingMethod.IGNORE, getControls( modifyRecord ), monitor, null );
        }
        else if ( record instanceof LdifChangeModDnRecord )
        {
            LdifChangeModDnRecord modDnRecord = ( LdifChangeModDnRecord ) record;
            if ( modDnRecord.getNewrdnLine() != null && modDnRecord.getDeloldrdnLine() != null )
            {
                String newRdn = modDnRecord.getNewrdnLine().getValueAsString();
                boolean deleteOldRdn = modDnRecord.getDeloldrdnLine().isDeleteOldRdn();

                try
                {
                    LdapDN newDn;
                    if ( modDnRecord.getNewsuperiorLine() != null )
                        newDn = DnUtils.composeDn( newRdn, modDnRecord.getNewsuperiorLine().getValueAsString() );
                    else
                    {
                        LdapDN dnObject = new LdapDN( dn );
                        LdapDN parent = DnUtils.getParent( dnObject );
                        newDn = DnUtils.composeDn( newRdn, parent.getUpName() );
                    }

                    browserConnection.getConnection().getJNDIConnectionWrapper().renameEntry( dn, newDn.toString(),
                        deleteOldRdn, ReferralHandlingMethod.IGNORE, getControls( modDnRecord ), monitor, null );
                }
                catch ( InvalidNameException ne )
                {
                    throw new ConnectionException( ne );
                }
            }
        }
    }
View Full Code Here

                        numberInBatch++;
                    }
                }
                catch ( Throwable e )
                {
                    ConnectionException ce = JNDIUtils.createConnectionException( null, e );

                    if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
                    {
                        // continue with search
                    }
                    else
                    {
View Full Code Here

                                        { Integer.toString( searchResultList.size() ) } ) );
                    }
                }
                catch ( Exception e )
                {
                    ConnectionException ce = JNDIUtils.createConnectionException( searchParameter, e );

                    if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
                    {
                        search.setCountLimitExceeded( true );
                    }
                    else
                    {
View Full Code Here

    public static ConnectionException createConnectionException( SearchParameter searchParameter, Throwable e )
    {
      // TODO: remove when improving error handling
        e.printStackTrace();
       
        ConnectionException connectionException = null;
        ConnectionException lastException = null;

        do
        {
            String message = e.getMessage() != null ? e.getMessage() : e.getClass().getName();
            int ldapStatusCode = -1;

            // get LDAP status code
            // [LDAP: error code 21 - telephoneNumber: value #0 invalid per syntax]
            if ( message != null && message.startsWith( "[LDAP: error code " ) ) { //$NON-NLS-1$
                int begin = "[LDAP: error code ".length(); //$NON-NLS-1$
                int end = begin + 2;
                try
                {
                    ldapStatusCode = Integer.parseInt( message.substring( begin, end ).trim() );
                }
                catch ( NumberFormatException nfe )
                {
                }
            }

            // special causes
            // java_io_IOException=I/O exception occurred: {0}
            // java_io_EOFException=End of file encountered: {0}
            // java_io_FileNotFoundException=File not found: {0}
            // java_io_InterruptedIOException=I/O has been interrupted.
            // java_net_UnknownHostException=Cannot locate host: {0}
            // java_net_ConnectException=Cannot connect to host: {0}
            // java_net_SocketException=Socket Exception: {0}
            // java_net_NoRouteToHostException={0}
            if ( e instanceof ConnectException )
            {
                message = e.getMessage() + " (" + e.getMessage() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
            }
            if ( e instanceof NoRouteToHostException )
            {
                message += e.getMessage() + " (" + e.getMessage() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
            }
            if ( e instanceof UnknownHostException )
            {
                message = BrowserCoreMessages.model__unknown_host + e.getMessage();
            }
            if ( e instanceof SocketException )
            {
                message = e.getMessage() + " (" + e.getMessage() + ")";; //$NON-NLS-1$ //$NON-NLS-2$
            }

            ConnectionException ce = new ConnectionException( ldapStatusCode, message, e );
            if ( lastException != null )
            {
                lastException.initCause( ce );
            }
            lastException = ce;
View Full Code Here

                        numberInBatch++;
                    }
                }
                catch ( Throwable e )
                {
                    ConnectionException ce = JNDIUtils.createConnectionException( null, e );

                    if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
                    {
                        // continue with search
                    }
                    else
                    {
View Full Code Here

                                        { Integer.toString( searchResultList.size() ) } ) );
                    }
                }
                catch ( Exception e )
                {
                    ConnectionException ce = JNDIUtils.createConnectionException( searchParameter, e );

                    if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
                    {
                        search.setCountLimitExceeded( true );
                    }
                    else
                    {
                        monitor.reportError( ce );
                    }
                }

                // check for response controls
                try
                {
                    if ( enumeration != null )
                    {
                        Control[] jndiControls = enumeration.getResponseControls();
                        if ( jndiControls != null )
                        {
                            for ( Control jndiControl : jndiControls )
                            {
                                if ( jndiControl instanceof PagedResultsResponseControl )
                                {
                                    PagedResultsResponseControl prrc = ( PagedResultsResponseControl ) jndiControl;
                                    StudioPagedResultsControl studioControl = new StudioPagedResultsControl( prrc
                                        .getResultSize(), prrc.getCookie(), prrc.isCritical(), false );
                                    search.getResponseControls().add( studioControl );

                                    search.setCountLimitExceeded( prrc.getCookie() != null );
                                }
                                else
                                {
                                    StudioControl studioControl = new StudioControl();
                                    studioControl.setOid( jndiControl.getID() );
                                    studioControl.setCritical( jndiControl.isCritical() );
                                    studioControl.setControlValue( jndiControl.getEncodedValue() );
                                    search.getResponseControls().add( studioControl );
                                }
                            }
                        }
                    }
                }
                catch ( Exception e )
                {
                    ConnectionException ce = JNDIUtils.createConnectionException( searchParameter, e );
                    monitor.reportError( ce );
                }

                monitor.reportProgress( searchResultList.size() == 1 ? BrowserCoreMessages.model__retrieved_1_entry
                    : BrowserCoreMessages.bind( BrowserCoreMessages.model__retrieved_n_entries, new String[]
View Full Code Here

                        numberInBatch++;
                    }
                }
                catch ( Throwable e )
                {
                    ConnectionException ce = JNDIUtils.createConnectionException( null, e );

                    if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
                    {
                        // continue with search
                    }
                    else
                    {
View Full Code Here

TOP

Related Classes of org.apache.directory.studio.ldapbrowser.core.model.ConnectionException

Copyright © 2018 www.massapicom. 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.