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 package org.apache.directory.server.tools; 021 022 023 import java.io.File; 024 025 import org.apache.commons.cli.CommandLine; 026 import org.apache.commons.cli.Options; 027 import org.apache.directory.daemon.InstallationLayout; 028 import org.apache.directory.server.configuration.ApacheDS; 029 030 031 /** 032 * Simple base class for tool commands. 033 * 034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 035 * @version $Rev: 921363 $ 036 */ 037 public abstract class ToolCommand 038 { 039 private final String name; 040 private boolean debugEnabled = false; 041 private boolean verboseEnabled = false; 042 private boolean quietEnabled = false; 043 private String version; 044 private InstallationLayout layout; 045 private ApacheDS apacheDS; 046 047 private InstanceLayout instanceLayout; 048 049 protected ToolCommand( String name ) 050 { 051 this.name = name; 052 } 053 054 055 public abstract void execute( CommandLine cmd ) throws Exception; 056 057 058 public abstract Options getOptions(); 059 060 061 public String getName() 062 { 063 return this.name; 064 } 065 066 067 public void setLayout( File installationDirectory ) 068 { 069 this.layout = new InstallationLayout( installationDirectory ); 070 } 071 072 073 public void setLayout( String installationPath ) 074 { 075 this.layout = new InstallationLayout( new File( installationPath ) ); 076 } 077 078 079 public void setLayout( InstallationLayout layout ) 080 { 081 this.layout = layout; 082 } 083 084 085 public void setInstanceLayout( InstanceLayout instanceLayout ) 086 { 087 this.instanceLayout = instanceLayout; 088 } 089 090 091 public InstanceLayout getInstanceLayout() 092 { 093 return instanceLayout; 094 } 095 096 097 public InstallationLayout getLayout() 098 { 099 return layout; 100 } 101 102 103 public void setApacheDS( ApacheDS apacheDS ) 104 { 105 this.apacheDS = apacheDS; 106 } 107 108 109 public ApacheDS getApacheDS() 110 { 111 return apacheDS; 112 } 113 114 115 public void setVersion( String version ) 116 { 117 this.version = version; 118 } 119 120 121 public String getVersion() 122 { 123 return version; 124 } 125 126 127 public String toString() 128 { 129 return getName(); 130 } 131 132 133 public void setDebugEnabled( boolean debugEnabled ) 134 { 135 this.debugEnabled = debugEnabled; 136 } 137 138 139 public boolean isDebugEnabled() 140 { 141 return debugEnabled; 142 } 143 144 145 public void setVerboseEnabled( boolean verboseEnabled ) 146 { 147 this.verboseEnabled = verboseEnabled; 148 } 149 150 151 public boolean isVerboseEnabled() 152 { 153 return verboseEnabled; 154 } 155 156 157 public void setQuietEnabled( boolean quietEnabled ) 158 { 159 this.quietEnabled = quietEnabled; 160 } 161 162 163 public boolean isQuietEnabled() 164 { 165 return quietEnabled; 166 } 167 }