1 |
|
package be.dvw.administration.services.instruments; |
2 |
|
|
3 |
|
import org.exolab.castor.xml.Unmarshaller; |
4 |
|
import org.exolab.castor.xml.MarshalException; |
5 |
|
import org.exolab.castor.xml.ValidationException; |
6 |
|
import org.exolab.castor.xml.Marshaller; |
7 |
|
import org.apache.commons.logging.Log; |
8 |
|
import org.apache.commons.logging.LogFactory; |
9 |
|
|
10 |
|
import java.util.List; |
11 |
|
import java.util.Vector; |
12 |
|
import java.io.*; |
13 |
|
|
14 |
|
import be.dvw.administration.model.Score; |
15 |
|
import be.dvw.administration.model.Instrument; |
16 |
|
import be.dvw.administration.mvc.actions.ScoreAction; |
17 |
|
import be.dvw.administration.util.FileUtils; |
18 |
|
import be.dvw.administration.services.scores.ScoreService; |
19 |
|
import be.dvw.administration.services.scores.ScoreServiceCastorImpl; |
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
12 |
public class InstrumentServiceCastorImpl implements InstrumentService |
27 |
|
{ |
28 |
|
|
29 |
24 |
private static Log LOG = LogFactory.getLog(InstrumentServiceCastorImpl.class); |
30 |
|
|
31 |
|
public List getAll() |
32 |
|
throws Exception |
33 |
|
{ |
34 |
|
try |
35 |
|
{ |
36 |
6 |
LOG.debug("Getting all instruments"); |
37 |
|
|
38 |
6 |
InputStreamReader reader = FileUtils.getInputStreamReader("etc/instrumentlijst-all.xml"); |
39 |
|
|
40 |
6 |
List list = (List)Unmarshaller.unmarshal(List.class, reader); |
41 |
6 |
LOG.debug("Returning all instruments"); |
42 |
6 |
return list; |
43 |
|
} |
44 |
0 |
catch (Exception e) |
45 |
|
{ |
46 |
0 |
throw new Exception("STOP!!!", e); |
47 |
|
} |
48 |
|
} |
49 |
|
|
50 |
|
public Instrument load(int id) throws IOException, ValidationException, MarshalException |
51 |
|
{ |
52 |
6 |
LOG.debug("Loading partituur with id [" + id + "]"); |
53 |
|
|
54 |
6 |
String fileName = new StringBuffer ("etc/instrument_").append(id).append(".xml").toString(); |
55 |
6 |
InputStreamReader reader = FileUtils.getInputStreamReader(fileName); |
56 |
|
|
57 |
6 |
Instrument p = (Instrument)Unmarshaller.unmarshal(Instrument.class, reader); |
58 |
6 |
LOG.debug(new StringBuffer(). |
59 |
|
append("\n=========================\n"). |
60 |
|
append(p.toString()). |
61 |
|
append("\n=========================\n loaded").toString()); |
62 |
|
|
63 |
6 |
return p; |
64 |
|
} |
65 |
|
|
66 |
|
public List search(String searchString) throws Exception { |
67 |
|
try |
68 |
|
{ |
69 |
0 |
LOG.debug("Getting all instruments"); |
70 |
|
|
71 |
0 |
InputStreamReader reader = FileUtils.getInputStreamReader("etc/instrumentlijst-search.xml"); |
72 |
|
|
73 |
0 |
List list = (List) Unmarshaller.unmarshal(List.class, reader); |
74 |
0 |
LOG.debug("Returning " + list.size() + " search results "); |
75 |
0 |
return list; |
76 |
|
} |
77 |
0 |
catch (Exception e) |
78 |
|
{ |
79 |
0 |
throw new Exception("STOP!!!", e); |
80 |
|
} |
81 |
|
} |
82 |
|
|
83 |
|
public float getPurchaseValue() |
84 |
|
{ |
85 |
0 |
return 1000; |
86 |
|
} |
87 |
|
|
88 |
|
public int getTotalNumber() { |
89 |
0 |
return 236; |
90 |
|
} |
91 |
|
|
92 |
|
public float getCurrentValue() { |
93 |
0 |
return 123; |
94 |
|
} |
95 |
|
|
96 |
|
public Instrument save(Instrument instrument, boolean newInstrument) |
97 |
|
throws MarshalException, ValidationException, IOException |
98 |
|
{ |
99 |
0 |
LOG.debug("Creating new instrument? " + newInstrument); |
100 |
0 |
LOG.debug(new StringBuffer(). |
101 |
|
append("\n=========================\n"). |
102 |
|
append(instrument.toString()). |
103 |
|
append("\n=========================\n should be saved").toString()); |
104 |
0 |
if (newInstrument) |
105 |
0 |
instrument.setId(9999); |
106 |
0 |
return instrument; |
107 |
|
} |
108 |
|
|
109 |
|
public void delete(int id) throws Exception { |
110 |
0 |
LOG.debug("Deleted instrument " + id); |
111 |
0 |
} |
112 |
|
|
113 |
|
|
114 |
|
} |