Holds a reference to a WebSocket endpoint class for later instantiation.
| 28 | * Holds a reference to a WebSocket endpoint class for later instantiation. |
| 29 | */ |
| 30 | public class EndpointClassHolder implements ClientEndpointHolder { |
| 31 | |
| 32 | private static final StringManager sm = StringManager.getManager(EndpointClassHolder.class); |
| 33 | |
| 34 | private final Class<? extends Endpoint> clazz; |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * Creates a new holder for the specified endpoint class. |
| 39 | * |
| 40 | * @param clazz The endpoint class to hold |
| 41 | */ |
| 42 | public EndpointClassHolder(Class<? extends Endpoint> clazz) { |
| 43 | this.clazz = clazz; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | @Override |
| 48 | public String getClassName() { |
| 49 | return clazz.getName(); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | @Override |
| 54 | public Endpoint getInstance(InstanceManager instanceManager) throws DeploymentException { |
| 55 | try { |
| 56 | if (instanceManager == null) { |
| 57 | return clazz.getConstructor().newInstance(); |
| 58 | } else { |
| 59 | return (Endpoint) instanceManager.newInstance(clazz); |
| 60 | } |
| 61 | } catch (ReflectiveOperationException | NamingException e) { |
| 62 | throw new DeploymentException(sm.getString("clientEndpointHolder.instanceCreationFailed"), e); |
| 63 | } |
| 64 | } |
| 65 | } |
nothing calls this directly
no test coverage detected