如鹏网 大学生计算机学习社区

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开源团队 阅读(472) | 评论 (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开源团队 阅读(702) | 评论 (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开源团队 阅读(890) | 评论 (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开源团队 阅读(3220) | 评论 (0)编辑 收藏

书稿终于发给出版社了,随书光盘也发给出版社了,两个月的“闭门造书”总算有了一点结果。现在就祈祷这本书能顺利出版了。
写书的过程中有一些“下脚料”,扔了怪可惜,就在blog中陆续共享出来吧。“下脚料”并不代表写的差,大部分是因为和书的结构有偏离,所以被cut下来了。所以的下脚料文章都以“xjl:”开头,以免得以后我发的文章也被当成下脚料了。:)

posted @ 2007-01-02 23:31 CowNew开源团队 阅读(322) | 评论 (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开源团队 阅读(2005) | 评论 (0)编辑 收藏

经过40多天的“闭门造书”,终于被释放了,终于可以上网了,做个记号,以后博客又可以更新了,团队网站又可以维护了!
讲个刚看到的故事吧:
联合利华引进了一条香皂包装生产线,结果发现这条生产线有个缺陷:常常会有盒子里没装入香皂。总不能把空盒子卖给顾客啊,他们只好请了一个学自动化的博士后设计一个方案来分拣空的香皂盒。博士后拉起了一个十几人的科研攻关小组,综合采用了机械、微电子、自动化、X射线探测等技术,花了几十万,成功解决了问题。每当生产线上有空香皂盒通过,两旁的探测器会检测到,并且驱动一只机械手把空皂盒推走。 中国南方有个乡镇企业也买了同样的生产线,老板发现这个问题后大为光火,找了个小工来说你他妈给我把这个搞定。小工果然想出了办法:他在生产线旁边放了台风扇猛吹,空皂盒自然会被吹走。
posted @ 2006-12-15 00:25 CowNew开源团队 阅读(363) | 评论 (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开源团队 阅读(954) | 评论 (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开源团队 阅读(890) | 评论 (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开源团队 阅读(2053) | 评论 (3)编辑 收藏

仅列出标题
共30页: First 上一页 16 17 18 19 20 21 22 23 24 下一页 Last