Coverage Report - de.smartics.properties.spi.config.support.KeySetBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
KeySetBuilder
0%
0/43
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.spi.config.support;
 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.util.lang.NullArgumentException;
 25  
 
 26  
 /**
 27  
  * Explodes the key to its defaulting keys.
 28  
  */
 29  
 class KeySetBuilder
 30  
 {
 31  
   // ********************************* Fields *********************************
 32  
 
 33  
   // --- constants ------------------------------------------------------------
 34  
 
 35  
   // --- members --------------------------------------------------------------
 36  
 
 37  
   // ****************************** Initializer *******************************
 38  
 
 39  
   // ****************************** Constructors ******************************
 40  
 
 41  
   /**
 42  
    * Default constructor.
 43  
    */
 44  
   public KeySetBuilder()
 45  0
   {
 46  0
   }
 47  
 
 48  
   // ****************************** Inner Classes *****************************
 49  
 
 50  
   // ********************************* Methods ********************************
 51  
 
 52  
   // --- init -----------------------------------------------------------------
 53  
 
 54  
   // --- get&set --------------------------------------------------------------
 55  
 
 56  
   // --- business -------------------------------------------------------------
 57  
 
 58  
   public List<ConfigurationKey> createKeySet(final ConfigurationKey key)
 59  
   {
 60  0
     final List<ConfigurationKey> list = new ArrayList<ConfigurationKey>();
 61  0
     list.add(key);
 62  
 
 63  0
     final EnvironmentId envId = key.getEnvironmentId();
 64  0
     final ApplicationId appId = key.getApplicationId();
 65  
 
 66  0
     addAppKeys(list, envId, appId);
 67  
 
 68  0
     if (envId.getNode() != null)
 69  
     {
 70  0
       final EnvironmentId defaultEnv = new EnvironmentId(envId.getName());
 71  0
       if (!ApplicationId.ANY_APP.equals(appId))
 72  
       {
 73  0
         if (appId.getVersion() != null)
 74  
         {
 75  0
           final ConfigurationKey defaultKey =
 76  
               new ConfigurationKey(defaultEnv, appId);
 77  0
           list.add(defaultKey);
 78  
         }
 79  
 
 80  0
         addAppKeys(list, defaultEnv, appId);
 81  
       }
 82  
       else
 83  
       {
 84  0
         list.add(new ConfigurationKey(defaultEnv, ApplicationId.ANY_APP));
 85  
       }
 86  
     }
 87  
 
 88  0
     addAppKeyNoEnv(list, appId);
 89  
 
 90  0
     final ConfigurationKey defaultKey =
 91  
         new ConfigurationKey(EnvironmentId.ANY_ENV, ApplicationId.ANY_APP);
 92  0
     list.add(defaultKey);
 93  
 
 94  0
     return list;
 95  
   }
 96  
 
 97  
   private void addAppKeys(final List<ConfigurationKey> list,
 98  
       final EnvironmentId envId, final ApplicationId appId)
 99  
     throws IllegalArgumentException, NullArgumentException
 100  
   {
 101  0
     if (appId.getVersion() != null)
 102  
     {
 103  0
       final ApplicationId defaultAppId =
 104  
           new ApplicationId(appId.getGroupId(), appId.getArtifactId(), null);
 105  0
       final ConfigurationKey defaultKey =
 106  
           new ConfigurationKey(envId, defaultAppId);
 107  0
       list.add(defaultKey);
 108  
     }
 109  
 
 110  0
     if (appId.getArtifactId() != null)
 111  
     {
 112  0
       final ApplicationId defaultAppId =
 113  
           new ApplicationId(appId.getGroupId(), null, null);
 114  0
       final ConfigurationKey defaultKey =
 115  
           new ConfigurationKey(envId, defaultAppId);
 116  0
       list.add(defaultKey);
 117  
     }
 118  
 
 119  0
     if (appId.getGroupId() != null)
 120  
     {
 121  0
       final ConfigurationKey defaultKey =
 122  
           new ConfigurationKey(envId, ApplicationId.ANY_APP);
 123  0
       list.add(defaultKey);
 124  
     }
 125  0
   }
 126  
 
 127  
   private void addAppKeyNoEnv(final List<ConfigurationKey> list,
 128  
       final ApplicationId appId) throws NullArgumentException,
 129  
     IllegalArgumentException
 130  
   {
 131  0
     if (appId.getVersion() != null)
 132  
     {
 133  0
       final ConfigurationKey defaultAppKey =
 134  
           new ConfigurationKey(EnvironmentId.ANY_ENV, appId);
 135  0
       list.add(defaultAppKey);
 136  
     }
 137  
 
 138  0
     if (appId.getArtifactId() != null)
 139  
     {
 140  0
       final ApplicationId noEnvAppId =
 141  
           new ApplicationId(appId.getGroupId(), appId.getArtifactId(), null);
 142  0
       final ConfigurationKey defaultAppKey =
 143  
           new ConfigurationKey(EnvironmentId.ANY_ENV, noEnvAppId);
 144  0
       list.add(defaultAppKey);
 145  
     }
 146  
 
 147  0
     if (appId.getGroupId() != null)
 148  
     {
 149  0
       final ApplicationId noEnvAppId =
 150  
           new ApplicationId(appId.getGroupId(), null, null);
 151  0
       final ConfigurationKey defaultAppKey =
 152  
           new ConfigurationKey(EnvironmentId.ANY_ENV, noEnvAppId);
 153  0
       list.add(defaultAppKey);
 154  
     }
 155  0
   }
 156  
 
 157  
   // --- object basics --------------------------------------------------------
 158  
 
 159  
 }