View Javadoc

1   package com.ontotext.ordi.wsmo4rdf.remote.server;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.util.HashMap;
6   import java.util.Map;
7   
8   import javax.jws.WebService;
9   
10  import org.apache.log4j.Logger;
11  
12  import com.ontotext.ordi.Factory;
13  import com.ontotext.ordi.tripleset.TSource;
14  import com.ontotext.ordi.trree.TRREEAdapter;
15  import com.ontotext.ordi.wsmo4rdf.WsmoSource;
16  import com.ontotext.ordi.wsmo4rdf.remote.exception.IllegalSourceNameException;
17  import com.ontotext.ordi.wsmo4rdf.remote.exception.ServiceLimitExceededException;
18  import com.ontotext.ordi.wsmo4rdf.remote.server.exception.RegistryFullException;
19  
20  @WebService(endpointInterface = "com.ontotext.ordi.wsmo4rdf.remote.server.RemoteFactory", serviceName = "RemoteFactory")
21  public class RemoteFactoryImpl implements RemoteFactory {
22      private static Logger logger = Logger.getLogger(RemoteFactoryImpl.class);
23  
24      public RemoteFactoryImpl() {
25  	super();
26      }
27  
28      public int getNewWsmoSource(final String sourceName)
29  	    throws ServiceLimitExceededException, IllegalSourceNameException {
30  	for(int i = 0; i<sourceName.length(); i++) {
31  	    if (!Character.isJavaIdentifierPart(sourceName.charAt(i))) {
32  		throw new IllegalSourceNameException();
33  	    }
34  	}
35  	
36  	Map<Object, Object> tSourceProps = new HashMap<Object, Object>();
37  	Map<Object, Object> wsmoSourceProps = new HashMap<Object, Object>();
38  
39  	File sourceDir = new File(Configuration.newInstance().getStoreDirPath(), "source_" + sourceName);
40  	logger.debug("Storage directory path for source: " + sourceName + " is: \"" + sourceDir.getAbsolutePath() + "\".");
41  	if ( ! sourceDir.exists()) {
42  	    sourceDir.mkdir();
43  	    File entitypoolBin = new File(sourceDir, "entitypool.bin");
44  	    try {
45  		entitypoolBin.createNewFile();
46  	    } catch (IOException e) {
47  		logger.error("This WsmoSource cannot be created");
48  		throw new ServiceLimitExceededException();//TODO(mihail):fix it
49  	    }
50  	}
51  	
52  	tSourceProps.put(TRREEAdapter.STORAGE_DIRECTORY, sourceDir.getAbsolutePath());
53  	TSource tsource = Factory.createTSource(tSourceProps);
54  	wsmoSourceProps.put(WsmoSource.ORDI_SOURCE, tsource);
55  
56  	WsmoSource source = Factory.create(WsmoSource.class, wsmoSourceProps);
57  	int sourceId = Integer.MIN_VALUE;
58  	try {
59  	    sourceId = RegistryManager.getInstance().getWsmoSourceRegistry()
60  		    .register(source);
61  	} catch (RegistryFullException rfe) {
62  	    throw new ServiceLimitExceededException(rfe);
63  	}
64  	assert (sourceId != Integer.MIN_VALUE);
65  	return sourceId;
66      }
67  
68      public boolean destroyWsmoSource(final int wsmoSourceId) {
69  	logger.debug("A request to destroy " + WsmoSource.class.getName()
70  		+ " with ID=" + wsmoSourceId + " have been received.");
71  	if (!Registry.isValid(wsmoSourceId)) {
72  	    return false;
73  	}
74  	WsmoSource source = RegistryManager.getInstance()
75  		.getWsmoSourceRegistry().unregister(wsmoSourceId);
76  	if (source == null)
77  	    return false;
78  	source.shutdown();
79  	source = null;
80  	return true;
81      }
82  
83  }