1 /*
2 * This file is part of NetPisteur.
3 *
4 * Copyright 2001-2002 : Olivier CORNEC, David BOUANCHEAU, Loic LOPEZ,
5 * Gaetan BOUDARD, Mael LE LANNOU, Julien ROBINEAU
6 *
7 * Copyright 2002-2003 : Olivier BRIENS, Simon DEZE, Florence FRIGOULT,
8 * Olivier JOURNEAULT, Francois MARTINIER, Damien RAUDE-MORVAN
9 *
10 * Copyright 2004-2007 : Damien RAUDE-MORVAN
11 *
12 * NetPisteur is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * NetPisteur is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with NetPisteur; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 *
26 * $Author: drazzib $
27 * $Date: 2004-07-08 23:10:03 +0200 (Thu, 08 Jul 2004) $
28 * $Id: ConnexionFactory.java 37 2004-07-08 21:10:03Z drazzib $
29 */
30 package com.drazzib.netpisteur.loader;
31
32 import java.net.URL;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36
37 /**
38 * <P>
39 * <STRONG>Description </STRONG>
40 * <P>
41 * Defines a pattern to make a local or an http connexion
42 *
43 *
44 * @version 1.0
45 * @since 2002/03/18
46 * @author NetPisteur Team
47 */
48
49 public class ConnexionFactory {
50
51 private static final String PROTO_JAR = "jar";
52 private static final String PROTO_FILE = "file";
53 private static final String PROTO_HTTP = "http";
54
55 private static Log log = LogFactory.getLog(ConnexionFactory.class);
56
57 /**
58 * Creates a connection type according to the protocol mentions in the Url -
59 * a connexionLocal - a connexionHttp
60 *
61 * @return A Connexion
62 * @param uneUrl
63 */
64 public Connexion creerConnexion(URL uneUrl) {
65
66 String protocol;
67 protocol = uneUrl.getProtocol();
68
69 if (protocol.equals(PROTO_HTTP)) {
70 log.info("Protocole : 'http'");
71 return new ConnexionHttp(uneUrl);
72
73 } else if (protocol.equals(PROTO_FILE)) {
74 log.info("Protocole : 'file'");
75 return new ConnexionLocal(uneUrl);
76
77 } else if (protocol.equals(PROTO_JAR)) {
78 log.info("Protocole : 'jar'");
79 return new ConnexionLocal(uneUrl);
80
81 }
82
83 return null;
84
85 } // -------------------------------creerConnexion
86
87 } // ---------------------------------------------------------endofclass
88