List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:com.spotify.heroic.shell.Tasks.java
public static String name(final Class<? extends ShellTask> task) { final TaskName n = task.getAnnotation(TaskName.class); if (n != null) { return n.value(); }/*from w ww . jav a2s . c o m*/ throw new IllegalStateException( String.format("No name configured with @TaskName on %s", task.getCanonicalName())); }
From source file:com.baasbox.configuration.PropertiesConfigurationHelper.java
/*** * Returns an Enumerator value by its key * The Enumerator must implement the IProperties interface * @param en// w w w. j a v a 2 s . com * @param iKey * @return the enumerator value * @throws ConfigurationException * @throws Exception if the en Class is not an Enumerator that implements the IProperties interface */ public static Object findByKey(Class en, String iKey) throws ConfigurationException { EnumSet values = EnumSet.allOf(en); for (Object v : values) { try { if (((String) en.getMethod("getKey").invoke(v)).equalsIgnoreCase(iKey)) return v; } catch (Exception e) { throw new ConfigurationException( "Is it " + en.getCanonicalName() + " an Enum that implements the IProperties interface?", e); } } return null; }
From source file:com.ksmpartners.ernie.util.TestUtil.java
/** * Verifies that an object created from the given Class can be serialized to/from a JSON and the resulting object * is equal to the original./*from w w w . j a v a2 s .co m*/ * @param clazz - the Class to be verified * @throws InstantiationException, IllegalAccessException - if the object can't be instantiated */ public static <T> void verifySerialization(Class<T> clazz) throws InstantiationException, IllegalAccessException { T t = clazz.newInstance(); populateFields(clazz, t); String json = serialize(t); T newT = deserialize(json, clazz); String newJson = serialize(newT); // TODO: Verify that this is a good test. Assert.assertTrue(json.equals(newJson), "Pre and post serialization JSONs are not equal for class " + clazz.getCanonicalName()); }
From source file:com.palantir.atlasdb.table.description.ColumnValueDescription.java
@SuppressWarnings("unchecked") public static ColumnValueDescription forPersistable(Class<? extends Persistable> clazz, Compression compression) { Validate.notNull(Persistables.getHydrator(clazz), "Not a valid persistable class because it has no hydrator"); return new ColumnValueDescription(Format.PERSISTABLE, clazz.getName(), clazz.getCanonicalName(), compression, null);/*from ww w . j ava 2 s . c om*/ }
From source file:com.unboundid.scim2.common.utils.SchemaUtils.java
/** * Gets SCIM schema attributes for a class. * * @param classesProcessed a stack containing the classes processed prior * to this class. This is used for cycle detection. * @param cls the class to get the attributes for. * @return a collection of SCIM schema attributes for the class. * @throws IntrospectionException thrown if an error occurs during * Introspection./*from www . jav a 2 s . c om*/ */ private static Collection<AttributeDefinition> getAttributes(final Stack<String> classesProcessed, final Class<?> cls) throws IntrospectionException { String className = cls.getCanonicalName(); if (!cls.isAssignableFrom(AttributeDefinition.class) && classesProcessed.contains(className)) { throw new RuntimeException("Cycles detected in Schema"); } Collection<PropertyDescriptor> propertyDescriptors = getPropertyDescriptors(cls); Collection<AttributeDefinition> attributes = new ArrayList<AttributeDefinition>(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (propertyDescriptor.getName().equals("subAttributes") && cls.isAssignableFrom(AttributeDefinition.class) && classesProcessed.contains(className)) { // Skip second nesting of subAttributes the second time around // since there is no subAttributes of subAttributes in SCIM. continue; } AttributeDefinition.Builder attributeBuilder = new AttributeDefinition.Builder(); Field field = findField(cls, propertyDescriptor.getName()); if (field == null) { continue; } Attribute schemaProperty = null; JsonProperty jsonProperty = null; if (field.isAnnotationPresent(Attribute.class)) { schemaProperty = field.getAnnotation(Attribute.class); } if (field.isAnnotationPresent(JsonProperty.class)) { jsonProperty = field.getAnnotation(JsonProperty.class); } // Only generate schema for annotated fields. if (schemaProperty == null) { continue; } addName(attributeBuilder, propertyDescriptor, jsonProperty); addDescription(attributeBuilder, schemaProperty); addCaseExact(attributeBuilder, schemaProperty); addRequired(attributeBuilder, schemaProperty); addReturned(attributeBuilder, schemaProperty); addUniqueness(attributeBuilder, schemaProperty); addReferenceTypes(attributeBuilder, schemaProperty); addMutability(attributeBuilder, schemaProperty); addMultiValued(attributeBuilder, propertyDescriptor, schemaProperty); addCanonicalValues(attributeBuilder, schemaProperty); Class propertyCls = propertyDescriptor.getPropertyType(); // if this is a multivalued attribute the real sub attribute class is the // the one specified in the annotation, not the list, set, array, etc. if ((schemaProperty.multiValueClass() != NullType.class)) { propertyCls = schemaProperty.multiValueClass(); } AttributeDefinition.Type type = getAttributeType(propertyCls); attributeBuilder.setType(type); if (type == AttributeDefinition.Type.COMPLEX) { // Add this class to the list to allow cycle detection classesProcessed.push(cls.getCanonicalName()); Collection<AttributeDefinition> subAttributes = getAttributes(classesProcessed, propertyCls); attributeBuilder .addSubAttributes(subAttributes.toArray(new AttributeDefinition[subAttributes.size()])); classesProcessed.pop(); } attributes.add(attributeBuilder.build()); } return attributes; }
From source file:ca.uhn.fhir.rest.method.BaseMethodBinding.java
private static String toLogString(Class<?> theType) { if (theType == null) { return null; }//from w w w .ja v a 2 s.c o m return theType.getCanonicalName(); }
From source file:io.appium.java_client.MobileBy.java
private static IllegalArgumentException formIllegalArgumentException(Class<?> givenClass, Class<?> class1, Class<?> class2) { return new IllegalArgumentException(String.format(ERROR_TEXT, givenClass.getCanonicalName(), class1.getCanonicalName(), class2.getCanonicalName())); }
From source file:de.decoit.simu.cbor.ifmap.deserializer.ExtendedIdentifierDeserializerManager.java
/** * Register a deserializer object for vendor specific extended identifiers. * The deserializer class must implement VendorIdentifierDeserializer for the type specified * as target class./*from w ww .j a va 2s . c o m*/ * * @param <M> Vendor specific identifier type * @param deserializer Deserializer class object * @param targetClass Type of the object to be deserialized * @param namespace Namespace of the registered element * @param elementName Name of the registered element */ public static <M extends AbstractExtendedIdentifier> void registerVendorDeserializer( VendorIdentifierDeserializer<M> deserializer, Class<M> targetClass, String namespace, String elementName) { if (deserializer == null) { throw new IllegalArgumentException("VendorIdentifierDeserializer object must not be null"); } if (targetClass == null) { throw new IllegalArgumentException("Target class must not be null"); } if (registeredDeserializers.containsKey(targetClass)) { throw new IllegalStateException( "Deserializer already registered for " + targetClass.getCanonicalName()); } registerResolveKey(namespace, elementName, targetClass); registeredDeserializers.put(targetClass, deserializer); }
From source file:me.st28.flexseries.flexlib.plugin.FlexPlugin.java
/** * Retrieves a FlexPlugin's instance of a given module. * * @param plugin The class of the plugin. * @param module The class of the module. * @return The module matching the class and plugin. * @throws IllegalArgumentException Thrown if the provided module class is not registered. * @throws ModuleDisabledException Thrown if the module is disabled. *//*from ww w. ja v a2 s . com*/ public static <T extends FlexModule> T getPluginModule(Class<? extends FlexPlugin> plugin, Class<T> module) { Validate.notNull(plugin, "Plugin class cannot be null."); Validate.notNull(module, "Module class cannot be null."); FlexPlugin pluginInst = JavaPlugin.getPlugin(plugin); if (pluginInst == null) { throw new IllegalArgumentException("Plugin '" + plugin.getCanonicalName() + "' not found."); } FlexModule moduleInst = pluginInst.modules.get(module); if (moduleInst == null) { throw new IllegalArgumentException("No module '" + module.getCanonicalName() + "' is registered under plugin '" + pluginInst.getName() + "'"); } ModuleStatus status = moduleInst.getStatus(); if (!status.isEnabled()) { throw new ModuleDisabledException(moduleInst); } return (T) moduleInst; }
From source file:org.apache.metron.dataloads.taxii.TaxiiHandler.java
public static <RESPONSE_T, REQUEST_T> RESPONSE_T call(HttpClient taxiiClient, URI endpoint, REQUEST_T request, HttpClientContext context, Class<RESPONSE_T> responseClazz) throws JAXBException, IOException { //TaxiiXml taxiiXml = xmlFactory.get().createTaxiiXml(); //String req = taxiiXml.marshalToString(request, true); // Call the service Object responseObj = taxiiClient.callTaxiiService(endpoint, request, context); LOG.info("Request made : " + request.getClass().getCanonicalName() + " => " + responseObj.getClass().getCanonicalName() + " (expected " + responseClazz.getCanonicalName() + ")"); //String resp = taxiiXml.marshalToString(responseObj, true); try {/* www . j a v a 2s . c o m*/ return responseClazz.cast(responseObj); } catch (ClassCastException cce) { TaxiiXml taxiiXml = xmlFactory.get().createTaxiiXml(); String resp = taxiiXml.marshalToString(responseObj, true); String msg = "Didn't return the response we expected: " + responseObj.getClass() + " \n" + resp; LOG.error(msg, cce); throw new RuntimeException(msg, cce); } }