001    /**
002     * Copyright (c) 2000-2010 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    import com.liferay.portal.model.ServiceComponent;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class ServiceComponentImpl
030            extends ServiceComponentModelImpl implements ServiceComponent {
031    
032            public ServiceComponentImpl() {
033            }
034    
035            public void setData(String data) {
036                    super.setData(data);
037    
038                    _dataEl = null;
039            }
040    
041            public String getTablesSQL() {
042                    return _getData("tables-sql");
043            }
044    
045            public String getSequencesSQL() {
046                    return _getData("sequences-sql");
047            }
048    
049            public String getIndexesSQL() {
050                    return _getData("indexes-sql");
051            }
052    
053            private String _getData(String name) {
054                    try {
055                            return _getDataEl().elementText(name);
056                    }
057                    catch (Exception e) {
058                            _log.error(e, e);
059    
060                            return StringPool.BLANK;
061                    }
062            }
063    
064            private Element _getDataEl() throws DocumentException {
065                    if (_dataEl == null) {
066                            Document doc = SAXReaderUtil.read(getData());
067    
068                            _dataEl = doc.getRootElement();
069                    }
070    
071                    return _dataEl;
072            }
073    
074            private static Log _log = LogFactoryUtil.getLog(ServiceComponentImpl.class);
075    
076            private Element _dataEl;
077    
078    }