+
+ /**
+ * Returns a javascript object that is passed as second argument to the
+ * ready function. This method uses {@link #getConfigurationObject()} to
+ * obtain the configuration object to use which is then serialized to
+ * javascript using {@link JSONSerializer}. Subclasses can override the
+ * default JSONSerializer by implementing {@link #getCustomSerializer()}.
+ * <p>
+ * Subclasses should override this method to perform custom serialization.
+ *
+ * @return Configuration object in javascript.
+ */
+ protected String getConfigurationJavascript() {
+ Object config = getConfigurationObject();
+ return getActualSerializer().serialize(config);
+ }
+
+ /**
+ * Gets the actual serializer to use. It uses {@link #getCustomSerializer()}
+ * to check if there is a custom serializer available.
+ *
+ * @return Serializer.
+ */
+ private JSONSerializer getActualSerializer() {
+ JSONSerializer serializer = getCustomSerializer();
+ if (serializer != null) {
+ return serializer;
+ }
+ return DEFAULT_JSON_SERIALIZER;
+ }
+
+ /**
+ * Returns the serializer to use. Implementations can override this method
+ * to perform custom initialization of the serializer knowing the type of
+ * configuration object to use.
+ *
+ * @return Custom serializer to use.
+ */
+ protected JSONSerializer getCustomSerializer() {
+ return null;
+ }
+
+ /**
+ * Gets the configuration object to use. This is transformed to JSON using
+ * the serializer.
+ *
+ * @return Configuration object.
+ */
+ protected ConfigType getConfigurationObject() {
+ return null;
+ }