1 /* *************************************************************************** 2 * Copyright (c) 2008 Brabenetz Harald, Austria. 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 *****************************************************************************/ 17 package org.settings4j; 18 19 20 /** 21 * <p>The ObjectResolver is a Helper to resolve byte[] Content to a Java Object. 22 * 23 * <pre> 24 * Example Configuration in settings4j.xml: 25 * <div style="border-width:1px;border-style:solid;"> 26 * <connector name="<span style="color:green;">ClasspathConnector</span>" 27 * class="org.settings4j.connector.ClasspathConnector"> 28 * <objectResolver-ref ref="<span style="color:red;">JavaXMLBeansObjectResolver</span>" /> 29 * </connector> 30 * <objectResolver name="<span style="color:red;">JavaXMLBeansObjectResolver</span>" 31 * class="org.settings4j.objectresolver.JavaXMLBeansObjectResolver" /> 32 * </div></pre> 33 * 34 * 35 * <p>You can now store a XMLEncoded (Serialized) Java-Objects into your Classpath.<br /> 36 * see {@link org.settings4j.objectresolver.JavaXMLBeansObjectResolver} for more details.<br /> 37 * Or see {@link org.settings4j.objectresolver.SpringConfigObjectResolver} for more details on a Spring Configuration 38 * File to generate an Object. Requires Springframework (tested with 2.5.6)<br /> 39 * 40 * @author Harald.Brabenetz 41 * 42 */ 43 public interface ObjectResolver { 44 45 /** 46 * Reads the byte[] content from the ContentResolver and creates an Object. 47 * 48 * The normal usecase of an implementation of this ObjectResolver Interface:<br /> 49 * 50 * <ol> 51 * <li>Read the Propertyfile from {@link ContentResolver}.getContent(key + ".properties")</li> 52 * <li>Read the Value of "objectResolverKey" from propertyfile</li> 53 * <li>The "objectResolverKey" defines which ObjectResolver-Implementation should 54 * solve the byte[] content to a Java-Object</li> 55 * <li>Convert the byte[] from {@link ContentResolver#getContent(String key)} to an Object.</li> 56 * <li>Maybe additional values are consumed from the propertyfile</li> 57 * </ol> 58 * 59 * 60 * @param key The Key of the byte[] who should be converted to an Object. 61 * @param contentResolver The contentResolver, from where the content could be read. 62 * @return the Object, or null if this Object-Resolver can not convert the byte[] Content to an Object. 63 */ 64 Object getObject(String key, ContentResolver contentResolver); 65 66 /** 67 * Some Implementations of a {@link ObjectResolver} are delegating the functionality 68 * to other ObjectResolvers.<br /> 69 * Examples are: {@link org.settings4j.objectresolver.UnionObjectResolver} 70 * 71 * <pre> 72 * -------------------------------------- 73 * <objectResolver name="DefaultObjectResolver" class="org.settings4j.objectresolver.UnionObjectResolver"> 74 * <objectResolver-ref ref="JavaXMLBeansObjectResolver" /> 75 * <objectResolver-ref ref="SpringConfigObjectResolver" /> 76 * </objectResolver> 77 * -------------------------------------- 78 * </pre> 79 * 80 * @param objectResolver the original objectResolver to delegate. 81 */ 82 void addObjectResolver(ObjectResolver objectResolver); 83 }