View Javadoc
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.castor.xml;
15  
16  import org.castor.mapping.BindingType;
17  import org.exolab.castor.xml.ClassDescriptorResolverFactory;
18  import org.exolab.castor.xml.Introspector;
19  import org.exolab.castor.xml.XMLClassDescriptorResolver;
20  import org.exolab.castor.xml.XMLContext;
21  import org.exolab.castor.xml.util.ResolverStrategy;
22  import org.exolab.castor.xml.util.resolvers.CastorXMLStrategy;
23  
24  /**
25   * As the name already expresses: this class is there for backward compatibility and should be
26   * removed from Castor with a future release.
27   * 
28   * Normally the internal context is created by XMLContext exclusivly and then handed down the call
29   * chain. This very class is used in all cases, which fail to be on a call chain started with
30   * {@link XMLContext}.
31   * 
32   * Ideally, all usage of this class should disappear and be replaced with proper usage of
33   * {@link XMLContext}.
34   * 
35   * @see XMLContext
36   * @author Joachim Grueneis, jgrueneis_at_gmail_dot_com
37   * @version $Id$
38   */
39  public class BackwardCompatibilityContext extends AbstractInternalContext
40      implements InternalContext {
41  
42    public BackwardCompatibilityContext() {
43      super();
44      setClassLoader(getClass().getClassLoader());
45  
46      XMLClassDescriptorResolver cdr = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory
47          .createClassDescriptorResolver(BindingType.XML);
48      cdr.setInternalContext(this);
49      setXMLClassDescriptorResolver(cdr);
50  
51      Introspector introspector = new Introspector();
52      introspector.setInternalContext(this);
53      setIntrospector(introspector);
54      cdr.setIntrospector(introspector);
55  
56      ResolverStrategy resolverStrategy = new CastorXMLStrategy();
57      setResolverStrategy(resolverStrategy);
58      cdr.setResolverStrategy(resolverStrategy);
59    }
60  }