如鵬網 大學生計算機學習社區

          CowNew開源團隊

          http://www.cownew.com 郵件請聯系 about521 at 163.com

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            363 隨筆 :: 2 文章 :: 808 評論 :: 0 Trackbacks

          #

          由于系統遭受惡意攻擊,CowNew開源論壇2006年12月30日至2007年1月13日的數據丟失,給各位朋友帶來的不便表示歉意。
          在此警告惡意攻擊者:你們這些用別人寫的工具攻擊別人發現的漏洞,并且在自己都不知道原理的情況下對系統進行攻擊,你們只是惡意攻擊者,是一群小孩子。靠牛開源是致力于開源技術推廣的網站,需要更多的精力投入到開源系統的開發中,沒有時間去修復動網BBS中那些漏洞。請那些有惡意攻擊企圖的小朋友們好好學習去吧,不要如此無聊。對于對CowNew開源網站進行惡意攻擊的人我只想說:日你老母!
          posted @ 2007-01-14 00:14 CowNew開源團隊 閱讀(481) | 評論 (3)編輯 收藏

          今天收到一封郵件,哈哈,我發財了!
          Mr. Richard Khoza.
          Director of Projects
          Department of Minerals & Energy
          Pretoria South Africa.

          Fax: +27- 86 516 9900
          Fax: +27- 86 516 9351


          Attention: President/CEO


          I write, asking for your indulgence in re-profiling funds to tune of Fifty
          Million, Eight Hundred Thousand United States Dollars (US$52.8M) which we
          want kept safely overseas under your supervision.

          In other words, we would like you to receive the said funds on our behalf.
          The Funds were derived over time from a project awarded to a foreign firm
          by my Department, and presently the actual contract cost have been paid to
          the original project executors, leaving the balance in the tune of the
          said amount which we have in principle obtained approval to remit
          overseas.

          Kindly pardon the use of a medium as informal as this for reaching out to
          you to make a request of great importance to us.

          Currently, I work as a Director of Projects at the Department of Minerals
          & Energy here in Pretoria South Africa. I have the authority and approval
          of my partners involved in this transaction to negotiate a suitable
          compensation for your participation and I propose 32.2 percent for you,
          while we also propose that we receive 56.6 percent and 11.2 percent are
          earmarked for purposes of taxation and other expenses.

          This endeavor has a minimal risk factor on your part provided you treat it
          with the utmost discretion. You are advised to reach me through my private
          fax for more information.

          I am available via fax to discuss further with you. I kindly wait to hear
          from you.

          Yours Sincerely,
          Mr. Richard Khoza.

          NOTE: Please dont reply to this email address for security reasons.
          Contact me via my private Fax +27 86 516 9900 or +27 86 516 9351


          __________________________________________
          DISCLAIMER:
          The information contained in this e-mail may be confidential, proprietary,
          and/or legally privileged. It is intended only for the person or entity to
          which it is addressed. If you are not the intended recipient, you are not
          allowed to distribute, copy, review, retransmit, disseminate or use this
          e-mail or any part of it in any form whatsoever for any purpose. If you
          have received this e-mail in error, please immediately notify the sender
          and delete the original message. Please be aware that the contents of this
          e-mail may not be secure and should not be seen as forming a legally
          binding contract unless otherwise stated.

          posted @ 2007-01-13 11:26 CowNew開源團隊 閱讀(708) | 評論 (0)編輯 收藏

          Rhino 中使用 Java 對象

          與網頁中所使用的 JavaScript 不同的是, Rhino 中的腳本可以使用 Java 中的對象。要在腳本中使用 Java 類必須將 Java 類引入腳本。

          使用 cx.initStandardObjects 創建出來的 Scriptable 類型實例,不支持在腳本中使用 import 語句,此時需要使用如下的代碼來創建一個 ImporterTopLevel 類的實例,它是 Scriptable 一個實現,這樣就支持在腳本中使用 importPackage 語句:

          Context cx = Context.enter();

          Scriptable iptScope = new ImporterTopLevel(cx);

          在腳本中如下引入包名:

          importPackage(Packages.javax.swing);

          如果不使用 importPackage 語句,也可以采用直接包名來使用類:

          Packages.javax.swing.JFrame frame = new JFrame(“myWindow”);

          ?

          下面的代碼演示在腳本中創建一個窗口,并在窗口上顯示一個按鈕。

          import org.mozilla.javascript.Context;

          import org.mozilla.javascript.ImporterTopLevel;

          import org.mozilla.javascript.Scriptable;

          ?

          public class JSTest3

          {

          ???? public static void main(String[] args)

          ???? {

          ???????? StringBuffer script = new StringBuffer();

          ???????? script.append("importPackage(java.awt);\n");

          ???????? script.append("frame = new Frame(\"JavaScript\");\n");

          ???????? script.append("frame.show();\n");

          ???????? script.append("frame.setSize(new Dimension(200,100));\n");

          ???????? script.append("button = new Button(\" 按鈕 \");\n");

          ???????? script.append("frame.add(button);\n");

          ???????? script.append("frame.show();\n");

          ?

          ???????? Context ctx = Context.enter();

          ???????? Scriptable scope = new ImporterTopLevel(ctx);

          ???????? try

          ???????? {

          ????????????? ctx.evaluateString(scope, script.toString(), null, 1, null);

          ???????? } finally

          ???????? {

          ????????????? Context.exit();

          ???????? }

          ???? }

          }

          運行以后就會顯示下面的窗口:

          ri1.JPG

          posted @ 2007-01-03 21:17 CowNew開源團隊 閱讀(895) | 評論 (0)編輯 收藏

          Spring 事務管理創造性的解決了很多以前要用重量級的應用服務器才能解決的事務問題,那么其實現原理一定很深奧吧?可是如果讀者仔細研究了Spring事務管理的代碼以后就會發現,事務管理其實也是如此簡單的事情。這也印證了在本書開頭的一句話“重劍無鋒、大巧不工”,Spring并沒有使用什么特殊的API,它運行的原理就是事務的原理。下面是DataSourceTransactionManager的啟動事務用的代碼(經簡化):
          protected void doBegin(Object transaction, TransactionDefinition definition)
          {
          ?DataSourceTransactionObject txObject =
          (DataSourceTransactionObject) transaction;
          ?Connection con = null;
          ?try
          ?{
          ??if (txObject.getConnectionHolder() == null)
          ??{
          ???Connection newCon = this.dataSource.getConnection();
          ???txObject.setConnectionHolder(
          new ConnectionHolder(newCon), true);
          ??}
          ??txObject.getConnectionHolder()
          .setSynchronizedWithTransaction(true);
          ??con = txObject.getConnectionHolder().getConnection();

          ??Integer previousIsolationLevel = DataSourceUtils
          ?????.prepareConnectionForTransaction(con, definition);
          ??txObject.setPreviousIsolationLevel(previousIsolationLevel);
          ??if (con.getAutoCommit())
          ??{
          ???txObject.setMustRestoreAutoCommit(true);
          ???con.setAutoCommit(false);
          ??}
          ??txObject.getConnectionHolder().setTransactionActive(true);
          ??// Bind the session holder to the thread.
          ??if (txObject.isNewConnectionHolder())
          ??{
          ???TransactionSynchronizationManager.bindResource(
          getDataSource(),txObject.getConnectionHolder());
          ??}
          ?}
          ?catch (SQLException ex)
          ?{
          ??DataSourceUtils.releaseConnection(con, this.dataSource);
          ??throw new CannotCreateTransactionException(
          ?????"Could not open JDBC Connection for transaction", ex);
          ?}
          }
          本文出自:http://www.cownew.com
          在調用一個需要事務的組件的時候,管理器首先判斷當前調用(即當前線程)有沒有一個事務,如果沒有事務則啟動一個事務,并把事務與當前線程綁定。Spring使用TransactionSynchronizationManager的bindResource方法將當前線程與一個事務綁定,采用的方式就是ThreadLocal,這可以從TransactionSynchronizationManager類的代碼看出。
          public abstract class TransactionSynchronizationManager
          {
          ?……
          ?private static final ThreadLocal currentTransactionName = new ThreadLocal();
          ?private static final ThreadLocal currentTransactionReadOnly = new ThreadLocal();
          ?private static final ThreadLocal actualTransactionActive = new ThreadLocal();?……
          }
          從doBegin的代碼中可以看到在啟動事務的時候,如果Connection是的自動提交的(也就是getAutoCommit()方法返回true)則事務管理就會失效,所以首先要調用setAutoCommit(false)方法將其改為非自動提交的。setAutoCommit(false)這個動作在有的JDBC驅動中會非常耗時,所以最好在配置數據源的時候就將“autoCommit”屬性配置為true。

          posted @ 2007-01-02 23:33 CowNew開源團隊 閱讀(3235) | 評論 (0)編輯 收藏

          書稿終于發給出版社了,隨書光盤也發給出版社了,兩個月的“閉門造書”總算有了一點結果?,F在就祈禱這本書能順利出版了。
          寫書的過程中有一些“下腳料”,扔了怪可惜,就在blog中陸續共享出來吧?!跋履_料”并不代表寫的差,大部分是因為和書的結構有偏離,所以被cut下來了。所以的下腳料文章都以“xjl:”開頭,以免得以后我發的文章也被當成下腳料了。:)

          posted @ 2007-01-02 23:31 CowNew開源團隊 閱讀(328) | 評論 (1)編輯 收藏

          procedure TMainForm.CopyFileByFolder(Ahandle: THandle; fromDir,
          ? toDir: String);
          var
          ? SHFileOpStruct: TSHFileOpStruct;
          ? pFromDir, pToDir: PAnsiChar;
          begin
          ? GetMem(pFromDir, Length(fromDir)+2);
          ? try
          ??? GetMem(pToDir, Length(toDir)+2);
          ??? try

          ????? FillChar(pFromDir^, Length(fromDir)+2, 0);
          ????? FillChar(pToDir^, Length(toDir)+2, 0);

          ????? StrCopy(pFromDir, PChar(fromDir));
          ????? StrCopy(pToDir, PChar(toDir));

          ????? with SHFileOpStruct do
          ????? begin
          ??????? Wnd??? := AHandle;?? // Assign the window handle
          ??????? wFunc? := FO_COPY;? // Specify a file copy
          ??????? pFrom? := pFromDir;
          ??????? pTo??? := pToDir;
          ??????? fFlags := FOF_NOCONFIRMATION or FOF_SILENT;
          ??????? fAnyOperationsAborted := True;
          ??????? hNameMappings := nil;
          ??????? lpszProgressTitle := nil;
          ??????? if SHFileOperation(SHFileOpStruct) <> 0 then
          ????????? RaiseLastWin32Error;
          ????? end;
          ??? finally
          ????? FreeMem(pToDir, Length(ToDir)+2);
          ??? end;
          ? finally
          ??? FreeMem(pFromDir, Length(FromDir)+2);
          ? end;
          end;

          posted @ 2006-12-31 00:18 CowNew開源團隊 閱讀(2012) | 評論 (0)編輯 收藏

          經過40多天的“閉門造書”,終于被釋放了,終于可以上網了,做個記號,以后博客又可以更新了,團隊網站又可以維護了!
          講個剛看到的故事吧:
          聯合利華引進了一條香皂包裝生產線,結果發現這條生產線有個缺陷:常常會有盒子里沒裝入香皂??偛荒馨芽蘸凶淤u給顧客啊,他們只好請了一個學自動化的博士后設計一個方案來分揀空的香皂盒。博士后拉起了一個十幾人的科研攻關小組,綜合采用了機械、微電子、自動化、X射線探測等技術,花了幾十萬,成功解決了問題。每當生產線上有空香皂盒通過,兩旁的探測器會檢測到,并且驅動一只機械手把空皂盒推走。 中國南方有個鄉鎮企業也買了同樣的生產線,老板發現這個問題后大為光火,找了個小工來說你他媽給我把這個搞定。小工果然想出了辦法:他在生產線旁邊放了臺風扇猛吹,空皂盒自然會被吹走。
          posted @ 2006-12-15 00:25 CowNew開源團隊 閱讀(371) | 評論 (1)編輯 收藏

          public class DTODataChangeInterceptor implements MethodInterceptor, Serializable
          {
          ?private static final String SET = "set";
          ?private Set changedPropSet;
          ?
          ?public DTODataChangeInterceptor()
          ?{
          ??changedPropSet = new HashSet();
          ?}

          ?public Object intercept(Object obj, Method method, Object[] args,
          ???MethodProxy proxy) throws Throwable
          ?{
          ??String name = method.getName();

          ??if (name.startsWith(SET))
          ??{
          ???String s = name.substring(SET.length() - 1);
          ???String propName = StringUtils.firstLowerCase(s);
          ???changedPropSet.add(propName);
          ??}

          ??return proxy.invokeSuper(obj, args);
          ?}
          ?
          ?public Set getChangedPropSet()
          ?{
          ??return Collections.unmodifiableSet(changedPropSet);
          ?}
          ?
          ?public void reset()
          ?{
          ??changedPropSet.clear();
          ?}
          }

          然后如下調用來初始化javaBean

          ??Enhancer enhancer = new Enhancer();
          ??enhancer.setSuperclass(destClass);
          ??enhancer.setCallback(new DTODataChangeInterceptor());
          ??
          ??IValueObject newBean = (IValueObject) enhancer.create();

          ........初始化newBean

          ??DTODataChangeInterceptor interceptor = InterceptorUtils
          //????.getDTODataChangeInterceptor(newBean);
          ??interceptor.reset();

          然后就可以將newBean傳遞給其他層進行操作,操作完畢,調用:
          ?public static DTODataChangeInterceptor getDTODataChangeInterceptor(Object obj)
          ?{
          ??if(!(obj instanceof Factory))
          ??{
          ???return null;
          ??}
          ??Factory f = (Factory)obj;
          ??Callback[] callBacks = f.getCallbacks();
          ??for(int i=0,n=callBacks.length;i<n;i++)
          ??{
          ???Callback callBack = callBacks[i];
          ???if(callBack instanceof DTODataChangeInterceptor)
          ???{
          ????return (DTODataChangeInterceptor)callBack;
          ???}
          ??}
          ??return null;
          ?}
          既可以得到哪些字段變化了。

          ?

          posted @ 2006-10-19 01:53 CowNew開源團隊 閱讀(958) | 評論 (0)編輯 收藏

          ??Button btnBrowsePackage = new Button(container, SWT.NONE);
          ??btnBrowsePackage.setText("...");
          ??btnBrowsePackage.addSelectionListener(new SelectionListenerAdapter(){
          ???public void widgetSelected(SelectionEvent e)
          ???{
          ????super.widgetSelected(e);
          ????IJavaProject javaProject = JavaCore.create(getCurrentProject());
          ????SelectionDialog dialog = null;
          ????try
          ????{
          ?????dialog = JavaUI.createPackageDialog(getSite().getShell(),
          ???????javaProject,IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
          ????} catch (JavaModelException e1)
          ????{
          ?????ExceptionHandler.handleExceptionAndAbort(e1);
          ????}
          ????if (dialog.open() != Window.OK)
          ????{
          ?????return;
          ????}
          ????IPackageFragment pck = (IPackageFragment) dialog.getResult()[0];
          ????if (pck != null)
          ????{
          ?????txtPackageName.setText(pck.getElementName());
          ????}

          ???}
          ???
          ??});?

          posted @ 2006-10-08 23:08 CowNew開源團隊 閱讀(898) | 評論 (0)編輯 收藏

          我正在寫一個小東西,用hibernate做數據層,用hessian提供的remoting做業務層,表現層通過http的方式取得業務層的服務,有的地方需要把PO傳遞到表現層(有人不同意把PO和VO重用,但是我的觀點是:大部分實體對象只要vo、po重用就可以了,只有vo、po差距較大的地方才分開,這樣就做到了簡潔性和可擴展性的良好折中)。
          但是在我將一個PO傳遞到表現層的時候出現了下面的問題:
          java.lang.InstantiationException: org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer
          ?at java.lang.Class.newInstance0(Unknown Source)
          ?at java.lang.Class.newInstance(Unknown Source)
          ?at com.caucho.hessian.io.JavaDeserializer.instantiate(JavaDeserializer.java:104)
          ?at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:54)
          ?at com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java:147)
          ?at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:781)
          ?at com.caucho.hessian.io.MapDeserializer.readMap(MapDeserializer.java:88)
          ?at com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java:149)
          ?at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:781)
          ?at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:69)
          ?at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:55)
          ?at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:658)
          ?at com.caucho.hessian.io.HessianInput.readReply(HessianInput.java:241)
          ?at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:179)
          ?at $Proxy2.loadByPK(Unknown Source)
          ?at com.cownew.PIS.demo.client.HelloTest.testDAO(HelloTest.java:85)
          ?at com.cownew.PIS.demo.client.HelloTest.main(HelloTest.java:94)
          java.lang.reflect.UndeclaredThrowableException
          ?at $Proxy2.loadByPK(Unknown Source)
          ?at com.cownew.PIS.demo.client.HelloTest.testDAO(HelloTest.java:85)
          ?at com.cownew.PIS.demo.client.HelloTest.main(HelloTest.java:94)
          Caused by: java.io.IOException: java.lang.InstantiationException: org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer
          ?at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:60)
          ?at com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java:147)
          ?at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:781)
          ?at com.caucho.hessian.io.MapDeserializer.readMap(MapDeserializer.java:88)
          ?at com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java:149)
          ?at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:781)
          ?at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:69)
          ?at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:55)
          ?at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:658)
          ?at com.caucho.hessian.io.HessianInput.readReply(HessianInput.java:241)
          ?at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:179)
          ?... 3 more

          我的這個對象是如下定義的:
          package com.cownew.PIS.demo.common;
          import com.cownew.PIS.framework.common.BaseObjectValue;

          public class MaterialInfo extends BaseObjectValue
          {??
          ?? private String Id;?????
          ?? private String Number;?????
          ?? private PersonInfo Manager;??
          ??
          ?? public void setId(String value)
          ?? {
          ???? this.Id=value;
          ?? }
          ??
          ??
          ?? public void setNumber(String value)
          ?? {
          ???? this.Number=value;
          ?? }
          ??
          ??
          ?? public void setManager(PersonInfo value)
          ?? {
          ???? this.Manager=value;
          ?? }
          ??
          ??
          ?? public String getId()
          ?? {
          ???? return Id;
          ?? }
          ??
          ??
          ?? public String getNumber()
          ?? {
          ???? return Number;
          ?? }
          ??
          ??
          ?? public PersonInfo getManager()
          ?? {
          ???? return Manager;
          ?? }
          ?????
          }
          經跟蹤發現原來是在反序列化getManager的返回值的時候出錯的。hibernate使用CGLIB實現的惰性加載,這樣getManager的返回值的類型其實是PersonInfo 的一個子類,其中有一個CGLIBLazyInitializer類型的字段,這個CGLIBLazyInitializer是沒有默認構造函數的,這樣就造成了反序列化失敗。
          我的解決方式是寫一個DTOAssembler來將PO手動轉換成VO,這個VO的類型和PO一樣,但是對于關聯屬性進行了針對CGLIB的特別處理。然后把轉換后的VO傳遞到表現層。
          請各位多指教。謝謝。

          ?

          posted @ 2006-10-06 00:58 CowNew開源團隊 閱讀(2061) | 評論 (3)編輯 收藏

          僅列出標題
          共30頁: First 上一頁 16 17 18 19 20 21 22 23 24 下一頁 Last 
          主站蜘蛛池模板: 金湖县| 榆社县| 同江市| 彭州市| 禄丰县| 湖南省| 友谊县| 银川市| 宣恩县| 景洪市| 北川| 兰西县| 横山县| 平泉县| 南康市| 巨野县| 彭山县| 永福县| 红河县| 信宜市| 石首市| 大安市| 肥乡县| 视频| 崇左市| 贺州市| 新河县| 茂名市| 克东县| 永寿县| 汝南县| 喀喇沁旗| 南投县| 赤水市| 新民市| 梧州市| 泾阳县| 涞源县| 会昌县| 修水县| 怀集县|