Wiki source code of About the Properties file
Last modified by Theodore Petrosky on 2016/06/28 12:30
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
6.1 | 1 | == Introduction == |
2 | |||
![]() |
18.1 | 3 | Most applications need a place to hold application configuration information. In java, a file with simple entries in traditional [[java.util.Properties>>url:http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream)||shape="rect"]] format can be read and merged with the System properties, usually at application launch time. The traditional (as distinct from the XML format supported by java 1.5) simple format of a java properties file is like this: |
![]() |
6.1 | 4 | |
5 | {{panel}} | ||
6 | myproperty=12345 | ||
![]() |
18.1 | 7 | myotherproperty=This is a sentence |
![]() |
6.1 | 8 | {{/panel}} |
9 | |||
![]() |
18.1 | 10 | WebObjects manages application preferences using a similar mechanism implemented by its [[com.webobjects.foundation.NSProperties>>url:http://developer.apple.com/documentation/MacOSXServer/Reference/WO54_Reference/com/webobjects/foundation/NSProperties.html||shape="rect"]] class. The file format is as per the spec. In many references you will see specs say that a certain file is in java.io.Properties file format, however if I am not mistaken, they really mean the java.util.Properties, since even as far back as Java 1.1 API, there was no such class as java.io.Properties. |
![]() |
6.1 | 11 | |
![]() |
19.1 | 12 | In any case, WebObjects directly supports the use of [[Java 1.4 style properties>>url:http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html||shape="rect"]] entries in the file named Resources/Properties in the woa and framework bundle format. |
![]() |
6.1 | 13 | |
14 | == Using Properties in WebObjects == | ||
15 | |||
16 | For a traditional WebObjects application, Properties are read first from the framework bundles and finally from the application bundle. Hence frameworks can have default values in their Properties file and those framework configuration properties can be **over-ridden** in the application's Properties file | ||
17 | |||
18 | No coding is needed to use property entries in the Properties file. WebObjects automatically reads them in at application launch time and merges them with the system properties, so they can be accessed using System.getProperty | ||
19 | |||
20 | == Enhanced Properties management in WOnder == | ||
21 | |||
22 | Project WOnder enhances the use of the traditional WebObjects Properties file in a number of ways: | ||
23 | |||
24 | === ERXProperties === | ||
25 | |||
26 | WOnder introduces the class ERXProperties that provides enhancements to the kind and format of Properties files | ||
27 | |||
28 | === Configurability === | ||
29 | |||
![]() |
16.1 | 30 | Firstly, WOnder makes useful settings available as Properties which are not available out of the box as simple Properties entries in traditional WebObjects applications. |
![]() |
6.1 | 31 | |
![]() |
12.1 | 32 | For example: |
![]() |
6.1 | 33 | |
![]() |
12.1 | 34 | * EOModel connection dictionary parameters for each model |
35 | * log4j configuration properties | ||
36 | * Prototype model loading order | ||
37 | |||
![]() |
6.1 | 38 | === User Properties === |
39 | |||
![]() |
16.1 | 40 | If your user name is 'joe', then in your WebObjects application, you can create a file named Properties.joe which is read in last when joe launches his WebObjects app in his Eclipse development enviromnent. This is useful for development teams. Each team member can have properties specific to his/her own development enviromnent such as smtp server, logging properties, database connection dictionary settings, etc. |
![]() |
12.1 | 41 | |
42 | === Derived Properties === | ||
43 | |||
44 | WOnder supports the use of @@ delimiters so that certain properties can depend on previously defined properties. | ||
45 | |||
46 | {{code title="Derived Properties example"}} | ||
![]() |
16.1 | 47 | ## Set the smtp server host one time here... and the rest get it thru |
![]() |
12.1 | 48 | #+ use of derived propertiesw calculated on the fly when loaded into System properties. |
49 | app.smtpserver=mail.domain.com | ||
50 | |||
51 | ## WebObjects smtp host setting | ||
52 | WOSMTPHost=@@app.smtpserver@@ | ||
53 | |||
54 | ## Setting for a log4j smtp appender named 'myMail' | ||
55 | log4j.appender.myMail.SMTPHost=@@app.smtpserver@@ | ||
56 | |||
57 | ## Setting for Wonder's ERJavaMail framework | ||
58 | er.javamail.smtpHost=@@app.smtpserver@@ | ||
59 | |||
60 | ## Setting for Sun's javamail library | ||
61 | mail.smtp.host=@@app.smtpserver@@ | ||
62 | |||
63 | {{/code}} | ||
64 | |||
65 | === Accessing properties in WOnder === | ||
66 | |||
67 | Use ERXProperties static methods to get system properties from your Properties files and it offers a bunch of convenience methods to return values coerced into thyeir intended object types. It even handles arrays .... look at the source or API for ERXProperties for more details. | ||
68 | |||
69 | == Conclusion == | ||
70 | |||
![]() |
18.1 | 71 | So, simply putting application and logging properties into the Properties file means that all your configuration is in one place **and** each member of the development team can override those deployment settings with their own user based Properties files. Useful when they want to add DEBUG logging on stuff that other team members are not interested in. |