001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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 String getIndexesSQL() {
035                    return _getData("indexes-sql");
036            }
037    
038            @Override
039            public String getSequencesSQL() {
040                    return _getData("sequences-sql");
041            }
042    
043            @Override
044            public String getTablesSQL() {
045                    return _getData("tables-sql");
046            }
047    
048            @Override
049            public void setData(String data) {
050                    super.setData(data);
051    
052                    _dataEl = null;
053            }
054    
055            private String _getData(String name) {
056                    try {
057                            return _getDataEl().elementText(name);
058                    }
059                    catch (Exception e) {
060                            _log.error(e, e);
061    
062                            return StringPool.BLANK;
063                    }
064            }
065    
066            private Element _getDataEl() throws DocumentException {
067                    if (_dataEl == null) {
068                            Document doc = SAXReaderUtil.read(getData());
069    
070                            _dataEl = doc.getRootElement();
071                    }
072    
073                    return _dataEl;
074            }
075    
076            private static Log _log = LogFactoryUtil.getLog(ServiceComponentImpl.class);
077    
078            private Element _dataEl;
079    
080    }