GhApplication.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package hello;
  2. import com.techempower.*;
  3. import com.techempower.gemini.*;
  4. import com.techempower.gemini.exceptionhandler.*;
  5. import com.techempower.gemini.path.*;
  6. import com.techempower.js.*;
  7. import com.techempower.js.legacy.*;
  8. import hello.home.entity.*;
  9. import hello.home.handler.*;
  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 ResinGeminiApplication
  22. {
  23. //
  24. // Static variables.
  25. //
  26. private static final GhApplication INSTANCE = new GhApplication();
  27. //
  28. // Member methods.
  29. //
  30. /**
  31. * Constructor. This method can be extended to construct references
  32. * to custom components for the application.
  33. */
  34. public GhApplication()
  35. {
  36. super();
  37. }
  38. //
  39. // Protected component constructors.
  40. //
  41. /**
  42. * Constructs a Version reference. This is overloaded to return a
  43. * custom GhVersion object.
  44. */
  45. @Override
  46. protected Version constructVersion()
  47. {
  48. return new GhVersion();
  49. }
  50. /**
  51. * Creates a JavaScriptWriter for writing JSON.
  52. */
  53. @Override
  54. protected JavaScriptWriter constructJavaScriptWriter()
  55. {
  56. return LegacyJavaScriptWriter.custom()
  57. .addVisitorFactory(World.class, World.VISITOR_FACTORY)
  58. .addVisitorFactory(CachedWorld.class, CachedWorld.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.