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