View Javadoc

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   * User: Toon
23   * Date: 4-jul-2005
24   * Time: 19:31:26
25   */
26  public class InstrumentServiceCastorImpl implements InstrumentService
27  {
28  
29      private static Log LOG = LogFactory.getLog(InstrumentServiceCastorImpl.class);
30  
31      public List getAll()
32              throws Exception
33      {
34          try
35          {
36              LOG.debug("Getting all instruments");
37              // Create a Reader to the file to unmarshal from
38              InputStreamReader reader = FileUtils.getInputStreamReader("etc/instrumentlijst-all.xml");
39              // Marshal the person object
40              List list = (List)Unmarshaller.unmarshal(List.class, reader);
41              LOG.debug("Returning all instruments");
42              return list;
43          }
44          catch (Exception e)
45          {
46              throw new Exception("STOP!!!", e);
47          }
48      }
49  
50      public Instrument load(int id) throws IOException, ValidationException, MarshalException
51      {
52          LOG.debug("Loading partituur with id [" + id  + "]");
53          // Create a Reader to the file to unmarshal from
54          String fileName = new StringBuffer ("etc/instrument_").append(id).append(".xml").toString();
55          InputStreamReader reader = FileUtils.getInputStreamReader(fileName);
56          // Marshal the person object
57          Instrument p = (Instrument)Unmarshaller.unmarshal(Instrument.class, reader);
58          LOG.debug(new StringBuffer().
59                  append("\n=========================\n").
60                  append(p.toString()).
61                  append("\n=========================\n loaded").toString());
62  
63          return p;
64      }
65  
66      public List search(String searchString) throws Exception {
67          try
68          {
69              LOG.debug("Getting all instruments");
70              // Create a Reader to the file to unmarshal from
71              InputStreamReader reader = FileUtils.getInputStreamReader("etc/instrumentlijst-search.xml");
72              // Marshal the list object
73              List list = (List) Unmarshaller.unmarshal(List.class, reader);
74              LOG.debug("Returning " + list.size() + " search results ");
75              return list;
76          }
77          catch (Exception e)
78          {
79              throw new Exception("STOP!!!", e);
80          }
81      }
82  
83      public float getPurchaseValue()
84      {
85          return 1000;  //To change body of implemented methods use File | Settings | File Templates.
86      }
87  
88      public int getTotalNumber() {
89          return 236;  //To change body of implemented methods use File | Settings | File Templates.
90      }
91  
92      public float getCurrentValue() {
93          return 123;  //To change body of implemented methods use File | Settings | File Templates.
94      }
95  
96      public Instrument save(Instrument instrument, boolean newInstrument)
97              throws MarshalException, ValidationException, IOException
98      {
99          LOG.debug("Creating new instrument? " + newInstrument);
100         LOG.debug(new StringBuffer().
101                 append("\n=========================\n").
102                 append(instrument.toString()).
103                 append("\n=========================\n should be saved").toString());
104         if (newInstrument)
105             instrument.setId(9999);
106         return instrument;
107     }
108 
109     public void delete(int id) throws Exception {
110         LOG.debug("Deleted instrument " + id);
111     }
112 
113 
114 }