本文整理了Java中com.thoughtworks.xstream.XStream.setClassLoader()
方法的一些代码示例,展示了XStream.setClassLoader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XStream.setClassLoader()
方法的具体详情如下:
包路径:com.thoughtworks.xstream.XStream
类名称:XStream
方法名:setClassLoader
[英]Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will register for all kind of classes and types of the current JDK, but not for any 3rd party type. To ensure that all other types are loaded with your class loader, you should call this method as early as possible - or consider to provide the class loader directly in the constructor.
[中]更改XStream用于加载类的类加载器。创建XStream实例时,它将注册当前JDK的所有类和类型,但不会注册任何第三方类型。为了确保所有其他类型都加载了类加载器,应尽早调用此方法,或者考虑在构造函数中直接提供类加载器。
代码示例来源:origin: kiegroup/optaplanner
/**
* @param solverConfigContext never null
*/
public XStreamXmlSolverFactory(SolverConfigContext solverConfigContext) {
super(solverConfigContext);
xStream = buildXStream();
ClassLoader actualClassLoader = solverConfigContext.determineActualClassLoader();
xStream.setClassLoader(actualClassLoader);
}
代码示例来源:origin: kiegroup/jbpm
private XStream getXStream() {
XStream xstream = createXStream();
if (classLoader != null) {
xstream.setClassLoader(classLoader);
if (classLoader instanceof ProjectClassLoader ) {
Map<String, byte[]> store = ((ProjectClassLoader) classLoader).getStore();
if (store != null) {
String[] classes = store.keySet().stream()
.map( s -> s.replace( '/', '.' ) )
.map( s -> s.endsWith( ".class" ) ? s.substring( 0, s.length() - ".class".length() ) : s )
.toArray( String[]::new );
xstream.addPermission( new ExplicitTypePermission( classes ) );
}
}
}
return xstream;
}
代码示例来源:origin: kiegroup/optaplanner
/**
* @param solverConfigContext never null
*/
public XStreamXmlPlannerBenchmarkFactory(SolverConfigContext solverConfigContext) {
super(solverConfigContext);
xStream = XStreamXmlSolverFactory.buildXStream();
ClassLoader actualClassLoader = solverConfigContext.determineActualClassLoader();
xStream.setClassLoader(actualClassLoader);
xStream.processAnnotations(PlannerBenchmarkConfig.class);
xStream.registerConverter(new FileConverter() {
@Override
public String toString(Object obj) {
// Write "/" path separators (even on Windows) for portability
return FilenameUtils.separatorsToUnix(((File) obj).getPath());
}
});
}
代码示例来源:origin: AxonFramework/AxonFramework
private Serializer buildSerializer(RevisionResolver revisionResolver,
SerializerProperties.SerializerType serializerType) {
switch (serializerType) {
case JACKSON:
Map<String, ObjectMapper> objectMapperBeans = applicationContext.getBeansOfType(ObjectMapper.class);
ObjectMapper objectMapper = objectMapperBeans.containsKey("defaultAxonObjectMapper")
? objectMapperBeans.get("defaultAxonObjectMapper")
: objectMapperBeans.values().stream().findFirst()
.orElseThrow(() -> new NoClassDefFoundError(
"com/fasterxml/jackson/databind/ObjectMapper"
));
ChainingConverter converter = new ChainingConverter(beanClassLoader);
return JacksonSerializer.builder()
.revisionResolver(revisionResolver)
.converter(converter)
.objectMapper(objectMapper)
.build();
case JAVA:
return JavaSerializer.builder().revisionResolver(revisionResolver).build();
case XSTREAM:
case DEFAULT:
default:
XStreamSerializer xStreamSerializer = XStreamSerializer.builder()
.revisionResolver(revisionResolver)
.build();
xStreamSerializer.getXStream().setClassLoader(beanClassLoader);
return xStreamSerializer;
}
}
代码示例来源:origin: hcoles/pitest
private static XStream getXStreamForLoader(final ClassLoader loader) {
XStream foreginXstream = CACHE.get(loader);
if (foreginXstream == null) {
foreginXstream = new XStream(new PitXmlDriver());
foreginXstream.setClassLoader(loader);
// possible that more than one instance will be created
// per loader, but probably better than synchronizing the whole method
synchronized (CACHE) {
CACHE.put(loader, foreginXstream);
}
}
return foreginXstream;
}
代码示例来源:origin: stackoverflow.com
ClassLoader bootstrapClassLoader = ClassLoader.getSystemClassLoader().getParent();
List urls = new ArrayList();
urls.add(new File("yourJarOfXstreamBeanClasses.jar").toURL());
ClassLoader xstreamClassLoader = new URLClassLoader(urls.toArray(new URL[0]), bootstrapClassLoader);
XStream xstream = new XStream();
xstream.setClassLoader(xstreamClassLoader);
代码示例来源:origin: org.apache.activemq/activemq-all
public XStream getXStream() {
if (xStream == null) {
xStream = createXStream();
// make it work in OSGi env
xStream.setClassLoader(getClass().getClassLoader());
}
return xStream;
}
代码示例来源:origin: org.randombits.storage/storage
/**
* Sets the classloader which will be used for serialization.
*
* @param classLoader
* The serialization classloader.
*/
public void setClassLoader( ClassLoader classLoader ) {
getXStream().setClassLoader( classLoader );
}
代码示例来源:origin: org.apache.activemq/activemq-http
public XStream getXStream() {
if (xStream == null) {
xStream = createXStream();
// make it work in OSGi env
xStream.setClassLoader(getClass().getClassLoader());
}
return xStream;
}
代码示例来源:origin: org.apache.activemq/activemq-optional
public XStream getXStream() {
if (xStream == null) {
xStream = createXStream();
// make it work in OSGi env
xStream.setClassLoader(getClass().getClassLoader());
}
return xStream;
}
代码示例来源:origin: net.sf.taverna.t2.ui-api/contextual-views-api
protected Object cloneBean(Object bean) {
XStream xstream = new XStream(new DomDriver());
xstream.setClassLoader(bean.getClass().getClassLoader());
return (xstream.fromXML(xstream.toXML(bean)));
}
代码示例来源:origin: org.tinygroup/org.tinygroup.xstream
private static XStream newXStream(ClassLoader classLoader) {
XStream xstream = new XStream();
if (classLoader != null) {
xstream.setClassLoader(classLoader);
} else {
xstream.setClassLoader(XStreamFactory.class.getClassLoader());
}
xstream.autodetectAnnotations(true);
xstream.setMode(XStream.NO_REFERENCES);
xstream.processAnnotations(XStreamConfiguration.class);
return xstream;
}
代码示例来源:origin: net.sf.taverna.t2.ui-api/contextual-views-api
protected String convertBeanToString(Object bean) {
XStream xstream = new XStream(new DomDriver());
xstream.setClassLoader(bean.getClass().getClassLoader());
return xstream.toXML(bean);
}
代码示例来源:origin: org.fuzzydb.attrs/org.fuzzydb.attrs
public static void updateScorerConfig(Store store, String content) {
XStream xs = XStreamHelper.getScorerXStream(store);
xs.setClassLoader( WWConfigHelper.class.getClassLoader() ); // OSGi: We need it to use our classLoader, as it's own bundle won't help it :)
ScoreConfiguration sc = (ScoreConfiguration) xs.fromXML(content);
updateScorerConfigInternal(store, sc);
}
代码示例来源:origin: org.fuzzydb.attrs/org.fuzzydb.attrs
public static void updateIndexConfig(Store store, InputStream inputStream) {
XStream xs = XStreamHelper.getIndexConfigXStream(store);
xs.setClassLoader( WWConfigHelper.class.getClassLoader() ); // OSGi: We need it to use our classLoader, as it's own bundle won't help it :)
ManualIndexStrategy strategy = (ManualIndexStrategy) xs.fromXML(inputStream);
updateIndexConfigInternal(store, strategy);
}
代码示例来源:origin: org.fuzzydb.attrs/org.fuzzydb.attrs
/**
* Update split configs
* FIXME: This does not check if no change has been made. Server side needs to have code to detect this
* and avoid rebuilding an index for no reason (unless forced)
*/
public static void updateIndexConfig(Store store, String content) {
XStream xs = XStreamHelper.getIndexConfigXStream(store);
xs.setClassLoader( WWConfigHelper.class.getClassLoader() ); // OSGi: We need it to use our classLoader, as it's own bundle won't help it :)
ManualIndexStrategy strategy = (ManualIndexStrategy) xs.fromXML(content);
updateIndexConfigInternal(store, strategy);
}
代码示例来源:origin: net.sf.taverna.t2.ui-activities/disabled-activity-ui
public boolean isConfigurationChanged() {
XStream xstream = new XStream(new DomDriver());
xstream.setClassLoader(configuration.getActivity().getClass().getClassLoader());
return (!xstream.toXML(clonedConfig).equals(origConfigXML));
}
代码示例来源:origin: com.atlassian.confluence.extra.webdav/webdav-plugin
@Autowired
public BandanaWebdavSettingsManager(@ComponentImport BandanaManager bandanaManager) {
this.bandanaManager = bandanaManager;
this.xStream = new XStream(new Sun14ReflectionProvider());
xStream.setClassLoader(getClass().getClassLoader());
}
代码示例来源:origin: net.sf.taverna.t2.ui-activities/component-activity-ui
private String getConfigString(Activity<?> baseActivity) {
XStream xstream = new XStream(new DomDriver());
Object baseConfig = baseActivity.getConfiguration();
xstream.setClassLoader(baseConfig.getClass().getClassLoader());
return xstream.toXML(baseConfig);
}
代码示例来源:origin: org.jfrog.teamcity/teamcity-artifactory-plugin-server
public ServerConfigPersistenceManager(@NotNull ServerPaths serverPaths) {
xStream = new XStream();
xStream.setClassLoader(SerializableServers.class.getClassLoader());
xStream.processAnnotations(new Class[]{SerializableServer.class, SerializableServers.class});
configFile = new File(serverPaths.getConfigDir(), CONFIG_FILE_NAME);
loadSettings();
}
内容来源于网络,如有侵权,请联系作者删除!