1 /* 2 * Copyright 2007 Joachim Grueneis 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package org.exolab.castor.xml.util; 15 16 import java.util.Map; 17 18 import org.castor.xml.AbstractInternalContext; 19 import org.exolab.castor.mapping.ClassDescriptor; 20 import org.exolab.castor.xml.ResolverException; 21 import org.exolab.castor.xml.XMLClassDescriptor; 22 23 /** 24 * A resolver strategy implements how ClassDescriptor's are found for a given class. It uses 25 * multiple ResolveCommand's for first time resolution, but also some caching of already evaluated 26 * classes. 27 * 28 * @author <a href="mailto:jgrueneis AT gmail DOT com">Joachim Grueneis</a> 29 * @version $Revision$ $Date$ 30 * @since 1.2 31 */ 32 public interface ResolverStrategy { 33 /** To set the class loader property for resolving. */ 34 String PROPERTY_CLASS_LOADER = "org.exolab.castor.xml.util.ResolverStrategy.ClassLoader"; 35 36 /** To set the use introspection property for resolving. */ 37 String PROPERTY_USE_INTROSPECTION = 38 "org.exolab.castor.xml.util.ResolverStrategy.useIntrospection"; 39 40 /** To set the introspector property for resolving. */ 41 String PROPERTY_INTROSPECTOR = "org.exolab.castor.xml.util.ResolverStrategy.Introspector"; 42 43 /** To set the LoadPackageMappings property for resolving. */ 44 String PROPERTY_LOAD_PACKAGE_MAPPINGS = 45 "org.exolab.castor.xml.util.ResolverStrategy.LoadPackageMappings"; 46 47 /** To set the mapping loader property for resolving. */ 48 String PROPERTY_MAPPING_LOADER = "org.exolab.castor.xml.util.ResolverStrategy.MappingLoader"; 49 50 /** 51 * To set properties for strategy and/or commands. 52 * 53 * @param key name of the property 54 * @param value value the property is set to 55 */ 56 void setProperty(final String key, final Object value); 57 58 /** 59 * Implementes a strategy how a class is resolved into a list of class descriptors. 60 * 61 * @param resolverResults to put the resolver reszlts into 62 * @param className the class to resolve 63 * @return the ClassDescriptor for the class or null if the class couldn't be resolved 64 * @throws ResolverException in case that resolving fails fatally 65 */ 66 ClassDescriptor resolveClass(final ResolverResults resolverResults, final String className) 67 throws ResolverException; 68 69 /** 70 * Implementes a strategy how a package is resolved into a list of class descriptors. 71 * 72 * @param resolverResults to put the resolver reszlts into 73 * @param packageName the package to resolve 74 * @throws ResolverException in case that resolving fails fatally 75 */ 76 void resolvePackage(ResolverResults resolverResults, String packageName) throws ResolverException; 77 78 /** 79 * As a strategy generate one or more class descriptors it needs a place to put the results to. 80 * This is a minimal interface to give the strategy a place where to put generated class 81 * descriptors to. 82 * 83 * @author <a href="mailto:jgrueneis AT gmail DOT com">Joachim Grueneis</a> 84 * @version $Revision$ 85 */ 86 public interface ResolverResults { 87 /** 88 * Adds a descriptor to this caches maps.<br> 89 * The descriptor is mapped both with the class name and its XML name. 90 * 91 * The descriptor will not be mapped with its XML name is <code>null</code>, the empty string 92 * (""), or has the value of the constant INTERNAL_CONTAINER_NAME. 93 * 94 * If there already is a descriptor for the given <code>className</code> and/or the descriptor's 95 * XML name the previously cached descriptor is replaced. 96 * 97 * @param className The class name to be used for mapping the given descriptor. 98 * @param descriptor The descriptor to be mapped. 99 * 100 * @see #INTERNAL_CONTAINER_NAME 101 */ 102 void addDescriptor(String className, XMLClassDescriptor descriptor); 103 104 /** 105 * To add not only a single descriptor but a map of descriptors at once. 106 * 107 * @param descriptors a Map of className (String) and XMLClassDescriptor pairs 108 */ 109 void addAllDescriptors(Map descriptors); 110 111 /** 112 * Gets the descriptor that is mapped to the given class name. 113 * 114 * @param className The class name to get a descriptor for. 115 * @return The descriptor mapped to the given name or <code>null</code> if no descriptor is 116 * stored in this cache. 117 */ 118 XMLClassDescriptor getDescriptor(String className); 119 } 120 }