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

📄 treestructuremanager.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
字号:
/* * 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 org.apache.myfaces.application;import org.apache.myfaces.util.ClassUtils;import javax.faces.component.UIComponent;import javax.faces.component.UIViewRoot;import java.io.Serializable;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Map;/** * @author Manfred Geiler (latest modification by $Author: matze $) * @version $Revision: 1.6 $ $Date: 2004/10/13 11:50:59 $ */public class TreeStructureManager{    //private static final Log log = LogFactory.getLog(TreeStructureManager.class);    //private FacesContext _facesContext;    public TreeStructureManager()    {        //_facesContext = facesContext;    }    public Object buildTreeStructureToSave(UIViewRoot viewRoot)    {        return internalBuildTreeStructureToSave(viewRoot);    }    private TreeStructComponent internalBuildTreeStructureToSave(UIComponent component)    {        TreeStructComponent structComp = new TreeStructComponent(component.getClass().getName(),                                                                 component.getId());        //children        if (component.getChildCount() > 0)        {            List childList = component.getChildren();            List structChildList = new ArrayList();            for (int i = 0, len = childList.size(); i < len; i++)            {                UIComponent child = (UIComponent)childList.get(i);                if (!child.isTransient())                {                    TreeStructComponent structChild = internalBuildTreeStructureToSave(child);                    structChildList.add(structChild);                }            }            TreeStructComponent[] childArray = (TreeStructComponent[])structChildList.toArray(new TreeStructComponent[structChildList.size()]);            structComp.setChildren(childArray);        }        //facets        Map facetMap = component.getFacets();        if (!facetMap.isEmpty())        {            List structFacetList = new ArrayList();            for (Iterator it = facetMap.entrySet().iterator(); it.hasNext(); )            {                Map.Entry entry = (Map.Entry)it.next();                UIComponent child = (UIComponent)entry.getValue();                if (!child.isTransient())                {                    String facetName = (String)entry.getKey();                    TreeStructComponent structChild = internalBuildTreeStructureToSave(child);                    structFacetList.add(new Object[] {facetName, structChild});                }            }            Object[] facetArray = structFacetList.toArray(new Object[structFacetList.size()]);            structComp.setFacets(facetArray);        }        return structComp;    }    public UIViewRoot restoreTreeStructure(Object treeStructRoot)    {        if (treeStructRoot instanceof TreeStructComponent)        {            return (UIViewRoot)internalRestoreTreeStructure((TreeStructComponent)treeStructRoot);        }        else        {            throw new IllegalArgumentException("TreeStructure of type " + treeStructRoot.getClass().getName() + " is not supported.");        }    }    private UIComponent internalRestoreTreeStructure(TreeStructComponent treeStructComp)    {        String compClass = treeStructComp.getComponentClass();        String compId = treeStructComp.getComponentId();        UIComponent component = (UIComponent)ClassUtils.newInstance(compClass);        component.setId(compId);        //children        TreeStructComponent[] childArray = treeStructComp.getChildren();        if (childArray != null)        {            List childList = component.getChildren();            for (int i = 0, len = childArray.length; i < len; i++)            {                UIComponent child = internalRestoreTreeStructure(childArray[i]);                childList.add(child);            }        }        //facets        Object[] facetArray = treeStructComp.getFacets();        if (facetArray != null)        {            Map facetMap = component.getFacets();            for (int i = 0, len = facetArray.length; i < len; i++)            {                Object[] tuple = (Object[])facetArray[i];                String facetName = (String)tuple[0];                TreeStructComponent structChild = (TreeStructComponent)tuple[1];                UIComponent child = internalRestoreTreeStructure(structChild);                facetMap.put(facetName, child);            }        }        return component;    }    public static class TreeStructComponent            implements Serializable    {        private String _componentClass;        private String _componentId;        private TreeStructComponent[] _children = null;    // Array of children        private Object[] _facets = null;                   // Array of Array-tuples with Facetname and TreeStructComponent        TreeStructComponent(String componentClass, String componentId)        {            _componentClass = componentClass;            _componentId = componentId;        }        public String getComponentClass()        {            return _componentClass;        }        public String getComponentId()        {            return _componentId;        }        void setChildren(TreeStructComponent[] children)        {            _children = children;        }        TreeStructComponent[] getChildren()        {            return _children;        }        Object[] getFacets()        {            return _facets;        }        void setFacets(Object[] facets)        {            _facets = facets;        }    }}

⌨️ 快捷键说明

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