View Javadoc
1   /*
2    * Copyright (C) 2010-2014 Hamburg Sud and the contributors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.aludratest.service.cmdline.impl;
17  
18  import org.aludratest.config.ConfigProperties;
19  import org.aludratest.config.Preferences;
20  import org.aludratest.exception.AutomationException;
21  import org.aludratest.service.AbstractConfigurableAludraService;
22  import org.aludratest.service.Implementation;
23  import org.aludratest.service.cmdline.CommandLineCondition;
24  import org.aludratest.service.cmdline.CommandLineInteraction;
25  import org.aludratest.service.cmdline.CommandLineService;
26  import org.aludratest.service.cmdline.CommandLineVerification;
27  import org.apache.commons.vfs2.FileSystemException;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  /** Default implementation of the {@link CommandLineService}. It uses a single {@link CommandLineActionImpl} instance.
32   * @author Volker Bergmann */
33  @Implementation({ CommandLineService.class })
34  @ConfigProperties({})
35  public class CommandLineServiceImpl extends AbstractConfigurableAludraService implements CommandLineService {
36  
37      /** The logger of the class. */
38      private static final Logger LOGGER = LoggerFactory.getLogger(CommandLineServiceImpl.class);
39  
40      private CommandLineActionImpl action;
41  
42      private CommandLineServiceConfiguration configuration;
43  
44      // properties --------------------------------------------------------------
45  
46      @Override
47      public String getDescription() {
48          return getClass().getSimpleName();
49      }
50  
51      // Configurable interface implementation ----------------------------------
52  
53      @Override
54      public String getPropertiesBaseName() {
55          return "commandLineService";
56      }
57  
58      @Override
59      public void configure(Preferences preferences) throws AutomationException {
60          try {
61              configuration = new CommandLineServiceConfiguration(preferences);
62          }
63          catch (FileSystemException e) {
64              LOGGER.error("Error configuring FileService", e);
65              throw new AutomationException("Error initializing " + this, e);
66          }
67      }
68  
69      // AludraService interface implementation ----------------------------------
70  
71      @Override
72      public void initService() {
73          this.action = new CommandLineActionImpl(configuration);
74      }
75  
76      /** Closes the service */
77      @Override
78      public void close() {
79          this.configuration.close();
80      }
81  
82      // functional interface ----------------------------------------------------
83  
84      @Override
85      public CommandLineInteraction perform() {
86          return action;
87      }
88  
89      @Override
90      public CommandLineVerification verify() {
91          return action;
92      }
93  
94      @Override
95      public CommandLineCondition check() {
96          return action;
97      }
98  
99      @Override
100     public String getBaseDirectory() {
101         return configuration.getBaseDirectory();
102     }
103 
104 }