/** * @return the singleton instance of the UIRegistry. */ public static synchronized UIRegistry getInstance() { if (instance == null) { instance = Factory.newInstance(UIRegistry.class); } return instance; }
@Test public void testImplementationExists() { Assert.assertFalse("No implementation should exist", Factory.implementationExists( TestInterface.class)); final String key = ConfigurationProperties.FACTORY_PREFIX + TestInterface.class.getName(); Config.getInstance().setProperty(key, " "); Assert.assertFalse("No implementation should exist", Factory.implementationExists( TestInterface.class)); Config.getInstance().setProperty(key, TestInterfaceImpl.class.getName()); Assert.assertTrue("An implementation should exist", Factory.implementationExists( TestInterface.class)); }
/** * Renders the content after the backing component. * * @param writer the writer to write to. */ protected void afterPaint(final PrintWriter writer) { PageShell pageShell = Factory.newInstance(PageShell.class); pageShell.writeFooter(writer); pageShell.closeDoc(writer); } }
/** * @return a mapped version of the {@link #error}'s message. */ protected String getMessage() { SystemFailureMapper mapper = Factory.newInstance(SystemFailureMapper.class); String desc = I18nUtilities.format(null, mapper.toMessage(error)); return desc; }
/** * Renders the content before the backing component. * * @param writer the writer to write to. */ protected void beforePaint(final PrintWriter writer) { PageShell pageShell = Factory.newInstance(PageShell.class); pageShell.openDoc(writer); pageShell.writeHeader(writer); }
FatalErrorPageFactory factory = Factory.newInstance(FatalErrorPageFactory.class); WComponent errorPage = factory.createErrorPage(friendly, ex);
@Test(expected = SystemException.class) public void testNewInstanceNoImpl() { Factory.newInstance(TestInterface.class); }
@Test public void testNewInstanceWithImpl() { Config.getInstance().setProperty(ConfigurationProperties.FACTORY_PREFIX + TestInterface.class.getName(), TestInterfaceImpl.class.getName()); Assert.assertTrue("Should be an instanceof TestInterface", Factory.newInstance( TestInterface.class) instanceof TestInterface); }
/** * Last resort error handling. * * @param error the error to handle. * @throws IOException if there is an error writing the error HTML. */ public void handleError(final Throwable error) throws IOException { LOG.debug("Start handleError..."); // Should the session be removed upon error? boolean terminate = ConfigurationProperties.getTerminateSessionOnError(); // If we are unfriendly, terminate the session if (terminate) { invalidateSession(); } // Are we in developer friendly error mode? boolean friendly = ConfigurationProperties.getDeveloperErrorHandling(); FatalErrorPageFactory factory = Factory.newInstance(FatalErrorPageFactory.class); WComponent errorPage = factory.createErrorPage(friendly, error); String html = renderErrorPageToHTML(errorPage); // Setup the response Response response = getResponse(); response.setContentType(WebUtilities.CONTENT_TYPE_HTML); // Make sure not cached getResponse().setHeader("Cache-Control", CacheType.NO_CACHE.getSettings()); getResponse().setHeader("Pragma", "no-cache"); getResponse().setHeader("Expires", "-1"); getPrintWriter().println(html); LOG.debug("End handleError"); }
@Test public void testInterecptor() throws XpathException, SAXException, IOException { String tableKey = TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE; // Create interceptor DataListInterceptor interceptor = new DataListInterceptor(); interceptor.attachUI(new DefaultWComponent()); // Action phase MockRequest request = new MockRequest(); request.setParameter(WServlet.DATA_LIST_PARAM_NAME, tableKey); interceptor.serviceRequest(request); // Render phase MockResponse response = new MockResponse(); interceptor.attachResponse(response); interceptor.paint(new WebXmlRenderContext(new PrintWriter(response.getWriter()))); String xml = response.getWriterOutput(); // Ensure that the data matches the test table. List<TestLookupTable.TableEntry> table = (List<TestLookupTable.TableEntry>) Factory. newInstance(LookupTable.class).getTable(tableKey); assertXpathEvaluatesTo(String.valueOf(table.size()), "count(/ui:datalist/ui:option)", xml); for (int i = 0; i < table.size(); i++) { assertXpathEvaluatesTo(table.get(i).getCode(), "/ui:datalist/ui:option[" + (i + 1) + "]/@value", xml); assertXpathEvaluatesTo(table.get(i).getDesc(), "/ui:datalist/ui:option[" + (i + 1) + "]/text()", xml); } }
/** * {@inheritDoc} */ @Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); if (!isInitialised()) { LookupTable lookup = Factory.newInstance(LookupTable.class); for (Object entry : lookup.getTable("sex")) { WAbbrText abbr = new WAbbrText(); abbr.setTextWithDesc(entry); crtSexPanel.add(abbr); } for (Object entry : lookup.getTable("icao")) { WAbbrText abbr = new WAbbrText(); abbr.setTextWithCode(entry); crtIcaoPanel.add(abbr); } setInitialised(true); } } }
newInstance(LookupTable.class).getTable(tableKey);