/*
 * Created on Oct 24, 2003
 */
package xal.smf.proxy;

import java.util.*;

import xal.smf.AcceleratorNode;
import xal.smf.impl.Electromagnet;
import xal.ca.Channel;


/**
 * Access property values for a node
 * @author Tom Pelaia
 */
abstract public class AbstractPropertyAccessor implements PropertyAccessor {
	/** Get the scale factor for the specified property */
	protected double getPropertyScale( final String propertyName ) {
		return 1.0;
	}


	/** get the map of design values keyed by property name */
	protected Map<String,Double> getDesignValueMap( final AcceleratorNode node, final List<String> propertyNames ) {
		final Electromagnet magnet = (Electromagnet)node;

		final Map<String,Double> valueMap = new HashMap<String,Double>();
		for( final String propertyName : propertyNames	) {
			final double scale = getPropertyScale( propertyName );
			final double value = scale * magnet.getDesignPropertyValue( propertyName );
			valueMap.put( propertyName, value );
		}
		
		return valueMap;
	}

	
	/** get the map of live values keyed by property name */
	protected Map<String,Double> getLiveValueMap( final AcceleratorNode node, final Map<Channel,Double> channelValues, final List<String> propertyNames ) {
		final Map<String,Double> valueMap = new HashMap<String,Double>();
		for( final String propertyName : propertyNames	) {
			final Channel[] propertyChannels = node.getLivePropertyChannels( propertyName );
			final double[] propertyChannelValues = new double[propertyChannels.length];
			for ( int index = 0 ; index < propertyChannels.length ; index++ ) {
				final Channel channel = propertyChannels[index];
				propertyChannelValues[index] = channelValues.get( channel );
			}
			final double scale = getPropertyScale( propertyName );
			final double propertyValue = scale * node.getLivePropertyValue( propertyName, propertyChannelValues );
			valueMap.put( propertyName, propertyValue );
		}

		return valueMap;
	}


	/** get the channels for live property access */
	protected Collection<Channel> getLiveChannels( final AcceleratorNode node, final List<String> propertyNames ) {
		final Electromagnet magnet = (Electromagnet)node;
		final Set<Channel> channels = new HashSet<Channel>();

		for( final String propertyName : propertyNames	) {
			final Channel[] propertyChannels = node.getLivePropertyChannels( propertyName );
			for ( final Channel channel : propertyChannels ) {
				channels.add( channel );
			}
		}

		return channels;
	}
}

@@ -108,43 +108,8 @@
 de;%0A
-import xal.smf.impl.Electromagnet;%0A
 impo
@@ -592,61 +592,8 @@
 ) %7B%0A
-%09%09final Electromagnet magnet = (Electromagnet)node;%0A%0A
 %09%09fi
@@ -799,22 +799,20 @@
 scale * 
-magnet
+node
 .getDesi
@@ -2013,60 +2013,8 @@
 ) %7B%0A
-%09%09final Electromagnet magnet = (Electromagnet)node;%0A
 %09%09fi

Remove casts to Electromagnet in the AbstractPropertyAccessor as the node can be any subclass.