private void initializePluginAPI(TiWebView webView) { try { synchronized (this.getClass()) { // Initialize if (enumPluginStateOff == null) { Class<?> webSettings = Class.forName("android.webkit.WebSettings"); Class<?> pluginState = Class.forName("android.webkit.WebSettings$PluginState"); Field f = pluginState.getDeclaredField("OFF"); enumPluginStateOff = (Enum<?>) f.get(null); f = pluginState.getDeclaredField("ON"); enumPluginStateOn = (Enum<?>) f.get(null); f = pluginState.getDeclaredField("ON_DEMAND"); enumPluginStateOnDemand = (Enum<?>) f.get(null); internalSetPluginState = webSettings.getMethod("setPluginState", pluginState); // Hidden APIs // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/webkit/WebView.java;h=bbd8b95c7bea66b7060b5782fae4b3b2c4f04966;hb=4db1f432b853152075923499768639e14403b73a#l2558 internalWebViewPause = webView.getClass().getMethod("onPause"); internalWebViewResume = webView.getClass().getMethod("onResume"); } } } catch (ClassNotFoundException e) { Log.e(TAG, "ClassNotFound: " + e.getMessage(), e); } catch (NoSuchMethodException e) { Log.e(TAG, "NoSuchMethod: " + e.getMessage(), e); } catch (NoSuchFieldException e) { Log.e(TAG, "NoSuchField: " + e.getMessage(), e); } catch (IllegalAccessException e) { Log.e(TAG, "IllegalAccess: " + e.getMessage(), e); } }
public static final void checkDataVersion(final Object data1, final Object data2) { if (null != data1) { try { final Field data1Version = data1.getClass().getDeclaredField("version"); // LOG.debug("find updId in methodinvocation"); data1Version.setAccessible(true); final long data1Verlong = data1Version.getLong(data1); if (null == data2) { final Code3gException pos3ge = new Code3gException("B341005"); pos3ge.setStatus(1); throw pos3ge; } final Field data2Version = data2.getClass().getDeclaredField("version"); // LOG.debug("find updId in methodinvocation"); data2Version.setAccessible(true); final long data2Verlong = data2Version.getLong(data2); if (data1Verlong != data2Verlong) { final Code3gException pos3ge = new Code3gException("B341005"); pos3ge.setStatus(1); throw pos3ge; } } catch (NoSuchFieldException e) { LOG.error("check version error, " + e.getMessage(), e); } catch (IllegalArgumentException e) { LOG.error("check version error, " + e.getMessage(), e); } catch (IllegalAccessException e) { LOG.error("check version error, " + e.getMessage(), e); } } }
/** * When the DataSet editor runs, modifications to the queryText as done in the BindParameter * function will get written to the queryText. To avoid this, we test if the query is being run by * the DataSet editor. * * <p>BIRT 2.5 has added a new Task type that identifies the DataSet editor so that this code is * no longer required. * * @param reportContext * @return */ public static boolean isDataSetEditor(IReportContext reportContext) { try { // get the protect field 'context' from reportContext @SuppressWarnings({"rawtypes"}) Class rciClass = reportContext.getClass(); Field fieldFromScript = rciClass.getDeclaredField("context"); if (fieldFromScript == null) { throw new NoSuchFieldException("Reporting Access to context from IReportContext"); } // instantiate the ExecutionContext object that // populates the context field fieldFromScript.setAccessible(true); Object execContext = fieldFromScript.get(reportContext); ExecutionContext ectx = (ExecutionContext) execContext; IEngineTask et = ectx.getEngineTask(); if ("DummyEngineTask".equalsIgnoreCase(et.getClass().getSimpleName())) { logger.info("Is Data Set Editor"); return true; } } catch (SecurityException e) { logger.warning("BIRT Functions, check for DataSet Editor: " + e.getMessage()); } catch (NoSuchFieldException e) { logger.warning("BIRT Functions, check for DataSet Editor: " + e.getMessage()); } catch (IllegalArgumentException e) { logger.warning("BIRT Functions, check for DataSet Editor: " + e.getMessage()); } catch (IllegalAccessException e) { logger.warning("BIRT Functions, check for DataSet Editor: " + e.getMessage()); } logger.finest("Is Not a Data Set Editor"); return false; }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); // backward compatibility; matchCorrelation could have a value if read from old definition if (matchCorrelations == null) matchCorrelations = new ArrayList<OScope.CorrelationSet>(); if (matchCorrelation != null) { matchCorrelations.add(matchCorrelation); } // backward compatibility; joinCorrelations could be null if read from old definition if (joinCorrelations == null) { try { Field field = OEvent.class.getDeclaredField("joinCorrelations"); field.setAccessible(true); field.set(this, new ArrayList<CorrelationSet>()); } catch (NoSuchFieldException nfe) { throw new IOException(nfe.getMessage()); } catch (IllegalAccessException iae) { throw new IOException(iae.getMessage()); } } // backward compatibility; joinCorrelation could have a value if read from old definition if (joinCorrelation != null) { joinCorrelation.hasJoinUseCases = true; joinCorrelations.add(joinCorrelation); } }
private void setVars(Map<Var, Node> values, String fieldName) { if (values.isEmpty()) { return; } try { Field f = Query.class.getDeclaredField(fieldName); f.setAccessible(true); List<String> orig = (List<String>) f.get(query); List<String> lst = null; if (orig != null) { lst = new ArrayList<String>(); for (String s : orig) { Node n = null; if (s.startsWith("?")) { Var v = Var.alloc(s.substring(1)); n = values.get(v); } lst.add(n == null ? s : n.toString()); } f.set(query, lst); } } catch (NoSuchFieldException e) { throw new IllegalStateException(e.getMessage(), e); } catch (SecurityException e) { throw new IllegalStateException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new IllegalStateException(e.getMessage(), e); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (mUnfoldableView.isUnfolded()) { inflater.inflate(R.menu.detail_bar, menu); } else { inflater.inflate(R.menu.main_bar, menu); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setIconifiedByDefault(true); int id = searchView .getContext() .getResources() .getIdentifier("android:id/search_close_btn", null, null); ((ImageView) Views.find(searchView, id)).setImageResource(R.drawable.ab_search_clear); int searchId = searchView .getContext() .getResources() .getIdentifier("android:id/search_mag_icon", null, null); // SearchView.SearchAutoComplete autoComplete = // (SearchView.SearchAutoComplete)ll3.getChildAt(0); // Drawable drawable= getResources().getDrawable(R.drawable.ic_action_search); // drawable.setBounds(0, 0, drawable.getMinimumWidth(), // drawable.getMinimumHeight()); ((ImageView) Views.find(searchView, searchId)).setImageResource(R.drawable.ic_action_search); int searchId2 = searchView .getContext() .getResources() .getIdentifier("android:id/search_button", null, null); ((ImageView) Views.find(searchView, searchId2)) .setBackgroundResource(R.drawable.ic_action_search); searchView.setSearchableInfo( searchManager.getSearchableInfo(getActivity().getComponentName())); try { Field searchField = SearchView.class.getDeclaredField("mSearchButton"); searchField.setAccessible(true); ImageView searchBtn = (ImageView) searchField.get(searchView); searchBtn.setImageResource(R.drawable.ic_action_search); searchField = SearchView.class.getDeclaredField("mSearchPlate"); searchField.setAccessible(true); // LinearLayout searchPlate = (LinearLayout)searchField.get(searchView); // Drawable drawable= // getResources().getDrawable(R.drawable.ic_action_search); // drawable.setBounds(0, 0, drawable.getMinimumWidth(), // drawable.getMinimumHeight()); // // ((TextView)searchPlate.getChildAt(0)).setCompoundDrawables(drawable,null,null,null); // searchPlate.setBackgroundResource(R.drawable.edit_text_bkg); } catch (NoSuchFieldException e) { Log.e(TAG, e.getMessage(), e); } catch (IllegalAccessException e) { Log.e(TAG, e.getMessage(), e); } } }
static { try { _cookieSet = AbstractSession.class.getDeclaredField("_cookieSet"); _cookieSet.setAccessible(true); } catch (NoSuchFieldException e) { throw new RuntimeException(e.getMessage(), e); } }
private static long getPtrToCpAddress() { Field field; try { field = TEST_CLASS.getDeclaredField("CP_ADDRESS"); } catch (NoSuchFieldException nsfe) { throw new Error("TESTBUG : cannot find field \"CP_ADDRESS\" : " + nsfe.getMessage(), nsfe); } Object base = UNSAFE.staticFieldBase(field); return WB.getObjectAddress(base) + UNSAFE.staticFieldOffset(field); }
static { try { final Field field = Unsafe.class.getDeclaredField("theUnsafe"); field.setAccessible(true); UNSAFE = (Unsafe) field.get(null); } catch (IllegalAccessException e) { throw new IllegalAccessError(e.getMessage()); } catch (NoSuchFieldException e) { throw new NoSuchFieldError(e.getMessage()); } }
/** * Create this helper and {@link org.apache.zookeeper.ZooKeeper} delegate connected to the * specified URL string, but also set various callback {@link groovy.lang.Closure}s at once. * * @param callbacks * @param url * @throws IOException */ public GroovyZooKeeperHelper(Map<String, Closure> callbacks, String url) throws IOException { this(); for (String key : callbacks.keySet()) { try { getClass().getDeclaredField(key).set(this, callbacks.get(key)); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); } catch (NoSuchFieldException e) { log.error(e.getMessage(), e); } } setZookeeper(new ZooKeeper(url, DEFAULT_TIMEOUT, clientWatcher)); }
/** * 反射属性 * * @param obj obj * @param fieldName field * @return the value of the fieldName */ public static Object getObj(Object obj, String fieldName) { Object result = null; try { Field field = obj.getClass().getDeclaredField(fieldName); field.setAccessible(true); result = field.get(obj); } catch (NoSuchFieldException e) { Log.e(e.getMessage()); } catch (IllegalAccessException e) { Log.e(e.getMessage()); } return result; }
/** * Reads an IList with collumns <tt>assettype</tt> and <tt>assetid</tt> and creates a Collection * of AssetId objects. * * @param result * @return Collection of AssetIds, never null. */ public static Collection<AssetId> toAssetIdCollection(IList result) { if (result == null || !result.hasData()) return Collections.emptyList(); final List<AssetId> list = new LinkedList<AssetId>(); for (IList row : new IterableIListWrapper(result)) { AssetId id; try { id = AssetIdUtils.createAssetId(row.getValue("assettype"), row.getValue("assetid")); list.add(id); } catch (NoSuchFieldException e) { throw new RuntimeException(e.getMessage()); } } return list; }
private static Field getField(final Class<?> clazz, final String fieldName) { String desc = "Field " + fieldName; try { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); return field; } catch (NoSuchFieldException e) { final String message = "could not get " + desc; if (LOG.isWarnEnabled()) { LOG.warn(LogUtil.buildExceptionLogFormat(message), e.getClass().getName(), e.getMessage()); } LOG.debug(message, e); } return null; }
/** * Main method that does processing and exposes Constants in specified scope * * @return int * @throws JspException if processing fails */ @Override public int doStartTag() throws JspException { // Using reflection, get the available field names in the class Class c = null; int toScope = PageContext.PAGE_SCOPE; if (scope != null) { toScope = getScope(scope); } try { c = Class.forName(clazz); } catch (ClassNotFoundException cnf) { log.error("ClassNotFound - maybe a typo?"); throw new JspException(cnf.getMessage()); } try { // if var is null, expose all variables if (var == null) { Field[] fields = c.getDeclaredFields(); AccessibleObject.setAccessible(fields, true); for (Field field : fields) { pageContext.setAttribute(field.getName(), field.get(this), toScope); } } else { try { Object value = c.getField(var).get(this); pageContext.setAttribute(c.getField(var).getName(), value, toScope); } catch (NoSuchFieldException nsf) { log.error(nsf.getMessage()); throw new JspException(nsf); } } } catch (IllegalAccessException iae) { log.error("Illegal Access Exception - maybe a classloader issue?"); throw new JspException(iae); } // Continue processing this page return (SKIP_BODY); }
/** Provide password for window authentication */ public static void windowAuthenticationPassword(MethodParameters model) { Robot robot; try { robot = new Robot(); robot.keyPress(KeyEvent.VK_TAB); String letter = model.getData(); for (int i = 0; i < letter.length(); i++) { boolean upperCase = Character.isUpperCase(letter.charAt(i)); String KeyVal = Character.toString(letter.charAt(i)); String variableName = "VK_" + KeyVal.toUpperCase(); Class clazz = KeyEvent.class; Field field = clazz.getField(variableName); int keyCode = field.getInt(null); if (upperCase) { robot.keyPress(KeyEvent.VK_SHIFT); } robot.keyPress(keyCode); robot.keyRelease(keyCode); if (upperCase) { robot.keyRelease(KeyEvent.VK_SHIFT); } } robot.keyPress(KeyEvent.VK_ENTER); } catch (AWTException e) { MainTestNG.LOGGER.severe(e.getMessage()); } catch (NoSuchFieldException e) { MainTestNG.LOGGER.severe(e.getMessage()); } catch (SecurityException e) { MainTestNG.LOGGER.severe(e.getMessage()); } catch (IllegalArgumentException e) { MainTestNG.LOGGER.severe(e.getMessage()); } catch (IllegalAccessException e) { MainTestNG.LOGGER.severe(e.getMessage()); } }
public void setAttrByFieldName(String fieldName, String newValue) { Field field = null; try { field = this.getClass().getDeclaredField(fieldName); } catch (SecurityException e) { ErrorLogger.log(e.getMessage()); } catch (NoSuchFieldException e) { ErrorLogger.log(e.getMessage()); } if (null != field) { try { field.set(this, newValue); } catch (IllegalArgumentException e) { ErrorLogger.log(e.getMessage()); } catch (IllegalAccessException e) { ErrorLogger.log(e.getMessage()); } } }
/** * 设置私有字段的值 * * @param obj boject * @param key fieldName * @param value the value to be set */ public static void setFieldValue(Object obj, String key, Object value) { Field field = null; try { field = obj.getClass().getDeclaredField(key); field.setAccessible(true); field.set(obj, value); } catch (NoSuchFieldException e) { Log.e(e.getMessage()); } catch (IllegalArgumentException e) { // e.printStackTrace(); if (field != null) Log.e( "IllegalArgumentException--" + "field:" + field.getName() + "-value:" + field.getType()); } catch (IllegalAccessException e) { Log.e(e.getMessage()); } }
public String getAttrByFieldName(String fieldName) { Field field = null; try { field = this.getClass().getDeclaredField(fieldName); } catch (SecurityException e) { ErrorLogger.log(e.getMessage()); } catch (NoSuchFieldException e) { ErrorLogger.log(e.getMessage()); } String attr = null; if (null != field) { try { attr = (String) field.get(this); } catch (IllegalArgumentException e) { ErrorLogger.log(e.getMessage()); } catch (IllegalAccessException e) { ErrorLogger.log(e.getMessage()); } } return attr; }
public boolean setAttributeValue(String attributeName, Object value) { Field f = null; try { f = this.getClass().getDeclaredField(attributeName); f.setAccessible(true); // required if field is not normally accessible } catch (SecurityException e1) { SysLog.logError(e1.getMessage()); return false; } catch (NoSuchFieldException e1) { SysLog.logError(e1.getMessage()); return false; } try { f.set(this, value); } catch (Exception e) { SysLog.logError(e.getMessage()); return false; } return true; }
public static void authenticateEndpoint(Endpoint endpoint, String user, String password) { try { Field userField = endpoint.getClass().getSuperclass().getDeclaredField("user"); userField.setAccessible(true); userField.set(endpoint, user); Field passwordField = endpoint.getClass().getSuperclass().getDeclaredField("password"); passwordField.setAccessible(true); passwordField.set(endpoint, password); } catch (SecurityException e) { fail(e.getMessage()); e.printStackTrace(); } catch (NoSuchFieldException e) { fail(e.getMessage()); e.printStackTrace(); } catch (IllegalArgumentException e) { fail(e.getMessage()); e.printStackTrace(); } catch (IllegalAccessException e) { fail(e.getMessage()); e.printStackTrace(); } }
private OperateSet generateInsertOperateSet(Object obj) { Class<? extends Object> clazz = obj.getClass(); // 获取tablecache中的对应的info String typeName = clazz.getName(); TableInfo tbinfo = null; String autoKeyName = ""; if (typeName != null) { tbinfo = oManager.getTableCache().getByTN(typeName); } if (tbinfo == null) { // 提示错误 System.out.println( "[generateInsertOperateSet error]-Model<" + typeName + "> has not registered!"); return null; } String strSql = "insert into " + tbinfo.getTableName(); String strField = ""; String strValue = ""; Vector<Object> param = new Vector<Object>(); Vector<FieldInfo> fins = tbinfo.getAllFieldInfos(); for (FieldInfo fin : fins) { // 跳过自动增长的字段 if (fin.isAutoGenerate()) { autoKeyName = fin.getColumnName(); continue; } strField += fin.getColumnName() + ","; strValue += "?,"; // 获取值 Field fie = null; try { fie = clazz.getDeclaredField(fin.getFieldName()); fie.setAccessible(true); } catch (NoSuchFieldException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } catch (SecurityException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } if (fie != null) { try { param.add(fie.get(obj)); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } } } // 只有自增字段错误退出 if (strField.equals("")) { System.out.println( "[generateInsertOperateSet error]-Model<" + typeName + "> only have autogenerate field!"); return null; } // 去除尾部的,号 strField = strField.substring(0, strField.length() - 1); strValue = strValue.substring(0, strValue.length() - 1); strSql += " (" + strField + ") values(" + strValue + ")"; OperateSet os = new OperateSet(strSql, param, tbinfo); os.setAutoKeyName(autoKeyName); return os; }
// 生成查询Sql,以主键为查询条件,如果有指定读入的键那只读该键 private OperateSet generateReadOperateSet(Object obj, String... fieldnames) { Class<? extends Object> clazz = obj.getClass(); // 获取tablecache中的对应的info String typeName = clazz.getName(); TableInfo tbinfo = null; String autoKeyName = ""; if (typeName != null) { tbinfo = oManager.getTableCache().getByTN(typeName); } if (tbinfo == null) { // 提示错误 System.out.println( "[generateReadOperateSet error]-Model<" + typeName + "> has not registered!"); return null; } String strSql = "select "; String strField = ""; String strWhere = ""; Vector<Object> param = new Vector<Object>(); if (fieldnames.length != 0) { if (fieldnames.length == 1) { if (fieldnames[0].equals("")) { return null; } } for (String s : fieldnames) { strField += s + ","; } strField = strField.substring(0, strField.length() - 1); strSql += strField + " from " + tbinfo.getTableName(); Vector<FieldInfo> fins = tbinfo.getAllFieldInfos(); for (FieldInfo fin : fins) { // 以主键为查询条件,如果不是主键的继续,暂时不支持联合主键 if (!fin.isPrimaryKey()) { continue; } autoKeyName = fin.getColumnName(); strWhere += fin.getColumnName() + "=?"; Field field = null; try { field = obj.getClass().getDeclaredField(fin.getFieldName()); } catch (NoSuchFieldException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } catch (SecurityException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } field.setAccessible(true); try { param.add(field.get(obj)); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } } if (strWhere.equals("")) { // 提示错误 System.out.println( "[generateReadOperateSet error]-Model<" + typeName + "> has not set PrimaryKey to achieve this query!"); return null; } strSql += " where " + strWhere + " limit 1"; OperateSet oSet = new OperateSet(strSql, param, tbinfo); oSet.setAutoKeyName(autoKeyName); return oSet; } else { strSql += "* from " + tbinfo.getTableName(); Vector<FieldInfo> fins = tbinfo.getAllFieldInfos(); for (FieldInfo fin : fins) { // 以主键为查询条件,如果不是主键的继续,暂时不支持联合主键 if (!fin.isPrimaryKey()) { continue; } autoKeyName = fin.getColumnName(); strWhere += fin.getColumnName() + "=?"; Field field = null; try { field = obj.getClass().getDeclaredField(fin.getFieldName()); } catch (NoSuchFieldException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } catch (SecurityException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } field.setAccessible(true); try { param.add(field.get(obj)); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); return null; } } if (strWhere.equals("")) { // 提示错误 System.out.println( "[generateReadOperateSet error]-Model<" + typeName + "> has not set PrimaryKey to achieve this query!"); return null; } strSql += " where " + strWhere + " limit 1"; OperateSet oSet = new OperateSet(strSql, param, tbinfo); oSet.setAutoKeyName(autoKeyName); return oSet; } }
/* @author Comdex * @see com.reflectsky.cozy.Ormer#read(java.lang.Object, java.lang.String[]) */ @Override public boolean read(Object obj, String... fieldnames) { // TODO 自动生成的方法存根 OperateSet oSet = generateReadOperateSet(obj, fieldnames); PreparedStatement pstmt = null; ResultSet rs = null; boolean isOk = false; if (oSet == null) { return isOk; } try { pstmt = conn.prepareStatement(oSet.getStrSql()); ormDebug(oSet); } catch (SQLException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } if (pstmt != null) { Vector<Object> param = oSet.getParam(); for (int i = 0; i < param.size(); i++) { Object object = param.get(i); try { pstmt.setObject(i + 1, object); } catch (SQLException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } if (callbackobj != null) { Class<?> clazz = callbackobj.getClass(); Method[] mtds = clazz.getDeclaredMethods(); for (Method mtd : mtds) { if (mtd.getName().equals("beforeRead")) { Class<?>[] params = mtd.getParameterTypes(); if (params.length == 2) { if (params[0] == obj.getClass() && params[1] == Ormer.class) { // 用于回调的注入参数Ormer Ormer ormer = this.oManager.NewOrm(); mtd.setAccessible(true); try { mtd.invoke(callbackobj, obj, ormer); } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (InvocationTargetException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } } } } } try { rs = pstmt.executeQuery(); // 获取查询结果的值 Vector<Object> values = new Vector<Object>(); if (fieldnames.length != 0) { if (rs != null) { if (rs.next()) { for (String s : fieldnames) { values.add(rs.getObject(s)); } } } // 获取fieldname对应的字段名 Vector<String> fields = new Vector<String>(); Vector<FieldInfo> fins = oSet.getTbinfo().getAllFieldInfos(); for (String s : fieldnames) { for (FieldInfo fin : fins) { if (fin.getColumnName().equalsIgnoreCase(s)) { fields.add(fin.getFieldName()); } } } // 为对应的field设值 for (int i = 0; i < fields.size(); i++) { try { Field field = obj.getClass().getDeclaredField(fields.get(i)); field.setAccessible(true); field.set(obj, values.get(i)); } catch (NoSuchFieldException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (SecurityException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (Exception e) { // TODO: handle exception this.oManager.deBugInfo(e.getMessage()); } } this.oManager.closeRs(rs); this.oManager.closeStmt(pstmt); return isOk; } else { // 获取该对象所有字段名 Vector<String> fields = new Vector<String>(); Vector<FieldInfo> fins = oSet.getTbinfo().getAllFieldInfos(); if (rs != null) { if (rs.next()) { for (FieldInfo fin : fins) { values.add(rs.getObject(fin.getColumnName())); } } } // 为对应的Field设值 for (int i = 0; i < fins.size(); i++) { Field field = null; try { field = obj.getClass().getDeclaredField(fins.get(i).getFieldName()); } catch (NoSuchFieldException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (SecurityException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } field.setAccessible(true); try { field.set(obj, values.get(i)); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } this.oManager.closeRs(rs); this.oManager.closeStmt(pstmt); if (callbackobj != null) { Class<?> clazz = callbackobj.getClass(); Method[] mtds = clazz.getDeclaredMethods(); for (Method mtd : mtds) { if (mtd.getName().equals("afterRead")) { Class<?>[] params = mtd.getParameterTypes(); if (params.length == 2) { if (params[0] == obj.getClass() && params[1] == Ormer.class) { // 用于回调的注入参数Ormer Ormer ormer = this.oManager.NewOrm(); mtd.setAccessible(true); try { mtd.invoke(callbackobj, obj, ormer); } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (InvocationTargetException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } } } } } this.oManager.closeRs(rs); this.oManager.closeStmt(pstmt); return isOk; } } catch (SQLException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } if (rs != null) { this.oManager.closeRs(rs); } if (pstmt != null) { this.oManager.closeStmt(pstmt); } return isOk; }
/* 返回自增长的id,没有自增长时都是返回-1 * @author Comdex * @see com.reflectsky.cozy.Ormer#insert(java.lang.Object) */ @Override public long insert(Object obj) { // TODO 自动生成的方法存根 OperateSet oSet = generateInsertOperateSet(obj); PreparedStatement pstmt = null; ResultSet rs = null; long count = -1; if (oSet == null) { return count; } try { pstmt = conn.prepareStatement(oSet.getStrSql(), Statement.RETURN_GENERATED_KEYS); ormDebug(oSet); } catch (SQLException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } if (pstmt != null) { Vector<Object> param = oSet.getParam(); for (int i = 0; i < param.size(); i++) { Object object = param.get(i); try { pstmt.setObject(i + 1, object); } catch (SQLException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } // 如果开启方法回调支持功能 if (callbackobj != null) { Class<?> clazz = callbackobj.getClass(); Method[] mtds = clazz.getDeclaredMethods(); for (Method mtd : mtds) { if (mtd.getName().equals("beforeInsert")) { Class<?>[] params = mtd.getParameterTypes(); if (params.length == 2) { if (params[0] == obj.getClass() && params[1] == Ormer.class) { // 用于回调的注入参数Ormer Ormer ormer = this.oManager.NewOrm(); mtd.setAccessible(true); try { mtd.invoke(callbackobj, obj, ormer); } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (InvocationTargetException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } } } } } try { pstmt.executeUpdate(); } catch (SQLException e1) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e1.getMessage()); } try { if (!oSet.getAutoKeyName().equals("")) { rs = pstmt.getGeneratedKeys(); if (rs.next()) { long autoId = rs.getLong(1); Field field = null; try { field = obj.getClass().getDeclaredField(oSet.getAutoKeyName()); } catch (NoSuchFieldException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (SecurityException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } field.setAccessible(true); try { if (field.getClass().getName().equals("Integer")) { field.set(obj, (int) autoId); } else if (field.getClass().getName().equals("Short")) { field.set(obj, (short) autoId); } else { field.set(obj, (int) autoId); } this.oManager.closeRs(rs); this.oManager.closeStmt(pstmt); count = autoId; if (callbackobj != null) { Class<?> clazz = callbackobj.getClass(); Method[] mtds = clazz.getDeclaredMethods(); for (Method mtd : mtds) { if (mtd.getName().equals("afterInsert")) { Class<?>[] params = mtd.getParameterTypes(); if (params.length == 2) { if (params[0] == obj.getClass() && params[1] == Ormer.class) { // 用于回调的注入参数Ormer Ormer ormer = this.oManager.NewOrm(); mtd.setAccessible(true); try { mtd.invoke(callbackobj, obj, ormer); } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (InvocationTargetException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } } } } } this.oManager.closeStmt(pstmt); return count; } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } } else { this.oManager.closeStmt(pstmt); return count; } } catch (SQLException e) { // TODO 自动生成的 catch 块 this.oManager.deBugInfo(e.getMessage()); } } return count; }
/** Determines if the property orderProperty was defined for the object. */ @SuppressWarnings({"unchecked", "rawtypes"}) private void parseOrderDefined() { orderDefined = false; OrderBy orderBy = null; if (Is.empty(orderProperty)) { try { Field collectionField = parentClass.getDeclaredField(collectionName); if (collectionField.isAnnotationPresent(OrderBy.class)) { orderBy = collectionField.getAnnotation(OrderBy.class); } } catch (SecurityException e) { log.error(e); } catch (NoSuchFieldException e) { log.debug(e.getMessage()); } if (orderBy == null) { Method collectionMethod = null; try { collectionMethod = parentClass.getDeclaredMethod( "get" + Strings.firstUpper(collectionName), new Class[] {}); } catch (Exception e) { log.debug(e); } if (collectionMethod == null) { try { collectionMethod = parentClass.getDeclaredMethod( "is" + Strings.firstUpper(collectionName), new Class[] {}); } catch (Exception e) { log.debug(e); } } if (collectionMethod != null && collectionMethod.isAnnotationPresent(OrderBy.class)) { orderBy = collectionMethod.getAnnotation(OrderBy.class); } } if (orderBy != null) { String[] fieldNames = orderBy.value().split(","); if (fieldNames.length > 0) { orderProperty = fieldNames[fieldNames.length - 1].trim(); } } } if (!Is.empty(orderProperty)) { try { Object itemObject = nodeClass.newInstance(); Class propertyType = PropertyUtils.getPropertyType(itemObject, orderProperty); if (propertyType.isAssignableFrom(Integer.class)) { orderDefined = true; } } catch (IllegalAccessException e) { log.error(e); } catch (InvocationTargetException e) { log.error(e); } catch (NoSuchMethodException e) { log.error(e); } catch (Exception e) { log.error(e); } } }
/** * Called by a static initializer to load any classes, fields, and methods required at runtime to * locate the user's web browser. * * @return <code>true</code> if all intialization succeeded <code>false</code> if any portion of * the initialization failed */ private static boolean loadClasses() { switch (jvm) { case MRJ_2_0: try { Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget"); Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils"); Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent"); Class aeClass = Class.forName("com.apple.MacOS.ae"); aeDescClass = Class.forName("com.apple.MacOS.AEDesc"); aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] {int.class}); appleEventConstructor = appleEventClass.getDeclaredConstructor( new Class[] {int.class, int.class, aeTargetClass, int.class, int.class}); aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] {String.class}); makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] {String.class}); putParameter = appleEventClass.getDeclaredMethod( "putParameter", new Class[] {int.class, aeDescClass}); sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {}); Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject"); keyDirectObject = (Integer) keyDirectObjectField.get(null); Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID"); kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null); Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID"); kAnyTransactionID = (Integer) anyTransactionIDField.get(null); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); return false; } catch (NoSuchMethodException nsme) { errorMessage = nsme.getMessage(); return false; } catch (NoSuchFieldException nsfe) { errorMessage = nsfe.getMessage(); return false; } catch (IllegalAccessException iae) { errorMessage = iae.getMessage(); return false; } break; case MRJ_2_1: try { mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils"); mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType"); Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType"); kSystemFolderType = systemFolderField.get(null); findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] {mrjOSTypeClass}); getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] {File.class}); getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] {File.class}); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); return false; } catch (NoSuchFieldException nsfe) { errorMessage = nsfe.getMessage(); return false; } catch (NoSuchMethodException nsme) { errorMessage = nsme.getMessage(); return false; } catch (SecurityException se) { errorMessage = se.getMessage(); return false; } catch (IllegalAccessException iae) { errorMessage = iae.getMessage(); return false; } break; case MRJ_3_0: try { Class linker = Class.forName("com.apple.mrj.jdirect.Linker"); Constructor constructor = linker.getConstructor(new Class[] {Class.class}); linkage = constructor.newInstance(new Object[] {Browser.class}); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); return false; } catch (NoSuchMethodException nsme) { errorMessage = nsme.getMessage(); return false; } catch (InvocationTargetException ite) { errorMessage = ite.getMessage(); return false; } catch (InstantiationException ie) { errorMessage = ie.getMessage(); return false; } catch (IllegalAccessException iae) { errorMessage = iae.getMessage(); return false; } break; case MRJ_3_1: try { mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils"); openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] {String.class}); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); return false; } catch (NoSuchMethodException nsme) { errorMessage = nsme.getMessage(); return false; } break; default: break; } return true; }
public static void main(String args[]) throws IllegalArgumentException, SemanticException { String extension = "jl"; String className; if (args.length == 3 && args[0].equals("-ext")) extension = args[1]; if ((extension == null && args.length != 1) || (extension != null && args.length != 3)) { System.err.println( "Usage: " + "polyglot.util.typedump.Main " + "[-ext <extension>] <classname>"); System.exit(1); } if (extension == null) className = args[0]; else className = args[2]; ExtensionInfo extInfo = null; String extClassName = "polyglot.ext." + extension + ".ExtensionInfo"; Class<?> extClass = null; try { extClass = Class.forName(extClassName); } catch (ClassNotFoundException e) { try { extClass = Class.forName(extension); } catch (ClassNotFoundException e2) { System.err.println( "Extension " + extension + " not found: could not find class " + extClassName + "."); System.err.println(e2.getMessage()); System.exit(1); } } try { extInfo = (ExtensionInfo) extClass.newInstance(); } catch (Exception e) { System.err.println( "Extension " + extension + " could not be loaded: " + "could not instantiate " + extClassName + "."); System.exit(1); } try { // now try to establish the type system correctly. Options options = extInfo.getOptions(); Options.global = options; configureOptions(options); StdErrorQueue eq = new StdErrorQueue(System.err, 100, extInfo.compilerName()); new Compiler(extInfo, eq); TypeSystem ts = extInfo.typeSystem(); TypeDumper t = TypeDumper.load(className, ts, extInfo.version()); CodeWriter cw = new OptimalCodeWriter(System.out, 100); t.dump(cw); cw.newline(0); try { cw.flush(); } catch (java.io.IOException exn) { System.err.println(exn.getMessage()); } } catch (ClassNotFoundException exn) { System.err.println("Could not load .class: " + className); System.err.println(exn.getMessage()); } catch (NoSuchFieldException exn) { System.err.println("Could not reflect jlc fields"); System.err.println(exn.getMessage()); } catch (SecurityException exn) { System.err.println("Security policy error."); System.err.println(exn.getMessage()); } }
/** * Create a new object instance and load the stored values into it. * * @param result The result set come from the query * @param record The (tipically blank) DataTransferObject to mofify * @return The modified DataTransferObject * @throws SQLException * @throws Exception */ private DataTransferObject result2record(ResultSet result, DataTransferObject record) throws SQLException, Exception { if (null == result) { return null; } FieldMetadata fieldMeta; Method accessorMthd; Object value; Class<?> javaType; for (String field : meta.keySet()) { fieldMeta = meta.get(field); // String javaField = fieldMeta.getJavaField(); //TextUtil.toCamelCase(field); // String accessor = fieldMeta.getAccessor(); // TextUtil.toCamelCase("set_" + field); try { try { javaType = fieldMeta.getJavaType(record); if (javaType == null) { continue; } accessorMthd = fieldMeta.getAccessorMethod(record); if (javaType.equals(String.class)) { if (null != result.getBytes(field)) { value = new String(result.getBytes(field), "utf-8"); } else { value = null; } } else if (javaType.equals("chr")) { value = (char) result.getInt(field); /* if(result.getBytes(field) != null){ value = new String(result.getBytes(field), "utf-8"); } else { value = null; } */ } else if (javaType.equals(Date.class)) { value = result.getDate(field); } else if (javaType.equals(Integer.class)) { value = result.getInt(field); } else if (javaType.equals("int")) { value = result.getInt(field); } else if (javaType.equals(Boolean.class)) { value = result.getBoolean(field); } else if (javaType.equals(Timestamp.class)) { value = result.getTimestamp(field); } else { prglog.error("[PRG] Unhandled type: " + javaType); throw new Exception("Unhandled type: " + javaType); } if (null != accessorMthd) { accessorMthd.invoke(record, new Object[] {value}); } } catch (NoSuchFieldException e) { prglog.warn("[PRG] No such field: " + field + ". " + e.getMessage()); continue; } catch (NoSuchMethodException e) { prglog.warn("[PRG] No such method: " + fieldMeta.getAccessor() + ". " + e.getMessage()); continue; } } catch (InvocationTargetException e) { throw new Exception(e); } catch (Exception e) { e.printStackTrace(); throw new Exception(e); } } result = null; return record; }
private void processSessionExpirationUnderPortletsMyFaces( FacesContext context, UIViewRoot root, ExternalContext externalContext, Object session) { Object requestObject = context.getExternalContext().getRequest(); HttpServletRequest catalinaServletRequest = null; try { Class jbossRenderRequestClass = Class.forName("org.jboss.portlet.JBossRenderRequest"); Class abstractRequestContextClass = Class.forName("org.jboss.portal.portlet.impl.spi.AbstractRequestContext"); Class requestObjectClass = requestObject.getClass(); if (jbossRenderRequestClass.isAssignableFrom(requestObjectClass)) { Field requestContextField = requestObject .getClass() .getSuperclass() .getSuperclass() .getDeclaredField("requestContext"); requestContextField.setAccessible(true); Object requestContext = requestContextField.get(requestObject); Class requestContextClass = requestContext.getClass(); if (abstractRequestContextClass.isAssignableFrom(requestContextClass)) { Field reqField = requestContextClass.getDeclaredField("req"); reqField.setAccessible(true); Object req = reqField.get(requestContext); if (req instanceof HttpServletRequest) { catalinaServletRequest = (HttpServletRequest) req; } } } } catch (ClassNotFoundException e) { externalContext.log(e.getMessage()); } catch (NoSuchFieldException e) { externalContext.log(e.getMessage()); } catch (IllegalAccessException e) { externalContext.log(e.getMessage()); } if (AjaxUtil.isPortletRenderRequest(context) && !AjaxUtil.isAjaxRequest(context) && catalinaServletRequest != null && catalinaServletRequest.getParameterMap().size() > 0) { if (isNewSession(session)) { addAjaxRequestMarkerUnderPortlets(context, root); addSessionExpirationFlagUnderPortlets(context, root); } } if (Environment.isLiferay(context.getExternalContext().getRequestMap())) { if (context .getExternalContext() .getSessionMap() .containsKey(AjaxViewHandler.SESSION_EXPIRATION_PROCESSING)) { addAjaxRequestMarkerUnderPortlets(context, root); addSessionExpirationFlagUnderPortlets(context, root); context .getExternalContext() .getSessionMap() .remove(AjaxViewHandler.SESSION_EXPIRATION_PROCESSING); } } }