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.tools; 022 023 024 import java.io.File; 025 import java.io.FileFilter; 026 import java.util.ArrayList; 027 import java.util.List; 028 029 030 /** 031 * TODO InstanceLayout. 032 * 033 * ${ads-instance-name} 034 * |-- conf 035 * |-- ldif 036 * |-- log 037 * |-- partitions 038 * | |-- example 039 * | |-- schema 040 * | `-- system 041 * `-- run 042 * 043 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 044 * @version $Rev$, $Date$ 045 */ 046 public class InstanceLayout 047 { 048 /** the installation instance's base directory */ 049 private final File instanceRoot; 050 051 /** a file system directory filter */ 052 private FileFilter dirFilter = new FileFilter() 053 { 054 public boolean accept( File pathname ) 055 { 056 return pathname.isDirectory(); 057 } 058 059 }; 060 061 062 public InstanceLayout( File location ) 063 { 064 this.instanceRoot = location; 065 } 066 067 068 public InstanceLayout( String location ) 069 { 070 this.instanceRoot = new File( location ); 071 } 072 073 074 public File getPartitionsDir() 075 { 076 return new File( instanceRoot, "partitions" ); 077 } 078 079 080 public File getLogDir() 081 { 082 return new File( instanceRoot, "log" ); 083 } 084 085 086 public File getConfDir() 087 { 088 return new File( instanceRoot, "conf" ); 089 } 090 091 092 /** 093 * returns a list of partition directories 094 * @return list of partition directories 095 */ 096 public List<File> getPartitions() 097 { 098 List<File> partitions = new ArrayList<File>(); 099 100 File[] dirs = getPartitionsDir().listFiles( dirFilter ); 101 102 for ( File f : dirs ) 103 { 104 File masterFile = new File( f, "master.db" ); 105 if ( masterFile.isFile() && masterFile.exists() ) 106 { 107 partitions.add( f ); 108 } 109 } 110 111 return partitions; 112 } 113 }