设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> Java >> Peeking Inside the Box: Attribute-Oriented Programming with Java 1.5, Part 2 作者:Don Schwarz
精品推荐
Java点击TOP10
·java笔试题
·《Thinking in Java》读书笔记
·JSP的mysql_jdbc驱动程序
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·Java Coder 常用软件下载地址
·org.apache.commons.dbcp.SQLNestedException解决办法
·Java图形界面开发:SWT全接触
·如何使用Java POI生成Excel表文件 !
·功能强大的在线网页编辑器
·一些非常不错的Struts 例子下载
编程开发点击TOP10
·ASP.NET 程序中常用的三十三种代码
·利用ASP.NET构建网上考试系统
·C#版的网站新闻发布系统
·(转)23种设计模式汇集
·设计ASP.NET新闻管理系统
·深山红叶袖珍PE工具箱V16正式版
·我的.NET书架 (入门篇)
·java笔试题
·.NET:是什么?将走向哪里?
·C++经典电子书下载
精选专题

Peeking Inside the Box: Attribute-Oriented Programming with Java 1.5, Part 2 作者:Don Schwarz

作者: 来源:网络文章 时间:2005-12-15 21:00:43

Peeking Inside the Box: Attribute-Oriented Programming with Java 1.5, Part 2 作者:Don Schwarz(1)

Peeking Inside the Box: Attribute-Oriented Programming with Java 1.5

In the previous article in this series, "Java.com/pub/a/onJava/2004/06/30/insidebox1.html" lid="Peeking Inside the Box, Part 1">Peeking Inside the Box, Part 1," I introdUCed the concepts of Attribute-Oriented Programming, Java 1.5 annotations, and bytecode instrumentation. I used these concepts to provide a JStatusBar GUI component that reports on the progress of an application without any eXPlicit code. In this article I will introdUCe a completely different implementation of the same JStatusBar that uses thread sampling rather than bytecode instrumentation. I will then combine the two practices to develop a solution that has the best features of each.

In the previous article, I also defined a new annotation, @Status, which I used throughout my code to associate methods with user-readable status messages. For example:

@Status("Connecting to database")public void connectToDB (String url) { ...}

Exception Handling

As discussed in the previous article, I may want to write additional code which uses the @Status annotations for a different purpose. Let's consider the additional requirement that our application must catch all unhandled exceptions and display them to the user. Rather than providing a Java stack trace, however, it should only display methods that have a @Status annotation, and it should not show any code artifacts (class or method names, line numbers, etc.).

For example, consider the following stack trace:

Java.lang.RuntimeException: Could not load data for symbol IBM at boXPeeking.code.YourCode.loadData(Unknown Source) at boXPeeking.code.YourCode.go(Unknown Source) at boXPeeking.yourcode.ui.Main+2.run(Unknown Source) at Java.lang.Thread.run(Thread.Java:566)Caused by: Java.lang.RuntimeException: Timed out at boXPeeking.code.YourCode.connectToDB(Unknown Source) ... 4 more

This should result in the GUI pop-up box in Figure 1, assuming that YourCode.loadData(), YourCode.go(), and YourCode.connectToDB() all have @Status annotations. Note that the order of the exceptions is reversed so that the user is given the most detailed information first.

Figure 1Java.com/onJava/2004/07/21/graphiCS/exception.png" width=268>

共5页 9 7 [1] [2] [3] [4] [58 :>

Peeking Inside the Box: Attribute-Oriented Programming with Java 1.5, Part 2 作者:Don Schwarz 相关文章:
Peeking Inside the Box: Attribute-Oriented Programming with Java 1.5, Part 2 作者:Don Schwarz 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com