All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.util.RobustCollectionConverter Maven / Gradle / Ivy

package hudson.util;

import com.thoughtworks.xstream.converters.collections.CollectionConverter;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.mapper.Mapper;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.alias.CannotResolveClassException;

import java.util.Collection;

/**
 * {@link CollectionConverter} that ignores {@link CannotResolveClassException}.
 *
 * 

* This allows Hudson to load XML files that contain non-existent classes * (the expected scenario is that those classes belong to plugins that were unloaded.) * * @author Kohsuke Kawaguchi */ public class RobustCollectionConverter extends CollectionConverter { public RobustCollectionConverter(Mapper mapper) { super(mapper); } protected void populateCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection) { while (reader.hasMoreChildren()) { reader.moveDown(); try { Object item = readItem(reader, context, collection); collection.add(item); } catch (CannotResolveClassException e) { System.err.println("failed to locate class: "+e); } reader.moveUp(); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy