Example usage for java.lang ClassNotFoundException getClass

List of usage examples for java.lang ClassNotFoundException getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.sunchenbin.store.feilong.core.lang.reflect.ConstructorUtil.java

/**
 * ,Returns a new instance of the specified class choosing the right constructor from the list of parameter types.<br>
 * ://from  w ww  .  j  av  a  2 s  . co m
 * 
 * <pre>
 * {@code
 * User user = ConstructorUtil.newInstance("com.sunchenbin.store.feilong.test.User") user 
 * 
 * ? 
 * User user1 = ConstructorUtil.newInstance("com.sunchenbin.store.feilong.test.User", 100L);  id 100
 * }
 * </pre>
 *
 * @param <T>
 *            t
 * @param className
 *            ??, com.sunchenbin.store.feilong.test.User
 * @param parameterValues
 *            ?
 * @return ,??T 
 * @see ClassUtil#loadClass(String)
 * @see #newInstance(Class, Object...)
 * @see "org.springframework.beans.BeanUtils.instantiateClass(Constructor<T>, Object...)"
 */
@SuppressWarnings("unchecked")
public static <T> T newInstance(String className, Object... parameterValues) {
    if (Validator.isNullOrEmpty(className)) {
        throw new NullPointerException("className can't be null/empty!");
    }

    // ?
    Class<?> klass = null;
    try {
        klass = ClassUtil.loadClass(className);
    } catch (ClassNotFoundException e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new ReflectException(e);
    }
    return (T) newInstance(klass, parameterValues);
}

From source file:com.feilong.commons.core.lang.reflect.ConstructorUtil.java

/**
 * ,Returns a new instance of the specified class choosing the right constructor from the list of parameter types.<br>
 * ://from  ww w  .j a v  a  2  s  .c o  m
 * 
 * <pre>
 * {@code
 * User user = ConstructorUtil.newInstance("com.feilong.test.User") user 
 * 
 * ? 
 * User user1 = ConstructorUtil.newInstance("com.feilong.test.User", 100L);  id 100
 * }
 * </pre>
 *
 * @param <T>
 *            t
 * @param className
 *            ??, com.feilong.test.User
 * @param parameterValues
 *            ?
 * @return ,??T 
 * @throws ReflectException
 *             the reflect exception
 * @throws NullPointerException
 *             if isNullOrEmpty(className)
 * @see ClassUtil#loadClass(String)
 * @see #newInstance(Class, Object...)
 */
@SuppressWarnings("unchecked")
public static <T> T newInstance(String className, Object... parameterValues)
        throws ReflectException, NullPointerException {
    if (Validator.isNullOrEmpty(className)) {
        throw new NullPointerException("className can't be null/empty!");
    }

    // ?
    Class<?> klass = null;
    try {
        klass = ClassUtil.loadClass(className);
    } catch (ClassNotFoundException e) {
        log.error(e.getClass().getName(), e);
        throw new ReflectException(e);
    }
    return (T) newInstance(klass, parameterValues);
}

From source file:com.linkedin.cubert.operator.CubeOperator.java

private static void createAggregators(JsonNode json, BlockSchema inputSchema, boolean hasInnerDimensions,
        List<CubeAggInfo> aggs, List<DupleCubeAggInfo> dupleAggs) throws PreconditionException {
    for (JsonNode aggregateJson : json.get("aggregates")) {
        JsonNode typeJson = aggregateJson.get("type");
        // validate that type is defined in json
        if (typeJson == null || typeJson.isNull())
            throw new PreconditionException(PreconditionExceptionType.INVALID_CONFIG,
                    "<type> property not defined in Json: " + typeJson.toString());

        // validate that type is a string or array
        if (!typeJson.isTextual() && !typeJson.isArray())
            throw new PreconditionException(PreconditionExceptionType.INVALID_CONFIG,
                    "<type> property not text or array: " + typeJson.toString());

        // if array, validate that type has one or two items
        if (typeJson.isArray() && !(typeJson.size() == 1 || typeJson.size() == 2))
            throw new PreconditionException(PreconditionExceptionType.INVALID_CONFIG,
                    "<type> property as array can have either one or two items: " + typeJson.toString());

        // validate that the input columns are present in input schema
        String[] inputColNames = null;
        DataType[] inputColTypes = null;

        if (aggregateJson.has("input") && !aggregateJson.get("input").isNull()) {
            inputColNames = JsonUtils.asArray(aggregateJson, "input");
            inputColTypes = new DataType[inputColNames.length];
            int idx = 0;
            for (String colName : inputColNames) {
                if (!inputSchema.hasIndex(colName))
                    throw new PreconditionException(PreconditionExceptionType.COLUMN_NOT_PRESENT, colName);

                inputColTypes[idx++] = inputSchema.getType(inputSchema.getIndex(colName));
            }/* ww w .  ja v  a 2 s . c  o m*/
        }

        // handle first the special case of array with two items
        if (typeJson.isArray() && typeJson.size() == 2) {
            String[] aggregators = JsonUtils.asArray(typeJson);

            ValueAggregationType outerType = getCubeAggregationType(aggregators[0], true);
            ValueAggregationType innerType = getCubeAggregationType(aggregators[1], true);

            // the "type" of inner aggregate is the type of input column
            ValueAggregator innerAggregator = ValueAggregatorFactory.get(innerType, inputColTypes[0],
                    inputColNames[0]);
            // the "type" of outer aggregate is the output type of inner aggregate
            ValueAggregator outerAggregator = ValueAggregatorFactory.get(outerType,
                    innerAggregator.outputType(), inputColNames[0]);

            DupleCubeAggregator cubeAggregator = new DefaultDupleCubeAggregator(outerAggregator,
                    innerAggregator);

            if (!hasInnerDimensions)
                errorInnerDimensionsNotSpecified(java.util.Arrays.toString(aggregators));

            dupleAggs.add(new DupleCubeAggInfo(cubeAggregator, aggregateJson));
        } else {
            String type = typeJson.isArray() ? typeJson.get(0).getTextValue() : typeJson.getTextValue();

            ValueAggregationType aggType = getCubeAggregationType(type, false);

            // if this is builtin aggregator
            if (aggType != null) {

                ValueAggregator aggregator = ValueAggregatorFactory.get(aggType,
                        inputColTypes == null ? null : inputColTypes[0],
                        inputColNames == null ? null : inputColNames[0]);

                CubeAggregator cubeggregator = new DefaultCubeAggregator(aggregator);

                aggs.add(new CubeAggInfo(cubeggregator, aggregateJson));

            } else if (type.equals("COUNT_DISTINCT")) {
                if (!hasInnerDimensions)
                    errorInnerDimensionsNotSpecified(type);

                DupleCubeAggregator cubeAggregator = new CountDistinctCubeAggregator(inputColNames[0]);

                dupleAggs.add(new DupleCubeAggInfo(cubeAggregator, aggregateJson));
            }
            // this is udaf
            else {
                Object object = null;

                try {
                    Class<?> cls = ClassCache.forName(type);
                    object = instantiateObject(cls, aggregateJson.get("constructorArgs"));

                } catch (ClassNotFoundException e) {
                    throw new PreconditionException(PreconditionExceptionType.CLASS_NOT_FOUND, type);
                } catch (Exception e) {
                    throw new PreconditionException(PreconditionExceptionType.MISC_ERROR,
                            e.getClass().getSimpleName() + " " + e.getMessage() + " for class: " + type);
                }

                if (object instanceof DupleCubeAggregator) {
                    DupleCubeAggregator cubeAggregator = (DupleCubeAggregator) object;

                    if (!hasInnerDimensions)
                        errorInnerDimensionsNotSpecified(type);
                    dupleAggs.add(new DupleCubeAggInfo(cubeAggregator, aggregateJson));

                } else if (object instanceof CubeAggregator) {
                    CubeAggregator cubeAggregator = (CubeAggregator) object;

                    aggs.add(new CubeAggInfo(cubeAggregator, aggregateJson));
                }

                else if (object instanceof EasyCubeAggregator) {
                    EasyCubeAggregatorBridge cubeAggregator = new EasyCubeAggregatorBridge(
                            (EasyCubeAggregator) object);

                    if (!hasInnerDimensions)
                        errorInnerDimensionsNotSpecified(type);

                    dupleAggs.add(new DupleCubeAggInfo(cubeAggregator, aggregateJson));
                } else {
                    String msg = String.format(
                            "%s should implement one of these interfaces: AdditiveCubeAggregate, PartitionedAdditiveAggregate, EasyCubeAggregate",
                            type);
                    throw new PreconditionException(PreconditionExceptionType.MISC_ERROR, msg);
                }
            }
        }
    }
}

From source file:com.clustercontrol.sql.util.AccessDB.java

/**
 * DB???//from   ww  w  .  j a  v a 2 s . c  om
 *
 * @throws SQLException
 * @throws ClassNotFoundException
 */
private void initial() throws SQLException, ClassNotFoundException {
    //JDBC??
    try {
        Class.forName(m_jdbcDriver);
    } catch (ClassNotFoundException e) {
        m_log.info("initial() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        throw e;
    }

    Properties prop = jdbcProps.getProperties();
    prop.put("user", m_user);
    prop.put("password", m_password);

    try {
        if (jdbcProps.isLoginTimeoutEnable()) {
            DriverManager.setLoginTimeout(jdbcProps.getLoginTimeout());
            m_log.debug(
                    "enabled loginTimeout (" + jdbcProps.getLoginTimeout() + " [sec]) for \"" + m_url + "\".");
        } else {
            m_log.debug("disabled loginTimeout for \"" + m_url + "\".");
        }
        m_connection = DriverManager.getConnection(m_url, prop);

        //SQL????Statement?
        m_statement = m_connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);

    } catch (SQLException e) {
        m_log.info("initial() database access failure : url = " + m_url + ", : " + e.getClass().getSimpleName()
                + ", " + e.getMessage());
        try {
            if (m_statement != null)
                m_statement.close();
        } catch (SQLException se) {
            m_log.info("initial() database closing failure : url = " + m_url + ", "
                    + se.getClass().getSimpleName() + ", " + se.getMessage());
        }
        try {
            if (m_connection != null)
                m_connection.close();
        } catch (SQLException se) {
            m_log.info("initial() database closing failure : url = " + m_url + ", "
                    + se.getClass().getSimpleName() + ", " + se.getMessage());
        }
        throw e;
    }
}

From source file:com.clustercontrol.sql.factory.RunMonitorSqlString.java

/**
 * SQL?/*  w w w . j  a  v a2 s  .  co m*/
 * 
 * @param facilityId ID
 * @return ???????true
 */
@Override
public boolean collect(String facilityId) {
    // set Generation Date
    if (m_now != null) {
        m_nodeDate = m_now.getTime();
    }

    boolean result = false;

    AccessDB access = null;
    ResultSet rSet = null;

    String url = m_url;

    try {
        // ???URL??
        if (nodeInfo != null && nodeInfo.containsKey(facilityId)) {
            Map<String, String> nodeParameter = RepositoryUtil.createNodeParameter(nodeInfo.get(facilityId));
            StringBinder strbinder = new StringBinder(nodeParameter);
            url = strbinder.bindParam(m_url);
            if (m_log.isTraceEnabled())
                m_log.trace("jdbc request. (nodeInfo = " + nodeInfo + ", facilityId = " + facilityId
                        + ", url = " + url + ")");
        }

        // DB??
        access = new AccessDB(m_jdbcDriver, url, m_user, m_password);

        // SQL?????
        if (m_query.length() >= 6) {
            String work = m_query.substring(0, 6);
            if (work.equalsIgnoreCase("SELECT")) {
                rSet = access.read(m_query);

                //1?1??
                rSet.first();
                m_value = rSet.getString(1);

                //?
                rSet.last();
                int number = rSet.getRow();

                NumberFormat numberFormat = NumberFormat.getNumberInstance();
                m_messageOrg = MessageConstant.RECORD_VALUE.getMessage() + " : " + m_value + ", "
                        + MessageConstant.RECORDS_NUMBER.getMessage() + " : " + numberFormat.format(number);
                m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;

                result = true;
            } else {
                //SELECT?
                m_log.info("collect(): "
                        + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage());
                m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage();
                m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query;
                m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
            }
        } else {
            //SELECT?
            m_log.info("collect(): " + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage());
            m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage();
            m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query;
            m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
        }
    } catch (ClassNotFoundException e) {
        m_log.debug("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        m_unKnownMessage = MessageConstant.MESSAGE_CANNOT_FIND_JDBC_DRIVER.getMessage();
        m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")";
        m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
    } catch (SQLException e) {
        // SQL
        m_log.info("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        m_unKnownMessage = MessageConstant.MESSAGE_FAILED_TO_EXECUTE_SQL.getMessage();
        m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")";
        m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
    } finally {
        try {
            if (rSet != null) {
                rSet.close();
            }
            if (access != null) {
                // DB?
                access.terminate();
            }
        } catch (SQLException e) {
            m_log.warn("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        }
    }
    return result;
}

From source file:com.clustercontrol.sql.factory.RunMonitorSql.java

/**
 * SQL?//w w w  .  j  av a  2  s  .com
 * 
 * @param facilityId ID
 * @return ???????true
 */
@Override
public boolean collect(String facilityId) {
    // set Generation Date
    if (m_now != null) {
        m_nodeDate = m_now.getTime();
    }

    boolean result = false;

    AccessDB access = null;
    ResultSet rSet = null;

    String url = m_url;

    try {
        // ???URL??
        if (nodeInfo != null && nodeInfo.containsKey(facilityId)) {
            Map<String, String> nodeParameter = RepositoryUtil.createNodeParameter(nodeInfo.get(facilityId));
            StringBinder strbinder = new StringBinder(nodeParameter);
            url = strbinder.bindParam(m_url);
            if (m_log.isTraceEnabled())
                m_log.trace("jdbc request. (nodeInfo = " + nodeInfo + ", facilityId = " + facilityId
                        + ", url = " + url + ")");
        }

        // DB??
        access = new AccessDB(m_jdbcDriver, url, m_user, m_password);

        // SQL?????
        if (m_query.length() >= 6) {
            String work = m_query.substring(0, 6);
            if (work.equalsIgnoreCase("SELECT")) {
                rSet = access.read(m_query);

                //1?1??
                rSet.first();
                double count = rSet.getDouble(1);
                m_value = count;

                //?
                rSet.last();
                int number = rSet.getRow();

                NumberFormat numberFormat = NumberFormat.getNumberInstance();
                m_message = MessageConstant.SELECT_VALUE.getMessage() + " : " + m_value;
                m_messageOrg = MessageConstant.RECORD_VALUE.getMessage() + " : " + numberFormat.format(m_value)
                        + ", " + MessageConstant.RECORDS_NUMBER.getMessage() + " : "
                        + numberFormat.format(number);
                m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;

                result = true;
            } else {
                //SELECT?
                m_log.info("collect(): "
                        + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage());
                m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage();
                m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query;
                m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
            }
        } else {
            //SELECT?
            m_log.info("collect(): " + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage());
            m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage();
            m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query;
            m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
        }
    } catch (ClassNotFoundException e) {
        m_log.debug("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        m_unKnownMessage = MessageConstant.MESSAGE_CANNOT_FIND_JDBC_DRIVER.getMessage();
        m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")";
        m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
    } catch (SQLException e) {
        // SQL
        m_log.info("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        m_unKnownMessage = MessageConstant.MESSAGE_FAILED_TO_EXECUTE_SQL.getMessage();
        m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")";
        m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
    } finally {
        try {
            if (rSet != null) {
                rSet.close();
            }
            if (access != null) {
                // DB?
                access.terminate();
            }
        } catch (SQLException e) {
            m_log.warn("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        }
    }
    return result;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.excelimport.EntityDataImporter.java

/**
 * @param typeName/*from   w  w  w  .  ja va  2  s . c  o  m*/
 * @param cellValue
 * @return the enum value for the given typeName and the enum value given as String in the cell value;
 *         or null if the value is not found.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object resolveJavaEnum(String typeName, Object cellValue) {
    Object result = null;
    try {
        Class<?> clazz = Class.forName(typeName);

        if (clazz.isEnum()) {
            return Enum.valueOf(((Class<Enum>) clazz), cellValue.toString());
        } else {
            logError("Type {0} is not an enum. Can not find value for {1}", typeName, cellValue.toString());
        }
    } catch (ClassNotFoundException e) {
        logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(),
                e.getMessage());
    } catch (SecurityException e) {
        logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(),
                e.getMessage());
    } catch (IllegalArgumentException e) {
        logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(),
                e.getMessage());
    }
    return result;
}

From source file:com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel.java

private <O extends ObjectType> List<LookupTableRowType> createLookupTableRows(JasperReportParameterDto param,
        String input) {/*from  ww w  .  j  a v  a 2  s .co  m*/
    ItemPath label = null;
    ItemPath key = null;
    List<LookupTableRowType> rows = new ArrayList<>();

    JasperReportParameterPropertiesDto properties = param.getProperties();

    if (properties == null) {
        return null;
    }

    String pLabel = properties.getLabel();
    if (pLabel != null) {
        label = new ItemPath(pLabel);
    }
    String pKey = properties.getKey();
    if (pKey != null) {
        key = new ItemPath(pKey);
    }

    String pTargetType = properties.getTargetType();
    Class<O> targetType = null;
    if (pTargetType != null) {
        try {
            targetType = (Class<O>) Class.forName(pTargetType);
        } catch (ClassNotFoundException e) {
            error("Error while creating lookup table for input parameter: " + param.getName() + ", "
                    + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");

        }
    }

    if (label != null && targetType != null && input != null) {
        OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
        Task task = createSimpleTask(OPERATION_LOAD_RESOURCES);

        Collection<PrismObject<O>> objects;
        ObjectQuery query = QueryBuilder.queryFor(targetType, getPrismContext())
                .item(new QName(SchemaConstants.NS_C, pLabel)).startsWith(input)
                .matching(new QName(SchemaConstants.NS_MATCHING_RULE, "origIgnoreCase"))
                .maxSize(AUTO_COMPLETE_BOX_SIZE).build();
        try {
            objects = getPageBase().getModelService().searchObjects(targetType, query,
                    SelectorOptions.createCollection(GetOperationOptions.createNoFetch()), task, result);

            for (PrismObject<O> o : objects) {
                Object realKeyValue = null;
                PrismProperty<?> labelItem = o.findProperty(label);

                //TODO: e.g. support not only for property, but also ref, container..
                if (labelItem == null || labelItem.isEmpty()) {
                    continue;
                }
                PrismProperty<?> keyItem = o.findProperty(key);
                if ("oid".equals(pKey)) {
                    realKeyValue = o.getOid();
                }
                if (realKeyValue == null && (keyItem == null || keyItem.isEmpty())) {
                    continue;
                }

                //TODO: support for single/multivalue value
                if (!labelItem.isSingleValue()) {
                    continue;
                }

                Object realLabelValue = labelItem.getRealValue();
                realKeyValue = (realKeyValue == null) ? keyItem.getRealValue() : realKeyValue;

                // TODO: take definition into account
                //                    QName typeName = labelItem.getDefinition().getTypeName();

                LookupTableRowType row = new LookupTableRowType();

                if (realKeyValue != null) {
                    row.setKey(convertObjectToPolyStringType(realKeyValue).getOrig());
                } else {
                    throw new SchemaException(
                            "Cannot create lookup table with null key for label: " + realLabelValue);
                }

                row.setLabel(convertObjectToPolyStringType(realLabelValue));

                rows.add(row);
            }

            return rows;
        } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException
                | ConfigurationException | ExpressionEvaluationException e) {
            error("Error while creating lookup table for input parameter: " + param.getName() + ", "
                    + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
        }

    }
    return rows;
}

From source file:org.apache.avalon.fortress.tools.FortressBean.java

/**
 * Use reflection to set up commons logging. If commons logging is available, it will be set up;
 * if it is not available, this section is ignored. This needs version 1.0.4 (or later) of commons
 * logging, earlier versions do not have avalon support.
 *//*from  w  ww  . j a  v  a2s .c  o  m*/
private void initializeCommonsLogging(ClassLoader cl) {
    try {
        //if commons logging is available, set the static logger for commons logging
        Class commonsLoggerClass;
        if (cl != null) {
            commonsLoggerClass = cl.loadClass(COMMONS_AVALON_LOGGER);
        } else {
            commonsLoggerClass = Class.forName(COMMONS_AVALON_LOGGER);
        }
        Method setDefaultLoggerMethod = commonsLoggerClass.getMethod("setDefaultLogger",
                new Class[] { Logger.class });
        setDefaultLoggerMethod.invoke(null, new Object[] { cm.getLogger() });
        //set the system property to use avalon logger
        System.setProperty(COMMONS_LOG_PROPERTY, COMMONS_AVALON_LOGGER);
        if (getLogger().isInfoEnabled())
            getLogger().info("AvalonLogger found, commons logging redirected to Avalon logs");
    } catch (ClassNotFoundException e) {
        if (getLogger().isInfoEnabled())
            getLogger().info("AvalonLogger not found, commons logging not redirected");
    } catch (Exception e) {
        if (getLogger().isDebugEnabled())
            getLogger().debug("error while initializing commons logging: " + e.getClass().getName() + ", "
                    + e.getMessage());
    }
}

From source file:org.apache.camel.impl.DefaultPackageScanClassResolver.java

/**
 * Add the class designated by the fully qualified class name provided to
 * the set of resolved classes if and only if it is approved by the Test
 * supplied.//w  w  w. j a  v  a  2  s  .c om
 *
 * @param test the test used to determine if the class matches
 * @param fqn  the fully qualified name of a class
 */
protected void addIfMatching(PackageScanFilter test, String fqn, Set<Class<?>> classes) {
    try {
        String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', '.');
        Set<ClassLoader> set = getClassLoaders();
        boolean found = false;
        for (ClassLoader classLoader : set) {
            if (log.isTraceEnabled()) {
                log.trace("Testing for class " + externalName + " matches criteria [" + test
                        + "] using classloader:" + classLoader);
            }
            try {
                Class<?> type = classLoader.loadClass(externalName);
                if (log.isTraceEnabled()) {
                    log.trace("Loaded the class: " + type + " in classloader: " + classLoader);
                }
                if (test.matches(type)) {
                    if (log.isTraceEnabled()) {
                        log.trace("Found class: " + type + " which matches the filter in classloader: "
                                + classLoader);
                    }
                    classes.add(type);
                }
                found = true;
                break;
            } catch (ClassNotFoundException e) {
                if (log.isTraceEnabled()) {
                    log.trace(
                            "Cannot find class '" + fqn + "' in classloader: " + classLoader + ". Reason: " + e,
                            e);
                }
            } catch (NoClassDefFoundError e) {
                if (log.isTraceEnabled()) {
                    log.trace("Cannot find the class definition '" + fqn + "' in classloader: " + classLoader
                            + ". Reason: " + e, e);
                }
            }
        }
        if (!found) {
            if (log.isDebugEnabled()) {
                // use debug to avoid being noisy in logs
                log.debug("Cannot find class '" + fqn + "' in any classloaders: " + set);
            }
        }
    } catch (Exception e) {
        if (log.isWarnEnabled()) {
            log.warn("Cannot examine class '" + fqn + "' due to a " + e.getClass().getName() + " with message: "
                    + e.getMessage(), e);
        }
    }
}