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;
17  
18  
19  /** Abstract parent class for custom {@link AludraService} implementations. It provides the features which are usually implemented
20   * equally among different services: Handling of context, test case and system connector.
21   * 
22   * @author Volker Bergmann */
23  public abstract class AbstractAludraService implements AludraService {
24  
25      /** The context of the service. */
26      protected AludraServiceContext aludraServiceContext;
27  
28      /** Implements the init() method. Stores the context parameter in the {@link #aludraServiceContext} field which can be accessed
29       * by subclasses. Extracts the test case log object from the context object and stores it in the {@link #testCaseLog} field
30       * which also can be accessed by subclasses. Afterwards, {@link #initService()} is called. */
31      @Override
32      public final void init(AludraServiceContext context) {
33          this.aludraServiceContext = context;
34          initService();
35      }
36  
37      @Override
38      public String getInstanceName() {
39          return aludraServiceContext.getInstanceName();
40      }
41  
42      /**
43       * Abstract initialization method to be implemented by child classes for individual initialization operations. Implementors
44       * can access the protected <code>aludraServiceContext</code> field to retrieve instances of other services, if required.
45       */
46      public abstract void initService();
47  
48      /** Implementation left empty since this is handled by a dynamic proxy. */
49      @Override
50      public void setSystemConnector(SystemConnector connector) {
51          // This does not need an implementation since it is handled by the wrapper
52      }
53  
54      @Override
55      public String toString() {
56          if (aludraServiceContext != null && aludraServiceContext.getInstanceName() != null) {
57              return getClass().getSimpleName() + "(" + aludraServiceContext.getInstanceName() + ")";
58          }
59          else {
60              return getClass().getSimpleName();
61          }
62      }
63  
64  }