package com.kryptnostic.rhizome.core;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.hazelcast.core.HazelcastInstance;
import com.kryptnostic.rhizome.hazelcast.serializers.RhizomeUtils.Pods;
import com.kryptnostic.rhizome.pods.AsyncPod;
import com.kryptnostic.rhizome.pods.ConfigurationPod;
import com.kryptnostic.rhizome.pods.HazelcastPod;
import com.kryptnostic.rhizome.pods.hazelcast.RegistryBasedHazelcastInstanceConfigurationPod;

public class RhizomeApplicationServer {
    private final AnnotationConfigApplicationContext context     = new AnnotationConfigApplicationContext();;
    public static final Class<?>[]                   defaultPods = new Class<?>[] {
            RegistryBasedHazelcastInstanceConfigurationPod.class, HazelcastPod.class,
            AsyncPod.class, ConfigurationPod.class };

    public RhizomeApplicationServer( Class<?>... pods ) {
        this.context.register( Pods.concatenate( defaultPods, pods ) );
    }

    public void intercrop( Class<?>... pods ) {
        context.register( pods );
    }

    public void sprout( String... activeProfiles ) {
        for ( String activeProfile : activeProfiles ) {
            context.getEnvironment().addActiveProfile( activeProfile );
        }
        context.refresh();
        context.start();
    }

    public void plowUnder() {
        HazelcastInstance hazelcast = context.getBean( HazelcastInstance.class );
        if ( hazelcast != null ) {
            hazelcast.shutdown();
        }
        context.close();
    }

    public AnnotationConfigApplicationContext getContext() {
        return context;
    }
}

@@ -32,16 +32,60 @@
 .core;%0A%0A
+import org.apache.commons.lang.StringUtils;%0A
 import o
@@ -204,16 +204,94 @@
 stance;%0A
+import com.kryptnostic.rhizome.configuration.ConfigurationConstants.Profiles;%0A
 import c
@@ -1245,32 +1245,106 @@
 iveProfiles ) %7B%0A
+        boolean awsProfile = false;%0A        boolean localProfile = false;%0A
         for ( St
@@ -1347,16 +1347,26 @@
 ( String
+ profile :
  activeP
@@ -1375,30 +1375,292 @@
 file
- : activeProfiles
+s ) %7B%0A            if ( StringUtils.equals( Profiles.AWS_CONFIGURATION_PROFILE, profile ) ) %7B%0A                awsProfile = true;%0A            %7D%0A%0A            if ( StringUtils.equals( Profiles.LOCAL_CONFIGURATION_PROFILE, profile
  )
+ )
  %7B%0A
+                localProfile = true;%0A            %7D%0A%0A
     
@@ -1710,23 +1710,17 @@
 rofile( 
-activeP
+p
 rofile )
@@ -1735,35 +1735,160 @@
   %7D%0A
-        context.refresh(
+%0A        if ( !awsProfile && !localProfile ) %7B%0A            context.getEnvironment().addActiveProfile( Profiles.LOCAL_CONFIGURATION_PROFILE 
 );%0A
+        %7D%0A
     
@@ -1903,13 +1903,15 @@
 ext.
-start
+refresh
 ();%0A

Fix profile handling in app server