001    /**
002     * Copyright (c) 2000-2011 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    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    }