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:com.netspective.axiom.TestUtils.java

static public DriverManagerConnectionProvider getConnProvider(Package connProviderId, boolean reCreateDb) {
    return getConnProvider(connProviderId.getName(), reCreateDb);
}

From source file:org.codehaus.enunciate.modules.xfire.EnunciatedJAXWSWebFaultHandler.java

/**
 * Get the fault bean class for the specified fault class.  This method assumes that the fault class
 * doesn't conform to the JAXWS pattern.
 *
 * @param faultClass The fault class.//w  w  w  . j a va 2s . c om
 * @return The fault bean class, or null if it wasn't found.
 */
public static Class getFaultBeanClass(Class<? extends Throwable> faultClass) {
    String faultBeanClassName;
    WebFault webFaultInfo = faultClass.getAnnotation(WebFault.class);
    if ((webFaultInfo != null) && (webFaultInfo.faultBean() != null)
            && (webFaultInfo.faultBean().length() > 0)) {
        faultBeanClassName = webFaultInfo.faultBean();
    } else {
        StringBuilder builder = new StringBuilder();
        Package pckg = faultClass.getPackage();
        if ((pckg != null) && (!"".equals(pckg.getName()))) {
            builder.append(pckg.getName()).append(".");
        }
        builder.append("jaxws.");
        builder.append(faultClass.getSimpleName()).append("Bean");
        faultBeanClassName = builder.toString();
    }

    Class faultBeanClass = null;
    try {
        faultBeanClass = ClassLoaderUtils.loadClass(faultBeanClassName, faultClass);
    } catch (NullPointerException npe) {
        //fall through.  treat the same as a class not found...
    } catch (ClassNotFoundException e) {
        //fall through.  treat it as a runtime exception...
    }
    return faultBeanClass;
}

From source file:cc.aileron.commons.util.ClassPattrnFinderUtils.java

/**
 * ??????/*www .jav  a  2  s . co  m*/
 * 
 * @param targetPackage
 * @param classNamePattern
 * @return ??
 * @throws ResourceNotFoundException
 * @throws URISyntaxException
 * @throws IOException
 */
public static final List<Class<?>> getClassNameList(final Package targetPackage, final Pattern classNamePattern)
        throws IOException, URISyntaxException, ResourceNotFoundException {
    return tryGetClassNameList(targetPackage.getName(), classNamePattern);
}

From source file:jfix.util.Reflections.java

/**
 * Returns all instanceable (sub-)classes of given type in given package.
 *//*from w  w  w. jav  a2  s .com*/
public static <E> E[] find(Class<E> classType, Package pckage) {
    File directory;
    try {
        String name = "/" + pckage.getName().replace('.', '/');
        directory = new File(classType.getResource(name).toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    List<E> result = new ArrayList<>();
    if (directory.exists()) {
        String[] files = directory.list();
        for (int i = 0; i < files.length; i++) {
            if (files[i].endsWith(".class")) {
                String classname = files[i].substring(0, files[i].length() - 6);
                try {
                    Object o = Class.forName(pckage.getName() + "." + classname).newInstance();
                    if (classType.isInstance(o)) {
                        result.add((E) o);
                    }
                } catch (ClassNotFoundException cnfex) {
                    System.err.println(cnfex);
                } catch (InstantiationException iex) {
                } catch (IllegalAccessException iaex) {
                }
            }
        }
    }
    result.sort(new Comparator<Object>() {
        public int compare(Object o1, Object o2) {
            return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
        }
    });
    return result.toArray((E[]) Array.newInstance(classType, result.size()));
}

From source file:org.mrgeo.utils.ClassLoaderUtil.java

public static Collection<String> getMostJars() {

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {/*from w  ww. j  av a 2 s  .  c o  m*/
        // this seems to populate more jars. Odd.
        getChildResources("META-INF/services");
        getChildResources("");
        getChildResources("/");

    } catch (Exception e1) {
        e1.printStackTrace();
    }
    Thief t = new Thief(classLoader);
    Package[] packages = t.getPackages();
    TreeSet<String> result = new TreeSet<String>();

    for (Package p : packages) {
        Enumeration<URL> urls;
        try {
            String path = p.getName().replace(".", "/");

            urls = classLoader.getResources(path);
            while (urls.hasMoreElements()) {
                URL resource = urls.nextElement();
                if (resource.getProtocol().equalsIgnoreCase("jar")) {
                    JarURLConnection conn = (JarURLConnection) resource.openConnection();
                    JarFile jarFile = conn.getJarFile();
                    result.add(jarFile.getName());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return result;
}

From source file:org.jbpm.services.task.jaxb.ComparePair.java

public static void compareObjectsViaFields(Object orig, Object copy, String... skipFields) {
    Class<?> origClass = orig.getClass();
    assertEquals("copy is not an instance of " + origClass + " (" + copy.getClass().getSimpleName() + ")",
            origClass, copy.getClass());
    for (Field field : orig.getClass().getDeclaredFields()) {
        try {//from ww  w.  j  a v a2s  .  c  o m
            field.setAccessible(true);
            Object origFieldVal = field.get(orig);
            Object copyFieldVal = field.get(copy);
            String fieldName = field.getName();

            boolean skip = false;
            for (String skipFieldName : skipFields) {
                if (skipFieldName.matches(fieldName)) {
                    skip = true;
                    break;
                }
            }
            if (skip) {
                continue;
            }

            boolean nullFound = false;
            if (origFieldVal == null || copyFieldVal == null) {
                nullFound = true;
                for (String nullFieldName : skipFields) {
                    if (nullFieldName.matches(fieldName)) {
                        nullFound = false;
                    }
                }
            }
            String failMsg = origClass.getSimpleName() + "." + field.getName() + " is null";
            assertFalse(failMsg + "!", nullFound);

            if (copyFieldVal != origFieldVal) {
                assertNotNull(failMsg + "in copy!", copyFieldVal);
                assertNotNull(failMsg + "in original!", origFieldVal);
                Package pkg = origFieldVal.getClass().getPackage();
                if (pkg == null || pkg.getName().startsWith("java.")) {
                    if (origFieldVal.getClass().isArray()) {
                        if (origFieldVal instanceof byte[]) {
                            assertArrayEquals(origClass.getSimpleName() + "." + field.getName(),
                                    (byte[]) origFieldVal, (byte[]) copyFieldVal);
                        }
                    } else if (origFieldVal instanceof Map<?, ?> && copyFieldVal instanceof Map<?, ?>) {
                        org.apache.commons.collections.CollectionUtils
                                .disjunction(((Map) origFieldVal).values(), ((Map) copyFieldVal).values());
                    } else {
                        assertEquals(origClass.getSimpleName() + "." + field.getName(), origFieldVal,
                                copyFieldVal);
                    }
                } else {
                    compareObjectsViaFields(origFieldVal, copyFieldVal, skipFields);
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(
                    "Unable to access " + field.getName() + " when testing " + origClass.getSimpleName() + ".",
                    e);
        }
    }
}

From source file:jef.jre5support.script.JavaScriptUtil.java

public static void importPackage(ScriptEngine e, Package pkg, Bindings... b) {
    try {//from w  w  w . j av a  2s . co  m
        if (b.length == 0) {
            e.eval("importPackage(Packages." + pkg.getName() + ")");
        } else {
            e.eval("importPackage(Packages." + pkg.getName() + ")", b[0]);
        }
    } catch (ScriptException e1) {
        throw new RuntimeException(e1);
    }
}

From source file:ips1ap101.lib.base.BaseBundle.java

public static String getString(Package pack, String key, String defaultString) {
    String prefix = pack == null ? "" : pack.getName() + ".";
    return defaultIfBlank(prefix + key, defaultString);
}

From source file:org.apache.axis2.jaxws.message.databinding.JAXBContextFromClasses.java

/**
 * Utility class that quickly divides a list of classes into two categories.
 * The primary category classes contains classes that are referenced.
 * The secondary category classes are the remaining classes
 * @param original/*from www .  ja v  a2 s.  co m*/
 * @param primary
 * @param secondary
 */
static void separate(List<Class> original, List<Class> primary, List<Class> secondary, List<String> classRefs) {
    for (int i = 0; i < original.size(); i++) {
        Class cls = original.get(i);
        String clsName = cls.getCanonicalName();
        if (commonArrayClasses.contains(cls)) {
            if (log.isDebugEnabled()) {
                log.debug("This looks like a JAXB common class. Adding it to primary list:" + cls.getName());
            }
            primary.add(cls);
        } else if (classRefs.contains(clsName)) {
            if (log.isDebugEnabled()) {
                log.debug("This is a referenced class. Adding it to primary list:" + clsName);
            }
            Package pkg = cls.getPackage();
            if (pkg != null && pkg.getName().endsWith(".jaxws")) {
                if (log.isDebugEnabled()) {
                    log.debug(
                            "This looks like a jaxws generated Class. Adding it to the front of the primary list:"
                                    + cls.getName());
                }
                primary.add(0, cls); // Add to the front of the list
            } else {
                primary.add(cls);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("This class is not referenced by the web service. Adding it to secondary list:"
                        + cls.getName());
            }
            Package pkg = cls.getPackage();
            if (pkg != null && pkg.getName().endsWith(".jaxws")) {
                if (log.isDebugEnabled()) {
                    log.debug(
                            "This looks like a jaxws generated Class. Adding it to the front of the secondary list:"
                                    + cls.getName());
                }
                secondary.add(0, cls); // Add to the front of the list
            } else {
                secondary.add(cls);
            }
        }
    }
}

From source file:org.javelin.sws.ext.utils.NamespaceUtils.java

/**
 * Converts package name to URL for namespace according to JAXB/JAX-WS conventions with separate domain and path fragments
 * //from   www  .  ja v a  2  s . co  m
 * @param pkg
 * @param domainComponentCount number of package components to be converted into domain part of URL. If zero than entire package will be a domain
 * @return
 */
public static String packageNameToNamespace(Package pkg, int domainComponentCount) {
    Assert.notNull(pkg, "Package should not be null");
    Assert.isTrue(domainComponentCount != 1,
            "The domain part should not consist of one component. It may be zero or more than 1.");

    List<String> elements = new ArrayList<String>(Arrays.asList(pkg.getName().split("\\.")));
    if (domainComponentCount > 0) {
        List<String> domain = elements.subList(0, domainComponentCount);
        List<String> path = elements.subList(domainComponentCount, elements.size());
        Collections.reverse(domain);
        return "http://" + StringUtils.collectionToDelimitedString(domain, ".") + "/"
                + StringUtils.collectionToDelimitedString(path, "/");
    } else {
        Collections.reverse(elements);
        return "http://" + StringUtils.collectionToDelimitedString(elements, ".") + "/";
    }
}