Creates instance of implementation class and loads it dynamic. This method
is used in testing.
@param cls
@return
@throws IOException
17945
public static Object createDynamicInstance(Class<?> cls) throws IOException
    {
        GenClassCompiler pc = GenClassCompiler.compile(El.getTypeElement(cls.getCanonicalName()), null);
        return pc.loadDynamic();
    }
196948
private Class createClass(String className) throws ClassNotFoundException {
        Class clazz;
        try {
            URLClassLoader classLoader = URLClassLoader.newInstance(new URL[]{root.toURI().toURL()});
            if (log.isDebugEnabled()) {
                log.debug("Classloader URLs:");
                for (URL url : classLoader.getURLs()) {
                    log.debug("  " + url.toString());
                }
            }

            clazz = Class.forName(className, true, classLoader);
            return clazz;

        } catch (MalformedURLException mue) {
            String info = "Could not load the " + description + " object " + className
                    + ". Malformed URL: ";
            info += mue.getMessage();
            throw new ClassNotFoundException(info, mue);

        } catch (ExceptionInInitializerError eiie) {
            String info = "Could not load the " + description + " object " + className
                    + ". Could not initialize static object in server: ";
            info += eiie.getMessage();
            throw new ClassNotFoundException(info, eiie);

        } catch (LinkageError le) {
            String info = "Could not load the " + description + " object " + className
                    + ". This object is depending on a class that has been changed after compilation ";
            info += "or a class that was not found: ";
            info += le.getMessage();
            throw new ClassNotFoundException(info, le);

        } catch (ClassNotFoundException cnfe) {
            String info = "Could not find the " + description + " object " + className + ": ";
            info += cnfe.getMessage();
            throw new ClassNotFoundException(info, cnfe);
        }
    }
1370479
private Object fromClass(final Class cl) throws Throwable {
    if (cl == null) {
      error("Must supply a class or have type attribute");
      return null;
    }

    return cl.newInstance();
  }
1317312
public <E> ClassFactory<E> createFactory(String... classes) {
    try {
      return new ClassFactory<E>(classname, classes);
    } catch (ClassCreationException e){
      throw e;
    } catch (Exception e) {
      throw new ClassCreationException(e);
    }
  }
65536
public Object createObject(String className, Class clazz) throws ClassNotFoundException {
        Object object;
        try {
            object = clazz.newInstance();

        } catch (InstantiationException ie) {
            String info = "Could not create " + description + " object: " + className
                    + ". Could not access object constructor: ";
            info += ie.getMessage();
            throw new ClassNotFoundException(info, ie);

        } catch (IllegalAccessException iae) {
            String info = "Could not create " + description + " object: " + className
                    + ". Could not instantiate object. Does the object classname refer to an abstract class, "
                    + "an interface or the like?: ";
            info += iae.getMessage();
            throw new ClassNotFoundException(info, iae);

        } catch (ClassCastException cce) {
            String info = "Could not create " + description + " object: " + className
                    + ". The specified object classname does not refer to the proper type: ";
            info += cce.getMessage();
            throw new ClassNotFoundException(info, cce);
        }

        return object;
    }
125316
public RTMPConnection createConnectionInstance(Class<?> cls) throws Exception {
        RTMPConnection conn = null;
        if (cls == RTMPMinaConnection.class) {
            conn = (RTMPMinaConnection) cls.newInstance();
        } else if (cls == RTMPTClientConnection.class) {
            conn = (RTMPTClientConnection) cls.newInstance();
        } else {
            conn = (RTMPConnection) cls.newInstance();
        }
        conn.setMaxHandshakeTimeout(maxHandshakeTimeout);
        conn.setMaxInactivity(maxInactivity);
        conn.setPingInterval(pingInterval);
        if (enableTaskExecutor) {
            // setup executor
            ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
            executor.setCorePoolSize(1);
            executor.setDaemon(true);
            executor.setMaxPoolSize(1);
            executor.setQueueCapacity(executorQueueCapacity);
            executor.initialize();
            conn.setExecutor(executor);
        }
        return conn;
    }
813555
public static void dynamicCodeGenerate(OutputStream os, Class cls, Charset charset, ICodeGenerator codeGenerator)
            throws IOException {
        if (cls == null) {
            throw new NullPointerException("Parameter 'cls' is null");
        }
        if (os == null) {
            throw new NullPointerException("Parameter 'os' is null");
        }
        if (charset == null) {
            charset = Charset.defaultCharset();
        }
        String code = codeGenerator.getCode();

        os.write(code.getBytes(charset));
    }
962027
public C createObject(String className, Class clazz, DynamicInitializer<C> di) throws ClassNotFoundException {
        C object;
        try {
            object = (C) clazz.newInstance();

        } catch (InstantiationException ie) {
            String info = "Could not create " + description + " object: " + className
                    + ". Could not access object constructor: ";
            info += ie.getMessage();
            throw new ClassNotFoundException(info, ie);

        } catch (IllegalAccessException iae) {
            String info = "Could not create " + description + " object: " + className
                    + ". Could not instantiate object. Does the object classname refer to an abstract class, "
                    + "an interface or the like?: ";
            info += iae.getMessage();
            throw new ClassNotFoundException(info, iae);

        } catch (ClassCastException cce) {
            String info = "Could not create " + description + " object: " + className
                    + ". The specified object classname does not refer to the proper type: ";
            info += cce.getMessage();
            throw new ClassNotFoundException(info, cce);
        }

        // Initialize object
        if (null != di) {
            di.initialize(object);
        }

        return object;
    }
16146
public static Class<?> loadClass(String className, ClassLoader cl) {
        try {
            return Class.forName(className, false, cl);
        } catch(ClassNotFoundException e) {
            throw new IllegalArgumentException(e);
        }
    }
294089
public Class<?> loadClassFrom(String name, AbstractClassLoader first) throws ClassNotFoundException {
		// try on the system one
		try { return AppClassLoader.class.getClassLoader().loadClass(name); }
		catch (ClassNotFoundException e) { /* not found. */ }
		Class<?> c = null;
		// check it is not loaded on one of the library
		for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
    		c = cl.isLoaded(name);
    		if (c != null) return c;
    	}
    	// try with the first one
    	if (first != null) {
    		try {
    			c = first.loadClassInLibrary(name);
    			if (c != null) return c;
    		} catch (FileNotFoundException e) {
    			// not found
    		} catch (IOException e) {
    			throw new ClassNotFoundException(e.getMessage());
    		}
    	}
    	// then, try on other libraries
    	for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
    		if (cl == first) continue;
    		try {
    			c = cl.loadClassInLibrary(name);
    			if (c != null) return c;
    		} catch (FileNotFoundException e) {
    			// not found
    		} catch (IOException e) {
    			throw new ClassNotFoundException(e.getMessage());
    		}
    	}
		StringBuilder msg = new StringBuilder(512);
		msg.append("Class not found: ").append(name);
		msg.append("\r\nFrom class loader: ").append(first);
		msg.append("\r\nlibraries currently registered:");
		for (int i = 0; i < libs.size(); i++)
			msg.append("\r\n - ").append(libs.get(i).toString());
		throw new ClassNotFoundException(msg.toString());
	}

	/** Load a resource. */
	@SuppressWarnings("resource")
	public IO.Readable getResourceIO(String name, byte priority) {
		if (name.length() == 0) return null;
		if (name.charAt(0) == '/') name = name.substring(1);
		IO.Readable io = null;
    	for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
   			try { io = cl.open(name, priority); }
   			catch (IOException e) { /* ignore */ }
    		if (io != null) return io;
    	}
       	// then try on the core one
        InputStream in = AppClassLoader.class.getClassLoader().getResourceAsStream(name);
        if (in == null) return null;
        return new IOFromInputStream(in, name, Threading.getUnmanagedTaskManager(), priority);
	}
1341547
private static Class<?> loadClass(String className) {
        try {
            return Class.forName(className, false, getClassLoader());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
419442
private byte[] loadClassBytes(File classFile) throws IOException
	{

		int size = (int) classFile.length();
		byte buff[] = new byte[size];

		FileInputStream fis = new FileInputStream(classFile);
		DataInputStream dis = null;

		try
		{
			dis = new DataInputStream(fis);
			dis.readFully(buff);
		}
		finally
		{
			if(dis != null)
				dis.close();
		}

		return buff;
	}
258383
public static Object loadInstance(Class clazz, Object[] args) throws ClassException, InvocationTargetException {
	if (args == null || args.length == 0) return loadInstance(clazz);

	Class[] cArgs = new Class[args.length];
	for (int i = 0; i < args.length; i++) {
	    cArgs[i] = args[i].getClass();
	}

	try {
	    Constructor c = clazz.getConstructor(cArgs);
	    return c.newInstance(args);

	}
	catch (SecurityException e) {
	    throw new ClassException("there is a security violation (throwed by security manager)");
	}
	catch (NoSuchMethodException e) {

	    StringBuilder sb = new StringBuilder(clazz.getName());
	    char del = '(';
	    for (int i = 0; i < cArgs.length; i++) {
		sb.append(del);
		sb.append(cArgs[i].getName());
		del = ',';
	    }
	    sb.append(')');

	    throw new ClassException("there is no constructor with this [" + sb + "] signature for the class [" + clazz.getName() + "]");
	}
	catch (IllegalArgumentException e) {
	    throw new ClassException("has been passed an illegal or inappropriate argument");
	}
	catch (InstantiationException e) {
	    throw new ClassException("the specified class object [" + clazz.getName() + "] cannot be instantiated because it is an interface or is an abstract class");
	}
	catch (IllegalAccessException e) {
	    throw new ClassException("can't load class because the currently executing method does not have access to the definition of the specified class");
	}
    }
1240327
static Class<?> reloadClass(ClassLoader cl, Class<?> classType) throws InvocationException {
        try {
            return cl.loadClass(classType.getName());
        } catch (ClassNotFoundException e) {
            throw new InvocationException(e, "Unable to reload class {0} with class loader {1}, previously loaded with {2}",
                    classType.getName(), cl, classType.getClassLoader());
        }
    }
990636
public static Object instance(String clsName,ClassLoader loader)
	{
		try
		{
			return Class.forName(clsName,true,loader).newInstance();
		}
		catch (InstantiationException e)
		{
			throw new RuntimeException(e);
		}
		catch (IllegalAccessException e)
		{
			throw new RuntimeException(e);
		}
		catch (ClassNotFoundException e)
		{
			throw new RuntimeException(e);
		}
	}
14860
public static <T extends SerializableObject> T deserialize(File file, Class<T> cls) throws IOException {
		FileInputStream stream = null;
		try {
			stream = new FileInputStream(file);
			DataInputStream in = new DataInputStream(stream);

			try {
				Constructor<T> constructor = cls.getDeclaredConstructor(DataInput.class);
				constructor.setAccessible(true);
				return constructor.newInstance(in);
			} catch (Exception e) {
				throw new IOException("Unable to instantiate class: " + cls, e);
			}
		} finally {
			Util.ensureClosed(stream);
		}
	}
80972
public static InitStrategy get(ClassLoader cl) throws IOException {
        Iterator<InitStrategy> it = ServiceLoader.load(InitStrategy.class, cl).iterator();
        if (!it.hasNext()) {
            return new InitStrategy(); // default
        }
        InitStrategy s = it.next();
        LOGGER.log(Level.FINE, "Using {0} as InitStrategy", s);
        return s;
    }