Example usage for java.lang Class getCanonicalName

List of usage examples for java.lang Class getCanonicalName

Introduction

In this page you can find the example usage for java.lang Class getCanonicalName.

Prototype

public String getCanonicalName() 

Source Link

Document

Returns the canonical name of the underlying class as defined by the Java Language Specification.

Usage

From source file:org.web4thejob.util.CoreUtil.java

public static String getDefaultListViewName(Class<? extends Entity> entityType) {
    return CoreUtil.getParameterValue(Category.ENTITY_TYPE_LIST_VIEW_PARAM, entityType.getCanonicalName(),
            String.class);
}

From source file:com.eucalyptus.entities.PersistenceContexts.java

static void addEntity(Class entity) {
    if (!isDuplicate(entity)) {
        String ctxName = Ats.from(entity).get(PersistenceContext.class).name();
        EventRecord.here(PersistenceContextDiscovery.class, EventType.PERSISTENCE_ENTITY_REGISTERED, ctxName,
                entity.getCanonicalName()).trace();
        entities.put(ctxName, entity);//from   ww  w .  j ava  2s . c om
    }
}

From source file:com.sqewd.open.dal.core.persistence.db.EntityHelper.java

public static void setEntity(final StructEntityReflect enref, final HashMap<String, AbstractEntity> entities,
        final ResultSet rs) throws Exception {
    Class<?> type = Class.forName(enref.Class);
    Object obj = type.newInstance();
    if (!(obj instanceof AbstractEntity))
        throw new Exception("Unsupported Entity type [" + type.getCanonicalName() + "]");
    AbstractEntity entity = (AbstractEntity) obj;
    AbstractJoinGraph gr = AbstractJoinGraph.lookup(type);

    for (StructAttributeReflect attr : enref.Attributes) {
        Stack<KeyValuePair<Class<?>>> path = new Stack<KeyValuePair<Class<?>>>();
        Class<?> at = attr.Field.getType();
        KeyValuePair<Class<?>> ak = new KeyValuePair<Class<?>>();
        ak.setValue(entity.getClass());/*from   ww  w.jav a 2  s.c o  m*/
        ak.setKey(attr.Column);
        path.push(ak);

        if (attr.Reference == null || attr.Reference.Type != EnumRefereceType.One2Many) {
            setColumnValue(rs, attr, entity, gr, path);
        } else if (attr.Reference != null) {
            // Object ao = createListInstance(entity, attr);
            Class<?> rt = Class.forName(attr.Reference.Class);
            Object ro = rt.newInstance();
            if (!(ro instanceof AbstractEntity))
                throw new Exception(
                        "Reference [" + attr.Column + "] is of invalid type. [" + at.getCanonicalName()
                                + "] does not extend from [" + AbstractEntity.class.getCanonicalName() + "]");
            AbstractEntity ae = (AbstractEntity) getColumnValue(rs, attr, entity, gr, path);
            addListValue(ae, entity, attr);
        }

    }
    String key = entity.getEntityKey();
    if (!entities.containsKey(key)) {
        entities.put(entity.getEntityKey(), entity);
    } else {
        AbstractEntity target = entities.get(key);
        for (StructAttributeReflect attr : enref.Attributes) {
            if (attr.Reference.Type == EnumRefereceType.One2Many) {
                copyToList(entity, target, attr);
            }
        }
    }
}

From source file:org.web4thejob.util.CoreUtil.java

public static String getDefaultEntityViewName(Class<? extends Entity> entityType) {
    return CoreUtil.getParameterValue(Category.ENTITY_TYPE_ENTITY_VIEW_PARAM, entityType.getCanonicalName(),
            String.class);
}

From source file:org.web4thejob.util.CoreUtil.java

public static Query getDefaultQueryForTargetType(Class<? extends Entity> targetType) {
    String id = CoreUtil.getParameterValue(Category.ENTITY_TYPE_QUERY_PARAM, targetType.getCanonicalName(),
            String.class, null);
    if (StringUtils.hasText(id)) {
        return ContextUtil.getDRS().findById(Query.class, Long.valueOf(id));
    }/*from w  w w  . ja va2s  .c o  m*/
    return null;
}

From source file:com.l2jfree.util.Introspection.java

private static boolean writeFields(Class<?> c, Object accessor, StringBuilder dest, String eol, boolean init) {
    if (c == null)
        throw new IllegalArgumentException("No class specified.");
    else if (!c.isInstance(accessor))
        throw new IllegalArgumentException(accessor + " is not a " + c.getCanonicalName());
    for (Field f : c.getDeclaredFields()) {
        int mod = f.getModifiers();
        if (Modifier.isStatic(mod))
            continue;
        if (init)
            init = false;//  w  w  w .j  ava 2 s .com
        else if (eol == null)
            dest.append(", ");
        String fieldName = null;
        final Column column = f.getAnnotation(Column.class);
        if (column != null)
            fieldName = column.name();
        if (StringUtils.isEmpty(fieldName))
            fieldName = f.getName();
        dest.append(fieldName);
        dest.append(" = ");
        try {
            f.setAccessible(true);
            Object val = f.get(accessor);
            if (accessor == val)
                dest.append("this");
            else
                deepToString(val, dest, null);
        } catch (Exception e) {
            dest.append("???");
        } finally {
            try {
                f.setAccessible(false);
            } catch (Exception e) {
                // ignore
            }
        }
        if (eol != null)
            dest.append(eol);
    }
    return !init;
}

From source file:me.st28.flexseries.flexlib.log.LogHelper.java

private static void logFromClass(Level level, Class clazz, String message) {
    Validate.notNull(clazz, "Class cannot be null.");
    Validate.notNull(message, "Message cannot be null.");

    if (FlexPlugin.class.isAssignableFrom(clazz)) {
        JavaPlugin plugin = JavaPlugin.getPlugin(clazz);

        if (plugin == null) {
            throw new IllegalArgumentException("Plugin '" + clazz.getCanonicalName() + "' not found.");
        }/*from   w  w w.  j  ava 2  s. co  m*/

        if (!(plugin instanceof FlexPlugin)) {
            throw new IllegalArgumentException("Plugin '" + plugin.getName() + "' is not a FlexPlugin.");
        }

        FlexPlugin fp = (FlexPlugin) plugin;

        if (level == Level.INFO) {
            info(fp, message);
        } else if (level == Level.WARNING) {
            warning(fp, message);
        } else if (level == Level.SEVERE) {
            severe(fp, message);
        } else if (level == null) {
            debug(fp, message);
        }
        throw new IllegalArgumentException("Invalid log level '" + level.getName() + "'");
    }

    if (FlexModule.class.isAssignableFrom(clazz)) {
        throw new IllegalArgumentException("Invalid log level '" + level.getName() + "'");
    }

    throw new IllegalArgumentException(
            "Class '" + clazz.getCanonicalName() + "' must be an instance of FlexPlugin or FlexModule.");
}

From source file:com.skcraft.launcher.persistence.Persistence.java

/**
 * Read an object from a byte source, without binding it.
 *
 * @param source byte source//from  ww w .  j ava  2 s .c  o m
 * @param cls the class
 * @param returnNull true to return null if the object could not be loaded
 * @param <V> the type of class
 * @return an object
 */
public static <V> V read(ByteSource source, Class<V> cls, boolean returnNull) {
    V object;
    Closer closer = Closer.create();

    try {
        object = mapper.readValue(closer.register(source.openBufferedStream()), cls);
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            log.log(Level.INFO, "Failed to load" + cls.getCanonicalName(), e);
        }

        if (returnNull) {
            return null;
        }

        try {
            object = cls.newInstance();
        } catch (InstantiationException e1) {
            throw new RuntimeException("Failed to construct object with no-arg constructor", e1);
        } catch (IllegalAccessException e1) {
            throw new RuntimeException("Failed to construct object with no-arg constructor", e1);
        }
    } finally {
        try {
            closer.close();
        } catch (IOException e) {
        }
    }

    return object;
}

From source file:com.krm.dbaudit.common.utils.Collections3.java

/**
  * map?bean//  w  ww  . jav  a 2  s.c  om
  *
  * @param map
  * @param beanClass
  * @return
  */
public static Object map2Bean(Map map, Class<?> beanClass) {
    try {
        //            Object bean = beanClass.newInstance();
        //            PropertyUtils.copyProperties(bean, map);
        return convertMap(beanClass, map);
    } catch (Exception e) {
        throw new RuntimeException(beanClass.getCanonicalName() + "!");
    }
}

From source file:io.fabric8.forge.rest.dto.UICommands.java

public static PropertyDTO createInputDTO(UIContext context, InputComponent<?, ?> input) {
    String name = input.getName();
    String description = input.getDescription();
    String label = input.getLabel();
    String requiredMessage = input.getRequiredMessage();
    char shortNameChar = input.getShortName();
    String shortName = Character.toString(shortNameChar);
    Object inputValue = InputComponents.getValueFor(input);

    /*// w w  w.j a v  a2 s . c  o m
            if (input instanceof ManyValued) {
    ManyValued manyValued = (ManyValued) input;
    inputValue = manyValued.getValue();
            }
    */
    Object value = convertValueToSafeJson(input.getValueConverter(), inputValue);

    Class<?> valueType = input.getValueType();
    String javaType = null;
    if (valueType != null) {
        javaType = valueType.getCanonicalName();
    }
    String type = JsonSchemaTypes.getJsonSchemaTypeName(valueType);
    boolean enabled = input.isEnabled();
    boolean required = input.isRequired();
    List<Object> enumValues = new ArrayList<>();
    List<Object> typeaheadData = new ArrayList<>();
    if (input instanceof SelectComponent) {
        SelectComponent selectComponent = (SelectComponent) input;
        Iterable valueChoices = selectComponent.getValueChoices();
        Converter converter = selectComponent.getItemLabelConverter();

        boolean isJson = isJsonDTO(javaType);
        for (Object valueChoice : valueChoices) {
            Object jsonValue;
            if (isJson) {
                jsonValue = Proxies.unwrap(valueChoice);
            } else {
                jsonValue = convertValueToSafeJson(converter, valueChoice);
            }
            enumValues.add(jsonValue);
        }
    }
    if (input instanceof HasCompleter) {
        HasCompleter hasCompleter = (HasCompleter) input;
        UICompleter completer = hasCompleter.getCompleter();
        if (completer != null) {
            String textValue = inputValue != null ? inputValue.toString() : "";
            Iterable valueChoices = completer.getCompletionProposals(context, input, textValue);
            // TODO is there a way to find a converter?
            Converter converter = null;
            for (Object valueChoice : valueChoices) {
                Object jsonValue = convertValueToSafeJson(converter, valueChoice);
                typeaheadData.add(jsonValue);
            }
        }
    }
    if (enumValues.isEmpty()) {
        enumValues = null;
    }
    if (typeaheadData.isEmpty()) {
        typeaheadData = null;
    }
    return new PropertyDTO(name, description, label, requiredMessage, value, javaType, type, enabled, required,
            enumValues, typeaheadData);
}