| 1 |
package org.astrogrid.samp; |
| 2 |
|
| 3 |
import java.util.Map; |
| 4 |
|
| 5 |
/** |
| 6 |
* Represents information provided to a client at registration by the hub. |
| 7 |
* |
| 8 |
* @author Mark Taylor |
| 9 |
* @since 14 Jul 2008 |
| 10 |
*/ |
| 11 |
public class RegInfo extends SampMap { |
| 12 |
|
| 13 |
/** Key for client public-id used by hub when sending messages itself. */ |
| 14 |
public static final String HUBID_KEY = "samp.hub-id"; |
| 15 |
|
| 16 |
/** Key for client public-id owned by the registering application. */ |
| 17 |
public static final String SELFID_KEY = "samp.self-id"; |
| 18 |
|
| 19 |
/** Key for private-key token used for communications between hub and |
| 20 |
* registering client (Standard Profile). */ |
| 21 |
public static final String PRIVATEKEY_KEY = "samp.private-key"; |
| 22 |
|
| 23 |
private static final String[] KNOWN_KEYS = new String[] { |
| 24 |
HUBID_KEY, |
| 25 |
SELFID_KEY, |
| 26 |
PRIVATEKEY_KEY, |
| 27 |
}; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructs an empty RegInfo. |
| 31 |
*/ |
| 32 |
public RegInfo() { |
| 33 |
super( KNOWN_KEYS ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Constructs a RegInfo based on an existing map. |
| 38 |
* |
| 39 |
* @param map map containing initial data for this object |
| 40 |
*/ |
| 41 |
public RegInfo( Map map ) { |
| 42 |
this(); |
| 43 |
putAll( map ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns the hub's own public client id. |
| 48 |
* |
| 49 |
* @return {@link #HUBID_KEY} value |
| 50 |
*/ |
| 51 |
public String getHubId() { |
| 52 |
return getString( HUBID_KEY ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Returns the registered client's public client id. |
| 57 |
* |
| 58 |
* @return {@link #SELFID_KEY} value |
| 59 |
*/ |
| 60 |
public String getSelfId() { |
| 61 |
return getString( SELFID_KEY ); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Returns the registered client's private key (Standard Profile). |
| 66 |
* |
| 67 |
* @return {@link #PRIVATEKEY_KEY} value |
| 68 |
*/ |
| 69 |
public String getPrivateKey() { |
| 70 |
return getString( PRIVATEKEY_KEY ); |
| 71 |
} |
| 72 |
|
| 73 |
public void check() { |
| 74 |
super.check(); |
| 75 |
checkHasKeys( new String[] { HUBID_KEY, SELFID_KEY, } ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Returns a given map as a RegInfo. |
| 80 |
* |
| 81 |
* @param map map |
| 82 |
* @return registration info |
| 83 |
*/ |
| 84 |
public static RegInfo asRegInfo( Map map ) { |
| 85 |
return map instanceof RegInfo |
| 86 |
? (RegInfo) map |
| 87 |
: new RegInfo( map ); |
| 88 |
} |
| 89 |
} |