001    /**
002     * Copyright (c) 2000-2012 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.util.LocaleUtil;
018    import com.liferay.portal.model.BaseModel;
019    import com.liferay.portal.model.CacheModel;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.expando.model.ExpandoBridge;
022    
023    import java.util.Collections;
024    import java.util.Locale;
025    import java.util.Map;
026    
027    /**
028     * The base implementation for all model classes. This class should never need
029     * to be used directly.
030     *
031     * @author Brian Wing Shun Chan
032     */
033    public abstract class BaseModelImpl<T> implements BaseModel<T> {
034    
035            public BaseModelImpl() {
036            }
037    
038            @Override
039            public abstract Object clone();
040    
041            public ExpandoBridge getExpandoBridge() {
042                    throw new UnsupportedOperationException();
043            }
044    
045            public Map<String, Object> getModelAttributes() {
046                    return Collections.emptyMap();
047            }
048    
049            public boolean isCachedModel() {
050                    return _cachedModel;
051            }
052    
053            public boolean isEscapedModel() {
054                    return _ESCAPED_MODEL;
055            }
056    
057            public boolean isNew() {
058                    return _new;
059            }
060    
061            public void resetOriginalValues() {
062            }
063    
064            public void setCachedModel(boolean cachedModel) {
065                    _cachedModel = cachedModel;
066            }
067    
068            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
069                    throw new UnsupportedOperationException();
070            }
071    
072            public void setModelAttributes(Map<String, Object> attributes) {
073            }
074    
075            public void setNew(boolean n) {
076                    _new = n;
077            }
078    
079            public CacheModel<T> toCacheModel() {
080                    throw new UnsupportedOperationException();
081            }
082    
083            public T toEscapedModel() {
084                    throw new UnsupportedOperationException();
085            }
086    
087            protected Locale getLocale(String languageId) {
088                    Locale locale = null;
089    
090                    if (languageId != null) {
091                            locale = LocaleUtil.fromLanguageId(languageId);
092                    }
093    
094                    if (locale == null) {
095                            locale = LocaleUtil.getMostRelevantLocale();
096                    }
097    
098                    return locale;
099            }
100    
101            private static final boolean _ESCAPED_MODEL = false;
102    
103            private boolean _cachedModel;
104            private boolean _new;
105    
106    }