001    /**
002     * Copyright (c) 2000-present 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.model.Country;
020    import com.liferay.portal.model.ListType;
021    import com.liferay.portal.model.Region;
022    import com.liferay.portal.service.CountryServiceUtil;
023    import com.liferay.portal.service.ListTypeServiceUtil;
024    import com.liferay.portal.service.RegionServiceUtil;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class AddressImpl extends AddressBaseImpl {
030    
031            @Override
032            public Country getCountry() {
033                    Country country = null;
034    
035                    try {
036                            country = CountryServiceUtil.getCountry(getCountryId());
037                    }
038                    catch (Exception e) {
039                            country = new CountryImpl();
040    
041                            if (_log.isWarnEnabled()) {
042                                    _log.warn(e);
043                            }
044                    }
045    
046                    return country;
047            }
048    
049            @Override
050            public Region getRegion() {
051                    Region region = null;
052    
053                    try {
054                            region = RegionServiceUtil.getRegion(getRegionId());
055                    }
056                    catch (Exception e) {
057                            region = new RegionImpl();
058    
059                            if (_log.isWarnEnabled()) {
060                                    _log.warn(e);
061                            }
062                    }
063    
064                    return region;
065            }
066    
067            @Override
068            public ListType getType() {
069                    ListType type = null;
070    
071                    try {
072                            type = ListTypeServiceUtil.getListType(getTypeId());
073                    }
074                    catch (Exception e) {
075                            type = new ListTypeImpl();
076    
077                            if (_log.isWarnEnabled()) {
078                                    _log.warn(e);
079                            }
080                    }
081    
082                    return type;
083            }
084    
085            private static final Log _log = LogFactoryUtil.getLog(AddressImpl.class);
086    
087    }