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  package org.apache.directory.server.tools;
21  
22  
23  import java.io.File;
24  
25  import org.apache.commons.cli.CommandLine;
26  import org.apache.commons.cli.Options;
27  import org.apache.directory.daemon.InstallationLayout;
28  import org.apache.directory.server.configuration.ApacheDS;
29  
30  
31  /**
32   * Simple base class for tool commands.
33   * 
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   * @version $Rev: 648932 $
36   */
37  public abstract class ToolCommand
38  {
39      private final String name;
40      private boolean debugEnabled = false;
41      private boolean verboseEnabled = false;
42      private boolean quietEnabled = false;
43      private String version;
44      private InstallationLayout layout;
45      private ApacheDS apacheDS;
46  
47  
48      protected ToolCommand( String name )
49      {
50          this.name = name;
51      }
52  
53  
54      public abstract void execute( CommandLine cmd ) throws Exception;
55  
56  
57      public abstract Options getOptions();
58  
59  
60      public String getName()
61      {
62          return this.name;
63      }
64  
65  
66      public void setLayout( File installationDirectory )
67      {
68          this.layout = new InstallationLayout( installationDirectory );
69      }
70  
71  
72      public void setLayout( String installationPath )
73      {
74          this.layout = new InstallationLayout( installationPath );
75      }
76  
77  
78      public void setLayout( InstallationLayout layout )
79      {
80          this.layout = layout;
81      }
82  
83  
84      public InstallationLayout getLayout()
85      {
86          return layout;
87      }
88  
89  
90      public void setApacheDS( ApacheDS apacheDS )
91      {
92          this.apacheDS = apacheDS;
93      }
94  
95  
96      public ApacheDS getApacheDS()
97      {
98          return apacheDS;
99      }
100 
101 
102     public void setVersion( String version )
103     {
104         this.version = version;
105     }
106 
107 
108     public String getVersion()
109     {
110         return version;
111     }
112 
113 
114     public String toString()
115     {
116         return getName();
117     }
118 
119 
120     public void setDebugEnabled( boolean debugEnabled )
121     {
122         this.debugEnabled = debugEnabled;
123     }
124 
125 
126     public boolean isDebugEnabled()
127     {
128         return debugEnabled;
129     }
130 
131 
132     public void setVerboseEnabled( boolean verboseEnabled )
133     {
134         this.verboseEnabled = verboseEnabled;
135     }
136 
137 
138     public boolean isVerboseEnabled()
139     {
140         return verboseEnabled;
141     }
142 
143 
144     public void setQuietEnabled( boolean quietEnabled )
145     {
146         this.quietEnabled = quietEnabled;
147     }
148 
149 
150     public boolean isQuietEnabled()
151     {
152         return quietEnabled;
153     }
154 }