KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > internal > model > Connection


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.core.internal.model;
22
23
24 import java.io.Serializable JavaDoc;
25 import java.io.Writer JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Set JavaDoc;
33
34 import org.apache.directory.ldapstudio.browser.core.BookmarkManager;
35 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
36 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
37 import org.apache.directory.ldapstudio.browser.core.SearchManager;
38 import org.apache.directory.ldapstudio.browser.core.events.ConnectionRenamedEvent;
39 import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
40 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
41 import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer;
42 import org.apache.directory.ldapstudio.browser.core.jobs.ExtendedProgressMonitor;
43 import org.apache.directory.ldapstudio.browser.core.model.ConnectionParameter;
44 import org.apache.directory.ldapstudio.browser.core.model.DN;
45 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
46 import org.apache.directory.ldapstudio.browser.core.model.IAuthHandler;
47 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
48 import org.apache.directory.ldapstudio.browser.core.model.IConnectionProvider;
49 import org.apache.directory.ldapstudio.browser.core.model.ICredentials;
50 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
51 import org.apache.directory.ldapstudio.browser.core.model.IRootDSE;
52 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
53 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
54 import org.apache.directory.ldapstudio.browser.core.model.IValue;
55 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
56 import org.apache.directory.ldapstudio.browser.core.model.NameException;
57 import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
58 import org.apache.directory.ldapstudio.browser.core.model.URL;
59 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
60 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
61 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
62 import org.eclipse.search.ui.ISearchPageScoreComputer;
63
64
65 public class Connection implements IConnection, Serializable JavaDoc
66 {
67
68     private static final long serialVersionUID = 2987596234755856270L;
69
70     private ConnectionParameter connectionParameter;
71
72     private IRootDSE rootDSE;
73
74     private Schema schema;
75
76     private SearchManager searchManager;
77
78     private BookmarkManager bookmarkManager;
79
80     private volatile Map JavaDoc dnToEntryCache;
81
82     private volatile Map JavaDoc entryToChildrenFilterMap;
83
84     private volatile Map JavaDoc entryToAttributeInfoMap;
85
86     private volatile Map JavaDoc entryToChildrenInfoMap;
87
88     private static final String JavaDoc DEFAULT_PROVIDER = JNDIConnectionProvider.class.getName();
89
90     transient IConnectionProvider connectionProvider;
91
92     transient ConnectionModifyHandler modifyHandler;
93
94     transient ConnectionSearchHandler searchHandler;
95
96
97     public Connection()
98     {
99         this( null, null, 0, 0, true, new DN(), 0, 0, IConnection.DEREFERENCE_ALIASES_NEVER,
100             IConnection.HANDLE_REFERRALS_IGNORE, IConnection.AUTH_ANONYMOUS, null, null );
101     }
102
103
104     public Connection( String JavaDoc name, String JavaDoc host, int port, int encryptionMethod, boolean fetchBaseDNs, DN baseDN,
105         int countLimit, int timeLimit, int aliasesDereferencingMethod, int referralsHandlingMethod, int authMethod,
106         String JavaDoc bindPrincipal, String JavaDoc bindPassword )
107     {
108
109         this.connectionParameter = new ConnectionParameter();
110         this.connectionParameter.setName( name );
111         this.connectionParameter.setHost( host );
112         this.connectionParameter.setPort( port );
113         this.connectionParameter.setEncryptionMethod( encryptionMethod );
114         this.connectionParameter.setCountLimit( countLimit );
115         this.connectionParameter.setTimeLimit( timeLimit );
116         this.connectionParameter.setAliasesDereferencingMethod( aliasesDereferencingMethod );
117         this.connectionParameter.setReferralsHandlingMethod( referralsHandlingMethod );
118         this.connectionParameter.setFetchBaseDNs( fetchBaseDNs );
119         this.connectionParameter.setBaseDN( baseDN );
120         this.connectionParameter.setAuthMethod( authMethod );
121         // this.connectionParameter.setBindDN(bindDn);
122
this.connectionParameter.setBindPrincipal( bindPrincipal );
123         this.connectionParameter.setBindPassword( bindPassword );
124
125         this.rootDSE = null;
126
127         this.schema = Schema.DEFAULT_SCHEMA;
128         this.searchManager = new SearchManager( this );
129         this.bookmarkManager = new BookmarkManager( this );
130
131         this.entryToChildrenFilterMap = new HashMap JavaDoc();
132         this.dnToEntryCache = new HashMap JavaDoc();
133         this.entryToAttributeInfoMap = new HashMap JavaDoc();
134         this.entryToChildrenInfoMap = new HashMap JavaDoc();
135
136         this.setConnectionProviderClassName( DEFAULT_PROVIDER );
137         this.modifyHandler = new ConnectionModifyHandler( this );
138         this.searchHandler = new ConnectionSearchHandler( this );
139     }
140
141
142     public URL getUrl()
143     {
144         return new URL( this );
145     }
146
147
148     public Object JavaDoc clone()
149     {
150         Connection newConnection = new Connection( this.getName(), this.getHost(), this.getPort(), this
151             .getEncryptionMethod(), this.isFetchBaseDNs(), this.getBaseDN(), this.getCountLimit(), this.getTimeLimit(),
152             this.getAliasesDereferencingMethod(), this.getReferralsHandlingMethod(), this.getAuthMethod(), this
153                 .getBindPrincipal(), this.getBindPassword() );
154
155         return newConnection;
156     }
157
158
159     public void reloadSchema( ExtendedProgressMonitor monitor )
160     {
161         monitor.reportProgress( BrowserCoreMessages.model__loading_schema );
162         this.loadSchema( monitor );
163     }
164
165
166     public void connect( ExtendedProgressMonitor monitor )
167     {
168         if ( this.connectionProvider == null )
169         {
170             if ( this.getConnectionProviderClassName() == null )
171             {
172                 monitor.reportError( BrowserCoreMessages.model__no_connection_provider );
173                 return;
174             }
175
176             try
177             {
178                 this.connectionProvider = ( IConnectionProvider ) Class.forName( this.getConnectionProviderClassName() )
179                     .newInstance();
180             }
181             catch ( Exception JavaDoc e )
182             {
183                 monitor.reportError( BrowserCoreMessages.model__no_connection_provider );
184                 return;
185             }
186         }
187
188         try
189         {
190             this.entryToChildrenFilterMap = new HashMap JavaDoc();
191             this.dnToEntryCache = new HashMap JavaDoc();
192             this.entryToAttributeInfoMap = new HashMap JavaDoc();
193             this.entryToChildrenInfoMap = new HashMap JavaDoc();
194
195             modifyHandler.connectionOpened();
196             searchHandler.connectionOpened();
197
198             monitor.reportProgress( BrowserCoreMessages.model__connecting );
199             this.connectionProvider.connect( this.connectionParameter, monitor );
200             monitor.worked( 1 );
201         }
202         catch ( ConnectionException e )
203         {
204             monitor.reportError( e.getMessage(), e );
205             this.connectionProvider = null;
206         }
207     }
208
209
210     public void bind( ExtendedProgressMonitor monitor )
211     {
212         this.connect( monitor );
213
214         if ( this.connectionProvider != null )
215         {
216             try
217             {
218                 monitor.reportProgress( BrowserCoreMessages.model__binding );
219
220                 IAuthHandler authHandler = BrowserCorePlugin.getDefault().getAuthHandler();
221                 if ( authHandler == null )
222                 {
223                     throw new ConnectionException( BrowserCoreMessages.model__no_auth_handler );
224                 }
225
226                 ICredentials credentials = authHandler.getCredentials( this.connectionParameter );
227                 if ( credentials == null )
228                 {
229                     throw new ConnectionException( BrowserCoreMessages.model__no_credentials );
230                 }
231
232                 this.connectionProvider.bind( this.connectionParameter, credentials, monitor );
233                 monitor.worked( 1 );
234             }
235             catch ( ConnectionException e )
236             {
237                 monitor.reportError( e.getMessage(), e );
238                 this.connectionProvider = null;
239             }
240         }
241     }
242
243
244     public void fetchRootDSE( ExtendedProgressMonitor monitor )
245     {
246         if ( this.connectionProvider != null && !monitor.errorsReported() )
247         {
248             try
249             {
250                 monitor.reportProgress( BrowserCoreMessages.model__loading_rootdse );
251                 this.loadRootDSE( monitor );
252                 monitor.worked( 1 );
253             }
254             catch ( Exception JavaDoc e )
255             {
256                 monitor.reportError( BrowserCoreMessages.model__error_loading_rootdse );
257                 this.rootDSE = null;
258             }
259
260             if ( monitor.errorsReported() )
261             {
262                 close();
263             }
264         }
265     }
266
267
268     public void open( ExtendedProgressMonitor monitor )
269     {
270         this.bind( monitor );
271         
272         this.fetchRootDSE( monitor );
273
274         if ( this.connectionProvider != null && this.rootDSE != null )
275         {
276             try
277             {
278                 monitor.reportProgress( BrowserCoreMessages.model__loading_schema );
279
280                 // check if schema is cached
281
if ( this.schema == Schema.DEFAULT_SCHEMA )
282                 {
283                     this.loadSchema( monitor );
284                 }
285                 else
286                 {
287                     if ( this.rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
288                     {
289                         // check if schema is up-to-date
290
SearchParameter sp = new SearchParameter();
291                         sp.setSearchBase( new DN( this.rootDSE.getAttribute(
292                             IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ).getStringValue() ) );
293                         sp.setFilter( Schema.SCHEMA_FILTER );
294                         sp.setScope( ISearch.SCOPE_OBJECT );
295                         sp.setReturningAttributes( new String JavaDoc[]
296                             { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
297                                 IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
298                         ISearch search = new Search( this, sp );
299                         // ISearch search = new Search(null, this, new
300
// DN(this.rootDSE.getAttribute("subschemaSubentry").getStringValue()),
301
// ISearch.FILTER_TRUE,
302
// new String[] {
303
// IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
304
// IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP },
305
// ISearch.SCOPE_OBJECT, 0, 0);
306
this.search( search, monitor );
307                         ISearchResult[] results = search.getSearchResults();
308
309                         if ( results != null && results.length == 1 )
310                         {
311                             String JavaDoc schemaTimestamp = results[0]
312                                 .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) != null ? results[0]
313                                 .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ).getStringValue()
314                                 : null;
315                             if ( schemaTimestamp == null )
316                             {
317                                 schemaTimestamp = results[0]
318                                     .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) != null ? results[0]
319                                     .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ).getStringValue()
320                                     : null;
321                             }
322                             String JavaDoc cacheTimestamp = this.schema.getModifyTimestamp() != null ? this.schema
323                                 .getModifyTimestamp() : this.schema.getCreateTimestamp();
324                             if ( cacheTimestamp == null
325                                 || ( cacheTimestamp != null && schemaTimestamp != null && schemaTimestamp
326                                     .compareTo( cacheTimestamp ) > 0 ) )
327                             {
328                                 this.loadSchema( monitor );
329                             }
330                         }
331                         else
332                         {
333                             this.schema = Schema.DEFAULT_SCHEMA;
334                             monitor.reportError( BrowserCoreMessages.model__no_schema_information );
335                         }
336                     }
337                     else
338                     {
339                         this.schema = Schema.DEFAULT_SCHEMA;
340                         monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
341                     }
342                 }
343
344             }
345             catch ( Exception JavaDoc e )
346             {
347                 this.schema = Schema.DEFAULT_SCHEMA;
348                 monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
349                 e.printStackTrace();
350                 return;
351             }
352
353             EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
354                 ConnectionUpdateEvent.EventDetail.CONNECTION_OPENED ), this );
355         }
356     }
357
358
359     public boolean isOpened()
360     {
361         return this.connectionProvider != null;
362     }
363
364
365     public boolean canOpen()
366     {
367         return !this.isOpened();
368     }
369
370
371     public boolean canClose()
372     {
373         return this.isOpened();
374     }
375
376
377     public void close()
378     {
379         if ( this.isOpened() )
380         {
381             if ( this.connectionProvider != null )
382             {
383                 try
384                 {
385                     this.connectionProvider.close();
386                 }
387                 catch ( ConnectionException ce )
388                 {
389                     ce.printStackTrace();
390                 }
391                 this.connectionProvider = null;
392             }
393
394             for ( int i = 0; i < this.getSearchManager().getSearchCount(); i++ )
395             {
396                 this.getSearchManager().getSearches()[i].setSearchResults( null );
397             }
398
399             this.dnToEntryCache.clear();
400             this.entryToAttributeInfoMap.clear();
401             this.entryToChildrenInfoMap.clear();
402             this.entryToChildrenFilterMap.clear();
403
404             modifyHandler.connectionClosed();
405             searchHandler.connectionClosed();
406
407             EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
408                 ConnectionUpdateEvent.EventDetail.CONNECTION_CLOSED ), this );
409             System.gc();
410         }
411     }
412
413
414     private void loadRootDSE( ExtendedProgressMonitor monitor ) throws Exception JavaDoc
415     {
416         if(rootDSE == null)
417         {
418             rootDSE = new RootDSE( this );
419             cacheEntry( rootDSE );
420         }
421
422         // get well-known root DSE attributes, includes + and *
423
ISearch search = new Search( null, this, new DN(), ISearch.FILTER_TRUE, ROOT_DSE_ATTRIBUTES, ISearch.SCOPE_OBJECT, 0,
424             0, IConnection.DEREFERENCE_ALIASES_NEVER, IConnection.HANDLE_REFERRALS_IGNORE, false, false, null );
425         search( search, monitor );
426
427         // get base DNs
428
if( !isFetchBaseDNs() && getBaseDN() != null && !"".equals( getBaseDN().toString() ))
429         {
430             // only add the specified base DN
431
DN dn = getBaseDN();
432             IEntry entry = new BaseDNEntry( new DN( dn ), this );
433             cacheEntry( entry );
434             rootDSE.addChild( entry );
435             
436             // check if entry exists
437
search = new Search( null, this, dn, ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, ISearch.SCOPE_OBJECT, 1, 0,
438                 IConnection.DEREFERENCE_ALIASES_NEVER, IConnection.HANDLE_REFERRALS_IGNORE, true, true, null );
439             search( search, monitor );
440         }
441         else
442         {
443             // get naming contexts
444
Set JavaDoc<String JavaDoc> namingContextSet = new HashSet JavaDoc<String JavaDoc>();
445             IAttribute attribute = rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_NAMINGCONTEXTS );
446             if ( attribute != null )
447             {
448                 String JavaDoc[] values = attribute.getStringValues();
449                 for ( int i = 0; i < values.length; i++ )
450                 {
451                     namingContextSet.add( values[i] );
452                 }
453             }
454             for ( String JavaDoc namingContext : namingContextSet )
455             {
456                 if ( !"".equals( namingContext ) ) { //$NON-NLS-1$
457
try
458                     {
459                         IEntry entry = new BaseDNEntry( new DN( namingContext ), this );
460                         rootDSE.addChild( entry );
461                         cacheEntry( entry );
462                     }
463                     catch ( Exception JavaDoc e )
464                     {
465                         monitor.reportError( BrowserCoreMessages.model__error_setting_base_dn, e );
466                     }
467                 }
468                 else
469                 {
470                     // special handling of empty namingContext: perform a one-level search and add all result DNs to the set
471
search = new Search( null, this, new DN(), ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, ISearch.SCOPE_ONELEVEL, 0,
472                         0, IConnection.DEREFERENCE_ALIASES_NEVER, IConnection.HANDLE_REFERRALS_IGNORE, false, false, null );
473                     search( search, monitor );
474                     ISearchResult[] results = search.getSearchResults();
475                     for ( int k = 0; results != null && k < results.length; k++ )
476                     {
477                         ISearchResult result = results[k];
478                         IEntry entry = result.getEntry();
479                         rootDSE.addChild( entry );
480                     }
481                 }
482             }
483         }
484
485         // get schema entry
486
DirectoryMetadataEntry[] schemaEntries = getDirectoryMetadataEntries( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY );
487         for ( int i = 0; i < schemaEntries.length; i++ )
488         {
489             schemaEntries[i].setSchemaEntry( true );
490             rootDSE.addChild( ( IEntry ) schemaEntries[i] );
491         }
492         
493         // get other metadata entries
494
String JavaDoc[] metadataAttributeNames = new String JavaDoc[]
495             { IRootDSE.ROOTDSE_ATTRIBUTE_MONITORCONTEXT, IRootDSE.ROOTDSE_ATTRIBUTE_CONFIGCONTEXT,
496                 IRootDSE.ROOTDSE_ATTRIBUTE_DSANAME };
497         for ( int x = 0; x < metadataAttributeNames.length; x++ )
498         {
499             DirectoryMetadataEntry[] metadataEntries = getDirectoryMetadataEntries( metadataAttributeNames[x] );
500             for ( int i = 0; i < metadataEntries.length; i++ )
501             {
502                 rootDSE.addChild( ( IEntry ) metadataEntries[i] );
503             }
504         }
505         
506         // set flags
507
rootDSE.setHasMoreChildren( false );
508         rootDSE.setAttributesInitialized( true );
509         rootDSE.setChildrenInitialized( true );
510         rootDSE.setHasChildrenHint( true );
511         rootDSE.setDirectoryEntry( true );
512
513     }
514
515
516     private DirectoryMetadataEntry[] getDirectoryMetadataEntries( String JavaDoc metadataAttributeName )
517         throws ModelModificationException
518     {
519         List JavaDoc metadataEntryList = new ArrayList JavaDoc();
520         IAttribute attribute = this.rootDSE.getAttribute( metadataAttributeName );
521         if ( attribute != null )
522         {
523             String JavaDoc[] values = attribute.getStringValues();
524             for ( int i = 0; i < values.length; i++ )
525             {
526                 try
527                 {
528                     metadataEntryList.add( new DN( values[i] ) );
529                 }
530                 catch ( NameException e )
531                 {
532                 }
533             }
534         }
535
536         DirectoryMetadataEntry[] metadataEntries = new DirectoryMetadataEntry[metadataEntryList.size()];
537         for ( int i = 0; i < metadataEntryList.size(); i++ )
538         {
539             metadataEntries[i] = new DirectoryMetadataEntry( ( DN ) metadataEntryList.get( i ), this );
540             metadataEntries[i].setDirectoryEntry( true );
541             cacheEntry( metadataEntries[i] );
542         }
543         return metadataEntries;
544     }
545
546
547     private void loadSchema( ExtendedProgressMonitor monitor )
548     {
549
550         this.schema = Schema.DEFAULT_SCHEMA;
551
552         try
553         {
554
555             if ( this.rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
556             {
557                 SearchParameter sp = new SearchParameter();
558                 sp.setSearchBase( new DN( this.rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY )
559                     .getStringValue() ) );
560                 sp.setFilter( Schema.SCHEMA_FILTER );
561                 sp.setScope( ISearch.SCOPE_OBJECT );
562                 sp.setReturningAttributes( new String JavaDoc[]
563                     { Schema.SCHEMA_ATTRIBUTE_OBJECTCLASSES, Schema.SCHEMA_ATTRIBUTE_ATTRIBUTETYPES,
564                         Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES, Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES,
565                         Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE, IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
566                         IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
567                 LdifEnumeration le = this.connectionProvider.search( sp, monitor );
568                 if ( le.hasNext( monitor ) )
569                 {
570                     LdifContentRecord schemaRecord = ( LdifContentRecord ) le.next( monitor );
571                     this.schema = new Schema();
572                     this.schema.loadFromRecord( schemaRecord );
573                     EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
574                         ConnectionUpdateEvent.EventDetail.SCHEMA_LOADED ), this );
575                 }
576                 else
577                 {
578                     monitor.reportError( BrowserCoreMessages.model__no_schema_information );
579                 }
580             }
581             else
582             {
583                 monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
584             }
585         }
586         catch ( Exception JavaDoc e )
587         {
588             monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
589             e.printStackTrace();
590         }
591
592         if ( this.schema == null )
593         {
594             this.schema = Schema.DEFAULT_SCHEMA;
595         }
596
597     }
598
599
600     public void search( ISearch searchRequest, ExtendedProgressMonitor monitor )
601     {
602         searchHandler.search( searchRequest, monitor );
603     }
604
605
606     public boolean existsEntry( DN dn, ExtendedProgressMonitor monitor )
607     {
608         return searchHandler.existsEntry( dn, monitor );
609     }
610
611
612     public IEntry getEntryFromCache( DN dn )
613     {
614
615         if ( this.dnToEntryCache != null && this.dnToEntryCache.containsKey( dn.toOidString( this.schema ) ) )
616         {
617             return ( IEntry ) dnToEntryCache.get( dn.toOidString( this.schema ) );
618         }
619         if ( this.rootDSE != null && this.rootDSE.getDn() != null && this.rootDSE.getDn().equals( dn ) )
620         {
621             return this.rootDSE;
622         }
623         return null;
624     }
625
626
627     public IEntry getEntry( DN dn, ExtendedProgressMonitor monitor )
628     {
629         return searchHandler.getEntry( dn, monitor );
630     }
631
632
633     public void create( IValue[] valuesToCreate, ExtendedProgressMonitor monitor )
634     {
635         modifyHandler.create( valuesToCreate, monitor );
636     }
637
638
639     public void modify( IValue oldValue, IValue newValue, ExtendedProgressMonitor monitor )
640     {
641         modifyHandler.modify( oldValue, newValue, monitor );
642     }
643
644
645     public void create( IEntry entryToCreate, ExtendedProgressMonitor monitor )
646     {
647         modifyHandler.create( entryToCreate, monitor );
648     }
649
650
651     public void rename( IEntry entryToRename, DN newDn, boolean deleteOldRdn, ExtendedProgressMonitor monitor )
652     {
653         modifyHandler.rename( entryToRename, newDn, deleteOldRdn, monitor );
654     }
655
656
657     public void move( IEntry entryToMove, DN newSuperior, ExtendedProgressMonitor monitor )
658     {
659         modifyHandler.move( entryToMove, newSuperior, monitor );
660     }
661
662
663     public LdifEnumeration exportLdif( SearchParameter searchParameter, ExtendedProgressMonitor monitor )
664         throws ConnectionException
665     {
666         LdifEnumeration subEnumeration = this.connectionProvider.search( searchParameter, monitor );
667         return subEnumeration;
668     }
669
670
671     public final String JavaDoc getName()
672     {
673         return this.connectionParameter.getName();
674     }
675
676
677     public final void setName( String JavaDoc name )
678     {
679         String JavaDoc oldName = this.getName();
680         this.connectionParameter.setName( name );
681         EventRegistry.fireConnectionUpdated( new ConnectionRenamedEvent( this, oldName ), this );
682     }
683
684
685     public boolean isFetchBaseDNs()
686     {
687         return this.connectionParameter.isFetchBaseDNs();
688     }
689
690
691     public void setFetchBaseDNs( boolean fetchBaseDNs )
692     {
693         this.connectionParameter.setFetchBaseDNs( fetchBaseDNs );
694         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
695             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
696     }
697
698
699     public DN getBaseDN()
700     {
701         return this.connectionParameter.getBaseDN();
702     }
703
704
705     public void setBaseDN( DN baseDN )
706     {
707         this.connectionParameter.setBaseDN( baseDN );
708         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
709             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
710     }
711
712
713     public int getCountLimit()
714     {
715         return this.connectionParameter.getCountLimit();
716     }
717
718
719     public void setCountLimit( int countLimit )
720     {
721         this.connectionParameter.setCountLimit( countLimit );
722         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
723             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
724     }
725
726
727     public String JavaDoc getHost()
728     {
729         return this.connectionParameter.getHost();
730     }
731
732
733     public void setHost( String JavaDoc host )
734     {
735         this.connectionParameter.setHost( host );
736         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
737             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
738     }
739
740
741     public int getPort()
742     {
743         return this.connectionParameter.getPort();
744     }
745
746
747     public void setPort( int port )
748     {
749         this.connectionParameter.setPort( port );
750         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
751             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
752     }
753
754
755     public int getAliasesDereferencingMethod()
756     {
757         return this.connectionParameter.getAliasesDereferencingMethod();
758     }
759
760
761     public void setAliasesDereferencingMethod( int aliasesDereferencingMethod )
762     {
763         this.connectionParameter.setAliasesDereferencingMethod( aliasesDereferencingMethod );
764         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
765             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
766     }
767
768
769     public int getReferralsHandlingMethod()
770     {
771         return this.connectionParameter.getReferralsHandlingMethod();
772     }
773
774
775     public void setReferralsHandlingMethod( int referralsHandlingMethod )
776     {
777         this.connectionParameter.setReferralsHandlingMethod( referralsHandlingMethod );
778         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
779             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
780     }
781
782
783     public int getEncryptionMethod()
784     {
785         return this.connectionParameter.getEncryptionMethod();
786     }
787
788
789     public void setEncryptionMethod( int encryptionMethod )
790     {
791         this.connectionParameter.setEncryptionMethod( encryptionMethod );
792         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
793             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
794     }
795
796
797     public int getTimeLimit()
798     {
799         return this.connectionParameter.getTimeLimit();
800     }
801
802
803     public void setTimeLimit( int timeLimit )
804     {
805         this.connectionParameter.setTimeLimit( timeLimit );
806         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
807             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
808     }
809
810
811     public String JavaDoc getBindPrincipal()
812     {
813         return this.connectionParameter.getBindPrincipal();
814     }
815
816
817     public void setBindPrincipal( String JavaDoc bindPrincipal )
818     {
819         this.connectionParameter.setBindPrincipal( bindPrincipal );
820         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
821             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
822     }
823
824
825     public String JavaDoc getBindPassword()
826     {
827         return this.connectionParameter.getBindPassword();
828     }
829
830
831     public void setBindPassword( String JavaDoc bindPassword )
832     {
833         this.connectionParameter.setBindPassword( bindPassword );
834         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
835             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
836     }
837
838
839     public int getAuthMethod()
840     {
841         return this.connectionParameter.getAuthMethod();
842     }
843
844
845     public void setAuthMethod( int authMethod )
846     {
847         this.connectionParameter.setAuthMethod( authMethod );
848         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
849             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
850     }
851
852
853     public String JavaDoc getConnectionProviderClassName()
854     {
855         return this.connectionParameter.getConnectionProviderClassName();
856     }
857
858
859     public void setConnectionProviderClassName( String JavaDoc connectionProviderClassName )
860     {
861         this.connectionParameter.setConnectionProviderClassName( connectionProviderClassName );
862         EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
863             ConnectionUpdateEvent.EventDetail.CONNECTION_PARAMETER_UPDATED ), this );
864     }
865
866
867     public final IRootDSE getRootDSE()
868     {
869         return this.rootDSE;
870     }
871
872
873     public Schema getSchema()
874     {
875         return schema;
876     }
877
878
879     public void setSchema( Schema schema )
880     {
881         this.schema = schema;
882     }
883
884
885     public ConnectionParameter getConnectionParameter()
886     {
887         return connectionParameter;
888     }
889
890
891     public void setConnectionParameter( ConnectionParameter connectionParameter )
892     {
893         this.connectionParameter = connectionParameter;
894     }
895
896
897     public String JavaDoc toString()
898     {
899         return this.connectionParameter.getName();
900     }
901
902
903     public SearchManager getSearchManager()
904     {
905         return searchManager;
906     }
907
908
909     public BookmarkManager getBookmarkManager()
910     {
911         return bookmarkManager;
912     }
913
914
915     public ModificationLogger getModificationLogger()
916     {
917         return modifyHandler.getModificationLogger();
918     }
919
920
921     public Object JavaDoc getAdapter( Class JavaDoc adapter )
922     {
923
924         if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) )
925         {
926             return new LdapSearchPageScoreComputer();
927         }
928         if ( adapter == IConnection.class )
929         {
930             return this;
931         }
932
933         return null;
934     }
935
936
937     public IConnection getConnection()
938     {
939         return this;
940     }
941
942
943     protected void cacheEntry( IEntry entry )
944     {
945         this.dnToEntryCache.put( entry.getDn().toOidString( this.schema ), entry );
946     }
947
948
949     protected void uncacheEntry( IEntry entry )
950     {
951         this.dnToEntryCache.remove( entry.getDn().toOidString( this.schema ) );
952     }
953
954
955     protected void uncacheEntry( DN dn )
956     {
957         this.dnToEntryCache.remove( dn.toOidString( this.schema ) );
958     }
959
960
961     protected String JavaDoc getChildrenFilter( IEntry entry )
962     {
963         return this.entryToChildrenFilterMap == null ? null : ( String JavaDoc ) this.entryToChildrenFilterMap.get( entry );
964     }
965
966
967     protected void setChildrenFilter( IEntry entry, String JavaDoc childrenFilter )
968     {
969         if ( childrenFilter == null || "".equals( childrenFilter ) ) { //$NON-NLS-1$
970
this.entryToChildrenFilterMap.remove( entry );
971         }
972         else
973         {
974             this.entryToChildrenFilterMap.put( entry, childrenFilter );
975         }
976     }
977
978
979     protected AttributeInfo getAttributeInfo( IEntry entry )
980     {
981         return this.entryToAttributeInfoMap == null ? null : ( AttributeInfo ) this.entryToAttributeInfoMap.get( entry );
982     }
983
984
985     protected void setAttributeInfo( IEntry entry, AttributeInfo ai )
986     {
987         if ( ai == null )
988         {
989             this.entryToAttributeInfoMap.remove( entry );
990         }
991         else
992         {
993             this.entryToAttributeInfoMap.put( entry, ai );
994         }
995     }
996
997
998     protected ChildrenInfo getChildrenInfo( IEntry entry )
999     {
1000        return this.entryToChildrenInfoMap == null ? null : ( ChildrenInfo ) this.entryToChildrenInfoMap.get( entry );
1001    }
1002
1003
1004    protected void setChildrenInfo( IEntry entry, ChildrenInfo si )
1005    {
1006        if ( si == null )
1007        {
1008            this.entryToChildrenInfoMap.remove( entry );
1009        }
1010        else
1011        {
1012            this.entryToChildrenInfoMap.put( entry, si );
1013        }
1014    }
1015
1016
1017    public void delete( IEntry entry, ExtendedProgressMonitor monitor )
1018    {
1019        modifyHandler.delete( entry, monitor );
1020    }
1021
1022
1023    public void delete( IValue[] valuesToDelete, ExtendedProgressMonitor monitor )
1024    {
1025        modifyHandler.delete( valuesToDelete, monitor );
1026    }
1027
1028
1029    public void delete( IAttribute[] attriubtesToDelete, ExtendedProgressMonitor monitor )
1030    {
1031        modifyHandler.delete( attriubtesToDelete, monitor );
1032    }
1033
1034
1035    public void importLdif( LdifEnumeration enumeration, Writer JavaDoc logWriter, boolean continueOnError,
1036        ExtendedProgressMonitor monitor )
1037    {
1038        modifyHandler.importLdif( enumeration, logWriter, continueOnError, monitor );
1039    }
1040
1041
1042    public synchronized boolean isSuspended()
1043    {
1044        return modifyHandler.isSuspended();
1045    }
1046
1047
1048    public synchronized void suspend()
1049    {
1050        modifyHandler.suspend();
1051    }
1052
1053
1054    public synchronized void resume( ExtendedProgressMonitor monitor )
1055    {
1056        modifyHandler.resume( monitor );
1057    }
1058
1059
1060    public synchronized void reset()
1061    {
1062        modifyHandler.reset();
1063    }
1064
1065}
1066
Popular Tags