1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.banking.ri.blzdirectory;
22
23 import java.io.IOException;
24 import java.text.NumberFormat;
25 import java.text.ParseException;
26 import java.text.SimpleDateFormat;
27 import java.util.Date;
28 import java.util.Properties;
29
30
31
32
33
34
35
36
37
38 public abstract class AbstractPropertiesBankfileProvider implements BankfileProvider
39 {
40
41
42 private static final String BANKFILE_COUNT_PROPERTY = "BankleitzahlenVerzeichnis.bankfileCount";
43
44
45 private static final String BANKFILE_PREFIX = "BankleitzahlenDatei.";
46
47
48 private Properties properties;
49
50
51 public AbstractPropertiesBankfileProvider()
52 {
53 super();
54 }
55
56 public long getLastModifiedMillis() throws IOException
57 {
58 return 0L;
59 }
60
61 public final int getBankfileCount() throws IOException
62 {
63 try
64 {
65 final String value = this.getProperties().getProperty( BANKFILE_COUNT_PROPERTY, Integer.toString( 0 ) );
66 return NumberFormat.getIntegerInstance().parse( value ).intValue();
67 }
68 catch ( final ParseException e )
69 {
70 throw (IOException) new IOException( e.getMessage() ).initCause( e );
71 }
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85 public String getBankfileLocation( final int index ) throws IOException
86 {
87 if ( index < 0 || index >= this.getBankfileCount() )
88 {
89 throw new IndexOutOfBoundsException( Integer.toString( index ) );
90 }
91
92 final String propertyKey = BANKFILE_PREFIX + index + ".location";
93 final String location = this.getProperties().getProperty( propertyKey );
94 assert location != null : "Property '" + propertyKey + "' not found.";
95 return location;
96 }
97
98 public final Date getDateOfValidity( final int index ) throws IOException
99 {
100 if ( index < 0 || index >= this.getBankfileCount() )
101 {
102 throw new IndexOutOfBoundsException( Integer.toString( index ) );
103 }
104
105 try
106 {
107 final String propertyKey = BANKFILE_PREFIX + index + ".dateOfValidity";
108 final String value = this.getProperties().getProperty( propertyKey );
109 assert value != null : "Property '" + propertyKey + "' not found.";
110 return new SimpleDateFormat( "yyyyMMdd" ).parse( value );
111 }
112 catch ( final ParseException e )
113 {
114 throw (IOException) new IOException( e.getMessage() ).initCause( e );
115 }
116 }
117
118 public final Date getDateOfExpiration( final int index ) throws IOException
119 {
120 if ( index < 0 || index >= this.getBankfileCount() )
121 {
122 throw new IndexOutOfBoundsException( Integer.toString( index ) );
123 }
124
125 try
126 {
127 final String propertyKey = BANKFILE_PREFIX + index + ".dateOfExpiration";
128 final String value = this.getProperties().getProperty( propertyKey );
129 assert value != null : "Property '" + propertyKey + "' not found.";
130 return new SimpleDateFormat( "yyyyMMdd" ).parse( value );
131 }
132 catch ( final ParseException e )
133 {
134 throw (IOException) new IOException( e.getMessage() ).initCause( e );
135 }
136 }
137
138
139
140
141
142
143
144
145 public Properties getProperties() throws IOException
146 {
147 if ( this.properties == null )
148 {
149 this.properties = new Properties();
150 }
151
152 return this.properties;
153 }
154
155
156
157
158
159
160 public void setProperties( final Properties value )
161 {
162 this.properties = value;
163 }
164
165 }