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.portlet.dynamicdatamapping.storage;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portlet.expando.model.ExpandoColumn;
020    import com.liferay.portlet.expando.model.ExpandoValue;
021    
022    import java.util.HashMap;
023    import java.util.List;
024    import java.util.Map;
025    
026    import org.springframework.expression.BeanResolver;
027    import org.springframework.expression.EvaluationContext;
028    
029    /**
030     * @author Marcellus Tavares
031     */
032    public class ExpandoValueBeanResolver implements BeanResolver {
033    
034            public ExpandoValueBeanResolver(List<ExpandoValue> expandoValues) {
035                    _expandoValues = new HashMap<String, ExpandoValue>();
036    
037                    try {
038                            for (ExpandoValue expandoValue : expandoValues) {
039                                    ExpandoColumn expandoColumn = expandoValue.getColumn();
040    
041                                    _expandoValues.put(expandoColumn.getName(), expandoValue);
042                            }
043                    }
044                    catch (Exception e) {
045                            _log.error(e.getMessage(), e);
046                    }
047            }
048    
049            @Override
050            public Object resolve(EvaluationContext context, String beanName) {
051                    return _expandoValues.get(beanName);
052            }
053    
054            private static Log _log = LogFactoryUtil.getLog(
055                    ExpandoValueBeanResolver.class);
056    
057            private Map<String, ExpandoValue> _expandoValues;
058    
059    }