You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/12/18 18:15:08 UTC
svn commit: r488345 [6/12] - in /directory/sandbox/pamarcelot/ldapstudio:
ldapstudio-browser-core/ ldapstudio-browser-core/META-INF/
ldapstudio-browser-core/about_files/ ldapstudio-browser-core/lib/
ldapstudio-browser-core/src/ ldapstudio-browser-core/...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/DummyEntry.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/DummyEntry.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/DummyEntry.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/DummyEntry.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.events.AttributeAddedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.AttributeDeletedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.ModelModifier;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierachie;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.model.RDN;
+import org.apache.directory.ldapstudio.browser.core.model.URL;
+import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Subschema;
+
+
+public class DummyEntry implements IEntry
+{
+
+ private static final long serialVersionUID = 4833907766031149971L;
+
+ private DN dn;
+
+ private DummyConnection dummyConnection;
+
+ private String connectionName;
+
+ private Map attributeMap;
+
+
+ protected DummyEntry()
+ {
+ }
+
+
+ public DummyEntry( DN dn, IConnection connection )
+ {
+ if ( connection instanceof DummyConnection )
+ {
+ this.dummyConnection = ( DummyConnection ) connection;
+ }
+ else
+ {
+ this.connectionName = connection.getName();
+ }
+
+ this.dn = dn;
+ attributeMap = new LinkedHashMap();
+ }
+
+
+ public void setDn( DN dn )
+ {
+ this.dn = dn;
+ }
+
+
+ public void addAttribute( IAttribute attributeToAdd, ModelModifier source ) throws ModelModificationException
+ {
+ attributeMap.put( attributeToAdd.getDescription().toLowerCase(), attributeToAdd );
+ EventRegistry.fireEntryUpdated( new AttributeAddedEvent( attributeToAdd.getEntry().getConnection(), this,
+ attributeToAdd, attributeToAdd.getEntry().getConnection() ), this );
+ }
+
+
+ public void addChild( IEntry childrenToAdd, ModelModifier source )
+ {
+ }
+
+
+ public void deleteAttribute( IAttribute attributeToDelete, ModelModifier source ) throws ModelModificationException
+ {
+ attributeMap.remove( attributeToDelete.getDescription().toLowerCase() );
+ EventRegistry.fireEntryUpdated( new AttributeDeletedEvent( attributeToDelete.getEntry().getConnection(), this,
+ attributeToDelete, attributeToDelete.getEntry().getConnection() ), this );
+ }
+
+
+ public void deleteChild( IEntry childrenToDelete, ModelModifier source )
+ {
+ }
+
+
+ public IAttribute getAttribute( String attributeDescription )
+ {
+ return ( IAttribute ) attributeMap.get( attributeDescription.toLowerCase() );
+ }
+
+
+ public AttributeHierachie getAttributeWithSubtypes( String attributeDescription )
+ {
+
+ AttributeDescription ad = new AttributeDescription( attributeDescription );
+
+ List attributeList = new ArrayList();
+ Iterator iterator = attributeMap.values().iterator();
+ while ( iterator.hasNext() )
+ {
+ IAttribute attribute = ( IAttribute ) iterator.next();
+
+ AttributeDescription other = new AttributeDescription( attributeDescription );
+ if ( other.isSubtypeOf( ad, getConnection().getSchema() ) )
+ {
+ attributeList.add( attribute );
+ }
+ }
+
+ if ( attributeList.isEmpty() )
+ {
+ return null;
+ }
+ else
+ {
+ AttributeHierachie ah = new AttributeHierachie( this, attributeDescription, ( IAttribute[] ) attributeList
+ .toArray( new IAttribute[attributeList.size()] ) );
+ return ah;
+ }
+ }
+
+
+ public IAttribute[] getAttributes()
+ {
+ return ( IAttribute[] ) attributeMap.values().toArray( new IAttribute[attributeMap.size()] );
+ }
+
+
+ public IConnection getConnection()
+ {
+ return dummyConnection != null ? dummyConnection : BrowserCorePlugin.getDefault().getConnectionManager()
+ .getConnection( this.connectionName );
+ }
+
+
+ public DN getDn()
+ {
+ return dn;
+ }
+
+
+ public URL getUrl()
+ {
+ return new URL( getConnection(), getDn() );
+ }
+
+
+ public IEntry getParententry()
+ {
+ return null;
+ }
+
+
+ public RDN getRdn()
+ {
+ return dn.getRdn();
+ }
+
+
+ public IEntry[] getChildren()
+ {
+ return null;
+ }
+
+
+ public int getChildrenCount()
+ {
+ return -1;
+ }
+
+
+ public String getChildrenFilter()
+ {
+ return ""; //$NON-NLS-1$
+ }
+
+
+ public Subschema getSubschema()
+ {
+ return new Subschema( this );
+ }
+
+
+ public boolean hasMoreChildren()
+ {
+ return false;
+ }
+
+
+ public boolean hasParententry()
+ {
+ return false;
+ }
+
+
+ public boolean hasChildren()
+ {
+ return false;
+ }
+
+
+ public boolean isAlias()
+ {
+ return Arrays.asList( this.getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_ALIAS );
+ }
+
+
+ public boolean isAttributesInitialized()
+ {
+ return true;
+ }
+
+
+ public boolean isConsistent()
+ {
+ // check empty attributes and empty values
+ Iterator attributeIterator = attributeMap.values().iterator();
+ while ( attributeIterator.hasNext() )
+ {
+ IAttribute attribute = ( IAttribute ) attributeIterator.next();
+ if ( !attribute.isConsistent() )
+ return false;
+ }
+
+ // check objectclass attribute
+ if ( !attributeMap.containsKey( IAttribute.OBJECTCLASS_ATTRIBUTE.toLowerCase() ) )
+ {
+ return false;
+ }
+ IAttribute ocAttribute = ( IAttribute ) attributeMap.get( IAttribute.OBJECTCLASS_ATTRIBUTE.toLowerCase() );
+ String[] ocValues = ocAttribute.getStringValues();
+ boolean structuralObjectClassAvailable = false;
+ for ( int i = 0; i < ocValues.length; i++ )
+ {
+ ObjectClassDescription ocd = this.getConnection().getSchema().getObjectClassDescription( ocValues[i] );
+ if ( ocd.isStructural() )
+ {
+ structuralObjectClassAvailable = true;
+ break;
+ }
+ }
+ if ( !structuralObjectClassAvailable )
+ {
+ return false;
+ }
+
+ // check must-attributes
+ String[] mustAttributeNames = this.getSubschema().getMustAttributeNames();
+ for ( int i = 0; i < mustAttributeNames.length; i++ )
+ {
+ if ( !attributeMap.containsKey( mustAttributeNames[i].toLowerCase() ) )
+ return false;
+ }
+
+ return true;
+ }
+
+
+ public boolean isDirectoryEntry()
+ {
+ return false;
+ }
+
+
+ public boolean isReferral()
+ {
+ return Arrays.asList( this.getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_REFERRAL );
+ }
+
+
+ public boolean isSubentry()
+ {
+ return Arrays.asList( this.getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_SUBENTRY );
+ }
+
+
+ public boolean isChildrenInitialized()
+ {
+ return false;
+ }
+
+
+ public void moveTo( IEntry newParent, ModelModifier source ) throws ModelModificationException
+ {
+ }
+
+
+ public void rename( RDN newRdn, boolean deleteOldRdn, ModelModifier source ) throws ModelModificationException
+ {
+
+ }
+
+
+ public void setAlias( boolean b )
+ {
+ }
+
+
+ public void setAttributesInitialized( boolean b, ModelModifier source )
+ {
+ }
+
+
+ public void setDirectoryEntry( boolean isDirectoryEntry )
+ {
+ }
+
+
+ public void setHasMoreChildren( boolean b, ModelModifier source )
+ {
+ }
+
+
+ public void setHasChildrenHint( boolean b, ModelModifier source )
+ {
+ }
+
+
+ public void setReferral( boolean b )
+ {
+ }
+
+
+ public void setSubentry( boolean b )
+ {
+ }
+
+
+ public void setChildrenFilter( String filter )
+ {
+ }
+
+
+ public void setChildrenInitialized( boolean b, ModelModifier source )
+ {
+ }
+
+
+ public Object getAdapter( Class adapter )
+ {
+ return null;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/DummySSLSocketFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/DummySSLSocketFactory.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/DummySSLSocketFactory.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/DummySSLSocketFactory.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+
+public class DummySSLSocketFactory extends SSLSocketFactory
+{
+
+ private static SocketFactory instance;
+
+
+ public static SocketFactory getDefault()
+ {
+ if ( instance == null )
+ {
+ instance = new DummySSLSocketFactory();
+ }
+ return instance;
+ }
+
+ private SSLSocketFactory delegate;
+
+
+ public DummySSLSocketFactory()
+ {
+
+ try
+ {
+ TrustManager tm = new X509TrustManager()
+ {
+ public X509Certificate[] getAcceptedIssuers()
+ {
+ return new X509Certificate[0];
+ }
+
+
+ public void checkClientTrusted( X509Certificate[] arg0, String arg1 ) throws CertificateException
+ {
+ }
+
+
+ public void checkServerTrusted( X509Certificate[] arg0, String arg1 ) throws CertificateException
+ {
+ }
+ };
+ TrustManager[] tma =
+ { tm };
+ SSLContext sc = SSLContext.getInstance( "TLS" ); //$NON-NLS-1$
+ sc.init( null, tma, new SecureRandom() );
+ delegate = sc.getSocketFactory();
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+
+ public String[] getDefaultCipherSuites()
+ {
+ return delegate.getDefaultCipherSuites();
+ }
+
+
+ public String[] getSupportedCipherSuites()
+ {
+ return delegate.getSupportedCipherSuites();
+ }
+
+
+ public Socket createSocket( Socket arg0, String arg1, int arg2, boolean arg3 ) throws IOException
+ {
+ try
+ {
+ return delegate.createSocket( arg0, arg1, arg2, arg3 );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+
+ public Socket createSocket( String arg0, int arg1 ) throws IOException, UnknownHostException
+ {
+ try
+ {
+ return delegate.createSocket( arg0, arg1 );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+
+ public Socket createSocket( InetAddress arg0, int arg1 ) throws IOException
+ {
+ try
+ {
+ return delegate.createSocket( arg0, arg1 );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+
+ public Socket createSocket( String arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException,
+ UnknownHostException
+ {
+ try
+ {
+ return delegate.createSocket( arg0, arg1, arg2, arg3 );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+
+ public Socket createSocket( InetAddress arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException
+ {
+ try
+ {
+ return delegate.createSocket( arg0, arg1, arg2, arg3 );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Entry.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Entry.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Entry.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Entry.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.events.ModelModifier;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.model.RDN;
+
+
+public class Entry extends AbstractEntry
+{
+
+ private static final long serialVersionUID = -4718107307581983276L;
+
+ protected RDN rdn;
+
+ protected IEntry parent;
+
+
+ protected Entry()
+ {
+ }
+
+
+ public Entry( IEntry parent, RDN rdn, ModelModifier source ) throws ModelModificationException
+ {
+ super();
+
+ if ( parent == null )
+ {
+ throw new ModelModificationException( BrowserCoreMessages.model__empty_entry );
+ }
+ if ( rdn == null )
+ {
+ throw new ModelModificationException( BrowserCoreMessages.model__empty_rdn );
+ }
+ if ( "".equals( rdn.toString() ) ) { //$NON-NLS-1$
+ throw new ModelModificationException( BrowserCoreMessages.model__empty_rdn );
+ }
+
+ this.parent = parent;
+ this.rdn = rdn;
+ }
+
+
+ // performance opt.
+ public RDN getRdn()
+ {
+ return this.rdn;
+ }
+
+
+ public DN getDn()
+ {
+ DN dn = new DN( new RDN( this.rdn ), this.parent.getDn() );
+ return dn;
+ }
+
+
+ public IEntry getParententry()
+ {
+ return this.parent;
+ }
+
+
+ public IConnection getConnection()
+ {
+ return this.getParententry().getConnection();
+ }
+
+
+ protected void setRdn( RDN newRdn )
+ {
+ this.rdn = newRdn;
+ }
+
+
+ protected void setParent( IEntry newParent )
+ {
+ this.parent = newParent;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIConnectionContext.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIConnectionContext.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIConnectionContext.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIConnectionContext.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,793 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import java.util.Hashtable;
+
+import javax.naming.CommunicationException;
+import javax.naming.Context;
+import javax.naming.InsufficientResourcesException;
+import javax.naming.Name;
+import javax.naming.NameNotFoundException;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.ServiceUnavailableException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.StartTlsRequest;
+import javax.naming.ldap.StartTlsResponse;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSession;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.jobs.ExtendedProgressMonitor;
+
+
+public class JNDIConnectionContext
+{
+
+ private Control[] connCtls;
+
+ private boolean useStartTLS;
+
+ private String authMethod;
+
+ private String principal;
+
+ private String credentials;
+
+ private Hashtable environment;
+
+ private InitialLdapContext context;
+
+ private boolean isConnected;
+
+ private Thread jobThread;
+
+
+ public JNDIConnectionContext() throws NamingException
+ {
+ }
+
+
+ public void connect( String host, int port, boolean useLdaps, boolean useStartTLS, Control[] connCtls,
+ ExtendedProgressMonitor monitor ) throws NamingException
+ {
+
+ this.environment = new Hashtable();
+ this.environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); //$NON-NLS-1$
+ this.environment.put( "java.naming.ldap.version", "3" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // timeouts
+ if ( !useLdaps )
+ {
+ this.environment.put( "com.sun.jndi.ldap.connect.timeout", "10000" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ this.environment.put( "com.sun.jndi.dns.timeout.initial", "2000" ); //$NON-NLS-1$ //$NON-NLS-2$
+ this.environment.put( "com.sun.jndi.dns.timeout.retries", "3" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // ldaps://
+ if ( useLdaps )
+ {
+ environment.put( Context.PROVIDER_URL, "ldaps://" + host + ":" + port ); //$NON-NLS-1$ //$NON-NLS-2$
+ environment.put( Context.SECURITY_PROTOCOL, "ssl" ); //$NON-NLS-1$
+ environment
+ .put(
+ "java.naming.ldap.factory.socket", "org.apache.directory.ldapstudio.browser.internal.model.DummySSLSocketFactory" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else
+ {
+ environment.put( Context.PROVIDER_URL, "ldap://" + host + ":" + port ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ this.useStartTLS = useStartTLS;
+
+ this.connCtls = connCtls;
+
+ this.context = null;
+ this.isConnected = false;
+ this.jobThread = null;
+
+ try
+ {
+ this.doConnect( monitor );
+ }
+ catch ( NamingException ne )
+ {
+ this.close();
+ throw ne;
+ }
+ }
+
+
+ public void bindAnonymous( ExtendedProgressMonitor monitor ) throws NamingException
+ {
+ this.authMethod = "none"; //$NON-NLS-1$
+ this.principal = ""; //$NON-NLS-1$
+ this.credentials = ""; //$NON-NLS-1$
+
+ try
+ {
+ this.doBind( monitor );
+ }
+ catch ( NamingException ne )
+ {
+ this.close();
+ throw ne;
+ }
+ }
+
+
+ public void bindSimple( String user, String password, ExtendedProgressMonitor monitor ) throws NamingException
+ {
+ this.authMethod = "simple"; //$NON-NLS-1$
+ this.principal = user;
+ this.credentials = password;
+
+ try
+ {
+ this.doBind( monitor );
+ }
+ catch ( NamingException ne )
+ {
+ this.close();
+ throw ne;
+ }
+ }
+
+
+ public void close() throws NamingException
+ {
+ if ( this.jobThread != null )
+ {
+ Thread t = this.jobThread;
+ this.jobThread = null;
+ t.interrupt();
+ }
+ if ( this.context != null )
+ {
+ this.context.close();
+ this.context = null;
+ }
+ this.isConnected = false;
+ System.gc();
+ }
+
+
+ public NameParser getNameParser() throws NamingException
+ {
+ if ( this.context != null )
+ {
+ return this.context.getNameParser( "" ); //$NON-NLS-1$
+ }
+ else
+ {
+ throw new NamingException( BrowserCoreMessages.model__no_connection );
+ }
+ }
+
+
+ public NamingEnumeration search( final String searchBase, final String filter, final SearchControls controls,
+ final String derefAliasMethod, final String handleReferralsMethod, final Control[] ldapControls,
+ final ExtendedProgressMonitor monitor ) throws NamingException
+ {
+ // start
+ InnerRunnable runnable = new InnerRunnable()
+ {
+ private NamingEnumeration namingEnumeration = null;
+
+ private NamingException namingException = null;
+
+
+ public void run()
+ {
+
+ try
+ {
+
+ // Control[] ldapControls = null;
+ // try {
+ // //Control subEntryControl = new
+ // JNDISubentriesControl();
+ // Control subEntryControl = new
+ // JNDIControl("1.3.6.1.4.1.4203.1.10.1", false, new
+ // byte[]{0x01, 0x01, ( byte ) 0xFF});
+ // ldapControls = new Control[]{subEntryControl};
+ // }
+ // catch(Exception e) {
+ // e.printStackTrace();
+ // }
+
+ LdapContext searchCtx = context.newInstance( ldapControls );
+ try
+ {
+ searchCtx.addToEnvironment( "java.naming.ldap.derefAliases", derefAliasMethod ); //$NON-NLS-1$
+ searchCtx.addToEnvironment( Context.REFERRAL, handleReferralsMethod );
+
+ }
+ catch ( NamingException e )
+ {
+ this.namingException = e;
+ }
+
+ try
+ {
+ Name searchBaseName = getNameParser().parse( searchBase );
+ this.namingEnumeration = searchCtx.search( searchBaseName, filter, controls );
+ }
+ catch ( NameNotFoundException nffe )
+ {
+
+ }
+ catch ( NamingException ne )
+ {
+ this.namingException = ne;
+ }
+
+ }
+ catch ( NamingException e )
+ {
+ this.namingException = e;
+ }
+
+ }
+
+
+ public NamingException getException()
+ {
+ return this.namingException;
+ }
+
+
+ public Object getResult()
+ {
+ return this.namingEnumeration;
+ }
+
+
+ public void reset()
+ {
+ this.namingEnumeration = null;
+ this.namingException = null;
+ }
+
+ };
+ this.checkConnectionAndRunAndMonitor( runnable, monitor );
+
+ if ( runnable.getException() != null )
+ {
+ throw runnable.getException();
+ }
+ else if ( runnable.getResult() != null && runnable.getResult() instanceof NamingEnumeration )
+ {
+ return ( NamingEnumeration ) runnable.getResult();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ void modifyAttributes( final String dn, final ModificationItem[] modificationItems, final Control[] controls,
+ final ExtendedProgressMonitor monitor ) throws NamingException
+ {
+
+ InnerRunnable runnable = new InnerRunnable()
+ {
+ private NamingException namingException = null;
+
+
+ public void run()
+ {
+ try
+ {
+ LdapContext modCtx = context.newInstance( controls );
+ modCtx.addToEnvironment( Context.REFERRAL, "throw" ); //$NON-NLS-1$
+
+ Name name = getNameParser().parse( dn );
+ modCtx.modifyAttributes( name, modificationItems );
+ }
+ catch ( NamingException ne )
+ {
+ this.namingException = ne;
+ }
+ }
+
+
+ public NamingException getException()
+ {
+ return this.namingException;
+ }
+
+
+ public Object getResult()
+ {
+ return null;
+ }
+
+
+ public void reset()
+ {
+ this.namingException = null;
+ }
+ };
+ this.checkConnectionAndRunAndMonitor( runnable, monitor );
+
+ if ( runnable.getException() != null )
+ {
+ throw runnable.getException();
+ }
+ }
+
+
+ void rename( final String oldDn, final String newDn, final boolean deleteOldRdn, final Control[] controls,
+ final ExtendedProgressMonitor monitor ) throws NamingException
+ {
+
+ InnerRunnable runnable = new InnerRunnable()
+ {
+ private NamingException namingException = null;
+
+
+ public void run()
+ {
+ try
+ {
+ LdapContext modCtx = context.newInstance( controls );
+ modCtx.addToEnvironment( Context.REFERRAL, "throw" ); //$NON-NLS-1$
+
+ Name oldName = getNameParser().parse( oldDn );
+ Name newName = getNameParser().parse( newDn );
+ modCtx.rename( oldName, newName );
+
+ }
+ catch ( NamingException ne )
+ {
+ this.namingException = ne;
+ }
+ }
+
+
+ public NamingException getException()
+ {
+ return this.namingException;
+ }
+
+
+ public Object getResult()
+ {
+ return null;
+ }
+
+
+ public void reset()
+ {
+ this.namingException = null;
+ }
+ };
+ this.checkConnectionAndRunAndMonitor( runnable, monitor );
+
+ if ( runnable.getException() != null )
+ {
+ throw runnable.getException();
+ }
+ }
+
+
+ void createSubcontext( final String dn, final Attributes attributes, final Control[] controls,
+ final ExtendedProgressMonitor monitor ) throws NamingException
+ {
+
+ InnerRunnable runnable = new InnerRunnable()
+ {
+ private NamingException namingException = null;
+
+
+ public void run()
+ {
+ try
+ {
+ LdapContext modCtx = context.newInstance( controls );
+ modCtx.addToEnvironment( Context.REFERRAL, "throw" ); //$NON-NLS-1$
+
+ Name name = getNameParser().parse( dn );
+ modCtx.createSubcontext( name, attributes );
+ }
+ catch ( NamingException ne )
+ {
+ this.namingException = ne;
+ }
+ }
+
+
+ public NamingException getException()
+ {
+ return this.namingException;
+ }
+
+
+ public Object getResult()
+ {
+ return null;
+ }
+
+
+ public void reset()
+ {
+ this.namingException = null;
+ }
+ };
+ this.checkConnectionAndRunAndMonitor( runnable, monitor );
+
+ if ( runnable.getException() != null )
+ {
+ throw runnable.getException();
+ }
+ }
+
+
+ void destroySubcontext( final String dn, final Control[] controls, final ExtendedProgressMonitor monitor )
+ throws NamingException
+ {
+
+ InnerRunnable runnable = new InnerRunnable()
+ {
+ private NamingException namingException = null;
+
+
+ public void run()
+ {
+ try
+ {
+ LdapContext modCtx = context.newInstance( controls );
+ modCtx.addToEnvironment( Context.REFERRAL, "throw" ); //$NON-NLS-1$
+
+ Name name = getNameParser().parse( dn );
+ modCtx.destroySubcontext( name );
+ }
+ catch ( NamingException ne )
+ {
+ this.namingException = ne;
+ }
+ }
+
+
+ public NamingException getException()
+ {
+ return this.namingException;
+ }
+
+
+ public Object getResult()
+ {
+ return null;
+ }
+
+
+ public void reset()
+ {
+ this.namingException = null;
+ }
+ };
+ this.checkConnectionAndRunAndMonitor( runnable, monitor );
+
+ if ( runnable.getException() != null )
+ {
+ throw runnable.getException();
+ }
+ }
+
+
+ private void doConnect( final ExtendedProgressMonitor monitor ) throws NamingException
+ {
+
+ this.context = null;
+ this.isConnected = true;
+
+ InnerRunnable runnable = new InnerRunnable()
+ {
+ private NamingException namingException = null;
+
+
+ public void run()
+ {
+ try
+ {
+ context = new InitialLdapContext( environment, connCtls );
+
+ if ( useStartTLS )
+ {
+ try
+ {
+ StartTlsResponse tls = ( StartTlsResponse ) context
+ .extendedOperation( new StartTlsRequest() );
+ tls.setHostnameVerifier( new HostnameVerifier()
+ {
+ public boolean verify( String arg0, SSLSession arg1 )
+ {
+ return true;
+ }
+ } );
+ // SSLSession session = tls.negotiate(new
+ // DummySSLSocketFactory());
+
+ // System.out.println("Session: " +
+ // session.toString());
+ // System.out.println("Protocol: " +
+ // session.getProtocol());
+ // System.out.println("PeerHost: " +
+ // session.getPeerHost());
+ // System.out.println("CipherSuite: " +
+ // session.getCipherSuite());
+ // System.out.println("PeerCerts: " +
+ // Arrays.asList(session.getPeerCertificates()));
+ // //System.out.println("LocalCerts: " +
+ // Arrays.asList(session.getLocalCertificates()));
+ // System.out.println("SessionContext: " +
+ // session.getSessionContext());
+
+ }
+ catch ( Exception e )
+ {
+ this.namingException = new NamingException( e.getMessage() != null ? e.getMessage()
+ : "Error while establishing TLS session" ); //$NON-NLS-1$
+ this.namingException.setRootCause( e );
+ context.close();
+ }
+ }
+
+ }
+ catch ( NamingException ne )
+ {
+ this.namingException = ne;
+ }
+ }
+
+
+ public NamingException getException()
+ {
+ return this.namingException;
+ }
+
+
+ public Object getResult()
+ {
+ return null;
+ }
+
+
+ public void reset()
+ {
+ this.namingException = null;
+ }
+ };
+ this.runAndMonitor( runnable, monitor );
+
+ if ( runnable.getException() != null )
+ {
+ throw runnable.getException();
+ }
+ else if ( this.context != null )
+ {
+ // all OK
+ }
+ else
+ {
+ throw new NamingException( "???" ); //$NON-NLS-1$
+ }
+ }
+
+
+ private void doBind( final ExtendedProgressMonitor monitor ) throws NamingException
+ {
+
+ if ( this.context != null && this.isConnected )
+ {
+
+ InnerRunnable runnable = new InnerRunnable()
+ {
+ private NamingException namingException = null;
+
+
+ public void run()
+ {
+ try
+ {
+ environment.put( Context.SECURITY_AUTHENTICATION, authMethod );
+ environment.put( Context.SECURITY_PRINCIPAL, principal );
+ environment.put( Context.SECURITY_CREDENTIALS, credentials );
+ context = new InitialLdapContext( environment, connCtls );
+ }
+ catch ( NamingException ne )
+ {
+ this.namingException = ne;
+ }
+ }
+
+
+ public NamingException getException()
+ {
+ return this.namingException;
+ }
+
+
+ public Object getResult()
+ {
+ return null;
+ }
+
+
+ public void reset()
+ {
+ this.namingException = null;
+ }
+ };
+ this.runAndMonitor( runnable, monitor );
+
+ if ( runnable.getException() != null )
+ {
+ throw runnable.getException();
+ }
+ else if ( this.context != null )
+ {
+ // all OK
+ }
+ else
+ {
+ throw new NamingException( "???" ); //$NON-NLS-1$
+ }
+
+ }
+ else
+ {
+ throw new NamingException( BrowserCoreMessages.model__no_connection );
+ }
+ }
+
+
+ private void checkConnectionAndRunAndMonitor( final InnerRunnable runnable, final ExtendedProgressMonitor monitor )
+ throws NamingException
+ {
+
+ // System.out.println("Context: " + this.context);
+
+ // check connection
+ if ( !this.isConnected || this.context == null )
+ {
+ this.doConnect( monitor );
+ this.doBind( monitor );
+ }
+ if ( this.context == null )
+ {
+ throw new NamingException( BrowserCoreMessages.model__no_connection );
+ }
+
+ // loop for reconnection
+ for ( int i = 0; i <= 1; i++ )
+ {
+
+ this.runAndMonitor( runnable, monitor );
+
+ // check reconnection
+ if ( i == 0
+ && runnable.getException() != null
+ && ( ( runnable.getException() instanceof CommunicationException )
+ || ( runnable.getException() instanceof ServiceUnavailableException ) || ( runnable.getException() instanceof InsufficientResourcesException ) ) )
+ {
+
+ this.doConnect( monitor );
+ this.doBind( monitor );
+ runnable.reset();
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+
+ private void runAndMonitor( final InnerRunnable runnable, final ExtendedProgressMonitor monitor )
+ throws CancelException
+ {
+
+ if ( !monitor.isCanceled() )
+ {
+
+ // monitor
+ ExtendedProgressMonitor.CancelListener listener = new ExtendedProgressMonitor.CancelListener()
+ {
+ public void cancelRequested( ExtendedProgressMonitor.CancelEvent event )
+ {
+ if ( monitor.isCanceled() )
+ {
+ if ( jobThread.isAlive() )
+ {
+ jobThread.interrupt();
+ }
+ if ( context != null )
+ {
+ try
+ {
+ context.close();
+ }
+ catch ( NamingException ne )
+ {
+ }
+ isConnected = false;
+ context = null;
+ System.gc();
+ }
+ isConnected = false;
+ }
+ }
+ };
+ monitor.addCancelListener( listener );
+ this.jobThread = Thread.currentThread();
+
+ // run
+ try
+ {
+
+ // try {
+ // Thread.sleep(5000);
+ // } catch (InterruptedException e) {
+ // System.out.println(System.currentTimeMillis() + ": sleep
+ // interrupted!");
+ // }
+ // System.out.println(System.currentTimeMillis() + ": " +
+ // runnable);
+
+ runnable.run();
+ }
+ finally
+ {
+ monitor.removeCancelListener( listener );
+ this.jobThread = null;
+ }
+
+ if ( monitor.isCanceled() )
+ {
+ throw new CancelException();
+ }
+
+ }
+ }
+
+ interface InnerRunnable extends Runnable
+ {
+ public NamingException getException();
+
+
+ public Object getResult();
+
+
+ public void reset();
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIConnectionProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIConnectionProvider.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIConnectionProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIConnectionProvider.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,613 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import java.net.ConnectException;
+import java.net.NoRouteToHostException;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.ReferralException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.Control;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.jobs.ExtendedProgressMonitor;
+import org.apache.directory.ldapstudio.browser.core.model.ConnectionParameter;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IConnectionProvider;
+import org.apache.directory.ldapstudio.browser.core.model.ICredentials;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.NameException;
+import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeDeleteRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModDnRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifControlLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecTypeLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifSepLine;
+
+
+public class JNDIConnectionProvider implements IConnectionProvider
+{
+
+ private JNDIConnectionContext context;
+
+
+ public JNDIConnectionProvider()
+ {
+ }
+
+
+ public void connect( ConnectionParameter parameter, ExtendedProgressMonitor monitor ) throws ConnectionException
+ {
+ try
+ {
+ this.context = new JNDIConnectionContext();
+ this.context.connect( parameter.getHost(), parameter.getPort(),
+ parameter.getEncryptionMethod() == IConnection.ENCYRPTION_LDAPS,
+ parameter.getEncryptionMethod() == IConnection.ENCYRPTION_STARTTLS, null, monitor );
+ }
+ catch ( NamingException ne )
+ {
+ this.context = null;
+ throw createConnectionException( null, ne );
+ }
+ }
+
+
+ public void bind( ConnectionParameter parameter, ICredentials credentials, ExtendedProgressMonitor monitor )
+ throws ConnectionException
+ {
+ try
+ {
+ if ( parameter.getAuthMethod() == IConnection.AUTH_SIMPLE )
+ {
+ String bindDN = credentials.getBindDN();
+ String bindPassword = credentials.getBindPassword();
+ this.context.bindSimple( bindDN, bindPassword, monitor );
+ }
+ else if ( parameter.getAuthMethod() == IConnection.AUTH_ANONYMOUS )
+ {
+ this.context.bindAnonymous( monitor );
+ }
+
+ }
+ catch ( NamingException ne )
+ {
+ this.context = null;
+ throw createConnectionException( null, ne );
+ }
+ }
+
+
+ public void close() throws ConnectionException
+ {
+ if ( this.context != null )
+ {
+ try
+ {
+ this.context.close();
+ this.context = null;
+ }
+ catch ( NamingException e )
+ {
+ }
+ }
+ }
+
+
+ public LdifEnumeration search( SearchParameter parameter, ExtendedProgressMonitor monitor )
+ throws ConnectionException
+ {
+ SearchControls controls = new SearchControls();
+ switch ( parameter.getScope() )
+ {
+ case ISearch.SCOPE_OBJECT:
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ break;
+ case ISearch.SCOPE_ONELEVEL:
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ break;
+ case ISearch.SCOPE_SUBTREE:
+ controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+ break;
+ default:
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ }
+ controls.setReturningAttributes( parameter.getReturningAttributes() );
+ controls.setCountLimit( parameter.getCountLimit() );
+ controls.setTimeLimit( parameter.getTimeLimit() );
+ String filter = parameter.getFilter();
+ String derefAliasMethod = getDerefAliasMethod( parameter );
+ String handleReferralsMethod = getReferralsHandlingMethod( parameter.getReferralsHandlingMethod() );
+
+ Control[] ldapControls = null;
+ if ( parameter.getControls() != null )
+ {
+ org.apache.directory.ldapstudio.browser.core.model.Control[] ctls = parameter.getControls();
+ ldapControls = new Control[ctls.length];
+ for ( int i = 0; i < ctls.length; i++ )
+ {
+ ldapControls[i] = new JNDIControl( ctls[i].getOid(), ctls[i].isCritical(), ctls[i].getControlValue() );
+ }
+ // Control subEntryControl = new
+ // JNDIControl("1.3.6.1.4.1.4203.1.10.1", false, new
+ // byte[]{0x01, 0x01, ( byte ) 0xFF});
+ // ldapControls = new Control[]{subEntryControl};
+ }
+
+ try
+ {
+ NamingEnumeration list = this.context.search( parameter.getSearchBase().toString(), filter, controls,
+ derefAliasMethod, handleReferralsMethod, ldapControls, monitor );
+ return new LdifEnumerationImpl( list, parameter );
+ }
+ catch ( NamingException e )
+ {
+ throw createConnectionException( parameter, e );
+ }
+
+ }
+
+
+ public void applyModification( LdifRecord record, int referralsHandlingMethod, ExtendedProgressMonitor 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();
+ // String valueType = attrVals[ii].getValueType();
+ // String value = attrVals[ii].getValue();
+ Object realValue = attrVals[ii].getValueAsObject();
+
+ if ( jndiAttributes.get( attributeName ) != null )
+ {
+ jndiAttributes.get( attributeName ).add( realValue );
+ }
+ else
+ {
+ jndiAttributes.put( attributeName, realValue );
+ }
+ }
+
+ try
+ {
+ this.context.createSubcontext( dn, jndiAttributes, getControls( attrValRecord ), monitor );
+ }
+ catch ( NamingException ne )
+ {
+ throw createConnectionException( null, ne );
+ }
+ }
+ 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 );
+ }
+ }
+
+ try
+ {
+ this.context.createSubcontext( dn, jndiAttributes, getControls( changeAddRecord ), monitor );
+ }
+ catch ( NamingException ne )
+ {
+ throw createConnectionException( null, ne );
+ }
+ }
+ else if ( record instanceof LdifChangeDeleteRecord )
+ {
+ LdifChangeDeleteRecord changeDeleteRecord = ( LdifChangeDeleteRecord ) record;
+ try
+ {
+ this.context.destroySubcontext( dn, getControls( changeDeleteRecord ), monitor );
+ }
+ catch ( NamingException ne )
+ {
+ throw createConnectionException( null, ne );
+ }
+ }
+ 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 );
+ }
+ }
+
+ try
+ {
+ this.context.modifyAttributes( dn, mis, getControls( modifyRecord ), monitor );
+ }
+ catch ( NamingException ne )
+ {
+ throw createConnectionException( null, ne );
+ }
+ }
+ 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
+ {
+ DN newDn;
+ if ( modDnRecord.getNewsuperiorLine() != null )
+ newDn = new DN( newRdn, modDnRecord.getNewsuperiorLine().getValueAsString() );
+ else
+ {
+ DN dnObject = new DN( dn );
+ newDn = new DN( newRdn.toString(), dnObject.getParentDn().toString() );
+ }
+
+ try
+ {
+ this.context.rename( dn.toString(), newDn.toString(), deleteOldRdn, getControls( modDnRecord ),
+ monitor );
+ }
+ catch ( NamingException ne )
+ {
+ throw createConnectionException( null, ne );
+ }
+ }
+ catch ( NameException ne )
+ {
+ throw new ConnectionException( ne );
+ }
+ }
+ }
+ }
+
+
+ private Control[] getControls( LdifRecord record )
+ {
+ Control[] controls = null;
+ if ( record instanceof LdifChangeRecord )
+ {
+ LdifChangeRecord changeRecord = ( LdifChangeRecord ) record;
+ LdifControlLine[] controlLines = changeRecord.getControls();
+ controls = new Control[controlLines.length];
+ for ( int i = 0; i < controlLines.length; i++ )
+ {
+ LdifControlLine line = controlLines[i];
+ // TODO: encoded control value
+ controls[i] = new JNDIControl( line.getUnfoldedOid(), line.isCritical(), null );
+ }
+ }
+ return controls;
+ }
+
+ class LdifEnumerationImpl implements LdifEnumeration
+ {
+
+ private NamingEnumeration enumeration;
+
+ private SearchParameter parameter;
+
+
+ public LdifEnumerationImpl( NamingEnumeration enumeration, SearchParameter parameter )
+ {
+ this.enumeration = enumeration;
+ this.parameter = parameter;
+ }
+
+
+ public boolean hasNext( ExtendedProgressMonitor monitor ) throws ConnectionException
+ {
+ try
+ {
+ return enumeration != null && enumeration.hasMore();
+ }
+ catch ( NamingException e )
+ {
+ throw createConnectionException( parameter, e );
+ }
+ }
+
+
+ public LdifContainer next( ExtendedProgressMonitor monitor ) throws ConnectionException
+ {
+
+ try
+ {
+ SearchResult sr = ( SearchResult ) enumeration.next();
+
+ DN dn = JNDIUtils.getDn( sr, parameter.getSearchBase().toString(), context );
+ LdifContentRecord record = LdifContentRecord.create( dn.toString() );
+
+ NamingEnumeration attributeEnumeration = sr.getAttributes().getAll();
+ while ( attributeEnumeration.hasMore() )
+ {
+ Attribute attribute = ( Attribute ) attributeEnumeration.next();
+ String attributeName = attribute.getID();
+ NamingEnumeration valueEnumeration = attribute.getAll();
+ while ( valueEnumeration.hasMore() )
+ {
+ Object o = valueEnumeration.next();
+ if ( o instanceof String )
+ {
+ record.addAttrVal( LdifAttrValLine.create( attributeName, ( String ) o ) );
+ }
+ if ( o instanceof byte[] )
+ {
+ record.addAttrVal( LdifAttrValLine.create( attributeName, ( byte[] ) o ) );
+ }
+ }
+ }
+
+ record.finish( LdifSepLine.create() );
+
+ return record;
+
+ }
+ catch ( NamingException e )
+ {
+ throw createConnectionException( parameter, e );
+ }
+ catch ( NameException e )
+ {
+ throw new ConnectionException( e );
+ }
+ catch ( NoSuchFieldException e )
+ {
+ throw new ConnectionException( e );
+ }
+ }
+
+ }
+
+
+ private ConnectionException createConnectionException( SearchParameter searchParameter, Throwable e )
+ {
+
+ ConnectionException connectionException = null;
+ ConnectionException lastException = null;
+
+ do
+ {
+
+ String message = e.getMessage() != null ? e.getMessage() : e.getClass().getName();
+ int ldapStatusCode = -1;
+ String[] referrals = null;
+
+ // 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$
+ }
+ if ( e instanceof ReferralException )
+ {
+
+ message = "Referrals: "; //$NON-NLS-1$
+ ReferralException re;
+ ArrayList referralsList = new ArrayList();
+
+ re = ( ReferralException ) e;
+ message += BrowserCoreConstants.LINE_SEPARATOR + re.getReferralInfo();
+ referralsList.add( re.getReferralInfo() );
+
+ while ( re.skipReferral() )
+ {
+ try
+ {
+ Context ctx = re.getReferralContext();
+ ctx.list( "" ); //$NON-NLS-1$
+ }
+ catch ( NamingException e1 )
+ {
+ if ( e1 instanceof ReferralException )
+ {
+ re = ( ReferralException ) e1;
+ message += BrowserCoreConstants.LINE_SEPARATOR + re.getReferralInfo();
+ referralsList.add( re.getReferralInfo() );
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ referrals = ( String[] ) referralsList.toArray( new String[referralsList.size()] );
+ }
+
+ ConnectionException ce;
+ if ( referrals != null )
+ {
+ ce = new org.apache.directory.ldapstudio.browser.core.internal.model.ReferralException(
+ searchParameter, referrals, ldapStatusCode, message, e );
+ }
+ else
+ {
+ ce = new ConnectionException( ldapStatusCode, message, e );
+ }
+ if ( lastException != null )
+ {
+ lastException.initCause( ce );
+ }
+ lastException = ce;
+ if ( connectionException == null )
+ {
+ connectionException = lastException;
+ }
+
+ // next cause
+ e = e.getCause();
+ }
+ while ( e != null );
+
+ return connectionException;
+
+ }
+
+
+ private String getDerefAliasMethod( SearchParameter parameter )
+ {
+ String m = "always"; //$NON-NLS-1$
+
+ switch ( parameter.getAliasesDereferencingMethod() )
+ {
+ case IConnection.DEREFERENCE_ALIASES_NEVER:
+ m = "never"; //$NON-NLS-1$
+ break;
+ case IConnection.DEREFERENCE_ALIASES_ALWAYS:
+ m = "always"; //$NON-NLS-1$
+ break;
+ case IConnection.DEREFERENCE_ALIASES_FINDING:
+ m = "finding"; //$NON-NLS-1$
+ break;
+ case IConnection.DEREFERENCE_ALIASES_SEARCH:
+ m = "searching"; //$NON-NLS-1$
+ break;
+ }
+
+ return m;
+ }
+
+
+ private String getReferralsHandlingMethod( int referralHandlingMethod )
+ {
+ String m = "follow"; //$NON-NLS-1$
+
+ switch ( referralHandlingMethod )
+ {
+ case IConnection.HANDLE_REFERRALS_IGNORE:
+ m = "ignore"; //$NON-NLS-1$
+ break;
+ case IConnection.HANDLE_REFERRALS_FOLLOW:
+ // m = "follow"; //$NON-NLS-1$
+ m = "throw"; //$NON-NLS-1$
+ break;
+ }
+
+ return m;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIControl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIControl.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIControl.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIControl.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import javax.naming.ldap.Control;
+
+
+public class JNDIControl implements Control
+{
+
+ private static final long serialVersionUID = -2051120560938595303L;
+
+ private String id;
+
+ private boolean criticality;
+
+ private byte[] encodedValue;
+
+
+ public JNDIControl( String id )
+ {
+ this( id, false, null );
+ }
+
+
+ public JNDIControl( String id, boolean criticality, byte[] encodedValue )
+ {
+ this.id = id;
+ this.criticality = criticality;
+ this.encodedValue = encodedValue;
+ }
+
+
+ public byte[] getEncodedValue()
+ {
+ return encodedValue;
+ }
+
+
+ public String getID()
+ {
+ return id;
+ }
+
+
+ public boolean isCritical()
+ {
+ return criticality;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDISubentriesControl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDISubentriesControl.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDISubentriesControl.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDISubentriesControl.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import javax.naming.ldap.Control;
+
+
+public class JNDISubentriesControl implements Control
+{
+
+ private static final long serialVersionUID = -6614360496036854589L;
+
+
+ // Note that TRUE visibility has the three octet encoding { 01 01 FF }
+ // and FALSE visibility has the three octet encoding { 01 01 00 }.
+
+ public JNDISubentriesControl()
+ {
+ // super(OID, false, null);
+ // super.value = setEncodedValue(FIRST, SECOND, sub?TRUE:FALSE);
+ }
+
+
+ public byte[] getEncodedValue()
+ {
+
+ byte[] value = new byte[]
+ {
+ // 0x30, 0x00,
+ // ( byte ) 0xa0, 0x23, // controls
+ // 0x30, 0x21,
+ // 0x04, 0x17,
+ // '1', '.', '3', '.', '6', '.', '1', '.', '4', '.', '1', '.',
+ // '4', '2', '0', '3',
+ // '.', '1', '.', '1', '0', '.', '1', // SubEntry OID
+ // 0x01, 0x01, ( byte ) 0xFF, // criticality: true
+ // 0x04, 0x03,
+ 0x01, 0x01, ( byte ) 0xFF // SubEntry visibility
+ };
+ return value;
+ }
+
+
+ public String getID()
+ {
+ return "1.3.6.1.4.1.4203.1.10.1";
+ }
+
+
+ public boolean isCritical()
+ {
+ return false;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIUtils.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIUtils.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/JNDIUtils.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.NameException;
+import org.apache.directory.ldapstudio.browser.core.model.URL;
+
+
+public class JNDIUtils
+{
+
+ public static DN getDn( SearchResult sr, String base, JNDIConnectionContext context ) throws NamingException,
+ NameException, NoSuchFieldException
+ {
+ DN dn = null;
+ if ( sr.isRelative() )
+ {
+ Name name = ( Name ) context.getNameParser().parse( base ).clone();
+ Name rdnName = context.getNameParser().parse( unescapeJndiName( sr.getName() ) );
+ name.addAll( rdnName );
+ dn = new DN( name.toString() );
+ }
+ else
+ {
+ URL url = new URL( sr.getName() );
+ dn = url.getDn();
+ // dn = new DN(sr.getName());
+ }
+ return dn;
+ }
+
+
+ /**
+ * Correct some JNDI encodings...
+ *
+ * @param name
+ * @return
+ */
+ public static String unescapeJndiName( String name )
+ {
+
+ if ( name.startsWith( "\"" ) && name.endsWith( "\"" ) ) { //$NON-NLS-1$ //$NON-NLS-2$
+ name = name.substring( 1, name.length() - 1 );
+ }
+
+ name = name.replaceAll( "\\\\\\\\\"", "\\\\\"" ); //$NON-NLS-1$ //$NON-NLS-2$
+ name = name.replaceAll( "\\\\2C", "\\\\," ); //$NON-NLS-1$ //$NON-NLS-2$
+ name = name.replaceAll( "\\\\3B", "\\\\;" ); //$NON-NLS-1$ //$NON-NLS-2$
+ name = name.replaceAll( "\\\\22", "\\\\\"" ); //$NON-NLS-1$ //$NON-NLS-2$
+ name = name.replaceAll( "\\\\3C", "\\\\<" ); //$NON-NLS-1$ //$NON-NLS-2$
+ name = name.replaceAll( "\\\\3E", "\\\\>" ); //$NON-NLS-1$ //$NON-NLS-2$
+ name = name.replaceAll( "\\\\2B", "\\\\+" ); //$NON-NLS-1$ //$NON-NLS-2$
+ name = name.replaceAll( "\\\\5C", "\\\\\\\\" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ return name;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ModificationLogger.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ModificationLogger.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ModificationLogger.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ModificationLogger.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.logging.FileHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
+
+
+public class ModificationLogger
+{
+
+ private Connection connection;
+
+ private FileHandler fileHandler;
+
+ private Logger logger;
+
+
+ public ModificationLogger( Connection connection )
+ {
+ this.connection = connection;
+ }
+
+
+ private void initModificationLogger()
+ {
+ this.logger = Logger.getAnonymousLogger();
+ this.logger.setLevel( Level.ALL );
+
+ String logfileName = ConnectionManager.getModificationLogFileName( connection.getName() );
+ try
+ {
+ fileHandler = new FileHandler( logfileName, 100000, 10, true );
+ fileHandler.setFormatter( new Formatter()
+ {
+ public String format( LogRecord record )
+ {
+ return record.getMessage();
+ }
+ } );
+ this.logger.addHandler( fileHandler );
+ }
+ catch ( SecurityException e )
+ {
+ e.printStackTrace();
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+ public void dispose()
+ {
+ if ( this.logger != null )
+ {
+ Handler[] handlers = this.logger.getHandlers();
+ for ( int i = 0; i < handlers.length; i++ )
+ {
+ handlers[i].close();
+ }
+
+ this.logger = null;
+ }
+ }
+
+
+ public void log( String s )
+ {
+ if ( this.logger == null )
+ {
+ if ( connection.getName() != null )
+ {
+ this.initModificationLogger();
+ }
+ }
+
+ if ( this.logger != null )
+ {
+ this.logger.log( Level.ALL, s );
+ }
+ }
+
+
+ public File[] getFiles()
+ {
+ if ( this.logger == null )
+ {
+ if ( connection.getName() != null )
+ {
+ this.initModificationLogger();
+ }
+ }
+
+ try
+ {
+ return getLogFiles( this.fileHandler );
+ }
+ catch ( Exception e )
+ {
+ return new File[0];
+ }
+ }
+
+
+ private static File[] getLogFiles( FileHandler fileHandler ) throws Exception
+ {
+ Field field = getFieldFromClass( "java.util.logging.FileHandler", "files" ); //$NON-NLS-1$ //$NON-NLS-2$
+ field.setAccessible( true );
+ File[] files = ( File[] ) field.get( fileHandler );
+ return files;
+ }
+
+
+ private static Field getFieldFromClass( String className, String fieldName ) throws Exception
+ {
+ Class clazz = Class.forName( className );
+ Field[] fields = clazz.getDeclaredFields();
+
+ for ( int i = 0; i < fields.length; i++ )
+ {
+ if ( fields[i].getName().equals( fieldName ) )
+ return fields[i];
+ }
+ return null;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ReferralBaseEntry.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ReferralBaseEntry.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ReferralBaseEntry.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ReferralBaseEntry.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.internal.model;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+
+
+public class ReferralBaseEntry extends DelegateEntry
+{
+
+ private static final long serialVersionUID = -6351277968774226912L;
+
+
+ protected ReferralBaseEntry()
+ {
+ }
+
+
+ public ReferralBaseEntry( IConnection connection, DN dn )
+ {
+ super( connection, dn );
+ }
+
+}