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 */ 017 package org.apache.geronimo.kernel.config.xstream; 018 019 import java.net.URI; 020 021 import com.thoughtworks.xstream.XStream; 022 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; 023 import com.thoughtworks.xstream.core.JVM; 024 import org.apache.geronimo.gbean.AbstractName; 025 import org.apache.geronimo.gbean.AbstractNameQuery; 026 import org.apache.geronimo.gbean.GBeanData; 027 import org.apache.geronimo.gbean.GBeanInfo; 028 import org.apache.geronimo.kernel.config.ConfigurationData; 029 import org.apache.geronimo.kernel.config.ConfigurationModuleType; 030 import org.apache.geronimo.kernel.repository.Artifact; 031 import org.apache.geronimo.kernel.repository.Dependency; 032 import org.apache.geronimo.kernel.repository.ImportType; 033 import org.apache.geronimo.kernel.repository.Version; 034 035 /** 036 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $ 037 */ 038 public final class XStreamUtil { 039 private XStreamUtil() { 040 } 041 042 public static XStream createXStream() { 043 JVM jvm = new JVM(); 044 ReflectionProvider reflectionProvider = jvm.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(reflectionProvider, xstream.getClassMapper())); 064 065 // ConfigurationModuleTypeConverter 066 xstream.alias("moduleType", ConfigurationModuleType.class); 067 xstream.addImmutableType(ConfigurationModuleType.class); 068 xstream.registerConverter(new ConfigurationModuleTypeConverter()); 069 070 // Dependency 071 xstream.alias("dependency", Dependency.class); 072 xstream.addImmutableType(Dependency.class); 073 074 // GBeanData 075 xstream.alias("gbean", GBeanData.class); 076 xstream.registerConverter(new GBeanDataConverter(xstream.getClassMapper())); 077 078 // GBeanInfo 079 xstream.alias("gbean-info", GBeanInfo.class); 080 081 // w3c Dom 082 xstream.registerConverter(new DomConverter()); 083 084 // ImportType 085 xstream.addImmutableType(ImportType.class); 086 xstream.registerConverter(new ImportTypeConverter()); 087 088 // QName 089 try { 090 xstream.registerConverter(new QNameConverter()); 091 } catch (Exception e) { 092 // cl can't see QName class so we don't need to register a converter for it 093 } 094 095 // Version 096 xstream.alias("version", Version.class); 097 xstream.addImmutableType(Version.class); 098 xstream.registerConverter(new VersionConverter()); 099 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 }