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

📄 componentdefinitionmap.java

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JAVA
字号:
/* ComponentDefinitionMap.java{{IS_NOTE	Purpose:			Description:			History:		Mon Sep  4 20:20:36     2006, Created by tomyeh}}IS_NOTECopyright (C) 2006 Potix Corporation. All Rights Reserved.{{IS_RIGHT	This program is distributed under GPL Version 2.0 in the hope that	it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.zk.ui.metainfo;import java.util.Map;import java.util.HashMap;import java.util.Collection;import java.util.Collections;import java.util.Iterator;/** * A map of component definitions. * Used with {@link PageDefinition#getComponentDefinitionMap} * and {@link LanguageDefinition}. * * <p>It is thread-safe (since it is used in {@link LanguageDefinition}). * * @author tomyeh */public class ComponentDefinitionMapimplements Cloneable, java.io.Serializable {	/** A map of component definition defined in this page. */	private transient Map _compdefs;	/** Map(String clsnm, ComponentDefinition compdef). */	private transient Map _compdefsByClass;	/** Whether the element name is case-insensitive. */	private final boolean _ignoreCase;	/** Constructor.	 */	public ComponentDefinitionMap(boolean ignoreCase) {		_ignoreCase = ignoreCase;	}	/** Returns whether the component names are case-insensitive.	 */	public boolean isCaseInsensitive() {		return _ignoreCase;	}	/** Returns a collection of component definitions, {@link ComponentDefinition},	 *  defined in this map.	 */	public Collection getNames() {		return _compdefs != null ?			_compdefs.keySet(): (Collection)Collections.EMPTY_LIST;	}	/** Adds a component definition to this map.	 *	 * <p>Thread safe.	 */	public void add(ComponentDefinition compdef) {		if (compdef == null)			throw new IllegalArgumentException("null");		String name = compdef.getName();		if (isCaseInsensitive())			name = name.toLowerCase();		Object implcls = compdef.getImplementationClass();		if (implcls instanceof Class)			implcls = ((Class)implcls).getName();		synchronized (this) {			if (_compdefs == null) {				_compdefsByClass =					Collections.synchronizedMap(new HashMap(3));				_compdefs =					Collections.synchronizedMap(new HashMap(3));			}			_compdefs.put(name, compdef);			_compdefsByClass.put(implcls, compdef);		}	}	/** Returns whether the specified component exists.	 */	public boolean contains(String name) {		return _compdefs != null			&& _compdefs.containsKey(				isCaseInsensitive() ? name.toLowerCase(): name);	}	/** Returns the component definition of the specified name, or null if not	 * not found.	 *	 * <p>Note: unlike {@link LanguageDefinition#getComponentDefinition},	 * this method doesn't throw ComponentNotFoundException if not found.	 * It just returns null.	 */	public ComponentDefinition get(String name) {		return _compdefs != null ?			(ComponentDefinition)_compdefs.get(				isCaseInsensitive() ? name.toLowerCase(): name):			null;	}	/** Returns the component definition of the specified class, or null if not	 * found.	 *	 * <p>Note: unlike {@link LanguageDefinition#getComponentDefinition},	 * this method doesn't throw ComponentNotFoundException if not found.	 * It just returns null.	 */	public ComponentDefinition get(Class cls) {		if (_compdefsByClass != null) {			for (; cls != null; cls = cls.getSuperclass()) {				final ComponentDefinition compdef =					(ComponentDefinition)_compdefsByClass.get(cls.getName());				if (compdef != null)					return compdef;			}		}		return null;	}	//Serializable//	//NOTE: they must be declared as private	private synchronized void writeObject(java.io.ObjectOutputStream s)	throws java.io.IOException {		s.defaultWriteObject();		if (_compdefs != null) {			synchronized (_compdefs) {				s.writeInt(_compdefs.size());				for (Iterator it = _compdefs.values().iterator(); it.hasNext();)					s.writeObject(it.next());			}		} else {			s.writeInt(0);		}	}	private synchronized void readObject(java.io.ObjectInputStream s)	throws java.io.IOException, ClassNotFoundException {		s.defaultReadObject();		int cnt = s.readInt();		while (--cnt >= 0)			add((ComponentDefinition)s.readObject());	}	//Cloneable//	public Object clone() {		final ComponentDefinitionMap clone;		try {			clone = (ComponentDefinitionMap)super.clone();			clone._compdefs =				Collections.synchronizedMap(new HashMap(_compdefs));			clone._compdefsByClass =				Collections.synchronizedMap(new HashMap(_compdefsByClass));		} catch (CloneNotSupportedException ex) {			throw new InternalError();		}		return clone;	}}

⌨️ 快捷键说明

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