001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.xml.Document;
021    import com.liferay.portal.kernel.xml.DocumentException;
022    import com.liferay.portal.kernel.xml.Element;
023    import com.liferay.portal.kernel.xml.SAXReaderUtil;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class ServiceComponentImpl extends ServiceComponentBaseImpl {
029    
030            public ServiceComponentImpl() {
031            }
032    
033            @Override
034            public void setData(String data) {
035                    super.setData(data);
036    
037                    _dataEl = null;
038            }
039    
040            public String getTablesSQL() {
041                    return _getData("tables-sql");
042            }
043    
044            public String getSequencesSQL() {
045                    return _getData("sequences-sql");
046            }
047    
048            public String getIndexesSQL() {
049                    return _getData("indexes-sql");
050            }
051    
052            private String _getData(String name) {
053                    try {
054                            return _getDataEl().elementText(name);
055                    }
056                    catch (Exception e) {
057                            _log.error(e, e);
058    
059                            return StringPool.BLANK;
060                    }
061            }
062    
063            private Element _getDataEl() throws DocumentException {
064                    if (_dataEl == null) {
065                            Document doc = SAXReaderUtil.read(getData());
066    
067                            _dataEl = doc.getRootElement();
068                    }
069    
070                    return _dataEl;
071            }
072    
073            private static Log _log = LogFactoryUtil.getLog(ServiceComponentImpl.class);
074    
075            private Element _dataEl;
076    
077    }