private void startStores(Properties properties) { String definitionStoreClassName = properties.getProperty(DEFINITION_STORE_CLASS); String contentStoreClassName = properties.getProperty(CONTENT_STORE_CLASS); // start definition store try { Class<?> definitionStoreClass = Class.forName(definitionStoreClassName); definitionStore = (MeemStoreDefinitionStore) definitionStoreClass.newInstance(); } catch (Exception e) { logger.log(Level.INFO, "Exception while starting MeemStoreDefinitionStore", e); } if (definitionStore != null) definitionStore.configure(this, properties); // start content store try { Class<?> contentStoreClass = Class.forName(contentStoreClassName); contentStore = (MeemStoreContentStore) contentStoreClass.newInstance(); } catch (Exception e) { logger.log(Level.INFO, "Exception while starting MeemStoreContentStore", e); } if (contentStore != null) contentStore.configure(this, properties); }
static { classNamesToConnectionTesters.put( C3P0Defaults.connectionTesterClassName(), C3P0Defaults.connectionTester()); String userManagementCoordinator = C3P0ConfigUtils.getPropsFileConfigProperty(MC_PARAM); if (userManagementCoordinator != null) { try { mc = (ManagementCoordinator) Class.forName(userManagementCoordinator).newInstance(); } catch (Exception e) { if (logger.isLoggable(MLevel.WARNING)) logger.log( MLevel.WARNING, "Could not instantiate user-specified ManagementCoordinator " + userManagementCoordinator + ". Using NullManagementCoordinator (c3p0 JMX management disabled!)", e); mc = new NullManagementCoordinator(); } } else { try { Class.forName("java.lang.management.ManagementFactory"); mc = (ManagementCoordinator) Class.forName("com.mchange.v2.c3p0.management.ActiveManagementCoordinator") .newInstance(); } catch (Exception e) { if (logger.isLoggable(MLevel.INFO)) logger.log( MLevel.INFO, "jdk1.5 management interfaces unavailable... JMX support disabled.", e); mc = new NullManagementCoordinator(); } } }
public static void register(String crClassName, String dmClassName) { Class dmClass; try { dmClass = Class.forName(dmClassName); } catch (java.lang.ClassNotFoundException e) { System.out.println("Error loading dm " + dmClassName); return; } Critic cr = (Critic) _singletonCritics.get(crClassName); if (cr == null) { Class crClass; try { crClass = Class.forName(crClassName); } catch (java.lang.ClassNotFoundException e) { System.out.println("Error loading cr " + crClassName); return; } try { cr = (Critic) crClass.newInstance(); } catch (java.lang.IllegalAccessException e) { System.out.println("Error instancating cr " + crClassName); return; } catch (java.lang.InstantiationException e) { System.out.println("Error instancating cr " + crClassName); return; } _singletonCritics.put(crClassName, cr); addCritic(cr); } register(cr, dmClass); }
public static Class getNestedPropertyType(DynaClass bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException, NoSuchFieldException { // Resolve nested references while (resolver.hasNested(name)) { String next = resolver.next(name); if (resolver.isIndexed(next) || resolver.isMapped(next)) { String property = resolver.getProperty(next); Class<?> clazz = Class.forName(bean.getName()); Class<?> detectTypeParameter = detectTypeParameter(clazz, property, resolver.isIndexed(name) ? 0 : 1); bean = WrapDynaClass.createDynaClass(detectTypeParameter); return getNestedPropertyType(bean, resolver.remove(name)); } DynaProperty db = bean.getDynaProperty(next); bean = WrapDynaClass.createDynaClass(db.getType()); name = resolver.remove(name); } if (resolver.isMapped(name) || resolver.isIndexed(name)) { String property = resolver.getProperty(name); Class<?> clazz = Class.forName(bean.getName()); return detectTypeParameter(clazz, property, resolver.isIndexed(name) ? 0 : 1); } Class<?> type = bean.getDynaProperty(name).getType(); return type; }
// 构造一个tri-trainer分类器。 public Tritrainer( String classifier, String trainingIns_File, String testIns_File, double precentage) { try { this.classifier1 = (Classifier) Class.forName(classifier).newInstance(); this.classifier2 = (Classifier) Class.forName(classifier).newInstance(); this.classifier3 = (Classifier) Class.forName(classifier).newInstance(); Instances trainingInstances = Util.getInstances(trainingIns_File); // 将trainIns_File按照precentage和(1-precentage)的比例切割成labeledIns和unlabeledIns; int length = trainingInstances.numInstances(); int i = new Double(length * precentage).intValue(); labeledIns = new Instances(trainingInstances, 0); for (int j = 0; j < i; j++) { labeledIns.add(trainingInstances.firstInstance()); trainingInstances.delete(0); } unlabeledIns = trainingInstances; testIns = Util.getInstances(testIns_File); Init(); } catch (Exception e) { } }
protected Method findBaseAccessor(Class clazz, Method accessor) { Method baseAccessor = null; if (clazz.getName().contains("$$EnhancerByCGLIB$$")) { try { baseAccessor = Thread.currentThread() .getContextClassLoader() .loadClass(clazz.getName().substring(0, clazz.getName().indexOf("$$"))) .getMethod(accessor.getName(), accessor.getParameterTypes()); } catch (Exception ex) { LOG.debug(ex.getMessage(), ex); } } else if (clazz.getName().contains("$$_javassist")) { try { baseAccessor = Class.forName(clazz.getName().substring(0, clazz.getName().indexOf("_$$"))) .getMethod(accessor.getName(), accessor.getParameterTypes()); } catch (Exception ex) { LOG.debug(ex.getMessage(), ex); } // in hibernate4.3.7,because javassist3.18.1's class name generate rule is '_$$_jvst'+... } else if (clazz.getName().contains("$$_jvst")) { try { baseAccessor = Class.forName(clazz.getName().substring(0, clazz.getName().indexOf("_$$"))) .getMethod(accessor.getName(), accessor.getParameterTypes()); } catch (Exception ex) { LOG.debug(ex.getMessage(), ex); } } else { return accessor; } return baseAccessor; }
public void initStax(String infName, String outfName) { try { initStax( (XMLInputFactory) Class.forName(infName).newInstance(), (XMLOutputFactory) Class.forName(outfName).newInstance()); } catch (Exception e) { throw new RuntimeException(e); } }
private Connection getSYBASEConnection() { try { Class.forName("com.sybase.jdbc2.jdbc.SybDriver"); return DriverManager.getConnection("jdbc:sybase:Tds:fe-test:2048/feDB", "sa", null); } catch (Exception e) { e.printStackTrace(); return null; } }
private Connection getSOLIDConnection() { try { Class.forName("solid.jdbc.SolidDriver"); return DriverManager.getConnection("jdbc:solid://nms-clienttest1:1313/dba/dba", "dba", "dba"); } catch (Exception e) { e.printStackTrace(); return null; } }
private Connection getTIMESTENConnection() { try { Class.forName("com.timesten.jdbc.TimesTenDriver"); return DriverManager.getConnection("jdbc:timesten:direct:WebNmsDB", "root", null); } catch (Exception e) { e.printStackTrace(); return null; } }
private Connection getMYSQLConnection() { try { Class.forName("org.gjt.mm.mysql.Driver"); return DriverManager.getConnection("jdbc:mysql://localhost/WebNmsDB", "root", null); } catch (Exception e) { e.printStackTrace(); return null; } }
private Connection getORACLEConnection() { try { Class.forName("oracle.jdbc.driver.OracleDriver"); return DriverManager.getConnection( "jdbc:oracle:thin:@kernel-win:1521:oracle", "BFW3", "BFW3"); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Returns either Consumes.class or ConsumeMime.class (old version) * * @return */ public static Class<?> getConsumesClass() { try { return Class.forName("javax.ws.rs.Consumes"); } catch (ClassNotFoundException e) { try { return Class.forName("javax.ws.rs.ConsumeMime"); } catch (ClassNotFoundException e1) { throw new RuntimeException(e1); } } }
// ------------------------------------------------------------------------------------------------ // 描述: // 设计: Skyline(2001.12.29) // 实现: Skyline // 修改: // ------------------------------------------------------------------------------------------------ public JFunctionStub getFunctionByID(String ID, Object OwnerObject) { IFunction IF = null; JFunctionStub FS = null; String FT; try { for (int i = 0; i < FunctionList.size(); i++) { FS = (JFunctionStub) FunctionList.get(i); // System.out.println(FS.FunctionID); FT = FS.FunctionID + "_"; if (FS.FunctionID.equals(ID) || FT.equals(ID)) { if (FS.Function == null) { FS.FunctionClass = Class.forName(FS.ClassName); FS.Function = (IFunction) FS.FunctionClass.newInstance(); FS.Function.InitFunction(FS); } /* else { // modify by liukun 找到了就直接返回吧 20100715 return FS; } */ // if (OwnerObject != null && OwnerObject instanceof Hashtable) { Hashtable OTable = (Hashtable) OwnerObject; JFunctionStub fs = (JFunctionStub) OTable.get(ID); if (fs == null) { fs = new JFunctionStub(); fs.ClassName = FS.ClassName; fs.FunctionClass = FS.FunctionClass; fs.FunctionID = FS.FunctionID; OTable.put(ID, fs); } if (fs.Function == null) { fs.FunctionClass = Class.forName(FS.ClassName); fs.Function = (IFunction) FS.FunctionClass.newInstance(); fs.Function.InitFunction(FS); } FS = fs; } else { /** * 如果不在用户列表中则需要重新初始化函数 不能直接用系统缓存因为系统缓存只在登录时初始 这样对于像BB类函数,缓冲坐标的行为就可能会出错(中间修改过行列) modified * by hufeng 2007.11.20 */ FS.Function = (IFunction) FS.FunctionClass.newInstance(); FS.Function.InitFunction(FS); } return FS; } } } catch (Exception e) { e.printStackTrace(); } return null; }
/** Performs tasks to resolve the lazy instantiation. */ private synchronized void init() { if (!initialized) { // Mimic the behavior of XStream's JVM class String vendor = System.getProperty("java.vm.vendor"); float version = 1.3f; try { version = Float.parseFloat(System.getProperty("java.version").substring(0, 3)); } catch (NumberFormatException nfe) { // Keep the default } Class unsafe = null; try { unsafe = Class.forName("sun.misc.Unsafe", false, getClass().getClassLoader()); } catch (ClassNotFoundException cnfe) { // Keep the default } ReflectionProvider reflectionProvider = null; if ((vendor.contains("Sun") || vendor.contains("Oracle") || vendor.contains("Apple") || vendor.contains("Hewlett-Packard") || vendor.contains("IBM") || vendor.contains("Blackdown")) && version >= 1.4f && unsafe != null) { try { reflectionProvider = (ReflectionProvider) Class.forName( "com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider", false, getClass().getClassLoader()) .newInstance(); } catch (InstantiationException ie) { reflectionProvider = new PureJavaReflectionProvider(); } catch (IllegalAccessException iae) { reflectionProvider = new PureJavaReflectionProvider(); } catch (ClassNotFoundException cnfe) { reflectionProvider = new PureJavaReflectionProvider(); } } else { reflectionProvider = new PureJavaReflectionProvider(); } HierarchicalStreamDriver driver = new DomDriver(); xs = new XStream(reflectionProvider, driver); xs.setMarshallingStrategy(new LockssReferenceByXPathMarshallingStrategy(lockssContext)); xs.registerConverter(new LockssDateConverter()); initialized = true; } }
private static void netxsurgery() throws Exception { /* Force off NetX codebase classloading. */ Class<?> nxc; try { nxc = Class.forName("net.sourceforge.jnlp.runtime.JNLPClassLoader"); } catch (ClassNotFoundException e1) { try { nxc = Class.forName("netx.jnlp.runtime.JNLPClassLoader"); } catch (ClassNotFoundException e2) { throw (new Exception("No known NetX on classpath")); } } ClassLoader cl = MainFrame.class.getClassLoader(); if (!nxc.isInstance(cl)) { throw (new Exception("Not running from a NetX classloader")); } Field cblf, lf; try { cblf = nxc.getDeclaredField("codeBaseLoader"); lf = nxc.getDeclaredField("loaders"); } catch (NoSuchFieldException e) { throw (new Exception("JNLPClassLoader does not conform to its known structure")); } cblf.setAccessible(true); lf.setAccessible(true); Set<Object> loaders = new HashSet<Object>(); Stack<Object> open = new Stack<Object>(); open.push(cl); while (!open.empty()) { Object cur = open.pop(); if (loaders.contains(cur)) continue; loaders.add(cur); Object curl; try { curl = lf.get(cur); } catch (IllegalAccessException e) { throw (new Exception("Reflection accessibility not available even though set")); } for (int i = 0; i < Array.getLength(curl); i++) { Object other = Array.get(curl, i); if (nxc.isInstance(other)) open.push(other); } } for (Object cur : loaders) { try { cblf.set(cur, null); } catch (IllegalAccessException e) { throw (new Exception("Reflection accessibility not available even though set")); } } }
/** * @param dataSourceStub JDataSourceStub * @return JConnection * @throws Exception */ protected static JConnection createConnection(JDataSourceStub dataSourceStub) throws Exception { JConnection jconn = null; if (dataSourceStub.DBClass == null) { dataSourceStub.DBClass = Class.forName(dataSourceStub.classname); } if (dataSourceStub.NAClass == null) { dataSourceStub.NAClass = Class.forName(dataSourceStub.dbclass); } if (dataSourceStub.NAClass != null) { jconn = (JConnection) dataSourceStub.NAClass.newInstance(); } if (jconn != null) jconn.setDataBaseType(dataSourceStub.DataBaseType); return jconn; }
private static boolean replaceServerProperties(XMLServer server) { Class<?> serverclazz; try { serverclazz = Class.forName(server.getClazz()); } catch (ClassNotFoundException e) { try { serverclazz = Class.forName("com.ingby.socbox.bischeck.servers." + server.getClazz()); } catch (Exception ret) { return false; } } java.util.Properties defaultproperties = null; Method method; try { method = serverclazz.getMethod("getServerProperties"); defaultproperties = (java.util.Properties) method.invoke(null); } catch (Exception ret) { return false; } Iterator<XMLProperty> iter = server.getProperty().iterator(); // Update the default properties with what is currently set // in the server property while (iter.hasNext()) { XMLProperty xmlprop = iter.next(); if (defaultproperties.containsKey(xmlprop.getKey())) defaultproperties.setProperty(xmlprop.getKey(), xmlprop.getValue()); } // Create a new server property list List<XMLProperty> serverproperty = new ArrayList<XMLProperty>(); Iterator<Object> keyiter = defaultproperties.keySet().iterator(); while (keyiter.hasNext()) { String key = (String) keyiter.next(); XMLProperty xmlprop = new XMLProperty(); xmlprop.setKey(key); xmlprop.setValue((String) defaultproperties.get(key)); serverproperty.add(xmlprop); } server.getProperty().clear(); server.getProperty().addAll(serverproperty); return true; }
private static Class<?> type(Location location) { try { return Class.forName(location.getClassName()); } catch (Exception e) { throw new RuntimeException(e); } }
/** For internal use only. */ private static Object makeDerivedWrapper(Element elt, String baseTypeName) { synchronized (DOMUtils.getDOMLock(elt)) { QName typeName = XArchUtils.getXSIType(elt); if (typeName == null) { return null; } else { if (!DOMUtils.hasXSIType( elt, "http://www.ics.uci.edu/pub/arch/xArch/changesets.xsd", baseTypeName)) { try { String packageTitle = XArchUtils.getPackageTitle(typeName.getNamespaceURI()); String packageName = XArchUtils.getPackageName(packageTitle); String implName = XArchUtils.getImplName(packageName, typeName.getName()); Class c = Class.forName(implName); java.lang.reflect.Constructor con = c.getConstructor(new Class[] {Element.class}); Object o = con.newInstance(new Object[] {elt}); return o; } catch (Exception e) { // Lots of bad things could happen, but this // is OK, because this is best-effort anyway. } } return null; } } }
private static Future<Void> startDeletionThread(@NotNull final File... tempFiles) { final RunnableFuture<Void> deleteFilesTask = new FutureTask<Void>( new Runnable() { @Override public void run() { final Thread currentThread = Thread.currentThread(); final int priority = currentThread.getPriority(); currentThread.setPriority(Thread.MIN_PRIORITY); try { for (File tempFile : tempFiles) { delete(tempFile); } } finally { currentThread.setPriority(priority); } } }, null); try { // attempt to execute on pooled thread final Class<?> aClass = Class.forName("com.intellij.openapi.application.ApplicationManager"); final Method getApplicationMethod = aClass.getMethod("getApplication"); final Object application = getApplicationMethod.invoke(null); final Method executeOnPooledThreadMethod = application.getClass().getMethod("executeOnPooledThread", Runnable.class); executeOnPooledThreadMethod.invoke(application, deleteFilesTask); } catch (Exception ignored) { new Thread(deleteFilesTask, "File deletion thread").start(); } return deleteFilesTask; }
protected static DeviceImpl importFromBEncodedMapStatic(DeviceManagerImpl manager, Map map) throws IOException { String impl = ImportExportUtils.importString(map, "_impl"); if (impl.startsWith(".")) { impl = MY_PACKAGE + impl; } try { Class<DeviceImpl> cla = (Class<DeviceImpl>) Class.forName(impl); Constructor<DeviceImpl> cons = cla.getDeclaredConstructor(DeviceManagerImpl.class, Map.class); cons.setAccessible(true); return (cons.newInstance(manager, map)); } catch (Throwable e) { Debug.out("Can't construct device for " + impl, e); throw (new IOException("Construction failed: " + Debug.getNestedExceptionMessage(e))); } }
public static void main(java.lang.String[] args) { String className = null; try { System.err.println("logging is done using log4j."); final ICQMessagingTest_Applet applet = new ICQMessagingTest_Applet(); className = cfg.REQPARAM_MESSAGING_NETWORK_IMPL_CLASS_NAME.trim(); CAT.info("Instantiating class \"" + className + "\"..."); try { applet.plugin = (MessagingNetwork) Class.forName(className).newInstance(); applet.plugin.init(); } catch (Throwable tr) { CAT.error("ex in main", tr); System.exit(1); } java.awt.Frame frame = new java.awt.Frame("MessagingTest"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { applet.quit(); } }); frame.add("Center", applet); frame.setSize(800, 650); frame.setLocation(150, 100); applet.init(); frame.show(); frame.invalidate(); frame.validate(); applet.start(); } catch (Throwable tr) { CAT.error("exception", tr); System.exit(1); } }
private static boolean isEmbeddable(String className) { try { return Class.forName(className).isAnnotationPresent(Embeddable.class); } catch (ClassNotFoundException e) { return false; } }
/** * Force initialization of the static members. As of Java 5, referencing a class doesn't force it * to initialize. Since this class requires that the classes be initialized to declare their * comparators, we force that initialization to happen. * * @param cls the class to initialize */ private static void forceInit(Class<?> cls) { try { Class.forName(cls.getName(), true, cls.getClassLoader()); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Can't initialize class " + cls, e); } }
public static void main(String[] args) { // read class name from command line args or user input String name; if (args.length > 0) name = args[0]; else { Scanner in = new Scanner(System.in); System.out.println("Enter class name (e.g. java.util.Date): "); name = in.next(); } try { // print class name and superclass name (if != Object) Class cl = Class.forName(name); Class supercl = cl.getSuperclass(); String modifiers = Modifier.toString(cl.getModifiers()); if (modifiers.length() > 0) System.out.print(modifiers + " "); System.out.print("class " + name); if (supercl != null && supercl != Object.class) System.out.print(" extends " + supercl.getName()); System.out.print("\n{\n"); printConstructors(cl); System.out.println(); printMethods(cl); System.out.println(); printFields(cl); System.out.println("}"); } catch (ClassNotFoundException e) { e.printStackTrace(); } System.exit(0); }
/** JNDI object factory so the proxy can be used as a resource. */ public Object getObjectInstance( Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Reference ref = (Reference) obj; String api = null; String url = null; String user = null; String password = null; for (int i = 0; i < ref.size(); i++) { RefAddr addr = ref.get(i); String type = addr.getType(); String value = (String) addr.getContent(); if (type.equals("type")) api = value; else if (type.equals("url")) url = value; else if (type.equals("user")) setUser(value); else if (type.equals("password")) setPassword(value); } if (url == null) throw new NamingException("`url' must be configured for HessianProxyFactory."); // XXX: could use meta protocol to grab this if (api == null) throw new NamingException("`type' must be configured for HessianProxyFactory."); ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class apiClass = Class.forName(api, false, loader); return create(apiClass, url); }
private /*synchronized*/ StructureType assignStructureType(String structType) throws VisualizerLoadException { if (debug) System.out.println("In assignStructureType with " + structType); // Handle objects whose constructors require args separately if ((structType.toUpperCase().compareTo("BAR") == 0) || (structType.toUpperCase().compareTo("SCAT") == 0)) return (new BarScat(structType.toUpperCase())); else if ((structType.toUpperCase().compareTo("GRAPH") == 0) || (structType.toUpperCase().compareTo("NETWORK") == 0)) return (new Graph_Network(structType.toUpperCase())); else { // Constructor for object does not require args try { return ((StructureType) ((Class.forName(insure_text_case_correct_for_legacy_scripts(structType))) .newInstance())); } catch (InstantiationException e) { System.out.println(e); throw (new VisualizerLoadException(structType + " is invalid structure type")); } catch (IllegalAccessException e) { System.out.println(e); throw (new VisualizerLoadException(structType + " is invalid structure type")); } catch (ClassNotFoundException e) { System.out.println(e); throw (new VisualizerLoadException(structType + " is invalid structure type")); } } }
public static Connection connect(String url, String dbuser, String dbpass) throws SQLException, ClassNotFoundException { Connection conn; Class.forName("org.postgis.DriverWrapper"); conn = DriverManager.getConnection(url, dbuser, dbpass); return conn; }
public static Skill createSkill(String sName, Entity ENT, int lev) { Ability A = null; Class C = null; sName = Utility.getProperClassName(sName); try { C = Class.forName(sName); A = (Ability) C.newInstance(); } catch (Exception e) { return null; } catch (Throwable t) { return null; } try { Skill Sk = (Skill) A; Sk.init(ENT, lev); return Sk; } catch (Exception e) { return null; } catch (Throwable t) { return null; } }