/**
   * Method to get all the config objects that match resource given This method check if the find
   * should be done by containment path or find and resolve or if it should be done by attribute
   * name
   *
   * @param session
   * @param configService
   * @param resource
   * @param scope
   * @param inSyncMethod
   * @return
   * @throws ConnectorException
   * @throws ConfigServiceException
   * @throws AttributeNotFoundException
   * @throws MalformedObjectNameException
   */
  public ObjectName[] findAllResourcesInConfig(
      Session session,
      ConfigService configService,
      Resource resource,
      ObjectName scope,
      boolean inSyncMethod)
      throws ConnectorException, ConfigServiceException, AttributeNotFoundException {
    logger.debug(">>> find all resources " + resource.getContainmentPath());
    ResourceHelper resourceHelper = new ResourceHelper();

    ObjectName[] configIDs = null;
    String attributeNameForDuplicateObjectTypeChild = null;
    if (resource.getAttributeList().get(ResourceConstants.ATTRUBUTENAME) != null) {
      attributeNameForDuplicateObjectTypeChild =
          resource.getAttributeList().get(ResourceConstants.ATTRUBUTENAME).toString();
    }
    /**
     * SyncFindModeContainmentPath is used for objects like SIBusMemberTarget where there can be
     * only one bus SIBusMemberTarget under SIBusMember, so that we display only that.
     *
     * <p>But in the find mode we use the logic of
     */
    if (resource.getResourceMetaData().isSyncFindModeContainmentPath()) {
      logger.trace(
          " Get all ConfigObjects for the containment path "
              + resource.getContainmentPath()
              + " ] ");
      configIDs = configService.resolve(session, resource.getContainmentPath());
      // configIDs = resourceHelper.getObjectNames(session,configService,
      // resource.getContainmentPath());

    } else if ((!inSyncMethod) && (!resource.getResourceMetaData().isFindAndResolve())) {
      logger.trace(
          " Get all ConfigObjects using resourceHelper.getObjectNames "
              + resource.getName()
              + " to find "
              + resource
                  .getAttributeList()
                  .get(resource.getResourceMetaData().getContainmentAttribute()));
      configIDs =
          resourceHelper.getObjectNames(session, configService, resource.getContainmentPath());
    } else if (scope == null) {
      logger.trace(
          " Get all ConfigObjects for the type "
              + resource.getName()
              + " to find "
              + resource
                  .getAttributeList()
                  .get(resource.getResourceMetaData().getContainmentAttribute()));
      configIDs = configService.resolve(session, resource.getName());
    } else if (attributeNameForDuplicateObjectTypeChild != null) {
      logger.trace(
          " Get all ConfigObjects by getting  value of the attribute "
              + resource.getAttributeList().get(ResourceConstants.ATTRUBUTENAME)
              + " for resource "
              + resource.getName()
              + " to find "
              + resource
                  .getAttributeList()
                  .get(resource.getResourceMetaData().getContainmentAttribute()));
      ObjectName[] newConfigObject = {
        ConfigServiceHelper.createObjectName(
            (AttributeList)
                configService.getAttribute(
                    session,
                    resource.getParent().getConfigId(),
                    attributeNameForDuplicateObjectTypeChild))
      };
      configIDs = newConfigObject;
    } else {
      logger.trace(
          " Get ConfigObjects for the type "
              + resource.getName()
              + " in scope "
              + configService.getAttribute(session, scope, "name")
              + " to find "
              + resource
                  .getAttributeList()
                  .get(resource.getResourceMetaData().getContainmentAttribute()));
      configIDs = configService.resolve(session, scope, resource.getName());
    }

    // matchAdditionalContainmentAttributeIfRequired
    logger.debug("<<<  number of objects found" + configIDs.length);
    return configIDs;
  }
  /**
   * Now check if there a syncPreMatchAttribute, If the value for the attribute exists Check if the
   * attribute is of reference type. If it is reference type then for the value of this attribute
   * from WAS config get the resource reference value. If resource reference value is not found then
   * mark this object as prematch fail If resource reference value is found then match the resource
   * reference name to the value of in the resource object. This is to ensure that type of object
   * reterived is correct.
   *
   * <p>This is useful for object like ActivationSpec, QCF and AdminObject which have
   * connectiondefination and adminobject attribute which defines what type of object it is
   *
   * <p>By match these attributes we ensure that in sync operation that we do not fetch the objects
   * that are not required.
   */
  public boolean doesConfigObjectPreMatch(
      Session session,
      ConfigService configService,
      Resource resource,
      ObjectName configObject,
      Resource referencedResources)
      throws ConnectorException, ConfigServiceException, AttributeNotFoundException,
          MalformedObjectNameException, AttributeNotFoundException, DeployException {

    boolean syncPreMatch = true;

    if ((resource.getResourceMetaData().getSyncPreMatchAttribute() != null)
        && (resource.getResourceMetaData().getSyncPreMatchAttribute().trim().length() > 0)) {
      String preMatchAttributeName = resource.getResourceMetaData().getSyncPreMatchAttribute();
      String preMatchAttributeValue =
          resource.getAttributeList().get(preMatchAttributeName).toString();

      if (configService.getAttribute(session, configObject, preMatchAttributeName) != null) {
        Object preMatchAttributeConfigValue =
            configService.getAttribute(session, configObject, preMatchAttributeName).toString();

        boolean isReference =
            ResourceHelper.isAttributeReference(
                configService.getAttributesMetaInfo(resource.getName()), preMatchAttributeName);
        String attributeType =
            ResourceHelper.getAttributeType(
                configService.getAttributesMetaInfo(resource.getName()), preMatchAttributeName);
        if (isReference) {
          Resource referenceMatchResource =
              getMatchingResourceReferenceForConfigObject(
                  configService,
                  session,
                  referencedResources,
                  new ObjectName(preMatchAttributeConfigValue.toString()),
                  attributeType);
          if (referenceMatchResource == null) {
            logger.warn(attributeType + " not supported");
            syncPreMatch = false;
          } else {
            if (!(PropertiesConstant.VARIABLE_PREFIX
                    + referenceMatchResource.getName()
                    + PropertiesConstant.VARIABLE_SUFFIX)
                .equalsIgnoreCase(preMatchAttributeValue)) {
              logger.trace(
                  "Prematch false Config:"
                      + PropertiesConstant.VARIABLE_PREFIX
                      + referenceMatchResource.getName()
                      + PropertiesConstant.VARIABLE_SUFFIX
                      + " and DAKS:"
                      + preMatchAttributeValue);
              syncPreMatch = false;
            }
          }
        } else {
          if (!(preMatchAttributeValue.equals(preMatchAttributeConfigValue.toString()))) {
            logger.trace(
                "Prematch false Config:"
                    + preMatchAttributeConfigValue
                    + " and DAKS:"
                    + preMatchAttributeValue);
            syncPreMatch = false;
          }
        }
      } else {
        logger.trace(
            "Prematch false Config value is null for "
                + preMatchAttributeName
                + " and DAKS:"
                + preMatchAttributeValue);
        syncPreMatch = false;
      }
    }
    return syncPreMatch;
  }