View Javadoc

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