private void showFragment(Class<?> paramClass, String paramString, boolean addToBackStack) { Log.d(TAG, "showFragment for " + paramClass); FragmentManager localFragmentManager = getSupportFragmentManager(); Fragment localFragment = localFragmentManager.findFragmentById(R.id.fragment_container); if ((localFragment == null) || (!paramClass.isInstance(localFragment))) { try { Log.d(TAG, "replacing fragments"); if (addToBackStack) { localFragment = (Fragment) paramClass.newInstance(); localFragmentManager .beginTransaction() .add(R.id.fragment_container, localFragment) .addToBackStack("growth_stack") .commit(); } else { localFragment = (Fragment) paramClass.newInstance(); localFragmentManager .beginTransaction() .replace(R.id.fragment_container, localFragment) .commitAllowingStateLoss(); } } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } }
/** Get new PHYSICAL connection, to be managed by a connection manager. */ public XAConnection getXAConnection() throws SQLException { // Comment out before public release: System.err.print("Executing " + getClass().getName() + ".getXAConnection()..."); try { Class.forName(driver).newInstance(); } catch (ClassNotFoundException e) { throw new SQLException("Error opening connection: " + e.getMessage()); } catch (IllegalAccessException e) { throw new SQLException("Error opening connection: " + e.getMessage()); } catch (InstantiationException e) { throw new SQLException("Error opening connection: " + e.getMessage()); } JDBCConnection connection = (JDBCConnection) DriverManager.getConnection(url, connProperties); // Comment out before public release: System.err.print("New phys: " + connection); JDBCXAResource xaResource = new JDBCXAResource(connection, this); JDBCXAConnectionWrapper xaWrapper = new JDBCXAConnectionWrapper(connection, xaResource, connectionDefaults); JDBCXAConnection xaConnection = new JDBCXAConnection(xaWrapper, xaResource); xaWrapper.setPooledConnection(xaConnection); return xaConnection; }
@Override public View getView(int position, View convertView, ViewGroup parent) { K holder = null; if (convertView == null) { convertView = LayoutInflater.from(mContext).inflate(getItemLayout(), parent, false); try { holder = classType.newInstance(); Log.i("INFO", "Complete"); } catch (InstantiationException e) { Log.i("INFO", "InstantiationException"); e.printStackTrace(); } catch (IllegalAccessException e) { Log.i("INFO", "IllegalAccessException"); e.printStackTrace(); } initViewHolder(convertView, holder); convertView.setTag(holder); } else { holder = (K) convertView.getTag(); } T entity = mEntities.get(position); setDataIntoView(holder, entity); return convertView; }
public void doArtefactConfiguration() { if (!pluginBean.isReadableProperty(ARTEFACTS)) { return; } List l = (List) plugin.getProperty(ARTEFACTS); for (Object artefact : l) { if (artefact instanceof Class) { Class artefactClass = (Class) artefact; if (ArtefactHandler.class.isAssignableFrom(artefactClass)) { try { application.registerArtefactHandler((ArtefactHandler) artefactClass.newInstance()); } catch (InstantiationException e) { LOG.error("Cannot instantiate an Artefact Handler:" + e.getMessage(), e); } catch (IllegalAccessException e) { LOG.error( "The constructor of the Artefact Handler is not accessible:" + e.getMessage(), e); } } else { LOG.error("This class is not an ArtefactHandler:" + artefactClass.getName()); } } else { if (artefact instanceof ArtefactHandler) { application.registerArtefactHandler((ArtefactHandler) artefact); } else { LOG.error( "This object is not an ArtefactHandler:" + artefact + "[" + artefact.getClass().getName() + "]"); } } } }
static void testReflectionTest3() { try { String imei = taintedString(); Class c = Class.forName("de.ecspride.ReflectiveClass"); Object o = c.newInstance(); Method m = c.getMethod("setIme" + "i", String.class); m.invoke(o, imei); Method m2 = c.getMethod("getImei"); String s = (String) m2.invoke(o); assert (getTaint(s) != 0); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public int getPrimaryID(String userName) { Connection koneksi = null; Statement stat = null; String str = ""; int iD = 0; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); koneksi = DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome"); System.out.println(koneksi); stat = koneksi.createStatement(); ResultSet hasil = stat.executeQuery("SELECT iD FROM loginInfo where userName='******'"); if (hasil.next()) iD = hasil.getInt(1); stat.close(); koneksi.close(); } catch (SQLException sqle) { str = "SQLException error"; } catch (ClassNotFoundException cnfe) { str = "ClassNotFoundException error"; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } System.out.println(str); return iD; }
public String checkUserOrEmailexit(String userName, String email) { Connection koneksi = null; Statement stat = null; String str = "Accepted"; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); koneksi = DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome"); System.out.println(koneksi); stat = koneksi.createStatement(); ResultSet hasil = stat.executeQuery( "SELECT userName, emailID FROM loginInfo WHERE userName='******' OR emailID='" + email + "';"); if (hasil.next()) str = "Rejected"; stat.close(); koneksi.close(); } catch (SQLException sqle) { str = "SQLException error"; } catch (ClassNotFoundException cnfe) { str = "ClassNotFoundException error"; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return str; }
public static void main(String... args) { try { Class<?> c = Class.forName("ConstructorTroubleToo"); // Method propagetes any exception thrown by the constructor // (including checked exceptions). if (args.length > 0 && args[0].equals("class")) { Object o = c.newInstance(); } else { Object o = c.getConstructor().newInstance(); } // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } catch (InstantiationException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } catch (NoSuchMethodException x) { x.printStackTrace(); } catch (InvocationTargetException x) { x.printStackTrace(); err.format("%n%nCaught exception: %s%n", x.getCause()); } }
/** * @param context * @param intent */ private void schuduleAlarm(Context context, Intent intent) { AlarmListener listener = null; try { Class<AlarmListener> cls = (Class<AlarmListener>) Class.forName("com.shephertz.app42.android.background.BackgroundAlarmListener"); try { listener = cls.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (listener != null) { if (intent.getAction() == null) { SharedPreferences prefs = context.getSharedPreferences(WakefulIntentService.Name, 0); prefs.edit().putLong(WakefulIntentService.LastAlarm, System.currentTimeMillis()).commit(); listener.sendBackgroundWork(context); } else { WakefulIntentService.scheduleAlarms(listener, context, true); } } }
@Before public void setUp() { try { Class.forName("com.intersys.jdbc.CacheDriver").newInstance(); } catch (InstantiationException ex) { System.out.print(ex.getMessage()); } catch (Exception ex) { System.out.print(ex.getMessage()); } CacheDataSource ds = new CacheDataSource(); try { ds.setURL("jdbc:Cache://192.168.1.172:56773/USER"); } catch (SQLException ex) { System.out.println(ex.getMessage()); } java.sql.Connection dbconn = null; try { dbconn = ds.getConnection("_SYSTEM", "SYS"); } catch (SQLException ex) { Logger.getLogger(DatabaseDAOTests.class.getName()).log(Level.SEVERE, null, ex); } try { db = CacheDatabase.getDatabase(dbconn); } catch (CacheException ex) { System.out.print(ex.getMessage()); } dbDao = new DatabaseDAO(dbconn, db); }
static { // API Level 11 is Build.VERSION_CODES.HONEYCOMB. // When right/left adjustment mode, outInsets uses touchableRegion to cut out IME rectangle. // Because only after API.11(HONEYCOMB) supports touchableRegion, filter it. InsetsCalculator tmpCalculator = null; if (Build.VERSION.SDK_INT >= 11) { // Try to create RegsionInsetsCalculator if the API level is high enough. try { Class<?> clazz = Class.forName( new StringBuilder(MozcView.class.getCanonicalName()) .append('$') .append("RegionInsetsCalculator") .toString()); tmpCalculator = InsetsCalculator.class.cast(clazz.newInstance()); } catch (ClassNotFoundException e) { MozcLog.e(e.getMessage(), e); } catch (IllegalArgumentException e) { MozcLog.e(e.getMessage(), e); } catch (IllegalAccessException e) { MozcLog.e(e.getMessage(), e); } catch (InstantiationException e) { MozcLog.e(e.getMessage(), e); } } if (tmpCalculator == null) { tmpCalculator = new DefaultInsetsCalculator(); } insetsCalculator = tmpCalculator; }
@Override public boolean connect() { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); String url = "jdbc:sqlserver://" + Config.DATABASE_IP + ":" + Config.DATABASE_PORT + ";databaseName=Narda"; conn = DriverManager.getConnection(url, Config.DATABASE_USERNAME, Config.DATABASE_PASSWORD); OrbitStamps.log(OrbitStamps.LOG_NOTICE, "HuddingeDataMapper: connection success!"); return true; } catch (ClassNotFoundException ex) { System.err.println(ex.getMessage()); } catch (IllegalAccessException ex) { System.err.println(ex.getMessage()); } catch (InstantiationException ex) { System.err.println(ex.getMessage()); } catch (SQLException ex) { System.err.println(ex.getMessage()); } OrbitStamps.log(OrbitStamps.LOG_NOTICE, "HuddingeDataMapper: connection failed!"); return false; }
/** * 画像のExif情報から回転角度を取得する * * <pre> * // Original code for Android 2.1(API Level 5 Later) * int rotation = 0; * try { * ExifInterface exif = new ExifInterface(fileName); * int orientation = exif.getAttributeInt( * ExifInterface.TAG_ORIENTATION, 1); * switch (orientation) { * case 6: * rotation = 90; * break; * } * } catch (IOException e) { * e.printStackTrace(); * } * </pre> * * @param fileName 画像のファイル名(フルパス) * @return 回転角度(0、90、180、270)※単位は度 */ public static int getRotation(String fileName) { int rotation = 0; try { Class<?> clazz = ExifInterface.class; Constructor<?> constructor = clazz.getConstructor(String.class); Object instance = constructor.newInstance(fileName); Method method = clazz.getMethod("getAttributeInt", String.class, int.class); if (method != null) { rotation = (Integer) method.invoke(instance, "Orientation"); } } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return rotation; }
@SuppressWarnings({"unchecked", "rawtypes"}) private Spell getSpellClass(int id, String name) { try { Object[] instanceArguments = new Object[] {id}; Class[] constructorArguments = new Class[] {int.class}; Class spellClass = Class.forName("com.ignoreourgirth.gary.oakmagic.spells." + name); Constructor spellConstructor = spellClass.getConstructor(constructorArguments); Object instancedClass = spellConstructor.newInstance(instanceArguments); Spell returnValue = (Spell) instancedClass; // OakMagic.log.info("Loaded: " + spellClass.getSimpleName()); return returnValue; } catch (ClassNotFoundException ex) { OakMagic.log.log(Level.SEVERE, ex.getMessage()); } catch (InstantiationException ex) { OakMagic.log.log(Level.SEVERE, ex.getMessage()); } catch (IllegalAccessException ex) { OakMagic.log.log(Level.SEVERE, ex.getMessage()); } catch (SecurityException ex) { OakMagic.log.log(Level.SEVERE, ex.getMessage()); } catch (NoSuchMethodException ex) { OakMagic.log.log(Level.SEVERE, ex.getMessage()); } catch (IllegalArgumentException ex) { OakMagic.log.log(Level.SEVERE, ex.getMessage()); } catch (InvocationTargetException ex) { OakMagic.log.log(Level.SEVERE, ex.getMessage()); } return null; }
public static synchronized void addAgentSelectorClass(Class newClass) throws IllegalArgumentException { try { AgentSelector newAlgorithm = (AgentSelector) newClass.newInstance(); // Make sure the interceptor isn't already in the list. List<AgentSelector> availableAgentSelectors = getAvailableAgentSelectors(); for (AgentSelector algorithm : availableAgentSelectors) { if (newAlgorithm.getClass().equals(algorithm.getClass())) { return; } } // Add in the new algorithm availableAgentSelectors.add(newAlgorithm); // Write out new class names. JiveGlobals.deleteProperty("agentSelector.classes"); for (int i = 0; i < availableAgentSelectors.size(); i++) { String cName = availableAgentSelectors.get(i).getClass().getName(); JiveGlobals.setProperty("agentSelector.classes." + i, cName); } } catch (IllegalAccessException e) { throw new IllegalArgumentException(e.getMessage()); } catch (InstantiationException e2) { throw new IllegalArgumentException(e2.getMessage()); } catch (ClassCastException e5) { throw new IllegalArgumentException("Class is not a AgentSelector"); } }
/** * The main function of your component. If no args are provided, then the CORBA object is not * bound to an SCA Domain or NamingService and can be run as a standard Java application. * * @param args * @generated */ public static void main(String[] args) { final Properties orbProps = new Properties(); // begin-user-code // TODO You may add extra startup code here, for example: // orbProps.put("com.sun.CORBA.giop.ORBFragmentSize", Integer.toString(fragSize)); // end-user-code try { Resource.start_component(SigGen.class, args, orbProps); } catch (InvalidObjectReference e) { e.printStackTrace(); } catch (NotFound e) { e.printStackTrace(); } catch (CannotProceed e) { e.printStackTrace(); } catch (InvalidName e) { e.printStackTrace(); } catch (ServantNotActive e) { e.printStackTrace(); } catch (WrongPolicy e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } // begin-user-code // TODO You may add extra shutdown code here // end-user-code }
protected ClientConnectionManager createClientConnectionManager() { final SchemeRegistry registry = SchemeRegistryFactory.createDefault(); ClientConnectionManager connManager = null; final HttpParams params = getParams(); ClientConnectionManagerFactory factory = null; final String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { try { final Class<?> clazz = Class.forName(className); factory = (ClientConnectionManagerFactory) clazz.newInstance(); } catch (final ClassNotFoundException ex) { throw new IllegalStateException("Invalid class name: " + className); } catch (final IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (final InstantiationException ex) { throw new InstantiationError(ex.getMessage()); } } if (factory != null) { connManager = factory.newInstance(params, registry); } else { connManager = new BasicClientConnectionManager(registry); } return connManager; }
/** * This method creates the constraint instance. * * @param constraintStructure the constraint's structure (bConstraint clss in blender 2.49). * @param ownerOMA the old memory address of the constraint's owner * @param influenceIpo the ipo curve of the influence factor * @param blenderContext the blender context * @throws BlenderFileException this exception is thrown when the blender file is somehow * corrupted */ protected Constraint createConstraint( Structure constraintStructure, Long ownerOMA, Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException { String constraintClassName = this.getConstraintClassName(constraintStructure, blenderContext); Class<? extends Constraint> constraintClass = constraintClasses.get(constraintClassName); if (constraintClass != null) { try { return (Constraint) constraintClass.getDeclaredConstructors()[0].newInstance( constraintStructure, ownerOMA, influenceIpo, blenderContext); } catch (IllegalArgumentException e) { throw new BlenderFileException(e.getLocalizedMessage(), e); } catch (SecurityException e) { throw new BlenderFileException(e.getLocalizedMessage(), e); } catch (InstantiationException e) { throw new BlenderFileException(e.getLocalizedMessage(), e); } catch (IllegalAccessException e) { throw new BlenderFileException(e.getLocalizedMessage(), e); } catch (InvocationTargetException e) { throw new BlenderFileException(e.getLocalizedMessage(), e); } } else { throw new BlenderFileException("Unknown constraint type: " + constraintClassName); } }
public String selectionQuery() { Connection koneksi = null; Statement stat = null; String str = ""; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); koneksi = DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome"); System.out.println(koneksi); stat = koneksi.createStatement(); ResultSet hasil = stat.executeQuery("SELECT * FROM loginInfo"); while (hasil.next()) { str = str + (hasil.getString(1)) + hasil.getString(2); } stat.close(); koneksi.close(); } catch (SQLException sqle) { str = "SQLException error"; } catch (ClassNotFoundException cnfe) { str = "ClassNotFoundException error"; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return str; }
public static void main(String args[]) { NumberFormat currency = NumberFormat.getCurrencyInstance(); final String DRIVER = "com.mysql.jdbc.Driver"; final String CONNECTION = "jdbc:mysql://localhost/AccountDatabase"; try { Class.forName(DRIVER).newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } // UNCOMMENT the lines below.sc try (Connection connection = DriverManager.getConnection(CONNECTION, "root", ""); java.sql.Statement statement = connection.createStatement(); ResultSet resultset = statement.executeQuery("select * from ACCOUNTS")) { while (resultset.next()) { System.out.println(resultset.getString("NAME")); System.out.print(", "); System.out.print(resultset.getString("ADDRESS")); System.out.print(" "); System.out.println(currency.format(resultset.getFloat("BALANCE"))); } } catch (SQLException e) { e.printStackTrace(); } }
public void addPasswordToDataBase(String password, int iD) { Connection koneksi = null; PreparedStatement pstmt = null; String str = ""; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); koneksi = DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome"); System.out.println("I am Here " + koneksi); String sql = "INSERT INTO loginPass(" + "iD," + "passWord) " + "VALUES(?,?)"; pstmt = koneksi.prepareStatement(sql); pstmt.setInt(1, iD); pstmt.setString(2, password); pstmt.executeUpdate(); System.out.println("Hello"); koneksi.close(); } catch (SQLException sqle) { str = "SQLException error"; } catch (ClassNotFoundException cnfe) { str = "ClassNotFoundException error"; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
public static void main(String[] args) { /* Use an appropriate Look and Feel */ try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } /* Turn off metal's use of bold fonts */ UIManager.put("swing.boldMetal", Boolean.FALSE); // Schedule a job for the event-dispatching thread: // adding TrayIcon. SwingUtilities.invokeLater( new Runnable() { public void run() { weather = new Wetter(); createAndShowGUI(); } }); }
/** * Creates the brain and launches if it is an agent. The brain class is given as a String. The * name argument is used to instantiate the name of the corresponding agent. If the gui flag is * true, a bean is created and associated to this agent. */ public void makeBrain(String className, String name, boolean gui, String behaviorFileName) { try { Class c; c = Utils.loadClass(className); myBrain = (Brain) c.newInstance(); myBrain.setBody(this); if (myBrain instanceof AbstractAgent) { String n = name; if (n == null) { n = getLabel(); } if (n == null) { n = getID(); } if (behaviorFileName != null) setBehaviorFileName(behaviorFileName); myBrain.init(); getStructure().getAgent().doLaunchAgent((AbstractAgent) myBrain, n, gui); } } catch (ClassNotFoundException ev) { System.err.println("Class not found :" + className + " " + ev); ev.printStackTrace(); } catch (InstantiationException e) { System.err.println("Can't instanciate ! " + className + " " + e); e.printStackTrace(); } catch (IllegalAccessException e) { System.err.println("illegal access! " + className + " " + e); e.printStackTrace(); } }
/** * @author ZhangXiang * @param args 2011-4-7 * @throws NoSuchMethodException * @throws InvocationTargetException * @throws SecurityException * @throws IllegalArgumentException */ public static void main(String[] args) throws IllegalArgumentException, SecurityException, InvocationTargetException, NoSuchMethodException { StringBuilder classStr = new StringBuilder("package dyclass;public class Foo{"); classStr.append("public void test(){"); classStr.append("System.out.println(\"Foo2\");}}"); JavaCompiler jc = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fileManager = jc.getStandardFileManager(null, null, null); Location location = StandardLocation.CLASS_OUTPUT; File[] outputs = new File[] {new File("D:/CodeProject/ToxinD/test-export/target/classes")}; try { fileManager.setLocation(location, Arrays.asList(outputs)); } catch (IOException e) { e.printStackTrace(); } JavaFileObject jfo = new JavaSourceFromString("dyclass.Foo", classStr.toString()); JavaFileObject[] jfos = new JavaFileObject[] {jfo}; Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(jfos); boolean b = jc.getTask(null, fileManager, null, null, null, compilationUnits).call(); if (b) { // 如果编译成功 try { Object c = Class.forName("dyclass.Foo").newInstance(); Class.forName("dyclass.Foo").getMethod("test").invoke(c); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException { try { ClassReader classReader = new ClassReader("com/asm/Before_Demo1"); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassAdapter ca = new AopClassAdapter(cw); classReader.accept(ca, ClassReader.SKIP_DEBUG); byte[] byteArray = cw.toByteArray(); MyClassLoader myClassLoader = new MyClassLoader(); Class<?> clazz = myClassLoader.myDefineClass(byteArray, "com.asm.Before_Demo1"); Method method = clazz.getMethod("sayHello"); method.invoke(clazz.newInstance()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * 获取状态栏高度 * * @param activity * @return */ public int getStatusHeight(Activity activity) { int statusHeight = 0; Rect localRect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect); statusHeight = localRect.top; if (0 == statusHeight) { Class<?> localClass; try { localClass = Class.forName("com.android.internal.R$dimen"); Object localObject = localClass.newInstance(); int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString()); statusHeight = activity.getResources().getDimensionPixelSize(i5); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } } return statusHeight; }
@Test public void testTimeSeriesAPIEntity() { InternalLog internalLog = new InternalLog(); Map<String, byte[]> map = new HashMap<String, byte[]>(); TestTimeSeriesAPIEntity apiEntity = new TestTimeSeriesAPIEntity(); EntityDefinition ed = null; try { ed = EntityDefinitionManager.getEntityByServiceName("TestTimeSeriesAPIEntity"); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } map.put("a", ByteUtil.intToBytes(12)); map.put("c", ByteUtil.longToBytes(123432432l)); map.put("cluster", new String("cluster4ut").getBytes()); map.put("datacenter", new String("datacenter4ut").getBytes()); internalLog.setQualifierValues(map); internalLog.setTimestamp(System.currentTimeMillis()); try { TaggedLogAPIEntity entity = HBaseInternalLogHelper.buildEntity(internalLog, ed); Assert.assertTrue(entity instanceof TestTimeSeriesAPIEntity); TestTimeSeriesAPIEntity tsentity = (TestTimeSeriesAPIEntity) entity; Assert.assertEquals("cluster4ut", tsentity.getTags().get("cluster")); Assert.assertEquals("datacenter4ut", tsentity.getTags().get("datacenter")); Assert.assertEquals(12, tsentity.getField1()); Assert.assertEquals(123432432l, tsentity.getField3()); } catch (Exception e) { e.printStackTrace(); } }
private Map<String, List<Object>> loadContextDatabase() { // context DB 생 Map<String, List<Object>> contextMap = new HashMap<String, List<Object>>(); log.d("pakage is " + pakagename); List<Class<?>> classlist = getFilterClasses(pakagename, ContextSchemable.class); try { ContextSchemable schemable; for (Class<?> clazz : classlist) { if (clazz.isEnum()) { // enum 타입 schemable = (ContextSchemable) clazz.getEnumConstants()[0]; // log.d("Type of enum: "+clazz.getSimpleName()); } else { // 그외 interface 타입 schemable = (ContextSchemable) clazz.newInstance(); // log.d("Type of class: "+clazz.getSimpleName()); } List<Object> list = schemable.getContextSchemaData(); if (list != null) { contextMap.put(schemable.getClass().getSimpleName(), list); } } } catch (InstantiationException e) { log.e(e.getMessage()); } catch (IllegalAccessException e) { log.e(e.getMessage()); } return contextMap; }
private static void callPluginApplicationOnCreate(PluginDescriptor pluginDescriptor) { Application application = null; if (pluginDescriptor.getPluginApplication() == null && pluginDescriptor.getPluginClassLoader() != null) { try { LogUtil.d("创建插件Application", pluginDescriptor.getApplicationName()); application = Instrumentation.newApplication( pluginDescriptor .getPluginClassLoader() .loadClass(pluginDescriptor.getApplicationName()), pluginDescriptor.getPluginContext()); pluginDescriptor.setPluginApplication(application); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } // 安装ContentProvider PluginInjector.installContentProviders( sApplication, pluginDescriptor.getProviderInfos().values()); // 执行onCreate if (application != null) { application.onCreate(); } changeListener.onPluginStarted(pluginDescriptor.getPackageName()); }
@Override protected ScriptEngine makeEngine() { try { Class<?> c; c = this.getClass().getClassLoader().loadClass("com.sun.script.java.JavaScriptEngineFactory"); ScriptEngineFactory fact = (ScriptEngineFactory) c.newInstance(); ScriptEngine engine = fact.getScriptEngine(); engine .getContext() .setAttribute( "com.sun.script.java.parentLoader", Trampoline2.trampoline.getClassLoader(), ScriptContext.ENGINE_SCOPE); engine .getContext() .setAttribute( "parentLoader", Trampoline2.trampoline.getClassLoader(), ScriptContext.ENGINE_SCOPE); return engine; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }