Example usage for org.apache.commons.lang ClassUtils getShortClassName

List of usage examples for org.apache.commons.lang ClassUtils getShortClassName

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils getShortClassName.

Prototype

public static String getShortClassName(Object object, String valueIfNull) 

Source Link

Document

Gets the class name minus the package name for an Object.

Usage

From source file:info.magnolia.cms.security.auth.callback.FormClientCallback.java

/**
 * simply sets "errorString" in case of login exception.
 * override this to pass more objects to the freemarker template.
 * @return an empty map/*from   ww w.  j ava2 s. c  o  m*/
 */
protected Map<String, Object> getMessages() {
    LoginResult loginResult = LoginResult.getCurrentLoginResult();
    LoginException exception = loginResult.getLoginException();
    Map<String, Object> messages = new HashMap<String, Object>();
    if (null != exception) {
        final String exName = ClassUtils.getShortClassName(exception, null);
        final Messages mm = MessagesManager.getMessages();
        final String defaultMessage = mm.get("login.defaultError");
        messages.put(ERROR_STRING, mm.getWithDefault("login." + exName, defaultMessage));
    }
    String serviceContact = this.configurationProperties.getProperty("magnolia.service.contact");
    if (serviceContact != null) {
        messages.put(SERVICE_CONTACT, serviceContact);
    }
    return messages;
}

From source file:it.unimi.di.big.mg4j.index.cluster.DocumentalCluster.java

public String toString() {
    return ClassUtils.getShortClassName(this, null) + Arrays.toString(localIndex);
}

From source file:org.apache.metron.common.field.FieldNameConverters.java

/**
 * Create a new {@link FieldNameConverter}.
 *
 * @param sensorType The type of sensor.
 * @param config The writer configuration.
 * @return/*from  w w  w. jav a 2s .  com*/
 */
public static FieldNameConverter create(String sensorType, WriterConfiguration config) {
    FieldNameConverter result = null;

    // which field name converter has been configured?
    String converterName = config.getFieldNameConverter(sensorType);
    if (StringUtils.isNotBlank(converterName)) {
        try {
            result = FieldNameConverters.valueOf(converterName);

        } catch (IllegalArgumentException e) {
            LOG.error("Invalid field name converter, using default; configured={}, knownValues={}, error={}",
                    converterName, FieldNameConverters.values(), ExceptionUtils.getRootCauseMessage(e));
        }
    }

    if (result == null) {
        // if no converter defined or an invalid converter is defined, default to 'DEDOT'
        result = FieldNameConverters.DEDOT;
    }

    LOG.debug("Created field name converter; sensorType={}, configured={}, class={}", sensorType, converterName,
            ClassUtils.getShortClassName(result, "null"));

    return result;
}

From source file:org.apache.metron.profiler.stellar.DefaultStellarExecutor.java

/**
 * Execute a Stellar expression and return the result.  The internal state of the executor
 * is not modified./*from w w w .j  a  v  a2 s  .c o m*/
 *
 * @param expression The expression to execute.
 * @param state      Additional state available to the expression.  This most often represents
 *                   the values available to the expression from an individual message. The state
 *                   maps a variable name to a variable's value.
 * @param clazz      The expected type of the expression's result.
 * @param <T>        The expected type of the expression's result.
 */
@Override
public <T> T execute(String expression, Map<String, Object> state, Class<T> clazz) {
    Object resultObject = execute(expression, state);

    // perform type conversion, if necessary
    T result = ConversionUtils.convert(resultObject, clazz);
    if (result == null) {
        throw new IllegalArgumentException(
                String.format("Unexpected type: expected=%s, actual=%s, expression=%s", clazz.getSimpleName(),
                        ClassUtils.getShortClassName(resultObject, "null"), expression));
    }

    return result;
}

From source file:org.projectforge.excel.ExcelImport.java

/**
 * convert a single row to an object.//from  w w  w  . j a  va 2 s  .co  m
 * 
 * @param row the row containing the values.
 * @param columnNames the row containing the column-names.
 * @param rowNum the current rownum
 * @return a new created object populated with the values.
 * @throws InstantiationException if the object creation fails.
 * @throws IllegalAccessException if the object creation fails or the invoked setter is not public.
 * @throws InvocationTargetException if the object creation fails with an exception or the setter threw an exception.
 * @throws NoSuchMethodException if the setter for the property name is not existant.
 */
private T convertToBean(final HSSFRow row, final HSSFRow columnNames, final int rowNum)
        throws InstantiationException, IllegalAccessException, InvocationTargetException,
        NoSuchMethodException {
    if (row == null) {
        log.debug("created no bean for row#" + rowNum);
        return null;
    }
    final T o = clazzFactory.newInstance(row);
    if (columnNames == null) {
        return null;
    }
    for (int column = 0; column < columnNames.getPhysicalNumberOfCells(); column++) {
        if (columnNames.getCell(column) == null) {
            continue;
        }
        String columnName = columnNames.getCell(column).getStringCellValue();
        if (columnName != null) {
            columnName = columnName.trim();
        }
        String propName = columnName;
        if (columnToPropertyMap != null) {
            final String mapName = columnToPropertyMap.get(columnName);
            if (mapName != null) {
                propName = mapName.trim();
            }
        }
        try {
            final Class<?> destClazz = PropertyUtils.getPropertyType(o, propName);
            if (propName == null || destClazz == null) {
                log.debug("Skipping column " + columnName);
                continue;
            }
            final Object value = toNativeType(row.getCell(column), destClazz);
            log.debug("Setting property=" + propName + " to " + value + " class="
                    + ClassUtils.getShortClassName(value, "null"));
            PropertyUtils.setProperty(o, propName, value);
        } catch (final ConversionException e) {
            log.warn(e);
            throw new ExcelImportException("Falscher Datentyp beim Excelimport", new Integer(row.getRowNum()),
                    columnName);
        } catch (final Exception e) {
            log.warn(e);
            throw new ExcelImportException("Falscher Datentyp beim Excelimport", new Integer(row.getRowNum()),
                    columnName);
        }
    }
    if (log.isDebugEnabled() == true) {
        log.debug("created bean " + o + " for row#" + rowNum);
    }
    return o;
}

From source file:org.projectforge.web.debug.SessionSerializableChecker.java

private void check(final HttpSession session, final String name, final Object value) {
    if (log.isInfoEnabled()) {
        try {//from  ww  w . j  ava  2 s .  co m
            if (log.isDebugEnabled()) {
                log.debug("Storing " + ClassUtils.getShortClassName(value, "null") + " under the name " + name
                        + " in session " + session.getId());
            }
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            final ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(value);
            oos.close();
            final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
            ois.readObject();
        } catch (final Exception ex) {
            log.warn("Trying to store non-serializable value " + value + " under the name " + name
                    + " in session " + session.getId(), ex);
        }
    }
}