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.separatedfile.impl;
17  
18  import org.aludratest.content.separated.SeparatedContent;
19  import org.aludratest.exception.TechnicalException;
20  import org.aludratest.service.AbstractAludraService;
21  import org.aludratest.service.Implementation;
22  import org.aludratest.service.file.FileService;
23  import org.aludratest.service.separatedfile.SeparatedFileCondition;
24  import org.aludratest.service.separatedfile.SeparatedFileInteraction;
25  import org.aludratest.service.separatedfile.SeparatedFileService;
26  import org.aludratest.service.separatedfile.SeparatedFileVerification;
27  
28  /**
29   * Default implementation of the {@link SeparatedFileService}.
30   * @author Volker Bergmann
31   */
32  @Implementation({ SeparatedFileService.class })
33  public class DefaultSeparatedFileService extends AbstractAludraService implements SeparatedFileService {
34  
35      /** Implementor of all action interfaces of the WebdecsSeparatedFileService. */
36      private DefaultSeparatedFileAction action;
37  
38      private FileService fileService;
39  
40      /** Public default constructor. */
41      public DefaultSeparatedFileService() {
42      }
43  
44      @Override
45      public FileService getFileService() {
46          return fileService;
47      }
48  
49      /** Provides an object that implements the {@link SeparatedFileInteraction} interface. */
50      @Override
51      public SeparatedFileInteraction perform() {
52          return action;
53      }
54  
55      /** Provides an object that implements the {@link SeparatedFileVerification} interface. */
56      @Override
57      public SeparatedFileVerification verify() {
58          return action;
59      }
60  
61      /** Provides an object that implements the {@link SeparatedFileCondition} interface. */
62      @Override
63      public SeparatedFileCondition check() {
64          return action;
65      }
66  
67      /** Callback method that is called by the AludraTest framework
68       * and initializes the service. */
69      @Override
70      public void initService() {
71          try {
72              fileService = aludraServiceContext.getNonLoggingService(FileService.class);
73              SeparatedContent contentHandler = aludraServiceContext.newComponentInstance(SeparatedContent.class);
74              this.action = new DefaultSeparatedFileAction(contentHandler, fileService);
75          } catch (Exception e) {
76              throw new TechnicalException("Error initializing " + this, e);
77          }
78      }
79  
80      /** Closes the service. */
81      @Override
82      public void close() {
83          // nothing to do
84      }
85  
86      /** Provides a description of the service instance. */
87      @Override
88      public String getDescription() {
89          return toString();
90      }
91  }