List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:com.egt.core.aplicacion.Bitacora.java
private static String getFirmaMetodo(Class clase, String metodo, int argumentos) { String string = clase == null ? "" : clase.getSimpleName(); return getFirmaMetodo(string, metodo, argumentos); }
From source file:de.unibi.techfak.bibiserv.util.codegen.Main.java
public static void generate(Class clazz, File runnableitem, File projectdir, File file, String path, RESOURCETYPE type) throws CodeGenParserException { try {/*from w w w . j av a 2 s . co m*/ Constructor constructor = clazz.getConstructor(); Object object = constructor.newInstance(); if (!(object instanceof CodeGen)) { throw new CodeGenParserException( "'" + clazz.getSimpleName() + "' does not implement the CodeGen Interface!"); } CodeGen codegen = (CodeGen) object; codegen.setRunnableFile(runnableitem); codegen.setResultDir(projectdir); // distinguish if path describes a file or resource if (file != null) { // template resource is a file switch (type) { case isFile: codegen.setTemplateFile(file); codegen.generate(); break; case isDirectory: for (File f : file.listFiles()) { codegen.setTemplateFile(f); codegen.generate(); } break; } } else if (path != null) { // template resource is a path switch (type) { case isFile: codegen.setTemplateResource(path); codegen.generate(); break; case isDirectory: for (String entry : getClasspathEntriesByPath(path)) { codegen.setTemplateResource(entry); codegen.generate(); } } } else { // otherwise use default template defined by CodeGen Implementation codegen.generate(); } } catch (NoSuchMethodException e) { throw new CodeGenParserException( "Unknown implementation '" + clazz.getSimpleName() + "' of CodeGen interface."); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new CodeGenParserException("Can not instantiate class '" + clazz.getSimpleName() + "'"); } catch (IOException e) { throw new CodeGenParserException("tbd"); } }
From source file:edu.usu.sdl.openstorefront.doc.JaxrsProcessor.java
private static Set<String> mapValueField(List<APIValueFieldModel> fieldModels, Field fields[], boolean onlyComsumeField) { Set<String> fieldNamesCaptured = new HashSet<>(); for (Field field : fields) { boolean capture = true; if (onlyComsumeField) { ConsumeField consumeField = (ConsumeField) field.getAnnotation(ConsumeField.class); if (consumeField == null) { capture = false;//w w w . j a v a2 s. c o m } } if (capture) { APIValueFieldModel fieldModel = new APIValueFieldModel(); fieldModel.setFieldName(field.getName()); fieldNamesCaptured.add(field.getName()); fieldModel.setType(field.getType().getSimpleName()); DataType dataType = (DataType) field.getAnnotation(DataType.class); if (dataType != null) { String typeName = dataType.value().getSimpleName(); if (StringUtils.isNotBlank(dataType.actualClassName())) { typeName = dataType.actualClassName(); } fieldModel.setType(fieldModel.getType() + ": " + typeName); } NotNull requiredParam = (NotNull) field.getAnnotation(NotNull.class); if (requiredParam != null) { fieldModel.setRequired(true); } StringBuilder validation = new StringBuilder(); ParamTypeDescription description = (ParamTypeDescription) field .getAnnotation(ParamTypeDescription.class); if (description != null) { validation.append(description.value()).append("<br>"); } APIDescription aPIDescription = (APIDescription) field.getAnnotation(APIDescription.class); if (aPIDescription != null) { fieldModel.setDescription(aPIDescription.value()); } if ("Date".equals(field.getType().getSimpleName())) { validation.append("Timestamp (milliseconds since UNIX Epoch<br>"); } if ("boolean".equalsIgnoreCase(field.getType().getSimpleName())) { validation.append("T | F"); } ValidationRequirement validationRequirement = (ValidationRequirement) field .getAnnotation(ValidationRequirement.class); if (validationRequirement != null) { validation.append(validationRequirement.value()).append("<br>"); } PK pk = (PK) field.getAnnotation(PK.class); if (pk != null) { if (pk.generated()) { validation.append("Primary Key (Generated)").append("<br>"); } else { validation.append("Primary Key").append("<br>"); } } Min min = (Min) field.getAnnotation(Min.class); if (min != null) { validation.append("Min Value: ").append(min.value()).append("<br>"); } Max max = (Max) field.getAnnotation(Max.class); if (max != null) { validation.append("Max Value: ").append(max.value()).append("<br>"); } Size size = (Size) field.getAnnotation(Size.class); if (size != null) { validation.append("Min Length: ").append(size.min()).append(" Max Length: ").append(size.max()) .append("<br>"); } Pattern pattern = (Pattern) field.getAnnotation(Pattern.class); if (pattern != null) { validation.append("Needs to Match: ").append(pattern.regexp()).append("<br>"); } ValidValueType validValueType = (ValidValueType) field.getAnnotation(ValidValueType.class); if (validValueType != null) { validation.append("Set of valid values: ").append(Arrays.toString(validValueType.value())) .append("<br>"); if (validValueType.lookupClass().length > 0) { validation.append("See Lookup table(s): <br>"); for (Class lookupClass : validValueType.lookupClass()) { validation.append(lookupClass.getSimpleName()); } } if (validValueType.enumClass().length > 0) { validation.append("See Enum List: <br>"); for (Class enumClass : validValueType.enumClass()) { validation.append(enumClass.getSimpleName()); if (enumClass.isEnum()) { validation.append(" (").append(Arrays.toString(enumClass.getEnumConstants())) .append(") "); } } } } fieldModel.setValidation(validation.toString()); fieldModels.add(fieldModel); } } return fieldNamesCaptured; }
From source file:com.evolveum.liferay.usercreatehook.ws.ModelPortWrapper.java
private static QName getTypeQName(Class<? extends ObjectType> type) { // QName typeQName = JAXBUtil.getTypeQName(type); QName typeQName = new QName(NS_COMMON, type.getSimpleName()); return typeQName; }
From source file:de.hasait.genesis.base.freemarker.FreemarkerModelWriter.java
static void write(final Configuration pConfiguration, final Writer pWriter, final Object pModel, final Map pParams) throws IOException, TemplateException { final Map<Class<?>, Template> templateCache = TEMPLATE_CACHE.get(); Class<?> currentType = pModel.getClass(); Template template = templateCache.get(currentType); if (template == null) { final LinkedList<TypeNode> queue = new LinkedList<TypeNode>(); queue.add(new TypeNode(null, currentType)); TemplateNotFoundException firstE = null; do {//from w ww. j a v a 2 s . c om // take first from queue TypeNode current = queue.removeFirst(); currentType = current._type; // determine template template = templateCache.get(currentType); if (template == null) { final String templateName = currentType.getSimpleName() + ".ftl"; try { template = pConfiguration.getTemplate(templateName); } catch (final TemplateNotFoundException e) { if (firstE == null) { firstE = e; } } } if (template != null) { // fill cache including parents templateCache.put(currentType, template); while (true) { templateCache.put(currentType, template); current = current._parent; if (current == null) { break; } currentType = current._type; } } else { // fill queue with next nodes for (final Class<?> interfaceType : currentType.getInterfaces()) { queue.add(new TypeNode(current, interfaceType)); } final Class<?> superclassType = currentType.getSuperclass(); if (superclassType != null) { queue.add(new TypeNode(current, superclassType)); } } } while (template == null && !queue.isEmpty()); if (template == null) { throw firstE; } } write(pConfiguration, pWriter, template, pModel, pParams); }
From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java
private static ObjectNode buildChoicesNode(final ObjectMapper objectMapper, final Type heapValueType, final SchemaLoader schemaLoader) { if (heapValueType == null || !(heapValueType instanceof Class<?>)) { return null; }//from w w w .j a va 2 s. co m final Class<?> choicesEnumClass = (Class<?>) heapValueType; if (!choicesEnumClass.isEnum()) { return null; } final URI choicesUri = schemaLoader.getTypeUri(choicesEnumClass); final String choicesName = choicesEnumClass.getSimpleName(); final ObjectNode choicesNode = objectMapper.createObjectNode(); choicesNode.put(PropertyName.title.name(), choicesName); choicesNode.put(PropertyName.uri.name(), choicesUri.toString()); // TODO: Only embed the choices once per schema to lighten the download? final Object[] enumConstants = choicesEnumClass.getEnumConstants(); if (enumConstants != null && enumConstants.length > 0) { final ArrayNode valuesNode = objectMapper.createArrayNode(); choicesNode.put(PropertyName.values.name(), valuesNode); for (final Object enumConstant : enumConstants) { final String choice = String.valueOf(enumConstant); valuesNode.add(choice); } } return choicesNode; }
From source file:fr.mby.utils.spring.aop.support.AopHelper.java
/** * Test if an object which implement or extend a parameterized object will be able to handle a specific type. * Example : NumberList implements List<Number> { ... } NumberList can store any subtypes of Number : Number, * Integer, Long, ... This method return true if called like this supportsType(numberList, Integer.class, * List.class) This method return false if called like this supportsType(numberList, String.class, List.class) * /*from ww w. ja v a 2 s . co m*/ * @param object * the instantiated object we want to test against * @param type * the type we want to test if the object can hanldle * @param genericIfc * the type of the parameterized object (not the parameter type) * @return true if the object implementing the genericIfc supports the specified type */ public static <T> boolean supportsType(final Object object, final Class<?> type, final Class<?> genericIfc) { Class<?> typeArg = GenericTypeResolver.resolveTypeArgument(object.getClass(), genericIfc); if (typeArg == null || typeArg.equals(genericIfc)) { final Class<?> targetClass = AopUtils.getTargetClass(object); if (targetClass != object.getClass()) { typeArg = GenericTypeResolver.resolveTypeArgument(targetClass, genericIfc); } } final boolean test = typeArg == null || typeArg.isAssignableFrom(type); final String logMsg; if (test) { logMsg = "[{}] supports type: [{}] for genericIfc [{}]."; } else { logMsg = "[{}] doesn't support type: [{}] for genericIfc [{}]."; } AopHelper.LOG.debug(logMsg, object.getClass().getSimpleName(), type.getSimpleName(), genericIfc.getSimpleName()); return test; }
From source file:com.erudika.para.core.ParaObjectUtils.java
/** * Searches through the Para core package and {@code Config.CORE_PACKAGE_NAME} package for {@link ParaObject} * subclasses and adds their names them to the map. * * @return a map of simple class names (lowercase) to class objects *//*from ww w . j a va 2 s . com*/ public static Map<String, Class<? extends ParaObject>> getCoreClassesMap() { if (coreClasses.isEmpty()) { try { Set<Class<? extends ParaObject>> s = scanner .getComponentClasses(ParaObject.class.getPackage().getName()); if (!Config.CORE_PACKAGE_NAME.isEmpty()) { Set<Class<? extends ParaObject>> s2 = scanner.getComponentClasses(Config.CORE_PACKAGE_NAME); s.addAll(s2); } for (Class<? extends ParaObject> coreClass : s) { boolean isAbstract = Modifier.isAbstract(coreClass.getModifiers()); boolean isInterface = Modifier.isInterface(coreClass.getModifiers()); boolean isCoreObject = ParaObject.class.isAssignableFrom(coreClass); if (isCoreObject && !isAbstract && !isInterface) { coreClasses.put(coreClass.getSimpleName().toLowerCase(), coreClass); } } logger.debug("Found {} ParaObject classes: {}", coreClasses.size(), coreClasses); } catch (Exception ex) { logger.error(null, ex); } } return Collections.unmodifiableMap(coreClasses); }
From source file:com.github.rvesse.airline.Accessor.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static Collection<Object> newCollection(Class<?> type) { if (Collection.class.equals(type) || List.class.equals(type)) { return new ArrayList<Object>(); }//from w w w . j a va2 s . c om if (Set.class.equals(type)) { return new HashSet<Object>(); } if (SortedSet.class.equals(type)) { return new TreeSet(); } try { return (Collection<Object>) type.getConstructor().newInstance(); } catch (Exception ignored) { } throw new ParseException( "Parameters of Collection type '%s' are not supported. Please use List or Set instead.", type.getSimpleName()); }
From source file:org.thoughtland.xlocation.Util.java
public static Method getMethod(Class<?> clazz, String name, Object[] args) { Util.log(null, Log.DEBUG, "Looking for " + name); for (Method m : clazz.getDeclaredMethods()) { Util.log(null, Log.DEBUG, "Got method " + clazz.getSimpleName() + "." + m.getName() + "( " + TextUtils.join(", ", m.getParameterTypes()) + " )"); if (m.getName().equals(name)) { Util.log(null, Log.DEBUG, " names match!"); if (args == null) return m; Class<?>[] params = m.getParameterTypes(); if (params.length == args.length) { Util.log(null, Log.DEBUG, " params length match!"); boolean matches = true; for (int i = 0; i < params.length; i++) { if (args[i] != null && !params[i].isInstance(args[i])) { Util.log(null, Log.DEBUG, " param[" + i + "] " + args[i].getClass().getName() + " does not match type " + params[i].getSimpleName()); matches = false; break; }/*from w w w.j a v a2 s .c o m*/ } if (matches) { Util.log(null, Log.DEBUG, "Found match for " + name); return m; } } } } return null; }