Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013-2015 Amazon Technologies, Inc. 
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); 
   * you may not use this file except in compliance with the License. 
   * You may obtain a copy of the License at:
   * 
   *    http://aws.amazon.com/apache2.0
   *
  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 
  * OR CONDITIONS OF ANY KIND, either express or implied. See the 
  * License for the specific language governing permissions and 
  * limitations under the License. 
  */
 package com.amazonaws.regions;
 
 import java.util.Map;
 
Metadata for an AWS region, including its name and what services are available in it.
 
 public final class Region {
 
     private static final String DEFAULT_DOMAIN = "amazonaws.com";
 
     private final String name;
     private final String domain;
 
     private final Map<StringStringserviceEndpoints =
         new HashMap<StringString>();
 
     private final Map<StringBooleanhttpSupport =
         new HashMap<StringBoolean>();
 
     private final Map<StringBooleanhttpsSupport =
         new HashMap<StringBoolean>();
 
     Region(final String namefinal String domain) {
         this. = name;
 
         if (domain == null) {
             this. = ;
         } else {
             this. = domain;
         }
     }

    
Returns the region with the id given, or null if it cannot be found in the current regions.xml file.
 
     public static Region getRegion(Regions region) {
         return RegionUtils.getRegion(region.getName());
     }

    
The unique system ID for this region; ex: "us-east-1".

Returns:
The unique system ID for this region.
 
     public String getName() {
         return ;
     }

    
Returns the domain for this region; ex: "amazonaws.com".

Returns:
The domain for this region.
 
     public String getDomain() {
         return ;
     }

    
Returns a map of the available services in this region and their endpoints. The keys of the map are service abbreviations, as defined in ServiceAbbreviations, and the values are the endpoint URLs.

Returns:
A map of the available services in this region.
 
         return ;
     }
 
     Map<StringBooleangetHttpSupport() {
         return ;
     }
 
     Map<StringBooleangetHttpsSupport() {
         return ;
     }

    
Returns the endpoint for the service given.

    public String getServiceEndpoint(String serviceName) {
        return .get(serviceName);
    }

    
Returns whether the given service is supported in this region.

    public boolean isServiceSupported(String serviceName) {
        return .containsKey(serviceName);
    }
    
    
Returns whether the given service support the https protocol in this region.

    public boolean hasHttpsEndpoint(String serviceName) {
        return .containsKey(serviceName) && .get(serviceName);
    }

    
Returns whether the given service support the http protocol in this region.

    public boolean hasHttpEndpoint(String serviceName) {
        return .containsKey(serviceName) && .get(serviceName);
    }    
    
    
Creates a new service client of the class given and configures it. If credentials or config are null, defaults will be used.

Parameters:
serviceClass The service client class to instantiate, e.g. AmazonS3Client.class
credentials The credentials provider to use, or null for the default credentials provider
config The configuration to use, or null for the default configuration
See also:
ServiceAbbreviations
    public <T extends AmazonWebServiceClient> T createClient(Class<T> serviceClass,
                                                             AWSCredentialsProvider credentials,
                                                             ClientConfiguration config) {
        Constructor<T> constructor;
        T client;
        try {
            if ( credentials == null && config == null ) {
                constructor = serviceClass.getConstructor();
                client = constructor.newInstance();
            } else if ( credentials == null ) {
                constructor = serviceClass.getConstructor(ClientConfiguration.class);
                client = constructor.newInstance(config);
            } else if ( config == null ) {
                constructor = serviceClass.getConstructor(AWSCredentialsProvider.class);
                client = constructor.newInstance(credentials);
            } else {
                constructor = serviceClass.getConstructor(AWSCredentialsProvider.classClientConfiguration.class);
                client = constructor.newInstance(credentialsconfig);
            }
            
            client.setRegion(this);
            return client;
        } catch ( Exception e ) {
            throw new RuntimeException("Couldn't instantiate instance of " + serviceClasse);
        }
    }
    @Override
    public boolean equals(Object obj) {
        if ( obj instanceof Region == false )
            return false;
        Region region = (Regionobj;
        return this.getName().equals(region.getName());
    }
    @Override
    public int hashCode() {
        return getName().hashCode();
    }
    @Override
    public String toString() {
        return getName();
    }
New to GrepCode? Check out our FAQ X