Permalink
Browse files

improving the names that show up in XML

  • Loading branch information...
1 parent 52243ea commit 340b87a3039c68a91129b1cb31f93fe287ae1ac4 @kohsuke kohsuke committed May 7, 2011
Showing with 15 additions and 8 deletions.
  1. +15 −8 src/main/java/org/jenkinsci/jruby/JRubyMapper.java
@@ -2,9 +2,13 @@
import com.thoughtworks.xstream.mapper.Mapper;
import com.thoughtworks.xstream.mapper.MapperWrapper;
+import org.jruby.RubyBasicObject;
import org.jruby.javasupport.proxy.InternalJavaProxy;
/**
+ * Set the proper alias for JRuby objects and proxy objects,
+ * so that implementation detail class names won't leak out to the persisted form.
+ *
* @author Kohsuke Kawaguchi
*/
public class JRubyMapper extends MapperWrapper {
@@ -13,25 +17,28 @@ public JRubyMapper(Mapper wrapped) {
}
public String serializedClass(Class type) {
- if (InternalJavaProxy.class.isAssignableFrom(type)) {
- return ALIAS;
- } else {
+ if (InternalJavaProxy.class.isAssignableFrom(type))
+ return RUBY_PROXY;
+ if (RubyBasicObject.class.isAssignableFrom(type))
+ return RUBY_OBJECT;
+ else
return super.serializedClass(type);
- }
}
public Class realClass(String elementName) {
- if (elementName.equals(ALIAS)) {
+ if (elementName.equals(RUBY_PROXY))
return DynamicProxy.class;
- } else {
+ if (elementName.equals(RUBY_OBJECT))
+ return RubyBasicObject.class;
+ else
return super.realClass(elementName);
- }
}
/**
* Place holder type used for dynamic proxies.
*/
public static class DynamicProxy {}
- private static final String ALIAS = "ruby-proxy-object";
+ private static final String RUBY_PROXY = "ruby-proxy-object";
+ private static final String RUBY_OBJECT = "ruby-object";
}

0 comments on commit 340b87a

Please sign in to comment.