KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > labelincrementers > PropertyFileLabelIncrementer


1 package net.sourceforge.cruisecontrol.labelincrementers;
2
3 import java.io.FileInputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
6 import java.util.Properties JavaDoc;
7
8 import net.sourceforge.cruisecontrol.LabelIncrementer;
9
10 import org.apache.log4j.Logger;
11 import org.jdom.Element;
12
13 public class PropertyFileLabelIncrementer implements LabelIncrementer {
14     private static final Logger LOG = Logger.getLogger(PropertyFileLabelIncrementer.class);
15
16     private String JavaDoc propertyFile;
17
18     private String JavaDoc propertyName;
19
20     private boolean preBuildIncrementer;
21
22     public String JavaDoc incrementLabel(String JavaDoc oldLabel, Element buildLog) {
23         return getLabel();
24     }
25
26     public boolean isValidLabel(String JavaDoc label) {
27         return true;
28     }
29
30     public boolean isPreBuildIncrementer() {
31         return this.preBuildIncrementer;
32     }
33
34     public String JavaDoc getDefaultLabel() {
35         return getLabel();
36     }
37
38     public void setPreBuildIncrementer(boolean preBuildIncrementer) {
39         this.preBuildIncrementer = preBuildIncrementer;
40     }
41
42     public void setPropertyFile(String JavaDoc propertyFile) {
43         this.propertyFile = propertyFile;
44     }
45
46     public void setPropertyName(String JavaDoc propertyName) {
47         this.propertyName = propertyName;
48     }
49
50     private String JavaDoc getLabel() {
51         InputStream JavaDoc is = null;
52         try {
53             is = new FileInputStream JavaDoc(propertyFile);
54             Properties JavaDoc p = new Properties JavaDoc();
55             p.load(is);
56
57             String JavaDoc label = p.getProperty(propertyName);
58             LOG.info("Retrieved label " + label);
59
60             return label;
61         } catch (IOException JavaDoc ex) {
62             String JavaDoc msg = "Unable to retrieve label " + ex.getMessage();
63             LOG.error(msg, ex);
64             throw new RuntimeException JavaDoc(msg);
65         } finally {
66             try {
67                 if (is != null) {
68                     is.close();
69                 }
70             } catch (Exception JavaDoc ex) {
71             }
72         }
73     }
74
75 }
76
Popular Tags