List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:info.archinnov.achilles.internals.schema.SchemaValidator.java
public static void validateDefaultTTL(AbstractTableMetadata metadata, Optional<Integer> staticTTL, Class<?> entityClass) { if (staticTTL.isPresent()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Validating table %s default TTL value", metadata.getName())); }/*from w w w . j a v a2 s .c om*/ final int defaultTimeToLive = metadata.getOptions().getDefaultTimeToLive(); validateBeanMappingTrue(staticTTL.get().equals(defaultTimeToLive), "Default TTL '%s' declared on entity '%s' does not match detected default TTL '%s' in live schema", staticTTL.get(), entityClass.getCanonicalName(), defaultTimeToLive); } }
From source file:cn.org.awcp.core.mybatis.mapper.EntityHelper.java
/** * ?/*w ww . j ava 2s . co m*/ * * @param entityClass * @return */ public static EntityTable getEntityTable(Class<?> entityClass) { EntityTable entityTable = entityTableMap.get(entityClass); if (entityTable == null) { initEntityNameMap(entityClass); entityTable = entityTableMap.get(entityClass); } if (entityTable == null) { throw new RuntimeException( "?" + entityClass.getCanonicalName() + "??!"); } return entityTable; }
From source file:de.decoit.simu.cbor.ifmap.deserializer.MetadataDeserializerManager.java
/** * Register a deserializer object for vendor specific metadata. * The deserializer class must implement VendorMetadataDeserializer for the type specified * as target class./*from ww w .j ava2 s.com*/ * * @param <M> Vendor specific metadata 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 AbstractMetadata> void registerVendorDeserializer( VendorMetadataDeserializer<M> deserializer, Class<M> targetClass, String namespace, String elementName) { if (deserializer == null) { throw new IllegalArgumentException("VendorMetadataDeserializer 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:com.baasbox.configuration.PropertiesConfigurationHelper.java
public static Object findByKey(String completeKey) throws ConfigurationException { String[] splittedKeys = completeKey.split("\\."); String section = splittedKeys[0]; Class en = PropertiesConfigurationHelper.CONFIGURATION_SECTIONS.get(section); EnumSet values = EnumSet.allOf(en); for (Object v : values) { try {//w w w.j a va 2s. c o m String key = StringUtils.join(Arrays.copyOfRange(splittedKeys, 1, splittedKeys.length), "."); if (((String) en.getMethod("getKey").invoke(v)).equalsIgnoreCase(key)) 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:Main.java
public static String getPrimitiveLetter(Class<?> paramClass) { if (Integer.TYPE.equals(paramClass)) { return "I"; }/*from w w w .j av a 2s. co m*/ if (Void.TYPE.equals(paramClass)) { return "V"; } if (Boolean.TYPE.equals(paramClass)) { return "Z"; } if (Character.TYPE.equals(paramClass)) { return "C"; } if (Byte.TYPE.equals(paramClass)) { return "B"; } if (Short.TYPE.equals(paramClass)) { return "S"; } if (Float.TYPE.equals(paramClass)) { return "F"; } if (Long.TYPE.equals(paramClass)) { return "J"; } if (Double.TYPE.equals(paramClass)) { return "D"; } throw new IllegalStateException("Type: " + paramClass.getCanonicalName() + " is not a primitive type"); }
From source file:com.github.venkateshamurthy.designpatterns.builders.FluentBuilders.java
/** * Get a Builder Proxy from POJO.//from ww w.ja va 2 s . co m * * @param <S> * represents a POJO class type * @param <T> * represents a Builder of type S * @param pojoClass * is the class to which a builder is needed * @return a builder of type pojoBuilder<pojo> * @throws ClassNotFoundException when pojoclass is not found */ public static <S, T extends Builder<S>> T builder(final Class<S> pojoClass) throws ClassNotFoundException { if (pojoClass == null) { throw new IllegalArgumentException( "Parameter to this method must be a valid public class obect representing a POJO"); } final String builderInterfaceName = pojoClass.getCanonicalName() + "Builder"; @SuppressWarnings("unchecked") final Class<T> pojoBuilderInterface = (Class<T>) Class.forName(builderInterfaceName); return ReflectionBuilder.<T>implementationFor(pojoBuilderInterface).create(); }
From source file:com.feilong.core.lang.EnumUtil.java
/** * <code>propertyName</code> <code>specifiedValue</code> . * // w w w .j a va 2 s. co m * <p> * <code>HttpMethodType</code> ?,?: * </p> * * <pre class="code"> * EnumUtil.getEnumByField(HttpMethodType.class, "method", "get") * </pre> * * <h3>:</h3> * * <blockquote> * <p> * ??,?<code>propertyName</code> <code>specifiedValue</code>,null * </p> * </blockquote> * * @param <E> * the element type * @param <T> * the generic type * @param enumClass * <code>HttpMethodType</code> * @param propertyName * ??, <code>HttpMethodType</code> method,javabean * @param specifiedValue * post * @param ignoreCase * ?? * @return the enum by property value * @throws NullPointerException * <code>enumClass</code> null, <code>propertyName</code> null * @throws IllegalArgumentException * <code>propertyName</code> blank * @throws BeanUtilException * <code>propertyName</code> , <code>HttpMethodType</code> <b>"method"</b> , <b>"method2222"</b> * @see com.feilong.core.bean.PropertyUtil#getProperty(Object, String) * @since 1.0.8 */ private static <E extends Enum<?>, T> E getEnumByPropertyValue(Class<E> enumClass, String propertyName, T specifiedValue, boolean ignoreCase) { Validate.notNull(enumClass, "enumClass can't be null!"); Validate.notBlank(propertyName, "propertyName can't be null/empty!"); //************************************************************************* // An enum is a kind of class // An annotation is a kind of interface // Class ?, null. E[] enumConstants = enumClass.getEnumConstants(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("enumClass:[{}],enumConstants:{}", enumClass.getCanonicalName(), JsonUtil.format(enumConstants, 0, 0)); } //************************************************************************* for (E e : enumConstants) { Object propertyValue = PropertyUtil.getProperty(e, propertyName); if (isEquals(propertyValue, specifiedValue, ignoreCase)) { return e; } } //************************************************************************* if (LOGGER.isInfoEnabled()) { String messagePattern = "[{}],propertyName:[{}],value:[{}],ignoreCase:[{}],constants not found"; LOGGER.info(Slf4jUtil.format(messagePattern, enumClass, propertyName, specifiedValue, ignoreCase)); } return null; }
From source file:cross.applicationContext.ReflectionApplicationContextGenerator.java
/** * Checks and adds type information for the given method, class and object * to the properties list.// ww w . j a v a 2s .c om * * @param method the method to check for a property * @param javaClass the class to check for settable property * @param obj the stub / default object of type javaClass * @param properties the properties list */ public static void checkMutableProperties(Method method, Class<?> javaClass, Object obj, List<ObjectProperty> properties) { if (method.getName().startsWith("get") || method.getName().startsWith("is")) { String methodBaseName = method.getName().startsWith("get") ? method.getName().substring(3) : method.getName().substring(2); try { //check for corresponding setter if (javaClass.getMethod("set" + methodBaseName, method.getReturnType()) != null) { String propertyName = toLowerCaseName(methodBaseName); // System.out.print("Handling property " + propertyName); ObjectProperty p = new ObjectProperty(); Class<?> returnType = method.getReturnType(); if (returnType.isArray()) { p.type = "Array"; } else { p.type = returnType.getCanonicalName(); } Class<?> genericReturnType = getGenericMethodReturnType(method); p.genericType = genericReturnType.getCanonicalName(); p.name = propertyName; Object methodObject = null; try { methodObject = method.invoke(obj); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { log.warn(ex.getLocalizedMessage()); } String value = null; if (methodObject == null) { value = ""; } else { if (methodObject.getClass().isArray()) { value = methodObject.getClass().getComponentType().getCanonicalName(); } else { value = methodObject.toString(); } } if (value == null) { value = ""; } else { value = value.trim(); } if (value.contains("\"")) { //remove the quotes that surround Strings value = value.replaceAll("\"", ""); } else if (value.contains("'")) { //remove the quotes that surround characters value = value.replaceAll("'", ""); } else if (value.endsWith("d") || value.endsWith("D") || value.endsWith("f") || value.endsWith("F") || value.endsWith("l") || value.endsWith("L")) { //remove the "double", "float", or "long" letters if they are there value = value.substring(0, value.length() - 1); } p.value = value; System.out.println(" value: " + p.value + " type: " + p.type); properties.add(p); } } catch (NoSuchMethodException ex) { log.info("Ignoring read-only property {}", methodBaseName); //Logger.getLogger(ReflectionApplicationContextGenerator.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { log.warn(ex.getLocalizedMessage()); } } }
From source file:com.discovery.darchrow.lang.EnumUtil.java
/** * fieldName value <br>//from www .j a va 2 s . c o m * * <pre> * * ?{@link HttpMethodType} ,?: * * {@code * EnumUtil.getEnumByField(HttpMethodType.class, "method", "get") * } * </pre> * * @param <E> * the element type * @param <T> * the generic type * @param enumClass * the enum class {@link HttpMethodType} * @param propertyName * ??, {@link HttpMethodType}method,javabean * @param value * post * @param ignoreCase * ?? * @return enum constant * @see com.baozun.nebulaplus.bean.BeanUtil#getProperty(Object, String) * @since 1.0.8 */ private static <E extends Enum<?>, T> E getEnumByPropertyValue(Class<E> enumClass, String propertyName, T value, boolean ignoreCase) { if (Validator.isNullOrEmpty(enumClass)) { throw new IllegalArgumentException("enumClass is null or empty!"); } if (Validator.isNullOrEmpty(propertyName)) { throw new IllegalArgumentException("the fieldName is null or empty!"); } // An enum is a kind of class // and an annotation is a kind of interface // Class ? null. E[] enumConstants = enumClass.getEnumConstants(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("enumClass:[{}],enumConstants:{}", enumClass.getCanonicalName(), JsonUtil.format(enumConstants)); } for (E e : enumConstants) { Object propertyValue = PropertyUtil.getProperty(e, propertyName); if (null == propertyValue && null == value) { return e; } if (null != propertyValue && null != value) { if (ignoreCase && propertyValue.toString().equalsIgnoreCase(value.toString())) { return e; } else if (propertyValue.equals(value)) { return e; } } } String messagePattern = "can not found the enum constants,enumClass:[{}],propertyName:[{}],value:[{}],ignoreCase:[{}]"; throw new BeanUtilException( Slf4jUtil.formatMessage(messagePattern, enumClass, propertyName, value, ignoreCase)); }
From source file:com.javadeobfuscator.deobfuscator.DeobfuscatorMain.java
public static int run(String[] args) { Options options = new Options(); options.addOption("transformer", true, "A transformer to use"); options.addOption("path", true, "A JAR to be placed in the classpath"); options.addOption("input", true, "The input file"); options.addOption("output", true, "The output file"); //TODO:/* w w w.ja v a 2s .co m*/ // * keepClass // * custom normalizer name CommandLineParser parser = new DefaultParser(); try { Deobfuscator deobfuscator = new Deobfuscator(); CommandLine cmd = parser.parse(options, args); if (!cmd.hasOption("input")) { System.out.println("No input jar specified"); return 3; } if (!cmd.hasOption("output")) { System.out.println("No output jar specified"); return 4; } File input = new File(cmd.getOptionValue("input")); if (!input.exists()) { System.out.println("Input file does not exist"); return 5; } File output = new File(cmd.getOptionValue("output")); if (output.exists()) { System.out.println("Warning! Output file already exists"); } deobfuscator.withInput(input).withOutput(output); String[] transformers = cmd.getOptionValues("transformer"); if (transformers == null || transformers.length == 0) { System.out.println("No transformers specified"); return 2; } for (String transformer : transformers) { Class<?> clazz = null; try { clazz = Class.forName("com.javadeobfuscator.deobfuscator.transformers." + transformer); } catch (ClassNotFoundException exception) { try { clazz = Class.forName(transformer); } catch (ClassNotFoundException exception1) { System.out.println("Could not locate transformer " + transformer); } } if (clazz != null) { if (Transformer.class.isAssignableFrom(clazz)) { deobfuscator.withTransformer(clazz.asSubclass(Transformer.class)); } else { System.out.println(clazz.getCanonicalName() + " does not extend com.javadeobfuscator.deobfuscator.transformers.Transformer"); } } } String[] paths = cmd.getOptionValues("path"); if (paths != null) { for (String path : paths) { File file = new File(path); if (file.exists()) { deobfuscator.withClasspath(file); } else { System.out.println("Could not find classpath file " + path); } } } try { deobfuscator.start(); return 0; } catch (Deobfuscator.NoClassInPathException ex) { System.out.println("Could not locate a class file."); System.out.println("Have you added the necessary files to the -path argument?"); System.out.println("The error was:"); ex.printStackTrace(System.out); return -2; } catch (Throwable t) { System.out.println("Deobfuscation failed. Please open a ticket on GitHub"); t.printStackTrace(System.out); return -1; } } catch (ParseException e) { return 1; } }