List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:com.bigstep.datalake.JsonUtil.java
private static String toJsonString(final Class<?> clazz, final Object value) { return toJsonString(clazz.getSimpleName(), value); }
From source file:iing.uabc.edu.mx.persistencia.util.JSON.java
private static Collection parseArray(JsonParser parser, CollectionManager manager) { Event evt;/*from w ww . ja v a 2 s .co m*/ Class elementClass = manager.getElementClass(); int pos = 0; do { evt = parser.next(); switch (evt) { case START_OBJECT: //The most expected case of all in an array System.out.println( "Nuevo Objeto: " + elementClass.getSimpleName() + " del arreglo en la pos: " + pos); BeanManager objectManager = new BeanManager(elementClass); Object result = parseObject(parser, objectManager); manager.addElement(result); pos++; break; // case START_ARRAY: // //Only possible if array of arrays in json which is unlikely // //Also if in the pojo there is a recursive collection diferent // //from arraylist then there will be some problems. // //// System.out.println("Nueva Colleccion de clase: " + //// elementClass.getSimpleName() + "dentro de otro " //// + "arreglo en la pos: " + pos); //// //// CollectionManager<T> collectionManager = new //// CollectionManager<>(new ArrayList<>(), elementClass); //// //// Collection<T> collection = parseArray(parser, collectionManager); //// manager.addElement(collection); //// pos++; // break; //if it is an array of booleans.... but no. case VALUE_FALSE: System.out.println("Agregando false al arreglo en la pos: " + pos); manager.addElement(false); pos++; break; case VALUE_NULL: System.out.println("Agregando null al arreglo en la pos: " + pos); manager.addElement(null); pos++; break; case VALUE_NUMBER: //double or int if (parser.isIntegralNumber()) { int value = parser.getInt(); System.out.println("Agregando " + value + " al arreglo en la pos: " + pos); manager.addElement(value); pos++; } else { double value = parser.getBigDecimal().doubleValue(); System.out.println("Agregando " + value + " al arreglo en la pos: " + pos); manager.addElement(value); pos++; } break; case VALUE_STRING: String value = parser.getString(); //Validate if the field is of type Date if (manager.getElementClass() == Date.class) { Calendar cal = DatatypeConverter.parseDateTime(value); Date date = cal.getTime(); System.out.println("Agregando " + date + " al arreglo en la pos: " + pos); manager.addElement(date); pos++; } else { System.out.println("Agregando " + value + " al arreglo en la pos: " + pos); manager.addElement(value); pos++; } break; case VALUE_TRUE: System.out.println("Agregando true al arreglo en la pos: " + pos); manager.addElement(true); pos++; break; } } while (evt != Event.END_ARRAY); return manager.getCollection(); }
From source file:org.cybercat.automation.annotations.AnnotationBuilder.java
@SuppressWarnings("unchecked") private static final <T extends IIntegrationService> T createIntegrationService(Class<T> clazz, CCIntegrationService aService) throws AutomationFrameworkException { Class<T> cService = versionControlPreprocessor(clazz); Constructor<T> cons;// ww w.j a va2 s . co m try { cons = cService.getConstructor(); T result = cons.newInstance(); processIntegrationService(result, result.getClass()); result.setup(); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(result); proxyFactory.addAspect(new IntegrationServiceAspect(aService.hasSession())); result = (T) proxyFactory.getProxy(); log.info(cService.getSimpleName() + " integration Service has been created."); return result; } catch (Exception e) { throw new AutomationFrameworkException("Integration service creation problem.", e); } }
From source file:be.fedict.eid.applet.maven.DocbookMojo.java
private static BasicVisualizationServer<String, String> createGraph() { AppletProtocolMessageCatalog catalog = new AppletProtocolMessageCatalog(); List<Class<?>> catalogClasses = catalog.getCatalogClasses(); Map<ProtocolState, List<String>> allowedProtocolStates = new HashedMap<ProtocolState, List<String>>(); String startMessage = null;// w ww. j a v a 2 s . c om List<String> stopMessages = new LinkedList<String>(); Graph<String, String> graph = new SparseMultigraph<String, String>(); for (Class<?> messageClass : catalogClasses) { StartRequestMessage startRequestMessageAnnotation = messageClass .getAnnotation(StartRequestMessage.class); if (null != startRequestMessageAnnotation) { if (null != startMessage) { throw new RuntimeException("only one single entry point possible"); } startMessage = messageClass.getSimpleName(); } StopResponseMessage stopResponseMessageAnnotation = messageClass .getAnnotation(StopResponseMessage.class); if (null != stopResponseMessageAnnotation) { stopMessages.add(messageClass.getSimpleName()); } graph.addVertex(messageClass.getSimpleName()); ProtocolStateAllowed protocolStateAllowedAnnotation = messageClass .getAnnotation(ProtocolStateAllowed.class); if (null != protocolStateAllowedAnnotation) { ProtocolState protocolState = protocolStateAllowedAnnotation.value(); List<String> messages = allowedProtocolStates.get(protocolState); if (null == messages) { messages = new LinkedList<String>(); allowedProtocolStates.put(protocolState, messages); } messages.add(messageClass.getSimpleName()); } } int edgeIdx = 0; for (Class<?> messageClass : catalogClasses) { ResponsesAllowed responsesAllowedAnnotation = messageClass.getAnnotation(ResponsesAllowed.class); if (null != responsesAllowedAnnotation) { Class<?>[] responseClasses = responsesAllowedAnnotation.value(); for (Class<?> responseClass : responseClasses) { String edgeName = "edge-" + edgeIdx; graph.addEdge(edgeName, messageClass.getSimpleName(), responseClass.getSimpleName(), EdgeType.DIRECTED); edgeIdx++; } } StateTransition stateTransitionAnnotation = messageClass.getAnnotation(StateTransition.class); if (null != stateTransitionAnnotation) { ProtocolState protocolState = stateTransitionAnnotation.value(); List<String> messages = allowedProtocolStates.get(protocolState); for (String message : messages) { graph.addEdge("edge-" + edgeIdx, messageClass.getSimpleName(), message, EdgeType.DIRECTED); edgeIdx++; } } } Layout<String, String> layout = new CircleLayout<String, String>(graph); layout.setSize(new Dimension(900, 600)); BasicVisualizationServer<String, String> visualization = new BasicVisualizationServer<String, String>( layout); visualization.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); Transformer<String, Paint> myVertexTransformer = new MyVertexTransformer(startMessage, stopMessages); visualization.getRenderContext().setVertexFillPaintTransformer(myVertexTransformer); Transformer<String, Paint> myEdgeTransformer = new MyEdgeTransformer(); visualization.getRenderContext().setEdgeDrawPaintTransformer(myEdgeTransformer); visualization.getRenderer().getVertexLabelRenderer().setPosition(Position.AUTO); visualization.setPreferredSize(new Dimension(900, 650)); visualization.setBackground(Color.WHITE); return visualization; }
From source file:com.flexive.shared.EJBLookup.java
/** * Build the correct JNDI name to request for lookups depending on the discovered lookup strategy * * @param appName EJB application name//from ww w . j a va 2 s . com * @param type the class to lookup * @return JNDI name */ private static <T> String buildName(String appName, Class<T> type) { switch (used_strategy) { case APP_SIMPLENAME_LOCAL: return appName + "/" + type.getSimpleName() + "/local"; case APP_SIMPLENAME_REMOTE: return appName + "/" + type.getSimpleName() + "/remote"; case COMPLEXNAME: return type.getCanonicalName(); case SIMPLENAME: return type.getSimpleName(); case SIMPLENAME_LOCAL: return type.getSimpleName() + "/local"; case SIMPLENAME_REMOTE: return type.getSimpleName() + "/remote"; case JAVA_COMP_ENV: return "java:comp/env/" + type.getSimpleName(); case GERONIMO_LOCAL: return "/" + type.getSimpleName() + "Local"; case GERONIMO_REMOTE: return "/" + type.getSimpleName() + "Remote"; case MAPPED_NAME_REMOTE: return type.getSimpleName() + "#" + type.getCanonicalName(); case EJB31_MODULE: // EJB 3.1: EJB packaged in module return "java:module/" + type.getSimpleName() + "!" + type.getCanonicalName() + "Local"; case EJB31_APP_MODULE: // EJB 3.1: flexive-ejb module in EAR return "java:app/flexive-ejb/" + type.getSimpleName() + "!" + type.getCanonicalName() + "Local"; case EJB31_EMBEDDED: // EJB 3.1: embedded container with global paths return "java:global/" + EJB31_EMBEDDED_APPNAME + "/" + type.getSimpleName() + "!" + type.getCanonicalName() + "Local"; default: throw new FxLookupException("Unsupported/unknown lookup strategy " + used_strategy + "!") .asRuntimeException(); } }
From source file:com.googlecode.fightinglayoutbugs.FindBugsRunner.java
private static List<Runner> getRunners(final Class<?> suiteClass) { try {/*w w w .j a v a 2s. co m*/ List<String> classPath = getClassPath(suiteClass); File classesDir = getClassesDir(classPath); Bugs bugs = analyzeClasses(classesDir, classPath); return getRunnersForPackage("", classesDir, bugs); } catch (final Exception e) { // Initialization failed, return single runner which rethrows the caught exception ... final Description description = Description.createSuiteDescription(suiteClass.getSimpleName()); Runner runner = new Runner() { @Override public Description getDescription() { return description; } @Override public void run(RunNotifier notifier) { notifier.fireTestStarted(description); notifier.fireTestFailure(new Failure(description, e)); notifier.fireTestFinished(description); } @Override public int testCount() { return 1; } }; return Collections.singletonList(runner); } }
From source file:MyClass.java
public static String getClassDescription(Class c) { StringBuilder classDesc = new StringBuilder(); int modifierBits = 0; String keyword = ""; if (c.isInterface()) { modifierBits = c.getModifiers() & Modifier.interfaceModifiers(); if (c.isAnnotation()) { keyword = "@interface"; } else {// ww w . j ava2 s. c om keyword = "interface"; } } else if (c.isEnum()) { modifierBits = c.getModifiers() & Modifier.classModifiers(); keyword = "enum"; } modifierBits = c.getModifiers() & Modifier.classModifiers(); keyword = "class"; String modifiers = Modifier.toString(modifierBits); classDesc.append(modifiers); classDesc.append(" " + keyword); String simpleName = c.getSimpleName(); classDesc.append(" " + simpleName); String genericParms = getGenericTypeParams(c); classDesc.append(genericParms); Class superClass = c.getSuperclass(); if (superClass != null) { String superClassSimpleName = superClass.getSimpleName(); classDesc.append(" extends " + superClassSimpleName); } String interfaces = Main.getClassInterfaces(c); if (interfaces != null) { classDesc.append(" implements " + interfaces); } return classDesc.toString(); }
From source file:org.hawkular.wildfly.agent.itest.util.AbstractITest.java
public static void writeNode(Class<?> caller, ModelNode node, String nodeFileName) throws UnsupportedEncodingException, FileNotFoundException { URL callerUrl = caller.getResource(caller.getSimpleName() + ".class"); if (!callerUrl.getProtocol().equals("file")) { throw new IllegalStateException(AbstractITest.class.getName() + ".store() works only if the caller's class file is loaded using a file:// URL."); }/*from w w w . j ava2 s.co m*/ String callerUrlPath = callerUrl.getPath(); String nodePath = callerUrlPath.replaceAll("\\.class$", "." + nodeFileName); nodePath = nodePath.replace("/target/test-classes/", "/src/test/resources/"); System.out.println("Storing a node to [" + nodePath + "]"); File outputFile = new File(nodePath); if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "utf-8"))) { node.writeString(out, false); } }
From source file:edu.ku.brc.af.core.db.DBTableIdMgr.java
/** * Returns the UIFieldFormatterIFace for a given Table Class and field Name. * @param tableClass the name of the class to look up * @param fieldName the field name/*w w w . j av a 2s. c o m*/ * @return null or the formatter */ public static UIFieldFormatterIFace getFieldFormatterFor(final Class<?> tableClass, final String fieldName) { DBTableInfo ti = DBTableIdMgr.getInstance().getByShortClassName(tableClass.getSimpleName()); if (ti != null) { DBFieldInfo fi = ti.getFieldByName(fieldName); if (fi != null) { return fi.getFormatter(); } } return null; }
From source file:com.trsst.Common.java
public static Attributes getManifestAttributes() { Attributes result = null;/*from w ww .j a v a 2 s . c o m*/ Class<Common> clazz = Common.class; String className = clazz.getSimpleName() + ".class"; URL classPath = clazz.getResource(className); if (classPath == null || !classPath.toString().startsWith("jar")) { // Class not from JAR return null; } String classPathString = classPath.toString(); String manifestPath = classPathString.substring(0, classPathString.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; try { Manifest manifest = new Manifest(new URL(manifestPath).openStream()); result = manifest.getMainAttributes(); } catch (MalformedURLException e) { log.error("Could not locate manifest: " + manifestPath); } catch (IOException e) { log.error("Could not open manifest: " + manifestPath); } return result; }