| FileTopicType.java |
1 /**
2 * Main responsibilites:
3 * 1. Collaborate with cls=FileEventClient to manage command-line args.
4 * Semantic is that the arg values will collaborate with "listFiles".
5 *
6 * 2. Create a list of files that represent the data that was just
7 * produced and that needs to be published.
8 *
9 * Details:
10 * decide where to get the correct cmdLine args..
11 * Arg values will then be used to create a fileList with a call to
12 * "setFiles()". SetFiles activity collaborates with FileSelector class.
13 *
14 * Sample call:
15 * this.setFiles(FileSelector.getFiles(args[n], args[n+1]))
16 *
17 * @param args - see "this.init()"
18 */
19/* Java class "FileTopicBean.java" generated from Poseidon for UML.
20 * Poseidon for UML is developed by <A HREF="http://www.gentleware.com">Gentleware</A>.
21 * Generated with <A HREF="http://jakarta.apache.org/velocity/">velocity</A> template engine.
22 */
23package com.borneo.po.event;
24
25import java.util.Collection;
26import java.util.StringTokenizer;
27
28import org.apache.log4j.Logger;
29import org.apache.log4j.PropertyConfigurator;
30
31import com.borneo.util.FileSelector;
32import com.borneo.util.POProperty;
33/**
34 */
35public class FileTopicType implements FileTopic {
36
37 ///////////////////////////////////////
38 // attributes
39 protected static Logger log;
40
41/**
42 */
43 private Collection file; // of type String
44
45/**
46 * <p>
47 * Represents ...
48 * </p>
49 */
50 private String topic;
51 ///////////////////////////////////////
52 // operations
53 public FileTopicType (){
54 }
55 public FileTopicType (String arg, Collection collection){
56 setTopic(arg);
57 setFiles(collection);
58 }
59
60 public FileTopicType (String[] args){
61
62 if (this.init(args)){
63 if(log.isDebugEnabled() ){POProperty.properties.list(System.out);}
64 }
65 else {
66 log.error("usage : req'd arg missing (arg=data.source.filename or arg=data.source.regex");
67 }
68 }
69 /**
70 * Property values affect "source" and "target" of the data transport.
71 * <p>A client request to create an event wrapper for some new data
72 * has presented here. Before that data can be wrapped in an event
73 * and posted, some config work needs doing.</p><p>
74 * Config properties for the file exchange can come from either
75 * Command Line or more static version in the config file.
76 * The client's command line args may be used to override
77 * Configuration key/value pairs contained in the config
78 * file. Any of the "source" elements below may be included
79 * on the cmdLne using "key=value" expressions.
80 * Sample cmdLne arg :
81 * $java clsNme data.source.lastfile=2003-07-29T15:23:30.609-08:00
82 *
83 * Semantic description of arg above :
84 * when selecting files from the sourcedirectory, using
85 * either filename or pattern for the file names, apply
86 * a "TimeStamp" filter to each prospective file. Pass the
87 * file only if it has a Timestamp indicating that it was
88 * created SINCE the value for XML Data Type=DATE indicated
89 * by valueOf "lastfile" element.
90 *
91 * * * * * * XML SCHEMA - source/target for data exchange * * *
92 <fileAssociation>
93 <source>
94 <filename>my_purchase_order.txt</filename>
95 <sourcedirectory>C:\intranet\dist\work\data</sourcedirectory>
96 <regex>walmart_po.*\.txt</regex>
97 <lastfile>2003-07-29T15:23:30.609-08:00</lastfile>
98 </source>
99 <target>
00 <targetdirectory>data</targetdirectory>
01 </target>
02 </fileAssociation>
03 * * * * * * XML SCHEMA - end
04 * * * * * * * * * * * * * * * * * * * * * * * * * * **
05 * @param args - command line args in the list below may be used
06 * to overide configuration file properties.
07 * Note : filename or regex is REQUIRED
08 * sourcedirectory is REQUIRED
09 * * * * * * * * * * * * * * * * * * * * * * * * * * **
10 * * * * * * CMD LINE Args - source/target for data exchange * * *
11 data.source.filename=
12 data.source.sourcedirectory=J:\\po_1_2\\config
13 data.source.regex=
14 data.source.lastfile=
15 data.topic.name=mytest
16 data.topic.action=publish
17
18 * @return
19 */
20 private boolean init(String[] args){
21
22 for (int i=0; i < args.length;i++){
23 StringTokenizer myst = new StringTokenizer (args[i] ,"=",false);
24 if ( myst.countTokens() > 1 ){
25 this.syncProperty(myst.nextToken(),myst.nextToken());
26 }
27 }
28 if (
29 ! POProperty.get("data.source.regex").equalsIgnoreCase("")
30 &&
31 POProperty.get("data.source.filename").equalsIgnoreCase("")
32 )
33 {
34 this.setFiles(
35 FileSelector.getFiles(
36 POProperty.get(
37 "data.source.sourcedirectory"
38 )
39 , POProperty.get(
40 "data.source.regex"
41 )
42 )
43 );
44
45 return true;
46 } else
47// TODO this isn't really correct to allow a regex as valuOF "filename"
48 { if(
49 POProperty.get("data.source.regex").equalsIgnoreCase("")
50 &&
51 ! POProperty.get("data.source.filename").equalsIgnoreCase("")
52 ){
53 this.setFiles(
54 FileSelector.getFiles(
55 POProperty.get(
56 "data.source.sourcedirectory"
57 )
58 , POProperty.get(
59 "data.source.filename"
60 )
61 )
62 );
63 return true;
64 } else{
65 return false;
66 }
67 }
68
69
70 }
71 private void syncProperty (String key, String val){
72 POProperty.properties.setProperty(key,val);
73 // TODO see more robust reconciliation of what may
74 // present via CmdLine versus what properties file
75 // has for values of the same "keys"
76 // sample belo from one of the Axis classes by Apache
77/* if(name == null || value == null)
78 return;
79 if(name.equals("javax.xml.rpc.security.auth.username"))
80 {
81 if(!(value instanceof String))
82 throw new IllegalArgumentException(JavaUtils.getMessage("badProp00", new String[] {
83 name, "java.lang.String", value.getClass().getName()
84 }));
85 setUsername((String)value);
86 } else
87 if(name.equals("javax.xml.rpc.security.auth.password")){}
88*/
89 }
90
91/**
92 * <p>
93 * Does ...
94 * </p><p>
95 *
96 * @return a String with ...
97 * </p>
98 */
99 public String getTopic() {
00// return topic;
01// delegate
02 return POProperty.properties.getProperty("data.topic.name");
03 } // end getTopic
04
05/**
06 * <p>
07 * Does ...
08 * </p><p>
09 *
10 * </p><p>
11 *
12 * @param _topic ...
13 * </p>
14 */
15 public void setTopic(String _topic) {
16// topic = _topic;
17// delegate
18 POProperty.properties.setProperty(
19 "data.topic.name"
20 ,_topic
21 );
22
23 } // end setTopic
24
25/**
26 * <p>
27 * Does ...
28 * </p><p>
29 *
30 * @return a Collection with ...
31 * </p>
32 */
33 public Collection getFiles() {
34 return file;
35 } // end getFiles
36
37/**
38 * <p>
39 * Does ...
40 * </p><p>
41 *
42 * </p><p>
43 *
44 * @param _file ...
45 * </p>
46 */
47 public void setFiles(Collection _file) {
48 file = _file;
49 } // end setFiles
50
51/**
52 * <p>
53 * Does ...
54 * </p><p>
55 *
56 * </p><p>
57 *
58 * @param _file ...
59 * </p>
60 */
61 public void addFile(String _file) {
62 if (! file.contains(_file)) file.add(_file);
63 } // end addFile
64
65/**
66 * <p>
67 * Does ...
68 * </p><p>
69 *
70 * </p><p>
71 *
72 * @param _file ...
73 * </p>
74 */
75 public void removeFile(String _file) {
76 file.remove(_file);
77 } // end removeFile
78
79 static
80 {
81 log = Logger.getLogger((com.borneo.po.event.FileTopicType.class).getName());
82 PropertyConfigurator.configure(com.borneo.po.event.FileTopicType.class.getClassLoader().getResource(
83 "config/log4j.properties"
84 ));
85 }
86
87} // end FileTopicBean
88
89
90
91