Package com.laamella.javamodel

Examples of com.laamella.javamodel.Block


        file.write(outputStreamFactory);
    }

    private void createMethodsForElement(Element element, ClassBody clas) {
        if (element.complex) {
            final Block closeTagMethod = clas.method("public void %s()", element.closeTagMethodName);
            for (Element child : element.children) {
                createMethodsForElement(child, clas);
                if (!child.complex) {
                    closeTagMethod.add("%s = null;", child.valueHandlerMethodName);
                }
            }
            for (Element child : element.attributes) {
                createMethodsForElement(child, clas);
                closeTagMethod.add("%s = null;", child.valueHandlerMethodName);
            }
        } else {
            clas.fields.add("protected %s %s = null;", element.javaType.name, element.valueHandlerMethodName);
            final Block valueHandlerMethod = clas.method("public void %s(%s %s)", element.valueHandlerMethodName, element.javaType.name, element.shortName);
            valueHandlerMethod.add("this.%s = %s;", element.valueHandlerMethodName, element.shortName);
        }
    }
View Full Code Here


        createReaderFor(element, clas);
    }

    private void createReaderForSimpleElement(final Element element, final ClassBody clas) {
        final Block reader = clas.method("public void %s(final XMLStreamReader xmlr) throws XMLStreamException", element.readTagMethodName);
        reader
                .open("do")
                .add("final int eventType = xmlr.next();")
                .open("switch (eventType)")
                .add("case START_ELEMENT:")
                .in(fail("Unexpected child: %s", "xmlr.getName()"))
                .out("case END_ELEMENT:")
                .in("return;")
                .out("case END_DOCUMENT:")
                .in(fail("Unexpected end of document"))
                .out("case CHARACTERS:")

                .in();
        createSimpleTypeHandlerCall(element, "xmlr.getText()", reader);

        reader
                .out("break;")
                .close()
                .close("while (xmlr.hasNext());")
                .add(fail("Unclosed element"));
View Full Code Here

                .method("protected String %s(final %s %s)", element.conversionMethodName, element.javaType.name, element.shortName)
                .add("return %s(%s);", element.javaType.methodName(), element.shortName);
    }

    private void createReaderForComplexElement(final Element element, final ClassBody clas) {
        final Block reader = clas.method("public void %s(final XMLStreamReader xmlr) throws XMLStreamException", element.readTagMethodName);
        reader.add("%s();", element.openTagMethodName);

        if (element.attributes.isEmpty()) {
            reader.open("if(xmlr.getAttributeCount()>0)");
            reader.add(fail("Unexpected attribute: %s", "xmlr.getAttributeName(0)"));
            reader.close();
        } else {
            reader
                    .open("for (int i = 0; i < xmlr.getAttributeCount(); i++)")
                    .add("final QName name = xmlr.getAttributeName(i);");
            for (Element attribute : element.attributes) {
                reader.add("if (name.equals(%s)) {", attribute.qNameField).in();
                createSimpleTypeHandlerCall(attribute, "xmlr.getAttributeValue(i)", reader);
                reader.close("else {");
            }
            reader.in(fail("Unexpected attribute: %s", "xmlr.getAttributeName(i)"));
            reader.close().close();
        }
        reader
                .open("do")
                .add("final int eventType = xmlr.next();")
                .add("switch (eventType) {")
                .in("case START_ELEMENT:")
                .in();

        if (element.children.isEmpty()) {
            reader.add(fail("Unexpected child: %s", "xmlr.getName()"));
        } else {
            for (Element child : element.children) {
                if (child.complex) {
                    reader
                            .open("if (xmlr.getName().equals(%s))", child.qNameField)
                            .add("%s(xmlr);", child.readTagMethodName)
                            .close("else");
                } else {
                    reader
                            .open("if (xmlr.getName().equals(%s))", child.qNameField)
                            .add("%s(xmlr);", child.readTagMethodName)
                            .close("else");
                }
            }
            reader.in(fail("Unexpected child: %s", "xmlr.getName()"));
            reader.out("break;");
        }

        reader
                .out("case END_ELEMENT:")
                .in("%s();", element.closeTagMethodName)
                .add("return;")
                .out("case END_DOCUMENT:")
                .in(fail("Unexpected end of document"))
View Full Code Here

            .add("return shipOrder;");
    }

    private void createMethodsForElement(Element element, ClassBody generatorClass) {
        if (element.complex) {
            final Block closeTagMethod = generatorClass.method("public void %s()", element.closeTagMethodName);
            generatorClass.fields.add("protected %s %s = null;", element.fullyQualifiedName, element.valueHandlerMethodName);

            List<String> constructorArgs = new ArrayList<String>();

            for (Element child : element.children) {
                createMethodsForElement(child, generatorClass);
                constructorArgs.add(child.valueHandlerMethodName);
            }
            for (Element child : element.attributes) {
                constructorArgs.add(child.valueHandlerMethodName);
            }

            closeTagMethod.add("%s = new %s(%s);", element.valueHandlerMethodName, element.fullyQualifiedName, join(", ", constructorArgs));
            closeTagMethod.add("super.%s();", element.closeTagMethodName);
        }
    }
View Full Code Here

            createReaderForSimpleElement(element, clas);
        }
    }

    private void createTypeConverter(JavaType javaType, final ClassBody clas) {
        final Block conversionMethod = clas.method("protected String %s(final %s value)", javaType.methodName(), javaType.name);
        javaType.writeBody(clas, conversionMethod);
    }
View Full Code Here

    public void generatorTest() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        XsdReader xsdReader = new XsdReader();
        String serviceName = "ship-order";
        XSModel xsModel = xsdReader.createSchemaLoader().loadURI(new File(Root.testResourcesDirectory(), serviceName + ".xsd").toURI().toString());
        final Schema someXsd = new XsdReader().readXsd(serviceName, xsModel);
        Block block = new Block();
        new ModelPrinter(block).print(someXsd);
        System.out.print(block);
    }
View Full Code Here

        createGetter(modelClass, attribute);
        createField(modelClass, attribute);
        constructorArgs.add(makeConstructorArg(attribute));
      }

      final Block constructor = modelClass.method("public %s(%s)", element.fullyQualifiedName, join(", ", constructorArgs));
      for (Element child : element.children) {
        constructor.add("this.%s = %s;", child.valueHandlerMethodName, child.valueHandlerMethodName);
      }
      for (Element attribute : element.attributes) {
        constructor.add("this.%s = %s;", attribute.valueHandlerMethodName, attribute.valueHandlerMethodName);
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.laamella.javamodel.Block

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.