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:io.swagger.inflector.config.Configuration.java

public Map<String, String> getModelMappings() {
    Map<String, String> output = new HashMap<String, String>();
    for (String key : modelMap.keySet()) {
        Class<?> value = modelMap.get(key);
        output.put(key, value.getCanonicalName());
    }/* w  ww.  j  av  a 2 s.  c  o  m*/
    return output;
}

From source file:org.ff4j.aop.FeatureAdvisor.java

/** {@inheritDoc} */
@Override/*  w w w  . jav a  2  s  . c  om*/
public Object postProcessBeforeInitialization(Object bean, String beanName) {
    // Before Initializing allow to check Annotations
    Class<?> target = bean.getClass();
    // Scan interface only once.
    if (!target.isInterface() && target.getInterfaces() != null) {
        // Get Interface
        for (Class<?> currentInterface : target.getInterfaces()) {
            String currentInterfaceName = currentInterface.getCanonicalName();
            if (!currentInterfaceName.startsWith("java.")
                    && !targetInterfacesNames.contains(currentInterfaceName)) {
                targetInterfacesNames.add(currentInterfaceName);
            }
        }
    }
    return bean;
}

From source file:com.netflix.paas.config.base.ConfigurationProxyUtils.java

static Supplier<?> getDynamicSupplier(Class<?> type, String key, String defaultValue,
        DynamicPropertyFactory propertyFactory) {
    if (type.isAssignableFrom(String.class)) {
        return new PropertyWrapperSupplier<String>(propertyFactory.getStringProperty(key, defaultValue));
    } else if (type.isAssignableFrom(Integer.class)) {
        return new PropertyWrapperSupplier<Integer>(
                propertyFactory.getIntProperty(key, defaultValue == null ? 0 : Integer.parseInt(defaultValue)));
    } else if (type.isAssignableFrom(Double.class)) {
        return new PropertyWrapperSupplier<Double>(propertyFactory.getDoubleProperty(key,
                defaultValue == null ? 0.0 : Double.parseDouble(defaultValue)));
    } else if (type.isAssignableFrom(Long.class)) {
        return new PropertyWrapperSupplier<Long>(
                propertyFactory.getLongProperty(key, defaultValue == null ? 0L : Long.parseLong(defaultValue)));
    } else if (type.isAssignableFrom(Boolean.class)) {
        return new PropertyWrapperSupplier<Boolean>(propertyFactory.getBooleanProperty(key,
                defaultValue == null ? false : Boolean.parseBoolean(defaultValue)));
    }//from  w  ww.  j av  a2  s .c om
    throw new RuntimeException("Unsupported value type " + type.getCanonicalName());
}

From source file:com.flipkart.foxtrot.server.util.ManagedActionScanner.java

@Override
public void start() throws Exception {
    Reflections reflections = new Reflections("com.flipkart.foxtrot", new SubTypesScanner());
    Set<Class<? extends Action>> actions = reflections.getSubTypesOf(Action.class);
    if (actions.isEmpty()) {
        throw new Exception("No analytics actions found!!");
    }//from   w  w w  .  j a v  a2  s  .  c o m
    List<NamedType> types = new Vector<NamedType>();
    for (Class<? extends Action> action : actions) {
        AnalyticsProvider analyticsProvider = action.getAnnotation(AnalyticsProvider.class);
        if (null == analyticsProvider.request() || null == analyticsProvider.opcode()
                || analyticsProvider.opcode().isEmpty() || null == analyticsProvider.response()) {
            throw new Exception("Invalid annotation on " + action.getCanonicalName());
        }
        if (analyticsProvider.opcode().equalsIgnoreCase("default")) {
            logger.warn("Action " + action.getCanonicalName() + " does not specify cache token. "
                    + "Using default cache.");
        }
        analyticsLoader.register(new ActionMetadata(analyticsProvider.request(), action,
                analyticsProvider.cacheable(), analyticsProvider.opcode()));
        types.add(new NamedType(analyticsProvider.request(), analyticsProvider.opcode()));
        types.add(new NamedType(analyticsProvider.response(), analyticsProvider.opcode()));
        logger.info("Registered action: " + action.getCanonicalName());
    }
    SubtypeResolver subtypeResolver = environment.getObjectMapperFactory().getSubtypeResolver();
    subtypeResolver.registerSubtypes(types.toArray(new NamedType[types.size()]));
}

From source file:com.haulmont.cuba.desktop.sys.DesktopExternalUIComponentsSource.java

@SuppressWarnings("unchecked")
protected void _registerComponent(InputStream is) throws ClassNotFoundException {
    ClassLoader classLoader = App.class.getClassLoader();

    Element rootElement = Dom4j.readDocument(is).getRootElement();
    List<Element> components = rootElement.elements("component");
    for (Element component : components) {
        String name = trimToEmpty(component.elementText("name"));
        String componentClassName = trimToEmpty(component.elementText("class"));

        String componentLoaderClassName = trimToEmpty(component.elementText("componentLoader"));
        String tag = trimToEmpty(component.elementText("tag"));
        if (StringUtils.isEmpty(tag)) {
            tag = name;//from w  ww.ja  v a  2 s  .c  o m
        }

        if (StringUtils.isEmpty(name) && StringUtils.isEmpty(tag)) {
            log.warn("You have to provide name or tag for custom component");
            // skip this <component> element
            continue;
        }

        if (StringUtils.isEmpty(componentLoaderClassName) && StringUtils.isEmpty(componentClassName)) {
            log.warn("You have to provide at least <class> or <componentLoader> for custom component {} / <{}>",
                    name, tag);
            // skip this <component> element
            continue;
        }

        if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(componentClassName)) {
            Class<?> componentClass = classLoader.loadClass(componentClassName);

            if (Component.class.isAssignableFrom(componentClass)) {
                log.trace("Register component {} class {}", name, componentClass.getCanonicalName());

                DesktopComponentsFactory.registerComponent(name, (Class<? extends Component>) componentClass);
            } else {
                log.warn("Component {} is not a subclass of com.haulmont.cuba.gui.components.Component",
                        componentClassName);
            }
        }

        if (StringUtils.isNotEmpty(tag) && StringUtils.isNotEmpty(componentLoaderClassName)) {
            Class<?> componentLoaderClass = classLoader.loadClass(componentLoaderClassName);

            if (ComponentLoader.class.isAssignableFrom(componentLoaderClass)) {
                log.trace("Register tag {} loader {}", tag, componentLoaderClass.getCanonicalName());

                LayoutLoaderConfig.registerLoader(tag, (Class<? extends ComponentLoader>) componentLoaderClass);
            } else {
                log.warn(
                        "Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader",
                        componentLoaderClassName);
            }
        }
    }

    _loadWindowLoaders(rootElement);
}

From source file:com.haulmont.cuba.web.sys.WebExternalUIComponentsSource.java

@SuppressWarnings("unchecked")
protected void _registerComponent(InputStream is) throws ClassNotFoundException {
    ClassLoader classLoader = App.class.getClassLoader();

    Element rootElement = Dom4j.readDocument(is).getRootElement();
    List<Element> components = rootElement.elements("component");
    for (Element component : components) {
        String name = trimToEmpty(component.elementText("name"));
        String componentClassName = trimToEmpty(component.elementText("class"));

        String componentLoaderClassName = trimToEmpty(component.elementText("componentLoader"));
        String tag = trimToEmpty(component.elementText("tag"));
        if (StringUtils.isEmpty(tag)) {
            tag = name;//from   w ww .j a v a2s  .com
        }

        if (StringUtils.isEmpty(name) && StringUtils.isEmpty(tag)) {
            log.warn("You have to provide name or tag for custom component");
            // skip this <component> element
            continue;
        }

        if (StringUtils.isEmpty(componentLoaderClassName) && StringUtils.isEmpty(componentClassName)) {
            log.warn("You have to provide at least <class> or <componentLoader> for custom component {} / <{}>",
                    name, tag);
            // skip this <component> element
            continue;
        }

        if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(componentClassName)) {
            Class<?> componentClass = classLoader.loadClass(componentClassName);

            if (Component.class.isAssignableFrom(componentClass)) {
                log.trace("Register component {} class {}", name, componentClass.getCanonicalName());

                webComponentsFactory.register(name, (Class<? extends Component>) componentClass);
            } else {
                log.warn("Component {} is not a subclass of com.haulmont.cuba.gui.components.Component",
                        componentClassName);
            }
        }

        if (StringUtils.isNotEmpty(tag) && StringUtils.isNotEmpty(componentLoaderClassName)) {
            Class<?> componentLoaderClass = classLoader.loadClass(componentLoaderClassName);

            if (ComponentLoader.class.isAssignableFrom(componentLoaderClass)) {
                log.trace("Register tag {} loader {}", tag, componentLoaderClass.getCanonicalName());

                LayoutLoaderConfig.registerLoader(tag, (Class<? extends ComponentLoader>) componentLoaderClass);
            } else {
                log.warn(
                        "Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader",
                        componentLoaderClassName);
            }
        }
    }

    _loadWindowLoaders(rootElement);
}

From source file:info.archinnov.achilles.internals.interceptor.DefaultPreMutateBeanValidationInterceptor.java

@Override
public boolean acceptEntity(Class<?> entityClass) {
    if (!constrainedClasses.containsKey(entityClass)) {
        constrainedClasses.put(entityClass, validator.getConstraintsForClass(entityClass).isBeanConstrained());
    }/*from  w  ww.j ava2 s . c  o  m*/
    final Boolean acceptEntity = constrainedClasses.get(entityClass);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(format("Accept entity %s for bean validation ? %s", entityClass.getCanonicalName(),
                acceptEntity));
    }
    return acceptEntity;
}

From source file:io.swagger.inflector.processors.BinaryProcessor.java

@Override
public Object process(MediaType mediaType, InputStream entityStream, Class<?> cls) throws ConversionException {
    try {//from  w w  w. j  av a2  s.c  om
        return IOUtils.toByteArray(entityStream);
    } catch (IOException e) {
        LOGGER.trace("unable to extract entity from content-type `" + mediaType + "` to byte[]", e);
        throw new ConversionException().message(new ValidationMessage().code(ValidationError.UNACCEPTABLE_VALUE)
                .message("unable to convert input to " + cls.getCanonicalName()));
    }
}

From source file:com.netflix.simianarmy.basic.BasicSimianArmyContext.java

/**
 * Load a class specified by the config; for drop-in replacements.
 * (Duplicates a method in MonkeyServer; refactor to util?).
 *
 * @param key//from w  w w  .  j  a  v  a 2 s . c  o m
 * @return
 */
@SuppressWarnings("rawtypes")
private Class loadClientClass(String key) {
    ClassLoader classLoader = getClass().getClassLoader();
    try {
        String clientClassName = config.getStrOrElse(key, null);
        if (clientClassName == null || clientClassName.isEmpty()) {
            LOGGER.info("using standard class for " + key);
            return null;
        }
        Class newClass = classLoader.loadClass(clientClassName);
        LOGGER.info("using " + key + " loaded " + newClass.getCanonicalName());
        return newClass;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Could not load " + key, e);
    }
}

From source file:com.sqewd.open.dal.services.DataServices.java

@Path("/read/{type}")
@GET//from   w w  w . jav a 2  s  . com
@Produces(MediaType.APPLICATION_JSON)
public JResponse<DALResponse> read(@Context HttpServletRequest req, @PathParam("type") String type,
        @DefaultValue("") @QueryParam("q") String query, @DefaultValue("1") @QueryParam("p") String page,
        @DefaultValue("20") @QueryParam("s") String size, @DefaultValue("off") @QueryParam("d") String debugs)
        throws Exception {
    try {
        Timer timer = new Timer();

        log.debug("[ENTITY TYPE:" + type + "]");

        int pagec = Integer.parseInt(page);
        int limit = Integer.parseInt(size);
        int count = pagec * limit;
        boolean debug = false;
        if (debugs.compareToIgnoreCase("on") == 0)
            debug = true;

        DataManager dm = DataManager.get();

        StructEntityReflect enref = ReflectionUtils.get().getEntityMetadata(type);
        if (enref == null)
            throw new Exception("No entity found for type [" + type + "]");
        Class<?> typec = Class.forName(enref.Class);

        List<AbstractEntity> data = dm.read(query, typec, count);
        DALResponse response = new DALResponse();
        String path = "/read/" + typec.getCanonicalName() + "?q=" + query;
        response.setRequest(path);
        if (data == null || data.size() <= 0) {
            response.setState(EnumResponseState.NoData);
        } else {
            response.setState(EnumResponseState.Success);
            int stindex = limit * (pagec - 1);
            if (stindex > 0) {
                if (stindex > data.size()) {
                    response.setState(EnumResponseState.NoData);
                } else {
                    List<AbstractEntity> subdata = data.subList(stindex, data.size());
                    DALReadResponse rr = new DALReadResponse();
                    rr.setData(subdata);
                    if (debug) {
                        EntitySchema schema = EntitySchema.loadSchema(typec);
                        rr.setSchema(schema);
                    }
                    response.setData(rr);
                }
            } else {
                DALReadResponse rr = new DALReadResponse();
                rr.setData(data);
                if (debug) {
                    EntitySchema schema = EntitySchema.loadSchema(typec);
                    rr.setSchema(schema);
                }
                response.setData(rr);
            }
        }
        response.setTimetaken(timer.stop());

        return JResponse.ok(response).build();
    } catch (Exception e) {
        LogUtils.stacktrace(log, e);
        log.error(e.getLocalizedMessage());

        DALResponse response = new DALResponse();
        response.setState(EnumResponseState.Exception);
        response.setMessage(e.getLocalizedMessage());
        return JResponse.ok(response).build();
    }
}