01: /**
02: *
03: */package net.refractions.udig.catalog.memory;
04:
05: import java.io.Serializable;
06: import java.net.URI;
07: import java.net.URL;
08: import java.util.Arrays;
09: import java.util.List;
10: import java.util.Map;
11:
12: import net.refractions.udig.catalog.IService;
13: import net.refractions.udig.catalog.memory.internal.MemoryGeoResourceImpl;
14: import net.refractions.udig.catalog.ui.CatalogUIPlugin;
15: import net.refractions.udig.catalog.ui.UDIGConnectionFactory;
16: import net.refractions.udig.catalog.ui.internal.Messages;
17:
18: import org.eclipse.core.runtime.IProgressMonitor;
19: import org.eclipse.core.runtime.NullProgressMonitor;
20: import org.geotools.data.DataStore;
21: import org.geotools.feature.AttributeType;
22: import org.geotools.feature.AttributeTypeFactory;
23: import org.geotools.feature.FeatureTypes;
24:
25: /**
26: * A ConnectionFactory for creating a new layer. The data will reside on disk.
27: *
28: * @author jones
29: */
30: public class NewServiceConnectionFactory extends UDIGConnectionFactory {
31:
32: @Override
33: public boolean canProcess(Object context) {
34: return context instanceof MemoryGeoResourceImpl;
35: }
36:
37: @Override
38: public Map<String, Serializable> createConnectionParameters(
39: Object context) {
40: Map<String, Serializable> params = null;
41:
42: IProgressMonitor monitor = new NullProgressMonitor();
43: try {
44: MemoryServiceExtensionImpl ext = new MemoryServiceExtensionImpl();
45: URL id = new URL("http://localhost/scratch"); //$NON-NLS-1$
46: params = ext.createParams(id);
47: IService service = ext.createService(id, params);
48: DataStore ds = service.resolve(DataStore.class, monitor);
49: int i = 0;
50: String typename = "New_Type_"; //$NON-NLS-1$
51: List<String> typenames = Arrays.asList(ds.getTypeNames());
52: while (typenames.contains(typename + i)) {
53: i++;
54: }
55: AttributeType at = AttributeTypeFactory.newAttributeType(
56: Messages.NewServiceConnectionFactory_defaultGeom,
57: com.vividsolutions.jts.geom.Geometry.class);
58:
59: ds.createSchema(FeatureTypes.newFeatureType(
60: new AttributeType[] { at }, typename + i, new URI(
61: "http://udig.refractions.net"), false)); //$NON-NLS-1$
62: } catch (Exception e) {
63: CatalogUIPlugin
64: .log(
65: "Error creating MemoryDatastore or feature type", e); //$NON-NLS-1$
66: return null;
67: } finally {
68: monitor.done();
69: }
70: return params;
71: }
72:
73: @Override
74: public URL createConnectionURL(Object context) {
75: return null;
76: }
77:
78: }
|