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