1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.kernel.xml.Document;
21  import com.liferay.portal.kernel.xml.DocumentException;
22  import com.liferay.portal.kernel.xml.Element;
23  import com.liferay.portal.kernel.xml.SAXReaderUtil;
24  import com.liferay.portal.model.ServiceComponent;
25  
26  /**
27   * <a href="ServiceComponentImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class ServiceComponentImpl
32      extends ServiceComponentModelImpl implements ServiceComponent {
33  
34      public ServiceComponentImpl() {
35      }
36  
37      public void setData(String data) {
38          super.setData(data);
39  
40          _dataEl = null;
41      }
42  
43      public String getTablesSQL() {
44          return _getData("tables-sql");
45      }
46  
47      public String getSequencesSQL() {
48          return _getData("sequences-sql");
49      }
50  
51      public String getIndexesSQL() {
52          return _getData("indexes-sql");
53      }
54  
55      private String _getData(String name) {
56          try {
57              return _getDataEl().elementText(name);
58          }
59          catch (Exception e) {
60              _log.error(e, e);
61  
62              return StringPool.BLANK;
63          }
64      }
65  
66      private Element _getDataEl() throws DocumentException {
67          if (_dataEl == null) {
68              Document doc = SAXReaderUtil.read(getData());
69  
70              _dataEl = doc.getRootElement();
71          }
72  
73          return _dataEl;
74      }
75  
76      private static Log _log = LogFactoryUtil.getLog(ServiceComponentImpl.class);
77  
78      private Element _dataEl;
79  
80  }