private void setDNAndEntryFields(final T o, final Entry e) throws LDAPPersistException { if (dnField != null) { try { dnField.set(o, e.getDN()); } catch (Exception ex) { debugException(ex); throw new LDAPPersistException( ERR_OBJECT_HANDLER_ERROR_SETTING_DN.get( type.getName(), e.getDN(), dnField.getName(), getExceptionMessage(ex)), ex); } } if (entryField != null) { try { entryField.set(o, new ReadOnlyEntry(e)); } catch (Exception ex) { debugException(ex); throw new LDAPPersistException( ERR_OBJECT_HANDLER_ERROR_SETTING_ENTRY.get( type.getName(), entryField.getName(), getExceptionMessage(ex)), ex); } } }
/** * オブジェクトのフィールドにデータを設定する<br> * Integer、Float、Float[]、Stringにしか対応していない * * @param obj 設定対象オブジェクト * @param fl 設定対象フィールド * @param ty 設定対象フィールドの型 * @param data 設定データ * @throws IllegalArgumentException * @throws IllegalAccessException */ protected void dataSetter(Object obj, Field fl, Class ty, String data) throws IllegalArgumentException, IllegalAccessException { // Integer型のデータを設定 if (ty.toString().equals("class java.lang.Integer")) { fl.set(obj, Integer.parseInt(data)); } // Float型のデータを設定 if (ty.toString().equals("class java.lang.Float")) { fl.set(obj, Float.parseFloat(data)); } // String型のデータを設定(""の内側) if (ty.toString().equals("class java.lang.String")) { fl.set(obj, getDoubleQuoatString(data)); } // Float[]型のデータを設定 if (ty.toString().equals("class [Ljava.lang.Float;")) { String[] s; s = data.split(" "); Float[] f = new Float[s.length]; for (int i = 0; i < s.length; i++) { f[i] = Float.parseFloat(s[i]); } fl.set(obj, f); } }
public static boolean readParam(String xNomeFile) { boolean ret = true; String xline; IOseq xFile; StringTokenizer st; String s1; String s2; Object m1; xFile = new IOseq("parameters.ne"); ret = xFile.IOseqOpenR(); if (ret) { try { Class c = Class.forName("jneat.Neat"); Field[] fieldlist = c.getDeclaredFields(); int number_params = fieldlist.length / 2; for (int i = 0; i < number_params; i++) { Field f1 = fieldlist[i]; String x1 = f1.getName(); Object x2 = f1.getType(); xline = xFile.IOseqRead(); st = new StringTokenizer(xline); // skip comment s1 = st.nextToken(); // real value s1 = st.nextToken(); if (x1.startsWith("p_")) { if (x2.toString().equals("double")) { double n1 = Double.parseDouble(s1); f1.set(c, (new Double(n1))); } if (x2.toString().equals("int")) { int n1 = Integer.parseInt(s1); f1.set(c, (new Integer(n1))); } } } } catch (Throwable e) { System.err.println(e); } xFile.IOseqCloseR(); } else System.err.print("\n : error during open " + xNomeFile); return ret; }
/** * Copy from the copy method in StructUtil. Did not want to drag that code in. maybe this actually * should go to struct. * * @param from * @param to * @param excludes * @return * @throws Exception */ public static <T extends struct> T xcopy(struct from, T to, String... excludes) throws Exception { Arrays.sort(excludes); for (Field f : from.fields()) { if (Arrays.binarySearch(excludes, f.getName()) >= 0) continue; Object o = f.get(from); if (o == null) continue; Field tof = to.getField(f.getName()); if (tof != null) try { tof.set(to, Converter.cnv(tof.getGenericType(), o)); } catch (Exception e) { System.out.println( "Failed to convert " + f.getName() + " from " + from.getClass() + " to " + to.getClass() + " value " + o + " exception " + e); } } return to; }
/** * Sets an attribute value of an object. * * @param obj the object to modify * @param field the attribute to set * @param value the value to assign to the field */ private static void setAttributeValue(Object obj, Field field, Object value) { try { field.set(obj, value); } catch (IllegalAccessException e) { throw ExceptionMapper.configurationException(e, field); } }
void put(Scriptable scope, String name, Object javaObject, Object value, boolean isStatic) { Map<String, Object> ht = isStatic ? staticMembers : members; Object member = ht.get(name); if (!isStatic && member == null) { // Try to get static member from instance (LC3) member = staticMembers.get(name); } if (member == null) throw reportMemberNotFound(name); if (member instanceof FieldAndMethods) { FieldAndMethods fam = (FieldAndMethods) ht.get(name); member = fam.field; } // Is this a bean property "set"? if (member instanceof BeanProperty) { BeanProperty bp = (BeanProperty) member; if (bp.setter == null) { throw reportMemberNotFound(name); } // If there's only one setter or if the value is null, use the // main setter. Otherwise, let the NativeJavaMethod decide which // setter to use: if (bp.setters == null || value == null) { Class<?> setType = bp.setter.argTypes[0]; Object[] args = {Context.jsToJava(value, setType)}; try { bp.setter.invoke(javaObject, args); } catch (Exception ex) { throw Context.throwAsScriptRuntimeEx(ex); } } else { Object[] args = {value}; bp.setters.call( Context.getContext(), ScriptableObject.getTopLevelScope(scope), scope, args); } } else { if (!(member instanceof Field)) { String str = (member == null) ? "msg.java.internal.private" : "msg.java.method.assign"; throw Context.reportRuntimeError1(str, name); } Field field = (Field) member; Object javaValue = Context.jsToJava(value, field.getType()); try { field.set(javaObject, javaValue); } catch (IllegalAccessException accessEx) { if ((field.getModifiers() & Modifier.FINAL) != 0) { // treat Java final the same as JavaScript [[READONLY]] return; } throw Context.throwAsScriptRuntimeEx(accessEx); } catch (IllegalArgumentException argEx) { throw Context.reportRuntimeError3( "msg.java.internal.field.type", value.getClass().getName(), field, javaObject.getClass().getName()); } } }
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")); } } }
public static void updateParam(vectTableModel _model) { // // write to file xpar all parameters..... // for (int j = 0; j < _model.data.size(); j++) { try { Class c = Class.forName("jneat.Neat"); ParamValue ox = (ParamValue) _model.data.elementAt(j); Object k = _model.getValueAt(j, 0); Object kv = _model.getValueAt(j, 1); String xkey = k.toString(); String xval = kv.toString(); /* System.out.print("\n j = "+j+" xkey = "+xkey); System.out.print(" xval = "+xval); */ Field f1 = c.getField("p_" + xkey); Object fty = f1.getType(); if (fty.toString().equals("double")) { double n1 = Double.parseDouble(xval); f1.set(c, (new Double(n1))); } if (fty.toString().equals("int")) { int n1 = Integer.parseInt(xval); f1.set(c, (new Integer(n1))); } } catch (Throwable e) { System.out.print("\n errore su jneat.updateParam = " + e); } } }
@Override public void init(GenericTask task, Map<String, String> properties) { Field[] fields = ReflectionHelper.getDeclaredFields(this.getClass(), null); for (Field field : fields) { if (!field.isAnnotationPresent(VersionProviderParam.class)) { continue; } VersionProviderParam param = field.getAnnotation(VersionProviderParam.class); if (!properties.containsKey(param.value())) { continue; } // make private and protected fields also accessible field.setAccessible(true); try { field.set(this, properties.get(param.value())); } catch (IllegalAccessException e) { throw new BuildException( "Failed to set build version provider param '" + param.value() + "'", e); } } }
public void setValue(int pos, String value) { Field fld = getField(pos); fld.set(value); }