Exemple #1
0
  protected FieldDescriptor createFieldDesc(Class javaClass, FieldMapping fieldMap)
      throws MappingException {
    FieldDescriptor fieldDesc;
    String ldapName;

    // If not an LDAP field, return a stock field descriptor.
    if (fieldMap.getLdap() == null) return super.createFieldDesc(javaClass, fieldMap);

    // Create a DAX field descriptor
    fieldDesc = super.createFieldDesc(javaClass, fieldMap);
    if (fieldMap.getLdap().getName() == null) ldapName = fieldDesc.getFieldName();
    else ldapName = fieldMap.getLdap().getName();
    return new DAXFieldDescriptor((FieldDescriptorImpl) fieldDesc, ldapName);
  }
 /**
  * Walks through all fields of a descriptor and resolves relation {@link ClassDescriptor}s by
  * using mapping information or, if not present, resolution by file to support generated {@link
  * ClassDescriptor}s. Resolved {@link ClassDescriptor}s will be set as a field's descriptor.
  *
  * @param clsDesc The ClassDescriptor in focus.
  */
 protected void resolveRelations(final ClassDescriptor clsDesc) {
   FieldDescriptor[] fields = clsDesc.getFields();
   for (int i = 0; i < fields.length; ++i) {
     FieldDescriptor field = fields[i];
     ClassDescriptor desc = getDescriptor(field.getFieldType().getName());
     // Resolve ClassDescriptor from the file system as well.
     if (desc == null && !field.getFieldType().isPrimitive()) {
       ClassResolutionByFile resolutionCommand = new ClassResolutionByFile();
       resolutionCommand.addNature(ClassLoaderNature.class.getName());
       ClassLoaderNature clNature = new ClassLoaderNature(resolutionCommand);
       clNature.setClassLoader(getClassLoader());
       desc = resolutionCommand.resolve(field.getFieldType());
       ((FieldDescriptorImpl) field).setClassDescriptor(desc);
     }
     if ((desc != null) && (field instanceof FieldDescriptorImpl)) {
       ((FieldDescriptorImpl) field).setClassDescriptor(desc);
     }
   }
 }
  protected FieldDescriptor findIdentityByName(
      final List<FieldDescriptor> fldList, final String idName, final Class javaClass)
      throws MappingException {
    for (int i = 0; i < fldList.size(); i++) {
      FieldDescriptor field = fldList.get(i);
      if (idName.equals(field.getFieldName())) {
        if (!(field.hasNature(FieldDescriptorJDONature.class.getName()))) {
          throw new IllegalStateException("Identity field must be of type JDOFieldDescriptor");
        }

        String[] sqlName = new FieldDescriptorJDONature(field).getSQLName();
        if (sqlName == null) {
          throw new MappingException(
              "mapping.noSqlName", field.getFieldName(), javaClass.getName());
        }

        fldList.remove(i);
        return field;
      }
    }
    return null;
  }