Adobe 38000382 JRun Guide - Page 111

Using XML metadata, Nested elements have their own metadata classes.

Page 111 highlights

Using XML metadata Follow these steps to edit the XML files. To edit XML files: 1 Find the appropriate class name. For web.xml, the JRunWebAppMetaData class instantiates this file. 2 Create a new class. If the file exists, you must execute the importXML(URL url) method on it. The URL is the file. If the file does not exist, you do not have to take any additional steps. You will set the location when you save the changes. 3 Issue getter and setter methods, as needed. The XML metadata classes include getters and setters for all elements found in the DTD. For example, if you want to set the value of the context-root in the web.xml file, you use the following method: fmd.setContextRoot("/root"); If there are multiple subelements, use the addXXX method, where XXX is the name of the element. For example, the following method adds several mappings for a filter in the web.xml file: fmmd.addURLPattern("/*"); You can also delete elements or set them to null. If an element does not extend XMLMetaData, use setFoo(null). Otherwise, call the XMLMetaData.remove method. When you import the XML file with the importXML method, JRun sets all the values using the following naming conventions: • First character is lowercase. • Hyphens are replaced with uppercase characters. • Nested elements have their own metadata classes. For example, the element context-root becomes contextRoot in your class. 4 Save the elements out to the file. 5 Call xmlclass.setMetaDataSource(file). 6 Call xmlclass.exportDocument. 7 Compile the class. Add jrun.jar to your classpath when compiling classes that use XML metadata methods. The following example compiles the MyMetaDataClass.java file: %> javac -classpath "c:/jrun4/lib/jrun.jar" MyMetaDataClass.java 8 Run the class. Add jrun.jar to your classpath when running classes that use XML metadata methods. If you created the class as a stand-alone Java application, you can execute the following: %> java -classpath "c:/jrun4/lib/jrun.jar" MyMetaDataClass Using XML metadata 97

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116

Using XML metadata
97
Using XML metadata
Follow these steps to edit the XML files.
To edit XML files:
1
Find the appropriate class name.
For web.xml, the
JRunWebAppMetaData
class instantiates this file.
2
Create a new class.
If the file exists, you must execute the
importXML(URL url)
method on it. The URL
is the file. If the file does not exist, you do not have to take any additional steps. You
will set the location when you save the changes.
3
Issue getter and setter methods, as needed. The XML metadata classes include getters
and setters for all elements found in the DTD. For example, if you want to set the
value of the context-root in the web.xml file, you use the following method:
fmd.setContextRoot("/root");
If there are multiple subelements, use the
addXXX
method, where
XXX
is the name of
the element. For example, the following method adds several mappings for a filter in
the web.xml file:
fmmd.addURLPattern("/*");
You can also delete elements or set them to null. If an element does not extend
XMLMetaData, use
setFoo(null)
. Otherwise, call the
XMLMetaData.remove
method.
When you import the XML file with the
importXML
method, JRun sets all the values
using the following naming conventions:
First character is lowercase.
Hyphens are replaced with uppercase characters.
Nested elements have their own metadata classes.
For example, the element
context-root
becomes
contextRoot
in your class.
4
Save the elements out to the file.
5
Call xmlclass.setMetaDataSource(file).
6
Call xmlclass.exportDocument.
7
Compile the class. Add jrun.jar to your classpath when compiling classes that use
XML metadata methods.
The following example compiles the MyMetaDataClass.java file:
%> javac -classpath "c:/jrun4/lib/jrun.jar" MyMetaDataClass.java
8
Run the class. Add jrun.jar to your classpath when running classes that use XML
metadata methods. If you created the class as a stand-alone Java application, you can
execute the following:
%> java -classpath "c:/jrun4/lib/jrun.jar" MyMetaDataClass