Package org.exolab.castor.builder.info.nature

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature


     * associated with this FieldInfo.
     *
     * @return true if the has and delete methods are needed.
     */
    public final boolean requiresHasAndDeleteMethods() {
        XSType xsType = new XMLInfoNature(this).getSchemaType();
        JType jType  = xsType.getJType();
        return ((!xsType.isEnumerated()) && jType.isPrimitive());
    } //-- requiresHasAndDeleteMethods
View Full Code Here


   private JSourceCode createOneToManyFieldInfoPart(final FieldInfo fInfo, final JSourceCode jsc) {
      
       //JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
       JDOClassInfoNature cNature = new JDOClassInfoNature(fInfo.getDeclaringClassInfo());
       JDOOneToManyNature manyNature = new JDOOneToManyNature(fInfo);
       XMLInfoNature xmlNature = new XMLInfoNature(fInfo);
      
       //-- set name
       String name = xmlNature.getNodeName();
       jsc.add("");
       jsc.add("//" + name + " field");
       jsc.add("String " + name + "FieldName = \"" + name + "\";");
      
       String sqlName = manyNature.getForeignKeys().get(0).toString();
       jsc.add("String " + name + "SqlName = \"" + sqlName + "\";");
      
       //-- initialize objects
       jsc.add("FieldDescriptorImpl " + name + "FieldDescr;");
       jsc.add("FieldMapping " + name + "FM = new FieldMapping();");

       //-- set typeInfo
       String type = null;
       XSList schemaType;
      
       schemaType = (XSList) xmlNature.getSchemaType();
       JType javaType = schemaType.getContentType().getJType();
       type = javaType.toString();
      
       String wrapperType = null;
       if (javaType instanceof JPrimitiveType) {
        wrapperType = ((JPrimitiveType) javaType).getWrapperName();
       } else {
           wrapperType = type;
       }      

       // TODO IS THERE A NEED TO CHECK THIS?!
       if ((type != null) && (type.length() > 0)) {
           jsc.add("TypeInfo " + name
                   + "Type = new TypeInfo(" + type + ".class);");
       }

       jsc.add("// Set columns required (= not null)");
       jsc.add(name + "Type.setRequired("
               + Boolean.toString(xmlNature.isRequired()) + ");");

       jsc.add("");

       jsc.add("FieldHandler " + name + "Handler;");
       jsc.add("try {");

       //-- get/set methods
       jsc.indent();
       // TODO HOW ABOUT GETTING THE NAME FROM NATURE?
       String className = fInfo.getDeclaringClassInfo().getJClass().getLocalName();
       // TODO IS THERE A NEED TO CHECK THIS?!
       if ((className != null) && (className.length() > 0)) {
           jsc.add("Method " + name + "GetMethod = "
                   + className + ".class.getMethod(\"get"
                   + toUpperCaseFirstLetter(name) + "\", null);");
           jsc.add("Method " + name + "SetMethod = "
                   + className + ".class.getMethod(\"set"
                   + toUpperCaseFirstLetter(name) + "\", new Class[]{");      
       }
      
       // TODO IS THERE A NEED TO CHECK THIS?!
       if ((type != null) && (type.length() > 0)) {
           jsc.addIndented(type + "[].class});");
       }

       jsc.add("");
       jsc.add(name + "Handler = new FieldHandlerImpl(" + name + "FieldName, ");
       jsc.append("null, null,");
       jsc.addIndented(name + "GetMethod, " + name + "SetMethod, " + name + "Type);");
       jsc.unindent();
       jsc.add("");

       //-- Catch of exceptions
       jsc.add("} catch (SecurityException e1) {");
       jsc.indent();
       jsc.add("throw new RuntimeException(e1.getMessage());");
       jsc.unindent();
       jsc.add("} catch (MappingException e1) {");
       jsc.indent();
       jsc.add("throw new RuntimeException(e1.getMessage());");
       jsc.unindent();
       jsc.add("} catch (NoSuchMethodException e1) {");
       jsc.indent();
       jsc.add("throw new RuntimeException(e1.getMessage());");
       jsc.unindent();
       jsc.add("}");


//       //-- JDOFieldDescriptorImpl constructor
//       jsc.add("// Instantiate " + name + " field descriptor");
//       jsc.add(name + "FieldDescr = new JDOFieldDescriptorImpl(");
//       jsc.append(name + "FieldName, " + name + "Type,");
//       jsc.indent();
//       jsc.add(name + "Handler, ");
//       jsc.append(Boolean.toString(fInfo.isTransient()) + ", ");
//       jsc.append("new String[] { },");
//       jsc.add("new int[] {SQLTypeInfos");
//       jsc.indent();
//       jsc.add(".javaType2sqlTypeNum(");
//
//       // TODO IS THERE NEED TO CHECK THIS?!
//       if ((type != null) && (type.length() > 0)) {
//           jsc.append(wrapperType + ".class) },");
//       }
//
//       jsc.unindent();
//       jsc.add("null, new String[] { " + name + "SqlName }, ");
//       jsc.append(Boolean.toString(manyNature.isDirty()) + ", ");
//       jsc.append(Boolean.toString(manyNature.isReadOnly()) + ");");
//       jsc.unindent();

       //-- invoke FieldDescriptorImpl constructor
       jsc.add("// Instantiate " + name + " field descriptor");
       jsc.add(name + "FieldDescr = new FieldDescriptorImpl(");
       jsc.append(name + "FieldName, " + name + "Type,");
       jsc.append(name + "Handler, ");
       jsc.append(Boolean.toString(fInfo.isTransient()) + ");");
      
       jsc.add(name + "FieldDescr.addNature(FieldDescriptorJDONature.class.getName());");

       jsc.add("FieldDescriptorJDONature " + name + "FieldJdoNature = new FieldDescriptorJDONature("
               + name + "FieldDescr);");

       jsc.add(name + "FieldJdoNature.setSQLName(null);");
       jsc.add(name + "FieldJdoNature.setSQLType(new int[] {SQLTypeInfos");
       jsc.append(".javaType2sqlTypeNum(");

       // TODO IS THERE NEED TO CHECK THIS?!
       if ((type != null) && (type.length() > 0)) {
           jsc.append(wrapperType + ".class) });");
       }

       jsc.add(name + "FieldJdoNature.setManyKey(new String[] { " + name + "SqlName });");
       jsc.add(name + "FieldJdoNature.setDirtyCheck(" + Boolean.toString(manyNature.isDirty()) + ");");
       jsc.add(name + "FieldJdoNature.setReadOnly(" + Boolean.toString(manyNature.isReadOnly()) + ");");
      
       jsc.add("");

       //-- parent class descriptor
       jsc.add(name + "FieldDescr.setContainingClassDescriptor(this);");
       jsc.add(name + "FieldDescr.setClassDescriptor(new " + getLocalName(type)
               + "JDODescriptor());");
       jsc.add(name + "FieldDescr.setMultivalued(true);");
      
       boolean isPrimaryKey = false;
       if (cNature.getPrimaryKeys() != null) {
           isPrimaryKey = (cNature.getPrimaryKeys().contains(xmlNature.getNodeName()));
       }

       //-- fieldmapping
       jsc.add(name + "FM.setIdentity(" + Boolean.toString(isPrimaryKey) + ");");
       jsc.add(name + "FM.setDirect(false);");
       jsc.add(name + "FM.setName(\"" + name + "\");");
       jsc.add(name + "FM.setRequired(" + xmlNature.isRequired() + ");");
       // TODO support of other collection types
       jsc.add(name + "FM.setCollection(FieldMappingCollectionType.ARRAY);");
      
       //-- sql part
       jsc.add("Sql " + name + "Sql = new Sql();");
View Full Code Here

     * Creates a new ClassInfo. Adds the {@link XMLInfoNature} for legacy compliance.
     * @param jClass the JClass which this ClassInfo describes
     */
    public ClassInfo(final JClass jClass) {
        this.addNature(XMLInfoNature.class.getName());
        XMLInfoNature xmlNature = new XMLInfoNature(this);
        xmlNature.setNodeType(NodeType.ELEMENT);
        if (jClass == null) {
            String err = "JClass passed to constructor of ClassInfo must not be null.";
            throw new IllegalArgumentException(err);
        }
        this._class = jClass;

        // set default GroupInfo instance
        xmlNature.setGroupInfo(new GroupInfo());
    }
View Full Code Here

            return;
        }

        fieldInfo.setDeclaringClassInfo(this);

        switch(new XMLInfoNature(fieldInfo).getNodeType()) {
            case ATTRIBUTE:
                if (!_atts.contains(fieldInfo)) {
                    _atts.addElement(fieldInfo);
                }
                break;
View Full Code Here

    public boolean contains(final FieldInfo fieldInfo) {
        if (fieldInfo == null) {
            return false;
        }

        switch (new XMLInfoNature(fieldInfo).getNodeType()) {
            case ATTRIBUTE:
                if (_atts != null) {
                    return _atts.contains(fieldInfo);
                }
                break;
View Full Code Here

            return null;
        }

        for (int i = 0; i < _atts.size(); i++) {
            FieldInfo temp = _atts.get(i);
            if (new XMLInfoNature(temp).getNodeName().equals(nodeName)) {
                return temp;
            }
        }

        return null;
View Full Code Here

     */
    public FieldInfo getElementField(final String nodeName) {
        if (_elements != null) {
            for (int i = 0; i < _elements.size(); i++) {
                FieldInfo temp = _elements.get(i);
                String elementNodeName = new XMLInfoNature(temp).getNodeName();
                if (elementNodeName != null && elementNodeName.equals(nodeName)) {
                    return temp;
                }
            }
        }
View Full Code Here

                this.getElementName());
        this._content = new FieldInfo(contentType, "v" + this.getMethodSuffix(),
                contentMemberAndAccessorFactory);
       
        // indicates that - per definition - we are dealing with multi-valuedness
        new XMLInfoNature(this).setMultivalued(true);
    } // -- CollectionInfo
View Full Code Here

    /**
     * Returns the type of content in this collection.
     * @return the type of content in this collection.
     */
    public final XSType getContentType() {
        return new XMLInfoNature(this.getContent()).getSchemaType();
    }
View Full Code Here

    /**
     * Returns the schema type represented by this collection.
     * @return the schema type represented by this collection.
     */
    public final XSListType getXSList() {
        return (XSListType) new XMLInfoNature(this).getSchemaType();
    }
View Full Code Here

TOP

Related Classes of org.exolab.castor.builder.info.nature.XMLInfoNature

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.