Package ognl.enhance

Examples of ognl.enhance.UnsupportedCompilationException


        return "{? " + _children[0] + " }";
    }

    public String toGetSourceString(OgnlContext context, Object target)
    {
        throw new UnsupportedCompilationException("Eval expressions not supported as native java yet.");
    }
View Full Code Here


        throw new UnsupportedCompilationException("Eval expressions not supported as native java yet.");
    }

    public String toSetSourceString(OgnlContext context, Object target)
    {
        throw new UnsupportedCompilationException("Eval expressions not supported as native java yet.");
    }
View Full Code Here

    }

    public String toGetSourceString(OgnlContext context, Object target)
    {
        if (context.getCurrentObject() == null)
            throw new UnsupportedCompilationException("Current target is null.");

        String result = "";
        Method m = null;

        try {
            /* System.out.println("astproperty is indexed? : " + isIndexedAccess() + " child: " + _children[0].getClass().getName()
+ " target: " + target.getClass().getName() + " current object: " + context.getCurrentObject().getClass().getName());*/

            if (isIndexedAccess())
            {
                Object value = _children[0].getValue(context, context.getRoot());

                if (value == null || DynamicSubscript.class.isAssignableFrom(value.getClass()))
                    throw new UnsupportedCompilationException("Value passed as indexed property was null or not supported.");

                // Get root cast string if the child is a type that needs it (like a nested ASTProperty)

                String srcString = _children[0].toGetSourceString(context, context.getRoot());
                srcString = ExpressionCompiler.getRootExpression(_children[0], context.getRoot(), context) + srcString;

                if (ASTChain.class.isInstance(_children[0]))
                {
                    String cast = (String)context.remove(ExpressionCompiler.PRE_CAST);
                    if (cast != null)
                        srcString = cast + srcString;
                }

                if (ASTConst.class.isInstance(_children[0]) && String.class.isInstance(context.getCurrentObject()))
                    srcString = "\"" + srcString + "\"";

                // System.out.println("indexed getting with child srcString: " + srcString + " value class: " + value.getClass() + " and child: " + _children[0].getClass());

                if (context.get("_indexedMethod") != null)
                {
                    m = (Method)context.remove("_indexedMethod");
                    _getterClass = m.getReturnType();

                    Object indexedValue = OgnlRuntime.callMethod(context, target, m.getName(), new Object[]{value});

                    context.setCurrentType(_getterClass);
                    context.setCurrentObject(indexedValue);
                    context.setCurrentAccessor(OgnlRuntime.getCompiler().getSuperOrInterfaceClass(m, m.getDeclaringClass()));

                    return "." + m.getName() + "(" + srcString + ")";
                } else
                {
                    PropertyAccessor p = OgnlRuntime.getPropertyAccessor(target.getClass());

//                    System.out.println("child value : " + _children[0].getValue(context, context.getCurrentObject()) + " using propaccessor " + p.getClass().getName()
//                        + " and srcString " + srcString + " on target: " +  target);

                    Object currObj = context.getCurrentObject();
                    Class currType = context.getCurrentType();
                    Class prevType = context.getPreviousType();

                    Object indexVal = p.getProperty(context, target, value);

                    // reset current object for accessor

                    context.setCurrentObject(currObj);
                    context.setCurrentType(currType);
                    context.setPreviousType(prevType);

/*                    System.out.println("astprop srcString: " + srcString
   + " from child class " + _children[0].getClass().getName()
   + " and indexVal " + indexVal
   + " propertyAccessor : " + p.getClass().getName() + " context obj " + context.getCurrentObject()
   + " context obj is array? : " + context.getCurrentObject().getClass().isArray()
              + " current type: " + context.getCurrentType());*/

                    if (ASTConst.class.isInstance(_children[0]) && Number.class.isInstance(context.getCurrentObject()))
                        context.setCurrentType(OgnlRuntime.getPrimitiveWrapperClass(context.getCurrentObject().getClass()));

                    result = p.getSourceAccessor(context, target, srcString);
                    _getterClass = context.getCurrentType();
                    context.setCurrentObject(indexVal);

                    return result;
                }
            }

            String name =  ((ASTConst) _children[0]).getValue().toString();

            if (!Iterator.class.isAssignableFrom(context.getCurrentObject().getClass())
                || (Iterator.class.isAssignableFrom(context.getCurrentObject().getClass()) && name.indexOf("next") < 0))
            {
                Object currObj = target;

                try
                {
                    target = getValue(context, context.getCurrentObject());
                } catch (NoSuchPropertyException e)
                {
                    try {
                        target = getValue(context, context.getRoot());
                    } catch (NoSuchPropertyException ex) {
                        // ignore
                    }
                } finally
                {
                    context.setCurrentObject(currObj);
                }
            }

            PropertyDescriptor pd = OgnlRuntime.getPropertyDescriptor(context.getCurrentObject().getClass(), name);

            if (pd != null && pd.getReadMethod() != null
                && !context.getMemberAccess().isAccessible(context, context.getCurrentObject(), pd.getReadMethod(), name))
            {
                throw new UnsupportedCompilationException("Member access forbidden for property " + name + " on class " + context.getCurrentObject().getClass());
            }

            if (this.getIndexedPropertyType(context, context.getCurrentObject()) > 0 && pd != null)
            {
                // if an indexed method accessor need to use special property descriptors to find methods
View Full Code Here

    {
        String result = "";
        Method m = null;

        if (context.getCurrentObject() == null)
            throw new UnsupportedCompilationException("Current target is null.");

        /*System.out.println("astproperty(setter) is indexed? : " + isIndexedAccess() + " child: " + _children[0].getClass().getName()
                           + " target: " + target.getClass().getName() + " children length: " + _children.length);*/

        try {

            if (isIndexedAccess())
            {
                Object value = _children[0].getValue(context, context.getRoot());

                if (value == null)
                    throw new UnsupportedCompilationException("Value passed as indexed property is null, can't enhance statement to bytecode.");

                String srcString = _children[0].toGetSourceString(context, context.getRoot());
                srcString = ExpressionCompiler.getRootExpression(_children[0], context.getRoot(), context) + srcString;

                if (ASTChain.class.isInstance(_children[0]))
                {
                    String cast = (String)context.remove(ExpressionCompiler.PRE_CAST);
                    if (cast != null)
                        srcString = cast + srcString;
                }

                if (ASTConst.class.isInstance(_children[0]) && String.class.isInstance(context.getCurrentObject()))
                {
                    srcString = "\"" + srcString + "\"";
                }

//                System.out.println("astproperty setter using indexed value " + value + " and srcString: " + srcString);

                if (context.get("_indexedMethod") != null)
                {
                    m = (Method)context.remove("_indexedMethod");
                    PropertyDescriptor pd = (PropertyDescriptor)context.remove("_indexedDescriptor");

                    boolean lastChild = lastChild(context);
                    if (lastChild)
                    {
                        m = getIndexedWriteMethod(pd);

                        if (m == null)
                            throw new UnsupportedCompilationException("Indexed property has no corresponding write method.");
                    }

                    _setterClass = m.getParameterTypes()[0];

                    Object indexedValue = null;
                    if (!lastChild)
                        indexedValue = OgnlRuntime.callMethod(context, target, m.getName(), new Object[]{value});

                    context.setCurrentType(_setterClass);
                    context.setCurrentAccessor(OgnlRuntime.getCompiler().getSuperOrInterfaceClass(m, m.getDeclaringClass()));

                    if (!lastChild)
                    {
                        context.setCurrentObject(indexedValue);
                        return "." + m.getName() + "(" + srcString + ")";
                    } else {
                        return "." + m.getName() + "(" + srcString + ", $3)";
                    }
                } else
                {
                    PropertyAccessor p = OgnlRuntime.getPropertyAccessor(target.getClass());

                    Object currObj = context.getCurrentObject();
                    Class currType = context.getCurrentType();
                    Class prevType = context.getPreviousType();

                    Object indexVal = p.getProperty(context, target, value);

                    // reset current object for accessor

                    context.setCurrentObject(currObj);
                    context.setCurrentType(currType);
                    context.setPreviousType(prevType);

                    if (ASTConst.class.isInstance(_children[0]) && Number.class.isInstance(context.getCurrentObject()))
                        context.setCurrentType(OgnlRuntime.getPrimitiveWrapperClass(context.getCurrentObject().getClass()));

                    result = lastChild(context) ? p.getSourceSetter(context, target, srcString) : p.getSourceAccessor(context, target, srcString);

                    /*System.out.println("ASTProperty using propertyaccessor and isLastChild? " + lastChild(context)
                                       + " generated source of: " + result + " using accessor class: " + p.getClass().getName());*/

                    //result = p.getSourceAccessor(context, target, srcString);
                    _getterClass = context.getCurrentType();
                    context.setCurrentObject(indexVal);

                    /* PropertyAccessor p = OgnlRuntime.getPropertyAccessor(target.getClass());

                    if (ASTConst.class.isInstance(_children[0]) && Number.class.isInstance(context.getCurrentObject()))
                    {
                        context.setCurrentType(OgnlRuntime.getPrimitiveWrapperClass(context.getCurrentObject().getClass()));
                    }

                    result = p.getSourceSetter(context, target, srcString);

                    context.setCurrentObject(value);
                    context.setCurrentType(_getterClass);*/
                    return result;
                }
            }

            String name = ((ASTConst) _children[0]).getValue().toString();

//            System.out.println(" astprop(setter) : trying to set " + name + " on object target " + context.getCurrentObject().getClass().getName());

            if (!Iterator.class.isAssignableFrom(context.getCurrentObject().getClass())
                || (Iterator.class.isAssignableFrom(context.getCurrentObject().getClass()) &&  name.indexOf("next") < 0)) {

                Object currObj = target;

                try {
                    target = getValue(context, context.getCurrentObject());
                } catch (NoSuchPropertyException e) {
                    try {

                        target = getValue(context, context.getRoot());

                    } catch (NoSuchPropertyException ex) { }
                } finally {

                    context.setCurrentObject(currObj);
                }
            }

            PropertyDescriptor pd = OgnlRuntime.getPropertyDescriptor(OgnlRuntime.getCompiler().getInterfaceClass(context.getCurrentObject().getClass()), name);

            if (pd != null)
            {
                Method pdMethod = lastChild(context) ? pd.getWriteMethod() : pd.getReadMethod();

                if (pdMethod != null && !context.getMemberAccess().isAccessible(context, context.getCurrentObject(), pdMethod, name))
                {
                    throw new UnsupportedCompilationException("Member access forbidden for property " + name + " on class " + context.getCurrentObject().getClass());
                }
            }

            if (pd != null && this.getIndexedPropertyType(context, context.getCurrentObject()) > 0)
            {
View Full Code Here

        return result;
    }

    public String toSetSourceString(OgnlContext context, Object target)
    {
        throw new UnsupportedCompilationException("Can't generate setter for ASTList.");
    }
View Full Code Here

        return "(" + _children[0] + ")(" + _children[1] + ")";
    }
   
    public String toGetSourceString(OgnlContext context, Object target)
    {
        throw new UnsupportedCompilationException("Eval expressions not supported as native java yet.");
    }
View Full Code Here

        throw new UnsupportedCompilationException("Eval expressions not supported as native java yet.");
    }
   
    public String toSetSourceString(OgnlContext context, Object target)
    {
        throw new UnsupportedCompilationException("Map expressions not supported as native java yet.");
    }
View Full Code Here

        try {
            Class clazz = OgnlRuntime.classForName(context, _className);
            Method m = OgnlRuntime.getMethod(context, clazz, _methodName, _children, true);

            if (clazz == null || m == null)
                throw new UnsupportedCompilationException("Unable to find class/method combo " + _className + " / "  + _methodName);

            if (!context.getMemberAccess().isAccessible(context, clazz, m, _methodName))
            {
                throw new UnsupportedCompilationException("Method is not accessible, check your jvm runtime security settings. " +
                                                          "For static class method " + _className + " / "  + _methodName);
            }

            if ((_children != null) && (_children.length > 0))
            {
View Full Code Here

    }

    public String toSetSourceString(OgnlContext context, Object target)
    {
        if (_parent == null)
            throw new UnsupportedCompilationException("Can't modify constant values.");
       
        return toGetSourceString(context, target);
    }
View Full Code Here

    {
        if (RuntimeException.class.isInstance(t))
            return (RuntimeException)t;

        if (OgnlException.class.isInstance(t))
            throw new UnsupportedCompilationException("Error evluating expression: " + t.getMessage(), t);
       
        return new RuntimeException(t);
    }
View Full Code Here

TOP

Related Classes of ognl.enhance.UnsupportedCompilationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.