Examples of XSType


Examples of org.exolab.castor.builder.types.XSType

                jsc.add("desc.setValidator(fieldValidator);");
                return;
            }

            XMLInfoNature xmlNature = new XMLInfoNature(member);
            XSType xsType = xmlNature.getSchemaType();
            //--handle collections
            if (xsType.isCollection()) {
                XSListType xsList = (XSListType) xsType;

                jsc.add("fieldValidator.setMinOccurs(");
                jsc.append(Integer.toString(xsList.getMinimumSize()));
                jsc.append(");");
                if (xsList.getMaximumSize() > 0) {
                    jsc.add("fieldValidator.setMaxOccurs(");
                    jsc.append(Integer.toString(xsList.getMaximumSize()));
                    jsc.append(");");
                }
            } else if (xmlNature.isRequired()) {
                jsc.add("fieldValidator.setMinOccurs(1);");
            }

            jsc.add("{ //-- local scope");
            jsc.indent();
            xsType.validationCode(jsc, member.getFixedValue(), FIELD_VALIDATOR_NAME);
            jsc.unindent();
            jsc.add("}");
        }
        jsc.add("desc.setValidator(fieldValidator);");
    }
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

            final String javaClassBindingName) {
        if (simpleType == null) {
            return null;
        }

        XSType xsType = null;
        //-- determine base type
        SimpleType base = simpleType;

        while ((base != null) && (!base.isBuiltInType())) {
            base = (SimpleType) base.getBaseType();
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

        }
        if (common == null) {
            return new XSClass(SGTypes.OBJECT);
        }
       
        XSType convertedType = convertType(common, packageName, useWrapper, useJava50, null);
        Union unionType = (Union) simpleType;
        Enumeration<SimpleType> memberTypes = unionType.getMemberTypes();
        while (memberTypes.hasMoreElements()) {
            SimpleType memberType = memberTypes.nextElement();
            convertedType.setFacets(memberType);
        }
        return convertedType;
    }
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

            final String packageName, final String javaClassBindingName) {
        if (!simpleType.hasFacet(Facet.ENUMERATION)) {
            return null;
        }

        XSType xsType = null;
        String typeName = simpleType.getName();

        //-- anonymous type
        if (typeName == null) {
            if (javaClassBindingName != null) {
                // handled by binding file
                if (!JNaming.isInJavaLang(javaClassBindingName)
                        && !JNaming.isReservedByCastor(javaClassBindingName)
                        && !JNaming.isReservedByWindows(javaClassBindingName)) {
                    typeName = javaClassBindingName;
//                    typeName += "Type";
                }
            }
        }
              
        if (typeName == null) {
            // not handled by binding file
            Structure parent = simpleType.getParent();
            if (parent instanceof ElementDecl) {
                typeName = ((ElementDecl) parent).getName();
            } else if (parent instanceof AttributeDecl) {
                typeName = ((AttributeDecl) parent).getName();
            }
               
            typeName = typeName + "Type";
        }

        String className = _config.getJavaNaming().toJavaClassName(typeName);
       
        // Get the appropriate package name for this type
        String typePackageName = packageName;
        if (typePackageName == null) {
            String ns = simpleType.getSchema().getTargetNamespace();
            typePackageName = _config.lookupPackageByNamespace(ns);
        }

        if (typePackageName != null && typePackageName.length() > 0) {
            typePackageName = typePackageName  + '.' + SourceGeneratorConstants.TYPES_PACKAGE;
        } else {
            typePackageName = SourceGeneratorConstants.TYPES_PACKAGE;
        }

        className = typePackageName  + '.' + className;

        xsType = new XSClass(new JClass(className));
        xsType.setAsEnumerated(true);

        return xsType;
    }
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

     */
    private void createFieldMapping(final ClassMapping classMapping, final FieldInfo member,
                                    final String nsURI) {
        XMLInfoNature xmlNature = new XMLInfoNature(member);
       
        XSType xsType = xmlNature.getSchemaType();

        boolean any = false;
        NodeType nodeType = xmlNature.getNodeType();
        boolean isAttribute = (nodeType == NodeType.ATTRIBUTE);
        boolean isText = (nodeType == NodeType.TEXT);

        //-- a hack, I know, I will change later (kv)
        if (member.getName().equals("_anyObject")) {
            any = true;
        }

        //Attributes can handle COLLECTION type for NMTOKENS or IDREFS for instance
        if (xsType.isCollection()) {
            xsType = new XMLInfoNature(((CollectionInfo) member).getContent()).getSchemaType();
        }

        //-- create class choice on demand
        ClassChoice classChoice = classMapping.getClassChoice();
        if (classChoice == null) {
            classChoice = new ClassChoice();
            classMapping.setClassChoice(classChoice);
        }

        //-- create field mapping
        FieldMapping fieldMap = new FieldMapping();
        classChoice.addFieldMapping(fieldMap);
        String fieldName = member.getName();
        if (fieldName.charAt(0) == '_') {
            fieldName = fieldName.substring(1);
        }
        fieldMap.setName(fieldName);
        String className = getClassName(xsType.getJType());
        if (className.equals("byte[]")) {
            className = "bytes";
        }
        fieldMap.setType(className);

        BindXml bindXml = new BindXml();
        fieldMap.setBindXml(bindXml);

        String nodeName = xmlNature.getNodeName();
        if ((nodeName != null) && (!isText)) {
            bindXml.setName(nodeName);
        }

        if (isAttribute) {
            bindXml.setNode(BindXmlNodeType.ATTRIBUTE);
        } else if (isText) {
            bindXml.setNode(BindXmlNodeType.TEXT);
        } else {
            bindXml.setNode(BindXmlNodeType.ELEMENT);
        }

        switch (xsType.getType()) {
            case XSType.IDREF_TYPE :
                bindXml.setReference(true);
                break;
            case XSType.ID_TYPE :
                classMapping.addIdentity(member.getName());
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

     * @param state our current state
     */
    void processEnumerationAsBaseType(final ExtendedBinding binding,
            final SimpleType simpleType, final FactoryState state) {
        SimpleType base = (SimpleType) simpleType.getBaseType();
        XSType baseType = null;

        if (base == null) {
            baseType = new XSString();
        } else {
            baseType = _typeConversion.convertType(base, getConfig().useJava50());
        }

        Enumeration<Facet> enumeration = simpleType.getFacets(Facet.ENUMERATION);

        JClass jClass    = state.getJClass();
        String className = jClass.getLocalName();

        JField      fValues = null;
        JDocComment jdc     = null;
        JSourceCode jsc     = null;

        //-- modify constructor
        JConstructor constructor = jClass.getConstructor(0);
        constructor.getModifiers().makePrivate();

        fValues = new JField(new JArrayType(
                baseType.getJType(), getConfig().useJava50()), "values");

        //-- Loop through "enumeration" facets
        //-- and create the default values for the type.
        int count = 0;

        StringBuilder values = new StringBuilder("{\n");

        while (enumeration.hasMoreElements()) {
            Facet facet = (Facet) enumeration.nextElement();
            String value = facet.getValue();

            //-- Should we make sure the value is valid before proceeding??

            //-- we need to move this code to XSType so that we don't have to do
            //-- special code here for each type

            if (count > 0) {
                values.append(",\n");
            }

            //-- indent for fun
            values.append("    ");

            if (baseType.getType() == XSType.STRING_TYPE) {
                values.append('\"');
                //-- escape value
                values.append(escapeValue(value));
                values.append('\"');
            } else {
                values.append(value);
            }

            ++count;
        }

        values.append("\n}");

        fValues.setInitString(values.toString());
        jClass.addField(fValues);

        //-- #valueOf method
        JMethod method = new JMethod("valueOf", jClass,
                                     "the String value of the provided " + baseType.getJType());
        method.addParameter(new JParameter(SGTypes.STRING, "string"));
        method.getModifiers().setStatic(true);
        jClass.addMethod(method);
        jdc = method.getJDocComment();
        jdc.appendComment("Returns the " + baseType.getJType());
        jdc.appendComment(" based on the given String value.");
        jsc = method.getSourceCode();

        jsc.add("for (int i = 0; i < values.length; i++) {");
        jsc.add("}");
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

                                    component, new XSString(), getConfig().useJava50());
                            handleField(fieldInfo, state, component);
                        } else if (complexType.getContentType().getType() == ContentType.SIMPLE) {
                            SimpleContent simpleContent = (SimpleContent) complexType.getContentType();
                            SimpleType temp = simpleContent.getSimpleType();
                            XSType xsType = _typeConversion.convertType(
                                    temp, packageName, getConfig().useJava50());
                            FieldInfo fieldInfo = _memberFactory.createFieldInfoForContent(
                                    component, xsType, getConfig().useJava50());
                            handleField(fieldInfo, state, component);
                            temp = null;
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

        }
       

        // discard primitiv types and collections
        if (textFieldInfo != null) {
            XSType textFieldType = new XMLInfoNature(textFieldInfo).getSchemaType();
            if (textFieldType != null && textFieldType.getJType().isArray()) {
                generate = false;
            }
        }

        if (!generate) {
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

            //--if the content type is a simpleType create a field info for it.
            if (complexType.getContentType().getType() == ContentType.SIMPLE) {
                SimpleContent simpleContent = (SimpleContent) complexType.getContentType();
                SimpleType temp = simpleContent.getSimpleType();
                SimpleType baseType = (SimpleType) temp.getBaseType();
                XSType xsType = _typeConversion.convertType(
                        temp, state.getPackageName(), getConfig().useJava50());

                FieldInfo fieldInfo = null;
                if ((baseType != null) && extendsSimpleType(state.getJClass(), baseType, state)) {
                    if (xsType.isEnumerated()) {
                        fieldInfo = _memberFactory.createFieldInfoForContent(
                                component, xsType, getConfig().useJava50());
                        fieldInfo.setBound(false);

                        handleField(fieldInfo, state, component);
View Full Code Here

Examples of org.exolab.castor.builder.types.XSType

        //--currently anyAttribute is not supported
        if (any.isAttributeWildcard()) {
            return null;
        }

        XSType xsType    = new XSClass(SGTypes.OBJECT, "any");
        String vName     = "_anyObject";
        String xmlName   = null;
        FieldInfo result = null;

        if (any.getMaxOccurs() > 1 || any.getMaxOccurs() < 0) {
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.