⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jrempropertymapper.java

📁 JRemoteControl is a simple Java&#8482 driven bluetooth remote control.It allows you to initiate virt
💻 JAVA
字号:
/* * JRemCntl - Copyright (C) 2007 Filippo Di Vattimo <fildiv@gmail.com> * See COPYING */package fildiv.jremcntl.server.core;import java.util.Collection;import java.util.Collections;import java.util.Hashtable;import java.util.Iterator;import java.util.Map;import fildiv.jremcntl.common.util.JRemUtils;public class JRemPropertyMapper {	protected static final short FIND_TYPE_INTNAME = 0;	protected static final short FIND_TYPE_XMLNAME = 1;	protected static final short FIND_TYPE_CLSNAME = 2;		private Map allPropertiesMap;	private Map objMap;		public static interface JRemPropertyValueMapper {		Object toCls(Object value); 		String toXml(Object value);	};		protected JRemPropertyMapper() {		allPropertiesMap = new Hashtable();		objMap = new Hashtable();			}	protected JRemPropertyMapper(Object propertiesArr[]) {		this();				final int columnCount = 4;		for (int index = 0; index < propertiesArr.length; 			index+= columnCount) {						String intPropName = (String) propertiesArr[index];			String xmlPropName = (String) propertiesArr[index + 1];			String clsPropName = (String) propertiesArr[index + 2];			JRemPropertyValueMapper pvm = (JRemPropertyValueMapper) 				propertiesArr[index + 3];			JRemProperty p = new JRemProperty(					intPropName, xmlPropName, 					clsPropName, pvm);								if (allPropertiesMap.get(intPropName) != null)				throw new IllegalArgumentException(						"Property (" + p.toString() + ") already registered");			allPropertiesMap.put(intPropName, p);		}	}		protected void registerProperty(String objName, JRemProperty property) {				if (allPropertiesMap.get(property) != null)			return;				String intPropName = property.getIntPropName();		allPropertiesMap.put(intPropName, property);				Map propertiesMap = getPropertiesMap(objName);		propertiesMap.put(intPropName, property);	}		protected JRemProperty getProperty(String objName) {				JRemProperty property = (JRemProperty) allPropertiesMap.get(objName);		if (property == null)			throw new IllegalArgumentException(					"The property '" + objName + "' was not defined");				return property;	}	protected Map getPropertiesMap(String objName) {				Map propertyMap = (Map) objMap.get(objName);		if (propertyMap == null)			propertyMap = new Hashtable();		objMap.put(objName, propertyMap);				return propertyMap;	}		protected void registerSupportedProperties(String objName, String[] propertyArr) {				if (propertyArr == null || JRemUtils.isEmptyString(objName))			throw new IllegalArgumentException();		Map propertiesMap = getPropertiesMap(objName);		for (int index = 0; index < propertyArr.length; ++index) {						String propertyName = propertyArr[index];						JRemProperty property = getProperty(propertyName);			propertiesMap.put(propertyName, property);		}			}	protected Collection getSupportedProperties(String objName) {				Map propertiesMap = getPropertiesMap(objName);				return Collections.unmodifiableCollection(				propertiesMap.values());	}	protected JRemProperty findProperty(String objName, String propValue, 			short findType) {		Collection c = getSupportedProperties(objName);				for (Iterator i = c.iterator(); i.hasNext(); ) {					JRemProperty p = (JRemProperty) i.next();			String value;						switch(findType) {			case FIND_TYPE_INTNAME:				value = p.getIntPropName();				break;			case FIND_TYPE_XMLNAME:				value = p.getXmlPropName();				break;			case FIND_TYPE_CLSNAME:				value = p.getClsPropName();				break;			default:				throw new IllegalArgumentException();			}						if (value.equals(propValue))				return p;		}		return null;	}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -