001 package railo.runtime.orm.naming; 002 003 import railo.runtime.Component; 004 import railo.runtime.engine.ThreadLocalPageContext; 005 import railo.runtime.exp.PageException; 006 import railo.runtime.exp.PageRuntimeException; 007 import railo.runtime.op.Caster; 008 import railo.runtime.type.UDF; 009 010 public class CFCNamingStrategy implements NamingStrategy { 011 012 Component cfc; 013 014 015 public CFCNamingStrategy(String cfcName) throws PageException{ 016 this.cfc=ThreadLocalPageContext.get().loadComponent(cfcName); 017 } 018 019 020 /** 021 * @see railo.runtime.orm.naming.NamingStrategy#convertTableName(java.lang.String) 022 */ 023 public String convertTableName(String tableName) { 024 return call("getTableName",tableName); 025 } 026 027 /** 028 * @see railo.runtime.orm.naming.NamingStrategy#convertColumnName(java.lang.String) 029 */ 030 public String convertColumnName(String columnName) { 031 return call("getColumnName",columnName); 032 } 033 034 private String call(String functionName, String name) { 035 Object res = cfc.get(functionName,null); 036 if(!(res instanceof UDF)) return name; 037 038 try { 039 return Caster.toString(cfc.call(ThreadLocalPageContext.get(), functionName, new Object[]{name})); 040 } catch (PageException pe) { 041 throw new PageRuntimeException(pe); 042 } 043 } 044 045 /** 046 * @see railo.runtime.orm.naming.NamingStrategy#getType() 047 */ 048 public String getType() { 049 return "cfc"; 050 } 051 052 }