/** * Insert the source code details, if available. * * @param ped The given program element. */ public void addSourcePosition(ProgramElementDoc ped, int indent) { if (!addSrcInfo) return; if (JDiff.javaVersion.startsWith("1.1") || JDiff.javaVersion.startsWith("1.2") || JDiff.javaVersion.startsWith("1.3")) { return; // position() only appeared in J2SE1.4 } try { // Could cache the method for improved performance Class c = ProgramElementDoc.class; Method m = c.getMethod("position", null); Object sp = m.invoke(ped, null); if (sp != null) { for (int i = 0; i < indent; i++) outputFile.print(" "); outputFile.println("src=\"" + sp + "\""); } } catch (NoSuchMethodException e2) { System.err.println("Error: method \"position\" not found"); e2.printStackTrace(); } catch (IllegalAccessException e4) { System.err.println("Error: class not permitted to be instantiated"); e4.printStackTrace(); } catch (InvocationTargetException e5) { System.err.println("Error: method \"position\" could not be invoked"); e5.printStackTrace(); } catch (Exception e6) { System.err.println("Error: "); e6.printStackTrace(); } }
private static void addRSPack(boolean refreash) { File rspack = new File(getConfigFolder(), "/resources"); if (!rspack.exists()) return; if (!Arrays.asList(rspack.list()).contains("pack.mcmeta")) { try { JsonWriter writer = new JsonWriter(new FileWriter(new File(rspack, "pack.mcmeta"))); writer.beginObject(); writer.name("pack"); writer.beginObject(); writer.name("pack_format").value(1); writer.name("description").value("Draconic Evolution GUI Images"); writer.endObject(); writer.endObject(); writer.close(); } catch (IOException e) { LogHelper.error("Error creating pack.mcmeta"); e.printStackTrace(); } } Field f = ReflectionHelper.findField(Minecraft.class, "defaultResourcePacks", "field_110449_ao"); f.setAccessible(true); try { List defaultResourcePacks = (List) f.get(Minecraft.getMinecraft()); defaultResourcePacks.add(new FolderResourcePack(rspack)); f.set(Minecraft.getMinecraft(), defaultResourcePacks); LogHelper.info("RS Added"); if (refreash) Minecraft.getMinecraft().refreshResources(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
/** * 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 = Class.forName(className); c = madkit.kernel.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); 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(); } }
public Matrix createVector(BitVector selector) { int rows = selector != null ? selector.countOnBits() : frame.size(); Matrix m = new Matrix(rows, 1); for (int i = 0, j = 0; j < frame.size(); j++) { if (selector == null || selector.isOn(j)) { M rowValue = frame.object(j); try { Number numValue = (Number) numericField.get(rowValue); m.set(i, 0, numValue.doubleValue()); } catch (IllegalAccessException e) { e.printStackTrace(); throw new IllegalStateException( String.format( "Couldn't access field %s: %s", numericField.getName(), e.getMessage())); } i++; } } return m; }
/** * Recherche dans la table spécifiée un objet ayant pour valeur propertyValue à l'attribut * propertyName. * * @param tableName Le nom de la table * @param propertyName Le nom de la propriété de l'objet à comparer * @param propertyValue La valeur de la propriété qui doit correspondre * @return Retourne le premier objet trouvé ou NULL si la recherche n'a pas aboutie */ public Object findOne(String tableName, String propertyName, Object propertyValue) { List<? extends Object> table = get(tableName); if (table == null) { return null; } // Recherche de l'objet contenant la valeur souhaitee dans la propriete for (Object row : table) { // Parcours de tous les champs de la classe try { Field field = row.getClass().getDeclaredField(propertyName); field.setAccessible(true); Object prop = field.get(row); if (prop.equals(propertyValue)) { return row; } } catch (NoSuchFieldException nsfe) { continue; } catch (IllegalAccessException iae) { System.err.println( "Impossible d'acceder a la propriete " + propertyName + " : acces refuse."); iae.printStackTrace(); } } return null; }
/** * Method to store the value under the specified key * * @param key Key to store the value under * @param value Object to store * @param listType Type of List implementation to use to store multivalues in * @param index Index into the list of values to place the new value * @return Previous object stored under this key */ public Object put(Object key, Object value, Class listType, int index) { // Get the list of values for the key List values = (List) super.get(key); // If none found, create a new list if (values == null) { // Create the new instance type of List try { values = (List) listType.newInstance(); } catch (IllegalAccessException eae) { eae.printStackTrace(); } catch (InstantiationException inste) { inste.printStackTrace(); } } // If the value doesn't already exist if (!values.contains(value)) { // If index is -1, then append to end if (index > -1) { values.add(index, value); } else { values.add(value); } } return super.put(key, values); }
/** * Set the object to be edited. * * @param value The object to be edited. */ public void setObject(Object value) { if (!(_type.isInstance(value))) { throw new IllegalArgumentException(value.getClass() + " is not of type " + _type); } _value = value; // Disable event generation. _squelchChangeEvents = true; // Iterate over each property, doing a lookup on the associated editor // and setting the editor's value to the value of the property. Iterator it = _prop2Editor.keySet().iterator(); while (it.hasNext()) { PropertyDescriptor desc = (PropertyDescriptor) it.next(); PropertyEditor editor = (PropertyEditor) _prop2Editor.get(desc); Method reader = desc.getReadMethod(); if (reader != null) { try { Object val = reader.invoke(_value, null); editor.setValue(val); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InvocationTargetException ex) { ex.getTargetException().printStackTrace(); } } } // Enable event generation. _squelchChangeEvents = false; }
public void setEntity(java.lang.Object ent) { Method[] methods = ent.getClass().getDeclaredMethods(); box.removeAll(); for (Method m : methods) { if (m.getName().toLowerCase().startsWith("get")) { String attName = m.getName().substring(3); Object result; try { result = m.invoke(ent, new Object[] {}); String value = "null"; if (result != null) value = result.toString(); JPanel attPane = new JPanel(new FlowLayout(FlowLayout.LEFT)); attPane.add(new JLabel(attName + " : " + m.getReturnType().getName() + " = " + value)); box.add(attPane); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } }
/** evaluate the link function */ public static Data link(VMethod m, Object[] o) throws VisADException { Data ans = null; if (o != null) { for (int i = 0; i < o.length; i++) { // convert VRealTypes to RealTypes if (o[i] instanceof VRealType) { o[i] = ((VRealType) o[i]).getRealType(); } } } try { ans = (Data) FormulaUtil.invokeMethod(m.getMethod(), o); } catch (ClassCastException exc) { if (FormulaVar.DEBUG) exc.printStackTrace(); throw new VisADException("Link error: invalid linked method"); } catch (IllegalAccessException exc) { if (FormulaVar.DEBUG) exc.printStackTrace(); throw new VisADException("Link error: cannot access linked method"); } catch (IllegalArgumentException exc) { if (FormulaVar.DEBUG) exc.printStackTrace(); throw new VisADException("Link error: bad method argument"); } catch (InvocationTargetException exc) { if (FormulaVar.DEBUG) exc.getTargetException().printStackTrace(); throw new VisADException("Link error: linked method threw an exception"); } if (ans == null) { throw new VisADException("Link error: linked method returned null data"); } return ans; }
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() + "]"); } } } }
/** * Sets the configurable class of this object. * * @throws RuntimeException if the the <code>Configurable</code> is already instantiated. */ void setConfigurableClass(Class<? extends Configurable> confClass) { ownerClass = confClass; // Don't allow changes of the class if the configurable has already been instantiated if (isInstanciated()) throw new RuntimeException("class is already instantiated"); // clean up the properties if necessary // registeredProperties.clear(); final Collection<String> classProperties = new HashSet<String>(); final Map<Field, Annotation> classProps = parseClass(ownerClass); for (Map.Entry<Field, Annotation> entry : classProps.entrySet()) { try { String propertyName = (String) entry.getKey().get(null); // make sure that there is not already another property with this name assert !classProperties.contains(propertyName) : "duplicate property-name for different properties: " + propertyName + " for the class " + confClass; registerProperty(propertyName, new S4PropWrapper(entry.getValue())); classProperties.add(propertyName); } catch (IllegalAccessException e) { e.printStackTrace(); } } }
// This is called client side. public List<ClientScreenModule> getClientScreenModules() { if (clientScreenModules == null) { needsServerData = false; clientScreenModules = new ArrayList<ClientScreenModule>(); for (int i = 0; i < inventoryHelper.getCount(); i++) { ItemStack itemStack = inventoryHelper.getStackInSlot(i); if (itemStack != null && itemStack.getItem() instanceof ModuleProvider) { ModuleProvider moduleProvider = (ModuleProvider) itemStack.getItem(); ClientScreenModule clientScreenModule; try { clientScreenModule = moduleProvider.getClientScreenModule().newInstance(); } catch (InstantiationException e) { e.printStackTrace(); continue; } catch (IllegalAccessException e) { e.printStackTrace(); continue; } clientScreenModule.setupFromNBT( itemStack.getTagCompound(), worldObj.provider.dimensionId, xCoord, yCoord, zCoord); clientScreenModules.add(clientScreenModule); if (clientScreenModule.needsServerData()) { needsServerData = true; } } else { clientScreenModules.add( null); // To keep the indexing correct so that the modules correspond with there slot // number. } } } return clientScreenModules; }
public static final void fireEvent(GenericEvent e, Method m, Vector listeners) throws PropertyVetoException { Object[] snapshot = null; synchronized (listeners) { snapshot = new Object[listeners.size()]; listeners.copyInto(snapshot); } // leighd 04/14/99 - modified for event debugging if (gDebugEvents) Engine.debugLog("Event : " + e.toString()); Object params[] = new Object[] {e}; for (int i = 0; i < snapshot.length; i++) { if ((e instanceof Consumable) && ((Consumable) e).isConsumed()) { // leighd 04/14/99 // note that we don't catch the consumption of the // event until we've passed through the loop again, // so we reference i-1 if (gDebugEvents) Engine.debugLog("Consumed By : " + snapshot[i - 1]); return; } try { m.invoke(snapshot[i], params); } catch (IllegalAccessException iae) { iae.printStackTrace(); } catch (InvocationTargetException ite) { Throwable t = ite.getTargetException(); if (t instanceof PropertyVetoException) throw ((PropertyVetoException) t); else t.printStackTrace(); } } }
public Distribution<T> parse(String distrAsString) { DiscreteDistribution<T> dist = new DiscreteDistribution<T>(); StringTokenizer tok = new StringTokenizer(distrAsString, ","); while (tok.hasMoreElements()) { String pair = tok.nextToken().trim(); StringTokenizer sub = new StringTokenizer(pair, "/"); try { T value = (T) domainType.getConstructor(String.class).newInstance(sub.nextToken().trim()); Degree deg = (Degree) getDegreeStringConstructor().newInstance(sub.nextToken().trim()); dist.put(value, deg); } catch (NoSuchMethodException nsme) { nsme.printStackTrace(); } catch (IllegalAccessException iae) { iae.printStackTrace(); } catch (InstantiationException ie) { ie.printStackTrace(); } catch (InvocationTargetException ite) { ite.printStackTrace(); } } return dist; }
private static Object decode(Class returnType, String valueStr, TypeResolver resolver) { if (returnType.isArray()) { int sIndex = valueStr.indexOf("{"); int eIndex = valueStr.lastIndexOf("}"); String content = valueStr.substring(sIndex + 1, eIndex).trim(); StringTokenizer tok = new StringTokenizer(content, ","); Object ar = java.lang.reflect.Array.newInstance(returnType.getComponentType(), tok.countTokens()); int j = 0; while (tok.hasMoreElements()) { java.lang.reflect.Array.set( ar, j++, decode(returnType.getComponentType(), tok.nextToken(), resolver)); } return ar; } else if (returnType.isEnum()) { try { String value = valueStr.trim(); if (value.indexOf('.') > 0) { value = valueStr.substring(valueStr.lastIndexOf(".") + 1); } return returnType.getMethod("valueOf", String.class).invoke(null, value); } catch (IllegalAccessException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (InvocationTargetException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (NoSuchMethodException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } } else if (String.class.equals(returnType)) { return unquote(valueStr); } else if (boolean.class.equals(returnType)) { return Boolean.valueOf(valueStr); } else if (int.class.equals(returnType)) { return Integer.valueOf(valueStr); } else if (double.class.equals(returnType)) { return Double.valueOf(valueStr); } else if (long.class.equals(returnType)) { return Long.valueOf(valueStr); } else if (float.class.equals(returnType)) { return Float.valueOf(valueStr); } else if (short.class.equals(returnType)) { return Short.valueOf(valueStr); } else if (char.class.equals(returnType)) { return unquote(valueStr).charAt(0); } else if (Class.class.equals(returnType)) { try { String cName = valueStr.trim().replace(".class", ""); return resolver.resolveType(cName); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); return Object.class; } } return null; }
/** * forward an execute request to a helper instance associated with the rule * * @param recipient the recipient of the method from which execution of this rule was triggered or * null if it was a static method * @param args the arguments of the method from which execution of this rule was triggered */ private void execute(Object recipient, Object[] args) throws ExecuteException { // type check and createHelperAdapter the rule now if it has not already been done if (ensureTypeCheckedCompiled()) { // create a helper and get it to execute the rule // eventually we will create a subclass of helper for each rule and createHelperAdapter // an implementation of execute from the rule source. for now we create a generic // helper and call the generic execute method which interprets the rule HelperAdapter helper; try { Constructor constructor = helperImplementationClass.getConstructor(Rule.class); helper = (HelperAdapter) constructor.newInstance(this); // helper = (RuleHelper)helperClass.newInstance(); // helper.setRule(this); helper.execute(recipient, args); } catch (NoSuchMethodException e) { // should not happen!!! System.out.println( "cannot find constructor " + helperImplementationClass.getCanonicalName() + "(Rule) for helper class"); e.printStackTrace(System.out); return; } catch (InvocationTargetException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (InstantiationException e) { // should not happen System.out.println( "cannot create instance of " + helperImplementationClass.getCanonicalName()); e.printStackTrace(System.out); return; } catch (IllegalAccessException e) { // should not happen System.out.println("cannot access " + helperImplementationClass.getCanonicalName()); e.printStackTrace(System.out); return; } catch (ClassCastException e) { // should not happen System.out.println("cast exception " + helperImplementationClass.getCanonicalName()); e.printStackTrace(System.out); return; } catch (EarlyReturnException e) { throw e; } catch (ThrowException e) { throw e; } catch (ExecuteException e) { System.out.println(getName() + " : " + e); throw e; } catch (Throwable throwable) { System.out.println(getName() + " : " + throwable); throw new ExecuteException(getName() + " : caught " + throwable, throwable); } } }
@Override public void setValue(_ValueType value, _RowType pRow) { try { mSetterMethod.invoke(pRow, value); } catch (IllegalAccessException e) { e.printStackTrace(); // Shouldn't happen } catch (InvocationTargetException e) { e.printStackTrace(); // shouldn't happen } }
@SuppressWarnings("unchecked") public AbstractNetSystem() { super(); try { this.marking = (M) Marking.class.newInstance(); this.marking.setPetriNet(this); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
public _ValueType getValue(_RowType pRow) { try { //noinspection unchecked return (_ValueType) mGetterMethod.invoke(pRow); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); // shouldn't happen } //noinspection ReturnOfNull return null; // only if it threw an exception. }
private Variation createInstance(String className) { try { return (Variation) Class.forName(className).newInstance(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }
public void processAction(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("processing test driver request ... "); processParams(request); boolean status = false; System.out.println("tc:" + tc); response.setContentType("text/plain"); ServletOutputStream out = response.getOutputStream(); out.println("TestCase: " + tc); if (tc != null) { try { Class<?> c = getClass(); Object t = this; Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { String mname = m.getName(); if (!mname.equals(tc.trim())) { continue; } System.out.println("Invoking : " + mname); try { m.setAccessible(true); Object o = m.invoke(t); System.out.println("Returned => " + (Boolean) o); status = new Boolean((Boolean) o).booleanValue(); // Handle any methods thrown by method to be invoked } catch (InvocationTargetException x) { Throwable cause = x.getCause(); System.err.format("invocation of %s failed: %s%n", mname, cause.getMessage()); } catch (IllegalAccessException x) { x.printStackTrace(); } } } catch (Exception ex) { ex.printStackTrace(); } if (status) { out.println(tc + ":pass"); } else { out.println(tc + ":fail"); } } }
private List<String> getActions() { List<String> actions = new ArrayList<String>(); for (Field field : UserAdmin.class.getDeclaredFields()) { if (field.getName().startsWith("CMD_ACTION_")) { try { actions.add(field.get(new UserAdmin()).toString()); } catch (IllegalAccessException e) { e.printStackTrace(); } } } return actions; }
@Nullable static ClassLoader createPluginClassLoader( @NotNull File[] classPath, @NotNull ClassLoader[] parentLoaders, @NotNull IdeaPluginDescriptor pluginDescriptor) { if (pluginDescriptor.getUseIdeaClassLoader()) { try { final ClassLoader loader = PluginManagerCore.class.getClassLoader(); final Method addUrlMethod = getAddUrlMethod(loader); for (File aClassPath : classPath) { final File file = aClassPath.getCanonicalFile(); addUrlMethod.invoke(loader, file.toURI().toURL()); } return loader; } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } PluginId pluginId = pluginDescriptor.getPluginId(); File pluginRoot = pluginDescriptor.getPath(); // if (classPath.length == 0) return null; if (isUnitTestMode()) return null; try { final List<URL> urls = new ArrayList<URL>(classPath.length); for (File aClassPath : classPath) { final File file = aClassPath .getCanonicalFile(); // it is critical not to have "." and ".." in classpath // elements urls.add(file.toURI().toURL()); } return new PluginClassLoader( urls, parentLoaders, pluginId, pluginDescriptor.getVersion(), pluginRoot); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
public static Object newInstance(Class clazz) throws FacesException { try { return clazz.newInstance(); } catch (NoClassDefFoundError e) { log.error("Class : " + clazz.getName() + " not found.", e); throw new FacesException(e); } catch (InstantiationException e) { log.error(e.getMessage(), e); throw new FacesException(e); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new FacesException(e); } }
/** * Examines a property's type to see which method should be used to parse the property's value. * * @param desc The description of the property * @param element The XML element containing the property value * @return The value stored in the element * @throws IOException If there is an error reading the document */ public Object getObjectValue(PropertyDescriptor desc, Element element) throws IOException { // Find out what kind of property it is Class type = desc.getPropertyType(); // If it's an array, get the base type if (type.isArray()) { type = type.getComponentType(); } // For native types, object wrappers for natives, and strings, use the // basic parse routine if (type.equals(Integer.TYPE) || type.equals(Long.TYPE) || type.equals(Short.TYPE) || type.equals(Byte.TYPE) || type.equals(Boolean.TYPE) || type.equals(Float.TYPE) || type.equals(Double.TYPE) || Integer.class.isAssignableFrom(type) || Long.class.isAssignableFrom(type) || Short.class.isAssignableFrom(type) || Byte.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type) || Float.class.isAssignableFrom(type) || Double.class.isAssignableFrom(type) || String.class.isAssignableFrom(type)) { return readBasicType(type, element); } else if (java.util.Date.class.isAssignableFrom(type)) { // If it's a date, use the date parser return readDate(element); } else { try { // If it's an object, create a new instance of the object (it should // be a bean, or there will be trouble) Object newOb = type.newInstance(); // Copy the XML element into the bean readObject(newOb, element); return newOb; } catch (InstantiationException exc) { throw new IOException( "Error creating object for " + desc.getName() + ": " + exc.toString()); } catch (IllegalAccessException exc) { throw new IOException( "Error creating object for " + desc.getName() + ": " + exc.toString()); } } }
public static void setStatsMap(HashMap<String, TableStats> s) { try { java.lang.reflect.Field statsMapF = TableStats.class.getDeclaredField("statsMap"); statsMapF.setAccessible(true); statsMapF.set(null, s); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
/** * Try to execute given method on given object. Handles invocation target exceptions. XXX nearly * duplicates tryMethod in JGEngine. * * @return null means method does not exist or returned null/void */ static Object tryMethod(Object o, String name, Object[] args) { try { Method met = JREEngine.getMethod(o.getClass(), name, args); if (met == null) return null; return met.invoke(o, args); } catch (InvocationTargetException ex) { Throwable ex_t = ex.getTargetException(); ex_t.printStackTrace(); return null; } catch (IllegalAccessException ex) { System.err.println("Unexpected exception:"); ex.printStackTrace(); return null; } }
public E getE() { if (e == null) { // 这是使用泛型没有办法之举:ERROR InstantiatingNullHandler Could not create // and/or set value back on to object // at // com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:169) try { e = this.getEntityClass().newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } return e; }
public Y call(X value) { Class cls = value.getClass(); try { Field f = cls.getField(fieldName); return (Y) f.get(value); } catch (SecurityException e) { e.printStackTrace(); throw new IllegalStateException(); } catch (NoSuchFieldException e) { e.printStackTrace(); throw new IllegalStateException(); } catch (IllegalAccessException e) { e.printStackTrace(); throw new IllegalStateException(); } }
/* ------------------------------------------------------------ */ public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException { if (log.isDebugEnabled()) log.debug("getAttribute " + name); Method getter = (Method) _getter.get(name); if (getter == null) throw new AttributeNotFoundException(name); try { Object o = _object; if (getter.getDeclaringClass().isInstance(this)) o = this; return getter.invoke(o, (java.lang.Object[]) null); } catch (IllegalAccessException e) { log.warn(LogSupport.EXCEPTION, e); throw new AttributeNotFoundException(e.toString()); } catch (InvocationTargetException e) { log.warn(LogSupport.EXCEPTION, e); throw new ReflectionException((Exception) e.getTargetException()); } }