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:Main.java

public static void main(String[] argv) throws Exception {
    Class cls = java.lang.String.class;
    Package pkg = cls.getPackage();
    String name = pkg.getName(); // java.lang
}

From source file:Main.java

public static void main(String[] args) {
    Date date = new Date();
    Package pack = date.getClass().getPackage();
    String packageName = pack.getName();
    System.out.println("Package Name = " + packageName);

}

From source file:Main.java

public static void main(String[] a) {
    Package p = Package.getPackage("java.lang");
    System.out.println("Name = " + p.getName());

    System.out.println("Implementation title = " + p.getImplementationTitle());

    System.out.println("Implementation vendor = " + p.getImplementationVendor());

    System.out.println("Implementation version = " + p.getImplementationVersion());
}

From source file:PackageInfo.java

public static void main(String[] args) {
    Package p = Package.getPackage("java.lang");

    System.out.println("Name = " + p.getName());

    System.out.println("Implementation title = " + p.getImplementationTitle());

    System.out.println("Implementation vendor = " + p.getImplementationVendor());

    System.out.println("Implementation version = " + p.getImplementationVersion());

    System.out.println("Specification title = " + p.getSpecificationTitle());

    System.out.println("Specification vendor = " + p.getSpecificationVendor());

    System.out.println("Specification version = " + p.getSpecificationVersion());
}

From source file:Main.java

public static void main(String[] args) {

    // create a package object for java.lang package
    Package pack = Package.getPackage("java.lang");

    // get the fully qualified name for this package
    System.out.println(pack.getName());
}

From source file:org.opennms.netmgt.poller.MonitorTester.java

public static void main(String[] args) {
    Options options = new Options();
    Option oI = new Option("i", "ipaddress", true, "IP Address to test [required]");
    oI.setRequired(true);//  w ww . j a  v  a2s .com
    options.addOption(oI);
    Option oS = new Option("s", "service", true, "Service name [required]");
    oS.setRequired(true);
    options.addOption(oS);
    options.addOption("P", "package", true, "Poller Package");
    options.addOption("p", "param", true, "Service parameter ~ key=value");
    options.addOption("c", "class", true, "Monitor Class");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        new HelpFormatter().printHelp(80, CMD_SYNTAX, String.format("ERROR: %s%n", e.getMessage()), options,
                null);
        System.exit(1);
    }

    initialize();

    final String packageName = cmd.getOptionValue('P');
    final String monitorClass = cmd.getOptionValue('c');
    final String ipAddress = cmd.getOptionValue('i');
    final String serviceName = cmd.getOptionValue('s');

    Map<String, Object> parameters = new HashMap<String, Object>();
    if (cmd.hasOption('p')) {
        for (String parm : cmd.getOptionValues('p')) {
            String[] data = parm.split("=");
            if (data.length == 2 && data[0] != null && data[1] != null) {
                parameters.put(data[0], data[1]);
            }
        }
    }

    final InetAddress addr = InetAddressUtils.addr(ipAddress);
    if (addr == null) {
        throw new IllegalStateException("Error getting InetAddress object for " + ipAddress);
    }

    final IpInterfaceDao dao = BeanUtils.getBean("daoContext", "ipInterfaceDao", IpInterfaceDao.class);
    final TransactionTemplate tt = BeanUtils.getBean("daoContext", "transactionTemplate",
            TransactionTemplate.class);
    MonitoredService monSvc = tt.execute(new TransactionCallback<MonitoredService>() {
        @Override
        public MonitoredService doInTransaction(TransactionStatus status) {
            final List<OnmsIpInterface> ips = dao.findByIpAddress(ipAddress);
            if (ips == null || ips.size() == 0) {
                System.err.printf("Error: Can't find the IP address %s on the database\n", ipAddress);
                return null;
            }
            if (ips.size() > 1) {
                System.out.printf(
                        "Warning: there are several IP interface objects associated with the IP address %s (picking the first one)\n",
                        ipAddress);
            }
            OnmsNode n = ips.get(0).getNode();
            return new SimpleMonitoredService(addr, n.getId(), n.getLabel(), serviceName);
        }
    });
    if (monSvc == null) {
        System.exit(1);
    }

    try {
        PollerConfigFactory.init();
    } catch (Exception e) {
        System.err.printf("Error: Can't initialize poller-configuration.xml. %s%n", e.getMessage());
        System.exit(1);
    }
    PollerConfig config = PollerConfigFactory.getInstance();

    System.out.printf("Checking service %s on IP %s%n", serviceName, ipAddress);

    org.opennms.netmgt.config.poller.Package pkg = packageName == null
            ? config.getFirstLocalPackageMatch(ipAddress)
            : config.getPackage(packageName);
    if (pkg == null) {
        System.err.printf("Error: Package %s doesn't exist%n", packageName);
        System.exit(1);
    }
    System.out.printf("Package: %s%n", pkg.getName());

    Service svc = config.getServiceInPackage(serviceName, pkg);
    if (svc == null) {
        System.err.printf("Error: Service %s not defined on package %s%n", serviceName, packageName);
        System.exit(1);
    }

    ServiceMonitor monitor = null;
    if (monitorClass == null) {
        monitor = config.getServiceMonitor(serviceName);
        if (monitor == null) {
            System.err.printf("Error: Service %s doesn't have a monitor class defined%n", serviceName);
            System.exit(1);
        }
    } else {
        try {
            final Class<? extends ServiceMonitor> mc = Class.forName(monitorClass)
                    .asSubclass(ServiceMonitor.class);
            monitor = mc.newInstance();
        } catch (Exception e) {
            System.err.printf("Error: Can't instantiate %s because %s%n", monitorClass, e.getMessage());
            System.exit(1);
        }
    }
    System.out.printf("Monitor: %s%n", monitor.getClass().getName());

    if (config.isPolledLocally(ipAddress, serviceName)) {
        for (Parameter p : svc.getParameters()) {
            if (!parameters.containsKey(p.getKey())) {
                String value = p.getValue();
                if (value == null) {
                    try {
                        value = JaxbUtils.marshal(p.getAnyObject());
                    } catch (Exception e) {
                    }
                }
                parameters.put(p.getKey(), value);
            }
        }
        for (Entry<String, Object> e : parameters.entrySet()) {
            System.out.printf("Parameter %s : %s%n", e.getKey(), e.getValue());
        }
        try {
            PollStatus status = monitor.poll(monSvc, parameters);
            System.out.printf("Available ? %s (status %s[%s])%n", status.isAvailable(), status.getStatusName(),
                    status.getStatusCode());
            if (status.isAvailable()) {
                System.out.printf("Response time: %s%n", status.getResponseTime());
            } else {
                if (status.getReason() != null) {
                    System.out.printf("Reason: %s%n", status.getReason());
                }
            }
        } catch (Exception e) {
            System.err.println("Error: Can't execute the monitor. " + e.getMessage());
            System.exit(1);
        }
    } else {
        System.err.printf("Error: Polling is not enabled for service %s using IP %s%n", serviceName, ipAddress);
    }

    System.exit(0);
}

From source file:Main.java

private static boolean isChromiumAnnotation(Annotation annotation) {
    Package pkg = annotation.annotationType().getPackage();
    return pkg != null && pkg.getName().startsWith("org.chromium");
}

From source file:Main.java

/**
 * Similar to {@link #isCglibGetCallbacks}, need to suppress
 * a cyclic reference to resolve [JACKSON-103]
 *///from   w w  w. j a  v a2  s  .c  om
protected static boolean isGroovyMetaClassSetter(AnnotatedMethod am) {
    Class<?> argType = am.getRawParameterType(0);
    Package pkg = argType.getPackage();
    if (pkg != null && pkg.getName().startsWith("groovy.lang")) {
        return true;
    }
    return false;
}

From source file:org.panbox.desktop.common.urihandler.PanboxURICmd.java

private static synchronized PanboxURICmd resolveInstance(String cmdIdentifier, byte[]... params)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException,
        InvocationTargetException, NoSuchMethodException, SecurityException {
    Package p = PanboxURICmd.class.getPackage();
    String lookup = p.getName() + "." + PanboxURICmd.class.getSimpleName() + cmdIdentifier;
    Class<?> tmp = Class.forName(lookup);
    return (PanboxURICmd) tmp.getConstructor(byte[][].class).newInstance(new Object[] { params });
}

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

/**
 * packageName to directoryName/*  ww  w.  j a va  2 s .  c  o m*/
 * 
 * @param targetPackage
 * 
 * @return ?
 */
public static final String packageNameToDirectoryName(final Package targetPackage) {
    return targetPackage.getName().replace('.', '/') + "/";
}