Debian Codegraph @

src/java/org/astrogrid/samp/xmlrpc/StandardHubProfileFactory.java

raw
1 package org.astrogrid.samp.xmlrpc;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.Iterator;
6 import java.util.List;
7 import org.astrogrid.samp.SampUtils;
8 import org.astrogrid.samp.hub.HubProfile;
9 import org.astrogrid.samp.hub.HubProfileFactory;
10
11 /**
12 * HubProfileFactory implementation for Standard Profile.
13 *
14 * @author Mark Taylor
15 * @since 31 Jan 2011
16 */
17 public class StandardHubProfileFactory implements HubProfileFactory {
18
19 private static final String secretUsage_ = "[-std:secret <secret>]";
20 private static final String lockUsage_ = "[-std:httplock]";
21
22 /**
23 * Returns "std".
24 */
25 public String getName() {
26 return "std";
27 }
28
29 public String[] getFlagsUsage() {
30 return new String[] {
31 secretUsage_,
32 lockUsage_,
33 };
34 }
35
36 public HubProfile createHubProfile( List flagList ) throws IOException {
37 String secret = null;
38 boolean httpLock = false;
39 for ( Iterator it = flagList.iterator(); it.hasNext(); ) {
40 String arg = (String) it.next();
41 if ( arg.equals( "-std:secret" ) ) {
42 it.remove();
43 if ( it.hasNext() ) {
44 secret = (String) it.next();
45 it.remove();
46 }
47 else {
48 throw new IllegalArgumentException( "Usage: "
49 + secretUsage_ );
50 }
51 }
52 else if ( arg.equals( "-std:httplock" ) ) {
53 it.remove();
54 httpLock = true;
55 }
56 else if ( arg.equals( "-std:nohttplock" ) ) {
57 it.remove();
58 httpLock = false;
59 }
60 }
61 File lockfile = httpLock
62 ? null
63 : SampUtils.urlToFile( StandardClientProfile.getLockUrl() );
64 XmlRpcKit xmlrpc = XmlRpcKit.getInstance();
65 if ( secret == null ) {
66 secret = StandardHubProfile.createSecret();
67 }
68 return new StandardHubProfile( xmlrpc.getClientFactory(),
69 xmlrpc.getServerFactory(),
70 lockfile, secret );
71 }
72
73 public Class getHubProfileClass() {
74 return StandardHubProfile.class;
75 }
76 }