package org.csstudio.utility.pv.simu;

import java.util.HashMap;
import java.util.Map;

import org.csstudio.utility.pv.IPVFactory;
import org.csstudio.utility.pv.PV;

/** PV Factory for simulated PVs
 *  @author Kay Kasemir
 */
@SuppressWarnings("nls")
public class SystemPVFactory implements IPVFactory
{
    /** PV type prefix */
    public static final String PREFIX = "sys";

    /** All the 'simulated' PVs, mapped by name */
    private static Map<String, Value> values =
        new HashMap<String, Value>();

    /** Create a 'dynamic' PV.
     *  @param name Name of the PV
     */
    public PV createPV(final String name)
    {
        Value value = values.get(name);
        if (value == null)
        {
            if (name.equals("time"))
                value = new TimeValue(name);
            else if (name.equals("free_mb"))
                value = new FreeMemValue(name);
            else if (name.equals("used_mb"))
                value = new UsedMemValue(name);
            else if (name.equals("max_mb"))
                value = new MaxMemValue(name);
            else if (name.equals("user"))
                value = new TextValue(name, System.getProperty("user.name"));
            else
                value = new TextValue(name,
                        "Unknown system property '" + name + "'", false);
            values.put(name, value);
        }
        if (value instanceof DynamicValue)
            return new SimulatedPV(PREFIX, (DynamicValue) value);
        return new StaticPV(PREFIX, value);
    }
}

@@ -32,16 +32,83 @@
 .simu;%0A%0A
+import java.net.InetAddress;%0Aimport java.net.UnknownHostException;%0A
 import j
@@ -1165,114 +1165,875 @@
 ame.
-equals(%22user%22))%0A                value = new TextValue(name, System.getProperty(%22user.name%22));%0A            
+startsWith(%22system.%22))%7B%0A            %09String prop = name.substring(7);%0A            %09String prop_value = System.getProperty(prop);%0A            %09if(prop_value != null)%0A            %09%09value = new TextValue(name, prop_value);%0A            %09else%0A            %09%09value = new TextValue(name,%0A                        %22Unknown system property '%22 + prop + %22'%22, false);%0A            %7D                %0A            else if (name.equals(%22host_name%22))%0A%09%09%09%09try %7B%0A%09%09%09%09%09value = new TextValue(name, InetAddress.getLocalHost().getHostName());%0A%09%09%09%09%7D catch (UnknownHostException e) %7B%0A%09%09%09%09%09value = new TextValue(name, %22Unknown Host%22, false);%0A%09%09%09%09%7D%0A%09%09%09else if (name.equals(%22qualified_host_name%22))%0A%09%09%09%09try %7B%0A%09%09%09%09%09value = new TextValue(name, InetAddress.getLocalHost().getCanonicalHostName());%0A%09%09%09%09%7D catch (UnknownHostException e) %7B%0A%09%09%09%09%09value = new TextValue(name, %22Unknown Host%22, false);%0A%09%09%09%09%7D%0A%09%09%09
 else

add some system properties