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.openspotlight.graph.query.AbstractGeneralQueryTest.java

/**
 * Adds the java interface hirarchy links.
 * /* w  w w . j a va 2s. com*/
 * @param root the root
 * @param iFace the i face
 * @param javaInterface the java interface
 */
private void addJavaInterfaceHirarchyLinks(final Context root, final Class<?> iFace,
        final JavaInterface javaInterface) {
    final Class<?>[] superIFaces = iFace.getInterfaces();
    for (final Class<?> superIFace : superIFaces) {
        final Package iFacePack = iFace.getPackage();
        final JavaPackage javaPackage = writer.addNode(root, JavaPackage.class, iFacePack.getName());
        // javaPackage.setCaption(iFacePack.getName());
        final JavaInterface superJavaInterface = writer.addChildNode(javaPackage, JavaInterface.class,
                superIFace.getName());
        writer.addLink(PackageContainsType.class, javaPackage, superJavaInterface);
        // superJavaInterface.setCaption(superIFace.getName());
        writer.addLink(JavaInterfaceHierarchy.class, javaInterface, superJavaInterface);
        addJavaInterfaceHirarchyLinks(root, superIFace, superJavaInterface);
    }
}

From source file:com.medallia.spider.SpiderServlet.java

/** @return the path to the StringTemplate with the given name */
protected String findPathForTemplate(String name) {
    name = "st/" + name;
    String path = name + ".st";
    Class<?> c = getServletClass();
    while (c != null) {
        if (c.getResource(path) != null)
            return c.getPackage().getName().replace('.', '/') + "/" + name;

        if (c == SpiderServlet.class)
            break;

        c = c.getSuperclass();/*from  w w  w.j a v a 2  s. co m*/
    }
    throw new RuntimeException("Cannot find template " + name);
}

From source file:org.echocat.jomon.runtime.i18n.RecursiveResourceBundleFactory.java

@Nonnull
protected List<ResourceBundle> getAllRecursivelyWithNoInheritanceFor(@Nonnull Class<?> type,
        @Nullable ClassLoader classLoader, @Nullable Locale locale) {
    final ClassLoader targetClassLoader = classLoader != null ? classLoader
            : Thread.currentThread().getContextClassLoader();
    final List<ResourceBundle> bundles = new ArrayList<>();
    if (targetClassLoader != null) {
        final ResourceBundle bundleForType = tryFindFor(type, locale, targetClassLoader);
        if (bundleForType != null) {
            bundles.add(bundleForType);/*from w ww . j a  v  a2 s  .com*/
        }
        bundles.addAll(getAllRecursivelyFor(type.getPackage(), locale, targetClassLoader));
    }
    return bundles;
}

From source file:org.springframework.web.method.ControllerAdviceBean.java

/**
 * Checks whether the given bean type should be assisted by this
 * {@code @ControllerAdvice} instance.// w  w w. j  a  v  a  2  s.c  om
 * @param beanType the type of the bean to check
 * @see org.springframework.web.bind.annotation.ControllerAdvice
 * @since 4.0
 */
public boolean isApplicableToBeanType(Class<?> beanType) {
    if (!hasSelectors()) {
        return true;
    } else if (beanType != null) {
        for (Class<?> clazz : this.assignableTypes) {
            if (ClassUtils.isAssignable(clazz, beanType)) {
                return true;
            }
        }
        for (Class<? extends Annotation> annotationClass : this.annotations) {
            if (AnnotationUtils.findAnnotation(beanType, annotationClass) != null) {
                return true;
            }
        }
        String packageName = beanType.getPackage().getName();
        for (Package basePackage : this.basePackages) {
            if (packageName.startsWith(basePackage.getName())) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.apache.drill.jdbc.proxy.InvocationReporterImpl.java

/**
 * Renders a type name.  Uses simple names for common types (JDBC interfaces
 * and {code java.lang.*}).//from   w  w w . j a  v  a 2  s  . c om
 */
private String formatType(final Class<?> type) {
    final String result;
    if (type.isArray()) {
        result = formatType(type.getComponentType()) + "[]";
    } else {
        // Suppress package name for common (JDBC and java.lang) types, except
        // when would be ambiguous (e.g., java.sql.Date vs. java.util.Date).
        if (PACKAGES_TO_ABBREVIATE.contains(type.getPackage())) {
            int sameSimpleNameCount = 0;
            for (Package p : PACKAGES_TO_ABBREVIATE) {
                try {
                    Class.forName(p.getName() + "." + type.getSimpleName());
                    sameSimpleNameCount++;
                } catch (ClassNotFoundException e) {
                    // Nothing to do.
                }
            }
            if (1 == sameSimpleNameCount) {
                result = type.getSimpleName();
            } else {
                // Multiple classes with same simple name, so would be ambiguous to
                // abbreviate, so use fully qualified name.
                result = type.getName();
            }
        } else {
            result = type.getName();
        }
    }
    return result;
}

From source file:org.kuali.rice.krad.service.impl.RemoteModuleServiceBase.java

/**
 * @param dataObjectClass the dataobject class
 * @return true if package prefixes has been defined and matches a package containing the dataObject
 */// w  w w .  j  a  v a 2s.  c  om
protected boolean packagePrefixesMatchesDataObject(Class dataObjectClass) {
    if (getModuleConfiguration().getPackagePrefixes() != null) {
        for (String prefix : getModuleConfiguration().getPackagePrefixes()) {
            if (dataObjectClass.getPackage().getName().startsWith(prefix)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.atricore.idbus.kernel.main.databinding.JAXBUtils.java

/**
 * @param list//  w  w  w  .  ja v  a 2  s . c om
 * @param pkg
 */
private static void checkClasses(List<Class> list, String pkg) {
    // The installed classfinder or directory search may inadvertently add too many
    // classes.  This rountine is a 'double check' to make sure that the classes
    // are acceptable.
    for (int i = 0; i < list.size();) {
        Class cls = list.get(i);
        if (!cls.isInterface()
                && (cls.isEnum() || getAnnotation(cls, XmlType.class) != null
                        || ClassUtils.getDefaultPublicConstructor(cls) != null)
                && !ClassUtils.isJAXWSClass(cls) && !isSkipClass(cls)
                && cls.getPackage().getName().equals(pkg)) {
            i++; // Acceptable class
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Removing class " + cls + " from consideration because it is not in package " + pkg
                        + " or is an interface or does not have a public constructor or is" + " a jaxws class");
            }
            list.remove(i);
        }
    }
}

From source file:com.eviware.soapui.plugins.LoaderBase.java

protected void loadAutoFactories(Reflections jarFileScanner, Collection<SoapUIFactory> factories) {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.addUrls(ClasspathHelper.forClass(AutoFactory.class));
    builder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
    builder.addClassLoader(Thread.currentThread().getContextClassLoader());
    Reflections autoAnnotationFinder = new Reflections(builder);

    for (Class clazz : autoAnnotationFinder.getTypesAnnotatedWith(AutoFactory.class)) {
        if (clazz.isAnnotation() && clazz.getSimpleName().startsWith("Plugin")) {
            try {
                String className = "Auto" + clazz.getSimpleName().substring(6) + "Factory";
                Class<? extends SoapUIFactory> factoryClass = (Class<? extends SoapUIFactory>) Class
                        .forName(clazz.getPackage().getName() + ".factories." + className);
                factories.addAll(findAutoFactoryObjects(jarFileScanner, clazz, factoryClass));
            } catch (ClassNotFoundException e) {
                SoapUI.logError(e);// w w  w  . ja va2 s .  c om
            }
        }
    }
}

From source file:com.github.gekoh.yagen.hst.CreateEntities.java

private String createHistoryEntity(String baseClassPackageName, Class baseEntity, Reader template,
        List<AccessibleObject> inverseFKs) {
    List<FieldInfo> fields = new ArrayList<FieldInfo>(FieldInfo.convertFields(baseEntity));
    if (inverseFKs != null) {
        fields.addAll(FieldInfo.convertInverseFKs(inverseFKs));
    }//from w w w.j  av a 2 s  .  c  o m

    TemporalEntity temporalEntity = (TemporalEntity) baseEntity.getAnnotation(TemporalEntity.class);

    return createHistoryEntity(baseClassPackageName, baseEntity.getPackage().getName(),
            baseEntity.getSimpleName() + HISTORY_ENTITY_SUFFIX,
            temporalEntity != null ? temporalEntity.historyTableName() : null,
            temporalEntity != null ? namingStrategy.classToTableShortName(baseEntity.getName()) : null,
            baseEntity, template, fields);
}

From source file:com.kjt.service.common.SoafwTesterMojo.java

private void genTest(String basedPath, String className) {
    //  //from w w  w. jav  a  2s.co m
    this.getLog().info("" + className + "");
    Map<String, Integer> methodCnt = new HashMap<String, Integer>();
    boolean hasmethod = false;
    try {

        Class cls = cl.loadClass(className);

        String testJFileName = cls.getSimpleName() + "Test.java";
        String pkgPath = cls.getPackage().getName().replace(".", File.separator);

        String testJFilePath = basedPath + File.separator + "src" + File.separator + "test" + File.separator
                + "java" + File.separator + pkgPath;

        int len = 0;
        Class[] inters = cls.getInterfaces();
        if (inters == null || (len = inters.length) == 0) {
            return;
        }

        /**
         * package import
         */
        StringBuffer jHeadBuf = createTestJHeadByClass(cls);

        StringBuffer testJBuf = new StringBuffer();

        testJBuf.append(jHeadBuf);
        Map<String, String> methodDefs = new HashMap<String, String>();
        for (int j = 0; j < len; j++) {
            /**
             * ?
             */
            Class interCls = inters[j];

            this.getLog().info("@interface: " + interCls.getName());

            String name = project.getName();

            Method[] methods = null;

            if (name.endsWith("-dao")) {

                methods = interCls.getDeclaredMethods();
            } else {
                methods = interCls.getMethods();
            }

            int mlen = 0;
            if (methods != null && (mlen = methods.length) > 0) {

                this.getLog().info("?" + className + "Test?");

                StringBuffer methodBuf = new StringBuffer();

                for (int m = 0; m < mlen; m++) {
                    Method method = methods[m];
                    int modf = method.getModifiers();
                    if (modf == 1025) {// ??
                        hasmethod = true;
                        /**
                         * ??????Test ???=??+Test
                         * ??:basedPath+File.separator
                         * +src+File.separator+test+File.separator
                         * +pkg+definesArray[i]+Test+.java
                         */
                        if (methodCnt.containsKey(method.getName())) {
                            methodCnt.put(method.getName(), methodCnt.get(method.getName()) + 1);
                        } else {
                            methodCnt.put(method.getName(), 0);
                        }
                        int cnt = methodCnt.get(method.getName());

                        addMethod(methodDefs, methodBuf, method, cnt);
                    }
                }

                testJBuf.append(methodBuf);
            } else {
                this.getLog().info(className + "");
            }
        }

        String testJFile = testJBuf.append("}").toString();
        if (hasmethod) {
            write(testJFilePath, testJFileName, testJFile);
        }

    } catch (Exception e) {
        this.getLog().error(e);
    } catch (Error er) {
        this.getLog().error(er);
    }

}