List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:Main.java
public static void main(String[] unused) { try {//from w w w . j av a 2 s. c om String n = "java.lang.Deprecated"; Class c = Class.forName(n); Class d = Class.forName("java.util.Date"); System.out.println(d.getAnnotation(c)); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:kieker.tools.bridge.cli.CLIServerMain.java
/** * CLI server main./*from w w w .ja v a2s. com*/ * * @param args * command line arguments */ public static void main(final String[] args) { Configuration configuration; int exitCode = 0; CLIServerMain.declareOptions(); try { // parse the command line arguments commandLine = new BasicParser().parse(options, args); // verbosity setup verbose = commandLine.hasOption(CMD_VERBOSE); // statistics stats = commandLine.hasOption(CMD_STATS); // daemon mode if (commandLine.hasOption(CMD_DAEMON)) { System.out.close(); System.err.close(); CLIServerMain.getPidFile().deleteOnExit(); } // Find libraries and setup mapping final ConcurrentMap<Integer, LookupEntity> lookupEntityMap = ServiceConnectorFactory .createLookupEntityMap(CLIServerMain.createRecordMap()); // Kieker setup if (commandLine.hasOption(CMD_KIEKER_CONFIGURATION)) { configuration = ConfigurationFactory.createConfigurationFromFile(commandLine.getOptionValue("c")); } else { configuration = ConfigurationFactory.createSingletonConfiguration(); } // reconfigure kieker configuration if (commandLine.hasOption(CMD_PORT) && commandLine.hasOption(CMD_TYPE)) { final String type = commandLine.getOptionValue(CMD_TYPE); if ("jms-embedded".equals(type)) { configuration.setProperty(JMSEmbeddedConnector.PORT, commandLine.getOptionValue(CMD_PORT)); } else if ("tcp-single-server".equals(type)) { configuration.setProperty(TCPSingleServerConnector.PORT, commandLine.getOptionValue(CMD_PORT)); } else if ("tcp-server".equals(type)) { configuration.setProperty(TCPMultiServerConnector.PORT, commandLine.getOptionValue(CMD_PORT)); } else if ("tcp-client".equals(type)) { configuration.setProperty(TCPClientConnector.PORT, commandLine.getOptionValue(CMD_PORT)); } else if ("http-rest".equals(type)) { configuration.setProperty(HTTPConnector.PORT, commandLine.getOptionValue(CMD_PORT)); } } if (commandLine.hasOption(CMD_HOST)) { configuration.setProperty(TCPClientConnector.HOSTNAME, commandLine.getOptionValue(CMD_HOST)); } if (commandLine.hasOption(CMD_USER)) { configuration.setProperty(JMSClientConnector.USERNAME, commandLine.getOptionValue(CMD_USER)); } if (commandLine.hasOption(CMD_PASSWORD)) { configuration.setProperty(JMSClientConnector.PASSWORD, commandLine.getOptionValue(CMD_PASSWORD)); } if (commandLine.hasOption(CMD_URL)) { configuration.setProperty(JMSClientConnector.URI, commandLine.getOptionValue(CMD_URL)); configuration.setProperty(HTTPConnector.REST_URL, commandLine.getOptionValue(CMD_URL)); } if (commandLine.hasOption(CMD_CONTEXT)) { configuration.setProperty(HTTPConnector.CONTEXT, commandLine.getOptionValue(CMD_CONTEXT)); } if (commandLine.hasOption(CMD_TYPE)) { final Reflections reflections = new Reflections("kieker.tools.bridge.connector"); final Set<Class<?>> connectors = reflections .getTypesAnnotatedWith(kieker.tools.bridge.connector.ConnectorProperty.class); for (final Class<?> connector : connectors) { if (connector.getAnnotation(kieker.tools.bridge.connector.ConnectorProperty.class).cmdName() .equals(commandLine.getOptionValue(CMD_TYPE))) { configuration.setProperty(CLI_CONNECTOR, connector.getCanonicalName()); break; } } } // start service depending on type final IServiceConnector connector = CLIServerMain.createService(configuration, lookupEntityMap); CLIServerMain.getLog().info("Service " + connector.getClass() .getAnnotation(kieker.tools.bridge.connector.ConnectorProperty.class).name()); CLIServerMain.runService(configuration, connector); } catch (final ParseException e) { CLIServerMain.usage("Parsing failed. Reason: " + e.getMessage()); exitCode = 4; } catch (final IOException e) { CLIServerMain.usage("Mapping file read error: " + e.getMessage()); exitCode = 1; } catch (final CLIConfigurationErrorException e) { CLIServerMain.usage("Configuration error: " + e.getMessage()); exitCode = 2; } catch (final ConnectorDataTransmissionException e) { CLIServerMain.usage("Communication error: " + e.getMessage()); exitCode = 3; } // finally { // // The URLClassLoader does not have a close method in Java 1.5 // // if (classLoader != null) { // // try { // // classLoader.close(); // // } catch (final IOException e) { // // LOG.error("Classloader failed on close."); // // exitCode = 5; // // } // // } // } System.exit(exitCode); }
From source file:Main.java
public static boolean isJacksonStdImpl(Class<?> implClass) { return (implClass.getAnnotation(JacksonStdImpl.class) != null); }
From source file:Main.java
private static String getName(Class<?> aClass) { XmlRootElement xmlRootElement = aClass.getAnnotation(XmlRootElement.class); return xmlRootElement.name(); }
From source file:Main.java
private static <T> String elementNameFrom(final Class<T> clazz) { return Optional.ofNullable(clazz.getAnnotation(XmlRootElement.class)).map(XmlRootElement::name) .orElseGet(clazz::getSimpleName); }
From source file:Main.java
public static <T> T getAnnotation(Object annotatedClass, Class<T> annotation) { Class screenType = annotatedClass.getClass(); return (T) screenType.getAnnotation(annotation); }
From source file:Main.java
static String getRootElementName(Class<?> clazz) { XmlRootElement element = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class); return !DEFAULT_NAME.equals(element.name()) ? element.name() : clazz.getSimpleName(); }
From source file:Main.java
public static boolean hasAnnotation(Class clas, Class annotationClass) { boolean has = false; Annotation a = clas.getAnnotation(annotationClass); return a == null ? false : true; }
From source file:Main.java
public static String getNamespace(Class<?> clazz) { XmlType xmlType = clazz.getAnnotation(XmlType.class); String namespace = null;/* w w w . j a v a2 s . c o m*/ if (xmlType != null) { namespace = xmlType.namespace(); if ("##default".equals(namespace)) { namespace = null; } } if (namespace == null) { Package itemPackage = clazz.getPackage(); XmlSchema xmlSchema = itemPackage.getAnnotation(XmlSchema.class); if (xmlSchema != null) { namespace = xmlSchema.namespace(); } } return namespace; }
From source file:koper.util.ReflectUtil.java
/** * ?Listen//from w w w.j a v a 2s. co m * * @param clazz Class * @return Listen */ public static Listen getListenAnnotation(Class<?> clazz) { return clazz.getAnnotation(Listen.class); }