/** * Creates a class loader for loading JAXB/WS 2.2 jar */ private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException { List<URL> urls = new ArrayList<URL>(); if(Service.class.getClassLoader()==null) { // JAX-WS API is loaded from bootstrap class loader URL res = cl.getResource("javax/xml/ws/EndpointContext.class"); if(res==null) throw new ClassNotFoundException("There's no JAX-WS 2.2 API in the classpath"); urls.add(ParallelWorldClassLoader.toJarUrl(res)); res = cl.getResource("javax/xml/bind/JAXBPermission.class"); if(res==null) throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath"); urls.add(ParallelWorldClassLoader.toJarUrl(res)); } return urls.toArray(new URL[urls.size()]); }
protected Class findClass(String name) throws ClassNotFoundException { StringBuffer sb = new StringBuffer(name.length()+prefix.length()+6); sb.append(prefix).append(name.replace('.','/')).append(".class"); InputStream is = getParent().getResourceAsStream(sb.toString()); if (is==null) throw new ClassNotFoundException(name); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while((len=is.read(buf))>=0) baos.write(buf,0,len); buf = baos.toByteArray(); int packIndex = name.lastIndexOf('.'); if (packIndex != -1) { String pkgname = name.substring(0, packIndex); // Check if package already loaded. Package pkg = getPackage(pkgname); if (pkg == null) { definePackage(pkgname, null, null, null, null, null, null, null); } } return defineClass(name,buf,0,buf.length); } catch (IOException e) { throw new ClassNotFoundException(name,e); } }
@Override protected URL findResource(String name) { URL u = getParent().getResource(prefix + name); if (u != null) { try { jars.add(new JarFile(new File(toJarUrl(u).toURI()))); } catch (URISyntaxException ex) { Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex); } catch (IOException ex) { Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex); } catch (ClassNotFoundException ex) { //ignore - not a jar } } return u; }
throw new ClassNotFoundException("There's no JAXB 2.1 API in the classpath"); cl = new URLClassLoader(new URL[]{ParallelWorldClassLoader.toJarUrl(apiUrl)},cl); cl = new ParallelWorldClassLoader(cl,"1.0/"); } else { if(mustang) cl = new ParallelWorldClassLoader(cl,"");
/** * Creates a class loader that can load JAXB/WS 2.2 API, * and then return a class loader that can RI classes, which can see all those APIs. */ public static ClassLoader createClassLoader(ClassLoader cl) throws ClassNotFoundException, IOException { URL[] urls = findIstack22APIs(cl); if(urls.length==0) return cl; // we seem to be able to load everything already. no need for the hack List<String> mask = new ArrayList<String>(Arrays.asList(maskedPackages)); if(urls.length>1) { // we need to load 2.1 API from side. so add them to the mask mask.add("javax.xml.bind."); mask.add("javax.xml.ws."); } // first create a protected area so that we load JAXB/WS 2.1 API // and everything that depends on them inside cl = new MaskingClassLoader(cl,mask); // then this class loader loads the API cl = new URLClassLoader(urls, cl); // finally load the rest of the RI. The actual class files are loaded from ancestors cl = new ParallelWorldClassLoader(cl,""); return cl; }
protected Enumeration<URL> findResources(String name) throws IOException { return getParent().getResources( prefix+name); }
throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath"); cl = new URLClassLoader(new URL[]{ParallelWorldClassLoader.toJarUrl(apiUrl)},cl); cl = new ParallelWorldClassLoader(cl,"1.0/"); } else { if(mustang) cl = new ParallelWorldClassLoader(cl,"");
@Override protected URL findResource(String name) { URL u = getParent().getResource(prefix + name); if (u != null) { try { jars.add(new JarFile(new File(toJarUrl(u).toURI()))); } catch (URISyntaxException ex) { Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex); } catch (IOException ex) { Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex); } catch (ClassNotFoundException ex) { //ignore - not a jar } } return u; }
/** * Creates a class loader that can load JAXB/WS 2.2 API, * and then return a class loader that can RI classes, which can see all those APIs. */ public static ClassLoader createClassLoader(ClassLoader cl) throws ClassNotFoundException, IOException { URL[] urls = findIstack22APIs(cl); if(urls.length==0) return cl; // we seem to be able to load everything already. no need for the hack List<String> mask = new ArrayList<String>(Arrays.asList(maskedPackages)); if(urls.length>1) { // we need to load 2.1 API from side. so add them to the mask mask.add("javax.xml.bind."); mask.add("javax.xml.ws."); } // first create a protected area so that we load JAXB/WS 2.1 API // and everything that depends on them inside cl = new MaskingClassLoader(cl,mask); // then this class loader loads the API cl = new URLClassLoader(urls, cl); // finally load the rest of the RI. The actual class files are loaded from ancestors cl = new ParallelWorldClassLoader(cl,""); return cl; }
protected URL findResource(String name) { return getParent().getResource(prefix+name); }
throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath"); cl = new URLClassLoader(new URL[]{ParallelWorldClassLoader.toJarUrl(apiUrl)},cl); cl = new ParallelWorldClassLoader(cl,"1.0/"); } else { if(mustang) cl = new ParallelWorldClassLoader(cl,"");
static File getJarFile(Class clazz) { URL url = null; try { url = ParallelWorldClassLoader.toJarUrl(clazz.getResource('/'+clazz.getName().replace('.','/')+".class")); return new File(url.toURI()); } catch (ClassNotFoundException e) { // if we can't figure out where JAXB/JAX-WS API are, we couldn't have been executing this code. throw new Error(e); } catch (MalformedURLException e) { // if we can't figure out where JAXB/JAX-WS API are, we couldn't have been executing this code. throw new Error(e); } catch (URISyntaxException e) { // url.toURI() is picky and doesn't like ' ' in URL, so this is the fallback return new File(url.getPath()); } }
@Override protected Enumeration<URL> findResources(String name) throws IOException { Enumeration<URL> en = getParent().getResources(prefix + name); while (en.hasMoreElements()) { try { jars.add(new JarFile(new File(toJarUrl(en.nextElement()).toURI()))); } catch (URISyntaxException ex) { //should not happen Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex); } catch (IOException ex) { Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex); } catch (ClassNotFoundException ex) { //ignore - not a jar } } return en; }
sb.append(prefix).append(name.replace('.','/')).append(".class"); URL u = getParent().getResource(sb.toString()); if (u == null) { throw new ClassNotFoundException(name); String pkgname = name.substring(0, packIndex); Package pkg = getPackage(pkgname); if (pkg == null) { definePackage(pkgname, null, null, null, null, null, null, null); return defineClass(name,buf,0,buf.length); } catch (IOException e) { throw new ClassNotFoundException(name,e);
/** * Creates a class loader that can load JAXB/WS 2.2 API, * and then return a class loader that can RI classes, which can see all those APIs. */ public static ClassLoader createClassLoader(ClassLoader cl) throws ClassNotFoundException, IOException { URL[] urls = findIstack22APIs(cl); if(urls.length==0) return cl; // we seem to be able to load everything already. no need for the hack List<String> mask = new ArrayList<String>(Arrays.asList(maskedPackages)); if(urls.length>1) { // we need to load 2.1 API from side. so add them to the mask mask.add("javax.xml.bind."); mask.add("javax.xml.ws."); } // first create a protected area so that we load JAXB/WS 2.1 API // and everything that depends on them inside cl = new MaskingClassLoader(cl,mask); // then this class loader loads the API cl = new URLClassLoader(urls, cl); // finally load the rest of the RI. The actual class files are loaded from ancestors cl = new ParallelWorldClassLoader(cl,""); return cl; }
throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath"); cl = new URLClassLoader(new URL[]{ParallelWorldClassLoader.toJarUrl(apiUrl)},cl); cl = new ParallelWorldClassLoader(cl,"1.0/"); } else { if(mustang) cl = new ParallelWorldClassLoader(cl,"");
/** * Creates a class loader for loading JAXB/WS 2.2 jar */ private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException { List<URL> urls = new ArrayList<URL>(); if(Service.class.getClassLoader()==null) { // JAX-WS API is loaded from bootstrap class loader URL res = cl.getResource("javax/xml/ws/EndpointContext.class"); if(res==null) throw new ClassNotFoundException("There's no JAX-WS 2.2 API in the classpath"); urls.add(ParallelWorldClassLoader.toJarUrl(res)); res = cl.getResource("javax/xml/bind/JAXBPermission.class"); if(res==null) throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath"); urls.add(ParallelWorldClassLoader.toJarUrl(res)); } return urls.toArray(new URL[urls.size()]); }
@Override protected Enumeration<URL> findResources(String name) throws IOException { Enumeration<URL> en = getParent().getResources(prefix + name); while (en.hasMoreElements()) { try { jars.add(new JarFile(new File(toJarUrl(en.nextElement()).toURI()))); } catch (URISyntaxException ex) { //should not happen Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex); } catch (IOException ex) { Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex); } catch (ClassNotFoundException ex) { //ignore - not a jar } } return en; }
sb.append(prefix).append(name.replace('.','/')).append(".class"); URL u = getParent().getResource(sb.toString()); if (u == null) { throw new ClassNotFoundException(name); String pkgname = name.substring(0, packIndex); Package pkg = getPackage(pkgname); if (pkg == null) { definePackage(pkgname, null, null, null, null, null, null, null); return defineClass(name,buf,0,buf.length); } catch (IOException e) { throw new ClassNotFoundException(name,e);
/** * Creates a class loader that can load JAXB/WS 2.2 API, * and then return a class loader that can RI classes, which can see all those APIs. */ public static ClassLoader createClassLoader(ClassLoader cl) throws ClassNotFoundException, IOException { URL[] urls = findIstack22APIs(cl); if(urls.length==0) return cl; // we seem to be able to load everything already. no need for the hack List<String> mask = new ArrayList<String>(Arrays.asList(maskedPackages)); if(urls.length>1) { // we need to load 2.1 API from side. so add them to the mask mask.add("javax.xml.bind."); mask.add("javax.xml.ws."); } // first create a protected area so that we load JAXB/WS 2.1 API // and everything that depends on them inside cl = new MaskingClassLoader(cl,mask); // then this class loader loads the API cl = new URLClassLoader(urls, cl); // finally load the rest of the RI. The actual class files are loaded from ancestors cl = new ParallelWorldClassLoader(cl,""); return cl; }