001/* 002@license.text@ 003 */ 004package com.hammurapi.common; 005 006import java.util.ArrayList; 007import java.util.List; 008 009 010/** 011 * Utility class which searches class hierarchy for a resource. 012 * Resource shall be named after class name, profile name is separated from 013 * class name by ! and locale separated from class name/profile by _. 014 * @author Pavel Vlasov 015 * @revision $Revision$ 016 */ 017public class ClassResourceLoader extends ResourceLoaderImpl { 018 019 public static String[] inheritancePath(Class<?> clazz) { 020 final List<String> accumulator = new ArrayList<String>(); 021 022 new ClassHierarchyVisitable(clazz).accept(new Visitor<Class<?>>() { 023 024 @Override 025 public boolean visit(Class<?> target) { 026 String cPath = target.getName().replace('.', '/'); 027 if (accumulator.contains(cPath)) { 028 return false; 029 } 030 accumulator.add(cPath); 031 return true; 032 } 033 }); 034 035 return accumulator.toArray(new String[accumulator.size()]); 036 } 037 038 private Class<?> clazz; 039 040 public ClassResourceLoader(ResourceSet resourceSet, Class<?> clazz) { 041 super(resourceSet, inheritancePath(clazz)); 042 this.clazz = clazz; 043 } 044 045 @Override 046 public String toString() { 047 return "Class resource loader for "+clazz.getName(); 048 } 049 050}