Coverage Report - de.smartics.properties.impl.config.domain.key.envapp.EnvAppKeyListBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
EnvAppKeyListBuilder
0%
0/44
0%
0/18
3.25
 
 1  
 /*
 2  
  * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package de.smartics.properties.impl.config.domain.key.envapp;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import de.smartics.properties.api.config.domain.key.ApplicationId;
 22  
 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
 23  
 import de.smartics.properties.api.config.domain.key.EnvironmentId;
 24  
 import de.smartics.properties.api.config.domain.key.KeyListBuilder;
 25  
 import de.smartics.util.lang.NullArgumentException;
 26  
 
 27  
 /**
 28  
  * Explodes the key to its defaulting keys.
 29  
  */
 30  
 final class EnvAppKeyListBuilder implements KeyListBuilder
 31  
 {
 32  
   // ********************************* Fields *********************************
 33  
 
 34  
   // --- constants ------------------------------------------------------------
 35  
 
 36  
   // --- members --------------------------------------------------------------
 37  
 
 38  
   // ****************************** Initializer *******************************
 39  
 
 40  
   // ****************************** Constructors ******************************
 41  
 
 42  
   /**
 43  
    * Default constructor.
 44  
    */
 45  
   EnvAppKeyListBuilder()
 46  0
   {
 47  0
   }
 48  
 
 49  
   // ****************************** Inner Classes *****************************
 50  
 
 51  
   // ********************************* Methods ********************************
 52  
 
 53  
   // --- init -----------------------------------------------------------------
 54  
 
 55  
   // --- get&set --------------------------------------------------------------
 56  
 
 57  
   // --- business -------------------------------------------------------------
 58  
 
 59  
   @Override
 60  
   public List<ConfigurationKey<?>> createKeyList(
 61  
       final ConfigurationKey<?> key)
 62  
   {
 63  0
     final List<ConfigurationKey<?>> list =
 64  
         new ArrayList<ConfigurationKey<?>>();
 65  0
     list.add(key);
 66  
 
 67  0
     final EnvAppConfigurationKey specific = (EnvAppConfigurationKey) key;
 68  0
     final EnvironmentId envId = specific.getEnvironmentId();
 69  0
     final ApplicationId appId = specific.getApplicationId();
 70  
 
 71  0
     addAppKeys(list, envId, appId);
 72  
 
 73  0
     if (envId.getNode() != null)
 74  
     {
 75  0
       final EnvironmentId defaultEnv = new EnvironmentId(envId.getName());
 76  0
       if (!ApplicationId.ANY_APP.equals(appId))
 77  
       {
 78  0
         if (appId.getVersion() != null)
 79  
         {
 80  0
           final EnvAppConfigurationKey defaultKey =
 81  
               new EnvAppConfigurationKey(defaultEnv, appId);
 82  0
           list.add(defaultKey);
 83  
         }
 84  
 
 85  0
         addAppKeys(list, defaultEnv, appId);
 86  
       }
 87  
       else
 88  
       {
 89  0
         list.add(new EnvAppConfigurationKey(defaultEnv, ApplicationId.ANY_APP));
 90  
       }
 91  
     }
 92  
 
 93  0
     addAppKeyNoEnv(list, appId);
 94  
 
 95  0
     final EnvAppConfigurationKey defaultKey =
 96  
         new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, ApplicationId.ANY_APP);
 97  0
     list.add(defaultKey);
 98  
 
 99  0
     return list;
 100  
   }
 101  
 
 102  
   private void addAppKeys(final List<ConfigurationKey<?>> list,
 103  
       final EnvironmentId envId, final ApplicationId appId)
 104  
     throws IllegalArgumentException, NullArgumentException
 105  
   {
 106  0
     if (appId.getVersion() != null)
 107  
     {
 108  0
       final ApplicationId defaultAppId =
 109  
           new ApplicationId(appId.getGroupId(), appId.getArtifactId(), null);
 110  0
       final EnvAppConfigurationKey defaultKey =
 111  
           new EnvAppConfigurationKey(envId, defaultAppId);
 112  0
       list.add(defaultKey);
 113  
     }
 114  
 
 115  0
     if (appId.getArtifactId() != null)
 116  
     {
 117  0
       final ApplicationId defaultAppId =
 118  
           new ApplicationId(appId.getGroupId(), null, null);
 119  0
       final EnvAppConfigurationKey defaultKey =
 120  
           new EnvAppConfigurationKey(envId, defaultAppId);
 121  0
       list.add(defaultKey);
 122  
     }
 123  
 
 124  0
     if (appId.getGroupId() != null)
 125  
     {
 126  0
       final EnvAppConfigurationKey defaultKey =
 127  
           new EnvAppConfigurationKey(envId, ApplicationId.ANY_APP);
 128  0
       list.add(defaultKey);
 129  
     }
 130  0
   }
 131  
 
 132  
   private void addAppKeyNoEnv(final List<ConfigurationKey<?>> list,
 133  
       final ApplicationId appId) throws NullArgumentException,
 134  
     IllegalArgumentException
 135  
   {
 136  0
     if (appId.getVersion() != null)
 137  
     {
 138  0
       final EnvAppConfigurationKey defaultAppKey =
 139  
           new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, appId);
 140  0
       list.add(defaultAppKey);
 141  
     }
 142  
 
 143  0
     if (appId.getArtifactId() != null)
 144  
     {
 145  0
       final ApplicationId noEnvAppId =
 146  
           new ApplicationId(appId.getGroupId(), appId.getArtifactId(), null);
 147  0
       final EnvAppConfigurationKey defaultAppKey =
 148  
           new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, noEnvAppId);
 149  0
       list.add(defaultAppKey);
 150  
     }
 151  
 
 152  0
     if (appId.getGroupId() != null)
 153  
     {
 154  0
       final ApplicationId noEnvAppId =
 155  
           new ApplicationId(appId.getGroupId(), null, null);
 156  0
       final EnvAppConfigurationKey defaultAppKey =
 157  
           new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, noEnvAppId);
 158  0
       list.add(defaultAppKey);
 159  
     }
 160  0
   }
 161  
 
 162  
   // --- object basics --------------------------------------------------------
 163  
 
 164  
 }