이거 말이다.
2008년도 10.16일 다시 개발 하려고 했던 것.
일부 프로그래밍 JAVA 소스
// jim.ois.DOMSerializer
패키지
package jjm.ois;
import java.io.*;
import org.w3c.dom.*;
// XML 객체를 XML 파일로 저장하는 넘!!!
public class DOMSerializer
{
// 들여쓰기
String indent;
// 줄 구분자
String lineSeparator;
// 생성자
public DOMSerializer(){
indent="\t";
lineSeparator="\n";
}
public void setLineSeparator(String ls){
this.lineSeparator=ls;
}
public void serialize(Document doc,OutputStream out) throws IOException{
Writer writer=new OutputStreamWriter(out);
serialize(doc,writer);
}
public void serialize(Document doc,File file) throws IOException{
Writer writer=new FileWriter(file);
serialize(doc,writer);
}
public void serialize(Document doc,Writer writer) throws IOException{
serializeNode(doc,writer,"");
writer.flush();
}
public boolean serializeNode(Node node,Writer writer,String indentLevel) throws IOException{
boolean hasChild = false; // 유효한 하위 노드를 포함하는지 여부 플래그
boolean isValid = true; // 현재 노드가 유효한 노드인지 여부 플래그(내용있는 텍스트 노드 외에는 모두 유효)
//노드 타입별로 출력
switch (node.getNodeType()){
case Node.DOCUMENT_NODE:
writer.write("<?xml version=\"1.0\" ENCODING=\"euc-kr\"?>");
//writer.write(lineSeparator);
NodeList nodes=node.getChildNodes();
if(nodes!=null){
for(int i=0;i<nodes.getLength();i++){
// 재귀호출
serializeNode(nodes.item(i),writer,"");
}
}
break;
case Node.ELEMENT_NODE:
String name=node.getNodeName();
writer.write(lineSeparator);
writer.write(indentLevel+"<"+name);
//속성을 처리하는 부분
NamedNodeMap attributes=node.getAttributes();
for(int i=0;i<attributes.getLength();i++){
Node current=attributes.item(i);
writer.write(" "+current.getNodeName()+"=\""+current.getNodeValue()+"\"");
}
writer.write(">");
//writer.write(lineSeparator);
NodeList children=node.getChildNodes();
if(children != null){
for(int i=0;i<children.getLength();i++){
hasChild |= serializeNode(children.item(i),writer,indentLevel+indent);
}
}
if(hasChild==true){
writer.write(lineSeparator);
writer.write(indentLevel);
hasChild = false;
}
writer.write("</"+name+">");
//writer.write(lineSeparator);
break;
case Node.TEXT_NODE:
//if("".equals(node.getNodeValue().trim()) != true){
//writer.write(indentLevel);
writer.write(node.getNodeValue().trim());
//writer.write(lineSeparator);
//}
isValid = false;
break;
case Node.CDATA_SECTION_NODE:
writer.write("<![CDATA["+node.getNodeValue()+"]]>");
break;
case Node.COMMENT_NODE:
writer.write(lineSeparator);
writer.write(indentLevel+"<!--"+node.getNodeValue()+"-->");
//writer.write(lineSeparator);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
writer.write(lineSeparator);
writer.write("<?"+node.getNodeName()+""+node.getNodeValue()+"?>");
//writer.write(lineSeparator);
break;
case Node.ENTITY_REFERENCE_NODE:
writer.write("&"+node.getNodeName()+";");
break;
case Node.DOCUMENT_TYPE_NODE:
DocumentType docType=(DocumentType)node;
writer.write(lineSeparator);
writer.write("<!DOCTYPE "+docType.getName());
if(docType.getPublicId()!=null){
System.out.println(" PUBLIC \""+
docType.getPublicId()+"\"");
}else{
writer.write(" SYSTEM ");
}
writer.write("\""+docType.getSystemId()+"\">");
// writer.write(lineSeparator);
break;
}
return isValid;
}
}
===========================================
// 테이블 구성
CREATE TABLE CAR_STATIC(
RFIDCODE VARCHAR2(50) PRIMARY KEY,
CARNO VARCHAR2(20) NOT NULL,
CARTYPE VARCHAR2(20) ,
CUSTSTART VARCHAR2(20) ,
CUSTEND VARCHAR2(20) ,
OWNERNAME VARCHAR2(10) ,
OWNERTEL VARCHAR2(15) ,
IMAGE VARCHAR2(20)
);
CREATE TABLE CAR_HISTORICAL(
NO NUMBER PRIMARY KEY,
RFIDCODE VARCHAR2(50) NOT NULL,
READERID VARCHAR2(20) NOT NULL,
ENTERTIME DATE ,
EXITTIME DATE
);
CREATE SEQUENCE carhistoryseq START WITH 1 INCREMENT BY 1
CREATE TABLE AREA_STATIC(
RFIDCODE VARCHAR2(50) PRIMARY KEY,
LOTID VARCHAR2(20) NOT NULL,
FLOOR VARCHAR2(20) NOT NULL,
REGDATE VARCHAR2(50) NOT NULL
);
//주차 구역 현황 테이블
CREATE TABLE TBLPARKING(
LOTID VARCHAR2(4) PRIMARY KEY,
PFLAG VARCHAR2(1) NOT NULL,
VACANT VARCHAR2(1) NOT NULL,
LASTUPDATED DATE NOT NULL
);
-----------------------------------------------------
// HomeFactory.java
package jjm.ois;
import java.util.*;
import javax.ejb.*;
import javax.rmi.*;
import javax.naming.*;
public class HomeFactory{
private Context ctx;
private HashMap hm;
private static HomeFactory hf;
private HomeFactory(){
try{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
ctx = new InitialContext(p);
hm = new HashMap();
}catch(Exception ex){
ex.printStackTrace();
}
}
public static HomeFactory getInstance(){
if(hf == null){
hf = new HomeFactory();
}
return hf;
}
public EJBHome getHome(Class c){
EJBHome eh = (EJBHome)hm.get(c.getName());
if(eh == null){
try{
// c.getName()이 패키지명을 포함한 클래스이름이 리턴되므로 JNDI 서버에 JNDI name 등록시
// 패키지명까지 포함한 홈인터페이스명을 등록한다.
System.out.println("홈팩토리 getHome()내부, 클래스이름:" + c.getName());
eh = (EJBHome)PortableRemoteObject.narrow(ctx.lookup(c.getName()), c);
}catch(Exception ex){
ex.printStackTrace();
}
hm.put(c.getName(), eh);
}
return eh;
}
}
--------------------------------------------------------
// Ois.java
package jjm.ois;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
import java.io.*;
// Remote Interface
public interface Ois extends EJBObject {
// 원격 클라이언트를 위해 선언하는 비즈니스 메소드 //XML 파일로 입력을 받고 XML 파일로 응답한다.
public String xmlService(String reqest) throws RemoteException;
//public String getDescriptionFile() throws RemoteException;
}
-----------------------------------------------------------
===========================================================
// Ois.EJB.java
package jjm.ois;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.rmi.*;
import javax.ejb.*;
import javax.naming.*;
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
// 무상태 세션빈
public class OisEJB implements SessionBean {
// XML 처리용
DocumentBuilderFactory dbf;
DocumentBuilder parser;
Document doc;
// DB 연결용
private DataSource ds;
// EJB 컨테이너와의 협약 메소드----------------------------------------------
public void setSessionContext(SessionContext sessionContext) {}
public void ejbCreate() throws CreateException {
try{
dbf = DocumentBuilderFactory.newInstance();
parser = dbf.newDocumentBuilder();
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
//p.put(Context.PROVIDER_URL, "t3://localhost:7001");
p.put(Context.PROVIDER_URL, "t3://192.168.3.29:7001");
Context ctx = new InitialContext(p);
ds = (DataSource)ctx.lookup("jdbc/OracleDS");
System.out.println("ejbCreate() in OISManagerEJB called");
}catch(Exception ex){
System.out.println("ejbCreate() 메소드 예외발생");
ex.printStackTrace();
}
}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate(){}
//---------------------------------------------------------------------------
// 비즈니스 메소드 구현
// public String getDescriptionFile(){
// return new File("description.xml");
// }
// XML 로 입력을 받아서 처리후 XML로 결과 반환하는 메소드
public String xmlService(String request){
try{
dbf = DocumentBuilderFactory.newInstance();
parser = dbf.newDocumentBuilder();
doc = parser.parse(new InputSource(new StringReader(request)));
}catch(Exception e){
System.out.println("exception: " + e);
}
Collection c = null;
Iterator iter = null;
Document docAns = null;
String table = "";
// 응답할 xml 의 root 엘리먼트를 만든다
docAns = parser.newDocument();
Element rootE = docAns.createElement("OIS");
rootE.setAttribute("msgType", "Answer");
docAns.appendChild(rootE);
// 추후에 user 정보 처리 할것
//
//NodeList list = doc.getElementsByTagName("OIS");
// 정보를 가져오는 요구처리(GET)
NodeList list = doc.getElementsByTagName("GET");
if(list != null){
for(int i=0; i<list.getLength(); i++){
// 쿼리 내용을 추출한다
Node n = list.item(i);
String select = getTextData("SELECT", n);
if(!select.trim().equals("")){
select = "SELECT " + select;
}
String from = getTextData("FROM", n);
table = from;
if(!from.trim().equals("")){
from = "FROM " + from;
}
String where = getTextData("WHERE", n);
if(!where.trim().equals("")){
where = "WHERE " + where;
}
c = getInfo(select + from + where);
iter = c.iterator();
String[] columnName = null;
if(iter.hasNext()){
columnName = (String[])iter.next(); //처음에는 컬럼명을 받는다
}
//해당하는 데이터를 받는다.
if(table.trim().split("_").length < 2){
System.out.println("잘못된 테이블 이름입니다: " + table);
continue;
}
//table = table.trim().split("_")[0];
//System.out.println("table name: " + table);
while(iter.hasNext()){
Element ele = docAns.createElement(table.trim());
rootE.appendChild(ele);
String[] info = (String[])iter.next();
for(int indexSel = 0; indexSel < info.length; indexSel++){
Element e = docAns.createElement(columnName[indexSel]);
System.out.println("getInfo()에서 반환된 컬럼명:" + columnName[indexSel]);
Text textNode = docAns.createTextNode(info[indexSel]);
System.out.println("getInfo()에서 반환된 데이터:" + info[indexSel]);
e.appendChild(textNode);
ele.appendChild(e);
}
}
}
}
// 정보를 추가하는 요구처리(ADD)
list = doc.getElementsByTagName("ADD");
if(list != null){
for(int i=0; i<list.getLength(); i++){
// 쿼리 내용을 추출한다
Node n = list.item(i);
String into = getTextData("INTO", n);
table = into;
if(!into.trim().equals("")){
into = "INSERT INTO " + into;
}
String values = getTextData("VALUES", n);
if(!values.trim().equals("")){
if(table.trim().toLowerCase().equals("car_historical")){
values = "VALUES (carhistoryseq.NEXTVAL, " + values + ")";
}else if(table.trim().toLowerCase().equals("area_historical")){
values = "VALUES (areahistoryseq.NEXTVAL, " + values + ")";
}
}
addInfo(into + values);
}
}
// 정보를 수정하는 요구처리(SET)
list = doc.getElementsByTagName("SET");
if(list != null){
for(int i=0; i<list.getLength(); i++){
// 쿼리 내용을 추출한다
Node n = list.item(i);
String update = getTextData("UPDATE", n);
table = update;
if(!update.trim().equals("")){
update = "UPDATE " + update;
}
String set = getTextData("SET", n);
if(!set.trim().equals("")){
set = "SET " + set;
}
String where = getTextData("WHERE", n);
if(!where.trim().equals("")){
where = "WHERE " + where;
}
setInfo(update + set + where);
}
}
// 리턴해줄 xml 스트링 생성 부분
StringWriter sw = new StringWriter();
try{
System.out.println("DOMSerializer 생성 전");
DOMSerializer ds = new DOMSerializer();
System.out.println("DOMSerializer 생성 완료");
ds.serialize(docAns, sw);
System.out.println("serialize() 완료");
}catch(Exception ex){
System.out.println("예외발생");
ex.printStackTrace();
}
System.out.println("결과 XML:" + sw.toString());
//return outString;
return sw.toString();
}
private String getTextData(String elementName, Node node){
Element ele = (Element)node;
Node n = ele.getElementsByTagName(elementName).item(0);
if(n==null) return "";
else return n.getFirstChild().getNodeValue();
}
private Collection getInfo(String query){
// 테이블 레코드 Select
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
System.out.println("query: " + query);
ArrayList list = new ArrayList();
try{
System.out.println("connection 얻기 전--");
con = ds.getConnection();
System.out.println("connection 얻음--");
pstmt = con.prepareStatement(query);
System.out.println("statement 준비완료--");
rs = pstmt.executeQuery();
System.out.println("Query 실행완료--");
int columnCount = rs.getMetaData().getColumnCount();
//System.out.println("columnCount: " + columnCount);
String[] ansString = new String[columnCount];
for(int i=0; i<columnCount; i++){
ansString[i] = rs.getMetaData().getColumnName(i+1);
System.out.println(ansString[i]);
}
list.add(ansString); // 컬럼명을 먼저 담는다
while(rs.next()){
ansString = new String[columnCount];
for(int i=0; i<columnCount; i++){
ansString[i] = rs.getString(i+1);
System.out.println(ansString[i]);
}
list.add(ansString); // DB정보를 담는다
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
try{
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(con != null) con.close();
System.out.println("connection close!!");
}catch(Exception ex){
ex.printStackTrace();
}
}
System.out.println("getInfo(..) 정상 실행");
return list;
}
private void addInfo(String query){
// 테이블 레코드 Select
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
System.out.println("query: " + query);
try{
System.out.println("connection 얻기 전--");
con = ds.getConnection();
System.out.println("connection 얻음--");
pstmt = con.prepareStatement(query);
System.out.println("statement 준비완료--");
rs = pstmt.executeQuery();
System.out.println("Query 실행완료--");
}catch(Exception ex){
ex.printStackTrace();
}finally{
try{
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(con != null) con.close();
System.out.println("connection close!!");
}catch(Exception ex){
ex.printStackTrace();
}
}
System.out.println("addInfo(..) 정상 실행");
}
private void setInfo(String query){
// 테이블 레코드 Select
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
System.out.println("query: " + query);
ArrayList list = new ArrayList();
try{
System.out.println("connection 얻기 전--");
con = ds.getConnection();
System.out.println("connection 얻음--");
pstmt = con.prepareStatement(query);
System.out.println("statement 준비완료--");
rs = pstmt.executeQuery();
System.out.println("Query 실행완료--");
}catch(Exception ex){
ex.printStackTrace();
}finally{
try{
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(con != null) con.close();
System.out.println("connection close!!");
}catch(Exception ex){
ex.printStackTrace();
}
}
System.out.println("setInfo(..) 정상 실행");
}
/*
public OisEJB(){ // 로컬에서 테스트용
try{
dbf = DocumentBuilderFactory.newInstance();
parser = dbf.newDocumentBuilder();
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx = new InitialContext(p);
ds = (DataSource)ctx.lookup("jdbc/OracleDS");
}catch(Exception ex){
System.out.println("ejbCreate() 메소드 예외발생");
ex.printStackTrace();
}
}
public static void main(String[] args){
OisEJB oe = new OisEJB();
String input = null;
String totalString = "";
System.out.println("main() 시작");
try{
BufferedReader br = new BufferedReader(new FileReader("query.xml"));
while( (input = br.readLine()) != null)
totalString += input;
}catch(Exception e){
System.out.println("exception: " + e);
}
System.out.println("query.xml 읽어옴");
//System.out.println(totalString);
System.out.println(oe.xmlService(totalString));
}
*/
}
------------------------------------------------------------
============================================================
// OisHome.java
package jjm.ois;
import java.rmi.*;
import java.util.*;
import javax.ejb.*;
// Remote Home Interface
public interface OisHome extends EJBHome {
public Ois create() throws CreateException, RemoteException;
}
PS) 이거 보고 껍데기라고 미친 놈이 있었다.
OIS server 연동도 모르고..
이거 RFID서버에서 에일리언 서버도 이용해야 한다.
지금은 없어진 서버제품이지만.