001    /**
002     * Implements the Cold Fusion Function structinsert
003     */
004    package railo.runtime.functions.struct;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.ExpressionException;
008    import railo.runtime.exp.PageException;
009    import railo.runtime.ext.function.Function;
010    import railo.runtime.type.Collection.Key;
011    import railo.runtime.type.KeyImpl;
012    import railo.runtime.type.Struct;
013    
014    public final class StructInsert implements Function {
015            public static boolean call(PageContext pc , Struct struct, String key, Object value) throws PageException {
016                    return call(pc , struct, key, value, false);
017            }
018            public static boolean call(PageContext pc , Struct struct, String strKey, Object value, boolean allowoverwrite) throws PageException {
019                    Key key = KeyImpl.init(strKey);
020                    if(allowoverwrite) { 
021                            struct.set(key,value);
022                    }
023                    else {
024                            if(struct.get(key,null)!=null) throw new ExpressionException("key ["+key+"] already exist in struct");
025                            struct.set(key,value);
026                    }
027                    return true;
028            }
029    }