001    /**
002     * Copyright (c) 2000-2013 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            @Override
042            public ExpandoBridge getExpandoBridge() {
043                    throw new UnsupportedOperationException();
044            }
045    
046            @Override
047            public Map<String, Object> getModelAttributes() {
048                    return Collections.emptyMap();
049            }
050    
051            @Override
052            public boolean isCachedModel() {
053                    return _cachedModel;
054            }
055    
056            @Override
057            public boolean isEscapedModel() {
058                    return _ESCAPED_MODEL;
059            }
060    
061            @Override
062            public boolean isNew() {
063                    return _new;
064            }
065    
066            @Override
067            public void resetOriginalValues() {
068            }
069    
070            @Override
071            public void setCachedModel(boolean cachedModel) {
072                    _cachedModel = cachedModel;
073            }
074    
075            @Override
076            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
077                    throw new UnsupportedOperationException();
078            }
079    
080            @Override
081            public void setModelAttributes(Map<String, Object> attributes) {
082            }
083    
084            @Override
085            public void setNew(boolean n) {
086                    _new = n;
087            }
088    
089            @Override
090            public CacheModel<T> toCacheModel() {
091                    throw new UnsupportedOperationException();
092            }
093    
094            @Override
095            public T toEscapedModel() {
096                    throw new UnsupportedOperationException();
097            }
098    
099            @Override
100            public T toUnescapedModel() {
101                    return (T)this;
102            }
103    
104            protected Locale getLocale(String languageId) {
105                    Locale locale = null;
106    
107                    if (languageId != null) {
108                            locale = LocaleUtil.fromLanguageId(languageId);
109                    }
110    
111                    if (locale == null) {
112                            locale = LocaleUtil.getMostRelevantLocale();
113                    }
114    
115                    return locale;
116            }
117    
118            private static final boolean _ESCAPED_MODEL = false;
119    
120            private boolean _cachedModel;
121            private boolean _new;
122    
123    }