Package com.sun.codemodel

Examples of com.sun.codemodel.JTryBlock


    // create new instance of the UDF class
    sub.assign(workspaceJVars[1], getUDFInstance(m));

    // create try..catch block to initialize the UDF instance with argument OIs
    JTryBlock udfInitTry = sub._try();
    udfInitTry.body().assign(
      workspaceJVars[0],
      workspaceJVars[1].invoke("initialize")
      .arg(oiArray));

    JCatchBlock udfInitCatch = udfInitTry._catch(m.directClass(Exception.class.getCanonicalName()));
    JVar exVar = udfInitCatch.param("ex");
    udfInitCatch.body()
      ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
        .arg(JExpr.lit(String.format("Failed to initialize GenericUDF"))).arg(exVar));
View Full Code Here


    // declare generic object for storing return value from GenericUDF.evaluate
    JVar retVal = sub.decl(m._ref(Object.class), "ret");

    // create try..catch block to call the GenericUDF instance with given input
    JTryBlock udfEvalTry = sub._try();
    udfEvalTry.body().assign(retVal,
      workspaceJVars[1].invoke("evaluate").arg(workspaceJVars[3]));

    JCatchBlock udfEvalCatch = udfEvalTry._catch(m.directClass(Exception.class.getCanonicalName()));
    JVar exVar = udfEvalCatch.param("ex");
    udfEvalCatch.body()
      ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
        .arg(JExpr.lit(String.format("GenericUDF.evaluate method failed"))).arg(exVar));
View Full Code Here

        type_dtFactory = model._ref(DatatypeFactory.class);
       
        JDefinedClass readerCls = rootReader.getReaderClass();
        dtf = readerCls.field(JMod.STATIC, type_dtFactory, "dtFactory");
        JMethod constructor = readerCls.constructor(JMod.PUBLIC);
        JTryBlock tb = constructor.body()._try();
        JBlock body = tb.body();
        body.assign(dtf, JExpr.direct(DatatypeFactory.class.getName()+".newInstance()"));
        tb._catch((JClass) rootReader.getCodeModel()._ref(DatatypeConfigurationException.class));
       
        Map<QName, ? extends RuntimeElementInfo> elementMappings = set.getElementMappings(null);
        for (Map.Entry<QName, ? extends RuntimeElementInfo> e : elementMappings.entrySet()) {
            QName q = e.getKey();
            RuntimeElementInfo rei = e.getValue();
View Full Code Here

        type_dtFactory = model._ref(DatatypeFactory.class);
       
        JDefinedClass readerCls = rootReader.getReaderClass();
        dtf = readerCls.field(JMod.STATIC, type_dtFactory, "dtFactory");
        JMethod constructor = builder.getParserConstructor();
        JTryBlock tb = constructor.body()._try();
        JBlock body = tb.body();
        body.assign(dtf, JExpr.direct(DatatypeFactory.class.getName()+".newInstance()"));
        tb._catch((JClass) rootReader.getCodeModel()._ref(DatatypeConfigurationException.class));
       
        Map<QName, ? extends RuntimeElementInfo> elementMappings = set.getElementMappings(null);
        for (Map.Entry<QName, ? extends RuntimeElementInfo> e : elementMappings.entrySet()) {
            QName q = e.getKey();
            RuntimeElementInfo rei = e.getValue();
View Full Code Here

    private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
        JBlock staticBlock = cls.init();
        JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
        JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
       
        JTryBlock tryBlock = staticBlock._try();
        tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
        JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
        catchBlock.param("ex");
        catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));

        staticBlock.assign(urlField, urlVar);
        staticBlock.assign(exField, exVar);
View Full Code Here

    // create new instance of the UDF class
    sub.assign(workspaceJVars[1], getUDFInstance(m));

    // create try..catch block to initialize the UDF instance with argument OIs
    JTryBlock udfInitTry = sub._try();
    udfInitTry.body().assign(
      workspaceJVars[0],
      workspaceJVars[1].invoke("initialize")
      .arg(oiArray));

    JCatchBlock udfInitCatch = udfInitTry._catch(m.directClass(Exception.class.getCanonicalName()));
    JVar exVar = udfInitCatch.param("ex");
    udfInitCatch.body()
      ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
        .arg(JExpr.lit(String.format("Failed to initialize GenericUDF"))).arg(exVar));
View Full Code Here

    // declare generic object for storing return value from GenericUDF.evaluate
    JVar retVal = sub.decl(m._ref(Object.class), "ret");

    // create try..catch block to call the GenericUDF instance with given input
    JTryBlock udfEvalTry = sub._try();
    udfEvalTry.body().assign(retVal,
      workspaceJVars[1].invoke("evaluate").arg(workspaceJVars[3]));

    JCatchBlock udfEvalCatch = udfEvalTry._catch(m.directClass(Exception.class.getCanonicalName()));
    JVar exVar = udfEvalCatch.param("ex");
    udfEvalCatch.body()
      ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
        .arg(JExpr.lit(String.format("GenericUDF.evaluate method failed"))).arg(exVar));
View Full Code Here

    // create new instance of the UDF class
    sub.assign(workspaceJVars[1], getUDFInstance(m));

    // create try..catch block to initialize the UDF instance with argument OIs
    JTryBlock udfInitTry = sub._try();
    udfInitTry.body().assign(
      workspaceJVars[0],
      workspaceJVars[1].invoke("initialize")
      .arg(oiArray));

    JCatchBlock udfInitCatch = udfInitTry._catch(m.directClass(Exception.class.getCanonicalName()));
    JVar exVar = udfInitCatch.param("ex");
    udfInitCatch.body()
      ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
        .arg(JExpr.lit(String.format("Failed to initialize GenericUDF"))).arg(exVar));
View Full Code Here

    // declare generic object for storing return value from GenericUDF.evaluate
    JVar retVal = sub.decl(m._ref(Object.class), "ret");

    // create try..catch block to call the GenericUDF instance with given input
    JTryBlock udfEvalTry = sub._try();
    udfEvalTry.body().assign(retVal,
      workspaceJVars[1].invoke("evaluate").arg(workspaceJVars[3]));

    JCatchBlock udfEvalCatch = udfEvalTry._catch(m.directClass(Exception.class.getCanonicalName()));
    JVar exVar = udfEvalCatch.param("ex");
    udfEvalCatch.body()
      ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
        .arg(JExpr.lit(String.format("GenericUDF.evaluate method failed"))).arg(exVar));
View Full Code Here

                    createMapBlock.assign(mapVar, fieldAccessorField.invoke("getObject").arg(builder.getXSR()).arg(builder.getReadContextVar()).arg(beanVar));
                }
            } else {
                Method getter = property.getGetter() ;
                if (!isPrivate(getter)) {
                    JTryBlock tryGetter = createMapBlock._try();
                    tryGetter.body().assign(mapVar, beanVar.invoke(getter.getName()));

                    JCatchBlock catchException = tryGetter._catch(context.toJClass(Exception.class));
                    catchException.body().invoke(builder.getReadContextVar(), "getterError")
                            .arg(builder.getXSR())
                            .arg(context.dotclass(property.getBean().getType()))
                            .arg(getter.getName())
                            .arg(catchException.param("e"));
                    catchException.body()._continue();
                } else {
                    JFieldVar propertyAccessorField = builder.getPrivatePropertyAccessor(property.getGetter(), property.getSetter(), property.getName());
                    createMapBlock.assign(mapVar, propertyAccessorField.invoke("getObject").arg(builder.getXSR()).arg(builder.getReadContextVar()).arg(beanVar));
                }
            }

            //     if (map != null) {
            //         map.clear();
            JConditional arrayFoundCondition = createMapBlock._if(mapVar.ne(JExpr._null()));
            arrayFoundCondition._then().invoke(mapVar, "clear");

            //     } else {
            //         map = new ArrayList();
            JType mapType = getMapClass(property.getType(), property.getComponentType());
            if (mapType != null) {
                arrayFoundCondition._else().assign(mapVar, JExpr._new(mapType));
            } else {
                arrayFoundCondition._else().invoke(builder.getReadContextVar(), "uncreatableMap")
                        .arg(builder.getXSR())
                        .arg(context.dotclass(property.getBean().getType()))
                        .arg(property.getName())
                        .arg(context.dotclass(property.getType()));
                arrayFoundCondition._else()._continue();
            }
        }
        //     }
        // }

        // collection.add(item);
        block.add(mapVar.invoke("put").arg(builder.getAttributeVar().invoke("getName")).arg(toSet));


        //
        // set the map into the bean at the bottom of the method
        //
        // if (map != null) {
        //     bean.setAnyAttribute(map);
        // }
        if (property.getField() != null) {
            Field field = property.getField();

            JBlock assignMapBlock = builder.getReadTailBlock()._if(mapVar.ne(JExpr._null()))._then();

            if (!isPrivate(field)) {
                assignMapBlock.assign(beanVar.ref(field.getName()), mapVar);
            } else {
                JFieldVar fieldAccessorField = builder.getPrivateFieldAccessor(field);
                assignMapBlock.add(fieldAccessorField.invoke("setObject").arg(builder.getXSR()).arg(builder.getReadContextVar()).arg(beanVar).arg(mapVar));
            }
        } else {
            // if there is no setter method, the map is not assigned into the class
            // this assumes that the getter returned the a map instance and held on to a reference
            Method setter = property.getSetter();
            if (setter != null) {
                JBlock assignMapBlock = builder.getReadTailBlock()._if(mapVar.ne(JExpr._null()))._then();
                if (!isPrivate(setter)) {

                    JTryBlock trySetter = assignMapBlock._try();
                    trySetter.body().add(beanVar.invoke(setter.getName()).arg(mapVar));

                    JCatchBlock catchException = trySetter._catch(context.toJClass(Exception.class));
                    catchException.body().invoke(builder.getReadContextVar(), "setterError")
                            .arg(builder.getXSR())
                            .arg(context.dotclass(property.getBean().getType()))
                            .arg(setter.getName())
                            .arg(context.dotclass(setter.getParameterTypes()[0]))
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JTryBlock

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.