View Javadoc
1   /*
2    * #%L
3    * settings4j
4    * ===============================================================
5    * Copyright (C) 2008 - 2015 Brabenetz Harald, Austria
6    * ===============================================================
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package org.settings4j;
21  
22  
23  /**
24   * The ObjectResolver is a Helper to resolve byte[] Content to a Java Object.
25   * <p>
26   * Example Configuration in settings4j.xml:
27   * </p>
28   *
29   * <pre style="border-width:1px;border-style:solid;">
30   * &lt;connector name="<span style="color:green;">ClasspathConnector</span>"
31   *          class="org.settings4j.connector.ClasspathConnector"&gt;
32   *     &lt;objectResolver-ref ref="<span style="color:red;">JavaXMLBeansObjectResolver</span>" /&gt;
33   * &lt;/connector&gt;
34   * &lt;objectResolver name="<span style="color:red;">JavaXMLBeansObjectResolver</span>"
35   *          class="org.settings4j.objectresolver.JavaXMLBeansObjectResolver" /&gt;
36   * </pre>
37   * <p>
38   * You can now store a XMLEncoded (Serialized) Java-Objects into your Classpath.<br>
39   * see {@link org.settings4j.objectresolver.JavaXMLBeansObjectResolver} for more details.<br>
40   * Or see {@link org.settings4j.objectresolver.SpringConfigObjectResolver} for more details on a Spring Configuration File to generate an Object. Requires
41   * Springframework (tested with 2.5.6)
42   * </p>
43   *
44   * @author Harald.Brabenetz
45   */
46  public interface ObjectResolver {
47  
48      /**
49       * Reads the byte[] content from the ContentResolver and creates an Object.
50       *
51       * The normal usecase of an implementation of this ObjectResolver Interface:<br>
52       *
53       * <ol>
54       * <li>Read the Propertyfile from {@link ContentResolver}.getContent(key + ".properties")</li>
55       * <li>Read the Value of "objectResolverKey" from propertyfile</li>
56       * <li>The "objectResolverKey" defines which ObjectResolver-Implementation should
57       *      solve the byte[] content to a Java-Object</li>
58       * <li>Convert the byte[] from {@link ContentResolver#getContent(String key)} to an Object.</li>
59       * <li>Maybe additional values are consumed from the propertyfile</li>
60       * </ol>
61       *
62       *
63       * @param key The Key of the byte[] who should be converted to an Object.
64       * @param contentResolver The contentResolver, from where the content could be read.
65       * @return the Object, or null if this Object-Resolver can not convert the byte[] Content to an Object.
66       */
67      Object getObject(String key, ContentResolver contentResolver);
68  
69      /**
70       * Some Implementations of a {@link ObjectResolver} are delegating the functionality to other ObjectResolvers.
71       * <p>
72       * Examples are: {@link org.settings4j.objectresolver.UnionObjectResolver}
73       * </p>
74       *
75       * <pre>
76       * --------------------------------------
77       * &lt;objectResolver name="DefaultObjectResolver" class="org.settings4j.objectresolver.UnionObjectResolver"&gt;
78       *     &lt;objectResolver-ref ref="JavaXMLBeansObjectResolver" /&gt;
79       *     &lt;objectResolver-ref ref="SpringConfigObjectResolver" /&gt;
80       * &lt;/objectResolver&gt;
81       * --------------------------------------
82       * </pre>
83       *
84       * @param objectResolver
85       *        the original objectResolver to delegate.
86       */
87      void addObjectResolver(ObjectResolver objectResolver);
88  }