Examples of JTryBlock


Examples of com.sun.codemodel.JTryBlock

    // public boolean marshall(final String filename) throws FileNotFoundException {
    final JMethod generateMarshalOutputStream = cc.implClass.method(JMod.PUBLIC, cc.implClass.owner().BOOLEAN, "marshal");
    generateMarshalOutputStream.javadoc().append(comment);

    // try {
    final JTryBlock tryBlock = generateMarshalOutputStream.body()._try();
    // m = this.createMarshaller();
    tryBlock.body().assign(mVar, JExpr._this().invoke(createMashaller));

    // JAXBElement<Kml> jaxbRootElement = new JAXBElement<Kml>(new QName("http://www.opengis.net/kml/2.2", "kml"), Kml.class, this);
//    JInvocation newJaxbElement = JExpr._new(jaxbElementClass).arg(createQName("http://www.opengis.net/kml/2.2", "kml")).arg(
//        kmlClass.boxify().dotclass()).arg(JExpr._this());
//    final JVar jaxbRootElementVar = tryBlock.body().decl(jaxbElementClass, "jaxbRootElement", newJaxbElement);

    // m.marshal(jaxbRootElement, outputStream);
    tryBlock.body().add(mVar.invoke("marshal").arg(JExpr._this()).arg(systemClass.boxify().staticRef("out")));

    // return true;
    tryBlock.body()._return(JExpr.TRUE);

    // } catch (JAXBException _x) {
    final JBlock catchBlock = tryBlock._catch(jaxbExceptionClass.boxify()).body();
    catchBlock.directStatement("_x.printStackTrace();");
    catchBlock._return(JExpr.FALSE);
    return generateMarshalOutputStream;
  }
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

    }
    generateMarshalOutputStream.javadoc().append(comment);
    final JVar value = generateMarshalOutputStream.param(JMod.FINAL, argumentType, argumentType.name().toLowerCase());

    // try {
    final JTryBlock tryBlock = generateMarshalOutputStream.body()._try();
    // m = this.createMarshaller();
    tryBlock.body().assign(mVar, JExpr._this().invoke(createMashaller));

    // JAXBElement<Kml> jaxbRootElement = new JAXBElement<Kml>(new QName("http://www.opengis.net/kml/2.2", "kml"), Kml.class, this);
//    JInvocation newJaxbElement = JExpr._new(jaxbElementClass).arg(createQName("http://www.opengis.net/kml/2.2", "kml")).arg(
//        kmlClass.boxify().dotclass()).arg(JExpr._this());
//    final JVar jaxbRootElementVar = tryBlock.body().decl(jaxbElementClass, "jaxbRootElement", newJaxbElement);

    // m.marshal(jaxbRootElement, outputStream);
    tryBlock.body().add(mVar.invoke("marshal").arg(JExpr._this()).arg(value));

    // return true;
    tryBlock.body()._return(JExpr.TRUE);

    // } catch (JAXBException _x) {
    final JBlock catchBlock = tryBlock._catch(jaxbExceptionClass.boxify()).body();
    catchBlock.directStatement("_x.printStackTrace();");
    catchBlock._return(JExpr.FALSE);
    return generateMarshalOutputStream;
  }
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

    generateUnMarshallerFromString.javadoc().add("          and KML 2.1 (namespace: http://earth.google.com/kml/2.1) \n");
    generateUnMarshallerFromString.javadoc().trimToSize();
   
    final JVar fileunmarshallVar = generateUnMarshallerFromString.param(JMod.FINAL, fileClass, "file");
    generateUnMarshallerFromString._throws(FileNotFoundException.class);
    final JTryBlock tryBlock = generateUnMarshallerFromString.body()._try();
    final JVar localUnmarshallerFile = tryBlock.body().decl(jaxbUnmarshallerClass, "unmarshaller",
        jaxbContextClass.boxify().staticInvoke("newInstance").arg(JExpr.direct("Kml.class")).invoke("createUnmarshaller"));
   
    final JVar inputsource = tryBlock.body().decl(inputsourceClass, "input", JExpr._new(inputsourceClass).arg(JExpr._new(fileReaderClass).arg(fileunmarshallVar)));
    final JVar saxsource = tryBlock.body().decl(saxsourceClass, "saxSource", JExpr._new(saxsourceClass).arg(JExpr._new(namespaceFilterXMLReaderclass).arg(JExpr.FALSE)).arg(inputsource));
    final JVar decl = tryBlock.body().decl(kmlClass, "jaxbRootElement", JExpr.cast(kmlClass, JExpr.invoke(localUnmarshallerFile, "unmarshal").arg(saxsource)));
    tryBlock.body()._return(decl);
    tryBlock._catch(saxExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryBlock._catch(parserConfigurationExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryBlock._catch(jaxbExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    generateUnMarshallerFromString.body()._return(JExpr._null());
  }
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

    generateUnMarshallerFromString.javadoc().add(
        "with the exception that it transforms a " + invokeMarshalWith.name() + " into a graph of Java objects. \n");
    generateUnMarshallerFromString.javadoc().trimToSize();
    final JVar stringunmarshallVar = generateUnMarshallerFromString.param(JMod.FINAL, invokeMarshalWith, "content");

    final JTryBlock tryStringBlock = generateUnMarshallerFromString.body()._try();
    final JVar localUnmarshaller = tryStringBlock.body().decl(jaxbUnmarshallerClass, "unmarshaller",
        jaxbContextClass.boxify().staticInvoke("newInstance").arg(JExpr.direct("Kml.class")).invoke("createUnmarshaller"));
   
    final JVar inputsource = tryStringBlock.body().decl(inputsourceClass, "input", JExpr._new(inputsourceClass).arg(stringunmarshallVar));
    final JVar saxsource = tryStringBlock.body().decl(saxsourceClass, "saxSource", JExpr._new(saxsourceClass).arg(JExpr._new(namespaceFilterXMLReaderclass).arg(JExpr.FALSE)).arg(inputsource));
    final JVar decl = tryStringBlock.body().decl(kmlClass, "jaxbRootElement", JExpr.cast(kmlClass, JExpr.invoke(localUnmarshaller, "unmarshal").arg(saxsource)));
    tryStringBlock.body()._return(decl);
    tryStringBlock._catch(saxExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryStringBlock._catch(parserConfigurationExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryStringBlock._catch(jaxbExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    generateUnMarshallerFromString.body()._return(JExpr._null());   
  }
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

    generateUnMarshallerFromString.javadoc().add("Similar to the other unmarshal methods \n\n");
    generateUnMarshallerFromString.javadoc().add("with the exception that it transforms a String into a graph of Java objects. \n");
    generateUnMarshallerFromString.javadoc().trimToSize();
    final JVar stringunmarshallVar = generateUnMarshallerFromString.param(JMod.FINAL, stringClass, "content");

    final JTryBlock tryStringBlock = generateUnMarshallerFromString.body()._try();
    final JVar localUnmarshaller = tryStringBlock.body().decl(jaxbUnmarshallerClass, "unmarshaller",
        jaxbContextClass.boxify().staticInvoke("newInstance").arg(JExpr.direct("Kml.class")).invoke("createUnmarshaller"));
   
    final JVar inputsource = tryStringBlock.body().decl(inputsourceClass, "input", JExpr._new(inputsourceClass).arg(JExpr._new(stringReaderClass).arg(stringunmarshallVar)));
    final JVar saxsource = tryStringBlock.body().decl(saxsourceClass, "saxSource", JExpr._new(saxsourceClass).arg(JExpr._new(namespaceFilterXMLReaderclass).arg(JExpr.FALSE)).arg(inputsource));
    final JVar decl = tryStringBlock.body().decl(kmlClass, "jaxbRootElement", JExpr.cast(kmlClass, JExpr.invoke(localUnmarshaller, "unmarshal").arg(saxsource)));
    tryStringBlock.body()._return(decl);
    tryStringBlock._catch(saxExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryStringBlock._catch(parserConfigurationExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryStringBlock._catch(jaxbExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    generateUnMarshallerFromString.body()._return(JExpr._null());   
  }
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

    generateUnMarshallerFileFile.javadoc().add("all constraints defined in OGC's KML schema specification.");
    generateUnMarshallerFileFile.javadoc().trimToSize();
    final JVar fileunmarshallVar = generateUnMarshallerFileFile.param(JMod.FINAL, fileClass, "file");
    final JVar validateVar = generateUnMarshallerFileFile.param(JMod.FINAL, boolean.class, "validate");

    final JTryBlock tryBlock = generateUnMarshallerFileFile.body()._try();
    final JVar localUnmarshallerFile = tryBlock.body().decl(jaxbUnmarshallerClass, "unmarshaller",
        jaxbContextClass.boxify().staticInvoke("newInstance").arg(JExpr.direct("Kml.class")).invoke("createUnmarshaller"));

    final JConditional ifBlockFilename = tryBlock.body()._if(validateVar.eq(JExpr.TRUE));
    ifBlockFilename._then().add(kmlClass.boxify().staticInvoke(generateValidate).arg(localUnmarshallerFile));
   
    final JVar inputsource = tryBlock.body().decl(inputsourceClass, "input", JExpr._new(inputsourceClass).arg(JExpr._new(fileReaderClass).arg(fileunmarshallVar)));
    final JVar saxsource = tryBlock.body().decl(saxsourceClass, "saxSource", JExpr._new(saxsourceClass).arg(JExpr._new(namespaceFilterXMLReaderclass).arg(validateVar)).arg(inputsource));
    final JVar decl = tryBlock.body().decl(kmlClass, "jaxbRootElement", JExpr.cast(kmlClass, JExpr.invoke(localUnmarshallerFile, "unmarshal").arg(saxsource)));
    tryBlock.body()._return(decl);
    tryBlock._catch(saxExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryBlock._catch(parserConfigurationExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryBlock._catch(jaxbExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    tryBlock._catch(fileNotFoundExceptionClass.boxify()).body().directStatement("_x.printStackTrace();");
    generateUnMarshallerFileFile.body()._return(JExpr._null());

    final JMethod generateUnMarshallerFile = cc.implClass.method(JMod.PUBLIC | JMod.STATIC, kmlClass, "unmarshal");
    generateUnMarshallerFile.param(JMod.FINAL, fileClass, "file");
    generateUnMarshallerFile.javadoc().add("KML to Java\n");
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

  }

  private JMethod generateValidateMethod(final ClassOutlineImpl cc) {
    final JMethod generateValidate = cc.implClass.method(JMod.PRIVATE | JMod.STATIC, cc.implClass.owner().BOOLEAN, "validate");
    final JVar unmarshallValidateVar = generateValidate.param(JMod.FINAL, jaxbUnmarshallerClass, "unmarshaller");
    final JTryBlock tryValidateBlock = generateValidate.body()._try();
    final JVar schemaFactoryVar = tryValidateBlock.body().decl(schemaFactoryClass, "sf",
        schemaFactoryClass.boxify().staticInvoke("newInstance").arg(xmlConstantsClass.boxify().staticRef("W3C_XML_SCHEMA_NS_URI")));
    final JVar schemaFileVar = tryValidateBlock.body().decl(fileClass, "schemaFile", JExpr._new(fileClass).arg(schemaLocationVar));
    final JVar schemaVar = tryValidateBlock.body().decl(schemaClass, "schema", schemaFactoryVar.invoke("newSchema").arg(schemaFileVar));
    tryValidateBlock.body().add(unmarshallValidateVar.invoke("setSchema").arg(schemaVar));
    tryValidateBlock.body()._return(JExpr.TRUE);
    final JBlock catchValidateBlock = tryValidateBlock._catch(saxExceptionClass.boxify()).body();
    catchValidateBlock.directStatement("_x.printStackTrace();");
    generateValidate.body()._return(JExpr.FALSE);
    return generateValidate;
  }
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

    // clone._throws(CloneNotSupportedException.class);

    final JVar copy = clone.body().decl(implClass, "copy");

    if (extends1.fullName().equals("java.lang.Object")) {
      final JTryBlock ctry = clone.body()._try();
      ctry.body().assign(copy, JExpr.cast(implClass, JExpr._super().invoke("clone")));
      ctry._catch(cloneNotSupportedException.boxify()).body()._throw(JExpr._new(internalError.boxify()).arg(JExpr.direct("_x.toString()")));
    } else {
      clone.body().assign(copy, JExpr.cast(implClass, JExpr._super().invoke("clone")));
    }

    for (final JFieldVar jFieldVar : fields) {
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

            of.method( JMod.STATIC, XMLGregorianCalendar.class, "createXMLGregorianCalendar" );

        createXMLGregorianCalendar.body().directStatement( "// " + getMessage( "title" ) );
        value = createXMLGregorianCalendar.param( JMod.FINAL, Calendar.class, "value" );

        final JTryBlock tryBlock = createXMLGregorianCalendar.body()._try();
        final JConditional notNull = tryBlock.body()._if( value.ne( JExpr._null() ) );

        final JVar calendar = notNull._then().decl( cm.ref( GregorianCalendar.class ), "calendar" );
        calendar.init( JExpr._new( cm.ref( GregorianCalendar.class ) ) );
        notNull._then().add( calendar.invoke( "setTimeZone" ).arg( value.invoke( "getTimeZone" ) ) );
        notNull._then().add( calendar.invoke( "setTimeInMillis" ).arg( value.invoke( "getTimeInMillis" ) ) );
        notNull._then()._return( cm.ref( DatatypeFactory.class ).staticInvoke( "newInstance" ).invoke(
            "newXMLGregorianCalendar" ).arg( calendar ) );

        tryBlock.body()._return( JExpr._null() );

        final JCatchBlock catchBlock = tryBlock._catch( cm.ref( DatatypeConfigurationException.class ) );
        catchBlock.body()._throw( JExpr._new( cm.ref( AssertionError.class ) ).arg( catchBlock.param( "e" ) ) );

        createXMLGregorianCalendar.javadoc().append(
            "Creates a " + XMLGregorianCalendar.class.getName() + " instance from a " + Calendar.class.getName()
            + " instance." );
View Full Code Here

Examples of com.sun.codemodel.JTryBlock

        JClass objectType = model.ref(Object.class);
        getEndpoint = servCls.method(JMod.PUBLIC, objectType, "getEndpoint");
        JVar epVar = getEndpoint.param(Endpoint.class, "endpoint");
       
        JBlock geBody = getEndpoint.body();
        JTryBlock tryBlock = geBody._try();
       
        JInvocation createProxy = pfVar.invoke("create");
        createProxy.arg(JExpr.direct(epVar.name()).invoke("getBinding"));
        createProxy.arg(JExpr.direct(epVar.name()).invoke("getUrl"));
       
        tryBlock.body()._return(createProxy);

        JCatchBlock catchBlock = tryBlock._catch(model.ref(MalformedURLException.class));
        JType xreType = model._ref(XFireRuntimeException.class);
        JInvocation xreThrow = JExpr._new(xreType);
        xreThrow.arg("Invalid URL");
        xreThrow.arg(catchBlock.param("e"));
       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.