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 aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.util.LocaleUtil;
020    import com.liferay.portal.model.BaseModel;
021    import com.liferay.portal.model.CacheModel;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portlet.expando.model.ExpandoBridge;
024    
025    import java.util.Collections;
026    import java.util.Locale;
027    import java.util.Map;
028    
029    /**
030     * The base implementation for all model classes. This class should never need
031     * to be used directly.
032     *
033     * @author Brian Wing Shun Chan
034     */
035    @ProviderType
036    public abstract class BaseModelImpl<T> implements BaseModel<T> {
037    
038            public BaseModelImpl() {
039            }
040    
041            @Override
042            public abstract Object clone();
043    
044            @Override
045            public ExpandoBridge getExpandoBridge() {
046                    throw new UnsupportedOperationException();
047            }
048    
049            @Override
050            public Map<String, Object> getModelAttributes() {
051                    return Collections.emptyMap();
052            }
053    
054            @Override
055            public boolean isCachedModel() {
056                    return _cachedModel;
057            }
058    
059            @Override
060            public boolean isEscapedModel() {
061                    return _ESCAPED_MODEL;
062            }
063    
064            @Override
065            public boolean isNew() {
066                    return _new;
067            }
068    
069            @Override
070            public void resetOriginalValues() {
071            }
072    
073            @Override
074            public void setCachedModel(boolean cachedModel) {
075                    _cachedModel = cachedModel;
076            }
077    
078            @Override
079            public void setExpandoBridgeAttributes(BaseModel<?> baseModel) {
080                    ExpandoBridge thisExpandoBridge = getExpandoBridge();
081    
082                    ExpandoBridge baseModelExpandoBridge = baseModel.getExpandoBridge();
083    
084                    thisExpandoBridge.setAttributes(baseModelExpandoBridge.getAttributes());
085            }
086    
087            @Override
088            public void setExpandoBridgeAttributes(ExpandoBridge expandoBridge) {
089                    ExpandoBridge thisExpandoBridge = getExpandoBridge();
090    
091                    thisExpandoBridge.setAttributes(expandoBridge.getAttributes());
092            }
093    
094            @Override
095            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
096                    throw new UnsupportedOperationException();
097            }
098    
099            @Override
100            public void setModelAttributes(Map<String, Object> attributes) {
101            }
102    
103            @Override
104            public void setNew(boolean n) {
105                    _new = n;
106            }
107    
108            @Override
109            public CacheModel<T> toCacheModel() {
110                    throw new UnsupportedOperationException();
111            }
112    
113            @Override
114            public T toEscapedModel() {
115                    throw new UnsupportedOperationException();
116            }
117    
118            @Override
119            public T toUnescapedModel() {
120                    return (T)this;
121            }
122    
123            protected Locale getLocale(String languageId) {
124                    Locale locale = null;
125    
126                    if (languageId != null) {
127                            locale = LocaleUtil.fromLanguageId(languageId);
128                    }
129    
130                    if (locale == null) {
131                            locale = LocaleUtil.getMostRelevantLocale();
132                    }
133    
134                    return locale;
135            }
136    
137            private static final boolean _ESCAPED_MODEL = false;
138    
139            private boolean _cachedModel;
140            private boolean _new;
141    
142    }