📄 pageimpl.java
字号:
return false; } } else { _listeners.put(evtnm, l = new LinkedList()); } l.add(listener); return true; } public boolean removeEventListener(String evtnm, EventListener listener) { if (evtnm == null || listener == null) throw new NullPointerException(); if (_listeners != null) { final List l = (List)_listeners.get(evtnm); if (l != null) { for (Iterator it = l.iterator(); it.hasNext();) { final EventListener li = (EventListener)it.next(); if (listener.equals(li)) { if (l.size() == 1) _listeners.remove(evtnm); else it.remove(); return true; } } } } return false; } public Component getFellow(String compId) { final Component comp = (Component)_fellows.get(compId); if (comp == null) if (compId != null && ComponentsCtrl.isAutoId(compId)) throw new ComponentNotFoundException(MZk.AUTO_ID_NOT_LOCATABLE, compId); else throw new ComponentNotFoundException("Fellow component not found: "+compId); return comp; } public Component getFellowIfAny(String compId) { return (Component)_fellows.get(compId); } //-- PageCtrl --// public void init(String id, String title, String style, String headers) { if (_desktop != null) throw new IllegalStateException("Don't init twice"); final Execution exec = Executions.getCurrent(); _desktop = exec.getDesktop(); if (_desktop == null) throw new IllegalArgumentException("null desktop"); _ip.setVariable("log", _zklog); _ip.setVariable("page", this); _ip.setVariable("desktop", _desktop); _ip.setVariable("pageScope", getAttributes()); _ip.setVariable("desktopScope", _desktop.getAttributes()); _ip.setVariable("applicationScope", _desktop.getWebApp().getAttributes()); _ip.setVariable("requestScope", REQUEST_ATTRS); _ip.setVariable("spaceOwner", this); final Session sess = _desktop.getSession(); _ip.setVariable("session", sess); _ip.setVariable("sessionScope", sess.getAttributes()); if (headers != null) _headers = headers; final DesktopCtrl dtctrl = (DesktopCtrl)_desktop; if (_id == null && id != null && id.length() != 0) _id = id; if (_id != null) _id = (String)exec.evaluate(this, _id, String.class); if (_id != null && _id.length() != 0) { final String INVALID = ".&\\%"; if (Strings.anyOf(_id, INVALID, 0) < _id.length()) throw new IllegalArgumentException("Invalid page ID: "+_id+". Invalid characters: "+INVALID); } else { _id = Strings.encode(new StringBuffer(12).append("_pp"), dtctrl.getNextId()).toString(); } dtctrl.addPage(this); if (_title.length() == 0 && title != null) setTitle(title); if (_style.length() == 0 && style != null) setStyle(style); } private static final Map REQUEST_ATTRS = new AbstractMap() { public Set entrySet() { final Execution exec = Executions.getCurrent(); if (exec == null) return Collections.EMPTY_SET; return exec.getAttributes().entrySet(); } public Object put(Object name, Object value) { final Execution exec = Executions.getCurrent(); if (exec == null) throw new IllegalStateException("No execution at all"); return exec.getAttributes().put(name, value); } public boolean containsKey(Object name) { final Execution exec = Executions.getCurrent(); return exec != null && exec.getAttributes().containsKey(name); } public Object get(Object name) { final Execution exec = Executions.getCurrent(); if (exec == null) return null; return exec.getAttributes().get(name); } public Object remove(Object name) { final Execution exec = Executions.getCurrent(); if (exec == null) return null; return exec.getAttributes().remove(name); } }; public String getHeaders() { return _headers; } public final Desktop getDesktop() { return _desktop; } public void addRoot(Component comp) { assert D.OFF || comp.getParent() == null; for (Iterator it = _roots.iterator(); it.hasNext();) if (comp == it.next()) return; _roots.add(comp); } public void removeRoot(Component comp) { for (Iterator it = _roots.iterator(); it.hasNext();) if (comp == it.next()) { it.remove(); return; } } public void addFellow(Component comp) { final String compId = comp.getId(); assert D.OFF || !ComponentsCtrl.isAutoId(compId); final Object old = _fellows.put(compId, comp); if (old != comp) { //possible due to recursive call if (old != null) { _fellows.put(((Component)old).getId(), old); //recover throw new InternalError("Called shall prevent replicated ID for roots"); } if (Variables.isValid(compId)) { try { setVariable(compId, comp); } catch (Throwable ex) { if (D.ON) log.warningBriefly("Unable to setVariable: "+compId, ex); } } } } public void removeFellow(Component comp) { final String compId = comp.getId(); if (_fellows.remove(compId) != null && Variables.isValid(compId)) { try { unsetVariable(compId); } catch (Throwable ex) { if (D.ON) log.warningBriefly("Unable to unsetVariable: "+compId, ex); } } } public boolean hasFellow(String compId) { return _fellows.containsKey(compId); } public void redraw(Collection responses, Writer out) throws IOException { if (log.debugable()) log.debug("Redrawing page: "+this+", roots="+_roots); final Execution exec = getExecution(); final ExecutionCtrl execCtrl = (ExecutionCtrl)exec; final boolean asyncUpdate = execCtrl.getVisualizer().isEverAsyncUpdate(); final boolean bIncluded = asyncUpdate || exec.isIncluded(); String uri = bIncluded ? _pgUri: _dkUri; uri = (String)exec.evaluate(this, uri, String.class); final Map attrs = new HashMap(6); attrs.put("page", this); attrs.put("asyncUpdate", Boolean.valueOf(asyncUpdate)); attrs.put("action", _desktop.getUpdateURI(null)); attrs.put("responses", responses != null ? responses: Collections.EMPTY_LIST); if (bIncluded) { exec.include(out, uri, attrs, Execution.PASS_THRU_ATTR); } else { execCtrl.setHeader("Cache-Control", "no-cache,no-store,must-revalidate,max-age=0"); // bug 1520444 execCtrl.setHeader("Pragma", "no-cache,no-store"); // bug 1520444 exec.forward(out, uri, attrs, Execution.PASS_THRU_ATTR); //Don't use include. Otherwise, headers (set by JSP) will be eaten. } } public Class getClass(String clsnm) throws ClassNotFoundException { return _ip.getNamespace().getClass(clsnm); } public final Namespace getNamespace() { return _ip.getNamespace(); } public void interpret(String script, Namespace ns) { _ip.interpret(script, ns); } public boolean isListenerAvailable(String evtnm) { if (_listeners != null) { final List l = (List)_listeners.get(evtnm); return l != null && !l.isEmpty(); } return false; } public Iterator getListenerIterator(String evtnm) { if (_listeners != null) { final List l = (List)_listeners.get(evtnm); if (l != null) return l.iterator(); } return CollectionsX.EMPTY_ITERATOR; } public final Component getOwner() { return _owner; } public final void setOwner(Component comp) { if (_owner != null) throw new IllegalStateException("owner can be set only once"); _owner = comp; } public Component getDefaultParent() { return _defparent; } public void setDefaultParent(Component comp) { _defparent = comp; } public void sessionWillPassivate(Desktop desktop) { for (Iterator it = _roots.iterator(); it.hasNext();) ((ComponentCtrl)it.next()).sessionWillPassivate(this); } public void sessionDidActivate(Desktop desktop) { _desktop = desktop; if (_ownerUuid != null) { _owner = _desktop.getComponentByUuid(_ownerUuid); _ownerUuid = null; } for (Iterator it = _roots.iterator(); it.hasNext();) ((ComponentCtrl)it.next()).sessionDidActivate(this); } public LanguageDefinition getLanguageDefinition() { return _langdef; } public ComponentDefinitionMap getComponentDefinitionMap() { return _compdefs; } public ComponentDefinition getComponentDefinition(String name, boolean recur) { final ComponentDefinition compdef = _compdefs.get(name); if (!recur || compdef != null) return compdef; try { return _langdef.getComponentDefinition(name); } catch (DefinitionNotFoundException ex) { } return null; } public ComponentDefinition getComponentDefinition(Class cls, boolean recur) { final ComponentDefinition compdef = _compdefs.get(cls); if (!recur || compdef != null) return compdef; try { return _langdef.getComponentDefinition(cls); } catch (DefinitionNotFoundException ex) { } return null; } //-- Serializable --// //NOTE: they must be declared as private private synchronized void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); s.writeObject(_langdef != null ? _langdef.getName(): null); s.writeObject(_owner != null ? _owner.getUuid(): null); s.writeObject(_defparent != null ? _defparent.getUuid(): null); Serializables.smartWrite(s, _attrs); Serializables.smartWrite(s, _listeners); _ip.getNamespace().write(s, new Namespace.Filter() { public boolean accept(String name, Object value) { return !(value instanceof Component); } }); } private synchronized void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); init(); final String langnm = (String)s.readObject(); if (langnm != null) _langdef = LanguageDefinition.lookup(langnm); _ownerUuid = (String)s.readObject(); //_owner is restored later when sessionDidActivate is called final String pid = (String)s.readObject(); if (pid != null) _defparent = fixDefaultParent(_roots, pid); Serializables.smartRead(s, _attrs); _listeners = Serializables.smartRead(s, _listeners); //might be null _ip.getNamespace().read(s); fixFellows(_roots); } private final void fixFellows(Collection c) { for (Iterator it = c.iterator(); it.hasNext();) { final Component comp = (Component)it.next(); final String compId = comp.getId(); if (!ComponentsCtrl.isAutoId(compId)) addFellow(comp); if (!(comp instanceof IdSpace)) fixFellows(comp.getChildren()); //recursive } } private static final Component fixDefaultParent(Collection c, String uuid) { for (Iterator it = c.iterator(); it.hasNext();) { Component comp = (Component)it.next(); if (uuid.equals(comp.getUuid())) return comp; //found comp = fixDefaultParent(comp.getChildren(), uuid); if (comp != null) return comp; } return null; } //-- Object --// public String toString() { return "[Page "+_id+']'; } private static class DualFuncMapper implements FunctionMapper { private FunctionMapper newm, oldm; private DualFuncMapper(FunctionMapper newm, FunctionMapper oldm) { this.newm = newm; this.oldm = oldm; } //-- FunctionMapper --// public Method resolveFunction(String prefix, String name) { Method m = this.newm.resolveFunction(prefix, name); if (m == null) m = this.oldm.resolveFunction(prefix, name); return m; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -