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

📄 componentinfo.java

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 *	 * @param page the page. It is used only if comp is null.	 * @param comp the component.	 * @return the forEach object to iterate this info multiple times,	 * or null if this info shall be interpreted only once.	 */	public ForEach getForEach(Page page, Component comp) {		return _forEach == null ? null:			comp != null ?				ForEachImpl.getInstance(					_evalr, comp, _forEach[0], _forEach[1], _forEach[2]):				ForEachImpl.getInstance(					_evalr, page, _forEach[0], _forEach[1], _forEach[2]);	}	/** Sets the forEach attribute, which is usually an expression.	 * @param expr the expression to return a collection of objects, or	 * null/empty to denote no iteration.	 */	public void setForEach(String expr, String begin, String end) {		_forEach = expr != null && expr.length() > 0 ?			new String[] {expr, begin, end}: null;	}	/** Returns whether the forEach condition is defined.	 * @since 3.0.0	 */	public boolean withForEach() {		return _forEach != null;	}	/** Returns the class name (String) that implements the component.	 */	public String getImplementationClass() {		return _implcls;	}	/** Sets the class name to implements the component.	 */	public void setImplementationClass(String clsnm) {		_implcls = clsnm;	}	/** Creates an component based on this info (never null).	 *	 * <p>Like {@link ComponentDefinition#newInstance},	 * this method doesn't invoke {@link #applyProperties}.	 * It is caller's job to invoke them if necessary.	 * Since the value of properties might depend on the component tree,	 * it is better to assign the component with a proper parent	 * before calling {@link #applyProperties}.	 */	public Component newInstance(Page page) {		ComponentsCtrl.setCurrentInfo(this);		final Component comp;		try {			comp = _compdef.newInstance(page, _implcls);		} catch (Exception ex) {			throw UiException.Aide.wrap(ex);		} finally {			ComponentsCtrl.setCurrentInfo((ComponentInfo)null);		}		if (comp instanceof DynamicTag)			((DynamicTag)comp).setTag(_tag);		return comp;	}	/** Resolves and returns the class for the component represented	 * by this info (never null).	 *	 * <p>Unlike {@link #getImplementationClass},	 * this method will resolve a class name (String) to a class (Class),	 * if necessary.	 *	 * @param page the page to check whether the class is defined	 * in its interpreters. Ignored if null.	 * This method will search the class loader of the current thread.	 * If not found, it will search the interpreters of the specifed	 * page ({@link Page#getLoadedInterpreters}).	 * Note: this method won't attach the component to the specified page.	 * @exception ClassNotFoundException if the class not found	 * @since 3.0.0	 */	public Class resolveImplementationClass(Page page)	throws ClassNotFoundException {		return _compdef.resolveImplementationClass(page, _implcls);	}	/** Returns the annotation map defined in this info, or null	 * if no annotation is ever defined.	 */	public AnnotationMap getAnnotationMap() {		return _annots;	}	/** Applies the event handlers, annotations, properties and	 * custom attributes to the specified component.	 *	 * <p>It also invokes {@link ComponentDefinition#applyProperties}.	 *	 * @since 3.0.0	 */	public void applyProperties(Component comp) {		_compdef.applyProperties(comp);		if (_evthds != null)			((ComponentCtrl)comp).addSharedEventHandlerMap(_evthds);		if (_props != null) {			for (Iterator it = _props.iterator(); it.hasNext();) {				final Property prop = (Property)it.next();				prop.assign(comp);			}		}	}	/** Evaluates and retrieves properties to the specified map from	 * {@link ComponentDefinition} (and {@link ComponentInfo}).	 *	 * @param propmap the map to store the retrieved properties	 * (String name, Object value).	 * If null, a HashMap instance is created.	 * @param owner the owner page; used if parent is null	 * @param parent the parent component (may be null)	 * @param defIncluded whether to call {@link ComponentDefinition#evalProperties}.	 */	public Map evalProperties(Map propmap, Page owner, Component parent,	boolean defIncluded) {		if (defIncluded)			propmap = _compdef.evalProperties(propmap, owner, parent);		else if (propmap == null)			propmap = new HashMap();		if (_props != null) {			for (Iterator it = _props.iterator(); it.hasNext();) {				final Property prop = (Property)it.next();				if (parent != null) {					if (prop.isEffective(parent))						propmap.put(prop.getName(), prop.getValue(parent));				} else {					if (prop.isEffective(owner))						propmap.put(prop.getName(), prop.getValue(owner));				}			}		}		return propmap;	}	/** Associates an annotation to this component info.	 *	 * @param annotName the annotation name (never null, nor empty).	 * @param annotAttrs a map of attributes, or null if no attribute at all.	 * The attribute must be in a pair of strings (String name, String value).	 */	public void addAnnotation(String annotName, Map annotAttrs) {		if (_annots == null)			_annots = new AnnotationMap();		_annots.addAnnotation(annotName, annotAttrs);	}	/** Adds an annotation to the specified proeprty of this component	 * info.	 *	 * @param propName the property name (never nul, nor empty).	 * @param annotName the annotation name (never null, nor empty).	 * @param annotAttrs a map of attributes, or null if no attribute at all.	 * The attribute must be in a pair of strings (String name, String value).	 */	public void addAnnotation(String propName, String annotName, Map annotAttrs) {		if (_annots == null)			_annots = new AnnotationMap();		_annots.addAnnotation(propName, annotName, annotAttrs);	}	//Condition//	public boolean isEffective(Component comp) {		return _cond == null || _cond.isEffective(_evalr, comp);	}	public boolean isEffective(Page page) {		return _cond == null || _cond.isEffective(_evalr, page);	}	//NodeInfo//	public PageDefinition getPageDefinition() {		return _evalr.getPageDefinition();	}	public NodeInfo getParent() {		return _parent;	}	protected EvaluatorRef getEvaluatorRef() {		return _evalr;	}	//Cloneable//	/** Clones this info.	 * After cloned, {@link #getParent} is null.	 */	public Object clone() {		try {			final ComponentInfo info = (ComponentInfo)super.clone();			info._parent = null;			if (_annots != null)				info._annots = (AnnotationMap)_annots.clone();			if (_props != null)				info._props = new LinkedList(_props);			if (_evthds != null)				info._evthds = (EventHandlerMap)_evthds.clone();			return info;		} catch (CloneNotSupportedException ex) {			throw new InternalError();		}	}	//Object//	public String toString() {		final StringBuffer sb = new StringBuffer(64)			.append("[ComponentInfo: ")			.append(_compdef.getName());		if (_tag != null)			sb.append(" <").append(_tag).append('>');		return sb.append(']').toString();	}	//Externalizable//	public final void writeExternal(java.io.ObjectOutput out)	throws java.io.IOException {		if (getSerializingEvalRef() != _evalr) {			pushSerializingEvalRef(_evalr);			try {				out.writeObject(_evalr);				writeMembers(out);			} finally {				popSerializingEvalRef();			}		} else {			out.writeObject(null); //to save space, don't need to write evalr			writeMembers(out);		}	}	/** Don't override this method. Rather, override {@link #readMembers}.	 * @since 3.0.0	 */	public final void readExternal(java.io.ObjectInput in)	throws java.io.IOException, ClassNotFoundException {		_evalr = (EvaluatorRef)in.readObject();		final EvaluatorRef top = getSerializingEvalRef();		if (_evalr == null)			_evalr = top;		if (_evalr != null &&  top != _evalr) {			pushSerializingEvalRef(_evalr);			try {				readMembers(in);			} finally {				popSerializingEvalRef();			}		} else {			readMembers(in);		}	}	private void writeMembers(java.io.ObjectOutput out)	throws java.io.IOException {		out.writeObject(_children);		out.writeObject(_compdef);		out.writeObject(_implcls);		out.writeObject(_props);		out.writeObject(_evthds);		out.writeObject(_annots);		out.writeObject(_tag);		out.writeObject(_cond);		out.writeObject(_fulfill);		out.writeObject(_apply);		out.writeObject(_forward);		out.writeObject(_forEach);	}	private void readMembers(java.io.ObjectInput in)	throws java.io.IOException, ClassNotFoundException {		_children = (List)in.readObject();		for (Iterator it = _children.iterator(); it.hasNext();) {			final Object o = it.next();			if (o instanceof ComponentInfo)				((ComponentInfo)o).setParentDirectly(this);		}		_compdef = (ComponentDefinition)in.readObject();		_implcls = (String)in.readObject();		_props = (List)in.readObject();		_evthds = (EventHandlerMap)in.readObject();		_annots = (AnnotationMap)in.readObject();		_tag = (String)in.readObject();		_cond = (ConditionImpl)in.readObject();		_fulfill = (String)in.readObject();		_apply = (ExValue)in.readObject();		_forward = (String)in.readObject();		_forEach = (String[])in.readObject();	}	/** Writes the evaluator reference.	 * It is called by {@link EvalRefStub} to serialize	 * the evaluator reference, in order to minimize the number of bytes	 * to serialize.	 */	/*package*/ static final	void writeEvalRef(java.io.ObjectOutputStream s, EvaluatorRef evalr)	throws java.io.IOException {		s.writeObject(getSerializingEvalRef() != evalr ? evalr: null);	}	/*package*/ static final	EvaluatorRef readEvalRef(java.io.ObjectInputStream s)	throws java.io.IOException, ClassNotFoundException {		final EvaluatorRef evalr = (EvaluatorRef)s.readObject();		return evalr != null ? evalr: getSerializingEvalRef();	}	/** Returns the evaluator reference of the info that is being serialized.	 * It is used to minimize the bytes to write when serialized.	 */	private static final EvaluatorRef getSerializingEvalRef() {		final List stack = (List)_evalRefStack.get();		return stack == null || stack.isEmpty() ? null: (EvaluatorRef)stack.get(0);	}	/** Pushes the sepcified evaluator referene to be the current one.	 */	private static final void pushSerializingEvalRef(EvaluatorRef evalr) {		List stack = (List)_evalRefStack.get();		if (stack == null)			_evalRefStack.set(stack = new LinkedList());		stack.add(0, evalr);	}	/** Pops out the current evaluator reference.	 */	private static final void popSerializingEvalRef() {		((List)_evalRefStack.get()).remove(0);	}	private static final ThreadLocal _evalRefStack = new ThreadLocal();	/** A composer to invoke a collection of other composers.	 */	private static class MultiComposer implements Composer, ComposerExt {		private final Composer[] _cs;		private MultiComposer(Object[] cs) throws Exception {			if (cs instanceof Composer[]) {				_cs = (Composer[])cs;			} else {				_cs = new Composer[cs.length];				for (int j = cs.length; --j >=0;) {					final Object o = cs[j];					_cs[j] = (Composer)(						o instanceof String ?							Classes.newInstanceByThread(((String)o).trim()):						o instanceof Class ?							((Class)o).newInstance(): (Composer)o);				}			}		}		public void doAfterCompose(Component comp) throws Exception {			for (int j = 0; j < _cs.length; ++j)				_cs[j].doAfterCompose(comp);		}		public ComponentInfo doBeforeCompose(Page page, Component parent,		ComponentInfo compInfo) {			for (int j = 0; j < _cs.length; ++j)				if (_cs[j] instanceof ComposerExt) {					compInfo = ((ComposerExt)_cs[j])						.doBeforeCompose(page, parent, compInfo);					if (compInfo == null)						return null;				}			return compInfo;		}		public void doBeforeComposeChildren(Component comp) throws Exception {			for (int j = 0; j < _cs.length; ++j)				if (_cs[j] instanceof ComposerExt)					((ComposerExt)_cs[j]).doBeforeComposeChildren(comp);		}		public boolean doCatch(Throwable ex) throws Exception {			for (int j = 0; j < _cs.length; ++j)				if (_cs[j] instanceof ComposerExt)					if (((ComposerExt)_cs[j]).doCatch(ex))						return true; //caught (eat it)			return false;		}		public void doFinally() throws Exception {			for (int j = 0; j < _cs.length; ++j)				if (_cs[j] instanceof ComposerExt)					((ComposerExt)_cs[j]).doFinally();		}	}}

⌨️ 快捷键说明

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