public static void build()

in odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java [429:530]


  public static void build(final JPAEdmAssociationView associationView,
      final JPAEdmPropertyView propertyView,
      final JPAEdmNavigationPropertyView navPropertyView, final boolean skipDefaultNaming, final int count) {

    boolean overrideSkipDefaultNaming = false;

    String toName = null;
    String fromName = null;
    String navPropName = null;
    NavigationProperty navProp = navPropertyView.getEdmNavigationProperty();
    String namespace = buildNamespace(associationView);

    Association association = associationView.getEdmAssociation();
    navProp.setRelationship(new FullQualifiedName(namespace, association
        .getName()));

    FullQualifiedName associationEndTypeOne = association.getEnd1()
        .getType();
    FullQualifiedName associationEndTypeTwo = association.getEnd2()
        .getType();

    Attribute<?, ?> jpaAttribute = propertyView.getJPAAttribute();
    JPAEdmMapping mapping = new JPAEdmMappingImpl();
    ((Mapping) mapping).setInternalName(jpaAttribute.getName());
    mapping.setJPAType(jpaAttribute.getJavaType());
    navProp.setMapping((Mapping) mapping);

    String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView()
        .getJPAEntityType().getName();
    JPAEdmMappingModelAccess mappingModelAccess = navPropertyView
        .getJPAEdmMappingModelAccess();

    String targetEntityTypeName = null;
    if (jpaAttribute.isCollection()) {
      targetEntityTypeName = ((PluralAttribute<?, ?, ?>) jpaAttribute).getElementType().getJavaType().getSimpleName();
    } else {
      targetEntityTypeName = jpaAttribute.getJavaType().getSimpleName();
    }

    if (mappingModelAccess != null
        && mappingModelAccess.isMappingModelExists()) {
      navPropName = mappingModelAccess.mapJPARelationship(
          jpaEntityTypeName, jpaAttribute.getName());
      toName = mappingModelAccess.mapJPAEntityType(targetEntityTypeName);
      fromName = mappingModelAccess
          .mapJPAEntityType(jpaEntityTypeName);
      if (navPropName != null) {
        overrideSkipDefaultNaming = true;
      }
    }
    if (toName == null) {
      toName = targetEntityTypeName;
    }

    if (fromName == null) {
      fromName = jpaEntityTypeName;
    }
    /*
     * Navigation Property name was provided in mapping then don't try to default the name
     */
    if (overrideSkipDefaultNaming == false && skipDefaultNaming == false) {
      if (navPropName == null) {
        navPropName = toName.concat(NAVIGATION_NAME);
      }
      if (count > 1) {
        navPropName = navPropName + Integer.toString(count - 1);
      }
    } else if (navPropName == null) {
      navPropName = jpaAttribute.getName();
    }

    navProp.setName(navPropName);

    // Condition for self join
    if (associationEndTypeOne.getName().equals(associationEndTypeTwo.getName())) {
      if (jpaAttribute.isCollection()) {
        if (association.getEnd2().getMultiplicity().equals(EdmMultiplicity.MANY)) {
          navProp.setToRole(association.getEnd2().getRole());
          navProp.setFromRole(association.getEnd1().getRole());
        } else {
          navProp.setToRole(association.getEnd1().getRole());
          navProp.setFromRole(association.getEnd2().getRole());
        }
      } else {
        if (association.getEnd2().getMultiplicity().equals(EdmMultiplicity.ONE)
            || association.getEnd2().getMultiplicity().equals(EdmMultiplicity.ZERO_TO_ONE)) {
          navProp.setToRole(association.getEnd2().getRole());
          navProp.setFromRole(association.getEnd1().getRole());
        } else {
          navProp.setToRole(association.getEnd1().getRole());
          navProp.setFromRole(association.getEnd2().getRole());
        }
      }
    } else if (toName.equals(associationEndTypeOne.getName())) {
      navProp.setFromRole(association.getEnd2().getRole());
      navProp.setToRole(association.getEnd1().getRole());
    } else if (toName.equals(associationEndTypeTwo.getName())) {

      navProp.setToRole(association.getEnd2().getRole());
      navProp.setFromRole(association.getEnd1().getRole());
    }
  }