public void render(FacesContext context) throws FacesException { if (context.getResponseComplete()) return; Application app = context.getApplication(); ViewHandler view = app.getViewHandler(); beforePhase(context, PhaseId.RENDER_RESPONSE); try { if (log.isLoggable(Level.FINER)) log.finer(context.getViewRoot() + " before render view"); view.renderView(context, context.getViewRoot()); } catch (java.io.IOException e) { if (sendError(context, "renderView", e)) return; throw new FacesException(e); } catch (RuntimeException e) { if (sendError(context, "renderView", e)) return; throw e; } finally { afterPhase(context, PhaseId.RENDER_RESPONSE); logMessages(context); } }
/** @see javax.faces.context.FacesContext#isPostback() */ @Override public boolean isPostback() { assertNotReleased(); Boolean postback = (Boolean) this.getAttributes().get(POST_BACK_MARKER); if (postback == null) { RenderKit rk = this.getRenderKit(); if (rk != null) { postback = rk.getResponseStateManager().isPostback(this); } else { // ViewRoot hasn't been set yet, so calculate the RK ViewHandler vh = this.getApplication().getViewHandler(); String rkId = vh.calculateRenderKitId(this); postback = RenderKitUtils.getResponseStateManager(this, rkId).isPostback(this); } this.getAttributes().put(POST_BACK_MARKER, postback); } return postback; }
private void restoreView(FacesContext context) throws FacesException { Application app = context.getApplication(); if (app instanceof ApplicationImpl) ((ApplicationImpl) app).initRequest(); ViewHandler view = app.getViewHandler(); view.initView(context); UIViewRoot viewRoot = context.getViewRoot(); if (viewRoot != null) { ExternalContext extContext = context.getExternalContext(); viewRoot.setLocale(extContext.getRequestLocale()); doSetBindings(context.getELContext(), viewRoot); return; } String viewId = calculateViewId(context); String renderKitId = view.calculateRenderKitId(context); RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); RenderKit renderKit = renderKitFactory.getRenderKit(context, renderKitId); ResponseStateManager stateManager = renderKit.getResponseStateManager(); if (stateManager.isPostback(context)) { viewRoot = view.restoreView(context, viewId); if (viewRoot != null) { doSetBindings(context.getELContext(), viewRoot); } else { // XXX: backward compat issues with ViewHandler and StateManager // throw new ViewExpiredException(L.l("{0} is an expired view", viewId)); context.renderResponse(); viewRoot = view.createView(context, viewId); context.setViewRoot(viewRoot); } context.setViewRoot(viewRoot); } else { context.renderResponse(); viewRoot = view.createView(context, viewId); context.setViewRoot(viewRoot); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub final ViewHandler viewHandler; if (null == convertView) { int layoutId = R.layout.highway_scale_business_statistics_details_list_layout; convertView = layoutInflater.inflate(layoutId, null); viewHandler = new ViewHandler(); viewHandler.m_p_type = (ImageView) convertView.findViewById(R.id.highway_scale_list_m_p_type_image); viewHandler.mNumberText = (TextView) convertView.findViewById(R.id.highway_scale_statistics_monitor_totalnumber_text); viewHandler.startDateText = (TextView) convertView.findViewById(R.id.highway_scale_statistics_start_date_text); viewHandler.endDateText = (TextView) convertView.findViewById(R.id.highway_scale_statistics_end_date_text); viewHandler.vehicleNumText = (TextView) convertView.findViewById(R.id.highway_scale_statistics_time_text); viewHandler.weightText = (TextView) convertView.findViewById(R.id.highway_scale_statistics_weight_text); convertView.setTag(viewHandler); } else { viewHandler = (ViewHandler) convertView.getTag(); } if (dataList != null) { HashMap<String, String> urlMap = ScaleTypeChooseControl.getImageUrlMap(); if (urlMap != null && urlMap.size() > 0) { /*带缓存的图片加载*/ ImageLoader.getInstance() .displayImage( urlMap.get(FraemworkConstant.highwayScale + ""), viewHandler.m_p_type, ImageCacheConfig.mOptions, ImageCacheConfig.mAnimateFirstDisplayListener); } viewHandler.mNumberText.setText(dataList.get(position).get("mName") + ""); viewHandler.startDateText.setText(resultStartTime); viewHandler.endDateText.setText(resultEndTime); viewHandler.vehicleNumText.setText( NumberStrFormat.fmtMicrometer(dataList.get(position).get("carNumber") + "")); viewHandler.weightText.setText( NumberStrFormat.fmtMicrometer(dataList.get(position).get("totalWeight") + "")); } return convertView; }
/** * Parses the specified reference (from a URI) and returns the appropriate transform. * * @param ref the reference of the URI that may specify additional attribute values such as the * viewBox, preserveAspectRatio or a transform * @param e the element interested in its view transform * @param w the width of the effective viewport * @param h The height of the effective viewport * @exception BridgeException if an error occured while computing the preserveAspectRatio * transform */ public static AffineTransform getViewTransform(String ref, Element e, float w, float h) { // no reference has been specified, no extra viewBox is defined if (ref == null || ref.length() == 0) { return getPreserveAspectRatioTransform(e, w, h); } ViewHandler vh = new ViewHandler(); FragmentIdentifierParser p = new FragmentIdentifierParser(); p.setFragmentIdentifierHandler(vh); p.parse(ref); Element attrDefElement = e; // the element that defines the attributes if (vh.hasId) { Document document = e.getOwnerDocument(); attrDefElement = document.getElementById(vh.id); } if (attrDefElement == null) { throw new BridgeException(e, ERR_URI_MALFORMED, new Object[] {ref}); } // if the referenced element is not a view, the attribute // values to use are those defined on the enclosed svg element if (!(attrDefElement.getNamespaceURI().equals(SVG_NAMESPACE_URI) && attrDefElement.getLocalName().equals(SVG_VIEW_TAG))) { attrDefElement = getClosestAncestorSVGElement(e); } // 'viewBox' float[] vb; if (vh.hasViewBox) { vb = vh.viewBox; } else { String viewBoxStr = attrDefElement.getAttributeNS(null, SVG_VIEW_BOX_ATTRIBUTE); vb = parseViewBoxAttribute(attrDefElement, viewBoxStr); } // 'preserveAspectRatio' short align; boolean meet; if (vh.hasPreserveAspectRatio) { align = vh.align; meet = vh.meet; } else { String aspectRatio = attrDefElement.getAttributeNS(null, SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE); PreserveAspectRatioParser pp = new PreserveAspectRatioParser(); ViewHandler ph = new ViewHandler(); pp.setPreserveAspectRatioHandler(ph); try { pp.parse(aspectRatio); } catch (ParseException ex) { throw new BridgeException( attrDefElement, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE, aspectRatio, ex}); } align = ph.align; meet = ph.meet; } // the additional transform that may appear on the URI AffineTransform transform = getPreserveAspectRatioTransform(vb, align, meet, w, h); if (vh.hasTransform) { transform.concatenate(vh.getAffineTransform()); } return transform; }
@SuppressWarnings("unchecked") public Object up(Event evt) { switch (evt.getType()) { case Event.MSG: Message msg = (Message) evt.getArg(); GmsHeader hdr = (GmsHeader) msg.getHeader(this.id); if (hdr == null) break; switch (hdr.type) { case GmsHeader.JOIN_REQ: view_handler.add( new Request(Request.JOIN, hdr.mbr, false, null, hdr.useFlushIfPresent)); break; case GmsHeader.JOIN_REQ_WITH_STATE_TRANSFER: view_handler.add( new Request( Request.JOIN_WITH_STATE_TRANSFER, hdr.mbr, false, null, hdr.useFlushIfPresent)); break; case GmsHeader.JOIN_RSP: impl.handleJoinResponse(hdr.join_rsp); break; case GmsHeader.LEAVE_REQ: if (hdr.mbr == null) return null; view_handler.add(new Request(Request.LEAVE, hdr.mbr, false)); break; case GmsHeader.LEAVE_RSP: impl.handleLeaveResponse(); break; case GmsHeader.VIEW: View new_view = hdr.view; if (new_view == null) return null; Address coord = msg.getSrc(); if (!new_view.containsMember(coord)) { sendViewAck( coord); // we need to send the ack first, otherwise the connection is removed impl.handleViewChange(new_view, hdr.my_digest); } else { impl.handleViewChange(new_view, hdr.my_digest); sendViewAck(coord); // send VIEW_ACK to sender of view } break; case GmsHeader.VIEW_ACK: Address sender = msg.getSrc(); ack_collector.ack(sender); return null; // don't pass further up case GmsHeader.MERGE_REQ: impl.handleMergeRequest(msg.getSrc(), hdr.merge_id, hdr.mbrs); break; case GmsHeader.MERGE_RSP: MergeData merge_data = new MergeData(msg.getSrc(), hdr.view, hdr.my_digest, hdr.merge_rejected); if (log.isTraceEnabled()) { log.trace( local_addr + ": got merge response from " + msg.getSrc() + ", merge_id=" + hdr.merge_id + ", merge data is " + merge_data); } impl.handleMergeResponse(merge_data, hdr.merge_id); break; case GmsHeader.INSTALL_MERGE_VIEW: impl.handleMergeView( new MergeData(msg.getSrc(), hdr.view, hdr.my_digest), hdr.merge_id); break; case GmsHeader.INSTALL_DIGEST: Digest tmp = hdr.my_digest; down_prot.down(new Event(Event.MERGE_DIGEST, tmp)); break; case GmsHeader.INSTALL_MERGE_VIEW_OK: // [JGRP-700] - FLUSH: flushing should span merge merge_ack_collector.ack(msg.getSrc()); break; case GmsHeader.CANCEL_MERGE: // [JGRP-524] - FLUSH and merge: flush doesn't wrap entire merge process impl.handleMergeCancelled(hdr.merge_id); break; case GmsHeader.GET_DIGEST_REQ: // only handle this request if it was sent by the coordinator (or at least a member) of // the current cluster synchronized (members) { if (!members.contains(msg.getSrc())) break; } // discard my own request: if (msg.getSrc().equals(local_addr)) return null; if (hdr.merge_id != null && !(merger.matchMergeId(hdr.merge_id) || merger.setMergeId(null, hdr.merge_id))) return null; // fetch only my own digest Digest digest = (Digest) down_prot.down(new Event(Event.GET_DIGEST, local_addr)); if (digest != null) { GmsHeader rsp_hdr = new GmsHeader(GmsHeader.GET_DIGEST_RSP); rsp_hdr.my_digest = digest; Message get_digest_rsp = new Message(msg.getSrc(), null, null); get_digest_rsp.setFlag(Message.OOB); get_digest_rsp.putHeader(this.id, rsp_hdr); down_prot.down(new Event(Event.MSG, get_digest_rsp)); } break; case GmsHeader.GET_DIGEST_RSP: Digest digest_rsp = hdr.my_digest; impl.handleDigestResponse(msg.getSrc(), digest_rsp); break; default: if (log.isErrorEnabled()) log.error("GmsHeader with type=" + hdr.type + " not known"); } return null; // don't pass up case Event.SUSPECT: Object retval = up_prot.up(evt); Address suspected = (Address) evt.getArg(); view_handler.add(new Request(Request.SUSPECT, suspected, true)); ack_collector.suspect(suspected); merge_ack_collector.suspect(suspected); return retval; case Event.UNSUSPECT: impl.unsuspect((Address) evt.getArg()); return null; // discard case Event.MERGE: view_handler.add( new Request(Request.MERGE, null, false, (Map<Address, View>) evt.getArg())); return null; // don't pass up case Event.IS_MERGE_IN_PROGRESS: return merger.isMergeInProgress(); } return up_prot.up(evt); }
public void stop() { view_handler.stop(true); if (impl != null) impl.stop(); if (prev_members != null) prev_members.clear(); }
@ManagedOperation public void resumeViewHandler() { view_handler.resumeForce(); }
@ManagedOperation public void suspendViewHandler() { view_handler.suspend(); }
@ManagedOperation public String dumpViewHandlerHistory() { return view_handler.dumpHistory(); }
@ManagedOperation public String dumpViewHandlerQueue() { return view_handler.dumpQueue(); }
@ManagedAttribute public boolean isViewHandlerSuspended() { return view_handler.suspended(); }
@ManagedAttribute public int getViewHandlerSize() { return view_handler.size(); }
private boolean sendError(FacesContext context, String lifecycle, Exception e) { for (Throwable cause = e; cause != null; cause = cause.getCause()) { if (cause instanceof DisplayableException) { if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new FacesException(e); } else if (cause instanceof ServletException) throw new FacesException(e); else if (cause instanceof JspException) throw new FacesException(e); } ExternalContext extContext = context.getExternalContext(); Object response = extContext.getResponse(); if (!(response instanceof HttpServletResponse)) { context.renderResponse(); if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new RuntimeException(e); } log.log(Level.WARNING, e.toString(), e); HttpServletResponse res = (HttpServletResponse) response; try { context.renderResponse(); context.responseComplete(); res.setStatus(500, "JSF Exception"); res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<body>"); out.println("<h3>JSF exception detected in " + lifecycle + " phase</h3>"); String msg = e.getMessage(); out.println("<span style='color:red;font:bold'>" + Html.escapeHtml(msg) + "</span><br/>"); out.println("<h3>Context: " + context.getViewRoot() + "</h3>"); out.println("<code><pre>"); String errorId = null; if (e instanceof FacesException && msg.startsWith("id=")) { int p = msg.indexOf(' '); errorId = msg.substring(3, p); } printComponentTree(out, errorId, context, context.getViewRoot(), 0); out.println("</pre></code>"); if (!Alarm.isTest()) { out.println("<h3>Stack Trace</h3>"); out.println("<pre>"); if (e.getCause() != null) e.getCause().printStackTrace(out); else e.printStackTrace(out); out.println("</pre>"); } out.println("</body>"); // clear, so we don't just loop Application app = context.getApplication(); ViewHandler view = app.getViewHandler(); UIViewRoot viewRoot = context.getViewRoot(); viewRoot = view.createView(context, viewRoot.getViewId()); context.setViewRoot(viewRoot); // view.writeState(context); // XXX: no need to output state, but review. return true; } catch (IOException e1) { throw new RuntimeException(e); } }