View Javadoc

1   package org.opensync.engine.server;
2   
3   import org.opensync.engine.server.Adapter;
4   import org.opensync.engine.server.adapter.*;
5   
6   import java.io.*;
7   import java.util.HashMap;
8   
9   /***
10   * This class encapsulate the concept of a source in the OpenSync application
11   */
12  
13  public class Source implements Serializable {
14    /***
15     * The source is a database source
16     *
17     */
18    public final static String TYPE_BD = "bd";
19    /***
20     * The source is a text source
21     *
22     */
23    public final static String TYPE_TXT = "txt";
24  
25    /***
26     * The name of the source
27     *
28     */
29    private String name;
30    /***
31     * The connector of the source
32     *
33     */
34    private Connector connector;
35    /***
36     * The return of the source
37     *
38     *
39     */
40    private Return ret;
41    /***
42     * The views of the source
43     *
44     */
45    //private Views views = new Views();
46    private HashMap views = new HashMap();
47  
48    /***
49     * Construct a source object
50     *
51     */
52    public Source() {
53    }
54    /***
55     * Set the name of the source
56     *
57     * @param	name the name of the source
58     */
59    public void setName(String name) {
60      this.name = name;
61    }
62    /***
63     * Get the name of the source
64     *
65     */
66    public String getName() {
67      return name;
68    }
69    /***
70     * Se the connector of the source
71     *
72     * @param	connector the conncetor of the source
73     */
74    public void setConnector(Connector connector) {
75      this.connector = connector;
76    }
77    /***
78     * Get the connector of the source
79     *
80     */
81    public Connector getConnector() {
82      return connector;
83    }
84    /***
85     * @param	protocol
86     */
87    /****/
88    /***
89     * Set the return of the source
90     *
91     * @param	ret the return of the source
92     */
93    public void setReturn(Return ret) {
94      this.ret = ret;
95    }
96    /***
97     * Get the return of the source
98     *
99     */
100   public Return getReturn() {
101     return ret;
102   }
103   /***
104    * Add a view to the source
105    *
106    * @param	view the view to add
107    */
108   public void addView(View view) {
109     //views.add(view);
110     views.put(view.getName(), view);
111   }
112   /***
113    * Get a view of the source
114    *
115    * @param	view the name of the view to get
116    */
117   public View getView(String view){
118     return (View)views.get(view);
119   }
120   /***
121    * Use for debug only
122    *
123    */
124   public String toString(){
125     StringBuffer buffer = new StringBuffer();
126     buffer.append("Source{\n");
127     buffer.append("\tname : ").append(name).append("\n");
128     if(connector != null){
129       buffer.append(connector);
130     }
131     if(ret != null){
132       buffer.append(ret.toString());
133     }
134     buffer.append(views);
135     return buffer.toString();
136   }
137   /***
138    * Get all views of the source
139    *
140    */
141   public HashMap getViews() {
142     return views;
143   }
144 
145   public void setViews(HashMap _views) {
146   	views.putAll(_views);
147   }
148 
149   public long lastModified() throws OpenSyncException, IOException {
150     String fileSeparator = System.getProperty("file.separator");
151     String configFolder = System.getProperty("opensync.configfolder");
152     configFolder = (configFolder == null ? "" : configFolder);
153 
154     long lastModified = -1;
155     Adapter anAdapter = getConnector().getAdapter();
156     if (anAdapter instanceof BDAdapter) {
157       String path = OpenSync.getInstance().getDirectoryPath("etc"+fileSeparator+configFolder+fileSeparator+"table", true);
158       File file = new File(path);
159       if (!(file.exists() && file.isDirectory())){
160 	throw new OpenSyncException("error.directory.not-found",new Object[]{path});
161       }
162       lastModified = new File(path + "/" + ((BDAdapter)anAdapter).getTablesDescriptor()).lastModified();
163       //System.out.println("Table "+path + "/" + ((BDAdapter)anAdapter).getTablesDescriptor()+" : "+lastModified);
164 
165       path = OpenSync.getInstance().getDirectoryPath("etc"+fileSeparator+configFolder+fileSeparator+"theme", true);
166       file = new File(path);
167       if (!(file.exists() && file.isDirectory())){
168 	throw new OpenSyncException("error.directory.not-found",new Object[]{path});
169       }
170       //System.out.println("Theme "+path + "/" + ((BDAdapter)anAdapter).getThemesDescriptor()+" : "+lastModified);
171       lastModified = Math.max(lastModified,
172 			      new File(path + "/" + ((BDAdapter)anAdapter).getThemesDescriptor()).lastModified());
173     }
174     //System.out.println("Source "+this.getName()+" : "+lastModified);
175     return lastModified;
176   }
177 }