View Javadoc

1   package com.ontotext.ordi.wsmo4rdf.remote.server;
2   
3   import javax.jws.WebService;
4   
5   import com.ontotext.ordi.wsmo4rdf.WsmoConnection;
6   import com.ontotext.ordi.wsmo4rdf.WsmoSource;
7   import com.ontotext.ordi.wsmo4rdf.remote.exception.AuthenticationFailedException;
8   import com.ontotext.ordi.wsmo4rdf.remote.exception.NonExistingEntryException;
9   import com.ontotext.ordi.wsmo4rdf.remote.exception.ServiceLimitExceededException;
10  import com.ontotext.ordi.wsmo4rdf.remote.server.exception.RegistryFullException;
11  
12  @WebService(endpointInterface = "com.ontotext.ordi.wsmo4rdf.remote.server.WsmoSourceService", 
13  	    serviceName = "WsmoSourceService")
14  public class WsmoSourceServiceImpl implements WsmoSourceService {
15  	public WsmoSourceServiceImpl() {
16  		super();
17  	}
18  
19  	public int getConnection(final int wsmoSourceId) throws NonExistingEntryException, ServiceLimitExceededException {
20  		WsmoSource source = getValidWsmoSource(wsmoSourceId);
21  		WsmoConnection wsmoConnection = source.getConnection();
22  		int connectionId = Integer.MIN_VALUE;
23  		try {
24  		    connectionId = RegistryManager.getInstance().getWsmoConnectionRegistry().register(wsmoConnection);
25  		} catch (RegistryFullException rfe) {
26  		    throw new ServiceLimitExceededException(rfe);
27  		}
28  		assert(connectionId != Integer.MIN_VALUE);
29  		return connectionId;
30  	}
31  
32  	public int getConnectionAuth(final int wsmoSourceId, String user,String pass) 
33  		throws NonExistingEntryException, ServiceLimitExceededException, AuthenticationFailedException {
34  		if (true) { // TODO (mihail): Authenticate user
35  			return getConnection(wsmoSourceId);
36  		}
37  		throw new AuthenticationFailedException();
38  	}
39  
40  	public void clearWarnings(final int wsmoSourceId)
41  			throws NonExistingEntryException {
42  		WsmoSource source = getValidWsmoSource(wsmoSourceId);
43  		source.clearWarnings();
44  	}
45  /*
46   * Freaking JAXB fails to handle this. Needs more work
47   
48  	public Map<Object, Object> getMetaData(final int wsmoSourceId)
49  			throws NonExistingEntryException {
50  		WsmoSource source = getValidWsmoSource(wsmoSourceId);
51  		return source.getMetaData();
52  	}
53  */
54  	
55  /*
56   * JAX-B Stack overflow
57  
58  	public ORDIWarning getWarning(final int wsmoSourceId) 
59  		throws NonExistingEntryException { 
60  		WsmoSource source = getValidWsmoSource(wsmoSourceId); return source.getWarning();
61  	}
62  */
63  
64  /*
65   * Do not delete. To be implemented at latter time probably
66   
67  	public boolean isWrapperFor(Class<?> iface) throws ORDIException { 
68  		// TODO Auto-generated method stub return false; 
69  	}
70  
71  	public <T> T unwrap(Class<T> iface) throws ORDIException {
72  		// TODO Auto-generated method stub return null;
73  	}
74  */
75  
76  	private WsmoSource getValidWsmoSource(final int sourceId)
77  			throws NonExistingEntryException {
78  		WsmoSource source = null;
79  		if (!Registry.isValid(sourceId)) {
80  		    return null;
81  		}
82  		source = RegistryManager.getInstance().getWsmoSourceRegistry().getById(sourceId);
83  		if (source == null) {
84  			throw new NonExistingEntryException("No such WsmoSource (id = " + sourceId + ")");
85  		}
86  		return source;
87  	}
88  	
89  	public void shutdown(final int wsmoSourceId) throws NonExistingEntryException {
90  		WsmoSource source = getValidWsmoSource(wsmoSourceId);
91  		source.shutdown();
92  	}
93  }