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

📄 uicomponentbase.java

📁 RESIN 3.2 最新源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	try {	  FacesListener listener = (FacesListener) cl.newInstance();	  if (listener instanceof StateHolder) {	    StateHolder holder = (StateHolder) listener;	    holder.restoreState(context, savedListeners[index + 1]);	  }	  _facesListeners[i] = listener;	} catch (Exception e) {	  throw new FacesException(e);	}      }    }  }  private Object saveExprMap(FacesContext context,			     Map<String,ValueExpression> exprMap)  {    if (exprMap == null)      return null;    int size = exprMap.size();        Object []values = new Object[3 * size];    int i = 0;    for (Map.Entry<String,ValueExpression> entry : exprMap.entrySet()) {      values[i++] = entry.getKey();      ValueExpression expr = entry.getValue();      values[i++] = expr.getExpressionString();      values[i++] = expr.getExpectedType();    }    return values;  }  private HashMap<String,ValueExpression>    restoreExprMap(FacesContext context, Object value)  {    if (value == null)      return null;    Object []state = (Object[]) value;    HashMap<String,ValueExpression> map      = new HashMap<String,ValueExpression>();        Application app = context.getApplication();    ExpressionFactory exprFactory = app.getExpressionFactory();    int i = 0;    while (i < state.length) {      String key = (String) state[i++];      String exprString = (String) state[i++];      Class type = (Class) state[i++];      ValueExpression expr	= exprFactory.createValueExpression(context.getELContext(),					    exprString,					    type);      map.put(key, expr);    }    return map;  }  public void setTransient(boolean isTransient)  {    _isTransient = isTransient;  }  public boolean isTransient()  {    return _isTransient;  }  private void removeChild(UIComponent child)  {    if (_children != null) {      if (_children.remove(child))	return;    }        if (_facets != null) {      for (Map.Entry<String,UIComponent> entry : _facets.entrySet()) {	if (entry.getValue() == child) {	  _facets.remove(entry.getKey());	  return;	}      }    }  }  public static Object saveAttachedState(FacesContext context,					 Object attachedObject)  {    if (attachedObject == null)      return null;    else if (attachedObject instanceof List) {      List list = (List) attachedObject;      ArrayList values = new ArrayList();      int len = list.size();            for (int i = 0; i < len; i++) {	values.add(saveAttachedState(context, list.get(i)));      }      return values;    }    else if (attachedObject instanceof StateHolder)      return new StateHandle(context, attachedObject);    else if (attachedObject instanceof Serializable)      return attachedObject;    else      return new StateHandle(context, attachedObject);  }  public static Object restoreAttachedState(FacesContext context,					    Object stateObject)  {    if (stateObject == null)      return null;    else if (stateObject instanceof List) {      List list = (List) stateObject;            ArrayList values = new ArrayList();      int size = list.size();      for (int i = 0; i < size; i++) {	values.add(restoreAttachedState(context, list.get(i)));      }            return values;    }    else if (stateObject instanceof StateHandle)      return ((StateHandle) stateObject).restore(context);    else      return stateObject;  }    private static class StateHandle implements java.io.Serializable {    private Class _class;    private Object _state;    public StateHandle()    {    }    public StateHandle(FacesContext context, Object value)    {      _class = value.getClass();      if (value instanceof StateHolder)	_state = ((StateHolder) value).saveState(context);    }    public Object restore(FacesContext context)    {      try {	Object value = _class.newInstance();	if (value instanceof StateHolder)	  ((StateHolder) value).restoreState(context, _state);	return value;      } catch (Exception e) {	throw new RuntimeException(e);      }    }  }  private static class ComponentList extends AbstractList<UIComponent>    implements java.io.Serializable  {    private ArrayList<UIComponent> _list = new ArrayList<UIComponent>();        private UIComponentBase _parent;    ComponentList(UIComponentBase parent)    {      _parent = parent;    }    @Override    public boolean add(UIComponent child)    {      setParent(child);      _parent._facetsAndChildren = null;      boolean result = _list.add(child);      FacesContext context = FacesContext.getCurrentInstance();      if (! PhaseId.RESTORE_VIEW.equals(context.getCurrentPhaseId()) &&          ! isPostback(context)) {        context.getApplication()          .publishEvent(AfterAddToParentEvent.class, child);        processResourceDependencies(context, child);      }      return result;    }    @Override    public void add(int i, UIComponent child)    {      _list.add(i, child);            setParent(child);      FacesContext context = FacesContext.getCurrentInstance();      if (! PhaseId.RESTORE_VIEW.equals(context.getCurrentPhaseId()) &&          ! isPostback(context)) {        context.getApplication()          .publishEvent(AfterAddToParentEvent.class, child);        processResourceDependencies(context, child);      }      _parent._facetsAndChildren = null;    }    @Override    public boolean addAll(int i, Collection<? extends UIComponent> list)    {      boolean isChange = false;            for (UIComponent child : list) {	setParent(child);	_list.add(i++, child);        FacesContext context = FacesContext.getCurrentInstance();        if (! PhaseId.RESTORE_VIEW.equals(context.getCurrentPhaseId()) &&            ! isPostback(context)) {          context.getApplication()            .publishEvent(AfterAddToParentEvent.class, child);          processResourceDependencies(context, child);        }        isChange = true;      }      _parent._facetsAndChildren = null;            return isChange;    }    private boolean isPostback(FacesContext context) {      RenderKitFactory factory        = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);      String renderKitId = context.getViewRoot().getRenderKitId();      RenderKit renderKit = factory.getRenderKit(context, renderKitId);      if (renderKit == null)        renderKit = factory.getRenderKit(context, RenderKitFactory.HTML_BASIC_RENDER_KIT);            return renderKit.getResponseStateManager().isPostback(context);    }    private void processResourceDependencies(FacesContext context,                                              UIComponent child)    {      ResourceDependency []dependencies = null;      Annotation annotation        = child.getClass().getAnnotation(ResourceDependency.class);      if (annotation != null)        dependencies          = new ResourceDependency []{(ResourceDependency) annotation};      annotation = child.getClass().getAnnotation(ResourceDependencies.class);      if (annotation != null) {        ResourceDependency []dependencyArray          = ((ResourceDependencies) annotation).value();                if (dependencies == null) {          dependencies = dependencyArray;        }        else {          ResourceDependency []newDependecies            = new ResourceDependency[dependencies            .length +                    dependencyArray                      .length];          System.arraycopy(dependencies,                           0,                           newDependecies,                           0,                           dependencies.length);          System.arraycopy(dependencyArray,                           0,                           newDependecies,                           dependencies.length,                           dependencyArray.length);          dependencies = newDependecies;        }      }      Renderer renderer = child.getRenderer(context);      if (renderer != null) {        annotation          = renderer.getClass().getAnnotation(ResourceDependency.class);                if (annotation != null) {          ResourceDependency dependency = (ResourceDependency) annotation;                    if (dependencies == null) {            dependencies = new ResourceDependency []{dependency};          }          else {            ResourceDependency []newDependencies              = new ResourceDependency[dependencies.length + 1];            System.arraycopy(dependencies,                             0,                             newDependencies,                             0,                             dependencies.length);            newDependencies[newDependencies.length - 1] = dependency;            dependencies = newDependencies;          }        }        annotation =          renderer.getClass().getAnnotation(ResourceDependencies.class);        if (annotation != null) {          ResourceDependency []dependencyArray            = ((ResourceDependencies) annotation).value();                    if (dependencies == null) {            dependencies = dependencyArray;          }          else {            ResourceDependency []newDependecies              = new ResourceDependency[dependencies              .length +                      dependencyArray                        .length];            System.arraycopy(dependencies,                             0,                             newDependecies,                             0,                             dependencies.length);            System.arraycopy(dependencyArray,                             0,                             newDependecies,                             dependencies.length,                             dependencyArray.length);            dependencies = newDependecies;          }        }      }      if (dependencies == null)        return;      Application app = context.getApplication();      ResourceHandler resourceHandler = app.getResourceHandler();      for (int i = 0; i < dependencies.length; i++) {        ResourceDependency dependency = dependencies[i];        String name = dependency.name();        if (name == null || name.length() == 0)          throw new IllegalArgumentException(            "Element name in ResourceDependency annotation for component '" +            child +            "' must have a value");        UIOutput componentDependency =          (UIOutput) app.createComponent(UIOutput.COMPONENT_TYPE);        Map<String, Object> attributes = componentDependency.getAttributes();        attributes.put("name", name);        String library = dependency.library();        if (library != null && library.length() > 0)          attributes.put("library", library);        String rendererType          = resourceHandler.getRendererTypeForResourceName(name);        componentDependency.setRendererType(rendererType);        String target = dependency.target();        if (target != null && target.length() > 0) {          attributes.put("target", target);          context.getViewRoot()            .addComponentResource(context, componentDependency, target);        }        else          context.getViewRoot()            .addComponentResource(context, componentDependency);      }    }    @Override    public UIComponent set(int i, UIComponent child)    {      UIComponent old = _list.remove(i);      if (old != null)	old.setParent(null);	      setParent(child);      _list.add(i, child);      _parent._facetsAndChildren = null;            return old;    }    @Override    public UIComponent remove(int i)    {      UIComponent old = _list.remove(i);      if (old != null) {	UIComponent parent = old.getParent();		old.setParent(null);      }      _parent._facetsAndChildren = null;            return old;    }    @Override    public boolean remove(Object v)    {      UIComponent comp = (UIComponent) v;            if (_list.remove(comp)) {	comp.setParent(null);	_parent._facetsAndChildren = null;      	return true;      }      else	return false;    }    @Override    public UIComponent get(int i)    {      return _list.get(i);    }    private void setParent(UIComponent child)    {      UIComponent parent = child.getParent();      if (parent == null) {      }

⌨️ 快捷键说明

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