public IGeoResource createResource(Object param) throws IOException {
    SimpleFeatureType featureType = (SimpleFeatureType) param;

    IService service = getMemoryService();

    MemoryDataStore ds = service.resolve(MemoryDataStore.class, new NullProgressMonitor());
    if (Arrays.asList(ds.getTypeNames()).contains(featureType.getName().getLocalPart()))
      ds.updateSchema(featureType.getName().getLocalPart(), featureType);
    else ds.createSchema(featureType);

    IGeoResource resource = null;
    for (IResolve resolve : service.resources(new NullProgressMonitor())) {
      if (resolve instanceof IGeoResource) {
        IGeoResource r = (IGeoResource) resolve;
        if (r.resolve(SimpleFeatureType.class, new NullProgressMonitor())
            .getName()
            .getLocalPart()
            .equals(featureType.getName().getLocalPart())) {
          resource = r;
          break;
        }
      }
    }
    return resource;
  }
Ejemplo n.º 2
0
 @Override
 public void dispose(IProgressMonitor monitor) {
   super.dispose(monitor); // clean up members
   if (dataStore != null) {
     dataStore.dispose();
     dataStore = null;
   }
   if (resources != null) {
     resources = null;
   }
 }
Ejemplo n.º 3
0
  @Test
  public void testCreateService() throws Exception {
    Activator instance = Activator.getDefault();
    assertNotNull("Run as a JUnit Plug-in Test", instance);

    Bundle bundle = instance.getBundle();
    URL url = bundle.getEntry("cities.csv");
    System.out.println("Bundle URL" + url);

    URL fileUrl = FileLocator.toFileURL(url);
    System.out.println("Bundle URL" + fileUrl);

    // get the service factory
    IServiceFactory factory = CatalogPlugin.getDefault().getServiceFactory();

    // create the service

    List<IService> services = factory.createService(fileUrl);

    // ensure the service was created
    assertNotNull(services);
    assertEquals(1, services.size());

    // ensure the right type of service was created
    IService service = services.get(0);
    assertNotNull(service);

    ICatalog catalog = CatalogPlugin.getDefault().getLocalCatalog();
    catalog.add(service); // we can now find this service!

    List<IResolve> found = catalog.search("csv", null, null);
    assertEquals(2, found.size());

    // get all the resources from the service
    List<? extends IGeoResource> resources = service.resources(null);
    assertNotNull(resources);
    assertEquals(resources.size(), 1);

    CSV csv = null;
    for (IGeoResource resource : resources) {
      IGeoResourceInfo info = resource.getInfo(null);

      String description = info.getDescription();
      assertNotNull(description);
      System.out.println("Description:" + description);

      ReferencedEnvelope bounds = info.getBounds();
      assertTrue(!bounds.isNull());
      System.out.println("Bounds:" + bounds);

      if (resource.canResolve(CSV.class)) {
        csv = resource.resolve(CSV.class, null);
      }
    }
    CsvReader reader = csv.reader();
    reader.readHeaders();
    reader.setCaptureRawRecord(true);
    reader.setTrimWhitespace(true);
    int count = 0;
    while (reader.readRecord()) {
      String x = reader.get("x");
      String y = reader.get("y");
      System.out.print(reader.getCurrentRecord() + " point " + x + " x " + y);
      Point point = CSV.getPoint(reader);
      System.out.println("-->" + point);

      count++;
    }
    reader.close();
    System.out.println(count);
  }
  /**
   * Generate text from the resolve.getURI()
   *
   * <p>Note this name is only used as a first try, the ResolveLabelDecorator is expected to provide
   * a label based on Name or Title information.
   *
   * @param element
   * @return label based on IResolve.getIdentifier
   */
  public String getText(Object element) {
    if (element instanceof IResolve) {
      IResolve resolve = (IResolve) element;
      try {
        if (resolve instanceof IGeoResource) {
          IGeoResource resource = (IGeoResource) resolve;
          String title = resource.getTitle();
          // This provider should be non-blocking
          //                    if (title == null) {
          //                        IGeoResourceInfo info = resource.getInfo(new
          // NullProgressMonitor());
          //                        if(info != null) {
          //                        	title = info.getTitle();
          //                        }
          //                    }
          ID id = resource.getID();
          if (title == null) {
            title = id.labelResource();
          }
          return title;

        } else if (resolve instanceof IService) {
          IService service = (IService) resolve;
          ID id = service.getID();

          String title = service.getTitle();
          //                    if (title == null) {
          //                        IServiceInfo info = service.getInfo(new NullProgressMonitor());
          //                        if (info != null) {
          //                            title = info.getTitle();
          //                        }
          //                    }
          if (title == null) {
            // we are going to fake something here
            String name = id.toString();
            name = name.replace('_', ' ');
            name = name.replace("%20", " "); // $NON-NLS-1$ //$NON-NLS-2$
            return name;
          }
          if (id.getTypeQualifier() != null) {
            return title + "(" + id.getTypeQualifier() + ")";
          } else {
            return title;
          }
        } else if (resolve instanceof IProcess) {
          IProcess proc = (IProcess) element;
          return proc.getInfo(new NullProgressMonitor()).getTitle();
        } else if (resolve instanceof ISearch) {
          ISearch search = (ISearch) element;
          return search.getInfo(new NullProgressMonitor()).getTitle();
        } else if (resolve instanceof IResolveFolder) {
          IResolveFolder folder = (IResolveFolder) element;
          return folder.getID().toString();
        } else {
          return resolve.getID().toString();
        }
      } catch (IOException e) {
        CatalogUIPlugin.trace("Error fetching the Title for the resource", e); // $NON-NLS-1$
      }
    }
    return super.getText(element);
  }