KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > util > RobustCollectionConverter


1 package hudson.util;
2
3 import com.thoughtworks.xstream.alias.CannotResolveClassException;
4 import com.thoughtworks.xstream.converters.UnmarshallingContext;
5 import com.thoughtworks.xstream.converters.collections.CollectionConverter;
6 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
7 import com.thoughtworks.xstream.mapper.Mapper;
8
9 import java.util.Collection JavaDoc;
10
11 /**
12  * {@link CollectionConverter} that ignores {@link CannotResolveClassException}.
13  *
14  * <p>
15  * This allows Hudson to load XML files that contain non-existent classes
16  * (the expected scenario is that those classes belong to plugins that were unloaded.)
17  *
18  * @author Kohsuke Kawaguchi
19  */

20 public class RobustCollectionConverter extends CollectionConverter {
21     public RobustCollectionConverter(Mapper mapper) {
22         super(mapper);
23     }
24
25     protected void populateCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection JavaDoc collection) {
26         while (reader.hasMoreChildren()) {
27             reader.moveDown();
28             try {
29                 Object JavaDoc item = readItem(reader, context, collection);
30                 collection.add(item);
31             } catch (CannotResolveClassException e) {
32                 System.err.println("failed to locate class: "+e);
33             }
34             reader.moveUp();
35         }
36     }
37
38 }
39
Popular Tags