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

📄 markupcontainer.java

📁 Wicket一个开发Java Web应用程序框架。它使得开发web应用程序变得容易而轻松。 Wicket利用一个POJO data beans组件使得它可以与任何持久层技术相结合。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			return 0;		}		else if (children instanceof Object[])		{			final Object[] children = (Object[])this.children;			for (int i = 0; i < children.length; i++)			{				if (getId(children[i]).equals(child.getId()))				{					return i;				}			}		}		return -1;	}	private final Component children_remove(Component component)	{		int index = children_indexOf(component);		if (index != -1)		{			return children_remove(index);		}		return null;	}	private final Component children_remove(int index)	{		if (children instanceof Component || children instanceof ComponentSourceEntry)		{			if (index == 0)			{				final Component removed = (Component)postprocess(children, true, null, -1);				children = null;				return removed;			}			else			{				throw new IndexOutOfBoundsException();			}		}		else		{			Object[] c = ((Object[])children);			final Object removed = c[index];			if (c.length == 2)			{				if (index == 0)				{					children = c[1];				}				else if (index == 1)				{					children = c[0];				}				else				{					throw new IndexOutOfBoundsException();				}			}			else			{				Object[] newChildren = new Object[c.length - 1];				int j = 0;				for (int i = 0; i < c.length; i++)				{					if (i != index)					{						newChildren[j++] = c[i];					}				}				children = newChildren;			}			return (Component)postprocess(removed, true, null, -1);		}	}	private final Object children_set(int index, Object child, boolean reconstruct)	{		Object replaced;		if (index < children_size())		{			if (children == null || children instanceof Component ||				children instanceof ComponentSourceEntry)			{				replaced = children;				children = child;			}			else			{				final Object[] children = (Object[])this.children;				replaced = children[index];				children[index] = child;			}		}		else		{			throw new IndexOutOfBoundsException();		}		return postprocess(replaced, reconstruct, null, -1);	}	private final Component children_set(int index, Component child)	{		return (Component)children_set(index, child, true);	}	private final int children_size()	{		if (children == null)		{			return 0;		}		else		{			if (children instanceof Component || children instanceof ComponentSourceEntry)			{				return 1;			}			return ((Object[])children).length;		}	}	/**	 * Ensure that there is space in childForId map for a new entry before adding it.	 * 	 * @param child	 *            The child to put into the map	 * @return Any component that was replaced	 */	private final Component put(final Component child)	{		int index = children_indexOf(child);		if (index == -1)		{			children_add(child);			return null;		}		else		{			return children_set(index, child);		}	}	/**	 * @param component	 *            Component being removed	 */	private final void removedComponent(final Component component)	{		// Notify Page that component is being removed		final Page page = component.findPage();		if (page != null)		{			page.componentRemoved(component);		}		component.detach();		// Component is removed		component.setParent(null);	}	/**	 * Renders the next element of markup in the given markup stream.	 * 	 * @param markupStream	 *            The markup stream	 */	private final void renderNext(final MarkupStream markupStream)	{		// Get the current markup element		final MarkupElement element = markupStream.get();		// If it a tag like <wicket..> or <span wicket:id="..." >		if ((element instanceof ComponentTag) && !markupStream.atCloseTag())		{			// Get element as tag			final ComponentTag tag = (ComponentTag)element;			// Get component id			final String id = tag.getId();			// Get the component for the id from the given container			final Component component = get(id);			// Failed to find it?			if (component != null)			{				component.render(markupStream);			}			else			{				// 2rd try: Components like Border and Panel might implement				// the ComponentResolver interface as well.				MarkupContainer container = this;				while (container != null)				{					if (container instanceof IComponentResolver)					{						if (((IComponentResolver)container).resolve(this, markupStream, tag))						{							return;						}					}					container = container.findParent(MarkupContainer.class);				}				// 3rd try: Try application's component resolvers				final List componentResolvers = getApplication().getPageSettings()					.getComponentResolvers();				final Iterator iterator = componentResolvers.iterator();				while (iterator.hasNext())				{					final IComponentResolver resolver = (IComponentResolver)iterator.next();					if (resolver.resolve(this, markupStream, tag))					{						return;					}				}				if (tag instanceof WicketTag)				{					if (((WicketTag)tag).isChildTag())					{						markupStream.throwMarkupException("Found " + tag.toString() +							" but no <wicket:extend>");					}					else					{						markupStream.throwMarkupException("Failed to handle: " + tag.toString());					}				}				// No one was able to handle the component id				markupStream.throwMarkupException("Unable to find component with id '" + id +					"' in " + this + ". This means that you declared wicket:id=" + id +					" in your markup, but that you either did not add the " +					"component to your page at all, or that the hierarchy does not match.");			}		}		else		{			// Render as raw markup			if (log.isDebugEnabled())			{				log.debug("Rendering raw markup");			}			getResponse().write(element.toCharSequence());			markupStream.next();		}	}	/**	 * Get the markup stream for this component.	 * 	 * @return The markup stream for this component, or if it doesn't have one, the markup stream	 *         for the nearest parent which does have one	 */	protected final MarkupStream findMarkupStream()	{		// Start here		MarkupContainer c = this;		// Walk up hierarchy until markup found		while (c.getMarkupStream() == null)		{			// Check parent			c = c.getParent();			// Are we at the top of the hierarchy?			if (c == null)			{				// Failed to find markup stream				throw new WicketRuntimeException(exceptionMessage("No markup found"));			}		}		return c.getMarkupStream();	}	/**	 * Handle the container's body. If your override of this method does not advance the markup	 * stream to the close tag for the openTag, a runtime exception will be thrown by the framework.	 * 	 * @param markupStream	 *            The markup stream	 * @param openTag	 *            The open tag for the body	 */	protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)	{		renderComponentTagBody(markupStream, openTag);	}	/**	 * Renders this component. This implementation just calls renderComponent.	 * 	 * @param markupStream	 */	protected void onRender(final MarkupStream markupStream)	{		renderComponent(markupStream);	}	/**	 * Renders this component and all sub-components using the given markup stream.	 * 	 * @param markupStream	 *            The markup stream	 */	protected void renderAll(final MarkupStream markupStream)	{		// Loop through the markup in this container		while (markupStream.hasMore())		{			// Element rendering is responsible for advancing markup stream!			final int index = markupStream.getCurrentIndex();			renderNext(markupStream);			if (index == markupStream.getCurrentIndex())			{				markupStream.throwMarkupException("Component at markup stream index " + index +					" failed to advance the markup stream");			}		}	}	/**	 * Renders markup for the body of a ComponentTag from the current position in the given markup	 * stream. If the open tag passed in does not require a close tag, nothing happens. Markup is	 * rendered until the closing tag for openTag is reached.	 * 	 * @param markupStream	 *            The markup stream	 * @param openTag	 *            The open tag	 */	protected final void renderComponentTagBody(final MarkupStream markupStream,		final ComponentTag openTag)	{		// If the open tag requires a close tag		boolean render = openTag.requiresCloseTag();		if (render == false)		{			// Tags like <p> do not require a close tag, but they may have.			render = !openTag.hasNoCloseTag();		}		if (render == true)		{			// Loop through the markup in this container			while (markupStream.hasMore() && !markupStream.get().closes(openTag))			{				// Render markup element. Doing so must advance the markup				// stream				final int index = markupStream.getCurrentIndex();				renderNext(markupStream);				if (index == markupStream.getCurrentIndex())				{					markupStream.throwMarkupException("Markup element at index " + index +						" failed to advance the markup stream");				}			}		}	}	/**	 * Set markup stream for this container.	 * 	 * @param markupStream	 *            The markup stream	 */	protected final void setMarkupStream(final MarkupStream markupStream)	{		this.markupStream = markupStream;	}	private static class ComponentSourceEntry extends org.apache.wicket.ComponentSourceEntry	{		private ComponentSourceEntry(MarkupContainer container, Component component,			IComponentSource componentSource)		{			super(container, component, componentSource);		}		private static final long serialVersionUID = 1L;		protected void setChild(MarkupContainer parent, int index, Component child)		{			parent.children_set(index, child, false);		}	}	void detachChildren()	{		super.detachChildren();		for (int i = children_size(); i-- > 0;)		{			Object child = children_get(i, false);			if (child instanceof Component)			{				Component component = (Component)child;				component.detach();				if (child instanceof IComponentSourceProvider)				{					ComponentSourceEntry entry = new ComponentSourceEntry(this, component,						((IComponentSourceProvider)child).getComponentSource());					children_set(i, entry, false);				}				else if (component.isAuto())				{					children_remove(i);				}			}		}	}	void internalMarkRendering()	{		super.internalMarkRendering();		final int size = children_size();		for (int i = 0; i < size; i++)		{			final Component child = children_get(i);			child.internalMarkRendering();		}	}	private Component[] copyChildren()	{		int size = children_size();		Component result[] = new Component[size];		for (int i = 0; i < size; ++i)		{			result[i] = children_get(i);		}		return result;	}	void onBeforeRenderChildren()	{		super.onBeforeRenderChildren();		// We need to copy the children list because the children components can		// modify the hierarchy in their onBeforeRender.		Component[] children = copyChildren();		try		{			// Loop through child components			for (int i = 0; i < children.length; i++)			{				// Get next child				final Component child = children[i];				// Call begin request on the child				// We need to check whether the child's wasn't removed from the				// component in the meanwhile (e.g. from another's child				// onBeforeRender)				if (child.getParent() == this)				{					child.beforeRender();				}			}		}		catch (RuntimeException ex)		{			if (ex instanceof WicketRuntimeException)			{				throw ex;			}			else			{				throw new WicketRuntimeException("Error attaching this container for rendering: " +					this, ex);			}		}	}	void onAfterRenderChildren()	{		// Loop through child components		final Iterator iter = iterator();		while (iter.hasNext())		{			// Get next child			final Component child = (Component)iter.next();			// Call end request on the child			child.afterRender();		}		super.onAfterRenderChildren();	}	/**	 * @return True if this markup container has associated markup	 */	public boolean hasAssociatedMarkup()	{		return getApplication().getMarkupSettings().getMarkupCache().hasAssociatedMarkup(this);	}	/**	 * @see org.apache.wicket.Component#setRenderAllowed()	 */	void setRenderAllowed()	{		super.setRenderAllowed();		visitChildren(new IVisitor()		{			public Object component(final Component component)			{				// Find out if this component can be rendered				final boolean renderAllowed = component.isActionAuthorized(RENDER);				// Authorize rendering				component.setRenderAllowed(renderAllowed);				return IVisitor.CONTINUE_TRAVERSAL;			}		});	}}

⌨️ 快捷键说明

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