View Javadoc

1   /**
2    * Copyright (c) 2011, University of Konstanz, Distributed Systems Group
3    * All rights reserved.
4    * 
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    * * Redistributions of source code must retain the above copyright
8    * notice, this list of conditions and the following disclaimer.
9    * * Redistributions in binary form must reproduce the above copyright
10   * notice, this list of conditions and the following disclaimer in the
11   * documentation and/or other materials provided with the distribution.
12   * * Neither the name of the University of Konstanz nor the
13   * names of its contributors may be used to endorse or promote products
14   * derived from this software without specific prior written permission.
15   * 
16   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19   * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   */
27  
28  package org.treetank.access.conf;
29  
30  import static com.google.common.base.Objects.toStringHelper;
31  
32  import java.security.Key;
33  
34  import org.treetank.access.Session;
35  import org.treetank.access.Storage;
36  
37  import com.google.inject.Inject;
38  import com.google.inject.assistedinject.Assisted;
39  
40  /**
41   * <h1>SessionConfiguration</h1>
42   * 
43   * <p>
44   * Holds the {@link Session}-wide settings that can not change within the runtime of a {@link Session}. This
45   * included stuff like commit-threshold and number of usable write/read transactions. Each
46   * {@link SessionConfiguration} is only bound through the location to a {@link Storage} and related resources.
47   * </p>
48   */
49  public final class SessionConfiguration {
50  
51      /** ResourceConfiguration for this ResourceConfig. */
52      private final String mResource;
53  
54      /** Key for accessing any encrypted data. */
55      private final Key mKey;
56  
57      /**
58       * Convenience constructor using the standard settings.
59       * 
60       * @param pResource
61       *            resource to be accessed
62       * @param pKey
63       *            key for accessing encrypted data
64       */
65      @Inject
66      public SessionConfiguration(@Assisted String pResource, Key pKey) {
67          mResource = pResource;
68          mKey = pKey;
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      @Override
75      public String toString() {
76          return toStringHelper(this).add("mResource", mResource).add("mKey", mKey).toString();
77      }
78  
79      /**
80       * Getter for the file.
81       * 
82       * @return the file for the configuration.
83       */
84      public String getResource() {
85          return mResource;
86      }
87  
88      /**
89       * Getter for the key material
90       * 
91       * @return the key within this session
92       */
93      public Key getKey() {
94          return mKey;
95      }
96  
97      /**
98       * 
99       * Factory for generating an {@link SessionConfiguration}-instance. Needed mainly
100      * because of Guice-Assisted utilization.
101      * 
102      * @author Sebastian Graf, University of Konstanz
103      * 
104      */
105     public static interface ISessionConfigurationFactory {
106 
107         /**
108          * Generating a storage for a fixed file.
109          * 
110          * @param pResourceName
111          *            Name of resource to be set.
112          * @return an {@link SessionConfiguration}-instance
113          */
114         SessionConfiguration create(String pResourceName);
115     }
116 }