Package com.envoisolutions.sxc.builder

Examples of com.envoisolutions.sxc.builder.BuildException


       
        try {
            writerClass = model._class(className);
            writerClass._extends(Writer.class);
        } catch (JClassAlreadyExistsException e) {
            throw new BuildException(e);
        }

        JMethod ctr = writerClass.constructor(JMod.PUBLIC);
        ctr.body().invoke("super").arg(ctr.param(Context.class,"context"));
View Full Code Here


                Class<?> readAs = method.getReturnType();
                JExpression val = handleElement(builder, target, adapter, readAs, nillable);
               
                toSet = handleEnum(builder, val, c);
            } catch (Exception e) {
                throw new BuildException(e);
            }
        } else if (c.equals(byte[].class)) {
            JClass buType = (JClass) builder.getCodeModel()._ref(BinaryUtils.class);
           
            toSet = buType.staticInvoke("decodeAsBytes").arg(builder.getXSR());
View Full Code Here

                writeNil._return();
               
                JVar valueVar = block.decl(valueType, "_enum", object.invoke("value"));
                writeSimpleTypeElement(b, target, adapter, valueVar, nillable, readAs, readAs, valueType);
            } catch (Exception e) {
                throw new BuildException(e);
            }
        } else if (c.equals(BigInteger.class) || c.equals(BigDecimal.class) || c.equals(Duration.class)) {
            writePropertyWithMethodInvoke(b, object, jt, "toString", nillable);
        } else if (c.equals(byte[].class)) {
            writeBase64Binary(b, object, jt, nillable)
View Full Code Here

                Class<?> readAs = method.getReturnType();
                JExpression val = handleElement(builder, target, adapter, readAs, nillable);
               
                toSet = handleEnum(builder, val, c);
            } catch (Exception e) {
                throw new BuildException(e);
            }
        } else if (c.equals(byte[].class)) {
            JClass buType = (JClass) builder.getCodeModel()._ref(BinaryUtils.class);
           
            toSet = buType.staticInvoke("decodeAsBytes").arg(builder.getXSR());
View Full Code Here

            Enum[] enumValues;
            try {
                Method method = type.getMethod("values");
                enumValues = (Enum[]) method.invoke(null);
            } catch (Exception e) {
                throw new BuildException("Class is not an enumeration " + type.getName());
            }

            if (enumValues.length == 0) {
                throw new BuildException("Enum contains no values " + type.getName());
            }

            Transducer transducer = (Transducer) runtimeEnumLeafInfo;
            for (Enum enumValue : enumValues) {
                String enumText;
                try {
                    enumText = transducer.print(enumValue).toString();
                } catch (AccessorException e) {
                    throw new BuildException(e);
                }
                enumInfo.getEnumMap().put(enumValue, enumText);
            }

            model.addEnum(enumInfo);
View Full Code Here

                try {
                    Field coreField = anyAttributeAccessor.getClass().getDeclaredField("core");
                    coreField.setAccessible(true);
                    anyAttributeAccessor = (Accessor) coreField.get(anyAttributeAccessor);
                } catch (Throwable e) {
                    throw new BuildException("Unable to access private fields of AdaptedAccessor class", e);
                }
            }

            if (anyAttributeAccessor instanceof Accessor.FieldReflection) {
                Accessor.FieldReflection fieldReflection = (Accessor.FieldReflection) anyAttributeAccessor;
                anyAttributeProperty = new Property(bean, fieldReflection.f.getName());
                anyAttributeProperty.setField(fieldReflection.f);
                anyAttributeProperty.setType(fieldReflection.f.getGenericType());
            } else if (anyAttributeAccessor instanceof Accessor.GetterSetterReflection) {
                Accessor.GetterSetterReflection getterSetterReflection = (Accessor.GetterSetterReflection) anyAttributeAccessor;

                if (getterSetterReflection.getter != null) {
                    String propertyName = getterSetterReflection.getter.getName();
                    if (propertyName.startsWith("get")) {
                        propertyName = Introspector.decapitalize(propertyName.substring(3));
                    } else if (propertyName.startsWith("is")) {
                        propertyName = Introspector.decapitalize(propertyName.substring(2));
                    }
                    anyAttributeProperty = new Property(bean, propertyName);
                    anyAttributeProperty.setType(getterSetterReflection.getter.getGenericReturnType());
                } else if (getterSetterReflection.setter != null) {
                    String propertyName = getterSetterReflection.setter.getName();
                    if (propertyName.startsWith("set")) {
                        propertyName = Introspector.decapitalize(propertyName.substring(3));
                    }
                    anyAttributeProperty = new Property(bean, propertyName);
                    anyAttributeProperty.setType(getterSetterReflection.setter.getGenericParameterTypes()[0]);
                } else {
                    throw new BuildException("Any attribute property for class " + bean + " does not have a getter or setter method");
                }

                anyAttributeProperty.setGetter(getterSetterReflection.getter);
                anyAttributeProperty.setSetter(getterSetterReflection.setter);
            } else {
                throw new BuildException("Unknown property accessor type '" + anyAttributeAccessor.getClass().getName() + "' for class " + bean);
            }           

            anyAttributeProperty.setXmlStyle(Property.XmlStyle.ATTRIBUTE);
            anyAttributeProperty.setComponentType(String.class);
            anyAttributeProperty.setXmlAny(true);
View Full Code Here

                Field coreField = accessor.getClass().getDeclaredField("core");
                coreField.setAccessible(true);
                accessor = (Accessor) coreField.get(accessor);

            } catch (Throwable e) {
                throw new BuildException("Unable to access private fields of AdaptedAccessor class", e);
            }
        }

        if (accessor instanceof Accessor.FieldReflection) {
            Accessor.FieldReflection fieldReflection = (Accessor.FieldReflection) accessor;
            property.setField(fieldReflection.f);
        } else if (accessor instanceof Accessor.GetterSetterReflection) {
            Accessor.GetterSetterReflection getterSetterReflection = (Accessor.GetterSetterReflection) accessor;
            property.setGetter(getterSetterReflection.getter);
            property.setSetter(getterSetterReflection.setter);
        } else {
            throw new BuildException("Unknown property accessor type '" + accessor.getClass().getName() + "' for property " + property);
        }

        if (runtimePropertyInfo instanceof RuntimeAttributePropertyInfo) {
            RuntimeAttributePropertyInfo attributeProperty = (RuntimeAttributePropertyInfo) runtimePropertyInfo;
            property.setXmlStyle(Property.XmlStyle.ATTRIBUTE);
            property.setXmlName(attributeProperty.getXmlName());
            property.setRequired(attributeProperty.isRequired());
            if (property.isCollection()) property.setXmlList(true);
        } else if (runtimePropertyInfo instanceof RuntimeElementPropertyInfo) {
            RuntimeElementPropertyInfo elementProperty = (RuntimeElementPropertyInfo) runtimePropertyInfo;
            property.setXmlStyle(Property.XmlStyle.ELEMENT);
            if (!elementProperty.isValueList()) {
                property.setXmlName(elementProperty.getXmlName());
                for (RuntimeTypeRef typeRef : elementProperty.getTypes()) {
                    ElementMapping elementMapping = createXmlMapping(property, typeRef);
                    property.getElementMappings().add(elementMapping);
                }
                property.setRequired(elementProperty.isRequired());
                property.setNillable(elementProperty.isCollectionNillable());
            } else {
                property.setXmlList(true);

                if (elementProperty.getTypes().size() != 1) throw new BuildException("Expected 1 element mapped to property " + property + " but there are " + elementProperty.getTypes().size() + " mappings");
                RuntimeTypeRef elementType = elementProperty.getTypes().get(0);
                ElementMapping elementMapping = createXmlMapping(property, elementType);
                elementMapping.setNillable(false);
                property.getElementMappings().add(elementMapping);

                property.setXmlName(elementType.getTagName());
                property.setRequired(false);
                property.setNillable(false);
            }
        } else  if (runtimePropertyInfo instanceof RuntimeReferencePropertyInfo) {
            RuntimeReferencePropertyInfo referenceProperty = (RuntimeReferencePropertyInfo) runtimePropertyInfo;
            property.setXmlStyle(Property.XmlStyle.ELEMENT_REF);
            for (RuntimeElement re : referenceProperty.getElements()) {
                ElementMapping elementMapping;
                if (re instanceof RuntimeElementInfo) {
                    RuntimeElementInfo runtimeElement = (RuntimeElementInfo) re;
                    elementMapping = createXmlMapping(property, runtimeElement);
                } else {
                    RuntimeClassInfo runtimeClassInfo = (RuntimeClassInfo) re;
                    elementMapping = createXmlMapping(property, runtimeClassInfo);
                }
                property.getElementMappings().add(elementMapping);
            }
            property.setNillable(referenceProperty.isCollectionNillable());
            property.setXmlAny(referenceProperty.getWildcard() != null);
            property.setLax(referenceProperty.getWildcard() == WildcardMode.LAX);
            property.setMixed(referenceProperty.isMixed());
        } else if (runtimePropertyInfo instanceof RuntimeValuePropertyInfo) {
            property.setXmlStyle(Property.XmlStyle.VALUE);
            if (property.isCollection()) property.setXmlList(true);
        } else {
            throw new BuildException("Unknown property type " + runtimePropertyInfo.getClass().getName());
        }

        return property;
    }
View Full Code Here

            if (bean.getType().isAssignableFrom(xsiTypeClass) && schemaTypeName != null && bean.getType() != xsiTypeClass && !Modifier.isAbstract(xsiTypeClass.getModifiers())) {
                JBlock block = builder.expectXsiType(schemaTypeName);

                JAXBObjectBuilder elementBuilder = builders.get(xsiTypeBean);
                if (elementBuilder == null) {
                    throw new BuildException("Unknown bean " + bean);
                }

                // invoke the reader method
                JInvocation method = invokeParser(builder, builder.getXSR(), elementBuilder);
                block._return(method);
View Full Code Here

        //     map = (Map) bean.getAnyTypeMap();
        if (property.getField() == null && property.getGetter() == null) {
            // write only maps are not allowed by the spec, but we can support it anyway
            JType mapType = getMapClass(property.getType(), property.getComponentType());
            if (mapType == null) {
                throw new BuildException("AnyAttribute map property does not have a getter and map does not have a default constructor: " +
                        property.getBean().getType().getName() + "." + property.getName());
            }
            createMapBlock.assign(mapVar, JExpr._new(mapType));
        } else {
            if (property.getField() != null) {
View Full Code Here

            } else {
                JFieldVar propertyAccessorField = builder.getPrivatePropertyAccessor(property.getGetter(), property.getSetter(), property.getName());
                block.add(propertyAccessorField.invoke("setObject").arg(builder.getXSR()).arg(builder.getReadContextVar()).arg(bean).arg(value));
            }
        } else {
            throw new BuildException("Property does not have a setter: " + property.getBean().getType().getName() + "." + property.getName());
        }
    }
View Full Code Here

TOP

Related Classes of com.envoisolutions.sxc.builder.BuildException

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.