View Javadoc

1   /**
2    *
3    * Copyright 2005 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.geronimo.kernel.config.xstream;
18  
19  import java.net.URI;
20  
21  import com.thoughtworks.xstream.XStream;
22  import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
23  import com.thoughtworks.xstream.core.JVM;
24  import org.apache.geronimo.gbean.AbstractName;
25  import org.apache.geronimo.gbean.AbstractNameQuery;
26  import org.apache.geronimo.gbean.GBeanData;
27  import org.apache.geronimo.gbean.GBeanInfo;
28  import org.apache.geronimo.kernel.config.ConfigurationData;
29  import org.apache.geronimo.kernel.config.ConfigurationModuleType;
30  import org.apache.geronimo.kernel.repository.Artifact;
31  import org.apache.geronimo.kernel.repository.Dependency;
32  import org.apache.geronimo.kernel.repository.ImportType;
33  import org.apache.geronimo.kernel.repository.Version;
34  
35  /**
36   * @version $Rev: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $
37   */
38  public final class XStreamUtil {
39      private XStreamUtil() {
40      }
41  
42      public static XStream createXStream() {
43          JVM jvm = new JVM();
44          ReflectionProvider reflectionProvider = jvm.bestReflectionProvider();
45          XStream xstream = new XStream(reflectionProvider);
46  
47          // AbstractName
48          xstream.alias("abstractName", AbstractName.class);
49          xstream.addImmutableType(AbstractName.class);
50          xstream.registerConverter(new AbstractNameConverter());
51  
52          // AbstractNameQuery
53          xstream.alias("abstractNameQuery", AbstractNameQuery.class);
54          xstream.addImmutableType(AbstractNameQuery.class);
55          xstream.registerConverter(new AbstractNameQueryConverter());
56  
57          // Artifact
58          xstream.alias("artifact", Artifact.class);
59          xstream.addImmutableType(Artifact.class);
60  
61          // ConfigurationData
62          xstream.alias("configurationData", ConfigurationData.class);
63          xstream.registerConverter(new ConfigurationDataConverter(reflectionProvider, xstream.getClassMapper()));
64  
65          // ConfigurationModuleTypeConverter
66          xstream.alias("moduleType", ConfigurationModuleType.class);
67          xstream.addImmutableType(ConfigurationModuleType.class);
68          xstream.registerConverter(new ConfigurationModuleTypeConverter());
69  
70          // Dependency
71          xstream.alias("dependency", Dependency.class);
72          xstream.addImmutableType(Dependency.class);
73  
74          // GBeanData
75          xstream.alias("gbean", GBeanData.class);
76          xstream.registerConverter(new GBeanDataConverter(xstream.getClassMapper()));
77  
78          // GBeanInfo
79          xstream.alias("gbean-info", GBeanInfo.class);
80  
81          // w3c Dom
82          xstream.registerConverter(new DomConverter());
83  
84          // ImportType
85          xstream.addImmutableType(ImportType.class);
86          xstream.registerConverter(new ImportTypeConverter());
87  
88          // QName
89          try {
90              xstream.registerConverter(new QNameConverter());
91          } catch (Exception e) {
92              // cl can't see QName class so we don't need to register a converter for it
93          }
94  
95          // Version
96          xstream.alias("version", Version.class);
97          xstream.addImmutableType(Version.class);
98          xstream.registerConverter(new VersionConverter());
99  
100         // URI
101         xstream.alias("uri", URI.class);
102         xstream.addImmutableType(URI.class);
103         xstream.registerConverter(new URIConverter());
104 
105         // XStreamGBeanState
106         xstream.registerConverter(new XStreamGBeanStateConverter());
107 
108         return xstream;
109     }
110 }