View Javadoc
1   package org.kuali.ole.handler;
2   
3   import com.thoughtworks.xstream.XStream;
4   import org.kuali.ole.bo.explain.*;
5   import org.kuali.ole.converters.*;
6   
7   /**
8    * Created with IntelliJ IDEA.
9    * User: ?
10   * Date: 7/19/12
11   * Time: 5:12 PM
12   * To change this template use File | Settings | File Templates.
13   */
14  public class OleSRUExplainOperationHandler {
15  
16      /**
17       * this method converts OleSRUExplainResponse object to an XML with required name space
18       *
19       * @param oleSRUExplainResponse object
20       * @return xml as a string
21       */
22      public String toXML(OleSRUExplainResponse oleSRUExplainResponse) {
23  
24          StringBuffer stringBuffer = new StringBuffer();
25          stringBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
26          stringBuffer.append("\n");
27          XStream xStream = new XStream();
28          xStream.alias("sru:explainResponse", OleSRUExplainResponse.class);
29          xStream.aliasField("sru:version", OleSRUExplainResponse.class, "version");
30          xStream.aliasField("sru:record", OleSRUExplainResponse.class, "record");
31          xStream.aliasField("sru:recordPacking", OleSRUExplainRecord.class, "recordPacking");
32          xStream.aliasField("sru:recordSchema", OleSRUExplainRecord.class, "recordSchema");
33          xStream.aliasField("sru:recordData", OleSRUExplainRecord.class, "recordData");
34          xStream.aliasField("zr:explain", OleSRUExplainRecordData.class, "explain");
35          xStream.aliasField("zr:serverInfo", OleSRUExplainOperation.class, "serverInfo");
36          xStream.aliasField("zr:databaseInfo", OleSRUExplainOperation.class, "databaseInfo");
37          xStream.aliasField("zr:indexInfo", OleSRUExplainOperation.class, "indexInfo");
38          xStream.aliasField("zr:schemaInfo", OleSRUExplainOperation.class, "schemaInfo");
39          xStream.aliasField("zr:configInfo", OleSRUExplainOperation.class, "configInfo");
40          xStream.aliasField("zr:host", OleSRUExplainServerInfo.class, "host");
41          xStream.aliasField("zr:port", OleSRUExplainServerInfo.class, "port");
42          xStream.aliasField("zr:database", OleSRUExplainServerInfo.class, "database");
43          //xStream.aliasField("zr:title", OleSRUExplainDatabaseInfo.class, "title");
44          xStream.aliasField("zr:index", OleSRUExplainIndexInfo.class, "index");
45          xStream.aliasField("zr:set", OleSRUExplainIndexInfo.class, "set");
46          xStream.aliasField("zr:map", OleSRUExplainIndex.class, "indexMap");
47          xStream.aliasField("zr:name", OleSRUExplainIndexMap.class, "name");
48          xStream.aliasField("zr:schema", OleSRUExplainSchemaInfo.class, "schema");
49          xStream.aliasField("zr:title", OleSRUExplainSchema.class, "title");
50          xStream.aliasField("zr:default", OleSRUExplainConfigurationInfo.class, "defaultValue");
51          xStream.aliasField("zr:setting", OleSRUExplainConfigurationInfo.class, "setting");
52          xStream.aliasField("zr:supports", OleSRUExplainConfigurationInfo.class, "supports");
53          xStream.registerConverter(new OleSRUExplainServerInfoConverter());
54          xStream.registerConverter(new OleSRUExplainDatabaseInfoConverter());
55          xStream.registerConverter(new OleSRUExplainIndexInfoConverter());
56          xStream.registerConverter(new OleSRUExplainSchemaInfoConverter());
57          xStream.registerConverter(new OleSRUExplainIndexMapNameConverter());
58          xStream.registerConverter(new OleSRUExplainConfigInfoSupportConverter());
59          xStream.registerConverter(new OleSRUExplainConfigInfoSettingConverter());
60          xStream.registerConverter(new OleSRUExplainConfigInfoDefaultConverter());
61          String xml = xStream.toXML(oleSRUExplainResponse);
62          xml = xml.replaceAll("<sru:explainResponse>", "<sru:explainResponse xmlns:sru=\"http://www.loc.gov/zing/srw/\">");
63          xml = xml.replaceAll("<zr:explain>", " <zr:explain xmlns:zr=\"http://explain.z3950.org/dtd/2.1/\">");
64          stringBuffer.append(xml);
65          return stringBuffer.toString();
66      }
67  
68  
69  }