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.ac.u.tokyo.m.resource.ResourceLoadUtil.java

/**
 * This method read Ini in the same package. <br>
 * If the file does not exist, logging WARN. <br>
 * <br>//from  www .ja va  2s .  co m
 * aFileName ????? Ini ???? <br>
 * ???????? <br>
 */
public static Ini loadUnnecessaryPackagePrivateIni(Class<?> aClass, String aFileName) {
    try {
        return loadIni(aClass, aFileName, aClass.getResourceAsStream(aFileName));
    } catch (NullPointerException e) {
        LogFactory.getLog(aClass).warn("not found : " + aClass.getPackage() + "." + aFileName);
        return new Ini();
    }
}

From source file:org.dasein.cloud.tier3.Tier3.java

static public @Nonnull Logger getWireLogger(@Nonnull Class<?> cls) {
    return Logger.getLogger("dasein.cloud.centurylink.wire." + getLastItem(cls.getPackage().getName()) + "."
            + getLastItem(cls.getName()));
}

From source file:jp.ac.u.tokyo.m.resource.ResourceLoadUtil.java

/**
 * This method read Properties in the same package. <br>
 * If the file does not exist, logging WARN. <br>
 * <br>//from w  w w.  ja  v  a2s . com
 * aFileName ????? Properties ???? <br>
 * ???????? <br>
 */
public static Properties loadUnnecessaryPackagePrivateProperties(Class<?> aClass, String aFileName) {
    try {
        return loadProperties(aClass, aFileName, aClass.getResourceAsStream(aFileName));
    } catch (NullPointerException e) {
        LogFactory.getLog(aClass).warn("not found : " + aClass.getPackage() + "." + aFileName);
        return new Properties();
    }
}

From source file:org.pentaho.di.core.util.PluginMessages.java

/**
 * Factory method.//from  w  w w  . j a v a  2  s.c  o  m
 *
 * @param someClassInPackage
 *          some class in package.
 * @return messages.
 * @throws IllegalArgumentException
 *           if class is null
 */
public static PluginMessages getMessages(final Class<?> someClassInPackage) throws IllegalArgumentException {
    Assert.assertNotNull(someClassInPackage, "Class cannot be null");
    return getMessages(someClassInPackage.getPackage().getName());
}

From source file:jp.ac.u.tokyo.m.resource.ResourceLoadUtil.java

/**
 * This method read Properties in the same package. <br>
 * If the file does not exist, throws exception. <br>
 * <br>/*from  w  w w  .j a v a  2  s  .c om*/
 * aFileName ????? Properties ???? <br>
 * ?????? <br>
 */
public static Properties loadNecessaryPackagePrivateProperties(Class<?> aClass, String aFileName) {
    try {
        return loadProperties(aClass, aFileName, aClass.getResourceAsStream(aFileName));
    } catch (NullPointerException e) {
        throw new RuntimeException(new FileNotFoundException(aClass.getPackage() + "." + aFileName));
    }
}

From source file:jp.ac.u.tokyo.m.resource.ResourceLoadUtil.java

private static Ini loadNecessaryIni(Class<?> aClass, String aFileName, InputStream aResourceAsStream) {
    try {//w  w w.j  a v a2 s.  com
        return loadIni(aClass, aFileName, aResourceAsStream);
    } catch (NullPointerException e) {
        throw new RuntimeException(new FileNotFoundException(aClass.getPackage() + "." + aFileName));
    }
}

From source file:com.rdm.common.util.ClassPathUtils.java

/**
 * Returns the fully qualified name for the resource with name {@code resourceName} relative to the given context.
 *
 * <p>Note that this method does not check whether the resource actually exists.
 * It only constructs the name./*from   w w  w. j a v  a  2  s.c o m*/
 * Null inputs are not allowed.</p>
 *
 * <pre>
 * ClassPathUtils.toFullyQualifiedName(StringUtils.class, "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"
 * </pre>
 *
 * @param context The context for constructing the name.
 * @param resourceName the resource name to construct the fully qualified name for.
 * @return the fully qualified name of the resource with name {@code resourceName}.
 * @throws java.lang.NullPointerException if either {@code context} or {@code resourceName} is null.
 */
public static String toFullyQualifiedName(final Class<?> context, final String resourceName) {
    Validate.notNull(context, "Parameter '%s' must not be null!", "context");
    Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
    return toFullyQualifiedName(context.getPackage(), resourceName);
}

From source file:com.rdm.common.util.ClassPathUtils.java

/**
 * Returns the fully qualified path for the resource with name {@code resourceName} relative to the given context.
 *
 * <p>Note that this method does not check whether the resource actually exists.
 * It only constructs the path./*from w ww . j  a v  a 2  s.co  m*/
 * Null inputs are not allowed.</p>
 *
 * <pre>
 * ClassPathUtils.toFullyQualifiedPath(StringUtils.class, "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"
 * </pre>
 *
 * @param context The context for constructing the path.
 * @param resourceName the resource name to construct the fully qualified path for.
 * @return the fully qualified path of the resource with name {@code resourceName}.
 * @throws java.lang.NullPointerException if either {@code context} or {@code resourceName} is null.
 */
public static String toFullyQualifiedPath(final Class<?> context, final String resourceName) {
    Validate.notNull(context, "Parameter '%s' must not be null!", "context");
    Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
    return toFullyQualifiedPath(context.getPackage(), resourceName);
}

From source file:org.dasein.cloud.google.Google.java

static public @Nonnull Logger getWireLogger(@Nonnull Class<?> cls) {
    return Logger.getLogger("dasein.cloud.google.wire." + getLastItem(cls.getPackage().getName()) + "."
            + getLastItem(cls.getName()));
}

From source file:com.graphaware.test.util.TestUtils.java

/**
 * Convert a JSON file to String.//from  w w  w . j  av  a  2 s.com
 *
 * @param caller   the class calling this method. The file is expected to be in the resources directory in the same
 *                 package as this class.
 * @param fileName name of the file present in the resources directory in the same package as the class above.
 * @return JSON as String.
 */
public static String jsonAsString(Class caller, String fileName) {
    return jsonAsString(caller.getPackage().getName().replace(".", "/") + "/", fileName);
}