001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020
021 package org.apache.directory.server.protocol.shared.catalog;
022
023
024 import java.util.HashMap;
025 import java.util.Map;
026
027 import org.apache.directory.server.constants.ApacheSchemaConstants;
028 import org.apache.directory.server.core.CoreSession;
029 import org.apache.directory.server.core.entry.ServerEntry;
030 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
031 import org.apache.directory.server.protocol.shared.store.DirectoryServiceOperation;
032 import org.apache.directory.shared.ldap.entry.EntryAttribute;
033 import org.apache.directory.shared.ldap.filter.FilterParser;
034 import org.apache.directory.shared.ldap.filter.SearchScope;
035 import org.apache.directory.shared.ldap.message.AliasDerefMode;
036 import org.apache.directory.shared.ldap.name.LdapDN;
037
038
039 /**
040 * A Session operation for building a catalog.
041 *
042 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
043 * @version $Rev: 682235 $, $Date: 2008-08-04 03:43:52 +0300 (Mon, 04 Aug 2008) $
044 */
045 public class GetCatalog implements DirectoryServiceOperation
046 {
047 private static final long serialVersionUID = -6657995003127926278L;
048
049
050 /**
051 * Note that the base is relative to the existing context.
052 */
053 public Object execute( CoreSession session, LdapDN base ) throws Exception
054 {
055 String filter = "(objectClass=" + ApacheSchemaConstants.APACHE_CATALOG_ENTRY_OC + ")";
056
057 EntryFilteringCursor list = session.search(
058 LdapDN.EMPTY_LDAPDN,
059 SearchScope.SUBTREE,
060 FilterParser.parse( filter ),
061 AliasDerefMode.DEREF_ALWAYS,
062 null );
063
064 Map<String, String> catalog = new HashMap<String, String>();
065
066 list.beforeFirst();
067
068 while ( list.next() )
069 {
070 ServerEntry result = list.get();
071
072 String name = null;
073 EntryAttribute attribute = result.get( ApacheSchemaConstants.APACHE_CATALOGUE_ENTRY_NAME_AT );
074
075 if ( attribute != null )
076 {
077 name = attribute.getString();
078 }
079
080 String basedn = null;
081 attribute = result.get( ApacheSchemaConstants.APACHE_CATALOGUE_ENTRY_BASE_DN_AT );
082
083 if ( attribute != null )
084 {
085 basedn = attribute.getString();
086 }
087
088
089 catalog.put( name, basedn );
090 }
091
092 return catalog;
093 }
094 }