/**
   * INTERNAL:
   *
   * @param property
   */
  public void addDeclaredProperty(SDOProperty property, int index) {
    if (!getDeclaredPropertiesMap().containsKey(property.getName())) {
      int currentSize = getDeclaredProperties().size();

      int allSize = getProperties().size();
      int insertPlace = allSize - currentSize + index;

      // updateSubTypesProps
      if (isBaseType()) {
        for (int i = 0; i < getSubTypes().size(); i++) {
          SDOType nextSubType = (SDOType) getSubTypes().get(i);
          nextSubType.updateIndices(insertPlace, property);
        }
      }

      getDeclaredProperties().add(index, property);
      getProperties().add(insertPlace, property);

      property.setContainingType(this);

      getDeclaredPropertiesMap().put(property.getName(), property);
      if (property.hasAliasNames()) {
        for (int j = 0; j < property.getAliasNames().size(); j++) {
          getDeclaredPropertiesMap().put(property.getAliasNames().get(j), property);
        }
      }
      if ((property.getType() != null) && (property.getType().isChangeSummaryType())) {
        changeSummaryProperty = property;
      }
    }
  }
  private void updateIndices(int insertPosition, Property property) {
    int declaredSize = getDeclaredProperties().size();
    SDOProperty nextProp = null;
    for (int i = 0; i < declaredSize; i++) {
      nextProp = (SDOProperty) getDeclaredProperties().get(i);
      nextProp.setIndexInType(nextProp.getIndexInType() + 1);
    }
    getProperties().add(insertPosition, property);
    if (isBaseType()) {
      int subTypesSize = getSubTypes().size();

      SDOType nextSubType = null;
      for (int i = 0; i < subTypesSize; i++) {
        nextSubType = (SDOType) getSubTypes().get(i);
        nextSubType.updateIndices(insertPosition, property);
      }
    }
  }
  /** INTERNAL: */
  public void postInitialize() {
    String idPropName = (String) get(SDOConstants.ID_PROPERTY);
    if (idPropName != null) {
      SDOProperty idProp = getProperty(idPropName);
      if (idProp != null) {
        String targetxpath = idProp.getQualifiedXPath(getURI(), true);
        getXmlDescriptor().addPrimaryKeyFieldName(targetxpath);
      }
    }
    setFinalized(true);
    if (null != nonFinalizedReferencingProps) {
      for (int i = 0; i < nonFinalizedReferencingProps.size(); i++) {
        SDOProperty nextProp = nonFinalizedReferencingProps.get(i);
        String nextURI = (String) getNonFinalizedMappingURIs().get(i);
        nextProp.buildMapping(nextURI, nextProp.getIndexInType());
      }
    }
    // set @sdoRef attribute mapping for complex types that are not involved in inheritance
    if (!isDataType() && !isSubType() && !isBaseType()) {
      String sdoPrefix =
          ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(SDOConstants.SDO_URL);
      XMLDirectMapping sdoRefMapping = new XMLDirectMapping();
      sdoRefMapping.setAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME);

      XMLField xmlField =
          new XMLField(
              "@"
                  + sdoPrefix
                  + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT
                  + SDOConstants.CHANGESUMMARY_REF);
      xmlField.getXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
      xmlField.getLastXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
      sdoRefMapping.setField(xmlField);
      xmlDescriptor.addMapping(sdoRefMapping);
    }
    if (!isDataType()) {
      getImplClass();
      if (!isAbstract() && !isWrapperType()) {
        TypeInstantiationPolicy tip = new TypeInstantiationPolicy(this);
        this.xmlDescriptor.setInstantiationPolicy(tip);
      }
    }
  }
 /** Verify that the class is a valid instance class. */
 private boolean isValidInstanceClass(Class clazz) {
   if (isDataType) {
     return true;
   }
   if (!clazz.isInterface()) {
     return false;
   }
   for (Object object : this.getDeclaredProperties()) {
     SDOProperty sdoProperty = (SDOProperty) object;
     SDOType sdoPropertyType = sdoProperty.getType();
     if (!sdoPropertyType.isChangeSummaryType()) {
       String javaType = SDOUtil.getJavaTypeForProperty(sdoProperty);
       try {
         // Verify get method
         String getMethodName = SDOUtil.getMethodName(sdoProperty.getName(), javaType);
         PrivilegedAccessHelper.getPublicMethod(clazz, getMethodName, EMPTY_CLASS_ARRAY, false);
       } catch (NoSuchMethodException e) {
         // if the method isn't found and the type is boolean try looking for a "get" method
         // instead of an "is" method
         if (sdoPropertyType == SDOConstants.SDO_BOOLEAN
             || sdoPropertyType == SDOConstants.SDO_BOOLEANOBJECT) {
           try {
             String booleanGetterMethodName =
                 SDOUtil.getBooleanGetMethodName(sdoProperty.getName(), javaType);
             PrivilegedAccessHelper.getPublicMethod(
                 clazz, booleanGetterMethodName, EMPTY_CLASS_ARRAY, false);
           } catch (NoSuchMethodException e2) {
             return false;
           }
         } else {
           return false;
         }
       }
     }
   }
   return true;
 }