posts - 97,  comments - 93,  trackbacks - 0
 
Today with tomcat admin, a Graphic interface for us to config the JNDI for our program,I configured the context and connection pool jioning IBM DB2 ExC-9.Actually,JNDI is an API specified in Java technology that provides naming and directory functionality to applications written in the Java programming language. It is designed especially for the Java platform using Java's object model. Using JNDI, applications based on Java technology can store and retrieve named Java objects of any type. In addition, JNDI provides methods for performing standard directory operations, such as associating attributes with objects and searching for objects using their attributes (Name-Value,context).JNDI is also defined independent of any specific naming or directory service implementation. It enables applications to access different, possibly multiple, naming and directory services using a common API. Different naming and directory service providers can be plugged in seamlessly behind this common API. This enables Java technology-based applications to take advantage of information in a variety of existing naming and directory services, such as LDAP, NDS, DNS, and NIS(YP), as well as enabling the applications to coexist with legacy software and systems. Using JNDI as a tool, we can build new powerful and portable applications that not only take advantage of Java's object model but are also well-integrated with the environment in which they are deployed.
A directory is typically used to associate attributes with objects. A person object, for example, can have a number of attributes, such as the person's surname, fisrtName,telephone numbers, electronic mail address and so on. Using JNDI, to retrieve the email address of a person object, the code looks as follows.
1 Attribute personAttribute=directory.getAttributes(personName).get("email");
2 String email = (String)personAttribute.get();
(Recently,finding that blogjava can help us format our code,that's perfect,but if can max the editor area which will enhance the function and coursely be better:).)
An intuitive model for the Java programmer is to be able to lookup objects like printers and databases from the naming/directory service. Using JNDI, to lookup a printer object, the code looks as follows. (it's important and most used)
1 Printer printer =(Printer)namespace.lookup(printerName);
2 printer.print(document);

posted @ 2007-04-08 15:10 wqwqwqwqwq 阅读(466) | 评论 (0)编辑 收藏

//*******************The Log class
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.uitl.Date;
import java.text.DateFormat;

public class Log{
   private static final String filePath = PropertyReader.getResource("Log_File_Path");//Supposing we have define in the last ProperyReader class and the file
  
   public static final String EXCEPTION                  =   "Exception";
   public static final String CREATE_STAFF           =   "Create Staff";
   public static final String EDIT_STAFF                 =   "Edit Staff";
   public static final String DELETE_STAFF            =   "Delete Staff";
   public static final String RECORD_HAS_EXIST  =   "Record Has Exist";

   public static void log(String msg_type, Exception e){
      StringBuffer errMsg = new StringBuffer(e.toString);
     
      for(int i=0;i<e.getStackTrace().length;i++){
         errMsg.append("\n\t at");
         errMsg.append(e.getStackTrace()[i].toString);
      }
      log(msg_type,errMsg.toString());
      OptionPanel.showErrMsg("Sorry,System may have an error \n System will exit");
      System.exit(-1);
   }

  public static void log(String msg.type,Staff staff){
     String msg = null;
     if(msg_type == CREATE_STAFF){
         msg = staff.toString() + "has benn created";
     }else if(msg_type == EDIT_STAFF){
         msg = staff.toString() + "has been Changed";
     }else if(msg_type == DELETE_STAFF){
         msg = staff.toString() + "has been Deleted";
     }else if(msg_type == RECORD_HAS_EXIST){
         msg = staff.toString() + "has exist in the database";
     }
     log(msg_type,msg);
  }

  private static void log(String msg_type,String msg){
      BufferedWriter out = null;
      DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
     
      try{
        out = new BufferedWriter(new FileWriter(getLogFilePath(),true));//如果为 true,则将字节写入文件末尾处,而不是写入文件开始处
        out.write("["+df.format(new Date()) + "] <" + msg_type + "> :" + msg);
        out.newline();
        out.newline();
      }catch(IOException e){
          e.printStackTrace();
      }finally{
         try{
           if(out!=null){
              out.close();
           }
         }catch(IOException e){
            e.printStackTrace();
         }
      }
  }

  private static String getLogFilePath(){
     File logDir = new File(filePath);
     if(!logDir.exists()){
       logDir.mkdir();
     }
    
     int i = 1;
     String fileName = filePath + "log_";
     File file = new File(fileName + i + ".txt");
   
     while(file.exists() && file.length() > 30000L) {
         i++;
         file = new File(fileName + i + ".txt");
     }
   
      return fileName + i + ".txt"
  }
}

//*****************************The OptionPanel Dialog Class for the Log Class
import javax.swing.JOptionPane;

public class OptionPanel {
   private static final String appTitle = PropertyReader.getResource("App_Title");//suposing the file has been established and the property app-title stands for the name of application
   private static final MainFrame frame = MainFrame.getMainFrame();

   public static void showWarningMsg(String msg){
      JOptionPane.showMessageDialog(frame,msg,appTitle,JOptionPane.WARNING_MESSAGE);
   }
   public static void showErrMsg(String msg){
       JOptionPane.showMessageDialog(frame,msg,appTitle,JOptionPane.Error_MESSAGE);
   }
   public static int showConfirmMsg(String msg){
        return JOptionPane.showConfirmDialog(frame,msg,appTitle,JOptionPane.YES_NO_OPTON,JOptionPane.QUESTION_MESSAGE);
   }
}

posted @ 2007-04-05 10:01 wqwqwqwqwq 阅读(865) | 评论 (1)编辑 收藏

In a project, we can write a class to read the properties.As following,

import java.io.InputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertyReader{
   private static Properties property = null;
  
   static{
      InputSteam stream = null;
      try{
        stream=PropertyReader.class.getResourceAsStream("/resource/properties.properties");
        property = new Properties();
        property.load(stream);
      }catch(IOException e){
          e.printStackTrace();
      }finally{
          if(stream != null){
             try{
                stream.close();
             }catch(IOException e){
                e.printStackTrace();
             }           
          }
      }
   }
   public static String getResource(String key){
     if(property == null){
       return null;// init error;
     }
     
     return property.getProperty(key);
   }
}

posted @ 2007-04-05 08:13 wqwqwqwqwq 阅读(477) | 评论 (0)编辑 收藏
These days I want to review some java classes and post them,cos i come to realize that i hava been coming to forget some of them, my god,Katrina,....:) it's really the sound,and u ? ...regarding MVC,cos be delayed, and may be will better.

List a class to use the title Properties.

import java.util.Properties;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FirstDayTestProperties {
   public static void main(String[] args) throws Exception{
       Properties ProTest = new Properties();
       String  fileName="PropertiesTest.properties";
      
       try{
          ProTest.setProperty("lastDir","C:\\PropertyTest");
          ProTest.store(new FileOutputStream(fileName),null);
       }catch(IOException e){
            e.printStackTrace();
       }

       try{
          FileInputStream inStream=new FileInputStream(fileName);
          ProTest.load(inStream);
          ProTest.list(System.out);
       }catch(FileNotFoundException e){
          e.printStackTrace();
       }
   }
}
The class I just write now without any testing,but i think it seems no errors:).Share.

posted @ 2007-04-04 21:32 wqwqwqwqwq 阅读(475) | 评论 (0)编辑 收藏
U may come across model view controller desigh pattern.It was first introduced by  Trygve Reenskaug. More details,MVC can be broken down into three elements.
<1>Module  Usually,in enterprise software,it presents the logic of the commercial bean.To the SE Swing GUI,it contains data and the rules that govern access to and updates of this data.
<2>View  It specifies exactly how the module data should be presented,changing with the model data.
<3>Controller   Controller defines all the methods connecting to the user action which are called by the View.
Especially,the model doesn't carry a reference to the view but instead uses an event-notification model to notify insteaded parties of a change.One of the consequences of this powerful design is that many views can have the same model.When a change in the data model occurs,each view is notified by a property change event and can change itself accordingly.Hence, the controller may mediate the data flow between the model and the view in both directions,which helps to more completely decouple the model from the view,and the controller may also provide the methods which effect the model's property changes for one or more views that are registered with it.

....Next,may be the two days after tomorrow ,I ll give a real example to explain this schema in details.......
posted @ 2007-03-26 23:16 wqwqwqwqwq 阅读(431) | 评论 (0)编辑 收藏
这几天忙忙乱乱的,也没顾及这个blog,其实说句实话,自己也好几天没在研究技术的东西了,只是在看看IBM的一些个产品,哎~所以今天还是没打算写写技术,只是来post自己这几天的一些琐琐碎碎。还算高兴的事情是自己的小队伍获得了国际数学建模竞赛2等奖,虽然不是很理想,但自己还是满足了,毕竟带的娘子(当然是除了我了)队伍实力不是很强,况且大过年的我原来的伙伴早飞回温暖的南方了。其实我本身早厌倦了那种比赛,不过还是比较欣赏美国人的精明和对中国人明知故犯的无奈,也许吧,其实还是要庆祝一下自己的最后一次这种竞赛...
这周学校组织无偿献血,虽然我并不在乎学校不给什么所谓的补偿,我也不会因为献血怎么怎么的就有所目的,只是感觉这种行为还算是对社会作出了一点贡献。最岖奇的是导员居然不让我献血,当然他的劝告算能让我接受,但是自己还是很固执的感觉,无奈的导员也只好应下了。哎~我这个人真是经不起别人的劝告发现,在好些个朋友的“吓唬”下,终于作出了心虚的妥协...哎~,不过也算给我的母亲一个很好的交代了。
不说这些令人扫兴的话题了,还有一件好事,就是跟我关系很铁的一个老师有了21个月的小宝宝,其实他才告诉我的,还是在网上。不过早应该猜到了,因为这几天就发现他“不误正业”,整天不在办公室,往家里一个劲的跑,不过在这里,虽然他不会知道,还是祝愿他博士论文顺利通过吧,双喜临门...
想早些休息了,Good night&& Good dream.
posted @ 2007-03-22 23:18 wqwqwqwqwq 阅读(436) | 评论 (0)编辑 收藏
刚刚看看过鲁豫有约的两期节目,是采访的年轻轻但身价过亿的李想、高燃、戴志和茅侃侃。其实,我并不因为他们的年轻或是很有钱,而感到任何诧异,但自己却很欣常他们各自所持有的信念和创业过程中对资金的运营勇气,我真的不知道随着他们事业的增长、社会的变更,他们还是否会是浪潮的宠儿、是否会和原来一样,对待更多的运营资本同样的保持清醒地头脑,但我还是很祝福他们...

看过之后,我的感触很深,在这个社会上,或许是因为随着一个人学历的渐渐增长,他也会变得懒惰,因为他再也不会像社会地位很卑微的人一样为生计担心,我本也相信,人在骨子里是懒惰的。其实,我自己也曾想过,以后能找个比较大的外企工作,几年之后一个月拿个几W块就ok了,然后就是一辈子平平淡淡的生活...:),或许我的思想还不够先进吧。他们的经历,也让我重新思考,说句实话,其实他们并没什么,只是在坎坷的社会中,为了自己的信念坚持了下来,并一直做到了现在。我想我也该在为别人打工的同时,定位自己的目标,并坚定的追求。高燃是我很佩服的一个人,完全是因为他的执著,无论是他考清华、追GirlFriend 还是去找投资人,最后到办好公司。人的天赋很重要,但我还是更喜欢执著...
posted @ 2007-03-18 23:32 wqwqwqwqwq 阅读(627) | 评论 (2)编辑 收藏
Yestoday night,CA coordinator emailed and phoned me for Sunstudio running and test the ping-home function,I m sorry that I really didn't know what's this really mean under Unix,I am not sure,maybe about to edit the file of host,but I just ping -s localhost,well,maybe another ip destination.more awful,I cannot run the #./SUNWspro/bin/f95, #./SUNWspro/bin/cc, #./SUNWspro/bin/CC...I have sent the first test result,and continue to learn more about it,but I m really sorry.

 


 


posted @ 2007-03-17 07:36 wqwqwqwqwq 阅读(161) | 评论 (0)编辑 收藏
The day before yestoday,I have received the intern offer letter from IBM CDL...to my surprise,cos of my little time,only can support 3-4ms.it's too absurd that when the assistant
ask my IdCard num,well,God,I forgot it...:) During the time,not so along,exactly,only a few days ago,I met a manager in the IBM(BJ)CRL,She is a very kind person,also a manager(i think),she has recommended me to her colleagues,which I really thank her.so yestoday,these persons phoned me and asked if wanted to do some QA jobs,if though,they knew that i was admired by CDL.To the manners,I think today I should take their phone test though I will not accept their opportunity as to my promise to the CDL,That's important I think.
Now I was a junior student,coming to realize that the campus life will be end,I was lucky I think,especailly about so many friends,can be ambassador of Sun Microsystems.lnc,can be a intern of IBM and so on.Now in my dream,hope that I can be a recommend student to get the master degree of tsingHua or BJUniversity this Sep.,then can go aboard for future research,last,back to the motherland to have a peace life,for which I will try my hard and best.
posted @ 2007-03-16 12:19 wqwqwqwqwq 阅读(461) | 评论 (0)编辑 收藏
Maybe,u are tied of Windows and come to thinking of trying Linux,so many good Operation Systems,like,Suse Redhat ...or Novell have all enterprise u might need,as well,support communities.well,it's true enough--Solaris is also available and as a OpenSolaris form with AMD and Intel friends,with a pretty community going && more and more third-party supporting.U may download the Solaris form www.opentech.org.cn, www.opensolaris.org, ...Sun.
I very like OpenSolaris not only its security,its creative,convinient...whereas,its all:).The Java Desktop is cool and we may also use click to operate,well,I like the terminal more.Now I use Solaris as a developer desktop,it integrates the Netbeans to develop Java which is also a excellent enviroment to develop others after u plug in,Sun Studio,a platform to develop C/C++ &&fortan,with sun compiler,efficient.If u think Solaris is too big and Enterprise-heavy,u will make a mistake,Solaris is very small but excellent perform,:),U can try urself.
yestoday i make a techtalk about Sun openSolaris and Java,C/C++ development under it in my campus(DaLian University of Technology).To my surprise There were more students from the  disrelated computer science Department,more,even more girls.I saw a Linux teachers attending,I was very pleased,cos of Solaris is sure to attract the fancy of the Linux users,at least,It's better in my...our's eyes.:),as following I attach some of pics of my tech-talking to share with u.
   
posted @ 2007-03-12 11:01 wqwqwqwqwq 阅读(605) | 评论 (0)编辑 收藏
仅列出标题
共10页: First 上一页 2 3 4 5 6 7 8 9 10 下一页 
<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567




常用链接

留言簿(10)

随笔分类(95)

随笔档案(97)

文章档案(10)

相册

J2ME技术网站

java技术相关

mess

搜索

  •  

最新评论

阅读排行榜

校园梦网网络电话,中国最优秀的网络电话