List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:com.ryantenney.metrics.spring.CachedGaugeAnnotationBeanPostProcessor.java
@Override protected void withMethod(final Object bean, String beanName, Class<?> targetClass, final Method method) { if (method.getParameterTypes().length > 0) { throw new IllegalStateException( "Method " + method.getName() + " is annotated with @CachedGauge but requires parameters."); }//from w w w . j a va 2 s . co m final CachedGauge annotation = method.getAnnotation(CachedGauge.class); final String metricName = Util.forCachedGauge(targetClass, method, annotation); metrics.register(metricName, new com.codahale.metrics.CachedGauge<Object>(annotation.timeout(), annotation.timeoutUnit()) { @Override protected Object loadValue() { return ReflectionUtils.invokeMethod(method, bean); } }); LOG.debug("Created cached gauge {} for method {}.{}", metricName, targetClass.getCanonicalName(), method.getName()); }
From source file:com.aujur.ebookreader.Configuration.java
public void setLastActivity(Class<? extends PageTurnerActivity> activityClass) { updateValue(KEY_LAST_ACTIVITY, activityClass.getCanonicalName()); }
From source file:io.siddhi.doc.gen.core.utils.DocumentationUtils.java
/** * Generate extension meta data from the annotated data in the class * * @param namespaceList The list of namespaces to which the new extension will be added * @param extensionClass Class from which meta data should be extracted from * @param logger The maven plugin logger *///from w w w . ja v a 2 s. c o m private static void addExtensionMetaDataIntoNamespaceList(List<NamespaceMetaData> namespaceList, Class<?> extensionClass, Log logger) { Extension extensionAnnotation = extensionClass.getAnnotation(Extension.class); if (extensionAnnotation != null) { // Discarding extension classes without annotation ExtensionMetaData extensionMetaData = new ExtensionMetaData(); // Finding extension type String extensionType = null; for (Map.Entry<ExtensionType, Class<?>> entry : ExtensionType.getSuperClassMap().entrySet()) { Class<?> superClass = entry.getValue(); if (superClass.isAssignableFrom(extensionClass) && superClass != extensionClass) { extensionType = entry.getKey().getValue(); break; } } // Discarding the extension if it belongs to an unknown type if (extensionType == null) { logger.warn("Discarding extension (belonging to an unknown extension type): " + extensionClass.getCanonicalName()); return; } extensionMetaData.setName(extensionAnnotation.name()); extensionMetaData.setDescription(extensionAnnotation.description()); // Adding query parameters ParameterMetaData[] parameters = new ParameterMetaData[extensionAnnotation.parameters().length]; for (int i = 0; i < extensionAnnotation.parameters().length; i++) { Parameter parameterAnnotation = extensionAnnotation.parameters()[i]; ParameterMetaData parameter = new ParameterMetaData(); parameter.setName(parameterAnnotation.name()); parameter.setType(Arrays.asList(parameterAnnotation.type())); parameter.setDescription(parameterAnnotation.description()); parameter.setOptional(parameterAnnotation.optional()); parameter.setDynamic(parameterAnnotation.dynamic()); parameter.setDefaultValue(parameterAnnotation.defaultValue()); parameters[i] = parameter; } extensionMetaData.setParameters(Arrays.asList(parameters)); // Adding system parameters SystemParameterMetaData[] systemParameters = new SystemParameterMetaData[extensionAnnotation .systemParameter().length]; for (int i = 0; i < extensionAnnotation.systemParameter().length; i++) { SystemParameter systemParameterAnnotation = extensionAnnotation.systemParameter()[i]; SystemParameterMetaData systemParameter = new SystemParameterMetaData(); systemParameter.setName(systemParameterAnnotation.name()); systemParameter.setDescription(systemParameterAnnotation.description()); systemParameter.setDefaultValue(systemParameterAnnotation.defaultValue()); systemParameter .setPossibleParameters(Arrays.asList(systemParameterAnnotation.possibleParameters())); systemParameters[i] = systemParameter; } extensionMetaData.setSystemParameters(Arrays.asList(systemParameters)); // Adding return attributes ReturnAttributeMetaData[] returnAttributes = new ReturnAttributeMetaData[extensionAnnotation .returnAttributes().length]; for (int i = 0; i < extensionAnnotation.returnAttributes().length; i++) { ReturnAttribute parameterAnnotation = extensionAnnotation.returnAttributes()[i]; ReturnAttributeMetaData returnAttribute = new ReturnAttributeMetaData(); returnAttribute.setName(parameterAnnotation.name()); returnAttribute.setType(Arrays.asList(parameterAnnotation.type())); returnAttribute.setDescription(parameterAnnotation.description()); returnAttributes[i] = returnAttribute; } extensionMetaData.setReturnAttributes(Arrays.asList(returnAttributes)); // Adding examples ExampleMetaData[] examples = new ExampleMetaData[extensionAnnotation.examples().length]; for (int i = 0; i < extensionAnnotation.examples().length; i++) { Example exampleAnnotation = extensionAnnotation.examples()[i]; ExampleMetaData exampleMetaData = new ExampleMetaData(); exampleMetaData.setSyntax(exampleAnnotation.syntax()); exampleMetaData.setDescription(exampleAnnotation.description()); examples[i] = exampleMetaData; } extensionMetaData.setExamples(Arrays.asList(examples)); // Finding the namespace String namespaceName = extensionAnnotation.namespace(); if (Objects.equals(namespaceName, "")) { namespaceName = Constants.CORE_NAMESPACE; } // Finding the relevant namespace in the namespace list NamespaceMetaData namespace = null; for (NamespaceMetaData existingNamespace : namespaceList) { if (Objects.equals(existingNamespace.getName(), namespaceName)) { namespace = existingNamespace; break; } } // Creating namespace if it doesn't exist if (namespace == null) { namespace = new NamespaceMetaData(); namespace.setName(namespaceName); namespace.setExtensionMap(new TreeMap<>()); namespaceList.add(namespace); } // Adding to the relevant extension metadata list in the namespace List<ExtensionMetaData> extensionMetaDataList = namespace.getExtensionMap() .computeIfAbsent(extensionType, k -> new ArrayList<>()); extensionMetaDataList.add(extensionMetaData); } }
From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java
/** * //from w w w. j av a2 s . c o m * @param clazz * @throws HstoreParseException */ public HstoreParser(Class<T> clazz, Hstore hstore) throws HstoreParseException { this.clazz = clazz; this.fieldsWithKeys = new HashMap<>(); this.hstore = hstore; //search all fields of all classes for annotated items initFields(clazz); //find empty constructor try { constructor = clazz.getConstructor(); } catch (NoSuchMethodException | SecurityException e) { throw new HstoreParseException( HstoreParseException.HSTORE_CONSTRUCTOR_EXCEPTION + clazz.getCanonicalName(), e); } }
From source file:ar.com.jrules.core.service.LoadJRules.java
private void validateExcuteRuleAnnotationParameters() { log.debug("Found " + this.clazzWithMethodThatJRulesImplement.size() + " class with JRule implementation"); for (Class<?> clazz : this.clazzWithMethodThatJRulesImplement) { for (Method method : clazz.getMethods()) { ExecuteRule executeRuleAnnotation = method.getAnnotation(ExecuteRule.class); if (executeRuleAnnotation != null) { if (executeRuleAnnotation.ruleClass().length == 0 && executeRuleAnnotation.ruleSetName().length == 0) { throw new JRuleConfigurationException( "Found error in ExecuteRule configuration. The method '" + method.getName() + "' in class " + clazz.getCanonicalName() + " has not properly declared annotation @ExecuteRule. Remember to declare a 'ruleClass' or 'ruleSetName'"); }/*from w ww . j av a2 s.c om*/ } } } }
From source file:ar.com.allium.rules.core.service.LoadAlliumRules.java
private void validateExcuteRuleAnnotationParameters() { log.debug("Found " + this.clazzWithMethodThatAlliumRulesImplement.size() + " class with AlliumRule implementation"); for (Class<?> clazz : this.clazzWithMethodThatAlliumRulesImplement) { for (Method method : clazz.getMethods()) { ExecuteRule executeRuleAnnotation = method.getAnnotation(ExecuteRule.class); if (executeRuleAnnotation != null) { if (executeRuleAnnotation.ruleClass().length == 0 && executeRuleAnnotation.ruleSetName().length == 0) { throw new AlliumRuleConfigurationException( "Found error in ExecuteRule configuration. The method '" + method.getName() + "' in class " + clazz.getCanonicalName() + " has not properly declared annotation @ExecuteRule. Remember to declare a 'ruleClass' or 'ruleSetName'"); }//from ww w . j av a 2 s. c om } } } }
From source file:info.archinnov.achilles.entity.parsing.EmbeddedIdParser.java
private Integer extractReversedClusteredKey(Class<?> embeddedIdClass) { @SuppressWarnings("unchecked") Set<Field> candidateFields = getFields(embeddedIdClass, ReflectionUtils.<Field>withAnnotation(Order.class)); List<Integer> reversedFields = new LinkedList<Integer>(); for (Field candidateField : candidateFields) { Order orderAnnotation = candidateField.getAnnotation(Order.class); if (orderAnnotation.reversed()) { reversedFields.add(orderAnnotation.value()); }/*from ww w .j a va 2 s. c o m*/ } Validator.validateBeanMappingTrue(reversedFields.size() <= 1, "There should be at most 1 field annotated with @Order(reversed=true) for the @EmbeddedId class '%s'", embeddedIdClass.getCanonicalName()); return reversedFields.size() > 0 ? reversedFields.get(0) : null; }
From source file:de.matzefratze123.heavyspleef.core.flag.FlagRegistry.java
public void registerFlag(Class<? extends AbstractFlag<?>> clazz) { Validate.notNull(clazz, "clazz cannot be null"); Validate.isTrue(!registeredFlagsMap.containsValue(clazz), "Cannot register flag twice"); /* Check if the class provides the required Flag annotation */ Validate.isTrue(clazz.isAnnotationPresent(Flag.class), "Flag-Class must be annotated with the @Flag annotation"); Flag flagAnnotation = clazz.getAnnotation(Flag.class); String name = flagAnnotation.name(); Validate.isTrue(!name.isEmpty(),/*from w w w . j av a 2 s . c om*/ "name() of annotation of flag for class " + clazz.getCanonicalName() + " cannot be empty"); /* Generate a path */ StringBuilder pathBuilder = new StringBuilder(); Flag parentFlagData = flagAnnotation; do { pathBuilder.insert(0, parentFlagData.name()); Class<? extends AbstractFlag<?>> parentFlagClass = parentFlagData.parent(); parentFlagData = parentFlagClass.getAnnotation(Flag.class); if (parentFlagData != null && parentFlagClass != NullFlag.class) { pathBuilder.insert(0, FLAG_PATH_SEPERATOR); } } while (parentFlagData != null); String path = pathBuilder.toString(); /* Check for name collides */ for (String flagPath : registeredFlagsMap.primaryKeySet()) { if (flagPath.equalsIgnoreCase(path)) { throw new IllegalArgumentException( "Flag " + clazz.getName() + " collides with " + registeredFlagsMap.get(flagPath).getName()); } } /* Check if the class can be instantiated */ try { Constructor<? extends AbstractFlag<?>> constructor = clazz.getDeclaredConstructor(); //Make the constructor accessible for future uses constructor.setAccessible(true); } catch (NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException("Flag-Class must provide an empty constructor"); } HookManager hookManager = heavySpleef.getHookManager(); boolean allHooksPresent = true; for (HookReference ref : flagAnnotation.depend()) { if (!hookManager.getHook(ref).isProvided()) { allHooksPresent = false; } } if (allHooksPresent) { for (Method method : clazz.getDeclaredMethods()) { if (!method.isAnnotationPresent(FlagInit.class)) { continue; } if ((method.getModifiers() & Modifier.STATIC) == 0) { throw new IllegalArgumentException("Flag initialization method " + method.getName() + " in type " + clazz.getCanonicalName() + " is not declared as static"); } queuedInitMethods.add(method); } if (flagAnnotation.hasCommands()) { CommandManager manager = heavySpleef.getCommandManager(); manager.registerSpleefCommands(clazz); } } registeredFlagsMap.put(path, flagAnnotation, clazz); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java
@Override public void setValue(Object value) { DesktopBackgroundWorker.checkSwingUIAccess(); if (datasource == null && metaClass == null) { throw new IllegalStateException("Datasource or metaclass must be set for field"); }/* w w w .j a v a2 s . co m*/ if (value != null) { Class fieldClass = getMetaClass().getJavaClass(); Class<?> valueClass = value.getClass(); //noinspection unchecked if (!fieldClass.isAssignableFrom(valueClass)) { throw new IllegalArgumentException( String.format("Could not set value with class %s to field with class %s", fieldClass.getCanonicalName(), valueClass.getCanonicalName())); } } if (!InstanceUtils.propertyValueEquals(prevValue, value)) { updateInstance(value); updateComponent(value); fireChangeListeners(value); } else { updateComponent(prevValue); } }
From source file:ma.glasnost.orika.test.perf.MultiThreadedTestCase.java
/** * Verifies that multiple threads requesting the type for the same set of * classes receive the same set of values over a large number of classes. *///from w w w. j ava 2 s . co m @Test @Concurrent(100) public void testDefineTypesSimultaneously() { int i = myIndex.getAndIncrement(); int c = 0; Map<Type<?>, Class<?>> types = new HashMap<Type<?>, Class<?>>(); for (Class<?> aClass : classes) { /* * In this section, we force each of the threads to trigger a GC at * some point in mid process; this should help shake out any issues * with weak references getting cleared (that we didn't expect to be * cleared). */ ++c; Type<?> aType; try { aType = TypeFactory.valueOf(aClass); } catch (StackOverflowError e) { throw new RuntimeException("while trying to evaluate valueOf(" + aClass.getCanonicalName() + ")", e); } if (aType == null) { throw new IllegalStateException("TypeFactory.valueOf() returned null for " + aClass); } else if (types.containsKey(aType)) { throw new IllegalStateException( "mapping already exists for " + aClass + ": " + aType + " = " + types.get(aType)); } else { if (aClass.isAssignableFrom(aType.getRawType())) { types.put(aType, aClass); } else { throw new IllegalStateException(aType + " is not an instance of " + aClass); } } if (c == i) { forceClearSoftAndWeakReferences(); } } Assert.assertEquals(classes.size(), types.size()); }