List of usage examples for java.lang ClassLoader loadClass
public Class<?> loadClass(String name) throws ClassNotFoundException
From source file:hermes.browser.dialog.HermesAdminFactoryConfigPanel.java
public void setConfig(String classPathId, ProviderExtConfig newConfig) { this.config = newConfig; if (cfComboModel.getIndexOf(ConfigDAOImpl.DEFAULT_PLUGIN) == -1) { cfComboModel.addElement(ConfigDAOImpl.DEFAULT_PLUGIN); }//from www .j a v a 2 s. c om for (Iterator iter = HermesBrowser.getConfigDAO().getAdminFactories().iterator(); iter.hasNext();) { String adminFactoryName = (String) iter.next(); String pluginName = HermesBrowser.getConfigDAO().getPlugInName(adminFactoryName); if (cfComboModel.getIndexOf(pluginName) == -1) { cfComboModel.addElement(pluginName); } } cfComboModel.setSelectedItem(HermesBrowser.getConfigDAO().getPlugInName(config.getClassName())); try { ClassLoaderManager classLoaderManager = (ClassLoaderManager) SingletonManager .get(ClassLoaderManager.class); ClassLoader classLoader = classLoaderManager.getClassLoader(classPathId); Thread.currentThread().setContextClassLoader(classLoader); bean = (HermesAdminFactory) classLoader.loadClass(config.getClassName()).newInstance(); } catch (Throwable e) { cat.error(e.getMessage(), e); } try { if (config.getProperties() == null) { try { config.setProperties(HermesBrowser.getBrowser().getConfigDAO().createPropertySet()); } catch (HermesException ex) { throw new HermesRuntimeException(ex); } } propertyTableModel = new PropertySetTableModel(bean, config.getProperties(), new HashSet()); propertyTable.setModel(propertyTableModel); updateCellEditor(); if (propertyTableModel.getProperties().size() == 0) { addItem.setEnabled(false); removeItem.setEnabled(false); } } catch (Throwable ex) { cat.error(ex.getMessage(), ex); } propertyTableModel.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent arg0) { dialog.setDirty(); } }); }
From source file:com.google.gdt.eclipse.designer.util.GwtInvocationEvaluatorInterceptor.java
/** * Tweaks arguments to fix know problem cases. *///from w ww . j a va2s . c om private void fixArguments(Class<?> clazz, Constructor<?> constructor, Object[] arguments) throws Exception { if (clazz.getName().equals("com.google.gwt.user.client.ui.Tree")) { String signature = ReflectionUtils.getConstructorSignature(constructor); if (signature.equals("<init>(com.google.gwt.user.client.ui.TreeImages)")) { if (arguments[0] == null) { arguments[0] = ScriptUtils.evaluate(clazz.getClassLoader(), CodeUtils.getSource("import com.google.gwt.core.client.GWT;", "import com.google.gwt.user.client.ui.*;", "return GWT.create(TreeImages);")); } } } // prevent "null" as "cell" in CellList if (clazz.getName().equals("com.google.gwt.user.cellview.client.CellList")) { String signature = ReflectionUtils.getConstructorSignature(constructor); if (signature.equals("<init>(com.google.gwt.cell.client.Cell)")) { if (arguments[0] == null) { ClassLoader classLoader = clazz.getClassLoader(); Class<?> classTextCell = classLoader.loadClass("com.google.gwt.cell.client.TextCell"); arguments[0] = classTextCell.newInstance(); } } } }
From source file:info.sargis.eventbus.config.EventBusHandlerBeanDefinitionParser.java
@SuppressWarnings("unchecked") protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader) { String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE); String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE); try {//from w w w. ja v a 2s .co m if ("annotation".equals(filterType)) { return new AnnotationTypeFilter((Class<Annotation>) classLoader.loadClass(expression)); } else if ("assignable".equals(filterType)) { return new AssignableTypeFilter(classLoader.loadClass(expression)); } else if ("regex".equals(filterType)) { return new RegexPatternTypeFilter(Pattern.compile(expression)); } else if ("custom".equals(filterType)) { Class filterClass = classLoader.loadClass(expression); if (!TypeFilter.class.isAssignableFrom(filterClass)) { throw new IllegalArgumentException( "Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression); } return (TypeFilter) BeanUtils.instantiateClass(filterClass); } else { throw new IllegalArgumentException("Unsupported filter type: " + filterType); } } catch (ClassNotFoundException ex) { throw new FatalBeanException("Type filter class not found: " + expression, ex); } }
From source file:com.haulmont.cuba.desktop.sys.DesktopExternalUIComponentsSource.java
protected Class loadWindowLoader(Element rootElement, String loaderElem) { ClassLoader classLoader = App.class.getClassLoader(); Element elem = rootElement.element(loaderElem); if (elem == null) { return null; }// w w w.ja v a2 s .c om String loaderClass = elem.element("class").getStringValue(); try { Class clazz = classLoader.loadClass(loaderClass); if (loaders.get(loaderElem).isAssignableFrom(clazz)) { //noinspection unchecked return clazz; } log.warn("Class {} is not suitable as {}", loaderClass, loaderElem); } catch (ClassNotFoundException e) { log.warn("Unable to load window loader class: {}", loaderClass); } return null; }
From source file:com.qmetry.qaf.automation.ui.selenium.SeleniumCommandProcessor.java
/** * @param listenerClasses/*from w w w . j a va 2s. com*/ */ @SuppressWarnings("unchecked") public void addListener(String... listenerClasses) { if (null != listenerClasses) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); for (String listenerClass : listenerClasses) { try { if (StringUtils.isEmpty(listenerClass)) { continue; } Class<SeleniumCommandListener> cls = (Class<SeleniumCommandListener>) loader .loadClass(listenerClass); SeleniumCommandListener listener = cls.newInstance(); commandListeners.add(listener); } catch (Throwable e) { System.err.println("unable to register" + listenerClass + " as SeleniumCommandListener: " + e.getMessage()); } } } }
From source file:com.google.gdt.eclipse.designer.model.widgets.UIObjectInfo.java
/** * Call enter() as if this UI was create as result of call from JavaScript. *///from w w w . j av a 2 s.c om private void call_Impl_enter() { if (isRoot()) { try { ClassLoader classLoader = JavaInfoUtils.getClassLoader(this); Class<?> class_Impl = classLoader.loadClass("com.google.gwt.core.client.impl.Impl"); ReflectionUtils.invokeMethod(class_Impl, "enter()"); } catch (Throwable e) { } } }
From source file:com.google.gdt.eclipse.designer.model.widgets.UIObjectInfo.java
/** * Call exit() as if this UI was create as result of call from JavaScript. *//*w w w.j av a 2 s .c om*/ private void call_Impl_exit() { if (isRoot()) { try { ClassLoader classLoader = JavaInfoUtils.getClassLoader(this); Class<?> class_Impl = classLoader.loadClass("com.google.gwt.core.client.impl.Impl"); ReflectionUtils.invokeMethod(class_Impl, "exit(boolean)", true); } catch (Throwable e) { } } }
From source file:it.cnr.icar.eric.client.ui.common.ReferenceAssociation.java
public void setReferenceAttributeOnSourceObject() throws JAXRException { String referenceAttribute = this.getReferenceAttribute(); //Now use Refelection API to add target to src try {/*from w ww . j a va 2 s. c o m*/ Class<? extends RegistryObject> srcClass = src.getClass(); Class<?> targetClass = target.getClass(); Class<?> registryObjectClass = null; String targetInterfaceName = targetClass.getName(); targetInterfaceName = targetInterfaceName.substring(targetInterfaceName.lastIndexOf(".") + 1); if (targetInterfaceName.endsWith("Impl")) { //Remove Impl suffix for JAXR provider Impl classes targetInterfaceName = targetInterfaceName.substring(0, targetInterfaceName.length() - 4); } targetInterfaceName = "javax.xml.registry.infomodel." + targetInterfaceName; ClassLoader classLoader = srcClass.getClassLoader(); try { targetClass = classLoader.loadClass(targetInterfaceName); registryObjectClass = classLoader.loadClass("javax.xml.registry.infomodel.RegistryObject"); } catch (ClassNotFoundException e) { throw new JAXRException("No JAXR interface found by name " + targetInterfaceName); } @SuppressWarnings("static-access") String suffix = UIUtility.getInstance().initCapString(referenceAttribute); Method method = null; Class<?>[] paramTypes = new Class[1]; //See if there is a simple attribute of this name using type of targetObject try { paramTypes[0] = targetClass; method = srcClass.getMethod("set" + suffix, paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = false; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } //See if there is a simple attribute of this name using base type RegistryObject try { paramTypes[0] = registryObjectClass; method = srcClass.getMethod("set" + suffix, paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = false; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } //See if there is a addCXXX method for suffix of XXX ending in "s" for plural if (suffix.endsWith("s")) { suffix = suffix.substring(0, suffix.length() - 1); } try { paramTypes[0] = targetClass; method = srcClass.getMethod("add" + suffix, paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = true; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } //See if there is a addCXXX method for suffix of XXX ending in "es" for plural if (suffix.endsWith("e")) { suffix = suffix.substring(0, suffix.length() - 1); } try { paramTypes[0] = targetClass; method = srcClass.getMethod("add" + suffix, paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = true; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } //Special case while adding child organization to an organization if (src instanceof Organization && target instanceof Organization) { try { paramTypes[0] = targetClass; method = srcClass.getMethod("addChildOrganization", paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = true; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } } throw new JAXRException("No method found for reference attribute " + referenceAttribute + " for src object of type " + srcClass.getName()); } catch (IllegalArgumentException e) { throw new JAXRException(e); } catch (InvocationTargetException e) { throw new JAXRException(e.getCause()); } catch (ExceptionInInitializerError e) { throw new JAXRException(e); } }
From source file:org.jsonschema2pojo.integration.EnumIT.java
@Test public void enumWithUppercaseProperty() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { ClassLoader resultsClassLoader = schemaRule .generateAndCompile("/schema/enum/enumWithUppercaseProperty.json", "com.example"); resultsClassLoader.loadClass("com.example.EnumWithUppercaseProperty"); resultsClassLoader.loadClass("com.example.EnumWithUppercaseProperty$TimeFormat"); }