@@ -0,0 +1,2706 @@
+/*%0A   Licensed to the Apache Software Foundation (ASF) under one%0A   or more contributor license agreements.  See the NOTICE file%0A   distributed with this work for additional information%0A   regarding copyright ownership.  The ASF licenses this file%0A   to you under the Apache License, Version 2.0 (the%0A   %22License%22); you may not use this file except in compliance%0A   with the License.  You may obtain a copy of the License at%0A%0A     http://www.apache.org/licenses/LICENSE-2.0%0A%0A   Unless required by applicable law or agreed to in writing,%0A   software distributed under the License is distributed on an%0A   %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A   KIND, either express or implied.  See the License for the%0A   specific language governing permissions and limitations%0A   under the License.    %0A */%0Apackage org.opentides.util;%0A%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport org.opentides.bean.Auditable;%0Aimport org.opentides.bean.AuditableField;%0Aimport org.opentides.bean.Searchable;%0A%0A/**%0A * Helper class to keep a cache of reusable attributes.%0A * %0A * @author allantan%0A *%0A */%0Apublic class CacheUtil %7B%0A%0A%09@SuppressWarnings(%22rawtypes%22)%0A%09public static final Map%3CClass, List%3CAuditableField%3E%3E auditable  = new HashMap%3CClass, List%3CAuditableField%3E %3E();%0A%0A%09@SuppressWarnings(%22rawtypes%22)%0A%09public static final Map%3CClass, List%3CString%3E%3E searchable = new HashMap%3CClass, List%3CString%3E%3E();%0A%09%0A%09/**%0A%09 * Retrieves auditable settings from the cache, if available.%0A%09 * Otherwise, adds settings to cache.%0A%09 * %0A%09 * @param obj%0A%09 * @return%0A%09 */%0A%09public static List%3CAuditableField%3E getAuditable(Auditable obj) %7B%0A%09%09List%3CAuditableField%3E ret = auditable.get(obj.getClass());%0A%09%09if (ret == null) %7B%0A%09%09%09auditable.put(obj.getClass(), obj.getAuditableFields());%0A%09%09%09ret =  auditable.get(obj.getClass());%0A%09%09%7D%0A%09%09return ret;%09%09%0A%09%7D%0A%09%0A%09/**%0A%09 * Retrieves the auditable field of the given object and field reference.%0A%09 * This is used to get the proper label of the given field.%0A%09 * @param obj%0A%09 * @param fieldName%0A%09 * @return%0A%09 */%0A%09public static AuditableField getAuditableField(Auditable obj, String fieldName) %7B%0A%09%09List%3CAuditableField%3E fields = CacheUtil.getAuditable(obj);%0A%09%09for (AuditableField field:fields) %7B%0A%09%09%09if (fieldName.equals(field.getFieldName()))%0A%09%09%09%09return field;%0A%09%09%7D%0A%09%09return null;%0A%09%7D%0A%09/**%0A%09 * Retrieves searchable settings from the cache, if available.%0A%09 * Otherwise, adds settings to cache.%0A%09 * %0A%09 * @param obj%0A%09 * @return%0A%09 */%0A%09public static List%3CString%3E getSearchable(Searchable obj) %7B%0A%09%09List%3CString%3E ret = searchable.get(obj.getClass());%0A%09%09if (ret == null) %7B%0A%09%09%09searchable.put(obj.getClass(), obj.getSearchProperties());%0A%09%09%09ret =  searchable.get(obj.getClass());%0A%09%09%7D%0A%09%09return ret;%09%09%09%09%0A%09%7D%0A%7D%0A

add cache for class properties (e.g. auditable,searchable)