Example usage for java.lang NoSuchMethodException getMessage

List of usage examples for java.lang NoSuchMethodException getMessage

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.frat.common.exception.AbstractExceptionHandler.java

private String getJsonNameFromMethod(final Field errorField, Class<?> dtoClass) {
    /** find annotation from get/set method........ **/
    String methodName = "set" + errorField.getName().substring(0, 1).toUpperCase()
            + errorField.getName().substring(1);
    try {/*from ww  w.  ja va 2s .c  o m*/
        Method method = dtoClass.getDeclaredMethod(methodName, errorField.getType());
        method.setAccessible(true);
        JsonProperty jsonProperty2 = method.getAnnotation(JsonProperty.class);
        if (jsonProperty2 != null) {
            String jp = jsonProperty2.value();
            LOGGER.debug("JsonProperty from SetMethod ===== " + jp);
            return jp;
        }
    } catch (NoSuchMethodException e) {
        LOGGER.debug("NoSuchMethodException {}, try to get JsonProperty from super class", methodName);
        try {
            /**
             * Get JsonProperty from super class. It is only a simple
             * implementation base on one assumption that super class should
             * exist this field. It does not process recursion.
             * **/
            Method method = dtoClass.getSuperclass().getDeclaredMethod(methodName, errorField.getType());
            method.setAccessible(true);
            JsonProperty jsonProperty2 = method.getAnnotation(JsonProperty.class);
            if (jsonProperty2 != null) {
                String jp = jsonProperty2.value();
                LOGGER.debug("JsonProperty from Super {} `s SetMethod ===== {} ", dtoClass.getSuperclass(), jp);
                return jp;
            }
        } catch (Exception ex) { // NOSONAR
            LOGGER.debug(e.getMessage());
        }
    } catch (SecurityException e) {
        LOGGER.debug(e.getMessage());
    }
    return null;
}

From source file:com.tesora.dve.tools.CLIBuilder.java

public void parseLine(String line) {
    if (StringUtils.isBlank(line)) {
        return;/*from w w w. j a  v a 2s  . co m*/
    }

    final CommandType command = findCommand(line);

    if (command != null) {

        // We need to create a new scanner based on the command we found.
        try (final Scanner scanner = new Scanner(line)) {

            // And skip the length of the command to get to the args.
            for (int i = 0; i < command.getCmdLength(); i++) {
                scanner.next();
            }

            // Try the currentCommandMap first to map this command to a method name.
            String methodName = currentCommandMap.buildMethodName(command);

            if (methodName == null) {
                methodName = globalCommandMap.buildMethodName(command);
            }

            try {
                final Class<? extends CLIBuilder> cls = this.getClass();

                try {
                    final Method method = cls.getMethod(methodName);
                    method.invoke(this);
                } catch (final NoSuchMethodException e) {
                    final Method method = cls.getMethod(methodName, Scanner.class);
                    method.invoke(this, scanner);
                }
            } catch (final NoSuchMethodException nsme) {
                println("Error: Failed to locate method for '" + methodName + "'");
                returnCode = 3;
            } catch (final Throwable e) {
                println("Error: Failed to execute '" + line + "'"
                        + (e.getMessage() != null ? " - " + e.getMessage() : ""));
                final Throwable cause = e.getCause();
                if (cause != null) {
                    printlnIndent("Caused by: " + cause.getMessage());
                    if (debugMode && (printStream != null)) {
                        cause.printStackTrace(printStream);
                    }
                }
                returnCode = 2;
            }
        }
    } else {
        println("Error: Failed to find matching command for '" + line + "'");
        returnCode = 1;
    }
}

From source file:org.o3project.odenos.core.manager.ComponentManager2.java

protected Response getComponentTypes() {
    Map<String, ComponentType> compTypes = new HashMap<>();

    for (String cmType : classList.keySet()) {
        RemoteObject component = null;
        String objectId = String.format("%s_%s", this.getObjectId(), cmType);
        try {//from w  w  w  .  j  a  v a  2  s.  c  o m
            Class<? extends RemoteObject> componentClass = classList.get(cmType);
            Constructor<? extends RemoteObject> ct = null;
            try {
                ct = componentClass.getConstructor(String.class, MessageDispatcher.class);
                component = ct.newInstance(objectId, null);
            } catch (NoSuchMethodException e) {
                ct = componentClass.getConstructor(String.class, String.class, MessageDispatcher.class);
                component = ct.newInstance(objectId, objectProperty.getBaseUri(), null);
            }
            ObjectProperty objProp = component.getProperty();
            String type = objProp.getProperty(ObjectProperty.PropertyNames.OBJECT_TYPE);
            String superType = objProp.getProperty(ObjectProperty.PropertyNames.OBJECT_SUPER_TYPE);

            Map<String, String> connectionTypes = new HashMap<>();
            String connectionTypesStr = objProp.getProperty(ObjectProperty.PropertyNames.CONNECTION_TYPES);
            String[] connStrList = connectionTypesStr.split(",");
            for (String connTypeElem : connStrList) {
                String[] connTypeElemList = connTypeElem.split(":");
                if (connTypeElemList.length == 2) {
                    connectionTypes.put(connTypeElemList[0], connTypeElemList[1]);
                }
            }

            String description = objProp.getProperty(ObjectProperty.PropertyNames.DESCRIPTION);
            compTypes.put(type, new ComponentType(type, superType, connectionTypes, description));
        } catch (Exception e) {
            return new Response(Response.INTERNAL_SERVER_ERROR, e.getMessage());
        }
    }
    return new Response(Response.OK, compTypes);
}

From source file:com.viettel.vfw5.base.dao.BaseFWDAOImpl.java

@Transactional
public String saveListUpdateCondition(List<T> obj, String methodName) {

    try {/*from w  ww.j  a  v  a2  s .c o  m*/
        session = getSession(); // tiepnv6 edit 27/07/15 16h:51
        for (T item : obj) {
            session.saveOrUpdate(item);
        }

        Class c = obj.get(0).getClass();
        Method method = null;
        try {
            method = c.getMethod("get" + StringUtils.upperFirstChar(methodName));
        } catch (NoSuchMethodException ex) {
            java.util.logging.Logger.getLogger(BaseFWDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            java.util.logging.Logger.getLogger(BaseFWDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

        for (T item : obj) {
            String value;
            try {
                value = String.valueOf(method.invoke(item));

            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                return ParamUtils.ERROR;
            }

            if (value == "null") {
                getSession().saveOrUpdate(item);
            } else {
                getSession().update(item);
            }
        }
    } catch (SecurityException ex) {
        return ex.getMessage();
    }
    return ParamUtils.SUCCESS;

}

From source file:org.broadinstitute.sting.commandline.ArgumentTypeDescriptor.java

/**
 *
 * @param value The source of the binding
 * @param parameterType The Tribble Feature parameter type
 * @param bindingClass The class type for the binding (ex: RodBinding, IntervalBinding, etc.) Must have the correct constructor for creating the binding.
 * @param bindingName The name of the binding passed to the constructor.
 * @param tags Tags for the binding used for parsing and passed to the constructor.
 * @param fieldName The name of the field that was parsed. Used for error reporting.
 * @return The newly created binding object of type bindingClass.
 */// w  w  w.j a va 2  s .  co m
public static Object parseBinding(ArgumentMatchValue value, Class<? extends Feature> parameterType,
        Type bindingClass, String bindingName, Tags tags, String fieldName) {
    try {
        String tribbleType = null;
        // must have one or two tag values here
        if (tags.getPositionalTags().size() > 2) {
            throw new UserException.CommandLineException(String.format(
                    "Unexpected number of positional tags for argument %s : %s. "
                            + "Rod bindings only support -X:type and -X:name,type argument styles",
                    value.asString(), fieldName));
        } else if (tags.getPositionalTags().size() == 2) {
            // -X:name,type style
            bindingName = tags.getPositionalTags().get(0);
            tribbleType = tags.getPositionalTags().get(1);

            FeatureManager manager = new FeatureManager();
            if (manager.getByName(tribbleType) == null)
                throw new UserException.UnknownTribbleType(tribbleType,
                        String.format(
                                "Unable to find tribble type '%s' provided on the command line. "
                                        + "Please select a correct type from among the supported types:%n%s",
                                tribbleType, manager.userFriendlyListOfAvailableFeatures(parameterType)));

        } else {
            // case with 0 or 1 positional tags
            FeatureManager manager = new FeatureManager();

            // -X:type style is a type when we cannot determine the type dynamically
            String tag1 = tags.getPositionalTags().size() == 1 ? tags.getPositionalTags().get(0) : null;
            if (tag1 != null) {
                if (manager.getByName(tag1) != null) // this a type
                    tribbleType = tag1;
                else
                    bindingName = tag1;
            }

            if (tribbleType == null) {
                // try to determine the file type dynamically
                File file = value.asFile();
                if (file.canRead() && file.isFile()) {
                    FeatureManager.FeatureDescriptor featureDescriptor = manager.getByFiletype(file);
                    if (featureDescriptor != null) {
                        tribbleType = featureDescriptor.getName();
                        logger.debug("Dynamically determined type of " + file + " to be " + tribbleType);
                    }
                }

                if (tribbleType == null) {
                    // IntervalBinding can be created from a normal String
                    Class rawType = (makeRawTypeIfNecessary(bindingClass));
                    try {
                        return rawType.getConstructor(String.class).newInstance(value.asString());
                    } catch (NoSuchMethodException e) {
                        /* ignore */
                    }

                    if (!file.exists()) {
                        throw new UserException.CouldNotReadInputFile(file, "file does not exist");
                    } else if (!file.canRead() || !file.isFile()) {
                        throw new UserException.CouldNotReadInputFile(file, "file could not be read");
                    } else {
                        throw new UserException.CommandLineException(String.format(
                                "No tribble type was provided on the command line and the type of the file could not be determined dynamically. "
                                        + "Please add an explicit type tag :NAME listing the correct type from among the supported types:%n%s",
                                manager.userFriendlyListOfAvailableFeatures(parameterType)));
                    }
                }
            }
        }

        Constructor ctor = (makeRawTypeIfNecessary(bindingClass)).getConstructor(Class.class, String.class,
                String.class, String.class, Tags.class);
        return ctor.newInstance(parameterType, bindingName, value.asString(), tribbleType, tags);
    } catch (Exception e) {
        if (e instanceof UserException)
            throw ((UserException) e);
        else
            throw new UserException.CommandLineException(String.format(
                    "Failed to parse value %s for argument %s. Message: %s", value, fieldName, e.getMessage()));
    }
}

From source file:org.wso2.carbon.user.core.common.DefaultRealm.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private Object createObjectWithOptions(String className, RealmConfiguration realmConfig, Map properties)
        throws UserStoreException {

    Class[] initClassOpt1 = new Class[] { RealmConfiguration.class, Map.class, ClaimManager.class,
            ProfileConfigurationManager.class, UserRealm.class, Integer.class };
    Object[] initObjOpt1 = new Object[] { realmConfig, properties, claimMan, null, this, tenantId };

    Class[] initClassOpt2 = new Class[] { RealmConfiguration.class, Map.class, ClaimManager.class,
            ProfileConfigurationManager.class, UserRealm.class };
    Object[] initObjOpt2 = new Object[] { realmConfig, properties, claimMan, null, this };

    Class[] initClassOpt3 = new Class[] { RealmConfiguration.class, Map.class };
    Object[] initObjOpt3 = new Object[] { realmConfig, properties };

    try {//  w  w w .  ja  va  2s  . co  m
        Class clazz = Class.forName(className);
        Constructor constructor = null;
        Object newObject = null;

        if (log.isDebugEnabled()) {
            log.debug("Start initializing class with the first option");
        }

        try {
            constructor = clazz.getConstructor(initClassOpt1);
            newObject = constructor.newInstance(initObjOpt1);
            return newObject;
        } catch (NoSuchMethodException e) {
            // if not found try again.
            if (log.isDebugEnabled()) {
                log.debug("Cannont initialize " + className + " using the option 1");
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("End initializing class with the first option");
        }

        try {
            constructor = clazz.getConstructor(initClassOpt2);
            newObject = constructor.newInstance(initObjOpt2);
            return newObject;
        } catch (NoSuchMethodException e) {
            // if not found try again.
            if (log.isDebugEnabled()) {
                log.debug("Cannont initialize " + className + " using the option 2");
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("End initializing class with the second option");
        }

        try {
            constructor = clazz.getConstructor(initClassOpt3);
            newObject = constructor.newInstance(initObjOpt3);
            return newObject;
        } catch (NoSuchMethodException e) {
            // cannot initialize in any of the methods. Throw exception.
            String message = "Cannot initialize " + className + ". Error " + e.getMessage();
            if (log.isDebugEnabled()) {
                log.debug(message, e);
            }
            throw new UserStoreException(message, e);
        }

    } catch (Throwable e) {
        String errorMessage = "Cannot create " + className;
        if (log.isDebugEnabled()) {
            log.debug(errorMessage, e);
        }
        throw new UserStoreException(e.getMessage() + "Type " + e.getClass(), e);
    }

}

From source file:org.apache.myfaces.config.FacesConfigurator.java

public void update() {
    //Google App Engine does not allow to get last modified time of a file; 
    //and when an application is running on GAE there is no way to update faces config xml file.
    //thus, no need to check if the config file is modified.
    if (ContainerUtils.isRunningOnGoogleAppEngine(_externalContext)) {
        return;/*from   w  ww.j a  va2  s  . co m*/
    }
    long refreshPeriod = (MyfacesConfig.getCurrentInstance(_externalContext).getConfigRefreshPeriod()) * 1000;

    if (refreshPeriod > 0) {
        long ttl = lastUpdate + refreshPeriod;
        if ((System.currentTimeMillis() > ttl) && (getLastModifiedTime() > ttl)) {
            try {
                purgeConfiguration();
            } catch (NoSuchMethodException e) {
                log.severe("Configuration objects do not support clean-up. Update aborted");

                // We still want to update the timestamp to avoid running purge on every subsequent
                // request after this one.
                //
                lastUpdate = System.currentTimeMillis();

                return;
            } catch (IllegalAccessException e) {
                log.severe("Error during configuration clean-up" + e.getMessage());
            } catch (InvocationTargetException e) {
                log.severe("Error during configuration clean-up" + e.getMessage());
            }
            configure();

            // JSF 2.0 Publish PostConstructApplicationEvent after all configuration resources
            // has been parsed and processed
            FacesContext facesContext = getFacesContext();
            Application application = facesContext.getApplication();

            application.publishEvent(facesContext, PostConstructApplicationEvent.class, Application.class,
                    application);
        }
    }
}

From source file:com.odoo.orm.OModel.java

/**
 * Check for functional column./*  w  ww  .  j a v a 2s  . c om*/
 * 
 * @param field
 *            the field
 * @return the method
 */
private Method checkForFunctionalColumn(Field field) {
    Annotation annotation = field.getAnnotation(Odoo.Functional.class);
    if (annotation != null) {
        Odoo.Functional functional = (Functional) annotation;
        String method_name = functional.method();
        try {
            if (functional.store())
                return getClass().getMethod(method_name, OValues.class);
            else
                return getClass().getMethod(method_name, ODataRow.class);
        } catch (NoSuchMethodException e) {
            Log.e(TAG, "No Such Method: " + e.getMessage());
        }
    }
    return null;
}

From source file:com.impetus.ankush2.framework.monitor.AbstractMonitor.java

public void monitor(Cluster cluster, String action, Map parameterMap) {
    this.dbCluster = cluster;
    this.parameterMap = parameterMap;
    result.clear();//  w w w .  ja v a 2 s  . c o  m
    try {
        this.clusterConf = dbCluster.getClusterConfig();
        Method method = null;
        try {
            // Create method object using the action name.
            method = this.getClass().getDeclaredMethod(action);
        } catch (NoSuchMethodException e) {
            method = this.getClass().getMethod(action);
        } catch (Exception e) {
            throw e;
        }
        // setting accessibility true.
        method.setAccessible(true);
        // invoking the method.
        method.invoke(this);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        if (e.getMessage() != null) {
            addAndLogError(e.getMessage());
        } else {
            addAndLogError(e.getCause().getMessage());
        }
        // Adding and logging error
        addAndLogError("Unable to process request");
    }
}

From source file:org.plasma.sdo.helper.DataConverter.java

private DataConverter() {

    if (javaClassToAllowableTypesMap == null) {
        javaClassToAllowableTypesMap = new HashMap<Class<?>, Map<String, DataType>>();
        for (int i = 0; i < DataType.values().length; i++) {
            DataType dataTypeEnum = DataType.values()[i];

            Class<?> javaClass = toPrimitiveJavaClass(dataTypeEnum);

            Map<String, DataType> allowableMap = new HashMap<String, DataType>();
            List<DataType> list = getAllowableTargetTypes(dataTypeEnum);
            for (DataType allowableType : list)
                allowableMap.put(allowableType.toString(), allowableType);
            javaClassToAllowableTypesMap.put(javaClass, allowableMap);
        }//  w w w .  ja  va  2  s.  co m
    }
    if (javaClassToConverterFromMethodMap == null) {
        javaClassToConverterFromMethodMap = new HashMap<Class<?>, Method>();
        Map<Class<?>, Method> map = javaClassToConverterFromMethodMap;
        try {

            Method method = this.getClass().getMethod("fromBoolean", Type.class, boolean.class);
            map.put(Boolean.class, method);
            map.put(boolean.class, method);

            method = this.getClass().getMethod("fromByte", Type.class, byte.class);
            map.put(Byte.class, method);
            map.put(byte.class, method);

            method = this.getClass().getMethod("fromBytes", Type.class, byte[].class);
            map.put(Byte[].class, method);
            map.put(byte[].class, method);

            method = this.getClass().getMethod("fromCharacter", Type.class, char.class);
            map.put(Character.class, method);
            map.put(char.class, method);

            method = this.getClass().getMethod("fromDate", Type.class, Date.class);
            map.put(Date.class, method);

            method = this.getClass().getMethod("fromDecimal", Type.class, BigDecimal.class);
            map.put(BigDecimal.class, method);

            method = this.getClass().getMethod("fromDouble", Type.class, double.class);
            map.put(Double.class, method);
            map.put(double.class, method);

            method = this.getClass().getMethod("fromFloat", Type.class, float.class);
            map.put(Float.class, method);
            map.put(float.class, method);

            method = this.getClass().getMethod("fromInt", Type.class, int.class);
            map.put(int.class, method);
            map.put(Integer.class, method);

            method = this.getClass().getMethod("fromInteger", Type.class, BigInteger.class);
            map.put(BigInteger.class, method);

            method = this.getClass().getMethod("fromLong", Type.class, long.class);
            map.put(Long.class, method);
            map.put(long.class, method);

            method = this.getClass().getMethod("fromShort", Type.class, short.class);
            map.put(Short.class, method);
            map.put(short.class, method);

            method = this.getClass().getMethod("fromString", Type.class, String.class);
            map.put(String.class, method);

            //Class<?> stringListClass = (java.lang.Class<java.util.List<java.lang.String>>)new ArrayList<java.lang.String>().getClass();              
            method = this.getClass().getMethod("fromStrings", Type.class, List.class);
            map.put(List.class, method);

        } catch (NoSuchMethodException e) {
            log.error(e.getMessage(), e);
        }
    }
}