// Path: src/main/java/org/kontalk/xmppserver/probe/DataServerlistRepository.java
// public class DataServerlistRepository implements ServerlistRepository {
// 
//     private static final String SELECT_QUERY_SQL = "SELECT fingerprint, host, enabled FROM servers";
// 
//     private DataRepository repo;
//     private List<ServerInfo> serverlist;
// 
//     @Override
//     public void init(Map<String, Object> props) throws DBInitException {
//         try {
//             String dbUri = (String) props.get("db-uri");
//             if (dbUri == null) {
//                 // fallback on user database
//                 dbUri = System.getProperty(RepositoryFactory.GEN_USER_DB_URI_PROP_KEY);
//             }
//             if (dbUri != null) {
//                 repo = RepositoryFactory.getDataRepository(null, dbUri, null);
//             }
//         }
//         catch (Exception e) {
//             throw new DBInitException("error initializing push data storage", e);
//         }
//     }
// 
//     @Override
//     public List<ServerInfo> getList() {
//         return serverlist;
//     }
// 
//     @Override
//     public boolean isNetworkDomain(String domain) {
//         if (serverlist != null) {
//             for (ServerInfo server : serverlist) {
//                 if (server.getHost().equalsIgnoreCase(domain))
//                     return true;
//             }
//         }
//         return false;
//     }
// 
//     @Override
//     public void reload() throws TigaseDBException {
//         Statement stm = null;
//         ResultSet rs = null;
//         try {
//             stm = repo.createStatement(null);
//             rs = stm.executeQuery(SELECT_QUERY_SQL);
//             serverlist = new LinkedList<ServerInfo>();
//             while (rs.next()) {
//                 String fpr = rs.getString(1);
//                 String host = rs.getString(2);
//                 int enabled = rs.getInt(3);
//                 serverlist.add(new ServerInfo(fpr, host, enabled != 0));
//             }
//         }
//         catch (SQLException e) {
//             throw new TigaseDBException(e.getMessage(), e);
//         }
//         finally {
//             repo.release(stm, rs);
//         }
//     }
// 
// }
// 
// Path: src/main/java/org/kontalk/xmppserver/probe/ServerlistRepository.java
// public interface ServerlistRepository {
// 
//     void init(Map<String, Object> props) throws DBInitException;
// 
//     void reload() throws TigaseDBException;
// 
//     List<ServerInfo> getList();
// 
//     boolean isNetworkDomain(String domain);
// 
//     class ServerInfo {
//         private String fingerprint;
//         private String host;
//         private boolean enabled;
// 
//         protected ServerInfo(String fingerprint, String host, boolean enabled) {
//             this.fingerprint = fingerprint;
//             this.host = host;
//             this.enabled = enabled;
//         }
// 
//         public String getFingerprint() {
//             return fingerprint;
//         }
// 
//         public String getHost() {
//             return host;
//         }
// 
//         public boolean isEnabled() {
//             return enabled;
//         }
//     }
// 
// }


import java.util.List;
import java.util.Map;
import org.kontalk.xmppserver.probe.DataServerlistRepository;
import org.kontalk.xmppserver.probe.ServerlistRepository;
import tigase.component.AbstractComponent;
import tigase.component.AbstractContext;
import tigase.component.modules.Module;
import tigase.component.modules.impl.AdHocCommandModule;
import tigase.component.modules.impl.DiscoveryModule;
import tigase.component.modules.impl.JabberVersionModule;
import tigase.component.modules.impl.XmppPingModule;
import tigase.conf.ConfigurationException;
import java.util.HashMap;
/*
 * Kontalk XMPP Tigase extension
 * Copyright (C) 2017 Kontalk Devteam <devteam@kontalk.org>

 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.kontalk.xmppserver;




/**
 * Component that handles commands for the network (e.g. server list).
 * @author Daniele Ricci
 */
public class NetworkComponent extends AbstractComponent<NetworkContext> {

    private DataServerlistRepository serverListRepo;

    private class NetworkContextImpl extends AbstractContext implements NetworkContext {
        public NetworkContextImpl(AbstractComponent<?> component) {
            super(component);
        }

        @Override
        public List<ServerlistRepository.ServerInfo> getServerList() {
            return serverListRepo.getList();
        }
    }

    @Override
    protected NetworkContext createContext() {
        return new NetworkContextImpl(this);
    }

    @Override
    public String getComponentVersion() {
        String version = this.getClass().getPackage().getImplementationVersion();
// Path: src/main/java/org/kontalk/xmppserver/probe/DataServerlistRepository.java
// public class DataServerlistRepository implements ServerlistRepository {
// 
//     private static final String SELECT_QUERY_SQL = "SELECT fingerprint, host, enabled FROM servers";
// 
//     private DataRepository repo;
//     private List<ServerInfo> serverlist;
// 
//     @Override
//     public void init(Map<String, Object> props) throws DBInitException {
//         try {
//             String dbUri = (String) props.get("db-uri");
//             if (dbUri == null) {
//                 // fallback on user database
//                 dbUri = System.getProperty(RepositoryFactory.GEN_USER_DB_URI_PROP_KEY);
//             }
//             if (dbUri != null) {
//                 repo = RepositoryFactory.getDataRepository(null, dbUri, null);
//             }
//         }
//         catch (Exception e) {
//             throw new DBInitException("error initializing push data storage", e);
//         }
//     }
// 
//     @Override
//     public List<ServerInfo> getList() {
//         return serverlist;
//     }
// 
//     @Override
//     public boolean isNetworkDomain(String domain) {
//         if (serverlist != null) {
//             for (ServerInfo server : serverlist) {
//                 if (server.getHost().equalsIgnoreCase(domain))
//                     return true;
//             }
//         }
//         return false;
//     }
// 
//     @Override
//     public void reload() throws TigaseDBException {
//         Statement stm = null;
//         ResultSet rs = null;
//         try {
//             stm = repo.createStatement(null);
//             rs = stm.executeQuery(SELECT_QUERY_SQL);
//             serverlist = new LinkedList<ServerInfo>();
//             while (rs.next()) {
//                 String fpr = rs.getString(1);
//                 String host = rs.getString(2);
//                 int enabled = rs.getInt(3);
//                 serverlist.add(new ServerInfo(fpr, host, enabled != 0));
//             }
//         }
//         catch (SQLException e) {
//             throw new TigaseDBException(e.getMessage(), e);
//         }
//         finally {
//             repo.release(stm, rs);
//         }
//     }
// 
// }
// 
// Path: src/main/java/org/kontalk/xmppserver/probe/ServerlistRepository.java
// public interface ServerlistRepository {
// 
//     void init(Map<String, Object> props) throws DBInitException;
// 
//     void reload() throws TigaseDBException;
// 
//     List<ServerInfo> getList();
// 
//     boolean isNetworkDomain(String domain);
// 
//     class ServerInfo {
//         private String fingerprint;
//         private String host;
//         private boolean enabled;
// 
//         protected ServerInfo(String fingerprint, String host, boolean enabled) {
//             this.fingerprint = fingerprint;
//             this.host = host;
//             this.enabled = enabled;
//         }
// 
//         public String getFingerprint() {
//             return fingerprint;
//         }
// 
//         public String getHost() {
//             return host;
//         }
// 
//         public boolean isEnabled() {
//             return enabled;
//         }
//     }
// 
// }


// Path: src/main/java/org/kontalk/xmppserver/NetworkComponent.java
import java.util.List;
import java.util.Map;
import org.kontalk.xmppserver.probe.DataServerlistRepository;
import org.kontalk.xmppserver.probe.ServerlistRepository;
import tigase.component.AbstractComponent;
import tigase.component.AbstractContext;
import tigase.component.modules.Module;
import tigase.component.modules.impl.AdHocCommandModule;
import tigase.component.modules.impl.DiscoveryModule;
import tigase.component.modules.impl.JabberVersionModule;
import tigase.component.modules.impl.XmppPingModule;
import tigase.conf.ConfigurationException;
import java.util.HashMap;

/*
 * Kontalk XMPP Tigase extension
 * Copyright (C) 2017 Kontalk Devteam <devteam@kontalk.org>

 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.kontalk.xmppserver;




/**
 * Component that handles commands for the network (e.g. server list).
 * @author Daniele Ricci
 */
public class NetworkComponent extends AbstractComponent<NetworkContext> {

    private DataServerlistRepository serverListRepo;

    private class NetworkContextImpl extends AbstractContext implements NetworkContext {
        public NetworkContextImpl(AbstractComponent<?> component) {
            super(component);
        }

        @Override
        public List<ServerlistRepository.ServerInfo> getServerList() {
            return serverListRepo.getList();
        }
    }

    @Override
    protected NetworkContext createContext() {
        return new NetworkContextImpl(this);
    }

    @Override
    public String getComponentVersion() {
        String version = this.getClass().getPackage().getImplementationVersion();
        return version == null ? "0.0.0" : version;