Example usage for java.lang ClassNotFoundException getLocalizedMessage

List of usage examples for java.lang ClassNotFoundException getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang ClassNotFoundException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.opentaps.common.reporting.ChartViewHandler.java

public void render(String name, String page, String info, String contentType, String encoding,
        HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException {

    /*/*from  w  w  w  .  j  a v  a  2  s  .c  o  m*/
     * Looks for parameter "chart" first. Send this temporary image files
     * to client if it exists and return.
     */
    String chartFileName = UtilCommon.getParameter(request, "chart");
    if (UtilValidate.isNotEmpty(chartFileName)) {
        try {
            ServletUtilities.sendTempFile(chartFileName, response);
            if (chartFileName.indexOf(ServletUtilities.getTempOneTimeFilePrefix()) != -1) {
                // delete temporary file
                File file = new File(System.getProperty("java.io.tmpdir"), chartFileName);
                file.delete();
            }
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * Next option eliminate need to store chart in file system. Some event handler
     * included in request chain prior to this view handler can prepare ready to use
     * instance of JFreeChart and place it to request attribute chartContext.
     * Currently chartContext should be Map<String, Object> and we expect to see in it:
     *   "charObject"       : JFreeChart
     *   "width"            : positive Integer
     *   "height"           : positive Integer
     *   "encodeAlpha"      : Boolean (optional)
     *   "compressRatio"    : Integer in range 0-9 (optional)
     */
    Map<String, Object> chartContext = (Map<String, Object>) request.getAttribute("chartContext");
    if (UtilValidate.isNotEmpty(chartContext)) {
        try {
            sendChart(chartContext, response);
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * Prepare context for next options
     */
    Map<String, Object> callContext = FastMap.newInstance();
    callContext.put("parameters", UtilHttp.getParameterMap(request));
    callContext.put("delegator", request.getAttribute("delegator"));
    callContext.put("dispatcher", request.getAttribute("dispatcher"));
    callContext.put("userLogin", request.getSession().getAttribute("userLogin"));
    callContext.put("locale", UtilHttp.getLocale(request));

    /*
     * view-map attribute "page" may contain BeanShell script in component
     * URL format that should return chartContext map.
     */
    if (UtilValidate.isNotEmpty(page) && UtilValidate.isUrl(page) && page.endsWith(".bsh")) {
        try {
            chartContext = (Map<String, Object>) BshUtil.runBshAtLocation(page, callContext);
            if (UtilValidate.isNotEmpty(chartContext)) {
                sendChart(chartContext, response);
            }
        } catch (GeneralException ge) {
            Debug.logError(ge.getLocalizedMessage(), module);
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * As last resort we can decide that "page" attribute contains class name and "info"
     * contains method Map<String, Object> getSomeChart(Map<String, Object> context).
     * There are parameters, delegator, dispatcher, userLogin and locale in the context.
     * Should return chartContext.
     */
    if (UtilValidate.isNotEmpty(page) && UtilValidate.isNotEmpty(info)) {
        Class handler = null;
        synchronized (this) {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            try {
                handler = loader.loadClass(page);
                if (handler != null) {
                    Method runMethod = handler.getMethod(info, new Class[] { Map.class });
                    chartContext = (Map<String, Object>) runMethod.invoke(null, callContext);
                    if (UtilValidate.isNotEmpty(chartContext)) {
                        sendChart(chartContext, response);
                    }
                }
            } catch (ClassNotFoundException cnfe) {
                Debug.logError(cnfe.getLocalizedMessage(), module);
            } catch (SecurityException se) {
                Debug.logError(se.getLocalizedMessage(), module);
            } catch (NoSuchMethodException nsme) {
                Debug.logError(nsme.getLocalizedMessage(), module);
            } catch (IllegalArgumentException iae) {
                Debug.logError(iae.getLocalizedMessage(), module);
            } catch (IllegalAccessException iace) {
                Debug.logError(iace.getLocalizedMessage(), module);
            } catch (InvocationTargetException ite) {
                Debug.logError(ite.getLocalizedMessage(), module);
            } catch (IOException ioe) {
                Debug.logError(ioe.getLocalizedMessage(), module);
            }
        }
    }

    // Why you disturb me?
    throw new ViewHandlerException(
            "In order to generate chart you have to provide chart object or file name. There are no such data in request. Please read comments to ChartViewHandler class.");
}

From source file:org.jaffa.loader.LifecycleHandlerConfig.java

/**
 * Get list of classes that contain rules with the input name and adds them to transformation handler classes
 * and lifecycle event classes.//from   w w  w .j  a v  a  2 s. c  o m
 */
private void addLifecycleHandlers(String ruleName) {

    // get list of classes that contain rules of the input type
    String[] classNames = MetaDataRepository.instance().getClassNamesByRuleName(ruleName);
    if (classNames == null) {
        return;
    }

    // for each class, try to add the rules to appropriate factory
    for (String className : classNames) {
        try {
            // if class is a transformation handler then add it's rules to the transformationHandlerFactory
            // else if a class is a lifecycle handler then add it's rule to the lifecycleHandlerFactory
            if (ITransformationHandler.class.isAssignableFrom(Class.forName(className))) {
                addHandlerToFactory(className, FactoryType.TransformationHandler, ruleName);
            } else if (ILifecycleHandler.class.isAssignableFrom(Class.forName(className))) {
                addHandlerToFactory(className, FactoryType.LifecycleHandler, ruleName);
            }
        } catch (ClassNotFoundException e) {
            log.debug(e.getLocalizedMessage());
        }
    }
}

From source file:org.jaffa.loader.LifecycleHandlerConfig.java

/**
 * Generates handlers based on the factory type and rule meta data in the rule repository for the supplied
 * class and inserts them into the appropriate factory.
 *
 * @param targetClassName The target Class
 *//*from w  ww  .j a  v  a  2 s  .  com*/
private void addHandlerToFactory(String targetClassName, FactoryType factoryType, String ruleName) {
    try {
        if (targetClassName == null) {
            return;
        }

        // get rules for this class from rule repository
        Map<String, List<RuleMetaData>> map = MetaDataRepository.instance().getPropertyRuleMap(targetClassName,
                ruleName);
        if (map == null) {
            return;
        }

        // for each rule, create the appropriate handler and add it to the factory
        for (Map.Entry<String, List<RuleMetaData>> me : map.entrySet()) {
            List<RuleMetaData> rules = me.getValue();
            for (RuleMetaData rule : rules) {
                switch (factoryType) {
                case TransformationHandler:
                    addTransformationHandler(ruleName, rule, targetClassName);
                    break;
                case LifecycleHandler:
                    addLifecycleHandler(ruleName, rule, targetClassName);
                    break;
                }
            }
        }
    } catch (ClassNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug(e.getLocalizedMessage());
        }
    }
}

From source file:com.hybris.mobile.lib.location.geofencing.service.GeofencingIntentService.java

/**
 * Send a notification when a geofence is triggered
 *
 * @param geofence           the geofence triggered
 * @param notification       the notification object
 * @param geofenceTransition the geofence transition type
 *//* ww w  .j a  v  a  2  s  .com*/
protected void sendNotification(Geofence geofence, GeofenceObject.Notification notification,
        int geofenceTransition) {

    if (notification != null) {

        // Notification
        String notificationContentTitle = notification.getNotificationTitle();
        String notificationContentText = notification.getNotificationText();
        int notificationIconResId = notification.getNotificationIconResId();

        Notification.Builder builder = new Notification.Builder(this);

        builder.setContentTitle(notificationContentTitle).setContentText(notificationContentText);

        if (notificationIconResId > 0) {
            builder.setSmallIcon(notificationIconResId);
        }

        try {
            // Intent on click on the notification
            if (StringUtils.isNotBlank(notification.getIntentClassDestination())) {
                Class<?> intentClassDestination = Class.forName(notification.getIntentClassDestination());

                // Create an explicit content Intent that starts the Activity defined in intentClassDestination
                Intent notificationIntent = new Intent(this, intentClassDestination);

                // Geofence Id to pass to the activity in order to retrieve the object
                if (notification.getIntentBundle() != null) {
                    GeofenceObject.IntentBundle intentBundle = notification.getIntentBundle();
                    notificationIntent.putExtra(intentBundle.getKeyName(), intentBundle.getBundle());

                    // Easter egg :)
                    if (intentBundle.getBundle().getBoolean(GeofencingConstants.EXTRA_PLAY_SOUND)) {
                        MediaPlayer mediaPlayer;
                        if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
                            Log.d(TAG, "Playing entering geofence sound");
                            mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.entering_geofence);
                        } else {
                            Log.d(TAG, "Playing exiting geofence sound");
                            mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.leaving_geofence);
                        }

                        mediaPlayer.start();
                    }
                }

                PendingIntent notificationPendingIntent = PendingIntent.getActivity(this,
                        geofence.getRequestId().hashCode(), notificationIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                builder.setContentIntent(notificationPendingIntent);
            }

        } catch (ClassNotFoundException e) {
            Log.e(TAG, "Unable to find class " + notification.getIntentClassDestination() + "."
                    + e.getLocalizedMessage());
        }

        // Constructing the Notification and setting the flag to auto remove the notification when the user click on it
        Notification notificationView;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            notificationView = builder.build();
        } else {
            notificationView = builder.getNotification();
        }

        notificationView.flags = Notification.FLAG_AUTO_CANCEL;
        notificationView.defaults = Notification.DEFAULT_ALL;

        // Get an instance of the Notification manager
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);

        // Issue the notification
        mNotificationManager.notify(UUID.randomUUID().toString().hashCode(), notificationView);
    } else {
        Log.e(TAG, "Notification empty for Geofence " + geofence);
    }

}

From source file:eu.stratosphere.api.io.jdbc.JDBCInputFormat.java

/**
 * Loads appropriate JDBC driver.// w  ww . j  ava2s  . co m
 * 
 * @param dbType
 *        Type of the database.
 * @return boolean value, indication whether an appropriate driver could be
 *         found.
 */
private void setClassForDBType() {
    try {
        Class.forName(driverName);
    } catch (ClassNotFoundException cnfe) {
        throw new IllegalArgumentException("JDBC-Class not found:\t" + cnfe.getLocalizedMessage());
    }
}

From source file:no.sintef.jarfter.PostgresqlInteractor.java

public PostgresqlInteractor() throws JarfterException {
    log("PostgresqlInteractor - Connecting to database...");

    try {/*from www  . ja v  a 2s. c  om*/
        // Loading the Driver
        Class.forName("org.postgresql.Driver");
        // Connecting to the database
        loginDB();
    } catch (ClassNotFoundException cnfe) {
        log("PostgresqlInteractor - Found ClassNotFoundException: " + cnfe.getLocalizedMessage());
        throw new JarfterException(JarfterException.Error.SQL_NO_DRIVER);
    }

    log("PostgresqlInteractor - Connected to database!");
}

From source file:org.ajax4jsf.templatecompiler.builder.AbstractCompilationContext.java

public Class<?> loadClass(String className) throws ClassNotFoundException {
    Class<?> clazz = null;//from   w  ww. j av  a  2s .  c o  m
    try {
        if (JavaPrimitive.isPrimitive(className)) {
            clazz = JavaPrimitive.forName(className);
        } else {
            clazz = this.classLoader.loadClass(className);
        }
    } catch (ClassNotFoundException e) {
        throw e;
    } catch (Throwable e) {
        log.error(e.getLocalizedMessage(), e);
    }

    if (null == clazz) {
        throw new ClassNotFoundException(className);
    }
    return clazz;
}

From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java

private Class doConvertToClass(Object value) {
    Class clazz = null;/*from   ww  w  .  j  a va2s  .  co m*/

    if (value instanceof String && value != null && ((String) value).length() > 0) {
        try {
            clazz = Class.forName((String) value);
        } catch (ClassNotFoundException e) {
            throw new XWorkException(e.getLocalizedMessage(), e);
        }
    }

    return clazz;
}

From source file:org.onehippo.repository.scxml.RepositorySCXMLRegistry.java

private SCXMLDefinition readSCXMLDefinition(final String scxmlDefId, final Node scxmlDefNode)
        throws SCXMLException {
    String scxmlDefPath;//from  w w w.  j  a  v  a 2s .c  om
    String scxmlSource;
    final List<CustomAction> customActions = new ArrayList<>();
    String className = null;

    try {
        scxmlDefPath = scxmlDefNode.getPath();
        scxmlSource = scxmlDefNode.getProperty(SCXML_SOURCE).getString();

        if (StringUtils.isBlank(scxmlSource)) {
            log.error("SCXML definition source is blank at '{}'. '{}'.", scxmlDefNode.getPath(), scxmlSource);
        }

        for (final Node actionNode : new NodeIterable(scxmlDefNode.getNodes())) {
            if (!actionNode.isNodeType(SCXML_ACTION)) {
                continue;
            }

            String namespace = actionNode.getProperty(SCXML_ACTION_NAMESPACE).getString();
            className = actionNode.getProperty(SCXML_ACTION_CLASSNAME).getString();
            @SuppressWarnings("unchecked")
            Class<? extends Action> actionClass = (Class<Action>) Thread.currentThread().getContextClassLoader()
                    .loadClass(className);
            customActions.add(new CustomAction(namespace, actionNode.getName(), actionClass));
        }
    } catch (ClassNotFoundException e) {
        throw new SCXMLException("Failed to find the custom action class: " + className, e);
    } catch (RepositoryException e) {
        throw new SCXMLException("Failed to read custom actions from repository. " + e.getLocalizedMessage(),
                e);
    } catch (Exception e) {
        throw new SCXMLException("Failed to load custom actions. " + e.getLocalizedMessage(), e);
    }

    try {
        Configuration configuration = createSCXMLReaderConfiguration(scxmlDefPath, customActions);
        SCXML scxml = SCXMLReader.read(new StreamSource(new StringReader(scxmlSource)), configuration);
        return new SCXMLDefinitionImpl(scxmlDefId, scxmlDefPath, scxml);
    } catch (IOException e) {
        throw new SCXMLException(
                "IO error while reading SCXML definition at '" + scxmlDefPath + "'. " + e.getLocalizedMessage(),
                e);
    } catch (ModelException e) {
        throw new SCXMLException(
                "Invalid SCXML model definition at '" + scxmlDefPath + "'. " + e.getLocalizedMessage(), e);
    } catch (XMLStreamException e) {
        throw new SCXMLException("Failed to read SCXML XML stream at '" + scxmlDefPath + "'. "
                + naturalizeXMLStreamExceptionMessage(e), e);
    }
}

From source file:org.ajax4jsf.templatecompiler.el.ELCompiler.java

private boolean processingValue(AstValue node, StringBuffer sb, CompilationContext componentBean) {
    String lastIndexValue = "null";
    String lastVariableType = null;
    List<String> names = new ArrayList<String>();

    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        StringBuffer sb1 = new StringBuffer();
        Node subChild = node.jjtGetChild(i);

        if (subChild instanceof AstIdentifier) {
            String variableName = subChild.getImage();
            if (componentBean.containsVariable(variableName)) {
                lastVariableType = componentBean.getVariableType(variableName).getName();
                names.add(variableName);
            } else {
                processingIdentifier((AstIdentifier) subChild, sb1, componentBean);
            }//from ww  w.jav a 2 s .  co m
        } else if (subChild instanceof AstDotSuffix) {
            String propertyName = subChild.getImage();
            log.debug("Object: " + lastVariableType + ", property: " + propertyName);

            if (lastVariableType != null) {
                try {

                    Class<?> clazz = componentBean.loadClass(lastVariableType);

                    PropertyDescriptor propertyDescriptor = getPropertyDescriptor(clazz, propertyName,
                            componentBean);

                    if (propertyDescriptor == null) {
                        throw new PropertyNotFoundException(
                                "property: " + propertyName + " not found in class: " + lastVariableType);
                    }

                    log.debug("propertyObject: " + propertyDescriptor.getPropertyType().getName());
                    StringBuffer tmpbuf = new StringBuffer();
                    tmpbuf.append(propertyDescriptor.getReadMethod().getName());
                    tmpbuf.append("()");
                    names.add(tmpbuf.toString());

                    lastVariableType = propertyDescriptor.getPropertyType().getName();
                } catch (ClassNotFoundException e) {
                    log.error(e.getLocalizedMessage(), e);
                }

            } else {

                sb1.append("getProperty(");
                sb1.append(lastIndexValue);
                sb1.append(",");
                sb1.append("\"");
                sb1.append(subChild.getImage());
                sb1.append("\")");
            }
        } else if (subChild instanceof AstBracketSuffix) {
            String bracketSuffix = processingBracketSuffix((AstBracketSuffix) subChild, componentBean);

            if (lastVariableType != null) {
                StringBuffer tmpbuf = new StringBuffer();
                if (lastVariableType.startsWith("[L")) {
                    tmpbuf.append("[");
                    tmpbuf.append(bracketSuffix);
                    tmpbuf.append("]");
                    names.add(tmpbuf.toString());
                }

                if ((lastVariableType.compareTo("java.util.List") == 0)
                        || (lastVariableType.compareTo("java.util.Map") == 0)) {
                    tmpbuf.append("get(");
                    tmpbuf.append(bracketSuffix);
                    tmpbuf.append(")");
                    names.add(tmpbuf.toString());
                }
            } else {

                sb1.append("getElelmentByIndex(");
                sb1.append(lastIndexValue);
                sb1.append(",");
                sb1.append(bracketSuffix);
                sb1.append(")");
            }

        }

    }

    if (names.size() != 0) {
        StringBuffer tmpbuf = new StringBuffer();
        for (String element : names) {
            if (tmpbuf.length() != 0) {
                tmpbuf.append(".");
            }
            tmpbuf.append(element);
        }
        sb.append(tmpbuf.toString());
    } else {
        sb.append(lastIndexValue);
    }

    return true;
}