精品国产一区二区三区性色av,激情久久av,国产免费av高清在线http://www.aygfsteel.com/luoqx/category/3050.htmlzh-cnThu, 01 Mar 2007 02:44:24 GMTThu, 01 Mar 2007 02:44:24 GMT60關(guān)于使用utf8編碼實(shí)現(xiàn)全球化的幾點(diǎn)困惑(請(qǐng)大家?guī)兔ο胂朕k法)http://www.aygfsteel.com/luoqx/articles/35704.htmlpublisher luopublisher luoThu, 16 Mar 2006 11:44:00 GMThttp://www.aygfsteel.com/luoqx/articles/35704.htmlhttp://www.aygfsteel.com/luoqx/comments/35704.htmlhttp://www.aygfsteel.com/luoqx/articles/35704.html#Feedback0http://www.aygfsteel.com/luoqx/comments/commentRss/35704.htmlhttp://www.aygfsteel.com/luoqx/services/trackbacks/35704.html某日一時(shí)興起將我們的內(nèi)容管理發(fā)布系統(tǒng)改成uft-8格式(即將所有頁(yè)面encode變?yōu)閡tf8,mysql字符集也變成uft-8)來(lái)支持能夠建立各種語(yǔ)言的網(wǎng)站(產(chǎn)品現(xiàn)在可以免費(fèi)下載,網(wǎng)址為:http://sourceforge.net/projects/nodepublisher)。但是在修改程序過(guò)程中發(fā)現(xiàn)了一個(gè)問(wèn)題,那就是在客戶端頁(yè)面提交過(guò)來(lái)的請(qǐng)求的編碼格式在服務(wù)器端無(wú)法獲知。如果提交頁(yè)面的<head>里面如果包含<meta http-equiv="Content-Type" content="text/html; charset=utf-8">,漢字部分則以u(píng)tf8編碼提交,如果沒(méi)有的話則以gbk編碼提交,而服務(wù)器端接受到的request無(wú)法判別編碼格式,取到的頭信息只有一些zh類似的說(shuō)明,所以無(wú)法正確的將其轉(zhuǎn)換成正確的編碼格式。
另一需要注意的是不能將取到的參數(shù)從ISO8859轉(zhuǎn)換成中文系統(tǒng)默認(rèn)的字符集GBK,然后再轉(zhuǎn)換成utf8,這樣的話如果出現(xiàn)奇數(shù)漢字的話會(huì)導(dǎo)致部分漢字亂碼,原因在于漢字在GBK編碼中為2個(gè)byte,而在utf8編碼則為3個(gè)byte,如果是偶數(shù)個(gè)漢字,從ISO8859(tomcat默認(rèn)得到的request都是ISO8859編碼)轉(zhuǎn)換成GBK,然后再轉(zhuǎn)換成ISO8859到還無(wú)妨,但是奇數(shù)個(gè),最后一個(gè)byte不知道會(huì)怎么轉(zhuǎn)換成GBK的,然后再轉(zhuǎn)回到utf8時(shí)最后那個(gè)字符就會(huì)成為亂碼,我想可能是跟String類里面的拆分char的方法有關(guān),不知道誰(shuí)有更加明確的分析和解釋。
再一數(shù)據(jù)庫(kù)方面使用mysql5,設(shè)置成utf8初始化數(shù)據(jù)腳本漢字轉(zhuǎn)換成uft8,一切正常。后來(lái)無(wú)意將數(shù)據(jù)庫(kù)轉(zhuǎn)換成GBK編碼,竟然程序運(yùn)行也正常,后來(lái)經(jīng)過(guò)測(cè)試將mysql設(shè)置成gbk,然后執(zhí)行初始化sql腳本,漢字編碼格式為GBK,程序運(yùn)行依然正常。不明白其中的原由。



]]>
spring本地事務(wù)與JTA事務(wù)實(shí)現(xiàn)解析http://www.aygfsteel.com/luoqx/articles/16451.htmlpublisher luopublisher luoSat, 22 Oct 2005 14:57:00 GMThttp://www.aygfsteel.com/luoqx/articles/16451.htmlhttp://www.aygfsteel.com/luoqx/comments/16451.htmlhttp://www.aygfsteel.com/luoqx/articles/16451.html#Feedback2http://www.aygfsteel.com/luoqx/comments/commentRss/16451.htmlhttp://www.aygfsteel.com/luoqx/services/trackbacks/16451.html      大家都知道spring支持兩種事務(wù),一種是本地連接事務(wù)(使用DataSourceTransactionManager),一種是JTA事務(wù)(使用JtaTransactionManager)。并且支持聲明式事務(wù)和編程式事務(wù)兩種方式。采用聲明式事務(wù)使用AOP方式的TransactionProxyFactoryBean代理工廠類。
      JTA事務(wù)實(shí)現(xiàn)相對(duì)較好理解,在執(zhí)行實(shí)際類的符合模式的方法時(shí),代理類通過(guò)在連接點(diǎn)前后插入預(yù)處理過(guò)程(開(kāi)始事務(wù))和后處理過(guò)程(commit或rollbak)即可。因?yàn)镴TA事務(wù)支持兩階段提交所以在代碼中啟動(dòng)多少個(gè)連接(不同的connection)都能保證事務(wù)最終提交或者回滾。可是本地連接事務(wù)是如何實(shí)現(xiàn)的呢?因?yàn)楸仨毢竺娴膁ao層必須使用的同一個(gè)連接才能保證事務(wù)正常提交和回滾,在業(yè)務(wù)邏輯層可以調(diào)用dao層的多個(gè)類的多個(gè)方法,每個(gè)方法如果顯式的將connection做為參數(shù)傳入到還可以,但是這樣connection就要出現(xiàn)調(diào)用的在業(yè)務(wù)邏輯層,而且dao的每個(gè)方法還要有個(gè)connection參數(shù)比較難看,而且開(kāi)發(fā)人員要關(guān)注事務(wù),這樣就沒(méi)有達(dá)到開(kāi)發(fā)人員只要關(guān)注業(yè)務(wù)邏輯即可的要求。 
      web應(yīng)用,各個(gè)類都要在多線程環(huán)境下運(yùn)行,所以每個(gè)方法要保證線程安全,這樣,不在dao方法中加參數(shù)而是在dao類中加入connection屬性也就不可取了,怎么辦?查看一下JdbcTemplate類,在執(zhí)行每個(gè)方法需要數(shù)據(jù)庫(kù)連接時(shí)都使用了DataSourceUtils.getConnection(getDataSource())方法?難道每回都從數(shù)據(jù)源里面取一條連接?不可能,這樣事務(wù)肯定沒(méi)法實(shí)現(xiàn),可是怎么能保證取的是一條連接呢?對(duì)了是不是采用本地線程呀(TreadLocal),因?yàn)橐欢问聞?wù)都是在一個(gè)線程中完成,所以只要在事務(wù)開(kāi)始的時(shí)候?qū)onnection存放在本地線程中,然后事務(wù)過(guò)程中從本地線程中取出connection,直到事務(wù)結(jié)束即可。不錯(cuò),這樣只需要在每個(gè)dao方法的取數(shù)據(jù)庫(kù)連接的方法中有個(gè)事務(wù)狀態(tài)的判斷即可。不錯(cuò)看看spring是不是這樣實(shí)現(xiàn)的?果然如此,DataSourceUtils.getConnection(DataSource)方法調(diào)用doGetConnection()方法,方法內(nèi)容如下:
public static Connection doGetConnection(DataSource dataSource) throws SQLException {
  Assert.notNull(dataSource, "No DataSource specified");

  ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
  if (conHolder != null) {
   conHolder.requested();
   return conHolder.getConnection();
  }

  logger.debug("Fetching JDBC Connection from DataSource");
  Connection con = dataSource.getConnection();

  if (TransactionSynchronizationManager.isSynchronizationActive()) {
   logger.debug("Registering transaction synchronization for JDBC Connection");
   // Use same Connection for further JDBC actions within the transaction.
   // Thread-bound object will get removed by synchronization at transaction completion.
   conHolder = new ConnectionHolder(con);
   conHolder.setSynchronizedWithTransaction(true);
   conHolder.requested();
   TransactionSynchronizationManager.registerSynchronization(
     new ConnectionSynchronization(conHolder, dataSource));
   TransactionSynchronizationManager.bindResource(dataSource, conHolder);
  }

  return con;
 }
conHolder?TransactionSynchronizationManager?很象呀,繼續(xù)看看TransactionSynchronizationManager類果真如此,里面使用TreadLocal來(lái)保存數(shù)據(jù)連接和事務(wù)狀態(tài)。原來(lái)如此,代碼里的各個(gè)層沒(méi)有特殊需要都不用再出現(xiàn)事務(wù)了,程序開(kāi)發(fā)人員只要關(guān)注業(yè)務(wù)就可以了,不用再勞心編寫(xiě)事務(wù)代碼了。



]]>
Spring遠(yuǎn)程數(shù)據(jù)源JTA事務(wù)連接配置http://www.aygfsteel.com/luoqx/articles/16447.htmlpublisher luopublisher luoSat, 22 Oct 2005 14:09:00 GMThttp://www.aygfsteel.com/luoqx/articles/16447.htmlhttp://www.aygfsteel.com/luoqx/comments/16447.htmlhttp://www.aygfsteel.com/luoqx/articles/16447.html#Feedback0http://www.aygfsteel.com/luoqx/comments/commentRss/16447.htmlhttp://www.aygfsteel.com/luoqx/services/trackbacks/16447.html        因?yàn)檎麄€(gè)項(xiàng)目組使用統(tǒng)一的配置管理,spring的applicationContext.xml大家都相同,每天還要做每日構(gòu)建,部署到服務(wù)器上也與配置管理上的文件相同,所以想是否可以將數(shù)據(jù)源和JTAmanager配置成遠(yuǎn)程的。
       查找spring官方文檔,太簡(jiǎn)單沒(méi)有這方面描述,上網(wǎng)google了半天,沒(méi)找到(奇怪?其實(shí)后來(lái)想想也不奇怪,大家要么使用本地?cái)?shù)據(jù)源(開(kāi)發(fā)調(diào)試),要么使用應(yīng)用服務(wù)的數(shù)據(jù)源也是在同一應(yīng)用服務(wù)器上,而不是在遠(yuǎn)程使用(部署的生產(chǎn)環(huán)境)。),所以干脆看看源碼算了。
       已知如下配置可以訪問(wèn)到同一應(yīng)用服務(wù)器的jndi數(shù)據(jù)源
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>jdbc/cqccms</value>
    </property>
 </bean>
        記得當(dāng)初使用jndi時(shí)可以遠(yuǎn)程訪問(wèn)寫(xiě)過(guò)client程序,主要除了要知道jndi名,還要設(shè)置jndi環(huán)境(Environment),所以查找一下JndiObjectFactoryBean的源代碼,看看有沒(méi)有設(shè)置jndi環(huán)境的方法,果然有setJndiEnvironment方法參數(shù)為properties,可以了,如下配置就能訪問(wèn)遠(yuǎn)程數(shù)據(jù)源了
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
 <property name="jndiName">
  <value>jdbc/cqccms</value>
 </property>
 <property name="jndiEnvironment">
     <props>
        <prop key="java.naming.factory.initial">
          weblogic.jndi.WLInitialContextFactory
        </prop>
        <prop key="java.naming.provider.url">t3://172.16.101.42:7001</prop>
        <prop key="java.naming.security.principal">weblogic</prop>
        <prop key="java.naming.security.credentials">weblogic</prop>
     </props>   
   </property> 
  </bean>
      不過(guò)要記得把weblogic.jar放到自己應(yīng)用的lib下,要不找不到weblogic.jndi.WLInitialContextFactory類。
      數(shù)據(jù)源搞定了,測(cè)試一下果真好用,不過(guò)jta對(duì)象遠(yuǎn)程訪問(wèn)好像沒(méi)那么順利,同理查看org.springframework.transaction.jta.JtaTransactionManager類,沒(méi)有發(fā)現(xiàn)上述方法,不過(guò)看到了setJndiTemplate()方法,也不錯(cuò)現(xiàn)配置一個(gè)jndiTemplate,如下:
 <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate" singleton="true"
  lazy-init="default" autowire="default" dependency-check="default">
  <property name="environment">
     <props>
        <prop key="java.naming.factory.initial">
          weblogic.jndi.WLInitialContextFactory
        </prop>
        <prop key="java.naming.provider.url">t3://172.16.101.42:7001</prop>
        <prop key="java.naming.security.principal">weblogic</prop>
        <prop key="java.naming.security.credentials">weblogic</prop>
     </props>   
   </property> 
 </bean>
      然后在配置一下transactionManager,如下
 <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" singleton="true"
  lazy-init="default" autowire="default" dependency-check="default">
  <property name="jndiTemplate">
   <ref local="jndiTemplate" />
  </property>
  <property name="userTransactionName">
   <value>weblogic/transaction/UserTransaction</value>
  </property>
 </bean>
      不過(guò)JtaTransactionManager默認(rèn)找jndi name為UserTransaction的jta對(duì)象,在同一應(yīng)用服務(wù)器上可以,遠(yuǎn)程訪問(wèn)不到,后直接查看weblogic的jndi樹(shù)找到這個(gè)jndi名weblogic/transaction/UserTransaction,配置上測(cè)試果然成功。

]]>
一個(gè)簡(jiǎn)單"決策樹(shù)"的實(shí)現(xiàn)http://www.aygfsteel.com/luoqx/articles/11780.htmlpublisher luopublisher luoThu, 01 Sep 2005 11:55:00 GMThttp://www.aygfsteel.com/luoqx/articles/11780.htmlhttp://www.aygfsteel.com/luoqx/comments/11780.htmlhttp://www.aygfsteel.com/luoqx/articles/11780.html#Feedback0http://www.aygfsteel.com/luoqx/comments/commentRss/11780.htmlhttp://www.aygfsteel.com/luoqx/services/trackbacks/11780.html


?? 客戶的權(quán)限要求采集回來(lái)了,天哪,根本不是什么權(quán)限的設(shè)置和判斷了,原有內(nèi)容管理中的權(quán)限管理(RBAC Role based Access Control 基于角色的訪問(wèn)控制)根本不能解決問(wèn)題.?經(jīng)過(guò)仔細(xì)分析,所有要求具為領(lǐng)導(dǎo)拍腦袋定下來(lái)的不符合邏輯的一些邏輯。如何解決?隨即想到了采用專家系統(tǒng)來(lái)解決這個(gè)問(wèn)題。找到開(kāi)源的rete算法java實(shí)現(xiàn)包Drools(http://www.theserverside.com/articles/content/Drools/article.html), 并察看了專家系統(tǒng)的部分書(shū)籍。但是項(xiàng)目時(shí)間緊迫所以放棄了,主要是其規(guī)則存放于xml中,沒(méi)想出好的辦法與本工程良好的配合起來(lái)。所以還是決定先采用簡(jiǎn)單 的決策樹(shù)(本系統(tǒng)中正好有樹(shù)狀結(jié)構(gòu)的內(nèi)容管理系統(tǒng),很容易擴(kuò)展)解決問(wèn)題。在每個(gè)樹(shù)狀決策節(jié)點(diǎn)可以加入條件和行為,如何解析?成了一個(gè)問(wèn)題。再 google一下,找找開(kāi)源的腳本解析,哦不錯(cuò)有java腳本的解析器( BeanShell---Java應(yīng)用程序腳本引摯 )可以直接解析java語(yǔ)句,功能比較強(qiáng)大,包也不大。不得不佩服現(xiàn)在的開(kāi)源真是如火如荼,還是早早的加入進(jìn)去吧。

主要測(cè)試代碼:
//創(chuàng)建一個(gè)bsh解釋器實(shí)例
??Interpreter bsh = new Interpreter();
//測(cè)試執(zhí)行一個(gè)接口實(shí)現(xiàn)的類
String program = "public Object excute(int aa,String bb){return \"Cool\";}";
program ="Command command= new Command(){"+program+"};";
program += "Object obj=command.excute(aa,bb);";
bsh.eval(program);
//測(cè)試執(zhí)行一個(gè)函數(shù)
String program = "Object excute(int aa,String bb){return \"bb+aa\";}";
program += "Object obj=excute(aa,bb);";String program = "Object excute(int aa,String bb){return \"bb+aa\";}";
program += "Object obj=excute(aa,bb);";
bsh.eval(program);
??
??bsh.eval(program);



]]>
xalan包的版本問(wèn)題http://www.aygfsteel.com/luoqx/articles/11779.htmlpublisher luopublisher luoThu, 01 Sep 2005 11:49:00 GMThttp://www.aygfsteel.com/luoqx/articles/11779.htmlhttp://www.aygfsteel.com/luoqx/comments/11779.htmlhttp://www.aygfsteel.com/luoqx/articles/11779.html#Feedback0http://www.aygfsteel.com/luoqx/comments/commentRss/11779.htmlhttp://www.aygfsteel.com/luoqx/services/trackbacks/11779.html


    一直好用的程序竟然不好用了,出現(xiàn)下列異常:

org.apache.xml.utils.WrappedRuntimeException: The output format must have a '{http://xml.apache.org/xalan}content-handler' property!

  終于找到原因,tomcat5 中自帶了xalan包,并且包的版本提升了,所以程序不好用了。詳細(xì)原因沒(méi)有查清。



]]>
哪里有好的樹(shù)狀結(jié)構(gòu)的容器?沒(méi)辦法自己寫(xiě)一個(gè)吧http://www.aygfsteel.com/luoqx/articles/11288.htmlpublisher luopublisher luoSat, 27 Aug 2005 03:18:00 GMThttp://www.aygfsteel.com/luoqx/articles/11288.htmlhttp://www.aygfsteel.com/luoqx/comments/11288.htmlhttp://www.aygfsteel.com/luoqx/articles/11288.html#Feedback0http://www.aygfsteel.com/luoqx/comments/commentRss/11288.htmlhttp://www.aygfsteel.com/luoqx/services/trackbacks/11288.html


到處找樹(shù)狀結(jié)構(gòu)的容器都沒(méi)找到,TreeMap和TreeSet是什么紅-黑樹(shù)沒(méi)看明白,沒(méi)時(shí)間仔細(xì)研究了,干脆簡(jiǎn)單寫(xiě)一個(gè)吧,反正并發(fā)要求不是很高,也不怎么排序,就是內(nèi)存緩存用。代碼如下:

/**
 * 樹(shù)操作類,定義樹(shù)型數(shù)據(jù)結(jié)構(gòu)的常用操作,其中包括定位樹(shù)結(jié)點(diǎn),插入樹(shù)結(jié)點(diǎn) 刪除樹(shù)結(jié)點(diǎn),修改樹(shù)結(jié)點(diǎn)等。 注意:樹(shù)根節(jié)點(diǎn)的標(biāo)志從0開(kāi)始
 */
public class DataTree implements Serializable {

 private DataTreeNode rootDataTreeNode = null; //定義樹(shù)根
 private Hashtable nodeList = new Hashtable();

 /**
  * 設(shè)置根節(jié)點(diǎn)
  * @param nodeID 節(jié)點(diǎn)nodeid
  * @param node   節(jié)點(diǎn)數(shù)據(jù)對(duì)象
  */
 private void setRoot(String nodeID, Object node) {

  DataTreeNode treeNode = new DataTreeNode();
  treeNode.setLevel(0);
  treeNode.setNode(node);
  treeNode.setNodeID(nodeID);
  treeNode.setUpNodeID("0");
  this.rootDataTreeNode = treeNode;
  nodeList.put(nodeID, treeNode);
 }

 /**
  * 設(shè)置根節(jié)點(diǎn)
  * @param node Object,節(jié)點(diǎn)包含數(shù)據(jù)對(duì)象
  */
 public void setRoot(Object node) {
  String nodeID = DataAccess.getCode();
  setRoot(node);
 }
 /**
  * 取得根節(jié)點(diǎn)
  * @return 樹(shù)型節(jié)點(diǎn)
  */
 public DataTreeNode getRoot(){
  return rootDataTreeNode;
 }
 /**
  * 取得節(jié)點(diǎn)數(shù)據(jù)對(duì)象
  * @return 數(shù)據(jù)對(duì)象
  */
 public Object getRootNode(){
  return rootDataTreeNode.getNode() ;
 }
 
 /**
  * 給一個(gè)節(jié)點(diǎn)添加子節(jié)點(diǎn)
  * @param supNode 父節(jié)點(diǎn)
  * @param node 數(shù)據(jù)對(duì)象
  * @return 封裝過(guò)的樹(shù)型節(jié)點(diǎn)
  */
 public DataTreeNode addSubNode(DataTreeNode supNode,Object node){
  DataTreeNode newTreeNode =  supNode.addSubNode(node);
  this.nodeList.put( newTreeNode.getNodeID() ,newTreeNode);
  return newTreeNode;
 }
 /**
  * 刪除一個(gè)子節(jié)點(diǎn)
  * @param supNode 父節(jié)點(diǎn)
  * @param subNode 子節(jié)點(diǎn)
  * @return 成功,失敗
  */
 public boolean removeSubNode(DataTreeNode supNode,DataTreeNode subNode){
  if(supNode.removeSubNode( subNode)){
   this.nodeList.remove( subNode.getNodeID() );
   return true;
  }else{
   return false;
  }
 }
 /**
  * 刪除一個(gè)子節(jié)點(diǎn)
  * @param supNode 父節(jié)點(diǎn)
  * @param orderid 序號(hào),從0開(kāi)始
  * @return 成功,失敗
  */
 public boolean removeSubNode(DataTreeNode supNode,int orderid){
  DataTreeNode subNode = supNode.getSubNode( orderid);
  if(supNode.removeSubNode( orderid)){
   this.nodeList.remove( subNode.getNodeID() );
   return true;
  }else{
   return false;
  }
 }
 
 public static DataTree creatDataTree(ArrayList nodeList,
   String upNodeIDName,
   String nodeIDName,
   Object root){
  
  String getNodeIDMethodName = "get"+nodeIDName;
  String getUpNodeIDMethodName = "get"+upNodeIDName;
  String rootNodeid = getValue(root ,getNodeIDMethodName);
  String nodeid = "";
  String upnodeid = "";
  
  
  
  Object[][] nodes = new Object[nodeList.size()][3];

  int count =0;
  //將arraylist數(shù)據(jù)存儲(chǔ)到兩個(gè)Hashtable中
  for(int i=0;i<nodeList.size();i++){
   Object obj = nodeList.get(i);
   if (obj != null){
    nodeid = new String(getValue(obj,getNodeIDMethodName));
    if (nodeid != null ){
     upnodeid = new String(getValue(obj ,getUpNodeIDMethodName));
     if (upnodeid != null){
      nodes[count][0] = nodeid;
      nodes[count][1] = upnodeid;
      nodes[count][2] = nodeList.get(i);
      count ++;
     }
    }
   }
  }  
  DataTree dataTree = new DataTree();
  dataTree.setRoot( rootNodeid,root);
  findChildNodeAndAdd(dataTree.getRoot(),nodes);
  return dataTree;
 }
 
 private static void findChildNodeAndAdd(DataTreeNode treeNode,Object[][] nodes){
  String nodeid = treeNode.getNodeID() ;
  for (int i=0;i<nodes.length ;i++){
   if (nodeid.equals(nodes[i][1])){
    DataTreeNode childTreeNode = treeNode.addSubNode( (String)nodes[i][0],nodes[i][2]);
    findChildNodeAndAdd(childTreeNode,nodes);
   }
  }  
 }
 
 private static String getValue(Object obj, String functionName){
  return (String)ObjectTool.invokeMethod(obj,null,null,functionName);
 }
 /**
  * 樹(shù)型數(shù)據(jù)結(jié)構(gòu)定義類。定義樹(shù)型數(shù)據(jù)結(jié)構(gòu)的基本單元--樹(shù)型節(jié)點(diǎn)的結(jié)構(gòu)。
  * 
  */
 public class DataTreeNode  {

  private String upNodeID; //父節(jié)點(diǎn)ID

  private String nodeID; //屬性節(jié)點(diǎn)標(biāo)志ID

  private int level; //層號(hào)

  private Object node; //存儲(chǔ)用數(shù)據(jù)對(duì)象

  private ArrayList subNodes; //所有子節(jié)點(diǎn)

  /**
   * 空構(gòu)造
   * 
   */
  private DataTreeNode() {
   subNodes = new ArrayList();
  }

  /**
   * @return Returns the level.
   */
  public int getLevel() {
   return level;
  }

  /**
   * @param level
   *            The level to set.
   */
  private void setLevel(int level) {
   this.level = level;
  }

  /**
   * @return Returns the node.
   */
  public Object getNode() {
   return node;
  }

  /**
   * @param node
   *            The node to set.
   */
  private void setNode(Object node) {
   this.node = node;
  }

  /**
   * @return Returns the nodeID.
   */
  public String getNodeID() {
   return nodeID;
  }

  /**
   * @param nodeID
   *            The nodeID to set.
   */
  private void setNodeID(String nodeID) {
   this.nodeID = nodeID;
  }

  /**
   * @return Returns the orderid.
   */
  public int getSubNodeOrderid(DataTreeNode treeNode) {
   for (int i = 0; i < subNodes.size(); i++) {
    if (this.getSubNode(i).equals(treeNode)) {
     return i;
    }
   }
   return -1;
  }

  /**
   * @return Returns the subNode.
   */
  public ArrayList getSubNodes() {
   return (ArrayList) subNodes.clone();
  }

  /**
   * @param subNode
   *            The subNode to set.
   */
  private void setSubNodes(ArrayList subNodes) {
   this.subNodes = subNodes;
  }

  /**
   * @return Returns the subNodeNo.
   */
  private int getSubNodeNo() {
   return this.subNodes.size();
  }

  /**
   * @return Returns the upNodeID.
   */
  public String getUpNodeID() {
   return upNodeID;
  }

  /**
   * @param upNodeID
   *            The upNodeID to set.
   */
  private void setUpNodeID(String upNodeID) {
   this.upNodeID = upNodeID;
  }

  /**
   * 增加一個(gè)子節(jié)點(diǎn)
   *
   * @param treeNode
   *            帶樹(shù)結(jié)構(gòu)的節(jié)點(diǎn)
   */
  private void addSubTreeNode(DataTreeNode treeNode) {
   this.subNodes.add(treeNode);
  }

  /**
   * 增加一個(gè)子節(jié)點(diǎn),指定nodeid
   *
   * @param nodeID
   *            指定的nodeid
   * @param node
   *            節(jié)點(diǎn)附帶數(shù)據(jù)對(duì)象
   */
  private DataTreeNode addSubNode(String nodeID, Object node) {
   DataTreeNode treeNode = new DataTreeNode();
   treeNode.setLevel(this.level + 1);
   treeNode.setNode(node);
   treeNode.setNodeID(nodeID);
   //treeNode.setOrderid( getSubNodeNo() );
   treeNode.setUpNodeID(this.nodeID);
   addSubTreeNode(treeNode);
   return treeNode;
  }

  /**
   * 增加一個(gè)子節(jié)點(diǎn),自動(dòng)分配nodeid
   *
   * @param node
   *            節(jié)點(diǎn)附帶數(shù)據(jù)對(duì)象
   */
  private DataTreeNode addSubNode(Object node) {
   String nodeID = DataAccess.getCode();
   return addSubNode(nodeID, node);
  }

  /**
   * 按序號(hào)取出節(jié)點(diǎn)
   *
   * @param orderid
   *            序號(hào)
   * @return
   */
  private DataTreeNode getSubNode(int orderid) {
   return (DataTreeNode) this.subNodes.get(orderid);
  }

  private boolean removeSubNode(int orderid) {
   try {
    subNodes.remove(orderid);
    return true;
   } catch (Exception ex) {
    return false;
   }
  }

  private boolean removeSubNode(DataTreeNode treeNode) {
   return subNodes.remove(treeNode);
  }

  /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#equals(java.lang.Object)
   */
  public boolean equals(Object treeNode) {
   if (treeNode instanceof DataTreeNode) {
    if (this.nodeID.equals(((DataTreeNode) treeNode).getNodeID())) {
     return true;
    } else {
     return false;
    }
   } else {
    return false;
   }
  }

  /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
  public String toString() {
   return this.nodeID + " " + node.toString();
  }
 }

}




]]>
why? EnterpriseBean extend Serializablehttp://www.aygfsteel.com/luoqx/articles/11287.htmlpublisher luopublisher luoSat, 27 Aug 2005 03:17:00 GMThttp://www.aygfsteel.com/luoqx/articles/11287.htmlhttp://www.aygfsteel.com/luoqx/comments/11287.htmlhttp://www.aygfsteel.com/luoqx/articles/11287.html#Feedback0http://www.aygfsteel.com/luoqx/comments/commentRss/11287.htmlhttp://www.aygfsteel.com/luoqx/services/trackbacks/11287.html

    同事問(wèn)了一個(gè)這樣的問(wèn)題,大家都知道,ejb的本地接口,遠(yuǎn)程接口還有參數(shù)都需要序列話,這是因?yàn)檫@些東西都需要分布式傳輸,可是在容器了的bean不需要分布傳輸為什么也要實(shí)現(xiàn)serializable接口呢?
    上網(wǎng)差了些資料,主要有兩種說(shuō)法,一個(gè)是app server要作cluster,交換內(nèi)存中數(shù)據(jù)(包括ejb)。二是ejbPassivate(鈍化)和ejbActivate() (活化)時(shí)需要使用序列話。第二種說(shuō)法可能性比較大。
參考資料:
 


]]>
如何從response里面取出向客戶端輸出的html流http://www.aygfsteel.com/luoqx/articles/10338.htmlpublisher luopublisher luoWed, 17 Aug 2005 06:40:00 GMThttp://www.aygfsteel.com/luoqx/articles/10338.htmlhttp://www.aygfsteel.com/luoqx/comments/10338.htmlhttp://www.aygfsteel.com/luoqx/articles/10338.html#Feedback0http://www.aygfsteel.com/luoqx/comments/commentRss/10338.htmlhttp://www.aygfsteel.com/luoqx/services/trackbacks/10338.html    但是此方法需要耗費(fèi)兩次網(wǎng)絡(luò)傳輸,肯定性能不加,而且處理起來(lái)要幾塊程序同時(shí)協(xié)作才行。還是想辦法從服務(wù)器端直接獲取。因?yàn)閺膔esponse無(wú)法直接得到輸出流,得想其他的辦法。一種是干脆在服務(wù)器端寫(xiě)一個(gè)監(jiān)控socket接口的客戶端程序,或者用httpunit幫助完成,就是把客戶端程序移到服務(wù)器端執(zhí)行。還是相對(duì)比較復(fù)雜,能不能從response入手?
   答案是肯定的,采用response代理來(lái)截獲response的幾個(gè)輸出函數(shù),然后存儲(chǔ)起來(lái),已備查詢。
靈感來(lái)自于前一陣一直研究的java動(dòng)態(tài)代理機(jī)制(現(xiàn)在應(yīng)用在spring的aop實(shí)現(xiàn)中),此處不用動(dòng)態(tài)代理,就使用靜態(tài)代理,proxy模式就足夠了。
  分別實(shí)現(xiàn)三個(gè)代理類:ServletResponseProxy,ServletOutputStreamProxy,PrintWriterProxy
Responseproxy 主要代碼:
public class ServletResponseProxy implements HttpServletResponse {
 private HttpServletResponse obj;//實(shí)際的HttpServletResponse 實(shí)例
 
 public ServletResponseProxy(HttpServletResponse obj) {
  this.obj = obj;
  HtmlBuffer.cleanStr(); //情空緩存
 }   
 
//獲得outputStreamProxy
 public ServletOutputStream getOutputStream() throws IOException {
  ServletOutputStream so = obj.getOutputStream();
  ServletOutputStreamProxy sop = new ServletOutputStreamProxy(so);
  return sop;
 }
 //獲得printWriterProxy
 public PrintWriter getWriter() throws IOException {
  PrintWriter pw = obj.getWriter();
  PrintWriterProxy pwp = new PrintWriterProxy(pw);
  return (PrintWriter) pwp;
 }
}
PrintWriterProxy:
 
public class PrintWriterProxy
    extends PrintWriter {
  private PrintWriter pw = null;
 
  public PrintWriterProxy(PrintWriter pw) {
    super(pw);
    this.pw = pw;
  }
//截獲寫(xiě)內(nèi)容寫(xiě)入buffer
  public void write(int c) {
    char a = (char) c;
    String s = new String(new char[] {a});
    HtmlBuffer.addStr(s);
    pw.write(c);
  }
}
 
ServletOutputStreamProxy:
public class ServletOutputStreamProxy
    extends ServletOutputStream {
  private ServletOutputStream obj;
  public ServletOutputStreamProxy(ServletOutputStream obj){
    this.obj = obj;
  }
//截獲寫(xiě)內(nèi)容寫(xiě)入buffer
  public void write(int b) throws IOException {
    Integer it = new Integer(b);
    HtmlBuffer.addStr(new String(new byte[]{it.byteValue()}));
    obj.write(b);
  }
}

 
    由于web Httpserver 是多線程執(zhí)行服務(wù)端程序,所以buffer應(yīng)該分線程來(lái)存取,這樣大家才能不互相干擾。所以buffer需要實(shí)現(xiàn)TreadLocal接口。
    HtmlBuffer代碼簡(jiǎn)單實(shí)現(xiàn)如下:
public class HtmlBuffer {
 private static class HtmlInfo extends ThreadLocal {
  private Map values = Collections.synchronizedMap(new HashMap());
  public Object initialValue() {
   return new String();
  }
  public String getHtmlStr() {
   return (String) this.get();
  }
  public Object get() {
   Thread curThread = Thread.currentThread();
   Object o = values.get(curThread);
   if (o == null && !values.containsKey(curThread)) {
    o = initialValue();
    values.put(curThread, o);
   }
   return o;
  }
  public void set(Object newValue) {
   values.put(Thread.currentThread(), newValue);
  }
 } 
 private static HtmlInfo htmlInfo = new HtmlInfo();
 
 public static void cleanStr(){
  htmlInfo.set( "");
 }
 public static void addStr(String htmlStr) {
  String htmlstr = (String)htmlInfo.get();
  if(htmlstr == null) htmlstr ="";
  htmlstr += htmlStr;
  htmlInfo.set( htmlstr);
 }
 public static String getStr() {
  return (String)htmlInfo.get();
 }
}


]]>
主站蜘蛛池模板: 隆昌县| 惠州市| 青铜峡市| 石狮市| 佳木斯市| 资讯 | 邯郸县| 仪征市| 彭水| 河池市| 阿克苏市| 枣阳市| 屏东县| 苏尼特左旗| 满城县| 临汾市| 涡阳县| 乌拉特前旗| 城口县| 长沙县| 彭水| 安宁市| 天门市| 翼城县| 奇台县| 许昌县| 西丰县| 崇信县| 西充县| 建瓯市| 西乌| 金坛市| 墨竹工卡县| 双峰县| 墨江| 邳州市| 西平县| 德令哈市| 陈巴尔虎旗| 竹山县| 延庆县|