GhApplication.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package hello;
  2. import hello.home.entity.*;
  3. import hello.home.handler.*;
  4. import com.techempower.*;
  5. import com.techempower.gemini.*;
  6. import com.techempower.gemini.exceptionhandler.*;
  7. import com.techempower.gemini.path.*;
  8. import com.techempower.gemini.pyxis.*;
  9. import com.techempower.js.*;
  10. /**
  11. * GeminiHello Application. As a subclass of GeminiApplication, this
  12. * class acts as the central "hub" of references to components such as
  13. * the Dispatcher and EntityStore.
  14. *
  15. * Development history:
  16. * 2012-04-19 - mh - Created
  17. *
  18. * @author mhixson
  19. */
  20. public class GhApplication
  21. extends GeminiApplication
  22. implements PyxisApplication
  23. {
  24. //
  25. // Static variables.
  26. //
  27. private static final GhApplication INSTANCE = new GhApplication();
  28. //
  29. // Member methods.
  30. //
  31. /**
  32. * Constructor. This method can be extended to construct references
  33. * to custom components for the application.
  34. */
  35. public GhApplication()
  36. {
  37. super();
  38. }
  39. //
  40. // Protected component constructors.
  41. //
  42. /**
  43. * Constructs a Version reference. This is overloaded to return a
  44. * custom GhVersion object.
  45. */
  46. @Override
  47. protected Version constructVersion()
  48. {
  49. return new GhVersion();
  50. }
  51. /**
  52. * Creates a JavaScriptWriter for writing JSON.
  53. */
  54. @Override
  55. protected JavaScriptWriter constructJavaScriptWriter()
  56. {
  57. return JavaScriptWriter.custom()
  58. .addVisitorFactory(World.class, World.VISITOR_FACTORY)
  59. .build();
  60. }
  61. /**
  62. * Constructs a Dispatcher.
  63. */
  64. @Override
  65. protected Dispatcher constructDispatcher()
  66. {
  67. final PathDispatcher.Configuration<Context> config = new PathDispatcher.Configuration<>();
  68. config.setDefault(new HelloHandler(this))
  69. .add(new BasicExceptionHandler(this));
  70. return new PathDispatcher<>(this, config);
  71. }
  72. //
  73. // Static methods.
  74. //
  75. public static GhApplication getInstance()
  76. {
  77. return INSTANCE;
  78. }
  79. } // End GhApplication.