### *** This class provides Binary Compatibility only, not Source Compatibility ***

Package com.sas.services.discovery

# Class ServiceComponentAttribute

java.lang.Object
com.sas.services.AbstractServiceAttribute
com.sas.services.discovery.MetadataAttribute
com.sas.services.discovery.ServiceComponentAttribute

All Implemented Interfaces:
  `ServiceAttributeInterface`, `Serializable`

@SASScope("ALL") @BinaryCompatibilityOnly public final class ServiceComponentAttribute extends MetadataAttribute
A foundation service discovery attribute which represents an foundation service.

When a service is deployed, a `ServiceComponentAttribute` will be added to its service discovery configuration representing the the service.

A service is represented by a metadata `ServiceComponent`.

Attribute | Description
--- | ---
id | the fully-qualified metadata ID of the `ServiceComponent` that represents a foundation service (i.e. `ServiceComponent.Id`)
name | the name of the `ServiceComponent` that represents a foundation service (i.e. `ServiceComponent.Name`)

Any values that are not specified should be `null` to indicate a "don't care".

## Examples

Examples are provided to find a service by its:

- name
- metadata ID
- name and metadata ID

## Example 1: Find a service using its name

To find a service using its name, define a service template that specifies one or more interfaces that the desired service must implement and this attribute initialized to the service's name.

The following example shows how to define a service template that can be used to discover an Authentication service that is named "Authentication Service".

    import com.sas.services.discovery.DiscoveryService;
    import com.sas.services.discovery.ServiceAttributeInterface;
    import com.sas.services.discovery.ServiceComponentAttribute;
    import com.sas.services.discovery.ServiceTemplate;
    import com.sas.services.security.AuthenticationServiceInterface;

    ...

    // specify the desired service type(s)
    Class[] desiredServiceTypes = new Class[] {
       AuthenticationServiceInterface.class};

    // the name of desired service
    String serviceName = "Authentication Service";

    // specify the optional attributes to be used to qualify a discovery lookup
    // to include only those services with the specified name.
    ServiceAttributeInterface[] serviceAttributes =
       new ServiceAttributeInterface[] {
          new ServiceDeploymentAttribute(
             serviceName,
             null)};// don't care about the service's metadata ID

    // create a service lookup template specifying the required
    // service interface(s) and a service attribute for a
    // the desired service
    ServiceTemplate serviceTemplate = new ServiceTemplate(
       desiredServiceTypes,
       serviceAttributes);

    // discover a service satisfying the service template
    AuthenticationServiceInterface authenticationService = (AuthenticationServiceInterface)
       DiscoveryService.defaultInstance().findService(serviceTemplate);

## Example 2: Find a service using its metadata ID

To find a service using its metadata ID define a service template that specifies one or more interfaces that the desired service must implement and this attribute initialized to the desired service's ID.

The following example shows how to define a service template that can be used to discover an Authentication service whose metadata ID is "A0000001.12341234".

    import com.sas.metadata.remote.ServiceComponent;
    import com.sas.services.discovery.DiscoveryService;
    import com.sas.services.discovery.ServiceAttributeInterface;
    import com.sas.services.discovery.ServiceComponentAttribute;
    import com.sas.services.discovery.ServiceTemplate;
    import com.sas.services.security.AuthenticationServiceInterface;

    ...

    // specify the desired service type(s)
    final Class[] desiredServiceTypes = new Class[] {
       AuthenticationServiceInterface.class};

    // The ServiceComponent.Id for the metadata service component
    // that represents the desired service
    String serviceMetadataID = "A0000001.12341234";

    // specify the optional attributes to be used to qualify a discovery lookup
    // to include only those services which belong to an application service
    // deployment with the specified metadata ID.
    ServiceAttributeInterface[] serviceAttributes =
       new ServiceAttributeInterface[] {
          new ServiceComponentAttribute(
             null,// don't care about the service's name
             serviceMetadataID)};

    // create a service lookup template specifying the required
    // service interface(s) and a service attribute for a
    // service whose metadata ID matches the specified attribute
    ServiceTemplate serviceTemplate = new ServiceTemplate(
       desiredServiceTypes,
       serviceAttributes);

    // discover a service satisfying the service template
    AuthenticationServiceInterface authenticationService = (AuthenticationServiceInterface)
       DiscoveryService.defaultInstance().findService(serviceTemplate);

## Example 3: Find a service using its name and metadata ID

To find a service using the service's name and metadata ID define a service template that specifies the desired service interface(s) and this attribute initialized to the desired service's name and ID.

The following example shows how to define a service template that can be used to discover an Authentication service that whose name and ID are obtained from the metadata ServiceComponent that represents the desired service.

    import com.sas.metadata.remote.ServiceComponent;
    import com.sas.services.discovery.DiscoveryService;
    import com.sas.services.discovery.ServiceAttributeInterface;
    import com.sas.services.discovery.ServiceComponentAttribute;
    import com.sas.services.discovery.ServiceTemplate;
    import com.sas.services.security.AuthenticationServiceInterface;

    ...

    // specify the desired service type(s)
    final Class[] desiredServiceTypes = new Class[] {
       AuthenticationServiceInterface.class};

    // given the metadata ServiceComponent metadata object
    // representing a foundation service, determine
    // the service's name and metadata ID
    ServiceComponent serviceComponent = ...
    String serviceName = serviceComponent.getName();
    String serviceMetadataID = serviceComponent.getFQID();

    // specify the optional attributes to be used to qualify a discovery lookup
    // to include only those services which match the specified name and metadata ID.
    ServiceAttributeInterface[] serviceAttributes =
       new ServiceAttributeInterface[] {
          new ServiceDeploymentAttribute(
             serviceName,
             serviceMetadataID)};

    // create a service lookup template specifying the required
    // service interface(s) and a service attribute for a
    // service that belongs to a particular application service deployment
    ServiceTemplate serviceTemplate = new ServiceTemplate(
       desiredServiceTypes,
       serviceAttributes);

    // discover a service satisfying the service template
    AuthenticationServiceInterface authenticationService = (AuthenticationServiceInterface)
       DiscoveryService.defaultInstance().findService(serviceTemplate);

Since:
  1.2
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `String`
  `runtimeId`
  The service's runtime ID.

  ### Fields inherited from class com.sas.services.discovery.MetadataAttribute

  `classIdentifier, elementType, id, name`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ServiceComponentAttribute()`
  Constructs a default instance with the application service deployment ID and name initialized to `null`.
  `ServiceComponentAttribute(com.sas.metadata.remote.ServiceComponent serviceComponent)`
  Constructs a service discovery attribute which may be used to lookup a service represented by the specified by a remote JOMA `ServiceComponent`.
  `ServiceComponentAttribute(String attributeName, String attributeId)`
  Constructs a service discovery attribute which may be used to lookup a service which belongs to the specified application service deployment.
  `ServiceComponentAttribute(String attributeName, String attributeId, String runtimeServiceId)`
  Constructs a service discovery attribute which may be used to lookup a service which belongs to the specified application service deployment.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Map<String,String>`
  `getFieldNameToValueMap()`
  Gets a map of this attribute's fields and their values which includes the runtimeId plus fields defined in the superclass.

  ### Methods inherited from class com.sas.services.AbstractServiceAttribute

  `equals, hashCode, toString`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### runtimeId

    public String runtimeId
    The service's runtime ID.

- ## Constructor Details

  - ### ServiceComponentAttribute

    public ServiceComponentAttribute()
    Constructs a default instance with the application service deployment ID and name initialized to `null`.

  - ### ServiceComponentAttribute

    public ServiceComponentAttribute(String attributeName, String attributeId)
    Constructs a service discovery attribute which may be used to lookup a service which belongs to the specified application service deployment.

    Use this constructor if you don't have a `SoftwareComponent` that represents an application's service deployment and you want to initialize a service discovery attribute that can be used to lookup a service that belongs to a particular service deployment using its ID and/or name.

    Parameters:
      `attributeName` - The metadata element's name or `null` if unspecified.
      `attributeId` - The metadata element's id (i.e. "A5K2EL3N.B000000B") or `null` if unspecified.
    See Also:
      - `ServiceComponentAttribute(ServiceComponent)`

  - ### ServiceComponentAttribute

    public ServiceComponentAttribute(String attributeName, String attributeId, String runtimeServiceId)
    Constructs a service discovery attribute which may be used to lookup a service which belongs to the specified application service deployment.

    Use this constructor if you don't have a `SoftwareComponent` that represents an application's service deployment and you want to initialize a service discovery attribute that can be used to lookup a service that belongs to a particular service deployment using its ID and/or name.

    Parameters:
      `attributeName` - The metadata element's name or `null` if unspecified.
      `attributeId` - The metadata element's id (i.e. "A5K2EL3N.B000000B") or `null` if unspecified.
      `runtimeServiceId` - The service's runtime id or `null` if unspecified.
    See Also:
      - `ServiceComponentAttribute(ServiceComponent)`

  - ### ServiceComponentAttribute

    public ServiceComponentAttribute(com.sas.metadata.remote.ServiceComponent serviceComponent) throws IllegalArgumentException
    Constructs a service discovery attribute which may be used to lookup a service represented by the specified by a remote JOMA `ServiceComponent`.

    Use this constructor if you have a `ServiceComponent` that represents a foundation service and you want to initialize a service discovery attribute that can be used to lookup this service by its ID and/or name.

    Parameters:
      `serviceComponent` - A remote JOMA metadata element that represents a foundation service.
    Throws:
      `IllegalArgumentException` - if a `null` parameter is specified or if the `ServiceComponent` does not represent a foundation service.
    See Also:
      - `ServiceComponentAttribute(String, String, String)`

- ## Method Details

  - ### getFieldNameToValueMap

    public Map<String,String> getFieldNameToValueMap()
    Gets a map of this attribute's fields and their values which includes the runtimeId plus fields defined in the superclass.
    Overrides:
      `getFieldNameToValueMap` in class `MetadataAttribute`
    Returns:
      String summarizing the state of this attribute.
    See Also:
      - `MetadataAttribute.getFieldNameToValueMap()`