View Javadoc
1   /*
2    * Copyright 2007 Joachim Grueneis
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.exolab.castor.xml.util;
17  
18  import java.util.Map;
19  
20  import org.castor.xml.AbstractInternalContext;
21  import org.exolab.castor.mapping.ClassDescriptor;
22  import org.exolab.castor.xml.ResolverException;
23  import org.exolab.castor.xml.XMLClassDescriptor;
24  
25  /**
26   * A resolver strategy implements how ClassDescriptor's are found for a
27   * given class. It uses multiple ResolveCommand's for first time resolution,
28   * but also some caching of already evaluated classes.
29   * 
30   * @author <a href="mailto:jgrueneis AT gmail DOT com">Joachim Grueneis</a>
31   * @version $Revision$ $Date$
32   * @since 1.2
33   */
34  public interface ResolverStrategy {
35      /** To set the class loader property for resolving. */
36      String PROPERTY_CLASS_LOADER =
37          "org.exolab.castor.xml.util.ResolverStrategy.ClassLoader";
38      
39      /** To set the use introspection property for resolving. */
40      String PROPERTY_USE_INTROSPECTION =
41          "org.exolab.castor.xml.util.ResolverStrategy.useIntrospection";
42      
43      /** To set the introspector property for resolving. */
44      String PROPERTY_INTROSPECTOR =
45          "org.exolab.castor.xml.util.ResolverStrategy.Introspector";
46      
47      /** To set the LoadPackageMappings property for resolving. */
48      String PROPERTY_LOAD_PACKAGE_MAPPINGS =
49          "org.exolab.castor.xml.util.ResolverStrategy.LoadPackageMappings";
50      
51      /** To set the mapping loader property for resolving. */
52      String PROPERTY_MAPPING_LOADER =
53          "org.exolab.castor.xml.util.ResolverStrategy.MappingLoader";
54          
55      /**
56       * To set properties for strategy and/or commands.
57       * 
58       * @param key name of the property
59       * @param value value the property is set to
60       */
61      void setProperty(final String key, final Object value);
62  
63      /**
64       * Implementes a strategy how a class is resolved into a list of class descriptors.
65       * 
66       * @param resolverResults to put the resolver reszlts into
67       * @param className the class to resolve
68       * @return the ClassDescriptor for the class or null if the class couldn't be resolved
69       * @throws ResolverException in case that resolving fails fatally
70       */
71      ClassDescriptor resolveClass(final ResolverResults resolverResults, final String className)
72      throws ResolverException;
73      
74      /**
75       * Implementes a strategy how a package is resolved into a list of class descriptors.
76       * 
77       * @param resolverResults to put the resolver reszlts into
78       * @param packageName the package to resolve
79       * @throws ResolverException in case that resolving fails fatally
80       */
81      void resolvePackage(ResolverResults resolverResults, String packageName)
82      throws ResolverException;
83  
84      /**
85       * As a strategy generate one or more class descriptors it needs a place
86       * to put the results to. This is a minimal interface to give the strategy a
87       * place where to put generated class descriptors to.
88       * 
89       * @author <a href="mailto:jgrueneis AT gmail DOT com">Joachim Grueneis</a>
90       * @version $Revision$
91       */
92      public interface ResolverResults {
93          /**
94           * Adds a descriptor to this caches maps.<br>
95           * The descriptor is mapped both with the class name and its XML name.
96           * 
97           * The descriptor will not be mapped with its XML name is
98           * <code>null</code>, the empty string (""), or has the value of the
99           * constant INTERNAL_CONTAINER_NAME.
100          * 
101          * If there already is a descriptor for the given <code>className</code>
102          * and/or the descriptor's XML name the previously cached descriptor is
103          * replaced.
104          * 
105          * @param className The class name to be used for mapping the given descriptor.
106          * @param descriptor The descriptor to be mapped.
107          * 
108          * @see #INTERNAL_CONTAINER_NAME
109          */
110         void addDescriptor(String className, XMLClassDescriptor descriptor);
111 
112         /**
113          * To add not only a single descriptor but a map of descriptors at once.
114          * 
115          * @param descriptors a Map of className (String) and XMLClassDescriptor pairs
116          */
117         void addAllDescriptors(Map descriptors);
118 
119         /**
120          * Gets the descriptor that is mapped to the given class name.
121          * 
122          * @param className The class name to get a descriptor for.
123          * @return The descriptor mapped to the given name or <code>null</code>
124          *         if no descriptor is stored in this cache.
125          */
126         XMLClassDescriptor getDescriptor(String className);
127     }
128 }