Package org.exolab.castor.mapping.xml

Examples of org.exolab.castor.mapping.xml.MapTo


    protected void initQuery(ClassMapping clsMapping, QueryExpression expr)
        throws DTXException
    {
        ClassMapping extend;
  MapTo mapTo = clsMapping.getMapTo();

  if (mapTo == null) {
      throw new DTXException("no table mapping for: " + clsMapping.getName());
  }

  String table = mapTo.getTable();

        FieldMapping[] fields = clsMapping.getFieldMapping();
  FieldMapping identity = null;

        String identityName = clsMapping.getIdentity(0);

  for (int j = 0; j < fields.length; j++) {
      if (fields[j].getName().equals(identityName)) {
    identity = fields[j];
    break;
      }
  }

  if (identity == null) {
      throw new DTXException("no identity field in class: " + clsMapping.getName());
  }

  Sql identitySQLElement = identity.getSql();

  if (identitySQLElement == null) {
      throw new DTXException("no identity SQL info in class: " + clsMapping.getName());
  }

  String identitySQL = identitySQLElement.getName()[0];

  _ids.add(table + "." + identitySQL);

  DTXClassDescriptor desc = new DTXClassDescriptor(clsMapping);

  _classes.put(table + "." + identitySQL, desc);

        // If this class extends another class, create a join with the parent table and
        // add the load fields of the parent class (but not the store fields)
        if (clsMapping.getExtends() != null) {

        /**
          * TODO : Needs to be resolved by Hand
          */

        MapTo extendsTo = new MapTo();//(ClassMapping) clsMapping.getExtends()).getMapTo();
      if (extendsTo == null) {
    throw new DTXException("no mapping info for extends table.");
      }
      String extendsTable = extendsTo.getTable();
            expr.addInnerJoin(table, identitySQL, extendsTable, identitySQL);
            /**
             * needs to be resolved by hand
             */
            initQuery(new ClassMapping(), expr);
            //(ClassMapping) clsMapping.getExtends(), expr);
        }

        for (int i = 0; i < fields.length; ++i) {
      FieldMapping field = fields[i];
      Sql fieldSql = field.getSql();
      ClassMapping relMapping = _eng.getClassMapping(field.getType());

      if (fieldSql == null) {
    if (relMapping != null) {

        // We have a one-to-many relationship with a sub object.
        // get those objects, too.

                    FieldMapping[] relFields = relMapping.getFieldMapping();
        MapTo relMapTo = relMapping.getMapTo();

        if (relMapTo == null) {
      throw new DTXException("dtx.NoRelatedMapTo");
        }

        String relTable = relMapTo.getTable();

        String relId = null;
                    String foreKey = null;

                    for (int k = 0; k < relFields.length; k++ ) {
View Full Code Here


            return clsDesc;

        // Use super class to create class descriptor. Field descriptors will be
        // generated only for supported fields, see createFieldDesc later on.
        clsDesc = super.createDescriptor( clsMap );
        MapTo mapTo = clsMap.getMapTo();
        if (( mapTo == null) || (mapTo.getXml() == null)) {
            String clsName = clsDesc.getJavaClass().getName();
            int idx = clsName.lastIndexOf('.');
            if (idx >= 0) {
                clsName = clsName.substring(idx+1);
            }
            xmlName = _naming.toXMLName( clsName );
        }
        else {
            xmlName = clsMap.getMapTo().getXml();

        }

        XMLClassDescriptorImpl xmlClassDesc
            = new XMLClassDescriptorAdapter( clsDesc, xmlName, _primitiveNodeType );

        if (clsMap.getAutoComplete()) {

            XMLClassDescriptor referenceDesc = null;
            Class type = xmlClassDesc.getJavaClass();
           
            //-- check compiled descriptors
            ClassDescriptorResolverImpl cdr
                = new ClassDescriptorResolverImpl();
            cdr.setIntrospection(false);
            referenceDesc = cdr.resolve(type);
            if (referenceDesc == null) {
                Introspector introspector = new Introspector();
                try {
                    referenceDesc = introspector.generateClassDescriptor(type);
                } catch (MarshalException mx) {
                    String error = "unable to introspect class '" +
                        type.getName() + "' for auto-complete: ";
                    throw new MappingException(error + mx.getMessage());
                }
            }

            //-- check for identity
            String identity = "";
            if (clsMap.getIdentityCount() > 0)
                identity = clsMap.getIdentity(0);

            FieldDescriptor[] fields = xmlClassDesc.getFields();

            // Attributes
            XMLFieldDescriptor[] introFields = referenceDesc.getAttributeDescriptors();
            for (int i = 0; i<introFields.length; ++i) {
                if (!isMatchFieldName(fields, introFields[i].getFieldName())) {
                    // If there is no field with this name, we can add it
                    if (introFields[i].getFieldName().equals(identity)) {
                        xmlClassDesc.setIdentity(introFields[i]);
                    }
                    else {
                        xmlClassDesc.addFieldDescriptor(introFields[i]);
                    }
                }
            }

            // Elements
            introFields = referenceDesc.getElementDescriptors();
            for (int i = 0; i<introFields.length; ++i) {
                if (!isMatchFieldName(fields, introFields[i].getFieldName())) {
                    // If there is no field with this name, we can add it
                    if (introFields[i].getFieldName().equals(identity)) {
                        xmlClassDesc.setIdentity(introFields[i]);
                    }
                    else {
                        xmlClassDesc.addFieldDescriptor(introFields[i]);
                    }
                }
            }

            // Content
            XMLFieldDescriptor field = referenceDesc.getContentDescriptor();
            if (field!= null)
                if (isMatchFieldName(fields, field.getFieldName()))
                    // If there is no field with this name, we can add
                    xmlClassDesc.addFieldDescriptor(field);


        } //-- End of auto-complete


        //-- copy ns-uri + ns-prefix
        if (mapTo != null) {
            xmlClassDesc.setNameSpacePrefix(mapTo.getNsPrefix());
            xmlClassDesc.setNameSpaceURI(mapTo.getNsUri());
        }
        return xmlClassDesc;
    } //-- createDescriptor
View Full Code Here

TOP

Related Classes of org.exolab.castor.mapping.xml.MapTo

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.