/**
 * Copyright (c) 2005-2008 Intalio inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Intalio inc. - initial API and implementation
 */
package org.intalio.tempo.deployment.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.intalio.tempo.deployment.DeploymentService;
import org.intalio.tempo.deployment.spi.DeploymentServiceCallback;
import org.intalio.tempo.registry.Registry;
import org.intalio.tempo.registry.RegistryFactory;
import org.springframework.util.SystemPropertyUtils;

/**
 * Utility class to lookup DeploymentService.
 */
public class DeploymentServiceLookup {
    public static final String DEFAULT_PROPERTY_FILE     = "${org.intalio.tempo.configDirectory}/tempo-deploy.properties";
    public static final String DEFAULT_DEPLOYMENT_SERVICE_NAME  = "DeploymentService";
    public static final String DEFAULT_DEPLOYMENT_CALLBACK_NAME = "DeploymentServiceCallback";

    public String  propertyFile = DEFAULT_PROPERTY_FILE;
    public String  deploymentServiceName  = DEFAULT_DEPLOYMENT_SERVICE_NAME;
    public String  deploymentCallbackName = DEFAULT_DEPLOYMENT_CALLBACK_NAME;

    private Registry _registry;
    
    /**
     * Default constructor.
     */
    public DeploymentServiceLookup() {
    }
    
    /**
     * Load configuration from properties file.
     */
    public void loadProperties() {
        RegistryFactory registryFactory = new RegistryFactory();
        registryFactory.init();
        _registry = registryFactory.getRegistry();
        
        String configFile = SystemPropertyUtils.resolvePlaceholders(propertyFile);
        try {
            Properties props = new Properties();
            if (new File(configFile).exists())
                props.load(new FileInputStream(configFile));
            deploymentServiceName = (String) props.getProperty("deployment.service.name", DEFAULT_DEPLOYMENT_SERVICE_NAME);
            deploymentCallbackName = (String) props.getProperty("deployment.callback.name", DEFAULT_DEPLOYMENT_CALLBACK_NAME);
        } catch (IOException except) {
            throw new RuntimeException(except);
        }
    }

    /**
     * Lookup DeploymentService via JNDI
     */
    public DeploymentService lookupDeploymentService() {
        return lookup(deploymentServiceName);
    }
    
    /**
     * Lookup DeploymentServiceCallback via JNDI
     */
    public DeploymentServiceCallback lookupDeploymentCallback() {
        return lookup(deploymentCallbackName);
    }
    
    /**
     * Lookup an object via JNDI
     */
    @SuppressWarnings("unchecked")
    private <T> T lookup(String name) {
        return (T) _registry.lookup(name, getClass().getClassLoader());
    }
    
}

@@ -757,62 +757,8 @@
 ry;%0D
-%0Aimport org.springframework.util.SystemPropertyUtils;%0D
 %0A%0D%0A/
@@ -1811,16 +1811,23 @@
 gFile = 
+resolve
 SystemPr
@@ -1835,33 +1835,10 @@
 pert
-yUtils.resolvePlaceholder
+ie
 s(pr
@@ -2965,23 +2965,660 @@
 r());%0D%0A    %7D
-%0D
+%0A%0A    private static String resolveSystemProperties(String str) %7B%0A        int fromIndex = 0;%0A        while (true) %7B%0A            int start = str.indexOf(%22$%7B%22, fromIndex);%0A            if (start %3C 0) break;%0A            int end = str.indexOf(%22%7D%22, start);%0A            if (end %3C 0) break;%0A            String replace = str.substring(start, end+1);%0A            String key = str.substring(start+2, end);%0A            String value = System.getProperty(key);%0A            if (value != null) %7B%0A                str = str.replace(replace, value);%0A            %7D else %7B%0A                fromIndex = start+2;%0A            %7D%0A        %7D%0A        return str;%0A    %7D
 %0A    %0D%0A%7D%0D%0A

Remove dependency on Spring