Example usage for java.lang Class getPackage

List of usage examples for java.lang Class getPackage

Introduction

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

Prototype

public Package getPackage() 

Source Link

Document

Gets the package of this class.

Usage

From source file:org.apache.streams.moreover.MoreoverXmlActivitySerializer.java

private JAXBContext createContext(Class articleClass) {
    JAXBContext context;/*from  w ww  .  j  a va2  s.  c o m*/
    try {
        context = JAXBContext.newInstance(articleClass.getPackage().getName(),
                ObjectFactory.class.getClassLoader());
    } catch (JAXBException ex) {
        throw new IllegalStateException("Unable to create JAXB Context for Moreover data", ex);
    }
    return context;
}

From source file:org.carewebframework.ui.zk.ZKUtil.java

/**
 * Returns the ZK resource path for the specified class.
 * /*from  ww w  .  j a  v  a2 s .c om*/
 * @param clazz Class to evaluate
 * @return String representing resource path
 */
public static final String getResourcePath(Class<?> clazz) {
    return getResourcePath(clazz.getPackage());
}

From source file:com.tojc.ormlite.android.annotation.info.ContentMimeTypeVndInfo.java

public ContentMimeTypeVndInfo(AnnotatedElement element) {
    DefaultContentMimeTypeVnd contentMimeTypeVnd = element.getAnnotation(DefaultContentMimeTypeVnd.class);
    String name = null;// w ww.j a v a2s.  c  o m
    String type = null;
    if (contentMimeTypeVnd != null) {
        name = contentMimeTypeVnd.name();
        type = contentMimeTypeVnd.type();
    }

    if (element instanceof Class<?>) {
        Class<?> clazz = (Class<?>) element;
        if (StringUtils.isEmpty(name)) {
            name = clazz.getPackage().getName() + PROVIDER_SUFFIX;
        }

        if (StringUtils.isEmpty(type)) {
            type = clazz.getSimpleName().toLowerCase();
        }
    }

    initialize(name, type);
}

From source file:org.wso2.andes.configuration.AndesConfigurationManager.java

/**
 * Given the data type and the value read from a config, this returns the parsed value
 * of the property./* ww w  . j a  v  a2  s. c  om*/
 *
 * @param key          The Key to the property being read (n xpath format as contained in file.)
 * @param dataType     Expected data type of the property
 * @param defaultValue This parameter should NEVER be null since we assign a default value to
 *                     every config property.
 * @param <T>          Expected data type of the property
 * @return Value of config in the expected data type.
 * @throws ConfigurationException
 */
public static <T> T deriveValidConfigurationValue(String key, Class<T> dataType, String defaultValue)
        throws ConfigurationException {

    if (log.isDebugEnabled()) {
        log.debug("Reading andes configuration value " + key);
    }

    String readValue = compositeConfiguration.getString(key);

    String validValue = defaultValue;

    // If the dataType is a Custom Config Module class, the readValue will be null (since the child properties
    // are the ones with values.). Therefore the warning is printed only in other situations.
    if (StringUtils.isBlank(readValue) && !CONFIG_MODULE_PACKAGE.equals(dataType.getPackage().getName())) {
        log.warn("Error when trying to read property : " + key + ". Switching to " + "default value : "
                + defaultValue);
    } else {
        validValue = overrideWithDecryptedValue(key, readValue);
    }

    if (log.isDebugEnabled()) {
        log.debug("Valid value read for andes configuration property " + key + " is : " + validValue);
    }

    try {

        if (Boolean.class.equals(dataType)) {
            return dataType.cast(Boolean.parseBoolean(validValue));

        } else if (Date.class.equals(dataType)) {
            // Sample date : "Sep 28 20:29:30 JST 2000"
            DateFormat df = new SimpleDateFormat("MMM dd kk:mm:ss z yyyy", Locale.ENGLISH);
            return dataType.cast(df.parse(validValue));

        } else if (dataType.isEnum()) {
            // this will indirectly forces programmer to define enum values in upper case
            return (T) Enum.valueOf((Class<? extends Enum>) dataType, validValue.toUpperCase(Locale.ENGLISH));

        } else if (CONFIG_MODULE_PACKAGE.equals(dataType.getPackage().getName())) {
            // Custom data structures defined within this package only need the root Xpath to extract the other
            // required child properties to construct the config object.
            return dataType.getConstructor(String.class).newInstance(key);

        } else {
            return dataType.getConstructor(String.class).newInstance(validValue);
        }

    } catch (NoSuchMethodException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    } catch (ParseException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    } catch (InvocationTargetException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    } catch (InstantiationException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    }
}

From source file:com.tojc.ormlite.android.annotation.info.ContentUriInfo.java

public ContentUriInfo(AnnotatedElement element) {
    DefaultContentUri contentUri = element.getAnnotation(DefaultContentUri.class);
    String authority = null;/*w ww .j  av a 2s .  c om*/
    String path = null;
    if (contentUri != null) {
        authority = contentUri.authority();
        path = contentUri.path();
    }

    if (element instanceof Class<?>) {
        Class<?> clazz = (Class<?>) element;
        if (StringUtils.isEmpty(authority)) {
            authority = clazz.getPackage().getName();
        }
        if (StringUtils.isEmpty(path)) {
            // TODO use DataBase annotation
            path = clazz.getSimpleName().toLowerCase();
        }
    }

    initialize(authority, path);
}

From source file:com.evolveum.midpoint.model.impl.rest.MidpointAbstractProvider.java

@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    if (type.getPackage().getName().startsWith("com.evolveum.midpoint")
            || type.getPackage().getName().startsWith("com.evolveum.prism")) {
        return true;
    }/*from  w w w . ja  v  a2  s  .c  o  m*/
    return false;
}

From source file:com.evolveum.midpoint.model.impl.rest.MidpointAbstractProvider.java

@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    if (type.getPackage().getName().startsWith("com.evolveum.midpoint")
            || type.getPackage().getName().startsWith("com.evolveum.prism")) {
        return true;
    }/*from  w w w  . ja va  2  s .  c  o  m*/
    return false;
}

From source file:com.ottogroup.bi.spqr.repository.CachedComponentClassLoaderTest.java

/**
 * Test case for {@link CachedComponentClassLoader#loadClass(String)}
 * being provided a reference towards a standard class 
 *///  ww w  .jav  a2s . c  om
@Test
public void testPackage_withStandardClassReference() throws ClassNotFoundException {
    CachedComponentClassLoader cl = new CachedComponentClassLoader(
            CachedComponentClassLoader.class.getClassLoader());
    Class<?> c = cl.loadClass("java.lang.String");
    Assert.assertEquals("Values must be equal", c.getPackage().getName(), "java.lang");
}

From source file:com.google.code.guice.repository.spi.CustomRepositoryImplementationResolver.java

public Class resolve(Class<? extends Repository> repositoryClass) {
    Assert.notNull(repositoryClass);//  w  w w.  jav  a  2s . com

    Class customRepository = null;
    /**
     * Detect only custom repository/enhancements interfaces - skip all from Spring and guice-repository project
     */
    Collection<Class<?>> superTypes = ReflectionUtils.getAllSuperTypes(repositoryClass, new Predicate<Class>() {
        @Override
        public boolean apply(Class input) {
            return isValidCustomInterface(input);
        }
    });

    /**
     * Searching for custom repository/enhancement implementation
     */
    if (!superTypes.isEmpty()) {
        Class customRepositoryClass = superTypes.iterator().next();
        Reflections reflections = new Reflections(customRepositoryClass.getPackage().getName());
        Iterable<Class> subTypesOf = reflections.getSubTypesOf(customRepositoryClass);
        for (Class aClass : subTypesOf) {
            if (!aClass.isInterface()) {
                customRepository = aClass;
                logger.info(String.format("Found custom repository implementation: [%s] -> [%s]",
                        repositoryClass.getName(), customRepository.getName()));
                break;
            }
        }
    }

    return customRepository;
}

From source file:org.apache.beam.runners.spark.SparkNativePipelineVisitor.java

private boolean knownComposite(Class<PTransform<?, ?>> transform) {
    String transformPackage = transform.getPackage().getName();
    for (String knownCompositePackage : knownCompositesPackages) {
        if (transformPackage.startsWith(knownCompositePackage)) {
            return true;
        }/*w w  w.  j  a  va2s. c om*/
    }
    return false;
}