??xml version="1.0" encoding="utf-8" standalone="yes"?>色综合咪咪久久网,午夜av成人,密臀av在线播放http://www.aygfsteel.com/carob/archive/2006/08/15/63766.htmlcarobcarobTue, 15 Aug 2006 12:56:00 GMThttp://www.aygfsteel.com/carob/archive/2006/08/15/63766.htmlhttp://www.aygfsteel.com/carob/comments/63766.htmlhttp://www.aygfsteel.com/carob/archive/2006/08/15/63766.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/63766.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/63766.html          从目前的势来看QOSGI在Y件行业的应用相当被看好,ECLIPSE,WAS也全面采用OSGI规范了,׃eclipse自n在采用OSGI之前有一套自恰的plugin机制Q而这U几乎具备无限扩充的plugin机制打开了一个巨大的plugin市场Q再加上OpenSource的东风,使得eclipse几乎一lJava的IDE市场?br />         ?.0eclipse全面采用OSGI开始,便对OSGI多了一份研IӞ在以eclipse景的桌面软g开发领域,osgi如鱼得水Q但我更多的是在做Java的server端开发,很想能够看到web领域能从osgi/Equinox中得C些灵感,很希望,那灵zȝplugin/bundle机制能发挥在web的前后端开发中Q之前在TSS上有人做了一个自UCؓRSPQ与RCP相响应)的DEMOQ展CZ如何在Web面中做C重启服务器来实现面数据的动态组装及服务h。我们都知道在eclipse的插件开发中Q我们可以单独开发一个viewpart或者菜单来插入到现成的IDE中而保持独立性,如果q种Ҏ能在WEB中实现的话,那是相当的诱人的Q现在Equinox已经实现的OSGI 的大部分规范Q也提供了对serlvet及jsp的支持,但仍不够方便Q希望在不久以后能看q方面的q展?br />     



carob 2006-08-15 20:56 发表评论
]]>
SWT中的Sytem Tray相关处理http://www.aygfsteel.com/carob/archive/2006/03/19/36076.htmlcarobcarobSun, 19 Mar 2006 08:36:00 GMThttp://www.aygfsteel.com/carob/archive/2006/03/19/36076.htmlhttp://www.aygfsteel.com/carob/comments/36076.htmlhttp://www.aygfsteel.com/carob/archive/2006/03/19/36076.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/36076.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/36076.html         SWT已经提供了对部分q_Q比如windowQ上的系l托盘的支持。但支持得还不够好,我最q需要在一个聊天工具实现Balloon效果(_附于系l托盘上的一个消息气泡效果,在IM软g中普遍被支持)Q查一下SWT API,到目前ؓ上ƈ没有提供支持。但一个好消息是在月底交要出来?.2M6中,对部分API做调_增加对Balloon的支持?br />

Milestone Plan  3.2  M6 March  31 2006   

 Implement custom draw 
for  table and tree 
Implement 
native  drag source effects  for  cursor 
Implement ImageTransfer support 
Implement Balloon tooltips 
Implement Accessibility on Mac OS X 

     q儿是EclipseZone上的一个针对这一效果的文章:TrayIcons and ToolTips  http://www.eclipsezone.com/eclipse/forums/t66093.rhtml


甚至在官方网站上Q已l提供了q一个API的Snippet

//http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet225.java
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * 
http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************
*/

package org.eclipse.swt.snippets;
  
/*
 * Tooltip example snippet: create a balloon tooltip for a tray item
 *
 * For a list of all SWT example snippets see
 * 
http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.0
 
*/

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet225 {

public static void main(String[] args) {
    Display display 
= new Display();
    Shell shell 
= new Shell(display);
    Image image 
= null;
    
final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
    tip.setMessage(
"Here is message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind.");
    Tray tray 
= display.getSystemTray();
    
if (tray != null{
        TrayItem item 
= new TrayItem(tray, SWT.NONE);
        image 
= new Image(display, Snippet225.class.getResourceAsStream("eclipse.png"));
        item.setImage(image);
        tip.setText(
"Notification from a tray item");
        item.setToolTip(tip);
    }
 else {
        tip.setText(
"Notification from anywhere");
        tip.setLocation(
400400);
    }

    Button button 
= new Button (shell, SWT.PUSH);
    button.setText(
"Press for balloon tip");
    button.addListener(SWT.Selection, 
new Listener() {
        
public void handleEvent(Event event) {
            tip.setVisible(
true);
        }

    }
);
    button.pack();
    shell.setBounds(
5050300200);
    shell.open();
    
while (!shell.isDisposed()) {
        
if (!display.readAndDispatch()) display.sleep();
    }

    
if (image != null) image.dispose();
    display.dispose();
}

}

除此之外Q也有其它的W三方API实现了此一效果。是?a >www.novocode.com提供的BalloonWindow。其API可在上述的网站中获得?/p>

carob 2006-03-19 16:36 发表评论
]]>
如何获取call stack(调用?信息——之?/title><link>http://www.aygfsteel.com/carob/archive/2005/03/13/2027.html</link><dc:creator>carob</dc:creator><author>carob</author><pubDate>Sun, 13 Mar 2005 10:25:00 GMT</pubDate><guid>http://www.aygfsteel.com/carob/archive/2005/03/13/2027.html</guid><wfw:comment>http://www.aygfsteel.com/carob/comments/2027.html</wfw:comment><comments>http://www.aygfsteel.com/carob/archive/2005/03/13/2027.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/carob/comments/commentRss/2027.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/carob/services/trackbacks/2027.html</trackback:ping><description><![CDATA[  从这儿可以看刎ͼ注意如果客户端程序没有显式地指定源方法名和源cdQ则LogRecord cd通过分析 call stack(调用?来自动提取这些信息(Ҏ<STRONG>getSourceMethodname</STRONG>和方?STRONG>getSourceClassName</STRONG>Q?我们已经走在正确的道路上了,l箋q查<STRONG>getSourceMethodname()</STRONG>………?BR>         <BR> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG id=Codehighlighter1_39_119_Open_Image onclick="this.style.display='none'; Codehighlighter1_39_119_Open_Text.style.display='none'; Codehighlighter1_39_119_Closed_Image.style.display='inline'; Codehighlighter1_39_119_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_39_119_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_39_119_Closed_Text.style.display='none'; Codehighlighter1_39_119_Open_Image.style.display='inline'; Codehighlighter1_39_119_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> String getSourceClassName() </SPAN><SPAN id=Codehighlighter1_39_119_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_39_119_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_65_88_Open_Image onclick="this.style.display='none'; Codehighlighter1_65_88_Open_Text.style.display='none'; Codehighlighter1_65_88_Closed_Image.style.display='inline'; Codehighlighter1_65_88_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_65_88_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_65_88_Closed_Text.style.display='none'; Codehighlighter1_65_88_Open_Image.style.display='inline'; Codehighlighter1_65_88_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000"> (needToInferCaller) </SPAN><SPAN id=Codehighlighter1_65_88_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_65_88_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        inferCaller();<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> sourceClassName;<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>    }</SPAN></SPAN></DIV></DIV>      l箋<BR> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> Private method to infer the caller's class and method names</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_94_491_Open_Image onclick="this.style.display='none'; Codehighlighter1_94_491_Open_Text.style.display='none'; Codehighlighter1_94_491_Closed_Image.style.display='inline'; Codehighlighter1_94_491_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_94_491_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_94_491_Closed_Text.style.display='none'; Codehighlighter1_94_491_Open_Image.style.display='inline'; Codehighlighter1_94_491_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> inferCaller() </SPAN><SPAN id=Codehighlighter1_94_491_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_94_491_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>    needToInferCaller </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> Get the stack trace.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">    StackTraceElement stack[] </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Throwable()).getStackTrace();<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> First, search back to a method in the Logger class.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> ix </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG id=Codehighlighter1_309_476_Open_Image onclick="this.style.display='none'; Codehighlighter1_309_476_Open_Text.style.display='none'; Codehighlighter1_309_476_Closed_Image.style.display='inline'; Codehighlighter1_309_476_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_309_476_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_309_476_Closed_Text.style.display='none'; Codehighlighter1_309_476_Open_Image.style.display='inline'; Codehighlighter1_309_476_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000"> (ix </SPAN><SPAN style="COLOR: #000000"><</SPAN><SPAN style="COLOR: #000000"> stack.length) </SPAN><SPAN id=Codehighlighter1_309_476_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_309_476_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        StackTraceElement frame </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> stack[ix];<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        String cname </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> frame.getClassName();<BR><IMG id=Codehighlighter1_446_462_Open_Image onclick="this.style.display='none'; Codehighlighter1_446_462_Open_Text.style.display='none'; Codehighlighter1_446_462_Closed_Image.style.display='inline'; Codehighlighter1_446_462_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_446_462_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_446_462_Closed_Text.style.display='none'; Codehighlighter1_446_462_Open_Image.style.display='inline'; Codehighlighter1_446_462_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>        </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000"> (cname.equals(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">java.util.logging.Logger</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)) </SPAN><SPAN id=Codehighlighter1_446_462_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_446_462_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        </SPAN><SPAN style="COLOR: #0000ff">break</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>        }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        ix</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>……………?BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>……………?/SPAN></DIV></DIV></SPAN>      直至q儿Q我们终于可以松一口气了,因ؓ我们已经扑ֈ了其中的关键<BR> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    StackTraceElement stack[] </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Throwable()).getStackTrace();</SPAN></DIV></DIV>   <BR>      没错Q就是这个StackTraceElement数组记蝲了我们想要的信息Q类名,Ҏ名等Q,q和我们用到的ExceptioncM的显C用栈是一个道理的?BR><BR>      注意Q这儉K过创徏一个Throwable实例Qƈ利用在ThrowablecM提供q个getStackTrace()ҎQ返回是StackTraceElement数组来获取到了调用栈信息?BR><BR>      我们来看一个小例子<BR> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG id=Codehighlighter1_23_227_Open_Image onclick="this.style.display='none'; Codehighlighter1_23_227_Open_Text.style.display='none'; Codehighlighter1_23_227_Closed_Image.style.display='inline'; Codehighlighter1_23_227_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_23_227_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_23_227_Closed_Text.style.display='none'; Codehighlighter1_23_227_Open_Image.style.display='inline'; Codehighlighter1_23_227_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000"> CallStack </SPAN><SPAN id=Codehighlighter1_23_227_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_23_227_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_48_116_Open_Image onclick="this.style.display='none'; Codehighlighter1_48_116_Open_Text.style.display='none'; Codehighlighter1_48_116_Closed_Image.style.display='inline'; Codehighlighter1_48_116_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_48_116_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_48_116_Closed_Text.style.display='none'; Codehighlighter1_48_116_Open_Image.style.display='inline'; Codehighlighter1_48_116_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>    String showTrace() </SPAN><SPAN id=Codehighlighter1_48_116_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_48_116_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Throwable().getStackTrace()[</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">].toString();<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_162_225_Open_Image onclick="this.style.display='none'; Codehighlighter1_162_225_Open_Text.style.display='none'; Codehighlighter1_162_225_Closed_Image.style.display='inline'; Codehighlighter1_162_225_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_162_225_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_162_225_Closed_Text.style.display='none'; Codehighlighter1_162_225_Open_Image.style.display='inline'; Codehighlighter1_162_225_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> main(String[] args) </SPAN><SPAN id=Codehighlighter1_162_225_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_162_225_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> CallStack().showTrace());<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>      <BR>      打印如下<BR>      chapter5.CallStack.showTrace(CallStack.java:5)<BR><BR>      我们亦可以通过q样一个简单地实例化一个Throwable来获取相应的call strack?BR>      不过Q一般的应用U程序里面不太会用到它,可能在工L软g里面用得多一点了Q)<BR><img src ="http://www.aygfsteel.com/carob/aggbug/2027.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/carob/" target="_blank">carob</a> 2005-03-13 18:25 <a href="http://www.aygfsteel.com/carob/archive/2005/03/13/2027.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何获取call stack(调用?信息——之一http://www.aygfsteel.com/carob/archive/2005/03/13/2025.htmlcarobcarobSun, 13 Mar 2005 09:58:00 GMThttp://www.aygfsteel.com/carob/archive/2005/03/13/2025.htmlhttp://www.aygfsteel.com/carob/comments/2025.htmlhttp://www.aygfsteel.com/carob/archive/2005/03/13/2025.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/2025.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/2025.html         
         我们先来看一D代?BR>
………?BR>………?BR>void doSomething(){
     logger.info(
"doSomething()调用成功");
}

………?BR>………?/SPAN>
q是我最常见的日志记录方式?BR>
      我下面就开始我们的q踪以查出logging API是如何记录上面提到的q些metadata的?BR>
      q儿以JDK1.4中的logging API为研I对象?BR>
      先进入java.util.logging.Logger中,看一下info(String msg)q个Ҏ
    public void info(String msg) {
    
if (Level.INFO.intValue() < levelValue) {
        
return;
    }

    log(Level.INFO, msg);
    }
      l箋q踪
    public void log(Level level, String msg) {
    
if (level.intValue() < levelValue || levelValue == offValue) {
        
return;
    }

    LogRecord lr 
= new LogRecord(level, msg);
    doLog(lr);
    }

q儿我们发现了一个值得x的类 LogRecord ,从名字上猜应该是和日志信息有关的一个类。我们来看一下它的Javadoc中的描述
/**
 * LogRecord objects are used to pass logging requests between
 * the logging framework and individual log Handlers.
 * <p>
 * When a LogRecord is passed into the logging framework it 
 * logically belongs to the framework and should no longer be
 * used or updated by the client application.
 * <p>
 * Note that if the client application has not specified an
 * explicit source method name and source class name, then the
 * LogRecord class will infer them automatically when they are
 * first accessed (due to a call on getSourceMethodName or
 * getSourceClassName) by analyzing the call stack.  
   
        从这儿可以看刎ͼ注意如果客户端程序没有显式地指定源方法名和源cdQ则LogRecord cd通过分析 call stack(调用?来自动提取这些信息(ҎgetSourceMethodname和方?STRONG>getSourceClassNameQ?我们已经走在正确的道路上了,l箋q查getSourceMethodname()………?BR>         
    Q未完)

carob 2005-03-13 17:58 发表评论
]]>
应用Java Dynamic Proxy 实现cL法的拦截(AOP)http://www.aygfsteel.com/carob/archive/2005/03/04/1678.htmlcarobcarobFri, 04 Mar 2005 02:37:00 GMThttp://www.aygfsteel.com/carob/archive/2005/03/04/1678.htmlhttp://www.aygfsteel.com/carob/comments/1678.htmlhttp://www.aygfsteel.com/carob/archive/2005/03/04/1678.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/1678.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/1678.html
比如我们现有一对Interface/ImplementionQSpeakable/Translater?BR>Speakable接口指明了可以sayEnglish(),sayChinese()。我们目前的translater实现了这两个Ҏ。现在我们在此基上,增加对translater的方法的logging功能?BR>
在以前,我们可以Q?BR>
1.直接改写原代码,增加logging功能?ugly)
2.增加一个LoggingTranlater实现Speakable,采用delegation(Design Pattern)Q对Ҏq行增强。对此类proxy可以参考jiveQ其中遍布proxy 。缺点就是每一个要增加的类都要实现一个代理类Q可以想象,代码量急剧膨胀?BR>
现在让我们来看看Java Dynamic Proxy是如何达到这一点的Q声明我l出的代理是CZ性的Q比较简陋,主要是给Z个实现方法,加以改进Q即可Ş成一个比较通用的工兗?BR>
先来看看我们的Interface/Implemention对:

package reflection.example;

public interface Speakable {
    
void sayEnglish();

    
void sayChinese();
}


package reflection.example;

public class Translater implements Speakable {

    
public void sayEnglish() {
        System.
out.println("Hello,i am robbie");

    }


    
public void sayChinese() {
        System.
out.println("你好Q我是饺?/SPAN>");

    }


}


现在我们要进行logging功能了,CQ我们只需提供一个InvocationHandler:

package reflection.example;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class LoggingInvoktionHandler implements InvocationHandler {
    
private Object target = null;

    
public LoggingInvoktionHandler(Object target) {
        
this.target = target;
    }


    
public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable 
{
        logging(method);
        
return method.invoke(target, args);
    }


    
private void logging(Method method) {
        
if ("sayChinese".equals(method.getName())) {
            System.
out.println("译开?/SPAN>");
        }


        
if ("sayEnglish".equals(method.getName())) {
            System.
out.println("Tranlation beginning");
        }

    }


}


q个LoggingInvocationHandler实现了InvocationHandler接中。方法的代理调用在invoke(…?中,可以如我dlogging()功能一P加入其它的Q何想要的功能Q然后再q行 real target的方法调用?BR>
如果logging(Method method)中的逻辑抽出来,攑ֈ外部文g(XML)中进行配|读取。再Ҏ法名采用正则表达式。是不是更ؓ通用了呢Q?/P>

下面是客L调用Q?BR>

package reflection.example;

import java.lang.reflect.Proxy;

public class Main {

    
/**
     * @param args
     
*/

    
public static void main(String[] args) {
        Speakable speaker 
= new Translater();

        Speakable loggingSpeaker 
= (Speakable) Proxy.newProxyInstance(
                speaker.getClass().getClassLoader(),
                
new Class[] { Speakable.class },
                
new LoggingInvoktionHandler(speaker));

        loggingSpeaker.sayChinese();
        loggingSpeaker.sayEnglish();
    }

}



是不是非常简单呢Q:)

如果到此为止Q还是看不出Dynamic在哪儿的Q想xq儿l出的示例与spring的AOP的不同,呵呵Q区别在于我q儿l出的Main亦是spring AOP的一部分Q在spring里, Ҏ个Interface的target的代理,采用了ReflectionQ以辑ֈ普遍适用的,不用象我q样直接昑ּ地给出类名而已。若我把Main做成一个Helperc,同时Q把配置接口及他的实现类都放到外部XML中配|,是不是就有点象一个超U简化的spring AOP了?

当然spring不是完全用Java Dynamic Proxy的,因ؓJava Dynamic Proxy的前提—?STRONG>针对接口~程Q,针对普通的cȝAOPQSpring采用了字节码增强来实现?BR>



carob 2005-03-04 10:37 发表评论
]]>
通过Java Reflection 获取指定static变量的?/title><link>http://www.aygfsteel.com/carob/archive/2005/03/04/1675.html</link><dc:creator>carob</dc:creator><author>carob</author><pubDate>Fri, 04 Mar 2005 01:28:00 GMT</pubDate><guid>http://www.aygfsteel.com/carob/archive/2005/03/04/1675.html</guid><wfw:comment>http://www.aygfsteel.com/carob/comments/1675.html</wfw:comment><comments>http://www.aygfsteel.com/carob/archive/2005/03/04/1675.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/carob/comments/commentRss/1675.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/carob/services/trackbacks/1675.html</trackback:ping><description><![CDATA[比如Q有一个SQLUtilc,是一个Hibernate目中的用来存储一pdsql的类Q皆为常量。在其它的类中可以根据变量的名称来烦引相应的|问题在于名称在另外的cM亦ؓ变量Q直接烦引是没有办法的,但可以透过Java Reflection非常方便的实现。给出的是示意性代码,相应的Exception处理昄不够 <STRONG>elegant</STRONG><BR> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG id=Codehighlighter1_0_153_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_153_Open_Text.style.display='none'; Codehighlighter1_0_153_Closed_Image.style.display='inline'; Codehighlighter1_0_153_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_0_153_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_153_Closed_Text.style.display='none'; Codehighlighter1_0_153_Open_Image.style.display='inline'; Codehighlighter1_0_153_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN id=Codehighlighter1_0_153_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_0_153_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * Created on 2005-3-3<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> *<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * TODO To change the template for this generated file go to<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * Window - Preferences - Java - Code Style - Code Templates<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>package reflection;<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_176_331_Open_Image onclick="this.style.display='none'; Codehighlighter1_176_331_Open_Text.style.display='none'; Codehighlighter1_176_331_Closed_Image.style.display='inline'; Codehighlighter1_176_331_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_176_331_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_176_331_Closed_Text.style.display='none'; Codehighlighter1_176_331_Open_Image.style.display='inline'; Codehighlighter1_176_331_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_176_331_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_176_331_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000">*<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * @author ruby<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> *<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * TODO To change the template for this generated type comment go to<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * Window - Preferences - Java - Code Style - Code Templates<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_354_409_Open_Image onclick="this.style.display='none'; Codehighlighter1_354_409_Open_Text.style.display='none'; Codehighlighter1_354_409_Closed_Image.style.display='inline'; Codehighlighter1_354_409_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_354_409_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_354_409_Closed_Text.style.display='none'; Codehighlighter1_354_409_Open_Image.style.display='inline'; Codehighlighter1_354_409_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000"> SQLUtil </SPAN><SPAN id=Codehighlighter1_354_409_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_354_409_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> final String SELECT_SQL</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">from Ruby</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV><BR> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG id=Codehighlighter1_0_153_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_153_Open_Text.style.display='none'; Codehighlighter1_0_153_Closed_Image.style.display='inline'; Codehighlighter1_0_153_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_0_153_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_153_Closed_Text.style.display='none'; Codehighlighter1_0_153_Open_Image.style.display='inline'; Codehighlighter1_0_153_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN id=Codehighlighter1_0_153_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_0_153_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * Created on 2005-3-3<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> *<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * TODO To change the template for this generated file go to<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * Window - Preferences - Java - Code Style - Code Templates<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>package reflection;<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>import java.lang.reflect.Field;<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_209_365_Open_Image onclick="this.style.display='none'; Codehighlighter1_209_365_Open_Text.style.display='none'; Codehighlighter1_209_365_Closed_Image.style.display='inline'; Codehighlighter1_209_365_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_209_365_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_209_365_Closed_Text.style.display='none'; Codehighlighter1_209_365_Open_Image.style.display='inline'; Codehighlighter1_209_365_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_209_365_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_209_365_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000">*<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * @author ruby<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * <BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * TODO To change the template for this generated type comment go to Window -<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top> * Preferences - Java - Code Style - Code Templates<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_388_821_Open_Image onclick="this.style.display='none'; Codehighlighter1_388_821_Open_Text.style.display='none'; Codehighlighter1_388_821_Closed_Image.style.display='inline'; Codehighlighter1_388_821_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_388_821_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_388_821_Closed_Text.style.display='none'; Codehighlighter1_388_821_Open_Image.style.display='inline'; Codehighlighter1_388_821_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000"> Manager </SPAN><SPAN id=Codehighlighter1_388_821_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_388_821_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> String getValue(String sqlName) throws SecurityException,<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>            NoSuchFieldException, IllegalArgumentException,<BR><IMG id=Codehighlighter1_541_624_Open_Image onclick="this.style.display='none'; Codehighlighter1_541_624_Open_Text.style.display='none'; Codehighlighter1_541_624_Closed_Image.style.display='inline'; Codehighlighter1_541_624_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_541_624_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_541_624_Closed_Text.style.display='none'; Codehighlighter1_541_624_Open_Image.style.display='inline'; Codehighlighter1_541_624_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>            IllegalAccessException </SPAN><SPAN id=Codehighlighter1_541_624_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_541_624_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        Field f </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> SQLUtil.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">.getField(sqlName);<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> f.</SPAN><SPAN style="COLOR: #0000ff">get</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">).toString();<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> main(String[] args) throws SecurityException,<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>            NoSuchFieldException, IllegalArgumentException,<BR><IMG id=Codehighlighter1_770_819_Open_Image onclick="this.style.display='none'; Codehighlighter1_770_819_Open_Text.style.display='none'; Codehighlighter1_770_819_Closed_Image.style.display='inline'; Codehighlighter1_770_819_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_770_819_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_770_819_Closed_Text.style.display='none'; Codehighlighter1_770_819_Open_Image.style.display='inline'; Codehighlighter1_770_819_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>            IllegalAccessException </SPAN><SPAN id=Codehighlighter1_770_819_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.aygfsteel.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_770_819_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align=top>        System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(getValue(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">SELECT_SQL</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV><img src ="http://www.aygfsteel.com/carob/aggbug/1675.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/carob/" target="_blank">carob</a> 2005-03-04 09:28 <a href="http://www.aygfsteel.com/carob/archive/2005/03/04/1675.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>搬到新家来:)http://www.aygfsteel.com/carob/archive/2005/02/28/1562.htmlcarobcarobMon, 28 Feb 2005 12:10:00 GMThttp://www.aygfsteel.com/carob/archive/2005/02/28/1562.htmlhttp://www.aygfsteel.com/carob/comments/1562.htmlhttp://www.aygfsteel.com/carob/archive/2005/02/28/1562.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/1562.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/1562.html?BR>“博客园”还应做得再专业一Ҏ行,注册的时候,按着提示赎ͼ竟然D是错误的Q注册到其它地方M?img src ="http://www.aygfsteel.com/carob/aggbug/1562.html" width = "1" height = "1" />

carob 2005-02-28 20:10 发表评论
]]>
Groovlets http://www.aygfsteel.com/carob/archive/2005/02/28/1564.htmlcarobcarobMon, 28 Feb 2005 03:18:00 GMThttp://www.aygfsteel.com/carob/archive/2005/02/28/1564.htmlhttp://www.aygfsteel.com/carob/comments/1564.htmlhttp://www.aygfsteel.com/carob/archive/2005/02/28/1564.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/1564.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/1564.html你能在Groovy里面写普通的Java Servlet?BR>存在一?STRONG>GroovyServletQ自动编?groovy文gQ{变成字节码,装蝲c,q缓存它们,直到修改了源文g?BR>q儿有一个简单的例子来向你说明这事:
(注意讉Ksession,output,request的隐式变量的用法)

import java.util.Date

if (session.counter == null{
  session.counter 
= 1
}


println 
"""
<html>
    
<head>
        
<title>Groovy Servlet</title>
    
</head>
    
<body>
Hello, $
{request.remoteHost}: ${session.counter}! ${new Date()}
    
</body>
</html>
"""
session.counter = session.counter + 1
或者,用MarkupBuilder完成相同的功?BR>
import java.util.Date
import groovy.xml.MarkupBuilder

if (session.counter == null{
      session.counter 
= 1
}


html.html 
{    // html is implicitly bound to new MarkupBuilder(out)
  head {
      title(
"Groovy Servlet")
  }

  body 
{
    p(
"Hello, ${request.remoteHost}: ${session.counter}! ${new Date()}")
  }

}

session.counter 
= session.counter + 1

隐式变量

o_implicit variables.jpg

* q些变量在groovylet里面不能被再ơ赋倹{他们在W一ơ访问时被绑定,允许诸如在用"out"之前调用对象"response"的方法?BR>
建立Groovylet

下面放入web.xml?BR>
<servlet>
<servlet-name>Groovy</servlet-name>
<servlet-class>groovy.servlet.GroovyServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Groovy</servlet-name>
<url-pattern>*.groovy</url-pattern>
</servlet-mapping>

然后Q所有groovy jar文g攑ֈWEB/lib目录?只需攑օgroovy.jar和asm.jar卛_)

?groovy文g攑օ根目?放html文g的地?中,groovy servlet会照管q些.groovy文g

p个例子用tomcat来说Q要~辑tomcat/conf/server.xml Q类g下面q样

<Context path="/groovy" docBase="c:/groovy-servlet"/>




carob 2005-02-28 11:18 发表评论
]]>
GSQLhttp://www.aygfsteel.com/carob/archive/2005/02/28/1565.htmlcarobcarobMon, 28 Feb 2005 02:26:00 GMThttp://www.aygfsteel.com/carob/archive/2005/02/28/1565.htmlhttp://www.aygfsteel.com/carob/comments/1565.htmlhttp://www.aygfsteel.com/carob/archive/2005/02/28/1565.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/1565.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/1565.html举例Q?BR>
/**
 * Test to verify valid construction of default DDL
 * 
 * @author <a href="mailto:jeremy.rayner@bigfoot.com">Jeremy Rayner</a>
 * @version $Revision: 1.2 $
 
*/

package org.javanicus.gsql

import java.io.
*

class SqlGeneratorTest extends GroovyTestCase {
    property database
    property sqlGenerator
              
    
void setUp() {
        typeMap 
= new TypeMap()          
        build 
= new RelationalBuilder(typeMap)
        sqlGenerator 
= new SqlGenerator(typeMap,System.getProperty( "line.separator""\n" ))
                  
        database 
= build.database(name:'genealogy'{
          table(name:
'event'{
              column(name:
'event_id', type:'integer', size:10, primaryKey:true, required:true)
              column(name:
'description', type:'varchar', size:30)          
          }

          table(name:
'individual'{
            column(name:
'individual_id', type:'integer', size:10, required:true, primaryKey:true, autoIncrement:true)
            column(name:
'surname', type:'varchar', size:15, required:true)
            column(name:
'event_id', type:'integer', size:10)
            foreignKey(foreignTable:
'event'{
                reference(local:
'event_id',foreign:'event_id')
            }

            index(name:
'surname_index'{
                indexColumn(name:
'surname')
            }

          }

        }

    }

    
    
void testGenerateDDL() {
        testWriter 
= new PrintWriter(new FileOutputStream("SqlGeneratorTest.sql"))
        sqlGenerator.writer 
= testWriter
        sqlGenerator.createDatabase(database,
true)
        testWriter.flush()
   }


}


carob 2005-02-28 10:26 发表评论
]]>
վ֩ģ壺 ԭƽ| | | ̨| | | ҵ| | ͭ| | | | ˮ| ƽ| ٹ| ٲ| | ϻ| Դ| | | | | | | | | ̩| üɽ| | | | Ͳ| ɽ| | | | ƽ| | ϵ| |