Package org.objectweb.jorm.metainfo.api

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


            tclass = ((SpeedoInheritedField) sf).inheritedField.getReferencedClass();
        }
        RdbClassMultiMapping trcm = (RdbClassMultiMapping) tclass.jormclass
                .getClassProject(cm.getProjectName()).getMapping(
                        cm.getMapperName()).getClassMapping();
        NameDef tnd = (NameDef) trcm.getIdentifierMapping().getLinkedMO();
        Class jclass = sf.moClass.jormclass;
        if (sf.join == null) {
            createLocalClassRefNameDefMapping(rcm, jclass, sf, nd, tnd, tclass);
        } else {
            createExternalClassRefNameDefMapping(rcm, jclass, sf, nd, trcm, tnd, tclass);
View Full Code Here


                    sf.columns[0], table, nd, null);
        } else {
            SpeedoClass tclass = sf.getReferencedClass();
            RdbClassMultiMapping trcm = getClassMapping(
                    (Mapping) gcm.getParent(), tclass.jormclass);
            NameDef tnd = (NameDef) trcm.getIdentifierMapping().getLinkedMO();
            Map tndproj = tnd.getNameRef().getProjection();
            Iterator it = nd.getNameRef().getProjection().entrySet()
                    .iterator();
            while (it.hasNext()) {
                Map.Entry me = (Map.Entry) it.next();
                //find the field in the genclass used in by this name def
View Full Code Here

            //get the ClassMapping of class owning the generic class
            RdbClassMultiMapping rcmOwner = (RdbClassMultiMapping) sf.moClass.jormclass
                    .getClassProject(rgcm.getProjectName()).getMapping(
                            rgcm.getMapperName()).getClassMapping();
            //get the namedef identifier of the generic class owner
            NameDef ndIdOwner = (NameDef) rcmOwner.getIdentifierMapping()
                    .getLinkedMO();
            //:compute the prefix for genclass field(s) used as identifier
            String prefix = mibh.getNameDefFieldPrefix(gcr, true, true, sf);
            Map classNdProj = ndIdOwner.getNameRef().getProjection();
            Iterator it = nd.getNameRef().getProjection().entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry me = (Map.Entry) it.next();
                String compositeFieldName = (String) me.getValue();
                //get the primitive element corresponding in the Generic class
View Full Code Here

                // The class meta object
                addMOClass(jdoClass.jormclass, desc.mos);

                // Add the CompositeName which could be used in the class name def
                for (Iterator it = jdoClass.jormclass.getNameDefs().iterator(); it.hasNext();) {
                    NameDef nd = (NameDef) it.next();
                    if (nd.isNameRef()) {
                        desc.mos.add(nd.getNameRef().getCompositeName());
                    }
                }

                //The compositeName used for the reference will be added by the
                // name definition of the referenced class.
View Full Code Here

        Class classJorm = manager.getClass(clas.getFQName());
        if (classJorm == null) {
            throw new SpeedoException("Jorm description of the class '"
                    + clas.getFQName() + "' is not availlable");
        }
        NameDef pName = null;
        SpeedoClass sc = clas;
        while(sc.getSuperClassName() != null) {
            SpeedoClass scl = sc;
            sc = sc.moPackage.xmlDescriptor.smi.getSpeedoClass(sc.getSuperClassName(), sc.moPackage);
            if (sc == null) {
                throw new SpeedoException("Class " + scl.getFQName()
                        + " not defined in the jorm meta information");
            }
        }
        Class pclassJorm = manager.getClass(sc.getFQName());
        pName = getClassNameDef(pclassJorm);

        if (classJorm == null) {
            throw new SpeedoXMLError("Class '" + clas.name + "' not defined in JORM metadata");
        }

        // Comparison from JDO
        clas.jormclass = classJorm;
        for (Iterator efield = clas.fields.values().iterator(); efield.hasNext();) {
            SpeedoField field = (SpeedoField) efield.next();
            String fieldName = field.name;

            // Fields with this persistent modifier shouldn't stay in JDO Metadata
            if (field.persistenceStatus == SpeedoField.NONE)
                continue;

            TypedElement tElem = classJorm.getTypedElement(fieldName);
            if (tElem == null) {
                throw new SpeedoXMLError("Field '" + fieldName
                    + "' not defined in JORM metadata of the class '"
                    + clas.getFQName() + "'");
            }

            // for application identity key fields have to be compared
            if (field.primaryKey) {
                boolean found = false;
                for (Iterator it = pName.iterateField(); it.hasNext() && !found;) {
                    found = fieldName.equals(it.next());
                }
                if (!found) {
                    throw new SpeedoXMLError("Field '" + fieldName
                        + "' not defined in Class NameDef's Fields of the class '"
                        + clas.getFQName() + "'");
                }
            }

            if (tElem instanceof GenClassRef && field.jdoTuple == null)
                throw new SpeedoXMLError("field '" + fieldName + "' should be a tuple in JDO metadata of the class '" + clas.getFQName() + "'");
        }

        // Comparison from JORM
        for (Iterator jormfield = classJorm.getFields().iterator(); jormfield.hasNext();) {
            TypedElement te = (TypedElement) jormfield.next();
            String fieldName = te.getName();
            if (!clas.fields.containsKey(fieldName)
                    && !isContainerIdField(classJorm, te, clas))
                throw new SpeedoXMLError("Field '" + fieldName + "' of the class '"
                            + clas.getFQName() + "' is not defined in the '"
                            + clas.moPackage.xmlDescriptor.xmlFile
                            + "' file (found: " + clas.fields.keySet() + ").");
        }

        // for application identity key fields have to be compared
        if (clas.getIdentityType() == SpeedoIdentity.USER_ID) {
            SpeedoClass classWithId = clas;
            while(classWithId.getSuperClassName() != null) {
                classWithId = classWithId.getSpeedoClassFromContext(classWithId.getSuperClassName());
            }
            boolean found = false;
            for (Iterator it = pName.iterateField(); it.hasNext() && !found;) {
                String fn = (String) it.next();
                SpeedoField sf = (SpeedoField) classWithId.fields.get(fn);
                if (sf == null) {
                    logger.log(BasicLevel.WARN, "Field " + fn + " defined in the identifier of "
                            + classWithId.name
View Full Code Here

                          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;
View Full Code Here

                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(
                        gcidNd, gcr, sp, sc, gcm, this, mb);
                //fillNameDef(gcidNd, sc, sc, gcr, gcr, gcm, mb, true, true, true, createdMOs);
                if (gcm != null) {
                    gcm.createIdentifierMapping(gcidNd);
View Full Code Here

                                 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);
                }
            }
View Full Code Here

    private void getJormConfig(SpeedoClass sc, Properties classProperties)
            throws SpeedoException {
        //Build the map
        // Put the binder class name of the current persistent class
        String id = JormPathHelper.getPath(sc.jormclass);
        NameDef nd = getClassNameDef(sc.jormclass);
        jormConfigs(nd, sc, sc.jormclass, id, classProperties);

        //Put the binder class name for each reference field
        SpeedoXMLDescriptor xml = sc.moPackage.xmlDescriptor;
        for (Iterator it = sc.jormclass.getAllFields().iterator(); it
View Full Code Here

TOP

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

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.