Examples of JLineComment


Examples of com.envoisolutions.sxc.builder.impl.JLineComment

                    if (!property.isXmlAny()) {
                        // create attribute block
                        JBlock block = builder.expectAttribute(property.getXmlName());

                        // add comment for readability
                        block.add(new JLineComment(property.getXmlStyle() + ": " + property.getName()));

                        // create collection var if necessary
                        JVar collectionVar = handleCollection(builder, property, beanVar);

                        // get the value to evaluate
                        JExpression value;
                        if (!property.isCollection()) {
                            value = builder.getAttributeVar().invoke("getValue");
                        } else {
                            JForEach forEach = block.forEach(context.toJClass(String.class), builder.getReadVariableManager().createId(property.getName() + "Item"), builder.getAttributeVar().invoke("getXmlListValue"));
                            block = forEach.body();
                            value = forEach.var();
                        }
                       
                        // read and set
                        JExpression toSet = handleAttribute(builder, block, property, value);
                        doSet(builder, block, property, beanVar, toSet, collectionVar);
                    } else {
                        handleAnyAttribute(builder, property, beanVar);
                    }

                }
                break;

                case ELEMENT:
                case ELEMENT_REF: {
                    JAXBObjectBuilder elementBuilder = builder;
                    JVar parentVar = beanVar;
                    if (property.getXmlName() != null && !property.isXmlList()) {
                        elementBuilder = builder.expectWrapperElement(property.getXmlName(), beanVar, property.getName(), property.isMixed());
                    }

                    // create collection var if necessary
                    JVar collectionVar = handleCollection(elementBuilder, property, parentVar);

                    for (ElementMapping mapping : property.getElementMappings()) {
                        // create element block
                        JBlock block = elementBuilder.expectElement(mapping.getXmlName());

                        // add comment for readability
                        block.add(new JLineComment(property.getXmlStyle() + ": " + property.getName()));

                        // get the value to evaluate
                        JVar xsrVar = builder.getChildElementVar();
                        if (!property.isXmlList()) {
                            // read and set
                            JExpression toSet = handleElement(builder, xsrVar, block, property, mapping.isNillable(), mapping.getComponentType());
                            doSet(builder, block, property, parentVar, toSet, collectionVar);
                        } else {
                            JForEach forEach = block.forEach(context.toJClass(String.class), builder.getReadVariableManager().createId(property.getName() + "Item"), xsrVar.invoke("getElementAsXmlList"));
                            block = forEach.body();
                            JExpression value = forEach.var();

                            // read and set
                            String propertyName = property.getName();
                            if (property.isCollection()) propertyName += "Item";
                            propertyName = builder.getReadVariableManager().createId(propertyName);

                            JExpression toSet;
                            if (property.isIdref() || property.getAdapterType() == null) {
                                toSet = coerce(builder, xsrVar, value, toClass(mapping.getComponentType()));
                            } else {
                                // adapted type
                                JVar adapterVar = builder.getAdapter(property.getAdapterType());
                   
                                block.add(new JBlankLine());

                                // convert raw value into bound type
                                Class targetType = toClass(mapping.getComponentType());
                                JVar valueVar = block.decl(context.toJClass(targetType), propertyName);
                                JTryBlock tryBlock = block._try();
                                tryBlock.body().assign(valueVar, adapterVar.invoke("unmarshal").arg(value));

                                JCatchBlock catchException = tryBlock._catch(context.toJClass(Exception.class));
                                JBlock catchBody = catchException.body();
                                catchBody.invoke(builder.getReadContextVar(), "xmlAdapterError")
                                        .arg(xsrVar)
                                        .arg(context.dotclass(property.getAdapterType()))
                                        .arg(context.dotclass(targetType))
                                        .arg(context.dotclass(targetType))
                                        .arg(catchException.param("e"));
                                catchBody._continue();

                                block.add(new JBlankLine());

                                toSet = valueVar;
                            }

                            // JaxB refs need to be wrapped with a JAXBElement
                            if (toClass(property.getComponentType()).equals(JAXBElement.class)) {
                                toSet = newJaxBElement(xsrVar, toClass(mapping.getComponentType()), toSet);
                            }

                            doSet(builder, block, property, parentVar, toSet, collectionVar);
                        }

                    }

                    if (property.isXmlAny()) {
                        // create element block
                        JBlock block = elementBuilder.expectAnyElement();

                        // add comment for readability
                        block.add(new JLineComment(property.getXmlStyle() + ": " + property.getName()));

                        // read and set
                        JInvocation toSet = builder.getReadContextVar().invoke("readXmlAny")
                                .arg(builder.getChildElementVar())
                                .arg(context.dotclass(property.getComponentType()))
                                .arg(property.isLax() ? JExpr.TRUE : JExpr.FALSE);
                        doSet(builder, block, property, parentVar, toSet, collectionVar);
                    }

                    if (property.isMixed()) {
                        // create element block
                        JBlock block = elementBuilder.expectMixedElement();

                        // add comment for readability
                        block.add(new JLineComment(property.getXmlStyle() + " (Mixed): " + property.getName()));

                        // read and set
                        JInvocation toSet = builder.getChildElementVar().invoke("getText");
                        doSet(builder, block, property, parentVar, toSet, collectionVar);
                    }
                }
                break;

                case VALUE: {
                    // value is read in class block
                    JBlock block = builder.expectValue();

                    // add comment for readability
                    block.add(new JBlankLine());
                    block.add(new JLineComment(property.getXmlStyle() + ": " + property.getName()));

                    // read and set value
                    handleValue(builder, builder.getXSR(), block, property, beanVar);
                }
                break;
View Full Code Here

Examples of com.envoisolutions.sxc.builder.impl.JLineComment

    private void handleAnyAttribute(JAXBObjectBuilder builder, Property property, JVar beanVar) {
        // create element block
        JBlock block = builder.expectAnyAttribute();

        // add comment for readability
        block.add(new JLineComment(property.getXmlStyle() + ": " + property.getName()));

        //
        // declare any attribute map property at top of method
        String mapVarName = builder.getReadVariableManager().createId(property.getName());
        JVar mapVar = builder.getReadMethod().body().decl(context.getGenericType(property.getType()), mapVarName, JExpr._null());
View Full Code Here

Examples of com.envoisolutions.sxc.builder.impl.JLineComment

        for (Property property : bean.getProperties()) {
            if (property.getXmlStyle() == Property.XmlStyle.ATTRIBUTE) {
                JBlock block = builder.getWriteMethod().body();
                block.add(new JBlankLine());
                block.add(new JLineComment(property.getXmlStyle() + ": " + property.getName()));

                JExpression propertyVar = getValue(builder, property, block);

                if (!property.isXmlAny()) {
                    if (!toClass(property.getType()).isPrimitive()) {
View Full Code Here

Examples of com.envoisolutions.sxc.builder.impl.JLineComment

        for (Property property : bean.getProperties()) {
            if (property.getXmlStyle() == Property.XmlStyle.ATTRIBUTE) continue;

            builder.getWriteMethod().body().add(new JBlankLine());
            builder.getWriteMethod().body().add(new JLineComment(property.getXmlStyle() + ": " + property.getName()));

            JVar propertyVar = getValue(builder, property, builder.getWriteMethod().body());

            switch (property.getXmlStyle()) {
                case ELEMENT:
View Full Code Here

Examples of com.envoisolutions.sxc.builder.impl.JLineComment

            if (!type.isEnum()) {
                // if isXsiNil return null;
                JBlock body = parserBuilder.getMethod().body();
                body.add(new JBlankLine());
                body.add(new JLineComment("Check for xsi:nil"));
                body._if(parserBuilder.getXSR().invoke("isXsiNil"))._then()._return(JExpr._null());

                // if context is null, initialize context
                body.add(new JBlankLine());
                JBlock contextNullBlock = body._if(parserBuilder.getContextVar().eq(JExpr._null()))._then();
View Full Code Here

Examples of com.envoisolutions.sxc.builder.impl.JLineComment

        parserBuilder.getMethod()._throws(Exception.class);

        getParserBuilder().expectElement(elementName, parserBuilder, beanVar);

        JBlock block = new JBlock();
        block.add(new JLineComment("ELEMENT WRAPPER: " + propertyName));
        getParserBuilder().setElementBlock(elementName, null, block);

        JAXBObjectBuilder builder = new JAXBObjectBuilder(this, parserBuilder, mixed);
        return builder;
    }
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.