/** * Reads local resources from - Jar files - Class folders - Jar Library * folders * * @param path */ public void loadResource(String path) { logger.debug( "Resource: {}", path ); File fp = new File( path ); if (!fp.exists() && !ignoreMissingResources) { throw new JclException( "File/Path does not exist" ); } loadResource( fp, "" ); }
/** * Reads local resources from - Jar files - Class folders - Jar Library * folders * * @param path */ public void loadResource(String path) { logger.debug( "Resource: {}", path ); File fp = new File( path ); if (!fp.exists() && !ignoreMissingResources) { throw new JclException( "File/Path does not exist" ); } loadResource( fp, "" ); }
/** * Reads the jar file from a specified URL * * @param url */ public void loadJar(URL url) { logger.debug( "Loading jar: {}", url.toString() ); InputStream in = null; try { String baseUrl = "jar:" + url.toString() + "!/"; in = url.openStream(); loadJar( baseUrl, in ); } catch (IOException e) { throw new JclException( e ); } finally { if (in != null) try { in.close(); } catch (IOException e) { throw new JclException( e ); } } }
/** * Reads the specified jar file * * @param jarFile */ public void loadJar(String jarFile) { logger.debug( "Loading jar: {}", jarFile ); FileInputStream fis = null; try { File file = new File( jarFile ); String baseUrl = "jar:" + file.toURI().toString() + "!/"; fis = new FileInputStream( file ); loadJar(baseUrl, fis); } catch (IOException e) { throw new JclException( e ); } finally { if (fis != null) try { fis.close(); } catch (IOException e) { throw new JclException( e ); } } }
/** * Reads the jar file from a specified URL * * @param url */ public void loadJar(URL url) { logger.debug( "Loading jar: {}", url.toString() ); InputStream in = null; try { String baseUrl = "jar:" + url.toString() + "!/"; in = url.openStream(); loadJar( baseUrl, in ); } catch (IOException e) { throw new JclException( e ); } finally { if (in != null) try { in.close(); } catch (IOException e) { throw new JclException( e ); } } }
/** * @param name * @return URL */ public URL getResourceURL(String name) { JclJarEntry entry = jarEntryContents.get(name); if (entry != null) { if (entry.getBaseUrl() == null) { throw new JclException( "non-URL accessible resource" ); } try { return new URL( entry.getBaseUrl().toString() + name ); } catch (MalformedURLException e) { throw new JclException( e ); } } return null; }
/** * @param name * @return URL */ public URL getResourceURL(String name) { JclJarEntry entry = jarEntryContents.get(name); if (entry != null) { if (entry.getBaseUrl() == null) { throw new JclException( "non-URL accessible resource" ); } try { return new URL( entry.getBaseUrl().toString() + name ); } catch (MalformedURLException e) { throw new JclException( e ); } } return null; }
@Override public Class loadClass(String className, boolean resolveIt) { Class clazz = null; if (enabled && isPartOfOsgiBootDelegation(className)) { clazz = getParentLoader().loadClass(className, resolveIt); if (clazz == null && strictLoading) { throw new JclException(new ClassNotFoundException("JCL OSGi Boot Delegation: Class " + className + " not found.")); } logger.debug("Class " + className + " loaded via OSGi boot delegation."); } return clazz; }
@Override public Class loadClass(String className, boolean resolveIt) { Class clazz = null; if (enabled && isPartOfOsgiBootDelegation(className)) { clazz = getParentLoader().loadClass(className, resolveIt); if (clazz == null && strictLoading) { throw new JclException(new ClassNotFoundException("JCL OSGi Boot Delegation: Class " + className + " not found.")); } logger.debug("Class " + className + " loaded via OSGi boot delegation."); } return clazz; }
/** * Reads local and remote resources * * @param url */ public void loadResource(URL url) { try { // Is Local loadResource( new File( url.toURI() ), "" ); } catch (IllegalArgumentException iae) { // Is Remote loadRemoteResource( url ); } catch (URISyntaxException e) { throw new JclException( "URISyntaxException", e ); } }
/** * Reads local and remote resources * * @param url */ public void loadResource(URL url) { try { // Is Local loadResource( new File( url.toURI() ), "" ); } catch (IllegalArgumentException iae) { // Is Remote loadRemoteResource( url ); } catch (URISyntaxException e) { throw new JclException( "URISyntaxException", e ); } }
@SuppressWarnings("unchecked") private void createDependencyOnJcl(Node node, BeanDefinitionHolder holder, ParserContext parserContext) { AbstractBeanDefinition definition = ( (AbstractBeanDefinition) holder.getBeanDefinition() ); String jclRef = node.getAttributes().getNamedItem( JCL_REF ).getNodeValue(); if( !parserContext.getRegistry().containsBeanDefinition( JCL_FACTORY ) ) { BeanDefinitionBuilder initializer = BeanDefinitionBuilder.rootBeanDefinition( JclObjectFactory.class, JCL_FACTORY_CONSTRUCTOR ); parserContext.getRegistry().registerBeanDefinition( JCL_FACTORY, initializer.getBeanDefinition() ); } if( parserContext.getRegistry().containsBeanDefinition( jclRef ) ) { String[] dependsOn = definition.getDependsOn(); if( dependsOn == null ) { dependsOn = new String[] { jclRef, JCL_FACTORY }; } else { List dependencies = new ArrayList( Arrays.asList( dependsOn ) ); dependencies.add( jclRef ); dependencies.add( JCL_FACTORY ); dependsOn = (String[]) dependencies.toArray( new String[0] ); } definition.setDependsOn( dependsOn ); } else throw new JclException( "JCL Bean definition " + jclRef + "not found" ); } }
/** * Creates the object of the specified class from the specified class loader * by invoking the right arguments-constructor based on the passed types * parameter * * @param jcl * @param className * @param args * @param types * @return Object */ public Object create(JarClassLoader jcl, String className, Object[] args, Class[] types) { Object obj = null; if (args == null || args.length == 0) { try { obj = jcl.loadClass( className ).newInstance(); } catch (Throwable e) { throw new JclException( e ); } } else { try { obj = jcl.loadClass( className ).getConstructor( types ).newInstance( args ); } catch (Exception e) { throw new JclException( e ); } } return newInstance( obj ); }
/** * Creates the object of the specified class from the specified class loader * by invoking the right static factory method * * @param jcl * @param className * @param methodName * @param args * @return Object */ public Object create(JarClassLoader jcl, String className, String methodName, Object... args) { if (args == null || args.length == 0) { try { return newInstance( jcl.loadClass( className ).getMethod( methodName ).invoke( null ) ); } catch (Exception e) { throw new JclException( e ); } } Class[] types = new Class[args.length]; for (int i = 0; i < args.length; i++) types[i] = args[i].getClass(); return create( jcl, className, methodName, args, types ); }
/** * Creates the object of the specified class from the specified class loader * by invoking the right static factory method * * @param jcl * @param className * @param methodName * @param args * @return Object */ public Object create(JarClassLoader jcl, String className, String methodName, Object... args) { if (args == null || args.length == 0) { try { return newInstance( jcl.loadClass( className ).getMethod( methodName ).invoke( null ) ); } catch (Exception e) { throw new JclException( e ); } } Class[] types = new Class[args.length]; for (int i = 0; i < args.length; i++) types[i] = args[i].getClass(); return create( jcl, className, methodName, args, types ); }
/** * Creates the object of the specified class from the specified class loader * by invoking the right arguments-constructor * * @param jcl * @param className * @param args * @return Object */ public Object create(JarClassLoader jcl, String className, Object... args) { if (args == null || args.length == 0) { try { return newInstance( jcl.loadClass( className ).newInstance() ); } catch (Throwable e) { throw new JclException( e ); } } Class[] types = new Class[args.length]; for (int i = 0; i < args.length; i++) types[i] = args[i].getClass(); return create( jcl, className, args, types ); }
/** * Creates the object of the specified class from the specified class loader * by invoking the right arguments-constructor * * @param jcl * @param className * @param args * @return Object */ public Object create(JarClassLoader jcl, String className, Object... args) { if (args == null || args.length == 0) { try { return newInstance( jcl.loadClass( className ).newInstance() ); } catch (Throwable e) { throw new JclException( e ); } } Class[] types = new Class[args.length]; for (int i = 0; i < args.length; i++) types[i] = args[i].getClass(); return create( jcl, className, args, types ); }
/** * Loads local/remote source * * @param source */ public void add(Object source) { if (source instanceof InputStream) add( (InputStream) source ); else if (source instanceof URL) add( (URL) source ); else if (source instanceof String) add( (String) source ); else throw new JclException( "Unknown Resource type" ); }
/** * Loads local/remote source * * @param source */ public void add(Object source) { if (source instanceof InputStream) add( (InputStream) source ); else if (source instanceof URL) add( (URL) source ); else if (source instanceof String) add( (String) source ); else throw new JclException( "Unknown Resource type" ); }
/** * Loads local/remote source * * @param source */ public void add(Object source) { if(source instanceof InputStream) { add((InputStream)source); } else if(source instanceof URL) { add((URL)source); } else if(source instanceof String) { add((String)source); } else { throw new JclException("Unknown Resource type"); } }