List of usage examples for java.lang NoSuchMethodException getMessage
public String getMessage()
From source file:org.silverpeas.dbbuilder.DBBuilderPiece.java
public void executeJavaInvoke(String currentInstruction, Object myClass) throws Exception { if (traceMode) { console.printMessage("\t\t>" + myClass.getClass().getName() + '.' + currentInstruction + "()"); }/*from w ww. j a v a 2 s. co m*/ ((DbBuilderDynamicPart) myClass).setConnection(connection); Method methode; try { methode = myClass.getClass().getMethod(currentInstruction); } catch (NoSuchMethodException e) { throw new Exception("No method \"" + currentInstruction + "\" defined for \"" + myClass.getClass().getName() + "\" class.", e); } catch (SecurityException e) { throw new Exception("No method \"" + currentInstruction + "\" defined for \"" + myClass.getClass().getName() + "\" class.", e); } try { methode.invoke(myClass); } catch (Exception e) { throw new Exception("\n\t\t***ERROR RETURNED BY THE JVM : " + e.getMessage(), e); } }
From source file:org.dspace.rest.providers.AbstractBaseProvider.java
public void deleteEntity(EntityReference ref, Map<String, Object> params) { String segments[] = getSegments(params); String action = ""; Map<String, Object> inputVar = new HashMap<String, Object>(); for (int x = 0; x < segments.length; x++) { switch (x) { case 1:/*from w w w .j a va 2s . com*/ inputVar.put("base", segments[x]); break; case 2: inputVar.put("id", segments[x]); break; case 3: inputVar.put("element", segments[x]); break; case 4: String s = segments[x]; if (s != null && !"".equals(s)) { if (s.lastIndexOf(".") > 0) { s = s.substring(0, s.lastIndexOf(".")); } } inputVar.put("eid", s); break; case 5: inputVar.put("trail", segments[x]); break; default: break; } } if (segments.length > 3) { action = segments[3]; } if (func2actionMapDELETE_rev.containsKey(action)) { String function = getMethod(action, func2actionMapDELETE_rev); if (function == null) { throw new EntityException("Bad request", "Method not supported - not defined", 400); } Context context = null; try { context = new Context(); refreshParams(context); Object CE = entityConstructor.newInstance(); Method method = CE.getClass().getMethod(function, funcParamsDELETE.get(action)); method.invoke(CE, ref, inputVar, context); } catch (NoSuchMethodException ex) { log.error(ex.getMessage(), ex); throw new EntityException("Not found", "Meethod not supported " + segments[3], 404); } catch (SQLException ex) { log.error(ex.getMessage(), ex); throw new EntityException("Internal server error", "SQL error", 500); } catch (InvocationTargetException ex) { if (ex.getCause() != null) { log.error(ex.getCause(), ex.getCause()); throw new EntityException(ex.getCause().toString(), "Invocation Target Exception", 500); } else { log.error(ex.getMessage(), ex); throw new EntityException("Internal server error", "Unknown error", 500); } } catch (Exception ex) { log.error(ex.getMessage(), ex); throw new EntityException("Internal server error", "Unknown error", 500); } finally { removeConn(context); } } else { throw new EntityException("Bad request", "Method not supported " + action, 400); } }
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
private boolean buildMethodsByReflection() { try {/*from w w w . j a v a 2s . c om*/ notificationBuilderConstructor = notificationBuilderClass.getDeclaredConstructor(Context.class); setContentTitleMethod = notificationBuilderClass.getDeclaredMethod("setContentTitle", CharSequence.class); setContentTextMethod = notificationBuilderClass.getDeclaredMethod("setContentText", CharSequence.class); setContentIntent = notificationBuilderClass.getDeclaredMethod("setContentIntent", PendingIntent.class); setStyleMethod = notificationBuilderClass.getDeclaredMethod("setStyle", notificationStyleClass); setSmallIconResIdMethod = notificationBuilderClass.getDeclaredMethod("setSmallIcon", int.class); buildMethod = notificationBuilderClass.getDeclaredMethod("build"); bigTextMethod = notificationBigTextStyleClass.getDeclaredMethod("bigText", CharSequence.class); bigPictureMethod = notificationBigPictureStyleClass.getDeclaredMethod("bigPicture", Bitmap.class); setSummaryMethod = notificationBigPictureStyleClass.getDeclaredMethod("setSummaryText", CharSequence.class); setLargeIconMethod = notificationBuilderClass.getDeclaredMethod("setLargeIcon", Bitmap.class); setPriorityMethod = notificationBuilderClass.getDeclaredMethod("setPriority", int.class); setSoundMethod = notificationBuilderClass.getDeclaredMethod("setSound", Uri.class); if (android.os.Build.VERSION.SDK_INT >= ANDROID_MARSHMALLOW) { setSmallIconMethod = notificationBuilderClass.getDeclaredMethod("setSmallIcon", iconClass); createWithBitmapMethod = iconClass.getDeclaredMethod("createWithBitmap", Bitmap.class); } return true; } catch (final NoSuchMethodException ex) { log.debug("Failed to get notification builder methods by reflection. : " + ex.getMessage(), ex); return false; } }
From source file:edu.harvard.mcz.imagecapture.loader.FieldLoader.java
/** * Give a barcode number and an arbitrary set of fields in Specimen, attempt to set the values for those fields for a record. * // w ww .j a v a 2 s .co m * @param barcode field, must match on exactly one Specimen record. * @param data map of field names and data values * @param questions value to append to this field in Specimen. * @param newWorkflowStatus to set Specimen.workflowStatus to. * @param allowUpdateExistingVerbatim if true can load can overwrite the value in an existing verbatim field. * * @return true if one or more fields were updated. * * @throws LoadException on an error (particularly from inability to map keys in data to fields in Specimen. */ public boolean loadFromMap(String barcode, Map<String, String> data, String newWorkflowStatus, boolean allowUpdateExistingVerbatim) throws LoadException { boolean result = false; log.debug(barcode); ArrayList<String> knownFields = new ArrayList<String>(); HashMap<String, String> knownFieldsLowerUpper = new HashMap<String, String>(); Method[] specimenMethods = Specimen.class.getDeclaredMethods(); for (int j = 0; j < specimenMethods.length; j++) { if (specimenMethods[j].getName().startsWith("set") && specimenMethods[j].getParameterTypes().length == 1 && specimenMethods[j].getParameterTypes()[0].getName().equals(String.class.getName())) { String actualCase = specimenMethods[j].getName().replaceAll("^set", ""); knownFields.add(specimenMethods[j].getName().replaceAll("^set", "")); knownFieldsLowerUpper.put(actualCase.toLowerCase(), actualCase); } } // List of input fields that will need to be parsed into relational tables ArrayList<String> toParseFields = new ArrayList<String>(); toParseFields.add("collectors"); toParseFields.add("numbers"); // Check that the proposed new state is allowed. if (newWorkflowStatus == null || (!newWorkflowStatus.equals(WorkFlowStatus.STAGE_VERBATIM) && !newWorkflowStatus.equals(WorkFlowStatus.STAGE_CLASSIFIED))) { throw new LoadException("Trying to load into unallowed new state." + newWorkflowStatus); } // Retrieve existing record for update (thus not blanking existing fields, and allowing for not updating fields with values, or appending comments). List<Specimen> matches = sls.findByBarcode(barcode); if (matches != null && matches.size() == 1) { Specimen match = matches.get(0); if ((newWorkflowStatus.equals(WorkFlowStatus.STAGE_VERBATIM) && !WorkFlowStatus.allowsVerbatimUpdate(match.getWorkFlowStatus())) || (newWorkflowStatus.equals(WorkFlowStatus.STAGE_CLASSIFIED) && !WorkFlowStatus.allowsClassifiedUpdate(match.getWorkFlowStatus()))) { // The target Specimen record has moved on past the state where it can be altered by a data load. throw new LoadTargetMovedOnException(barcode + " is in state " + match.getWorkFlowStatus() + " and can't be altered by this data load."); } else { // Target Specimen record is eligible to be updated by a data load. boolean foundData = false; boolean hasChange = false; boolean hasExternalWorkflowProcess = false; boolean hasExternalWorkflowDate = false; Iterator<String> i = data.keySet().iterator(); String separator = ""; StringBuilder keys = new StringBuilder(); while (i.hasNext()) { String keyOrig = i.next(); String key = keyOrig.toLowerCase(); String actualCase = knownFieldsLowerUpper.get(key); if (toParseFields.contains(key) || (actualCase != null && knownFields.contains(actualCase) && !key.equals("barcode") && MetadataRetriever.isFieldExternallyUpdatable(Specimen.class, key))) { String datavalue = data.get(keyOrig); keys.append(separator).append(key); separator = ","; Method setMethod; try { if (key.equals("collectors")) { // Special case, parse collectors to associated Collector table. datavalue = datavalue + "|"; String[] collectors = datavalue.split("\\|", 0); log.debug(collectors.length); for (int j = 0; j < collectors.length; j++) { String collector = collectors[j]; log.debug(collector); if (collector.trim().length() > 0) { // Check to see if Collector exists Set<Collector> existingCollectors = match.getCollectors(); Iterator<Collector> ic = existingCollectors.iterator(); boolean exists = false; while (ic.hasNext()) { Collector c = ic.next(); if (c.getCollectorName().equals(collector)) { exists = true; } } if (!exists) { // only add if it isn't allready present. Collector col = new Collector(); col.setSpecimen(match); col.setCollectorName(collector); CollectorLifeCycle cls = new CollectorLifeCycle(); cls.persist(col); match.getCollectors().add(col); foundData = true; hasChange = true; } } } } else if (key.toLowerCase().equals("numbers")) { // Special case, parse numbers to associated Number table. datavalue = datavalue + "|"; String[] numbers = datavalue.split("\\|", 0); for (int j = 0; j < numbers.length; j++) { String numberKV = numbers[j]; if (numberKV.trim().length() > 0) { String number = numberKV; String numType = "unknown"; if (numberKV.contains(":")) { String[] numbits = numberKV.split(":", 0); number = numbits[0]; numType = numbits[1]; if (numType == null || numType.trim().length() == 0) { numType = "unknown"; } } // check to see if number exists Set<Number> existingNumbers = match.getNumbers(); Iterator<Number> ic = existingNumbers.iterator(); boolean exists = false; while (ic.hasNext()) { Number c = ic.next(); if (c.getNumber().equals(number) || c.getNumberType().equals(numType)) { exists = true; } } if (!exists) { NumberLifeCycle nls = new NumberLifeCycle(); // only add if it isn't already present. Number num = new Number(); num.setNumber(number); num.setNumberType(numType); num.setSpecimen(match); nls.persist(num); hasChange = true; match.getNumbers().add(num); foundData = true; } } } } else { // Find the Specimen get and set methods for the current key setMethod = Specimen.class.getMethod("set" + actualCase, String.class); Method getMethod = Specimen.class.getMethod("get" + actualCase, null); // Obtain the current value in the Specimen record for the field matching the current key. String currentValue = (String) getMethod.invoke(match, null); // Assess whether changes to existing data are allowed for that field, // make changes only if they are allowed. if (key.equals("externalworkflowprocess")) { hasExternalWorkflowProcess = true; } if (key.equals("externalworkflowdate")) { hasExternalWorkflowDate = true; } if (key.equals("questions")) { // append if (currentValue != null && currentValue.trim().length() > 0) { datavalue = currentValue + " | " + datavalue; } setMethod.invoke(match, datavalue); foundData = true; hasChange = true; } else if (key.equals("externalworkflowprocess") || key.equals("externalworkflowdate") || key.equals("verbatimclusteridentifier")) { // overwrite existing metadata setMethod.invoke(match, datavalue); foundData = true; hasChange = true; } else { if (currentValue == null || currentValue.trim().length() == 0) { // Handle ISO date formatting variants if (key.equalsIgnoreCase("ISODate")) { EventResult parseResult = DateUtils .extractDateFromVerbatimER(datavalue); if (parseResult.getResultState() .equals(EventResult.EventQCResultState.DATE) || parseResult.getResultState() .equals(EventResult.EventQCResultState.RANGE)) { datavalue = parseResult.getResult(); } } // overwrite verbatim fields if update is allowed, otherwise no overwite of existing data. log.debug("Set: " + actualCase + " = " + datavalue); setMethod.invoke(match, datavalue); foundData = true; } else if (MetadataRetriever.isFieldVerbatim(Specimen.class, key) && allowUpdateExistingVerbatim) { setMethod.invoke(match, datavalue); foundData = true; hasChange = true; } else { log.error("Skipped set" + actualCase + " = " + datavalue); } } } } catch (NoSuchMethodException e) { throw new LoadException(e.getMessage(), e); } catch (SaveFailedException e) { throw new LoadException(e.getMessage(), e); } catch (SecurityException e) { log.error(e.getMessage(), e); throw new LoadException(e.getMessage()); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new LoadException(e.getMessage()); } catch (IllegalArgumentException e) { log.error(e.getMessage(), e); throw new LoadException(e.getMessage()); } catch (InvocationTargetException e) { log.error(e.getMessage(), e); throw new LoadException(e.getMessage(), e); } } else { log.error("Key: " + key); log.error("Key (actual case of method): " + actualCase); log.error("knownFields.contains(actualCase): " + knownFields.contains(actualCase)); log.error("toParseFields.contains(key): " + toParseFields.contains(key)); log.error("isFieldExternallyUpdatable:" + MetadataRetriever.isFieldExternallyUpdatable(Specimen.class, key)); throw new LoadException( "Column " + key + " is not an externally updateable field of Specimen."); } } if (foundData) { try { // save the updated specimen record match.setWorkFlowStatus(newWorkflowStatus); log.debug("Updating:" + match.getBarcode()); sls.attachDirty(match); result = hasChange; // If we were provided String ewProcess = "ArbitraryFieldLoad:" + match.getWorkFlowStatus() + ":" + keys.toString(); if (hasExternalWorkflowProcess) { ewProcess = match.getExternalWorkflowProcess(); } Date ewDate = new Date(); if (hasExternalWorkflowDate) { ewDate = match.getExternalWorkflowDate(); } logHistory(match, ewProcess, ewDate); } catch (SaveFailedException e) { log.error(e.getMessage(), e); throw new LoadTargetSaveException(); } } } } return result; }
From source file:com.espertech.esper.event.bean.BeanEventType.java
public EventBeanCopyMethod getCopyMethod(String[] properties) { if (copyMethodName == null) { if (JavaClassHelper.isImplementsInterface(clazz, Serializable.class)) { return new BeanEventBeanSerializableCopyMethod(this, eventAdapterService); }//from w ww . j av a 2s . c om return null; } Method method = null; try { method = clazz.getMethod(copyMethodName); } catch (NoSuchMethodException e) { log.error("Configured copy-method for class '" + clazz.getName() + " not found by name '" + copyMethodName + "': " + e.getMessage()); } if (method == null) { if (JavaClassHelper.isImplementsInterface(clazz, Serializable.class)) { return new BeanEventBeanSerializableCopyMethod(this, eventAdapterService); } throw new EPException("Configured copy-method for class '" + clazz.getName() + " not found by name '" + copyMethodName + "' and class does not implement Serializable"); } return new BeanEventBeanConfiguredCopyMethod(this, eventAdapterService, fastClass.getMethod(method)); }
From source file:org.sakaiproject.webservices.SakaiConfiguration.java
protected String getValueFromBean(String propName) { String beanName = propName.trim().split("@")[1]; Object bean = ComponentManager.get(beanName.trim()); if (bean != null) { String methodName = propName.trim().split("@")[0]; Class clazz = bean.getClass(); String methodNameEnd = Character.toUpperCase(methodName.charAt(0)) + methodName.substring(1); Method method = null;/* www. j a va 2 s . c o m*/ try { method = clazz.getMethod("get" + methodNameEnd, null); } catch (NoSuchMethodException e) { LOG.info("can't find method called " + " get" + methodNameEnd + " in class " + clazz.getName()); try { method = clazz.getMethod("is" + methodNameEnd, null); } catch (NoSuchMethodException e1) { LOG.info("can't find method called " + " is" + methodNameEnd + " in class " + clazz.getName()); } } if (method != null) { try { Object returnValue = method.invoke(bean, null); return returnValue.toString(); } catch (Exception e) { LOG.error("error calling accessor on bean :" + beanName + " msg: " + e.getMessage(), e); } } LOG.error("couldn't find config value for propName: " + propName); } else { LOG.error("can't find bean with id: " + beanName); } return null; }
From source file:org.mypsycho.beans.Injection.java
/** * Inject the content of this branch into the bean. * * @param type the type of collection if applicable * @param bean the object of inject//from www . j a v a2 s.co m * @param context injection context */ public void inject(Class<?> type, Object bean, InjectionContext context) { try { switch (nature) { case SIMPLE: injectSimple(bean, context); break; case MAPPED: case INDEXED: injectCollection(type, bean, context); break; default: throw new IllegalStateException("Unexpected nature " + nature); } } catch (NoSuchMethodException e) { Inject inject = bean.getClass().getAnnotation(Inject.class); if ((inject != null) && inject.deferred().length > 0) { if (Arrays.asList(inject.deferred()).contains(id)) { return; } } if (ATTRIBUT_PATTERN.matcher("" + id).matches()) { getInjector().notify(getCanonicalName(), e.getMessage(), e); } } catch (Exception e) { Throwable cause = e; while (cause instanceof InvocationTargetException) { cause = ((InvocationTargetException) cause).getTargetException(); } if (cause instanceof Error) { throw (Error) cause; } getInjector().notify(getCanonicalName(), cause.getMessage(), cause); } }
From source file:org.bbsync.webservice.client.proxytool.ContextProxyTool.java
/** * This method will instantiate a client Stub object from a Stub class * template and a web service URL using the existing ConfigurationContext. * /* w w w .jav a2s .co m*/ * @param client_stub - the class template used to determine the appropriate object * to instantiate. * @param service_url - the location of the server-side web service. * * @return Returns a client Stub object based on the parameters provided. */ protected Stub createClientWS(Class<? extends Stub> client_stub, String service_url) { Stub wsStub = null; //we're creating a generic class array and loading it with our 2 constructor object Classes Class<?>[] constructor_params = { ConfigurationContext.class, String.class }; try { //we're creating a parameterized constructor for a class that extends Stub. Constructor<? extends Stub> constructor = client_stub.getConstructor(constructor_params); //now we're instantiating the the actual subclass using the constructor that we just created. wsStub = constructor.newInstance(ctx, service_url); } catch (NoSuchMethodException e) { logger.error("Unable to create the client web service stub object: " + e.getMessage()); return null; } catch (SecurityException e) { logger.error("Unable to create the client web service stub object: " + e.getMessage()); return null; } catch (InstantiationException e) { logger.error("Unable to create the client web service stub object: " + e.getMessage()); return null; } catch (IllegalAccessException e) { logger.error("Unable to create the client web service stub object: " + e.getMessage()); return null; } catch (IllegalArgumentException e) { logger.error("Unable to create the client web service stub object: " + e.getMessage()); return null; } catch (InvocationTargetException e) { logger.error("Unable to create the client web service stub class: " + e.getMessage()); return null; } return wsStub; }
From source file:org.photovault.swingui.PhotoInfoEditor.java
/** Set the multivalued state of given field @param field Field to set//from ww w .j a va2s. c o m @param isMultivalued If <code>null, set the field to multivalued state. If not, set it to normal state */ public void setFieldMultivalued(PhotoInfoFields field, boolean isMultivalued) { String propertyName = field.getName() + "Multivalued"; try { PropertyUtils.setProperty(this, propertyName, isMultivalued); } catch (NoSuchMethodException ex) { log.error("Cannot set property " + propertyName); ex.printStackTrace(); } catch (IllegalAccessException ex) { log.error(ex.getMessage()); } catch (InvocationTargetException ex) { log.error(ex.getMessage()); } }
From source file:org.photovault.swingui.PhotoInfoEditor.java
public void setField(PhotoInfoFields field, Object newValue) { StringBuffer debugMsg = new StringBuffer(); debugMsg.append("setField ").append(field).append(": ").append(newValue); log.debug(debugMsg.toString());//from www . j av a2 s. c om String propertyName = field.getName(); try { PropertyUtils.setProperty(this, propertyName, newValue); } catch (NoSuchMethodException ex) { log.error("Cannot set property " + propertyName); ex.printStackTrace(); } catch (IllegalAccessException ex) { log.error(ex.getMessage()); } catch (InvocationTargetException ex) { log.error(ex.getMessage()); } }