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:jp.co.ctc_g.jfw.core.internal.InternalMessages.java

/**
 * ??????????// ww  w . j a  v a 2 s.co  m
 * ??????????????? ??????
 * {@link MissingResourceException}????
 *
 * @param clazz
 *            ?????
 * @return ????
 * @throws MissingResourceException
 *             ??????
 * @see ResourceBundle
 */
public static ResourceBundle getBundle(Class<?> clazz) {
    return ResourceBundle.getBundle(clazz.getPackage().getName() + MESSAGE_FILE);
}

From source file:de.thischwa.pmcms.tool.ToolVersionInfo.java

private static Map<TYPE, String> generateInfo(final Class<?> cls) {
    Map<TYPE, String> info = new HashMap<TYPE, String>(2);
    info.put(TYPE.title, StringUtils.defaultIfEmpty(cls.getPackage().getImplementationTitle(), "Unknown"));
    String version = StringUtils.defaultIfEmpty(cls.getPackage().getImplementationVersion(),
            cls.getPackage().getSpecificationVersion());
    info.put(TYPE.version, StringUtils.defaultIfEmpty(version, "n/n"));
    return info;/* w w  w . j  a v a 2 s  .  co  m*/
}

From source file:IntrospectionUtil.java

public static boolean containsSameMethodSignature(Method method, Class c, boolean checkPackage) {
    if (checkPackage) {
        if (!c.getPackage().equals(method.getDeclaringClass().getPackage()))
            return false;
    }//from   w w  w.  ja  v a  2 s. c o  m

    boolean samesig = false;
    Method[] methods = c.getDeclaredMethods();
    for (int i = 0; i < methods.length && !samesig; i++) {
        if (IntrospectionUtil.isSameSignature(method, methods[i]))
            samesig = true;
    }
    return samesig;
}

From source file:IntrospectionUtil.java

public static boolean containsSameFieldName(Field field, Class c, boolean checkPackage) {
    if (checkPackage) {
        if (!c.getPackage().equals(field.getDeclaringClass().getPackage()))
            return false;
    }//from   w  ww  . j av  a 2  s  .  co m

    boolean sameName = false;
    Field[] fields = c.getDeclaredFields();
    for (int i = 0; i < fields.length && !sameName; i++) {
        if (fields[i].getName().equals(field.getName()))
            sameName = true;
    }
    return sameName;
}

From source file:alluxio.cli.CommandUtils.java

/**
 * Get instances of all subclasses of {@link Command} in a sub-package called "command" the given
 * package.//  ww  w .  j  a  v a 2  s.c  om
 *
 * @param pkgName package prefix to look in
 * @param classArgs type of args to instantiate the class
 * @param objectArgs args to instantiate the class
 * @return a mapping from command name to command instance
 */
public static Map<String, Command> loadCommands(String pkgName, Class[] classArgs, Object[] objectArgs) {
    Map<String, Command> commandsMap = new HashMap<>();
    Reflections reflections = new Reflections(Command.class.getPackage().getName());
    for (Class<? extends Command> cls : reflections.getSubTypesOf(Command.class)) {
        // Add commands from <pkgName>.command.*
        if (cls.getPackage().getName().equals(pkgName + ".command")
                && !Modifier.isAbstract(cls.getModifiers())) {
            // Only instantiate a concrete class
            Command cmd = CommonUtils.createNewClassInstance(cls, classArgs, objectArgs);
            commandsMap.put(cmd.getCommandName(), cmd);
        }
    }
    return commandsMap;
}

From source file:Main.java

/**
 * Extracts the package name from the given class object
 *///from  www  . jav  a  2  s. com
public static String getPackage(Class<?> cls) {
    // cls.getPackage() sometimes returns null, in which case fall back to string massaging.
    java.lang.Package pkg = cls.isArray() ? cls.getComponentType().getPackage() : cls.getPackage();
    if (pkg == null) {
        int dotPos;
        int dolPos = cls.getName().indexOf('$');
        if (dolPos > 0) {
            // we have nested classes, so adjust dotpos to before first $
            dotPos = cls.getName().substring(0, dolPos).lastIndexOf('.');
        } else {
            dotPos = cls.getName().lastIndexOf('.');
        }

        if (dotPos > 0) {
            return cls.getName().substring(0, dotPos);
        } else {
            // must be default package.
            return "";
        }
    } else {
        return pkg.getName();
    }
}

From source file:Main.java

/**
 * Another helper method to deal with rest of [JACKSON-103]
 *///  ww w.j  a  va2s . co m
protected static boolean isGroovyMetaClassGetter(AnnotatedMethod am) {
    Class<?> rt = am.getRawType();
    if (rt == null || rt.isArray()) {
        return false;
    }
    Package pkg = rt.getPackage();
    if (pkg != null && pkg.getName().startsWith("groovy.lang")) {
        return true;
    }
    return false;
}

From source file:jfix.util.Reflections.java

/**
 * Returns all instanceable (sub-)classes of given type contained in the
 * package of given type./* w  ww  .j a  v a2  s.  c  o m*/
 */
public static <E> E[] find(Class<E> classType) {
    return find(classType, classType.getPackage());
}

From source file:org.axiom_tools.context.SpringContext.java

/**
 * Returns the standard bean name for a given class.
 *
 * @param beanType a bean type/*from   w  w w.  j av  a2s  .co  m*/
 * @return a bean name
 */
private static String getStandardBeanName(Class<?> beanType) {
    String packageName = beanType.getPackage().getName();
    if (packageName.length() > 0) {
        packageName += Dot;
    }
    int index = packageName.length();
    return beanType.getName().substring(index).replace(Dollar, Empty);
}

From source file:org.baswell.routes.ContentConversionType.java

static ContentConversionType mapContentConversionType(Class conversionType, MediaType mediaType,
        AvailableLibraries availableLibraries) {
    String returnClassName = conversionType.getCanonicalName();
    String returnTypePackage = conversionType.getPackage().getName();

    if (returnTypePackage.equals("org.json.simple")) {
        return ContentConversionType.JSON_SIMPLE;
    } else if (returnTypePackage.startsWith("org.w3c.dom")) {
        return ContentConversionType.W3C_NODE;
    } else if (returnClassName.equals("org.jdom2.Document")) {
        return ContentConversionType.JDOM2_DOCUMENT;
    } else if (returnClassName.equals("org.jdom2.Element")) {
        return ContentConversionType.JDOM2_ELEMENT;
    } else if (conversionType.getAnnotation(XmlRootElement.class) != null) {
        return ContentConversionType.JAXB;
    } else if ((((mediaType != null) && (mediaType == MediaType.JSON)))
            && availableLibraries.jacksonAvailable()) {
        return ContentConversionType.JACKSON;
    } else if ((((mediaType != null) && (mediaType == MediaType.JSON))) && availableLibraries.gsonAvailable()) {
        return ContentConversionType.GSON;
    } else if (classImplementsInterface(conversionType, CharSequence.class)) {
        return ContentConversionType.TO_STRING;
    } else {//from w  ww  .  j a  v a 2s  .  c  om
        return null;
    }
}