View Javadoc

1   package org.opensync.engine.server;
2   
3   import java.io.*;
4   import java.net.*;
5   import java.sql.*;
6   import java.util.*;
7   
8   import org.dom4j.*;
9   import org.dom4j.io.*;
10  import org.xml.sax.SAXException;
11  /***
12   * The default implementation of the adpater interface
13   */
14  
15  abstract public class DefaultAdapter implements Adapter, Serializable {
16  
17   /***
18     * The connector used by the adapter
19     *
20     */
21    protected Connector connector;
22  
23    /***
24     * The url of the tables descriptor
25     *
26     */
27    protected String tablesDescriptor;
28    /***
29     * The url of the themes descriptor
30     *
31     */
32    protected String themesDescriptor;
33  
34  
35    /***
36     * Construct a DefaultAdapter
37     *
38     */
39    public DefaultAdapter() {
40    }
41  
42    public void init() {}
43  
44    public void release() throws SQLException {
45    }
46  
47    public void releaseWithException() throws SQLException {
48    }
49  
50  /***
51     * Set the tables descriptor
52     *
53     * @param tablesDescriptor the url of the tables descriptor
54     */
55    public void setTablesDescriptor(String tablesDescriptor) {
56      this.tablesDescriptor = tablesDescriptor;
57    }
58    /***
59     * Get the tables descriptor
60     *
61     */
62    public String getTablesDescriptor() {
63      return tablesDescriptor;
64    }
65    /***
66     * Set the themes descriptor
67     *
68     * @param themesDescriptor the url of the themes descriptor
69     */
70    public void setThemesDescriptor(String themesDescriptor) {
71      this.themesDescriptor = themesDescriptor;
72    }
73    /***
74     * Get the themes descriptor
75     *
76     */
77    public String getThemesDescriptor() {
78      return themesDescriptor;
79    }
80  
81    public Document readThemeDescriptor() throws FileNotFoundException, DocumentException, SAXException, MalformedURLException {
82      SAXReader xmlReader = new SAXReader(true);
83      String fileSeparator = System.getProperty("file.separator");
84      String configFolder = System.getProperty("opensync.configfolder");
85      configFolder = (configFolder == null ? "" : configFolder);
86  
87      String fullFileName = OpenSync.getInstance().getFilePath(fileSeparator+"etc"+fileSeparator+configFolder+fileSeparator+"theme"+fileSeparator + themesDescriptor,true);
88      Document doc = xmlReader.read(new File(fullFileName).toURL().toExternalForm());
89      return doc;
90    }
91  
92    public List getPKs(Document themes, String theme) throws DocumentException, FileNotFoundException, SAXException, MalformedURLException {
93      XPath xpathSelector = DocumentHelper.createXPath("/DICTIONARY/VIEW[@KeyWord='"+theme+"']/COLUMN[@IsPrimaryKey='TRUE']");
94      List results = xpathSelector.selectNodes(themes);
95      List pks = new ArrayList();
96      for ( Iterator iter = results.iterator(); iter.hasNext(); ) {
97        Element element = (Element) iter.next();
98        pks.add(element.attribute("KeyWord").getValue());
99      }
100     return pks;
101   }
102   /***
103    *
104    */
105    public void validate() throws OpenSyncException {
106    }
107   /***
108    * @param	descriptor
109    */
110   /***
111    * @param	driver
112    */
113   /****/
114   /***
115    * Adapt the the data source format to the OpenSync
116    * data format
117    *
118    * @exception	IOException
119    * @param	xml the view in source format
120    * @param	view the view
121    * @exception	Exception
122    */
123   abstract public String adaptInputView(String xml,View view, Statistic stat, Window win)throws Exception;
124   /***
125    * Adapt the the data OpenSync format to the
126    * data source format
127    *
128    * @param	xml the view in OpenSync format
129    * @param	view the view
130    * @exception	Exception
131    */
132   abstract public String adaptOutputView(String xml,View view, Statistic stat)throws Exception;
133 
134   /***
135    * The the connector used by the adapter
136    *
137    * @param	connector
138    */
139   public void setConnector(Connector connector) {
140     this.connector = connector;
141   }
142   /***
143    * Get the connector used by the adapter
144    *
145    */
146   public Connector getConnector() {
147     return connector;
148   }
149   /***
150    * Use for debug only
151    *
152    */
153   public String toString(){
154     StringBuffer buffer = new StringBuffer();
155     buffer.append("DefaultAdapter{\n");
156     buffer.append(connector);
157     buffer.append("}\n");
158     return buffer.toString();
159   }
160 
161   /***
162    *
163    * @param status
164    */
165   public void startReadInputFile(boolean status) {
166   }
167 
168 
169 }