system.properties 값

풀그림 2008. 8. 22. 14:14

key

value

java.runtime.name

Java(TM) SE Runtime Environment

sun.boot.library.path

C:\Program Files\Java\jre1.6.0_01\bin

java.vm.version

1.6.0_01-b06

java.vm.vendor

Sun Microsystems Inc.

java.vendor.url

http://java.sun.com/

path.separator

;

java.vm.name

Java HotSpot(TM) Client VM

file.encoding.pkg

sun.io

sun.java.launcher

SUN_STANDARD

user.country

KR

sun.os.patch.level

Service Pack 2

java.vm.specification.name

Java Virtual Machine Specification

user.dir

D:\Dev\eclipse\workspace\icafe-middlewd

java.runtime.version

1.6.0_01-b06

java.awt.graphicsenv

sun.awt.Win32GraphicsEnvironment

java.endorsed.dirs

C:\Program Files\Java\jre1.6.0_01\lib\endorsed

os.arch

x86

java.io.tmpdir

C:\DOCUME~1\FIGHTI~1\LOCALS~1\Temp\

line.separator

 

java.vm.specification.vendor

Sun Microsystems Inc.

user.variant

 

os.name

Windows 2003

sun.jnu.encoding

MS949

java.library.path

C:\Program Files\Java\jre1.6.0_01\bin;.;C:\WINDOWS\Sun\Java\bin;

java.specification.name

Java Platform API Specification

java.class.version

50

sun.management.compiler

HotSpot Client Compiler

os.version

5.2

user.home

C:\Documents and Settings\fightingaf

user.timezone

 

java.awt.printerjob

sun.awt.windows.WPrinterJob

file.encoding

MS949

java.specification.version

1.6

java.class.path

D:\Dev\eclipse\workspace\icafe-middlewd\bin;D:\Dev\eclipse\workspace\icafe-middlewd\conf;D:\Dev\eclipse\workspace\icafe-middlewd\lib\activation-1.1.jar;

user.name

fightingaf

java.vm.specification.version

1

java.home

C:\Program Files\Java\jre1.6.0_01

sun.arch.data.model

32

user.language

ko

java.specification.vendor

Sun Microsystems Inc.

awt.toolkit

sun.awt.windows.WToolkit

java.vm.info

mixed mode, sharing

java.version

1.6.0_01

java.ext.dirs

C:\Program Files\Java\jre1.6.0_01\lib\ext;C:\WINDOWS\Sun\Java\lib\ext

sun.boot.class.path

C:\Program Files\Java\jre1.6.0_01\lib\resources.jar;

C:\Program Files\Java\jre1.6.0_01\lib\rt.jar;C:\Program Files\Java\jre1.6.0_01\lib\sunrsasign.jar;C:\Program Files\Java\jre1.6.0_01\lib\jsse.jar;C:\Program Files\Java\jre1.6.0_01\lib\jce.jar;C:\Program Files\Java\jre1.6.0_01\lib\charsets.jar;C:\Program Files\Java\jre1.6.0_01\classes

java.vendor

Sun Microsystems Inc.

file.separator

\

java.vendor.url.bug

http://java.sun.com/cgi-bin/bugreport.cgi

sun.io.unicode.encoding

UnicodeLittle

sun.cpu.endian

little

sun.desktop

windows

sun.cpu.isalist

 


Properties prop = System.getProperties();

Enumeration propKeys = prop.keys();

while(propKeys.hasMoreElements()) {

       Object obj = propKeys.nextElement();

       System.out.println(obj + " => [" + prop.getProperty(obj.toString()) + "]");

}

Posted by 파이팅야
,

iterator pattern

Pattern 2008. 8. 19. 20:46

. 정의

복합 객체 요소들(aggregate)의 내부 표현 방식을 공개하지 않고도 순차적으로 접근할 수 있는 방법을 제공한다.

 

사용자 삽입 이미지

 

public class Client {

public static void main(String[] args) {

         ArrayListAggregate newList = new ArrayListAggregate();

         newList.add('a');

         newList.add('c');

         newList.add('b');

         newList.add('d');

         IIterator iterator = newList.createIterator();

 

         Object obj = null;

         while(iterator.hasNext()) {

                  obj = iterator.next();

                  System.out.println(obj);

         }

        

         LinkedListAggregate newList2 = new LinkedListAggregate();

         newList2.add(1);

         newList2.add(3);

         newList2.add(2);

         newList2.add(4);

        

         IIterator iterator2 = newList2.createIterator();

 

         while(iterator2.hasNext()) {

                  obj = iterator2.next();

                  System.out.println(obj);

         }

--------------------------------------------------------------------

public interface IAggregate {

         public IIterator createIterator();

--------------------------------------------------------------------

public class ArrayListAggregate implements IAggregate {

         ArrayList arrayList = new ArrayList();

         public IIterator createIterator() {

                  return new ArrayListIterator(this);

         }

         public int size() {

                  return this.arrayList.size();

         }

         public boolean add(Object obj) {

                  return this.arrayList.add(obj);

         }

         public Object get(int index) {

                  return this.arrayList.get(index);

         }

--------------------------------------------------------------------

public class LinkedListAggregate implements IAggregate {

         LinkedList linkedList = new LinkedList();

         public IIterator createIterator() {

                  return new LinkedListIterator(this);

         }

         public int size() {

                  return this.linkedList.size();

         }

         public boolean add(Object obj) {

                  return this.linkedList.add(obj);

         }

         public Object get(int index) {

                  return this.linkedList.get(index);

         }

--------------------------------------------------------------------

public interface IIterator {

         abstract boolean hasNext();

         abstract Object next();

--------------------------------------------------------------------

public class ArrayListIterator implements IIterator {

         ArrayListAggregate aggregate = null;

         int currentIndex = -1;

        

         public ArrayListIterator(ArrayListAggregate arrayListAggregate) {

                  this.aggregate = arrayListAggregate;

         }

         public Object next() {

                  return this.aggregate.get(this.currentIndex);

         }

         public boolean hasNext() {

                  this.currentIndex++;

                  if (this.currentIndex >= this.aggregate.size() ||

                           this.aggregate.get(this.currentIndex) == null)

                           return false;

                  else

                           return true;

         }

--------------------------------------------------------------------

public class LinkedListIterator implements IIterator {

         LinkedListAggregate aggregate = null;

         int currentIndex = -1;

 

         public LinkedListIterator(LinkedListAggregate linkedListAggregate) {

                  this.aggregate = linkedListAggregate;

         }

         public Object next() {

                  return this.aggregate.get(this.currentIndex);

         }

         public boolean hasNext() {

                  this.currentIndex++;

                  if (this.currentIndex >= this.aggregate.size()

                     || this.aggregate.get(this.currentIndex) == null)

                           return false;

                  else

                           return true;

         }

Posted by 파이팅야
,

java xml jaxp sample

풀그림 2008. 8. 19. 19:05

JAXP (Java API for XML Processing)을 사용하는 간단한 예제들을 볼수 있음

== XML 데이터 == (XSD나 DTD는 안넣어놨음. )
<?xml version="1.0" encoding="utf-8"?>
<CHESSBOARDS>
 <CHESSBOARD>
  <WHITEPIECES>
   <KING><POSITION COLUMN="G" ROW="1"/></KING>
   <BISHOP><POSITION COLUMN="D" ROW="6"/></BISHOP>
     <ROOK><POSITION COLUMN="E" ROW="1"/></ROOK>
     <PAWN><POSITION COLUMN="A" ROW="4"/></PAWN>
     <PAWN><POSITION COLUMN="B" ROW="3"/></PAWN>
     <PAWN><POSITION COLUMN="C" ROW="2"/></PAWN>
     <PAWN><POSITION COLUMN="F" ROW="2"/></PAWN>
     <PAWN><POSITION COLUMN="G" ROW="2"/></PAWN>
     <PAWN><POSITION COLUMN="H" ROW="5"/></PAWN>
  </WHITEPIECES>
  <BLACKPIECES>
     <KING><POSITION COLUMN="B" ROW="6"/></KING>
     <QUEEN><POSITION COLUMN="A" ROW="7"/></QUEEN>
     <PAWN><POSITION COLUMN="A" ROW="5"/></PAWN>
     <PAWN><POSITION COLUMN="D" ROW="4"/></PAWN>
   </BLACKPIECES>
  </CHESSBOARD>
</CHESSBOARDS>

import org.xml.sax.*;
import javax.xml.parsers.*;
import java.io.*;
public class ChessboardSAXPrinter {
 private SAXParser parser;
 private static PrintStream out;
 
 @SuppressWarnings("deprecation")
 public class ChessboardHandler extends HandlerBase
 {
  private boolean whitePiece= false;
 
  @SuppressWarnings("deprecation")
  public void startElement(String name, AttributeList attrs)
  {
   if(name.equals("WHITEPIECES"))
   {
    whitePiece=true;
   }
   else if(name.equals("BLACKPIECES"))
   {
    whitePiece=false;
   }
   else if(name.equals("KING") || name.equals("QUEEN") || name.equals("BISHOP")|| name.equals("ROOK")
     || name.equals("ROOK") || name.equals("KNIGHT") || name.equals("PAWN"))
   {
    System.out.print((whitePiece ? "White" : "Black") + " " + name.toLowerCase() + ": ");   
   }
   else if(name.equals("POSITION"))
   {
    if(attrs!=null)
    {
     System.out.print(attrs.getValue("COLUMN"));
     System.out.println(attrs.getValue("ROW"));
    }  
   }
   return;   
  }
 }
 public ChessboardSAXPrinter(boolean validating) throws Exception
 {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setValidating(validating);
  parser=factory.newSAXParser();
 
  return;
 }
 
 public void print(String fileName, PrintStream out) throws SAXException, IOException
 {
  ChessboardHandler dh=new ChessboardHandler();
 
  parser.parse(fileName, dh);
  return;
 }
 
 public static void main(String[] args)
 {
  boolean validating=true;
  int r,n;
  r=1;
  n=1;
  for(int k=0; k < r; k++)
  {
   try
   {
    ChessboardSAXPrinter saxPrinter=new ChessboardSAXPrinter(validating);
    long time = System.currentTimeMillis();
      for (int i = 0; i < n; i++) {
        // n: number of document processed per run
       //saxPrinter.print(args[0], out);
       saxPrinter.print(args[0], out);
      }
     
      // print out the average time (s)
      // to process a document during the current run
      System.err.print(((double) (System.currentTimeMillis()- time)) / 1000 / n + "\t");
   }
   catch(SAXException ex)
   {
    System.out.println(ex.getMessage());
   }
   catch(IOException iex)
   {
    System.out.println(iex.getMessage());
   }
   catch(Exception uex)
   {
    System.out.println(uex.getMessage());
   }
  }
 }
}


----- DOM으로 처리한 경우 ----------

import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import java.io.*;

public class ChessboardDOMPrinter {
 private DocumentBuilder builder;
 boolean validate;
 public ChessboardDOMPrinter(boolean _validate)
 {
  validate=_validate;
 }
 
 public void print(String fileName, PrintStream out) throws SAXException, IOException, ParserConfigurationException
 { 
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     dbf.setValidating(validate);
     dbf.setNamespaceAware(true);
     dbf.setIgnoringElementContentWhitespace(true);
 
     DocumentBuilder builder = dbf.newDocumentBuilder();
    
  Document document = builder.parse(fileName);
  NodeList nodes_i = document.getDocumentElement().getChildNodes();
 
  for(int i=0; i< nodes_i.getLength(); i++)
  {
   Node node_i=nodes_i.item(i);
   if(node_i.getNodeType()==Node.ELEMENT_NODE && ((Element)node_i).getTagName().equals("CHESSBOARD"))
   {
    Element chessboard=(Element) node_i;
    NodeList nodes_j=chessboard.getChildNodes();
   
    for(int j=0; j< nodes_j.getLength(); j++)
    {
     Node node_j = nodes_j.item(j);
     if (node_j.getNodeType() == Node.ELEMENT_NODE) {
      Element pieces = (Element) node_j;
      NodeList nodes_k = pieces.getChildNodes();
      for (int k = 0; k < nodes_k.getLength(); k++) {
       Node node_k = nodes_k.item(k);
       if (node_k.getNodeType() == Node.ELEMENT_NODE) {
        Element piece = (Element) node_k;
        Element position = (Element) piece.getChildNodes().item(0);
        System.out.println((pieces.getTagName()
                            .equals("WHITEPIECES")
                          ? "White " : "Black ")
                         + piece.getTagName().toLowerCase()
                         + ": "
                         + position.getAttribute("COLUMN")
                         + position.getAttribute("ROW"));       
       }
      }
     }
    }
   }
  }
 
  return;
 }
 
 public void print2(String fileName, PrintStream out) throws SAXException, IOException, ParserConfigurationException {
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     dbf.setValidating(validate);
     dbf.setNamespaceAware(true);
     dbf.setIgnoringElementContentWhitespace(true);
 
     DocumentBuilder builder = dbf.newDocumentBuilder();
    
  Document document = builder.parse(fileName);
  NodeList positions = document.getElementsByTagName("POSITION");
  for (int i = 0; i < positions.getLength(); i++) {
   Element position = (Element) positions.item(i);
   Element piece = (Element) position.getParentNode();
   Element pieces = (Element) piece.getParentNode();
   out.println( (pieces.getTagName().equals("WHITEPIECES") ? "White " : "Black ")
      + piece.getTagName().toLowerCase() + ": "
      + position.getAttribute("COLUMN")
      + position.getAttribute("ROW"));
  }
  return;
 }
 
 public static void main(String[] args)
 {
  PrintStream out=System.out;
  try{
   ChessboardDOMPrinter domPrinter=new ChessboardDOMPrinter(false);
   domPrinter.print2("E:\\DEV_STUDY\\WebCrawler\\WebCrawler\\chessboard.xml", out);
  }
  catch(SAXException sex){
   System.err.println(sex.getMessage());
  }
  catch(IOException iex){
   System.err.println(iex.getMessage());
  }
  catch(ParserConfigurationException pcex)
  {
   System.err.println(pcex.getMessage());
  }
  catch(Exception ex){
   System.err.println(ex.getMessage());
  }
 
 }
}

====== XPATH 관련 ==========
// 추가
import javax.xml.transform.*;
import javax.xml.xpath.*;
.............

public void print3(String fileName, PrintStream out) throws TransformerException,SAXException, IOException, ParserConfigurationException
 {
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     dbf.setValidating(validate);
     dbf.setNamespaceAware(true);
     dbf.setIgnoringElementContentWhitespace(true);
    
     DocumentBuilder builder = dbf.newDocumentBuilder();
     Document document = builder.parse(fileName);

     NodeList allPieces=XPathAPI.selectNodeList(document.getDocumentElement(), "//*[self::WHITEPIECES or self::BLACKPIECES]/*");
    
     for(int i=0; i < allPieces.getLength(); i++)
     {
      Element piece=(Element)allPieces.item(i);
      Element pieces=(Element)piece.getParentNode();
      Element position = (Element) piece.getChildNodes().item(0);
      System.out.println((pieces.getTagName().equals("WHITEPIECES")? "White ":"Black ")+piece.getTagName().toLowerCase()+": " + position.getAttribute("COLUMN")+position.getAttribute("ROW"));    
     }
    
     return;
 }

출처 : http://ausgang.egloos.com/1998938
참조 : http://java.sun.com/developer/technicalArticles/xml/JavaTechandXML/#code14
 http://www.java2s.com/
 http://www.java2s.com/Code/JavaAPI/javax.xml.parsers/DocumentBuilderFactorynewDocumentBuilder.htm

Posted by 파이팅야
,