/**
 * Implements the Cold Fusion Function getmetadata
 */
package railo.runtime.functions.other;

import java.util.HashMap;

import railo.runtime.Component;
import railo.runtime.ComponentPro;
import railo.runtime.InterfaceImpl;
import railo.runtime.PageContext;
import railo.runtime.PagePlus;
import railo.runtime.component.ComponentLoader;
import railo.runtime.exp.ApplicationException;
import railo.runtime.exp.PageException;
import railo.runtime.ext.function.Function;
import railo.runtime.op.Caster;
import railo.runtime.type.Struct;

public final class GetComponentMetaData implements Function {

	public static Struct call(PageContext pc , Object obj) throws PageException {
		if(obj instanceof Component){
			return ((Component)obj).getMetaData(pc);
		}
		// load existing meta without loading the cfc
		try{
			PagePlus page = ComponentLoader.loadPage(pc, Caster.toString(obj), null,null);
			if(page.metaData!=null && page.metaData.get()!=null) return page.metaData.get();
		}
		catch(Throwable t){}
		
		/*try{
			PagePlus page = ComponentLoader.loadPage(pc, Caster.toString(obj), null,null);
			Struct meta=null;
			if(page!=null)meta=GetMetaData.getMetaData(page.getPageSource());
			if(meta!=null) return meta;
			
		}
		catch(Throwable t){}*/
		
		
		// load the cfc when metadata was not defined before
		try{
			Component cfc = CreateObject.doComponent(pc, Caster.toString(obj));
			return GetMetaData.getMetaData((ComponentPro) cfc, pc);
		}
		// TODO better solution
		catch(ApplicationException ae){
			InterfaceImpl inter = ComponentLoader.loadInterface(pc, Caster.toString(obj), new HashMap());
			return inter.getMetaData(pc);
		}
	}
}
@@ -1513,16 +1513,25 @@
 on ae)%7B%0A
+%09%09%09try%7B%0A%09
 %09%09%09Inter
@@ -1618,24 +1618,25 @@
 hMap());%0A%09%09%09
+%09
 return inter
@@ -1649,20 +1649,72 @@
 taData(pc);%0A
+%09%09%09%7D%0A%09%09%09catch(PageException pe)%7B%0A%09%09%09%09throw ae;%0A%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%7D

throw original exception in second change