private static Object createEscapeHandler(Class<?> cls, String simpleClassName) { try { String postFix = getPostfix(cls); if (postFix == null) { LOG.log(Level.WARNING, "Failed to create" + simpleClassName + " for unknown jaxb class:" + cls); return null; } Class<?> handlerClass = ClassLoaderUtils.loadClass("com.sun.xml" + postFix + ".bind.marshaller." + simpleClassName, cls); Class<?> handlerInterface = ClassLoaderUtils .loadClass("com.sun.xml" + postFix + ".bind.marshaller.CharacterEscapeHandler", cls); Object targetHandler = ReflectionUtil.getDeclaredField(handlerClass, "theInstance").get(null); return ProxyHelper.getProxy(cls.getClassLoader(), new Class[] {handlerInterface}, new EscapeHandlerInvocationHandler(targetHandler)); } catch (Exception e) { if ("NoEscapeHandler".equals(simpleClassName)) { //this class doesn't exist in JAXB 2.2 so expected LOG.log(Level.FINER, "Failed to create " + simpleClassName); } else { LOG.log(Level.INFO, "Failed to create " + simpleClassName); } } return null; }
private static Object createEscapeHandler(Class<?> cls, String simpleClassName) { try { String postFix = getPostfix(cls); if (postFix == null) { LOG.log(Level.WARNING, "Failed to create" + simpleClassName + " for unknown jaxb class:" + cls); return null; } Class<?> handlerClass = ClassLoaderUtils.loadClass("com.sun.xml" + postFix + ".bind.marshaller." + simpleClassName, cls); Class<?> handlerInterface = ClassLoaderUtils .loadClass("com.sun.xml" + postFix + ".bind.marshaller.CharacterEscapeHandler", cls); Object targetHandler = ReflectionUtil.getDeclaredField(handlerClass, "theInstance").get(null); return ProxyHelper.getProxy(cls.getClassLoader(), new Class[] {handlerInterface}, new EscapeHandlerInvocationHandler(targetHandler)); } catch (Exception e) { if ("NoEscapeHandler".equals(simpleClassName)) { //this class doesn't exist in JAXB 2.2 so expected LOG.log(Level.FINER, "Failed to create " + simpleClassName); } else { LOG.log(Level.INFO, "Failed to create " + simpleClassName); } } return null; }