View Javadoc

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.server.protocol.shared.catalog;
22  
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import org.apache.directory.server.constants.ApacheSchemaConstants;
28  import org.apache.directory.server.core.CoreSession;
29  import org.apache.directory.server.core.entry.ServerEntry;
30  import org.apache.directory.server.core.filtering.EntryFilteringCursor;
31  import org.apache.directory.server.protocol.shared.store.DirectoryServiceOperation;
32  import org.apache.directory.shared.ldap.entry.EntryAttribute;
33  import org.apache.directory.shared.ldap.filter.FilterParser;
34  import org.apache.directory.shared.ldap.filter.SearchScope;
35  import org.apache.directory.shared.ldap.message.AliasDerefMode;
36  import org.apache.directory.shared.ldap.name.LdapDN;
37  
38  
39  /**
40   * A Session operation for building a catalog.
41   *
42   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
43   * @version $Rev: 682235 $, $Date: 2008-08-04 02:43:52 +0200 (Mo, 04 Aug 2008) $
44   */
45  public class GetCatalog implements DirectoryServiceOperation
46  {
47      private static final long serialVersionUID = -6657995003127926278L;
48  
49  
50      /**
51       * Note that the base is relative to the existing context.
52       */
53      public Object execute( CoreSession session, LdapDN base ) throws Exception
54      {
55          String filter = "(objectClass=" + ApacheSchemaConstants.APACHE_CATALOG_ENTRY_OC + ")";
56  
57          EntryFilteringCursor list = session.search( 
58              LdapDN.EMPTY_LDAPDN, 
59              SearchScope.SUBTREE, 
60              FilterParser.parse( filter ), 
61              AliasDerefMode.DEREF_ALWAYS,
62              null );
63  
64          Map<String, String> catalog = new HashMap<String, String>();
65  
66          list.beforeFirst();
67          
68          while ( list.next() )
69          {
70              ServerEntry result = list.get();
71  
72              String name = null;
73              EntryAttribute attribute = result.get( ApacheSchemaConstants.APACHE_CATALOGUE_ENTRY_NAME_AT );
74              
75              if ( attribute != null )
76              {
77                  name = attribute.getString();
78              }
79              
80              String basedn = null;
81              attribute = result.get( ApacheSchemaConstants.APACHE_CATALOGUE_ENTRY_BASE_DN_AT );
82              
83              if ( attribute != null )
84              {
85                  basedn = attribute.getString();
86              }
87              
88  
89              catalog.put( name, basedn );
90          }
91  
92          return catalog;
93      }
94  }