All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.larmic.butterfaces.component.html.repeat.model.DataModelWrapperFactory Maven / Gradle / Ivy

The newest version!
/*
 * Copyright Lars Michaelis and Stephan Zerhusen 2016.
 * Distributed under the MIT License.
 * (See accompanying file README.md file or copy at http://opensource.org/licenses/MIT)
 */
package de.larmic.butterfaces.component.html.repeat.model;

import javax.faces.model.*;
import java.sql.ResultSet;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author Lars Michaelis
 */
public class DataModelWrapperFactory {

    public static DataModelWrapper createDataModelWrapper(Object value) {
        return new DataModelWrapper(convertToJsfDataModel(value));
    }

    private static DataModel convertToJsfDataModel(Object value) {
        DataModel model = null;

        if (value == null) {
            model = new ListDataModel(Collections.EMPTY_LIST);
        } else if (value instanceof DataModel) {
            model = (DataModel) value;
        } else if (value instanceof Collection) {
            model = new ListDataModel((List) value);
        } else if (Object[].class.isAssignableFrom(value.getClass())) {
            model = new ArrayDataModel((Object[]) value);
        } else if (value instanceof ResultSet) {
            model = new ResultSetDataModel((ResultSet) value);
        } else {
            model = new ScalarDataModel(value);
        }

        return model;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy