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

📄 uicomponentbase.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package javax.faces.component;import javax.faces.FactoryFinder;import javax.faces.context.FacesContext;import javax.faces.el.ValueBinding;import javax.faces.event.AbortProcessingException;import javax.faces.event.FacesEvent;import javax.faces.event.FacesListener;import javax.faces.render.RenderKit;import javax.faces.render.RenderKitFactory;import javax.faces.render.Renderer;import java.io.IOException;import java.io.Serializable;import java.lang.reflect.Array;import java.util.*;/** * see Javadoc of JSF Specification * * @author Manfred Geiler (latest modification by $Author: matzew $) * @version $Revision: 1.15 $ $Date: 2005/03/20 17:26:37 $ * $Log: UIComponentBase.java,v $ * Revision 1.15  2005/03/20 17:26:37  matzew * Component identifiers must obey the following syntax restrictions: * *     * Must not be a zero-length String. *     * First character must be a letter or an underscore ('_'). *     * Subsequent characters must be a letter, a digit, an underscore ('_'), or a dash ('-'). * * For more see JSF spec. * * Revision 1.14  2004/12/27 04:11:11  mmarinschek * Data Table stores the state of facets of children; script tag is rendered with type attribute instead of language attribute, popup works better as a column in a data table * * Revision 1.13  2004/08/27 10:45:55  manolito * log a warning when getClientId implicitly creates a component id * * Revision 1.12  2004/07/01 22:00:50  mwessendorf * ASF switch * * Revision 1.11  2004/05/03 10:28:03  manolito * getClientId automatically creates id now * */public abstract class UIComponentBase        extends UIComponent{    private _ComponentAttributesMap _attributesMap = null;    private Map _valueBindingMap = null;    private List _childrenList = null;    private Map _facetMap = null;    private List _facesListeners = null;    private String _clientId = null;    private String _id = null;    private UIComponent _parent = null;    private boolean _transient = false;    public UIComponentBase()    {    }    public Map getAttributes()    {        if (_attributesMap == null)        {            _attributesMap = new _ComponentAttributesMap(this);        }        return _attributesMap;    }    public ValueBinding getValueBinding(String name)    {        if (name == null) throw new NullPointerException("name");        if (_valueBindingMap == null)        {            return null;        }        else        {            return (ValueBinding)_valueBindingMap.get(name);        }    }    public void setValueBinding(String name,                                ValueBinding binding)    {        if (name == null) throw new NullPointerException("name");        if (_valueBindingMap == null)        {            _valueBindingMap = new HashMap();        }        _valueBindingMap.put(name, binding);    }    /**     * @param context     * @return     */    public String getClientId(FacesContext context)    {        if (context == null) throw new NullPointerException("context");                         if (_clientId != null) return _clientId;        boolean idWasNull = false;        String id = getId();        if (id == null)        {            //Although this is an error prone side effect, we automatically create a new id            //just to be compatible to the RI            UIViewRoot viewRoot = context.getViewRoot();            if (viewRoot != null)            {                id = viewRoot.createUniqueId();            }            else            {                context.getExternalContext().log("ERROR: Cannot automatically create an id for component of type " + getClass().getName() + " because there is no viewRoot in the current facesContext!");                id = "ERROR";            }            //We remember that the id was null and log a warning down below            idWasNull = true;        }        UIComponent namingContainer = _ComponentUtils.findParentNamingContainer(this, false);        if (namingContainer != null)        {            _clientId = namingContainer.getClientId(context) + NamingContainer.SEPARATOR_CHAR + id;        }        else        {            _clientId = id;        }        Renderer renderer = getRenderer(context);        if (renderer != null)        {            _clientId = renderer.convertClientId(context, _clientId);        }        if (idWasNull)        {            context.getExternalContext().log("WARNING: Component " + _clientId + " just got an automatic id, because there was no id assigned yet. " +                                             "If this component was created dynamically (i.e. not by a JSP tag) you should assign it an " +                                             "explicit static id or assign it the id you get from the createUniqueId from the current UIViewRoot " +                                             "component right after creation!");        }        return _clientId;    }    public String getId()    {        return _id;    }    public void setId(String id)    {        isIdValid(id);        _id = id;        _clientId = null;    }    public UIComponent getParent()    {        return _parent;    }    public void setParent(UIComponent parent)    {        _parent = parent;    }    public boolean getRendersChildren()    {        Renderer renderer = getRenderer(getFacesContext());        if (renderer != null)        {            return renderer.getRendersChildren();        }        else        {            return false;        }    }    public List getChildren()    {        if (_childrenList == null)        {            _childrenList = new _ComponentChildrenList(this);        }        return _childrenList;    }    public int getChildCount()    {        return _childrenList == null ? 0 : _childrenList.size();    }    /**     * @param expr     * @return     */    public UIComponent findComponent(String expr)    {        if (expr == null) throw new NullPointerException("expr");        if (expr.length() == 0) throw new IllegalArgumentException("empty expr"); //TODO: not specified!        UIComponent findBase;        if (expr.charAt(0) == NamingContainer.SEPARATOR_CHAR)        {            findBase = _ComponentUtils.getRootComponent(this);            expr = expr.substring(1);        }        else        {            if (this instanceof NamingContainer)            {                findBase = this;            }            else            {                findBase = _ComponentUtils.findParentNamingContainer(this, true /* root if not found */);            }        }        int separator = expr.indexOf(NamingContainer.SEPARATOR_CHAR);        if (separator == -1)        {            return _ComponentUtils.findComponent(findBase, expr);        }        else        {            findBase = _ComponentUtils.findComponent(findBase, expr.substring(0, separator));            if (findBase == null)            {                return null;            }            else            {                return findBase.findComponent(expr.substring(separator + 1));            }        }    }    public Map getFacets()    {        if (_facetMap == null)        {            _facetMap = new _ComponentFacetMap(this);        }        return _facetMap;    }    public UIComponent getFacet(String name)    {        return _facetMap == null ? null : (UIComponent)_facetMap.get(name);    }    public Iterator getFacetsAndChildren()    {        return new _FacetsAndChildrenIterator(_facetMap, _childrenList);    }    public void broadcast(FacesEvent event)            throws AbortProcessingException    {        if (event == null) throw new NullPointerException("event");        if (_facesListeners == null) return;        for (Iterator it = _facesListeners.iterator(); it.hasNext(); )        {            FacesListener facesListener = (FacesListener)it.next();            if (event.isAppropriateListener(facesListener))            {                event.processListener(facesListener);            }        }    }    public void decode(FacesContext context)    {        if (context == null) throw new NullPointerException("context");        Renderer renderer = getRenderer(context);        if (renderer != null)        {            renderer.decode(context, this);        }    }    public void encodeBegin(FacesContext context)            throws IOException    {        if (context == null) throw new NullPointerException("context");        if (!isRendered()) return;        Renderer renderer = getRenderer(context);        if (renderer != null)        {            renderer.encodeBegin(context, this);        }    }    public void encodeChildren(FacesContext context)            throws IOException    {        if (context == null) throw new NullPointerException("context");        if (!isRendered()) return;        Renderer renderer = getRenderer(context);        if (renderer != null)        {            renderer.encodeChildren(context, this);        }    }    public void encodeEnd(FacesContext context)            throws IOException    {        if (context == null) throw new NullPointerException("context");        if (!isRendered()) return;        Renderer renderer = getRenderer(context);        if (renderer != null)        {            renderer.encodeEnd(context, this);        }    }    protected void addFacesListener(FacesListener listener)    {        if (listener == null) throw new NullPointerException("listener");        if (_facesListeners == null)        {            _facesListeners = new ArrayList();        }        _facesListeners.add(listener);    }    protected FacesListener[] getFacesListeners(Class clazz)    {        if (_facesListeners == null)        {            return (FacesListener[])Array.newInstance(clazz, 0);        }        List lst = null;        for (Iterator it = _facesListeners.iterator(); it.hasNext(); )        {            FacesListener facesListener = (FacesListener)it.next();            if (clazz.isAssignableFrom(facesListener.getClass()))            {                if (lst == null) lst = new ArrayList();                lst.add(facesListener);            }        }        if (lst == null)        {            return (FacesListener[])Array.newInstance(clazz, 0);        }        else        {            return (FacesListener[])lst.toArray((FacesListener[])Array.newInstance(clazz, lst.size()));        }    }    protected void removeFacesListener(FacesListener listener)    {        if (_facesListeners != null)        {            _facesListeners.remove(listener);        }    }    public void queueEvent(FacesEvent event)    {        if (event == null) throw new NullPointerException("event");        UIComponent parent = getParent();        if (parent == null)        {            throw new IllegalStateException("component is not a descendant of a UIViewRoot");        }        parent.queueEvent(event);

⌨️ 快捷键说明

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