use of lucee.runtime.component.Member in project Lucee by lucee.
the class CFTag method getAttributeRequirments.
private static TagLibTag getAttributeRequirments(Component cfc, boolean runtime) {
Struct meta = null;
Member mem = cfc != null ? cfc.getMember(Component.ACCESS_PRIVATE, KeyConstants._metadata, true, false) : null;
if (mem != null)
meta = Caster.toStruct(mem.getValue(), null, false);
if (meta == null)
return null;
TagLibTag tag = new TagLibTag(null);
// TAG
// type
String type = Caster.toString(meta.get(ATTRIBUTE_TYPE, "dynamic"), "dynamic");
if ("fixed".equalsIgnoreCase(type))
tag.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_FIXED);
else
// else if("mixed".equalsIgnoreCase(type))tag.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_MIXED);
// else if("noname".equalsIgnoreCase(type))tag.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_NONAME);
tag.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_DYNAMIC);
if (!runtime) {
// hint
String hint = Caster.toString(meta.get(KeyConstants._hint, null), null);
if (!StringUtil.isEmpty(hint))
tag.setDescription(hint);
}
// ATTRIBUTES
Struct attributes = Caster.toStruct(meta.get(KeyConstants._ATTRIBUTES, null), null, false);
if (attributes != null) {
Iterator<Entry<Key, Object>> it = attributes.entryIterator();
// Iterator it = attributes.entrySet().iterator();
Entry<Key, Object> entry;
TagLibTagAttr attr;
Struct sct;
String name;
Object defaultValue;
while (it.hasNext()) {
entry = it.next();
name = Caster.toString(entry.getKey(), null);
if (StringUtil.isEmpty(name))
continue;
attr = new TagLibTagAttr(tag);
attr.setName(name);
sct = Caster.toStruct(entry.getValue(), null, false);
if (sct != null) {
attr.setRequired(Caster.toBooleanValue(sct.get(KeyConstants._required, Boolean.FALSE), false));
attr.setType(Caster.toString(sct.get(KeyConstants._type, "any"), "any"));
defaultValue = sct.get(KeyConstants._default, null);
if (defaultValue != null)
attr.setDefaultValue(defaultValue);
if (!runtime) {
attr.setDescription(Caster.toString(sct.get(KeyConstants._hint, null), null));
attr.setRtexpr(Caster.toBooleanValue(sct.get(RT_EXPR_VALUE, Boolean.TRUE), true));
}
}
tag.setAttribute(attr);
}
}
return tag;
}
use of lucee.runtime.component.Member in project Lucee by lucee.
the class PropertyFactory method addHas.
public static void addHas(ComponentImpl comp, Property prop) throws ApplicationException {
Member m = comp.getMember(Component.ACCESS_PRIVATE, KeyImpl.getInstance("has" + getSingularName(prop)), true, false);
if (!(m instanceof UDF)) {
UDF udf = new UDFHasProperty(comp, prop);
comp.registerUDF(KeyImpl.init(udf.getFunctionName()), udf);
}
}
use of lucee.runtime.component.Member in project Lucee by lucee.
the class PropertyFactory method addSet.
public static void addSet(ComponentImpl comp, Property prop) throws PageException {
Member m = comp.getMember(Component.ACCESS_PRIVATE, KeyImpl.getInstance("set" + prop.getName()), true, false);
if (!(m instanceof UDF)) {
UDF udf = new UDFSetterProperty(comp, prop);
comp.registerUDF(KeyImpl.init(udf.getFunctionName()), udf);
}
}
use of lucee.runtime.component.Member in project Lucee by lucee.
the class ComponentImpl method onMissingMethod.
public Object onMissingMethod(PageContext pc, int access, Member member, String name, Object[] _args, Struct _namedArgs, boolean superAccess) throws PageException {
Member ommm = access == -1 ? getMember(pc, KeyConstants._onmissingmethod, false, superAccess) : getMember(access, KeyConstants._onmissingmethod, false, superAccess);
if (ommm instanceof UDF) {
Argument args = new ArgumentImpl();
if (_args != null) {
for (int i = 0; i < _args.length; i++) {
args.setEL(ArgumentIntKey.init(i + 1), _args[i]);
}
} else if (_namedArgs != null) {
UDFUtil.argumentCollection(_namedArgs, new FunctionArgument[] {});
Iterator<Entry<Key, Object>> it = _namedArgs.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
args.setEL(e.getKey(), e.getValue());
}
}
// Struct newArgs=new StructImpl(StructImpl.TYPE_SYNC);
// newArgs.setEL(MISSING_METHOD_NAME, name);
// newArgs.setEL(MISSING_METHOD_ARGS, args);
Object[] newArgs = new Object[] { name, args };
return _call(pc, KeyConstants._onmissingmethod, (UDFPlus) ommm, null, newArgs);
}
if (member == null)
throw ComponentUtil.notFunction(this, KeyImpl.init(name), null, access);
throw ComponentUtil.notFunction(this, KeyImpl.init(name), member.getValue(), access);
}
use of lucee.runtime.component.Member in project Lucee by lucee.
the class ComponentImpl method callGetter.
private Object callGetter(PageContext pc, Collection.Key key, Object defaultValue) {
Key getterName = KeyImpl.getInstance("get" + key.getLowerString());
Member member = getMember(pc, getterName, false, false);
if (member instanceof UDFPlus) {
UDFPlus udf = (UDFPlus) member;
if (udf.getFunctionArguments().length == 0 && udf.getReturnType() != CFTypes.TYPE_VOID) {
try {
return _call(pc, getterName, udf, null, ArrayUtil.OBJECT_EMPTY);
} catch (PageException e) {
return defaultValue;
}
}
}
return defaultValue;
}
Aggregations