Search in sources :

Example 1 with ComponentScope

use of lucee.runtime.ComponentScope in project Lucee by lucee.

the class AxisCaster method _toPojo.

private static Pojo _toPojo(PageContext pc, Pojo pojo, TypeMapping tm, TypeEntry typeEntry, QName type, Component comp, Set<Object> done) throws PageException {
    // print.ds();System.exit(0);
    comp = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, comp);
    ComponentScope scope = comp.getComponentScope();
    // create Pojo
    if (pojo == null) {
        try {
            pojo = (Pojo) ClassUtil.loadInstance(ComponentUtil.getComponentPropertiesClass(pc, comp));
        } catch (ClassException e) {
            throw Caster.toPageException(e);
        }
    }
    // initialize Pojo
    Property[] props = comp.getProperties(false, true, false, false);
    _initPojo(pc, typeEntry, type, pojo, props, scope, comp, tm, done);
    return pojo;
}
Also used : ComponentScope(lucee.runtime.ComponentScope) ClassException(lucee.commons.lang.ClassException) Property(lucee.runtime.component.Property)

Example 2 with ComponentScope

use of lucee.runtime.ComponentScope in project Lucee by lucee.

the class ScriptConverter method _serializeComponent.

/**
 * serialize a Component
 * @param c Component to serialize
 * @param sb
 * @param done
 * @throws ConverterException
 */
private void _serializeComponent(Component c, StringBuilder sb, Set<Object> done) throws ConverterException {
    ComponentSpecificAccess cw = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, c);
    sb.append(goIn());
    try {
        sb.append("evaluateComponent(").append(QUOTE_CHR).append(c.getAbsName()).append(QUOTE_CHR).append(',').append(QUOTE_CHR).append(ComponentUtil.md5(c)).append(QUOTE_CHR).append(",{");
    } catch (Exception e) {
        throw toConverterException(e);
    }
    boolean doIt = false;
    Object member;
    {
        Iterator<Entry<Key, Object>> it = cw.entryIterator();
        deep++;
        Entry<Key, Object> e;
        while (it.hasNext()) {
            e = it.next();
            member = e.getValue();
            if (member instanceof UDF)
                continue;
            if (doIt)
                sb.append(',');
            doIt = true;
            sb.append(QUOTE_CHR);
            sb.append(escape(e.getKey().getString()));
            sb.append(QUOTE_CHR);
            sb.append(':');
            _serialize(member, sb, done);
        }
        sb.append("}");
        deep--;
    }
    {
        boolean isPeristent = c.isPersistent();
        ComponentScope scope = c.getComponentScope();
        Iterator<Entry<Key, Object>> it = scope.entryIterator();
        sb.append(",{");
        deep++;
        doIt = false;
        Property p;
        Boolean remotingFetch;
        Struct props = ignoreRemotingFetch ? null : ComponentUtil.getPropertiesAsStruct(c, false);
        Entry<Key, Object> e;
        Key k;
        while (it.hasNext()) {
            e = it.next();
            k = e.getKey();
            // String key=Caster.toString(it.next(),"");
            if (KeyConstants._THIS.equalsIgnoreCase(k))
                continue;
            if (!ignoreRemotingFetch) {
                p = (Property) props.get(k, null);
                if (p != null) {
                    remotingFetch = Caster.toBoolean(p.getDynamicAttributes().get(REMOTING_FETCH, null), null);
                    if (remotingFetch == null) {
                        if (isPeristent && ORMUtil.isRelated(p))
                            continue;
                    } else if (!remotingFetch.booleanValue())
                        continue;
                }
            }
            member = e.getValue();
            if (member instanceof UDF)
                continue;
            if (doIt)
                sb.append(',');
            doIt = true;
            sb.append(QUOTE_CHR);
            sb.append(escape(k.getString()));
            sb.append(QUOTE_CHR);
            sb.append(':');
            _serialize(member, sb, done);
        }
        sb.append("}");
        deep--;
    }
    sb.append(")");
// sb.append("");
// throw new ConverterException("can't serialize a component "+component.getDisplayName());
}
Also used : Entry(java.util.Map.Entry) ComponentScope(lucee.runtime.ComponentScope) UDF(lucee.runtime.type.UDF) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Property(lucee.runtime.component.Property) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) Key(lucee.runtime.type.Collection.Key) Struct(lucee.runtime.type.Struct)

Example 3 with ComponentScope

use of lucee.runtime.ComponentScope in project Lucee by lucee.

the class WDDXConverter method _deserializeComponent.

/**
 * Desirialize a Component Object
 *
 * @param elComp
 *            Component Object as XML Element
 * @return Component Object
 * @throws ConverterException
 * @throws ConverterException
 */
private Object _deserializeComponent(Element elComp) throws ConverterException {
    // String type=elStruct.getAttribute("type");
    String name = elComp.getAttribute("name");
    String md5 = elComp.getAttribute("md5");
    // TLPC
    PageContext pc = ThreadLocalPageContext.get();
    // Load comp
    Component comp = null;
    try {
        comp = pc.loadComponent(name);
        if (!ComponentUtil.md5(comp).equals(md5)) {
            throw new ConverterException("component [" + name + "] in this enviroment has not the same interface as the component to load, it is possible that one off the components has Functions added dynamicly.");
        }
    } catch (ConverterException e) {
        throw e;
    } catch (Exception e) {
        throw new ConverterException(e.getMessage());
    }
    NodeList list = elComp.getChildNodes();
    ComponentScope scope = comp.getComponentScope();
    int len = list.getLength();
    String scopeName;
    Element var, value;
    Collection.Key key;
    for (int i = 0; i < len; i++) {
        Node node = list.item(i);
        if (node instanceof Element) {
            var = (Element) node;
            value = getChildElement((Element) node);
            scopeName = var.getAttribute("scope");
            if (value != null) {
                key = Caster.toKey(var.getAttribute("name"), null);
                if (key == null)
                    continue;
                if ("variables".equalsIgnoreCase(scopeName))
                    scope.setEL(key, _deserialize(value));
                else
                    comp.setEL(key, _deserialize(value));
            }
        }
    }
    return comp;
}
Also used : Key(lucee.runtime.type.Collection.Key) ComponentScope(lucee.runtime.ComponentScope) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Collection(lucee.runtime.type.Collection) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) Component(lucee.runtime.Component) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) CoderException(lucee.runtime.coder.CoderException)

Example 4 with ComponentScope

use of lucee.runtime.ComponentScope in project Lucee by lucee.

the class WDDXConverter method _serializeComponent.

/**
 * serialize a Component
 *
 * @param component
 *            Component to serialize
 * @param done
 * @return serialized component
 * @throws ConverterException
 */
private String _serializeComponent(Component component, Set<Object> done) throws ConverterException {
    StringBuilder sb = new StringBuilder();
    Component ca;
    component = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, ca = component);
    boolean isPeristent = ca.isPersistent();
    deep++;
    Object member;
    Iterator<Key> it = component.keyIterator();
    Collection.Key key;
    while (it.hasNext()) {
        key = Caster.toKey(it.next(), null);
        member = component.get(key, null);
        if (member instanceof UDF)
            continue;
        sb.append(goIn() + "<var scope=\"this\" name=" + del + XMLUtil.escapeXMLString(key.toString()) + del + ">");
        sb.append(_serialize(member, done));
        sb.append(goIn() + "</var>");
    }
    Property p;
    Boolean remotingFetch;
    Struct props = ignoreRemotingFetch ? null : ComponentUtil.getPropertiesAsStruct(ca, false);
    ComponentScope scope = ca.getComponentScope();
    it = scope.keyIterator();
    while (it.hasNext()) {
        key = Caster.toKey(it.next(), null);
        if (!ignoreRemotingFetch) {
            p = (Property) props.get(key, null);
            if (p != null) {
                remotingFetch = Caster.toBoolean(p.getDynamicAttributes().get(REMOTING_FETCH, null), null);
                if (remotingFetch == null) {
                    if (isPeristent && ORMUtil.isRelated(p))
                        continue;
                } else if (!remotingFetch.booleanValue())
                    continue;
            }
        }
        member = scope.get(key, null);
        if (member instanceof UDF || key.equals(KeyConstants._this))
            continue;
        sb.append(goIn() + "<var scope=\"variables\" name=" + del + XMLUtil.escapeXMLString(key.toString()) + del + ">");
        sb.append(_serialize(member, done));
        sb.append(goIn() + "</var>");
    }
    deep--;
    try {
        // return goIn()+"<struct>"+sb+"</struct>";
        return goIn() + "<component md5=\"" + ComponentUtil.md5(component) + "\" name=\"" + XMLUtil.escapeXMLString(component.getAbsName()) + "\">" + sb + "</component>";
    } catch (Exception e) {
        throw toConverterException(e);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) CoderException(lucee.runtime.coder.CoderException) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) ComponentScope(lucee.runtime.ComponentScope) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Collection(lucee.runtime.type.Collection) Component(lucee.runtime.Component) Property(lucee.runtime.component.Property) Key(lucee.runtime.type.Collection.Key)

Example 5 with ComponentScope

use of lucee.runtime.ComponentScope in project Lucee by lucee.

the class XMLConverter method _serializeComponent.

/**
 * serialize a Component
 * @param component Component to serialize
 * @param done
 * @return serialized component
 * @throws ConverterException
 */
private String _serializeComponent(Component component, Map<Object, String> done) throws ConverterException {
    StringBuilder sb = new StringBuilder();
    Component ca;
    component = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, ca = component);
    boolean isPeristent = ca.isPersistent();
    deep++;
    Object member;
    Iterator<Key> it = component.keyIterator();
    Collection.Key key;
    while (it.hasNext()) {
        key = it.next();
        member = component.get(key, null);
        if (member instanceof UDF)
            continue;
        sb.append(goIn() + "<var scope=\"this\" name=" + del + key.toString() + del + ">");
        sb.append(_serialize(member, done));
        sb.append(goIn() + "</var>");
    }
    Property p;
    Boolean remotingFetch;
    Struct props = ignoreRemotingFetch ? null : ComponentUtil.getPropertiesAsStruct(ca, false);
    ComponentScope scope = ca.getComponentScope();
    it = scope.keyIterator();
    while (it.hasNext()) {
        key = Caster.toKey(it.next(), null);
        if (!ignoreRemotingFetch) {
            p = (Property) props.get(key, null);
            if (p != null) {
                remotingFetch = Caster.toBoolean(p.getDynamicAttributes().get(REMOTING_FETCH, null), null);
                if (remotingFetch == null) {
                    if (isPeristent && ORMUtil.isRelated(p))
                        continue;
                } else if (!remotingFetch.booleanValue())
                    continue;
            }
        }
        member = scope.get(key, null);
        if (member instanceof UDF || key.equals(KeyConstants._this))
            continue;
        sb.append(goIn() + "<var scope=\"variables\" name=" + del + key.toString() + del + ">");
        sb.append(_serialize(member, done));
        sb.append(goIn() + "</var>");
    }
    deep--;
    try {
        // return goIn()+"<struct>"+sb+"</struct>";
        return goIn() + "<component md5=\"" + ComponentUtil.md5(component) + "\" name=\"" + component.getAbsName() + "\">" + sb + "</component>";
    } catch (Exception e) {
        throw toConverterException(e);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) ComponentScope(lucee.runtime.ComponentScope) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Collection(lucee.runtime.type.Collection) Component(lucee.runtime.Component) Property(lucee.runtime.component.Property) Key(lucee.runtime.type.Collection.Key)

Aggregations

ComponentScope (lucee.runtime.ComponentScope)10 Key (lucee.runtime.type.Collection.Key)8 Component (lucee.runtime.Component)7 Property (lucee.runtime.component.Property)6 PageException (lucee.runtime.exp.PageException)6 IOException (java.io.IOException)5 UDF (lucee.runtime.type.UDF)5 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)4 Collection (lucee.runtime.type.Collection)4 Entry (java.util.Map.Entry)3 Struct (lucee.runtime.type.Struct)3 PageContext (lucee.runtime.PageContext)2 CoderException (lucee.runtime.coder.CoderException)2 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 ClassException (lucee.commons.lang.ClassException)1