+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Sets the configuration of the core.
+ *
+ * @param configuration
+ * The configuration of the core
+ * @return This core (for method chaining)
+ */
+ public Core configuration(Configuration configuration) {
+ this.configuration = configuration;
+ return this;
+ }
+
+ /**
+ * Sets the Freenet interface to use.
+ *
+ * @param freenetInterface
+ * The Freenet interface to use
+ * @return This core (for method chaining)
+ */
+ public Core freenetInterface(FreenetInterface freenetInterface) {
+ this.freenetInterface = freenetInterface;
+ return this;
+ }
+
+ /**
+ * Returns the local Sones.
+ *
+ * @return The local Sones
+ */
+ public Set<Sone> localSones() {
+ return localSones;
+ }
+
+ //
+ // ACTIONS
+ //
+
+ //
+ // SERVICE METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void serviceStart() {
+ loadConfiguration();
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Loads the configuration.
+ */
+ private void loadConfiguration() {
+ logger.entering(Core.class.getName(), "loadConfiguration()");
+
+ /* get names of all local Sones. */
+ String allSoneNamesString = configuration.getStringValue("Sone/Names").getValue(null);
+ if (allSoneNamesString == null) {
+ allSoneNamesString = "";
+ }
+ List<String> allSoneNames;
+ try {
+ allSoneNames = StringEscaper.parseLine(allSoneNamesString);
+ } catch (TextException te1) {
+ logger.log(Level.WARNING, "Could not parse Sone names: “" + allSoneNamesString + "”", te1);
+ allSoneNames = Collections.emptyList();
+ }
+
+ /* parse local Sones. */
+ for (String soneName : allSoneNames) {
+ String insertUri = configuration.getStringValue("Sone/Name." + soneName + "/InsertURI").getValue(null);
+ String requestUri = configuration.getStringValue("Sone/Name." + soneName + "/RequestURI").getValue(null);
+ try {
+ localSones.add(new Sone(soneName, new FreenetURI(requestUri), new FreenetURI(insertUri)));
+ } catch (MalformedURLException mue1) {
+ logger.log(Level.WARNING, "Could not create Sone from requestUri (“" + requestUri + "”) and insertUri (“" + insertUri + "”)!", mue1);
+ }
+ }
+
+ logger.exiting(Core.class.getName(), "loadConfiguration()");
+ }
+