Example usage for java.lang Class getSimpleName

List of usage examples for java.lang Class getSimpleName

Introduction

In this page you can find the example usage for java.lang Class getSimpleName.

Prototype

public String getSimpleName() 

Source Link

Document

Returns the simple name of the underlying class as given in the source code.

Usage

From source file:com.alta189.bukkit.script.event.EventScanner.java

private static Class<? extends Event> getEventClass(String pluginName, String event) {
    Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
    Set<? extends Class<? extends Event>> classes = pluginEvents.get(plugin);
    if (plugin != null) {
        if (event.contains(".")) {
            for (Class<? extends Event> clazz : classes) {
                String className = clazz.getCanonicalName();
                if (className == null) {
                    className = clazz.getName();
                }/*from w w  w .j a  va2  s .co  m*/
                if (className.equals(event)) {
                    return clazz;
                }
            }
        } else {
            for (Class<? extends Event> clazz : classes) {
                if (clazz.getSimpleName().equals(event)) {
                    return clazz;
                }
            }
        }
    }
    return null;
}

From source file:com.netxforge.oss2.core.xml.JaxbUtils.java

public static <T> T unmarshal(final Class<T> clazz, final InputSource inputSource,
        final JAXBContext jaxbContext, final boolean validate) {
    final Unmarshaller um = getUnmarshallerFor(clazz, jaxbContext, validate);

    LogUtils.tracef(clazz, "unmarshalling class %s from input source %s with unmarshaller %s",
            clazz.getSimpleName(), inputSource, um);
    try {/*  www.  j a  v  a2  s. c  o  m*/
        final XMLFilter filter = getXMLFilterForClass(clazz);
        final SAXSource source = new SAXSource(filter, inputSource);

        um.setEventHandler(new LoggingValidationEventHandler(clazz));

        final JAXBElement<T> element = um.unmarshal(source, clazz);
        return element.getValue();
    } catch (final SAXException e) {
        throw EXCEPTION_TRANSLATOR.translate("creating an XML reader object", e);
    } catch (final JAXBException e) {
        throw EXCEPTION_TRANSLATOR.translate("unmarshalling an object (" + clazz.getSimpleName() + ")", e);
    }
}

From source file:com.diversityarrays.dal.db.DalDatabaseUtil.java

static public void addEntityFields(Class<? extends DalEntity> entityClass, DalResponseBuilder responseBuilder) {

    responseBuilder.addResponseMeta("SCol");

    for (Field fld : entityClass.getDeclaredFields()) {
        if (!Modifier.isStatic(fld.getModifiers())) {
            Column column = fld.getAnnotation(Column.class);
            if (column != null) {

                DalResponseBuilder builder = responseBuilder.startTag("SCol");

                builder.attribute("Required", column.nullable() ? "0" : "1");

                int colSize = 11;
                Class<?> fieldType = fld.getType();
                if (String.class == fieldType) {
                    colSize = column.length();
                }/*from   w  w  w .j  a v a 2  s .  c o m*/
                builder.attribute("ColSize", Integer.toString(colSize));

                builder.attribute("Description", "");

                builder.attribute("Name", column.name());

                // TODO Synchronise with the Perl DAL code
                builder.attribute("DataType", fieldType.getSimpleName().toLowerCase());

                builder.endTag();
            }
        }
    }
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectory.java

private static <T extends ConfProvider> T loadParameters(Path path, Class<T> clazz, T existingInstance)
        throws Exception {
    T params = existingInstance != null ? existingInstance : (T) clazz.newInstance();

    if (params.hasChanged()) {
        log.trace("Loading {} from {}", clazz.getSimpleName(), path);

        params.load(path.toString());// w w  w .  j  ava2  s  .co m
    }

    return params;
}

From source file:com.github.riking.dropcontrol.ItemStringInterpreter.java

public static BasicItemMatcher valueOf(String itemString) throws IllegalArgumentException {
    itemString = itemString.toUpperCase();
    if (itemString.equals("ANY")) {
        return new BasicItemMatcher(null, null, null);
    }/*from  w ww .j a v  a  2 s  . c om*/
    String[] split = itemString.split(":");
    Validate.isTrue(split.length <= 2,
            "Unable to parse item string - too many colons (maximum 1). Please correct the format and reload the config. Input: "
                    + itemString);
    Material mat = getMaterial(split[0]);
    Validate.notNull(mat,
            "Unable to parse item string - unrecognized material. Please correct the format and reload the config. Input: "
                    + itemString);
    if (split.length == 1) {
        return new BasicItemMatcher(mat, null, null);
    }
    String dataString = split[1];
    short data;
    try {
        data = Short.parseShort(dataString);
        return new BasicItemMatcher(mat, data, null); // the datastring is not passed if it was just a number
    } catch (NumberFormatException ignored) {
    }
    if (materialData.containsKey(mat.getData())) {
        Class<? extends MaterialData> matClass = mat.getData();
        Class<? extends Enum> enumClass = materialData.get(mat.getData());
        Enum enumValue;
        try {
            enumValue = (Enum) enumClass.getMethod("valueOf", String.class).invoke(null, dataString);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Unable to parse item string - " + dataString
                    + " is not a valid member of " + enumClass.getSimpleName(), e.getCause());
        } catch (Exception rethrow) {
            throw new RuntimeException("Unexpected exception when parsing item string", rethrow);
        }
        MaterialData matData;
        try {
            matData = matClass.getConstructor(enumClass).newInstance(enumValue);
        } catch (Exception rethrow) {
            throw new RuntimeException("Unexpected exception when parsing item string", rethrow);
        }
        data = (short) matData.getData();
        return new BasicItemMatcher(mat, data, dataString);
    }
    if (workarounds.containsKey(mat)) {
        StringInterpreter interp = workarounds.get(mat);
        data = interp.interpret(dataString);
        return new BasicItemMatcher(mat, data, dataString);
    }
    throw new IllegalArgumentException(
            "Unable to parse item string - I don't know how to parse a word-data for " + mat);
}

From source file:com.ibm.watson.app.common.services.impl.BluemixServicesBinder.java

public static <T extends BluemixConfiguredService> int bind(Binder binder, Class<T> clazz) {

    if (AVAILABLE_SERVICES.isEmpty()) {
        registerBluemixServices();/* w  ww.  j  a v  a 2  s  . co m*/
    }

    @SuppressWarnings("unchecked")
    List<T> services = (List<T>) AVAILABLE_SERVICES.get(clazz);
    if (services == null || services.isEmpty()) {
        return 0;
    }
    if (services.size() > 1) {
        throw new IllegalStateException(MessageKey.AQWEGA04002E_multiple_instances_of_service_found_1
                .getMessage(clazz.getSimpleName()).getFormattedMessage());
    }

    binder.bind(clazz).toInstance(services.get(0));
    return 1;
}

From source file:com.qpark.eip.core.ToString.java

private static String outName(final String name, final Class<?> o) {
    StringBuffer sb = new StringBuffer(256);
    if (isComClass(o)) {
        // sb.append("\n");
    }//w w w.ja va 2s.  co  m
    sb.append("\n");
    if (name != null && name.length() > 0) {
        sb.append(name);
    }
    if (o != null) {
        sb.append("<");
        sb.append(o.getSimpleName());
        sb.append(">");
        if (name != null && name.length() > 0) {

        } else {
            sb.append(":");
        }
    }
    if (name != null && name.length() > 0) {
        sb.append("=");
    }
    return sb.toString();
}

From source file:edu.ku.brc.specify.ui.DBObjDialogFactory.java

/**
 * Checks the tree to see if it is locked so a form for the tree can be opened. Note: this method
 * will display a localized error before it returns.
 * //w w w.  j a va2s. com
 * @param lockTitle Title (not important)
 * @param view the view that needs to be opened
 * @param isNewForm whether the form is for a new object
 * @param isEdit whether the form is to edit an object
 * @return FormLockStatus for what happened
 */
public static FormLockStatus isLockOK(final String lockTitle, final ViewIFace view, final boolean isNewForm,
        final boolean isEdit) {
    Class<?> treeDefClass = ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getTreeDefClass(view);
    if (treeDefClass != null) {
        String treeSemaphoreName = treeDefClass.getSimpleName();
        String treeFormSemaphoreName = treeDefClass.getSimpleName() + "Form";

        DBTableInfo tableInfo = DBTableIdMgr.getInstance().getByClassName(view.getClassName());
        String title = tableInfo.getTitle() + " " + "Tree";

        // If this user owns the Tree Form Lock then they can open the View
        if (TaskSemaphoreMgr.doesOwnSemaphore(treeFormSemaphoreName, TaskSemaphoreMgr.SCOPE.Discipline)) {
            return FormLockStatus.OK;
        }

        TaskSemaphoreMgr.USER_ACTION action = TaskSemaphoreMgr.USER_ACTION.OK;
        if (isEdit || isNewForm) {
            // Check to see if the Tree Lock is locked
            //if (TaskSemaphoreMgr.isLocked(lockTitle, treeSemaphoreName, TaskSemaphoreMgr.SCOPE.Discipline))

            if (BaseTreeBusRules.ALLOW_CONCURRENT_FORM_ACCESS) {
                SpTaskSemaphore semaphore = TaskSemaphoreMgr.getLockInfo(title, treeSemaphoreName,
                        SCOPE.Discipline);
                if (semaphore != null && semaphore.getIsLocked()) {
                    String prevLockedBy = null;
                    SpecifyUser user = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
                    if (semaphore.getOwner() != null && !semaphore.getOwner().getId().equals(user.getId())
                            && semaphore.getOwner().getAgents() != null
                            && semaphore.getOwner().getAgents().size() > 0) {
                        prevLockedBy = semaphore.getOwner().getAgents().iterator().next().getIdentityTitle();
                    }
                    if (prevLockedBy != null) {
                        UIRegistry.displayInfoMsgDlgLocalized("DBObjDialogFactory.LockedOut1", title,
                                prevLockedBy);
                    } else {
                        UIRegistry.displayInfoMsgDlgLocalized("DBObjDialogFactory.LockedOut2", title,
                                prevLockedBy);
                    }
                    return FormLockStatus.Skip;
                }
            } else {
                action = TaskSemaphoreMgr.lock(title, treeSemaphoreName, "def",
                        TaskSemaphoreMgr.SCOPE.Discipline, !isNewForm && isEdit);
            }

            if (action != TaskSemaphoreMgr.USER_ACTION.OK) {
                if (action == TaskSemaphoreMgr.USER_ACTION.Cancel) {
                    return FormLockStatus.Skip;
                }
                if (isNewForm) {
                    //UIRegistry.showLocalizedError("TREE_LOCKED_NEW_OBJ");
                    return FormLockStatus.Skip;
                }

                if (isEdit) {
                    //UIRegistry.showLocalizedError("TREE_LOCKED_EDT_OBJ");
                    return FormLockStatus.ViewOnly;
                }

                return FormLockStatus.Skip;
            }
        } else {
            return FormLockStatus.ViewOnly;
        }

        // First try to grab the tree Lock
        //action = TaskSemaphoreMgr.lock(lockTitle, treeSemaphoreName, "def", TaskSemaphoreMgr.SCOPE.Discipline, false); 
        if (action == TaskSemaphoreMgr.USER_ACTION.OK) {
            // Now grab the Tree Form Lock
            if (BaseTreeBusRules.ALLOW_CONCURRENT_FORM_ACCESS) {
                if (!TaskSemaphoreMgr.incrementUsageCount(title, treeSemaphoreName, SCOPE.Discipline)) {
                    action = USER_ACTION.Error;
                }
            } else {
                action = TaskSemaphoreMgr.lock(title, treeFormSemaphoreName, "def",
                        TaskSemaphoreMgr.SCOPE.Discipline, false);
            }
            if (action != TaskSemaphoreMgr.USER_ACTION.OK) {
                if (!BaseTreeBusRules.ALLOW_CONCURRENT_FORM_ACCESS) {
                    // Since for some bizarre reason we didn't get the treeForm Lock release the tree lock.
                    TaskSemaphoreMgr.unlock(title, treeSemaphoreName, TaskSemaphoreMgr.SCOPE.Discipline);
                }
                UIRegistry.showLocalizedError("TREE_LOCKED_ERR_FRM");
                return FormLockStatus.Skip;
            }
            return FormLockStatus.GotLock;

        } else {
            UIRegistry.showLocalizedError("TREE_LOCKED_ERR");
            return FormLockStatus.Skip;
        }
    }
    return FormLockStatus.OK;
}

From source file:com.helpinput.spring.Commons.java

public static String getBeanName(Class<?> beanClass) {
    String beanName = null;//from ww w  .j a va  2s  .co  m
    Named nameAnn = beanClass.getAnnotation(Named.class);
    //todo named?bean;
    if (nameAnn != null) {
        if (Utils.hasLength(nameAnn.value()))
            beanName = nameAnn.value();
    } else {
        Component componentAnn = beanClass.getAnnotation(Component.class);
        if (componentAnn != null) {
            if (Utils.hasLength(componentAnn.value()))
                beanName = componentAnn.value();
        }
    }

    if (!Utils.hasLength(beanName)) {
        beanName = Utils.beanName(beanClass.getSimpleName());
    }
    return beanName;
}

From source file:com.smart.utils.ReflectionUtils.java

/**
 * ??,Class?.// w w  w.  j  av  a2 s .co  m
 * 
 * public UserDao extends HibernateDao<User,Long>
 * 
 * @param clazz
 *            clazz The class to introspect
 * @param index
 *            the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be
 *         determined
 */

@SuppressWarnings("unchecked")
public static Class getSuperClassGenricType(final Class clazz, final int index) {
    Type genType = clazz.getGenericSuperclass();
    if (!(genType instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }
    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
    if (index >= params.length || index < 0) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }
    return (Class) params[index];
}