KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > xml > EjbDescriptorHandler


1
2 package org.enhydra.tool.archive.xml;
3
4 //
5
import org.w3c.dom.Element JavaDoc;
6 //
7
public class EjbDescriptorHandler extends AbstractDescriptorHandler {
8     private final String JavaDoc DESC_NAME = "description";
9     private final String JavaDoc DESC_VALUE = "no description";
10     private final String JavaDoc DISPLAY_NAME = "display-name";
11     private final String JavaDoc DISPLAY_VALUE = "Ejb1";
12     private final String JavaDoc ENTERPRISE_BEANS = "enterprise-beans";
13     private final String JavaDoc PUBLIC_ID =
14         "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN";
15     private final String JavaDoc SYSTEM_ID =
16         "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd";
17
18     //
19
//
20
public static void main(String JavaDoc[] 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 JavaDoc e) {
28             e.printStackTrace();
29         }
30     }
31
32     //
33
protected String JavaDoc getSystemID() {
34         return SYSTEM_ID;
35     }
36
37     protected String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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