org.eclipse.swordfish.samples.configuration.ConfigurationProvider.java Source code

Java tutorial

Introduction

Here is the source code for org.eclipse.swordfish.samples.configuration.ConfigurationProvider.java

Source

/*******************************************************************************
 * Copyright (c) 2008, 2009 SOPERA GmbH.
 * 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:
 *     SOPERA GmbH - initial API and implementation
 *******************************************************************************/
package org.eclipse.swordfish.samples.configuration;

import java.text.DateFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swordfish.core.SwordfishContext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

public class ConfigurationProvider implements InitializingBean {

    private static final Log LOG = LogFactory.getLog(ConfigurationProvider.class);

    private SwordfishContext swordfishContext;
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setContext(SwordfishContext swordfishContext) {
        this.swordfishContext = swordfishContext;
    }

    public void afterPropertiesSet() throws Exception {
        Assert.notNull(id);
        final Map<String, Object> configData = new HashMap<String, Object>();
        configData.put("testProperty1", "Updated by ConfigurationProvider");
        configData.put("currentDateTime", DateFormat.getDateTimeInstance().format(new Date()));
        LOG.info("Updating configuration");
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                swordfishContext.getConfigurationService().updateConfiguration(id, configData);

            }
        }, 5000);

    }

}