/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package web.component.impl.aws;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import web.component.impl.Cloud;
import web.component.impl.CloudBlock;

/**
 *
 * @author Hiroshi
 */
public class AWS implements Cloud{
    
    private static final AWS INSTANCE = new AWS();

    private final Properties AWS_CONFIG = new Properties();
    
    private final Map<BlockName, CloudBlock> components = new HashMap<>();

    private AWS(){     

        try {
            AWS_CONFIG.load(AWS.class.getResourceAsStream("./aws_config.txt"));
        } catch (IOException ex) {
            System.out.println("configuration file not found.");
            throw new RuntimeException(ex);
        }
    }
    
    //interface to access cloud.
    public static AWS access(){
        return INSTANCE;
    }
    
    public final CloudBlock get(BlockName name){
        
        CloudBlock cb = components.get(name);
        
        if(cb == null){
        
            if(BlockName.EC2.equals(name))
                cb = AWSEC2.get();
            if(BlockName.ELB.equals(name))
                cb = AWSELB.get();
            if(BlockName.AutoScaling.equals(name))
                cb = AWSAutoScaling.get();
            
            components.put(name, cb);
        }
        return cb;
    }
    
    Properties conf(){
        
        return (Properties)AWS_CONFIG.clone();
    }
    
    AWSCredentials credentials(){
        
        String awsKey = AWS_CONFIG.getProperty("aws.key");
        String secretKey = AWS_CONFIG.getProperty("aws.secret");
        
        return new BasicAWSCredentials(awsKey,secretKey);
    }
    
    public static enum BlockName{
        EC2,ELB,AutoScaling;
    }
}

@@ -346,23 +346,74 @@
 va.util.
-HashMap
+ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List
 ;%0Aimport
@@ -712,24 +712,79 @@
 ies();%0A    %0A
+    private final AWSCredentials AWS_CREDENTIALS;%0A    %0A
     private 
@@ -1115,24 +1115,227 @@
 );%0A        %7D
+%0A%0A        String awsKey = AWS_CONFIG.getProperty(%22aws.key%22);%0A        String secretKey = AWS_CONFIG.getProperty(%22aws.secret%22);%0A        %0A        AWS_CREDENTIALS = new BasicAWSCredentials(awsKey,secretKey);
 %0A    %7D%0A    %0A
@@ -1918,24 +1918,89 @@
 %0A    %7D%0A    %0A
+   /*%0A    * returns a copy instancd of AWS client config.%0A    */%0A
     Properti
@@ -2006,32 +2006,33 @@
 ies conf()%7B%0A
+%0A
         
 %0A        ret
@@ -2023,66 +2023,403 @@
     
-%0A        return (Properties)AWS_CONFIG.clone(
+Properties copyConf = new Properties();%0A        %0A        List%3CObject%3E keys = new ArrayList%3C%3E(AWS_CONFIG.keySet());%0A        for(Object key : keys)%7B%0A            String keyString = (String)key;%0A            copyConf.setProperty(keyString, AWS_CONFIG.getProperty(keyString)
 );%0A    
+ 
+   
 %7D%0A    
+ 
+   %0A        return copyConf;%0A    %7D%0A    %0A   /*%0A    * returns a copy instancd of AWS client credentials.%0A    */
 %0A   
@@ -2491,35 +2491,37 @@
 WS_C
-ONFIG.getProperty(%22aws.key%22
+REDENTIALS.getAWSAccessKeyId(
 );%0A 
@@ -2555,49 +2555,80 @@
 WS_C
-ONFIG.getProperty(%22aws.secret%22);%0A        
+REDENTIALS.getAWSSecretKey();%0A        %0A        //return a copy instance.
 %0A   
@@ -2662,32 +2662,33 @@
 dentials(awsKey,
+ 
 secretKey);%0A    

modify conf, credentials methods to return its copy and not itself.