001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.kernel.config.xstream;
017:
018: import java.net.URI;
019:
020: import com.thoughtworks.xstream.XStream;
021: import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
022: import com.thoughtworks.xstream.core.JVM;
023: import org.apache.geronimo.gbean.AbstractName;
024: import org.apache.geronimo.gbean.AbstractNameQuery;
025: import org.apache.geronimo.gbean.GBeanData;
026: import org.apache.geronimo.gbean.GBeanInfo;
027: import org.apache.geronimo.kernel.config.ConfigurationData;
028: import org.apache.geronimo.kernel.config.ConfigurationModuleType;
029: import org.apache.geronimo.kernel.repository.Artifact;
030: import org.apache.geronimo.kernel.repository.Dependency;
031: import org.apache.geronimo.kernel.repository.ImportType;
032: import org.apache.geronimo.kernel.repository.Version;
033:
034: /**
035: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
036: */
037: public final class XStreamUtil {
038: private XStreamUtil() {
039: }
040:
041: public static XStream createXStream() {
042: JVM jvm = new JVM();
043: ReflectionProvider reflectionProvider = jvm
044: .bestReflectionProvider();
045: XStream xstream = new XStream(reflectionProvider);
046:
047: // AbstractName
048: xstream.alias("abstractName", AbstractName.class);
049: xstream.addImmutableType(AbstractName.class);
050: xstream.registerConverter(new AbstractNameConverter());
051:
052: // AbstractNameQuery
053: xstream.alias("abstractNameQuery", AbstractNameQuery.class);
054: xstream.addImmutableType(AbstractNameQuery.class);
055: xstream.registerConverter(new AbstractNameQueryConverter());
056:
057: // Artifact
058: xstream.alias("artifact", Artifact.class);
059: xstream.addImmutableType(Artifact.class);
060:
061: // ConfigurationData
062: xstream.alias("configurationData", ConfigurationData.class);
063: xstream.registerConverter(new ConfigurationDataConverter(
064: reflectionProvider, xstream.getClassMapper()));
065:
066: // ConfigurationModuleTypeConverter
067: xstream.alias("moduleType", ConfigurationModuleType.class);
068: xstream.addImmutableType(ConfigurationModuleType.class);
069: xstream
070: .registerConverter(new ConfigurationModuleTypeConverter());
071:
072: // Dependency
073: xstream.alias("dependency", Dependency.class);
074: xstream.addImmutableType(Dependency.class);
075:
076: // GBeanData
077: xstream.alias("gbean", GBeanData.class);
078: xstream.registerConverter(new GBeanDataConverter(xstream
079: .getClassMapper()));
080:
081: // GBeanInfo
082: xstream.alias("gbean-info", GBeanInfo.class);
083:
084: // w3c Dom
085: xstream.registerConverter(new DomConverter());
086:
087: // ImportType
088: xstream.addImmutableType(ImportType.class);
089: xstream.registerConverter(new ImportTypeConverter());
090:
091: // QName
092: try {
093: xstream.registerConverter(new QNameConverter());
094: } catch (Exception e) {
095: // cl can't see QName class so we don't need to register a converter for it
096: }
097:
098: // Version
099: xstream.alias("version", Version.class);
100: xstream.addImmutableType(Version.class);
101: xstream.registerConverter(new VersionConverter());
102:
103: // URI
104: xstream.alias("uri", URI.class);
105: xstream.addImmutableType(URI.class);
106: xstream.registerConverter(new URIConverter());
107:
108: // XStreamGBeanState
109: xstream.registerConverter(new XStreamGBeanStateConverter());
110:
111: return xstream;
112: }
113: }
|