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.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            public boolean isNew() {
038                    return _new;
039            }
040    
041            public void setNew(boolean n) {
042                    _new = n;
043            }
044    
045            public boolean isCachedModel() {
046                    return _cachedModel;
047            }
048    
049            public void setCachedModel(boolean cachedModel) {
050                    _cachedModel = cachedModel;
051            }
052    
053            public boolean isEscapedModel() {
054                    return _ESCAPED_MODEL;
055            }
056    
057            public ExpandoBridge getExpandoBridge() {
058                    throw new UnsupportedOperationException();
059            }
060    
061            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
062                    throw new UnsupportedOperationException();
063            }
064    
065            @Override
066            public abstract Object clone();
067    
068            public void resetOriginalValues() {
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 _new;
100            private boolean _cachedModel;
101    
102    }