001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonarqube.ws.client; 021 022import org.sonar.api.server.ws.LocalConnector; 023 024/** 025 * All provided implementations of {@link WsClientFactory}. 026 */ 027public class WsClientFactories { 028 029 private WsClientFactories() { 030 // prevent instantiation 031 } 032 033 /** 034 * Factory to be used when connecting to a remote SonarQube web server. 035 */ 036 public static WsClientFactory getDefault() { 037 return DefaultWsClientFactory.INSTANCE; 038 } 039 040 /** 041 * Factory that allows a SonarQube web service to interact 042 * with other web services, without using the HTTP stack. 043 * @see org.sonar.api.server.ws.LocalConnector 044 */ 045 public static LocalWsClientFactory getLocal() { 046 return DefaultLocalWsClientFactory.INSTANCE; 047 } 048 049 private enum DefaultWsClientFactory implements WsClientFactory { 050 INSTANCE; 051 052 @Override 053 public WsClient newClient(WsConnector connector) { 054 return new DefaultWsClient(connector); 055 } 056 } 057 058 private enum DefaultLocalWsClientFactory implements LocalWsClientFactory { 059 INSTANCE; 060 061 @Override 062 public WsClient newClient(WsConnector connector) { 063 return DefaultWsClientFactory.INSTANCE.newClient(connector); 064 } 065 066 @Override 067 public WsClient newClient(LocalConnector localConnector) { 068 return new DefaultWsClient(new LocalWsConnector(localConnector)); 069 } 070 } 071}