Package org.objectweb.jorm.metainfo.api

Examples of org.objectweb.jorm.metainfo.api.ClassMapping


                                    String projectName,
                                    String mapperName,
                          JormMIMappingBuilder mb)
          throws SpeedoException, PException {
    Class clazz = sc.jormclass;
    ClassMapping cm = clazz.getClassProject(projectName)
        .getMapping(mapperName).getClassMapping();
        logger.log(BasicLevel.DEBUG, "Generate the Jorm MI for the class "
                + clazz.getFQName());
        for (Iterator fieldsIt = sc.fields.values().iterator();fieldsIt.hasNext();) {
            SpeedoField sp = (SpeedoField) fieldsIt.next();
View Full Code Here


                                    String projectName,
                                    String mapperName,
                          JormMIMappingBuilder mb,
                          Collection createdMOs)
          throws SpeedoException, PException {
    ClassMapping cm = sc.jormclass.getClassProject(projectName)
        .getMapping(mapperName).getClassMapping();
    NameDef classNd = null;
    IdentifierMapping im = cm.getIdentifierMapping();
    if (im != null) {
      classNd = (NameDef) im.getLinkedMO();
      if (classNd != null) {
        return true;
      }
    }
    if (sc.getSuperClassName() == null) {
      classNd = sc.jormclass.createNameDef();
          nmf.getNamingManager(sc).defineClassIdentifierNameDef(
                  classNd, sc.jormclass, sc, cm, this, mb, createdMOs);
      if (cm != null) {
        cm.createIdentifierMapping(classNd);
      }
    } else {
      SpeedoClass parent = sc.getSpeedoClassFromContext(sc.getSuperClassName());
      im = parent.jormclass
          .getClassProject(projectName).getMapping(mapperName)
          .getClassMapping().getIdentifierMapping();
      if (im != null) {
        classNd = (NameDef) im.getLinkedMO();
        if (classNd != null) {
          cm.createIdentifierMapping(classNd);
        }
      }
    }
    if (debug) {
      logger.log(BasicLevel.DEBUG, "Create the identifier of the class '"
View Full Code Here

            throws SpeedoException, PException {
        Class clazz = manager.getClass(sc.getFQName());
        logger.log(BasicLevel.DEBUG, "Generate the Jorm MI for the references of class "
                + clazz.getFQName());
        Mapping mapping = null;
        ClassMapping cm = null;
        if (projectName != null && mapperName != null) {
            mapping = clazz.getClassProject(projectName)
                .getMapping(mapperName);
            cm = mapping.getClassMapping();
        }
        Iterator fieldsIt = sc.fields.values().iterator();
        //System.out.println("Manage reference of the class " + sc.getFQName());
        while (fieldsIt.hasNext()) {
            SpeedoField sp = (SpeedoField) fieldsIt.next();
          if (clazz.getTypedElement(sp.name) != null) {
                //the primitive element is already managed before(createJormClass)
                continue;
            }
          Type t = Type.getType(sp.type);
            String javatype = t.getClassName();
            if (!isGenClassRef(javatype)) {
                //                     reference to a class                   //
                //============================================================//
              if (debug) {
                    logger.log(BasicLevel.DEBUG, "Class reference field: "
                        + sp.name + " / javatype: " + javatype);
              }
                // reference to a class
                SpeedoClass tsc = sc.moPackage.xmlDescriptor
                        .getSpeedoClass(javatype, true);
                if (tsc == null) {
                    throw new SpeedoException("No persistent class '"
                            + javatype + "' found in the file: "
                            + sc.moPackage.xmlDescriptor.xmlFile);
                }
                Class tclass = manager.getClass(tsc.getFQName());
                if (tclass == null) {
                    manager.createClass(tsc.getFQName());
                }
                ClassRef cr = clazz.createClassRef(sp.name, tclass);
                NameDef refNd = cr.createRefNameDef();
                nmf.getNamingManager(tsc)
                  .defineClassReferenceNameDef(refNd, cr, sp, sc, cm, this, mb);
                if ( cm != null) {
                    cm.createReferenceMapping(sp.name, refNd);
                    cm.addDependency(tsc.getFQName());
                }

            } else {
                //                reference to a generic class                //
                //============================================================//
                String innerType = getInnerType(sp);
                if (innerType == null) {
                    throw new SpeedoException("The inner element type is " +
                            "required for the multivalued field '" + sp.name
                            + "' of the class '" + sc.getFQName()
                            + "' in the .jdo file '"
                            + sc.moPackage.xmlDescriptor.xmlFile + "'");
                }
                PType type = getPrimitivePType(innerType);
              if (type == null && !isPersistentClass(innerType, sc.moPackage.name, manager)) {
                logger.log(BasicLevel.INFO, "The field '" + sc.getFQName()
                        + "." + sp.name + " is managed as a Serialized field.");
                type = PTypeSpace.SERIALIZED;
              }
              if (debug) {
          logger.log(BasicLevel.DEBUG, "GenClass reference field: "
              + sp.name + " / javatype: " + javatype
              + " / innerType: " + innerType
            + " / ptype=" + (type == null ? null : type.getJavaName()));
              }
                GenClassRef gcr = clazz.createGenClassRef(sp.name, javatype);
                GenClassMapping gcm = null;
                ClassRef cr = null;
                SpeedoClass tsc = null;

                //element of the gen class
                if (type != null) {
                    // gen class of primitive type
                    gcr.createPrimitiveElement(type, PType.NOSIZE, PType.NOSIZE);
                } else if (!isGenClassRef(innerType)) {
                    // gen class of classref
                    tsc = sc.moPackage.xmlDescriptor.smi
                            .getSpeedoClass(innerType, sc.moPackage);
                    if (tsc == null) {
                        throw new SpeedoException("The persistent class '"
                                + sc.getFQName()
                                + "' tries to reference (througth the field '"
                                + sp.name
                                + "') the class '" + innerType
                                + "' not defined in the .jdo file '"
                                + sc.moPackage.xmlDescriptor.xmlFile + "'");
                    }
                    Class tclass = manager.getClass(tsc.getFQName());
                    if (tclass == null) {
                        throw new SpeedoException("The inner element class '"
                            + tsc.getFQName() + "' of the multivalued field '"
                            + sp.name + "' of the class '" + sc.getFQName()
                            + "' in the .jdo file '"
                            + sc.moPackage.xmlDescriptor.xmlFile
                                + "' has not been found among the persitent classes : "
                            + manager.getClasses());
                    }
                    cr = gcr.createClassRef(tclass);
                } else {
                    throw new SpeedoException(
                            "unmanaged the inner-element of the field '"
                            + sp.name + "' of the class '" + sc.getFQName()
                            + "' : " + innerType);
                }
                //Map the element of the generic class
                if (mapping != null) {
                    gcm = mb.createGenClassMapping(gcr, sp, mapping);
                    if (gcr.isPrimitive()) {
                        mb.createGenClassElementMapping(gcr.getPrimitiveElement(), sp, gcm);
                    } else {
                        NameDef elemNd = cr.createRefNameDef();
                        nmf.getNamingManager(tsc).defineClassReferenceNameDef(elemNd, cr, sp, sc, gcm, this, mb);
                        //fillNameDef(elemNd, tsc, sc, gcr, gcr, gcm, mb, false, true, true, createdMOs);
                        gcm.createReferenceMapping(sp.name, elemNd);
                        cm.addDependency(tsc.getFQName());
                    }
                }

                // reference to a generic class from the class
                NameDef refNd = gcr.createRefNameDef();
                nmf.getNamingManager(sc).defineGenClassReferenceNameDef(refNd, gcr, sp, sc, cm, this, mb);
                //fillNameDef(refNd, sc, sc, clazz, gcr, cm, mb, false, false, false, createdMOs);
                if (cm != null) {
                    cm.createReferenceMapping(sp.name, refNd);
                }

                //identifier of the gen class
                NameDef gcidNd = gcr.createIdNameDef();
                nmf.getNamingManager(sc).defineGenClassIdentifierNameDef(
View Full Code Here

  private void mapInheritance(SpeedoClass sc,
                                 String projectName,
                                 String mapperName,
                                 JormMIMappingBuilder mb)
      throws SpeedoException, PException {
    ClassMapping cm = sc.jormclass.getClassProject(projectName)
        .getMapping(mapperName).getClassMapping();
    NameDef nd = (NameDef) cm.getIdentifierMapping().getLinkedMO();

    if (sc.inheritance != null && sc.inheritance.discriminator != null) {
        SpeedoDiscriminator sd = sc.inheritance.discriminator;
        String filter = null;
        if (sd.expression != null) {
        filter = sd.expression;
        } else if (sd.elements.size() == 1) {
                SpeedoElement se = (SpeedoElement) sd.elements.get(0);
                if (se instanceof SpeedoField) {
                    filter = ((SpeedoField) se).name;
                } else if (se instanceof SpeedoNoFieldColumn) {
                    filter = HIDDEN_FIELD_CLASS_NAME;
                } else {
                    throw new SpeedoException("Unmanaged filter element: " + se);
                }
        } else {
            throw new SpeedoException(
                    "Composite inheritance discriminator not yet supported in Speedo");
        }
        if (filter != null) {
            sc.jormclass.setInheritanceFilter(nd, filter);
            logger.log(BasicLevel.DEBUG, "Assign filter: " + filter);
        }
            if (sc.inheritance.discriminator.elements != null
                    && sc.inheritance.discriminator.elements.size() == 1) {
                SpeedoElement se = (SpeedoElement) sc.inheritance.discriminator.elements.get(0);
                if (se instanceof SpeedoNoFieldColumn) {
                    if (sc.getSuper() == null) {
                        // The discriminator is a column not mapped to a
                        // persistent field. then we have to create a constant
                        // hidden field.
                        PrimitiveElement pe = sc.jormclass.createHiddenField(
                            HIDDEN_FIELD_CLASS_NAME, PTypeSpace.STRING, PType.NOSIZE, PType.NOSIZE);
                        pe.setStatus(PrimitiveElement.CONSTANT_PERSISTENT);
                        mb.createFieldMapping(pe, (SpeedoNoFieldColumn) se, cm);
                    }
                    if (sc.inheritance.discriminator.strategy ==
                                SpeedoDiscriminator.STRATEGY_CLASS_NAME
                                && sc.inheritance.discriminatorValues != null) {
                        // declare the constant value of the field
                        sc.jormclass.setConstantValue(HIDDEN_FIELD_CLASS_NAME,
                                (String) sc.inheritance.discriminatorValues.get(se));
                    }
                }
            }
    }
    if (sc.inheritance != null && sc.inheritance.discriminatorValues != null) {
        Object key = sc.inheritance.discriminatorValues.values().iterator().next();
          logger.log(BasicLevel.DEBUG, "Assign key: " + key);
      sc.jormclass.setInheritanceNamingKey(nd, key);
    }

    if (sc.getSuperClassName() == null) {
      return;
    }
    SpeedoClass parent = sc.getSpeedoClassFromContext(sc.getSuperClassName());
    String im = sc.getExtensionValueByKey(SpeedoProperties.INHERITANCE_MAPPING);

    // Map the inherited field if required
    if (sc.inheritance.isHorizontalMapping()) {
        for (Iterator it = sc.inheritance.remappedInheritedFields.values().iterator(); it.hasNext();) {
                SpeedoInheritedField sif = (SpeedoInheritedField) it.next();
        if (debug) {
          logger.log(BasicLevel.DEBUG, "Map the inherited field '"
            + sif.name + "'.");
        }
                TypedElement te = sif.inheritedField.moClass.jormclass.getTypedElement(sif.inheritedField.name);
                if (te == null) {
                    throw new SpeedoException("No inherited field '"
                            + sif.name + "' found from "
                            + sc.getSourceDesc());
                } else if (te instanceof PrimitiveElement) {
          mb.createFieldMapping((PrimitiveElement) te, sif, cm);
                } else if (te instanceof ClassRef) {
                    ClassRef cr = (ClassRef) te;
                    //Keep the same namedef than in the parent
                    //but map the field(s) used in name def on column defined
                    // in SpeedoInheritedField meta object.
                    NameDef refNd = (NameDef) cr.getRefNameDef().iterator().next();
                    cm.createReferenceMapping(sif.inheritedField.name, refNd);
                    //create PEM for each field used in the NameDef
                  mb.createClassRefNameDefMapping(cm, refNd, sif);
                }
            }
    } else if (sc.inheritance.isVerticalMapping()) {
View Full Code Here

TOP

Related Classes of org.objectweb.jorm.metainfo.api.ClassMapping

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.