List of usage examples for java.lang StackTraceElement getClassName
public String getClassName()
From source file:com.quinsoft.zeidon.dbhandler.PessimisticLockingViaDb.java
/** * Adds a string to the locking table that is a partial call stack. * * @param cursor/* w w w . j a v a2 s . com*/ */ private void addCallStack(EntityCursor cursor) { EntityDef zeidonLock = cursor.getEntityDef(); AttributeDef callStackAttr = zeidonLock.getAttribute("CallStack", false); if (callStackAttr == null || callStackAttr.isHidden()) return; StringBuilder sb = new StringBuilder(); int count = 0; StackTraceElement[] stack = new RuntimeException().getStackTrace(); for (StackTraceElement element : stack) { String classname = element.getClassName(); if (classname.startsWith("com.quinsoft.zeidon")) continue; sb.append(element.toString()).append("\n"); if (++count > 5) break; } // Make sure the string lenth isn't too long. int lth = cursor.getAttribute("CallStack").getAttributeDef().getLength(); if (sb.length() > lth) sb.setLength(lth); cursor.getAttribute("CallStack").setValue(sb.toString()); }
From source file:org.eclipse.wb.internal.core.editor.UndoManager.java
private void scheduleRefresh_onBufferChange() { final int bufferChangeCount = ++m_bufferChangeCount; Runnable runnable = new Runnable() { public void run() { if (isStillInSave()) { Display.getDefault().timerExec(1, this); return; }//from w w w . ja v a2 s . co m if (bufferChangeCount == m_bufferChangeCount) { refreshDesignerEditor(); } } /** * Save operation may run event loops, so wait for finishing "doSave()" to reparse when save * is complete. This allows also avoid deadlock in case if we will join to wait for finishing * auto build job. */ private boolean isStillInSave() { String editorClassName = "org.eclipse.wb.internal.core.editor.multi.DesignerEditor"; StackTraceElement[] elements = new Exception().getStackTrace(); for (StackTraceElement element : elements) { if (element.getClassName().equals(editorClassName)) { if (element.getMethodName().equals("doSave")) { return true; } } } return false; } }; Display.getDefault().asyncExec(runnable); }
From source file:gov.nih.nci.cagrid.identifiers.test.StressTestUtil.java
public void testOnlyRegisterGSID(long numberOfTests) { List<String> identifiers = new ArrayList<String>(); String suggestedIdentifier = null; int randomNumber; for (long i = 0l; i < numberOfTests; i++) { randomNumber = rand.nextInt(20); String parentIdentifiers[] = null; // 2 parents 5% if (randomNumber == 0 && identifiers.size() > 2) { int firstIdIndex = rand.nextInt(identifiers.size()); int secondIdIndex = rand.nextInt(identifiers.size()); while (secondIdIndex == firstIdIndex) secondIdIndex = rand.nextInt(identifiers.size()); parentIdentifiers = new String[] { identifiers.get(firstIdIndex), identifiers.get(secondIdIndex) }; }/* ww w .ja v a 2 s . co m*/ // 1 parent 25 % else if (identifiers.size() > 0 && randomNumber % 4 == 1) { int firstIdIndex = rand.nextInt(identifiers.size()); parentIdentifiers = new String[] { identifiers.get(firstIdIndex) }; } try { String identifier = testUtil.registerGSID(suggestedIdentifier, parentIdentifiers); // if(i%100==0) // System.out.println(i); addElement2List(identifiers, identifier); writeToFile(identifier); } catch (Exception e) { System.out.println("exception occured1 " + e.getMessage()); e.printStackTrace(); StringBuffer sb = new StringBuffer(); for (StackTraceElement temp : e.getStackTrace()) sb.append(temp.getClassName() + "[" + temp.getLineNumber() + "]\n"); log.debug("exception occured \n" + sb.toString()); } } }
From source file:com.ibm.sbt.test.lib.MockSerializer.java
private StackTraceElement getStackTraceElement() { StackTraceElement last = null; StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); for (StackTraceElement trace : stackTraceElements) { try {/*from w w w .ja va 2 s .c om*/ if (Class.forName(trace.getClassName()).getMethod(trace.getMethodName()) .isAnnotationPresent(Test.class)) last = trace; if (Class.forName(trace.getClassName()).getMethod(trace.getMethodName()) .isAnnotationPresent(After.class)) last = trace; if (Class.forName(trace.getClassName()).getMethod(trace.getMethodName()) .isAnnotationPresent(Before.class)) last = trace; if (Class.forName(trace.getClassName()).getMethod(trace.getMethodName()) .isAnnotationPresent(AfterClass.class)) last = trace; if (Class.forName(trace.getClassName()).getMethod(trace.getMethodName()) .isAnnotationPresent(BeforeClass.class)) last = trace; } catch (Exception e) { } } return last; }
From source file:com.ibm.sbt.test.lib.MockSerializer.java
public HttpResponse replayResponse() throws ClientServicesException { try {//from ww w. j a va 2 s . com Node r = getReader().next(); NamedNodeMap nnm = r.getAttributes(); String code = nnm.getNamedItem("statusCode").getTextContent(); String reason = nnm.getNamedItem("statusReason").getTextContent(); Node headers = (Node) DOMUtil.evaluateXPath(r, "./headers").getSingleNode(); Node data = (Node) DOMUtil.evaluateXPath(r, "./data").getSingleNode(); String entity = null; if (data != null) { if (data.getFirstChild() == null) entity = ""; else entity = ((CharacterData) data.getFirstChild()).getData(); } Iterator<Node> hIt = (Iterator<Node>) DOMUtil.evaluateXPath(headers, "./header").getNodeIterator(); ArrayList<Header> allHeaders = new ArrayList<Header>(); while (hIt.hasNext()) { Node headerNode = hIt.next(); String name = ((Node) DOMUtil.evaluateXPath(headerNode, "./name").getSingleNode()).getTextContent(); String value = ((Node) DOMUtil.evaluateXPath(headerNode, "./value").getSingleNode()) .getTextContent(); allHeaders.add(new BasicHeader(name, value)); } return buildResponse(allHeaders.toArray(new Header[allHeaders.size()]), Integer.valueOf(code), reason, entity); } catch (FileNotFoundException e) { StackTraceElement trace = getStackTraceElement(); String fullClassName = trace.getClassName(); String methodName = trace.getMethodName(); String endpointName = getEndpointName(); throw new MockingException(e, "Mocking file missing for test: " + fullClassName + "." + methodName + "/" + endpointName); } catch (Exception e) { throw new MockingException(e, "Corrupted Mocking file, please regenerate: " + getPath()); } }
From source file:com.ibm.sbt.test.lib.MockSerializer.java
private String getResource() { StackTraceElement trace = getStackTraceElement(); String methodName = trace.getMethodName(); String fullClassName = trace.getClassName().replace(".", "/"); String packageName = fullClassName.substring(0, fullClassName.lastIndexOf("/")); String className = fullClassName.substring(fullClassName.lastIndexOf("/")); String resource = new StringBuilder("/").append(packageName).append("/").append("mockData").append("/") .append(endpointName).append(className).append("_").append(methodName).append(".mock").toString(); return resource; }
From source file:org.cagrid.identifiers.namingauthority.StressTestUtil.java
public void testOnlyRegisterGSID(SecurityInfo client, long numberOfTests) { List<String> identifiers = new ArrayList<String>(); String suggestedIdentifier = null; int randomNumber; for (long i = 0l; i < numberOfTests; i++) { randomNumber = rand.nextInt(20); String parentIdentifiers[] = null; // 2 parents 5% if (randomNumber == 0 && identifiers.size() > 2) { int firstIdIndex = rand.nextInt(identifiers.size()); int secondIdIndex = rand.nextInt(identifiers.size()); while (secondIdIndex == firstIdIndex) secondIdIndex = rand.nextInt(identifiers.size()); parentIdentifiers = new String[] { identifiers.get(firstIdIndex), identifiers.get(secondIdIndex) }; }/* w ww . j a v a 2s . c o m*/ // 1 parent 25 % else if (identifiers.size() > 0 && randomNumber % 4 == 1) { int firstIdIndex = rand.nextInt(identifiers.size()); parentIdentifiers = new String[] { identifiers.get(firstIdIndex) }; } try { String identifier = testUtil.registerGSID(client, suggestedIdentifier, parentIdentifiers); // if(i%100==0) // System.out.println(i); addElement2List(identifiers, identifier); writeToFile(identifier); } catch (Exception e) { System.out.println("exception occured1 " + e.getMessage()); e.printStackTrace(); StringBuffer sb = new StringBuffer(); for (StackTraceElement temp : e.getStackTrace()) sb.append(temp.getClassName() + "[" + temp.getLineNumber() + "]\n"); log.debug("exception occured \n" + sb.toString()); } } }
From source file:com.chenxin.authority.common.logback.DBAppender.java
void bindCallerDataWithPreparedStatement(PreparedStatement stmt, StackTraceElement[] callerDataArray) throws SQLException { StackTraceElement callerData = callerDataArray[0]; if (callerData != null) { stmt.setString(CALLER_FILENAME_INDEX, callerData.getFileName()); stmt.setString(CALLER_CLASS_INDEX, callerData.getClassName()); stmt.setString(CALLER_METHOD_INDEX, callerData.getMethodName()); stmt.setString(CALLER_LINE_INDEX, Integer.toString(callerData.getLineNumber())); }//w w w . ja v a 2s . co m }
From source file:com.ibm.sbt.test.lib.MockSerializer.java
private String getPath() { StackTraceElement trace = getStackTraceElement(); String basePath = System.getProperty("user.dir"); String fullClassName = trace.getClassName().replace(".", File.separator); String className = fullClassName.substring(fullClassName.lastIndexOf(File.separatorChar)); String packageName = fullClassName.substring(0, fullClassName.lastIndexOf(File.separatorChar)); String methodName = trace.getMethodName(); String endpointName = getEndpointName(); String path = new StringBuilder(basePath).append(File.separator).append("src").append(File.separator) .append("test").append(File.separator).append("resources").append(File.separator) .append(packageName).append(File.separator).append("mockData").append(File.separator) .append(endpointName).append(className).append("_").append(methodName).append(".mock").toString(); return path;/*from w ww . ja v a 2 s.co m*/ }
From source file:org.usapi.common.USAPIException.java
private StackTraceElement getCaller() { StackTraceElement ste[] = Thread.currentThread().getStackTrace(); StackTraceElement candidate = null; // if browser (chrome?) hangs stacktrace can seemingly not have expected contents (invoke0), so // providing default value StackTraceElement caller = new StackTraceElement("UNKNOWN_CLASS", "UNKNOWN_METHOD", "UNKNOWN_FILE", -1); for (int ndx = 0; ndx < ste.length; ndx++) { candidate = ste[ndx];/*from w ww. j a v a 2 s . co m*/ if (candidate.getClassName().equals("sun.reflect.NativeMethodAccessorImpl") && candidate.getMethodName().equals("invoke0")) { // no worries about index out of bounds here, the match is guaranteed to // happen anywhere between index 5-8, total stack depth ~20 caller = ste[ndx - 1]; break; } } return caller; }