List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:it.sample.parser.util.CommonsUtil.java
/** * Metodo di utilita' per controllare che un'istanza di una classe abbia almeno un campo valorizzato * /*from www . java 2 s .c om*/ * @param instance * @return true se l'istanza ha almeno un campo valorizzato, false altrimenti */ public static <T> boolean isFilled(T instance) { boolean isFilled = false; Method[] methods = instance != null ? instance.getClass().getMethods() : new Method[] {}; for (Method method : methods) { if (isGetter(method)) { Class<?> returnType = method.getReturnType(); Object obj = null; try { obj = method.invoke(instance, new Object[] {}); if (obj != null && (returnType.getSimpleName().equals("String") && obj.toString().length() > 0)) { isFilled = true; break; } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } return isFilled; }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static Optional<Event> loadUnique(Connection connection, Class<? extends Event> eventType) throws SQLException, IOException { String statement = "SELECT \"id\", \"data\" FROM \"events\" WHERE \"type\" = ? AND \"removed\" = false"; try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setString(1, eventType.getSimpleName()); ResultSet result = stmt.executeQuery(); if (result.next()) { String evString = result.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = result.getLong("id"); event.removed = false;//from w w w .j a v a2 s . c o m return Optional.of(event); } else { return Optional.empty(); } } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.common.vbb.impl.util.VisualVariableHelper.java
private static EClassifier getEDataType(EPackage vvEPackage, Class<?> clazz) { for (EClassifier eClassifier : EcorePackage.eINSTANCE.getEClassifiers()) { if (eClassifier instanceof EDataType && eClassifier.getInstanceClass().equals(clazz)) { return eClassifier; }//from w w w .j a v a2 s .co m } if (vvEPackage.getEClassifier(clazz.getSimpleName()) == null) { try { if (clazz.getConstructor(String.class) != null) { EDataType dataType = EcoreFactory.eINSTANCE.createEDataType(); dataType.setName(clazz.getSimpleName()); dataType.setInstanceClass(clazz); vvEPackage.getEClassifiers().add(dataType); } } catch (SecurityException e) { LOGGER.error("Could not convert class to EDataType " + clazz.getName() + ".", e); } catch (NoSuchMethodException e) { LOGGER.error("Could not convert for class to EDataType " + clazz.getName() + ".", e); } } return vvEPackage.getEClassifier(clazz.getSimpleName()); }
From source file:com.stgmastek.core.comm.main.StartCoreCommunication.java
static void start() throws Exception { // Cache the clients ClientBook.getBook();/* w ww. j ava 2 s .c o m*/ // Loads or UP all the services as configured in the CORE_CONFIG table for (int i = 0; i < servicesList.size(); i++) { DeploymentMap map = servicesList.get(i); Class<? extends ServiceBase> serviceClass = map.getServiceInterface(); Class<?> serviceImpl = map.getServiceImpl(); WSServerAddress address = new WSServerAddress(); address.setHost(map.getAddress()); address.setPort(Integer.valueOf(map.getPort())); address.setDomain(serviceClass.getSimpleName()); WSServerInfo info = new WSServerInfo(serviceClass.getSimpleName(), address); WSServerManager.getInstance().createServer(serviceClass, serviceImpl.newInstance(), info); if (logger.isEnabledFor(LogLevel.NOTICE)) { logger.log(LogLevel.NOTICE, "Setting the server's publish address to be " + info.getAddress().getAddressURL()); logger.log(LogLevel.NOTICE, "Starting services : " + serviceClass.getSimpleName()); } } // Start the poller pollers.add(new OutBoundQueuePoller()); for (BasePoller poller : pollers) { new Thread(poller).start(); } }
From source file:com.topsem.common.utils.Reflections.java
/** * ??, Class?./*from w ww .j a va 2s. c om*/ * , Object.class. * <p/> * 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 */ public static Class getClassGenericType(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]; }
From source file:edu.usu.sdl.openstorefront.util.ReflectionUtil.java
/** * This checks class name to determine if a given class is subtype of the * class name;// w w w . j a va 2 s. c om * * @param className * @param entityClass * @return */ public static boolean isSubClass(String className, Class entityClass) { if (entityClass == null) { return false; } if (className.equals(entityClass.getSimpleName())) { return true; } else { return isSubClass(className, entityClass.getSuperclass()); } }
From source file:com.haulmont.cuba.core.global.PersistenceHelper.java
/** * @param entityClass entity class//from w w w .j a v a2 s . c om * @return entity name as defined in {@link javax.persistence.Entity} annotation */ public static String getEntityName(Class<?> entityClass) { Annotation annotation = entityClass.getAnnotation(javax.persistence.Entity.class); if (annotation == null) throw new IllegalArgumentException("Class " + entityClass + " is not a persistent entity"); String name = ((javax.persistence.Entity) annotation).name(); if (!StringUtils.isEmpty(name)) return name; else return entityClass.getSimpleName(); }
From source file:info.donsun.core.utils.Reflections.java
/** * ??, Class?. , Object.class./*from ww w .ja v a2s .c o 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 */ public static <T> Class<T> getClassGenricType(final Class clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return null; } 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 null; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return null; } return (Class) params[index]; }
From source file:com.sunchenbin.store.feilong.core.lang.ClassLoaderUtil.java
/** * ? {@link ClassLoader}.//from w w w . j a v a 2 s. c o m * * @param callingClass * the calling class * @return the class loader by class * @see java.lang.Class#getClassLoader() */ public static ClassLoader getClassLoaderByClass(Class<?> callingClass) { ClassLoader classLoader = callingClass.getClassLoader(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("{}.getClassLoader():{}", callingClass.getSimpleName(), JsonUtil.format(getClassLoaderInfoMapForLog(classLoader))); } return classLoader; }
From source file:org.synyx.hades.util.ClassUtils.java
/** * Returns the name ot the entity represented by this class. Used to build * queries for that class./*from www . j a v a 2 s.c o m*/ * * @param domainClass * @return */ public static String getEntityName(Class<?> domainClass) { Entity entity = domainClass.getAnnotation(Entity.class); boolean hasName = null != entity && StringUtils.hasText(entity.name()); return hasName ? entity.name() : domainClass.getSimpleName(); }