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(BaseModel<?> baseModel) {
077                    ExpandoBridge thisExpandoBridge = getExpandoBridge();
078    
079                    ExpandoBridge baseModelExpandoBridge = baseModel.getExpandoBridge();
080    
081                    thisExpandoBridge.setAttributes(baseModelExpandoBridge.getAttributes());
082            }
083    
084            @Override
085            public void setExpandoBridgeAttributes(ExpandoBridge expandoBridge) {
086                    ExpandoBridge thisExpandoBridge = getExpandoBridge();
087    
088                    thisExpandoBridge.setAttributes(expandoBridge.getAttributes());
089            }
090    
091            @Override
092            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
093                    throw new UnsupportedOperationException();
094            }
095    
096            @Override
097            public void setModelAttributes(Map<String, Object> attributes) {
098            }
099    
100            @Override
101            public void setNew(boolean n) {
102                    _new = n;
103            }
104    
105            @Override
106            public CacheModel<T> toCacheModel() {
107                    throw new UnsupportedOperationException();
108            }
109    
110            @Override
111            public T toEscapedModel() {
112                    throw new UnsupportedOperationException();
113            }
114    
115            @Override
116            public T toUnescapedModel() {
117                    return (T)this;
118            }
119    
120            protected Locale getLocale(String languageId) {
121                    Locale locale = null;
122    
123                    if (languageId != null) {
124                            locale = LocaleUtil.fromLanguageId(languageId);
125                    }
126    
127                    if (locale == null) {
128                            locale = LocaleUtil.getMostRelevantLocale();
129                    }
130    
131                    return locale;
132            }
133    
134            private static final boolean _ESCAPED_MODEL = false;
135    
136            private boolean _cachedModel;
137            private boolean _new;
138    
139    }