1 2 package org.enhydra.tool.archive.xml; 3 4 import org.w3c.dom.Element ; 6 public class EjbDescriptorHandler extends AbstractDescriptorHandler { 8 private final String DESC_NAME = "description"; 9 private final String DESC_VALUE = "no description"; 10 private final String DISPLAY_NAME = "display-name"; 11 private final String DISPLAY_VALUE = "Ejb1"; 12 private final String ENTERPRISE_BEANS = "enterprise-beans"; 13 private final String PUBLIC_ID = 14 "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; 15 private final String SYSTEM_ID = 16 "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd"; 17 18 public static void main(String [] args) { 21 EjbDescriptorHandler prep = new EjbDescriptorHandler(); 22 23 prep.setSource("d:/test/simple/test2.xml"); 24 prep.setOutStream(System.out); 25 try { 26 prep.prep(); 27 } catch (Exception e) { 28 e.printStackTrace(); 29 } 30 } 31 32 protected String getSystemID() { 34 return SYSTEM_ID; 35 } 36 37 protected String getPublicID() { 38 return PUBLIC_ID; 39 } 40 41 protected void prepElements() { 42 prepDescription(); 43 prepDisplayName(); 44 prepEnterpriseBeans(); 45 } 46 47 private void prepDescription() { 48 Element element = null; 49 50 element = lookup(getDoc().getDocumentElement(), DESC_NAME); 51 if (element == null) { 52 element = getDoc().createElement(DESC_NAME); 53 element.appendChild(getDoc().createTextNode(DESC_VALUE)); 54 getDoc().getDocumentElement().appendChild(element); 55 } 56 } 57 58 private void prepDisplayName() { 59 Element element = null; 60 61 element = lookup(getDoc().getDocumentElement(), DISPLAY_NAME); 62 if (element == null) { 63 element = getDoc().createElement(DISPLAY_NAME); 64 element.appendChild(getDoc().createTextNode(DISPLAY_VALUE)); 65 getDoc().getDocumentElement().appendChild(element); 66 } 67 } 68 69 private void prepEnterpriseBeans() { 70 Element element = null; 71 72 element = lookup(getDoc().getDocumentElement(), ENTERPRISE_BEANS); 73 if (element == null) { 74 element = getDoc().createElement(ENTERPRISE_BEANS); 75 getDoc().getDocumentElement().appendChild(element); 76 } 77 } 78 79 } 80 | Popular Tags |