Example usage for java.lang Package getName

List of usage examples for java.lang Package getName

Introduction

In this page you can find the example usage for java.lang Package getName.

Prototype

public String getName() 

Source Link

Document

Return the name of this package.

Usage

From source file:eu.gentech.osgi.packagescanner.utils.PackageNameValidatorTest.java

@Test
public void testClasspath() {
    final Package[] packages = Package.getPackages();
    for (final Package pkg : packages) {
        Assert.assertTrue(PackageNameValidator.isValid(pkg.getName()));
    }/*from  ww w.  j a v  a2s.c  om*/
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java

private static void archivePackage(Package installPackage, File packageManagerDataDir) {
    // create "archive" dir if it doesnt exist
    // create package archive dir (<package name>_v_<package version>)
    // copy contents of package metadata, autorun and patch file to archive dir
    try {/*from  www .  ja  v a  2 s.  c  o m*/
        File archiveDir = new File(packageManagerDataDir.getAbsolutePath() + "/" + ARCHIVE_DIR_NAME);
        File archivePackageDir = new File(archiveDir.getAbsolutePath() + "/" + installPackage.getName() + "_v_"
                + installPackage.getVersion());
        //            if(!archivePackageDir.exists())
        //            {
        //                archivePackageDir.mkdirs();
        //            }

        File archivePackageInstallDir = new File(
                archivePackageDir.getAbsolutePath() + "/" + JPackageManagerBU.INSTALL_DIR_NAME);
        if (!archivePackageInstallDir.exists()) {
            archivePackageInstallDir.mkdirs();
        }

        File archivePackageUninstallDir = new File(
                archivePackageDir.getAbsolutePath() + "/" + JPackageManagerBU.UNINSTALL_DIR_NAME);
        if (!archivePackageUninstallDir.exists()) {
            archivePackageUninstallDir.mkdirs();
        }

        // metadata archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerBU.METADATA_DIR_NAME),
                new File(archivePackageDir.getAbsolutePath() + "/" + JPackageManagerBU.METADATA_DIR_NAME));

        // install archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerBU.AUTORUN_DIR_NAME + "/" + JPackageManagerBU.INSTALL_DIR_NAME),
                new File(
                        archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManagerBU.AUTORUN_DIR_NAME));

        FileUtils.copyFileToDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerBU.PATCH_DIR_NAME + "/" + JPackageManagerBU.PATCH_FILE_NAME),
                new File(archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManagerBU.PATCH_DIR_NAME));

        // uninstall archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerBU.AUTORUN_DIR_NAME + "/" + JPackageManagerBU.UNINSTALL_DIR_NAME),
                new File(archivePackageUninstallDir.getAbsolutePath() + "/"
                        + JPackageManagerBU.AUTORUN_DIR_NAME));

        FileUtils.copyFileToDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerBU.PATCH_DIR_NAME + "/" + JPackageManagerBU.PATCH_FILE_NAME),
                new File(
                        archivePackageUninstallDir.getAbsolutePath() + "/" + JPackageManagerBU.PATCH_DIR_NAME));

    } catch (Exception e) {
        logger.error("", e);
        //            e.printStackTrace();
    }
}

From source file:org.wso2.carbon.is.migration.VersionMigration.java

public Migrator getMigrator(String migratorName) {
    Package aPackage = this.getClass().getPackage();
    String basePackage = aPackage.getName() + ".migrator";
    try {/*  www. j  a va2  s . c o  m*/
        Class<?> migratorClass = Class.forName(basePackage + "." + migratorName);
        Migrator migrator = (Migrator) migratorClass.newInstance();
        return migrator;
    } catch (ClassNotFoundException e) {
        log.error("Error while creating migration instance");
    } catch (InstantiationException e) {
        log.error("Error while creating migration instance");
    } catch (IllegalAccessException e) {
        log.error("Error while creating migration instance");
    }
    return null;
}

From source file:com.github.wolf480pl.mias4j.core.runtime.BMClassLoader.java

protected Package copyPackage(Package pkg, CodeSource cs) {
    return definePackage(pkg.getName(), pkg.getSpecificationTitle(), pkg.getSpecificationVersion(),
            pkg.getSpecificationVendor(), pkg.getImplementationTitle(), pkg.getImplementationVersion(),
            pkg.getImplementationVendor(), pkg.isSealed() ? cs.getLocation() : null);
}

From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.PackageSetBuilder.java

/**
 * For each data element, we need the package for both the element and its type.
 *
 * @param cls       Class representing element, type or both
 * @param namespace of the element//from w w w . j a  va2 s . c om
 * @param localPart of the element
 * @param set       with both type and element packages set
 */
private static void setTypeAndElementPackages(Class cls, String namespace, String localPart,
        TreeSet<String> set, MarshalServiceRuntimeDescription msrd) {

    // Get the element and type classes
    Class eClass = getElement(cls, msrd);
    Class tClass = getType(cls);

    // Set the package for the type
    if (tClass != null) {
        Package typePkg = tClass.getPackage();
        //For primitive types there is no package
        String pkg = (typePkg != null) ? typePkg.getName() : null;

        if (pkg != null) {
            set.add(pkg);
            set.add("@" + pkg); // Indicates a package from an actual class reference (versus namespace)
            set.add("[" + tClass.getCanonicalName() + "]"); // Indicates a actual class reference
        }
        // If there is an xmlType, and it maps to a package then add
        // an override if the package is different.
        if (pkg != null) {
            AnnotationDesc ad = msrd.getAnnotationDesc(tClass);
            if (ad != null && ad.hasXmlType()) {
                String ns = ad.getXmlTypeNamespace();
                if (ns != null && ns.length() > 0) {
                    List pkgs = makePackages(ns);
                    if (pkgs != null) {
                        for (int i = 0; i < pkgs.size(); i++) {
                            String pkg2 = (String) pkgs.get(i);
                            if (!pkg.equals(pkg2)) {
                                String override = pkg + " > " + pkg2;
                                if (!set.contains(override)) {
                                    set.add(override);
                                    if (log.isDebugEnabled()) {
                                        log.debug("Adding override=" + override);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        addXmlSeeAlsoPackages(tClass, msrd, set);
    }

    // Set the package for the element
    if (tClass != eClass) {
        if (eClass == null) {
            // A null or empty namespace indicates that the element is
            // unqualified.  This can occur if the parameter is represented as a child element 
            // in doc/lit wrapped.  The package is determined from the wrapper element in such casses.
            if (namespace != null && namespace.length() > 0) {
                // Use default namespace to package algorithm
                List pkgs = makePackages(namespace);
                if (pkgs != null) {
                    set.addAll(pkgs);
                }
            }
        } else {
            Package elementPkg = eClass.getPackage();
            String pkg = (elementPkg != null) ? elementPkg.getName() : null;
            if (pkg != null) {
                set.add(pkg);
                set.add("@" + pkg); // Indicates a package from an actual class reference (versus namespace)
                set.add("[" + eClass.getCanonicalName() + "]"); // Indicates a actual class reference
            }

            if (pkg != null) {
                AnnotationDesc ad = msrd.getAnnotationDesc(tClass);
                if (ad != null && ad.hasXmlRootElement()) {
                    String ns = ad.getXmlRootElementNamespace();
                    if (ns != null && ns.length() > 0) {
                        List pkgs = makePackages(ns);
                        if (pkgs != null) {
                            for (int i = 0; i < pkgs.size(); i++) {
                                String pkg2 = (String) pkgs.get(i);
                                if (!pkg.equals(pkg2)) {
                                    String override = pkg + " > " + pkg2;
                                    if (!set.contains(override)) {
                                        set.add(override);
                                        if (log.isDebugEnabled()) {
                                            log.debug("Adding override=" + override);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            addXmlSeeAlsoPackages(tClass, msrd, set);
        }
    }
}

From source file:com.astamuse.asta4d.web.initialization.SimplePropertyFileInitializer.java

@SuppressWarnings("rawtypes")
protected boolean expectInstance(Class clz) {
    Package pkg = clz.getPackage();
    if (pkg == null) {
        return false;
    } else {/*from   w w w  . j  a  va 2 s  .c om*/
        return pkg.getName().startsWith("com.astamuse.asta4d.");
    }
}

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

/**
 * Returns the ZK resource path for the specified package.
 * //  w  ww  . ja  v  a 2  s  .co  m
 * @param pkg Package to evaluate
 * @return String representing resource path
 */
public static final String getResourcePath(Package pkg) {
    return getResourcePath(pkg.getName());
}

From source file:org.castor.jaxb.reflection.PackageAnnotationProcessingServiceTest.java

/**
 * Test method for {@link org.castor.jaxb.annoproc.BaseAnnotationProcessingService#processAnnotations(org.castor.jaxb.reflection.info.Info, 
 * java.lang.annotation.Annotation[])}.//from   ww w  .  j a v  a2  s  .c om
 */
@Test
public final void testProcessAnnotations() {
    Class<USAddress> clazz = USAddress.class;
    Package pack = clazz.getPackage();
    Annotation[] annotations = pack.getAnnotations();
    JaxbPackageNature packageInfo = new JaxbPackageNature(new PackageInfo(pack.getName()));
    paps.processAnnotations(packageInfo, annotations);
    Assert.assertEquals(XmlAccessType.PROPERTY, packageInfo.getAccessType());
}

From source file:edu.duke.cabig.c3pr.rules.deploy.SystemRulesDeployer.java

public SystemRulesDeployer(RuleDeploymentService ruleDeploymentService) {
    if (log.isInfoEnabled())
        log.info("Begining system rule loading......");
    try {/*  ww  w  . j a  v  a 2 s.  c o m*/

        // 1. create the base pattern.
        String pattern = "classpath*:" + SystemRulesDeployer.class.getPackage().getName().replace(".", "/")
                + "/*.xml";

        // 2. Load the rule files, that are to be loaded in repository
        // and load them only if they are not already loaded.
        for (Resource resource : getResources(pattern)) {
            if (log.isDebugEnabled())
                log.debug("Loading rule file :" + resource.getURL().toString());
            try {
                String ruleXml = getFileContext(resource.getInputStream());
                org.drools.rule.Package rulePackage = XMLUtil.unmarshalToPackage(ruleXml);
                String ruleBindUri = rulePackage.getName();
                // unregister the rules
                try {
                    ruleDeploymentService.deregisterRuleSet(ruleBindUri);
                } catch (Exception ignore) {
                }
                // register the rules
                if (log.isDebugEnabled())
                    log.debug("Registering at bindUri : " + ruleBindUri + "\r\n\r\n" + ruleXml);
                ruleDeploymentService.registerRulePackage(ruleBindUri, rulePackage);
                if (log.isDebugEnabled())
                    log.debug("Sucessfully deployed rule at bindUri :" + ruleBindUri);
            } catch (RuntimeException e) {
                log.debug("It seems the system rule is already available, so ignoring", e);
            }

        }

    } catch (Exception e) {
        log.warn("Error while loading system rules :", e);
    }
    if (log.isInfoEnabled())
        log.debug("Finished system rule loading......");
}

From source file:com.github.wolf480pl.mias4j.core.runtime.BMClassLoader.java

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    if (name.equals(BNAME)) {
        URL res = getParent().getParent().getResource(RNAME); // double getParent because FilteringClassLoader
        if (res == null) {
            throw new ClassNotFoundException(name + ": no " + RNAME);
        }// w  w w.ja  va2  s .c  o m
        InputStream is;
        try {
            is = res.openStream();
        } catch (IOException e) {
            throw new ClassNotFoundException(name, e);
        }
        byte[] bytes;
        try {
            bytes = IOUtils.toByteArray(is);
        } catch (IOException e) {
            throw new ClassNotFoundException(name, e);
        }
        // TODO: Are we sure about this CodeSource?
        CodeSource cs = Bootstraps.class.getProtectionDomain().getCodeSource();
        Package pkg = Bootstraps.class.getPackage();
        if (pkg != null && getPackage(pkg.getName()) == null) {
            copyPackage(pkg, cs);
        }
        Class<?> c = defineClass(name, bytes, 0, bytes.length, cs);
        initHandle(c);
        return c;
    } else {
        throw new ClassNotFoundException(name);
    }
}