001    /**
002     * Copyright (c) 2000-present 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.kernel.search;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    import com.liferay.portal.kernel.util.ProxyFactory;
019    
020    import java.util.List;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     * @author Raymond Aug??
025     */
026    public class SortFactoryUtil {
027    
028            public static Sort create(String fieldName, boolean reverse) {
029                    return getSortFactory().create(fieldName, reverse);
030            }
031    
032            public static Sort create(String fieldName, int type, boolean reverse) {
033                    return getSortFactory().create(fieldName, type, reverse);
034            }
035    
036            public static Sort[] getDefaultSorts() {
037                    return getSortFactory().getDefaultSorts();
038            }
039    
040            public static Sort getSort(
041                    Class<?> clazz, int type, String orderByCol, boolean inferSortField,
042                    String orderByType) {
043    
044                    return getSortFactory().getSort(
045                            clazz, type, orderByCol, inferSortField, orderByType);
046            }
047    
048            public static Sort getSort(
049                    Class<?> clazz, int type, String orderByCol, String orderByType) {
050    
051                    return getSortFactory().getSort(clazz, type, orderByCol, orderByType);
052            }
053    
054            public static Sort getSort(
055                    Class<?> clazz, String orderByCol, String orderByType) {
056    
057                    return getSortFactory().getSort(clazz, orderByCol, orderByType);
058            }
059    
060            public static SortFactory getSortFactory() {
061                    PortalRuntimePermission.checkGetBeanProperty(SortFactoryUtil.class);
062    
063                    return _sortFactory;
064            }
065    
066            public static Sort[] toArray(List<Sort> sorts) {
067                    return getSortFactory().toArray(sorts);
068            }
069    
070            private static final SortFactory _sortFactory =
071                    ProxyFactory.newServiceTrackedInstance(SortFactory.class);
072    
073    }