/** * Insert the source code details, if available. * * @param ped The given program element. */ public void addSourcePosition(ProgramElementDoc ped, int indent) { if (!addSrcInfo) return; if (JDiff.javaVersion.startsWith("1.1") || JDiff.javaVersion.startsWith("1.2") || JDiff.javaVersion.startsWith("1.3")) { return; // position() only appeared in J2SE1.4 } try { // Could cache the method for improved performance Class c = ProgramElementDoc.class; Method m = c.getMethod("position", null); Object sp = m.invoke(ped, null); if (sp != null) { for (int i = 0; i < indent; i++) outputFile.print(" "); outputFile.println("src=\"" + sp + "\""); } } catch (NoSuchMethodException e2) { System.err.println("Error: method \"position\" not found"); e2.printStackTrace(); } catch (IllegalAccessException e4) { System.err.println("Error: class not permitted to be instantiated"); e4.printStackTrace(); } catch (InvocationTargetException e5) { System.err.println("Error: method \"position\" could not be invoked"); e5.printStackTrace(); } catch (Exception e6) { System.err.println("Error: "); e6.printStackTrace(); } }
protected synchronized Message receiveMessage() throws IOException { if (messageBuffer.size() > 0) { Message m = (Message) messageBuffer.get(0); messageBuffer.remove(0); return m; } try { InetSocketAddress remoteAddress = (InetSocketAddress) channel.receive(receiveBuffer); if (remoteAddress != null) { int len = receiveBuffer.position(); receiveBuffer.rewind(); receiveBuffer.get(buf, 0, len); try { IP address = IP.fromInetAddress(remoteAddress.getAddress()); int port = remoteAddress.getPort(); extractor.appendData(buf, 0, len, new SocketDescriptor(address, port)); receiveBuffer.clear(); extractor.updateAvailableMessages(); return extractor.nextMessage(); } catch (EOFException exc) { exc.printStackTrace(); System.err.println(buf.length + ", " + len); } catch (InvocationTargetException exc) { exc.printStackTrace(); } catch (IllegalAccessException exc) { exc.printStackTrace(); } catch (InstantiationException exc) { exc.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvalidCompressionMethodException e) { e.printStackTrace(); } } } catch (ClosedChannelException exc) { if (isKeepAlive()) { throw exc; } } return null; }
/** Clears the view. */ @Override public void clear() { final Drawing newDrawing = createDrawing(); try { SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { view.getDrawing().removeUndoableEditListener(undo); view.setDrawing(newDrawing); view.getDrawing().addUndoableEditListener(undo); undo.discardAllEdits(); } }); } catch (InvocationTargetException ex) { ex.printStackTrace(); } catch (InterruptedException ex) { ex.printStackTrace(); } }
/** * Processes the request coming to the servlet and grabs the attributes set by the servlet and * uses them to fire off pre-determined methods set in the setupActionMethods function of the * servlet. * * @param request the http request coming from the browser. * @param response the http response going to the browser. * @throws javax.servlet.ServletException * @throws java.io.IOException */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!actionInitialized) { LogController.write(this, "This dispatcher servlet is not initialized properly!"); return; } if (actionTag == null) { LogController.write(this, "There is no action attribute tag name!"); return; } HttpSession httpSession = request.getSession(); UserSession userSession = (UserSession) httpSession.getAttribute("user_session"); if (userSession == null) { LogController.write(this, "User session is no longer available in this http session."); userSession = new UserSession(); // We always want a user session though... httpSession.setAttribute("user_session", userSession); } String action = (String) request.getAttribute(actionTag); try { if (action == null) { // There is no action attribute specified, check parameters. String external_action = (String) request.getParameter(actionTag); if (external_action != null) { Method method = externalActions.get(external_action); if (method != null) { LogController.write(this, "Performing external action: " + external_action); method.invoke(this, new Object[] {userSession, request, response}); } else { if (defaultExternalMethod != null) { LogController.write(this, "Performing default external action."); defaultExternalMethod.invoke(this, new Object[] {userSession, request, response}); } else { LogController.write(this, "Unable to perform default external action."); } } } else { if (defaultExternalMethod != null) { LogController.write(this, "Performing default external action."); defaultExternalMethod.invoke(this, new Object[] {userSession, request, response}); } else { LogController.write(this, "Unable to perform default external action."); } } } else { Method method = internalActions.get(action); if (method != null) { LogController.write(this, "Performing internal action: " + action); method.invoke(this, new Object[] {userSession, request, response}); } else { if (defaultInternalMethod != null) { LogController.write(this, "Performing default internal action."); defaultInternalMethod.invoke(this, new Object[] {userSession, request, response}); } else { LogController.write(this, "Unable to perform default internal action."); } } request.removeAttribute("application_action"); } } catch (IllegalAccessException accessEx) { LogController.write(this, "Exception while processing request: " + accessEx.getMessage()); } catch (InvocationTargetException invokeEx) { LogController.write(this, "Exception while processing request: " + invokeEx.toString()); invokeEx.printStackTrace(); } catch (Exception ex) { LogController.write(this, "Unknown exception: " + ex.toString()); } }