Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SpotBug and apply code-formatter in 'udig.catalog.wfs' #550

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/maven-jdk8-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,39 @@
import java.net.MalformedURLException;
import java.net.URL;

import org.locationtech.udig.catalog.IGeoResource;
import org.locationtech.udig.catalog.IGeoResourceInfo;
import org.locationtech.udig.catalog.IService;

import org.eclipse.core.runtime.IProgressMonitor;
import org.geotools.data.FeatureStore;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.data.simple.SimpleFeatureStore;
import org.geotools.data.wfs.WFSDataStore;
import org.locationtech.udig.catalog.IGeoResource;
import org.locationtech.udig.catalog.IGeoResourceInfo;
import org.locationtech.udig.catalog.IService;

/**
* Access a feature type in a wfs.
*
*
* @author David Zwiers, Refractions Research
* @since 0.6
*/
public class WFSGeoResourceImpl extends IGeoResource {
WFSServiceImpl parent;

String typename = null;

private URL identifier;

@SuppressWarnings("unused")
private WFSGeoResourceImpl() {/* not for use */
}

/**
* Construct <code>WFSGeoResourceImpl</code>.
*
*
* @param parent
* @param typename
*/
public WFSGeoResourceImpl( WFSServiceImpl parent, String typename ) {
public WFSGeoResourceImpl(WFSServiceImpl parent, String typename) {
this.service = parent;
this.parent = parent;
this.typename = typename;
Expand All @@ -55,67 +58,77 @@ public WFSGeoResourceImpl( WFSServiceImpl parent, String typename ) {
}
}

@Override
public URL getIdentifier() {
return identifier;
}

/*
/**
* @see org.locationtech.udig.catalog.IGeoResource#getStatus()
*/
@Override
public Status getStatus() {
return parent.getStatus();
}

/*
/**
* @see org.locationtech.udig.catalog.IGeoResource#getStatusMessage()
*/
@Override
public Throwable getMessage() {
return parent.getMessage();
}

/*
* Required adaptions: <ul> <li>IGeoResourceInfo.class <li>IService.class </ul>
/**
* Required adoptions:
* <ul>
* <li>IGeoResourceInfo.class
* <li>IService.class
* </ul>
*
* @see org.locationtech.udig.catalog.IResolve#resolve(java.lang.Class,
* org.eclipse.core.runtime.IProgressMonitor)
* org.eclipse.core.runtime.IProgressMonitor)
*/
public <T> T resolve( Class<T> adaptee, IProgressMonitor monitor ) throws IOException {
if (adaptee == null){
@Override
public <T> T resolve(Class<T> adaptee, IProgressMonitor monitor) throws IOException {
if (adaptee == null) {
return null;
}
if (adaptee.isAssignableFrom(WFSDataStore.class)){
if (adaptee.isAssignableFrom(WFSDataStore.class)) {
return parent.resolve(adaptee, monitor);
}
if (adaptee.isAssignableFrom(IGeoResource.class)){
if (adaptee.isAssignableFrom(IGeoResource.class)) {
return adaptee.cast(this);
}
if (adaptee.isAssignableFrom(IGeoResourceInfo.class)){
if (adaptee.isAssignableFrom(IGeoResourceInfo.class)) {
return adaptee.cast(createInfo(monitor));
}
if (adaptee.isAssignableFrom(SimpleFeatureSource.class)) {
WFSDataStore wfs = parent.getDS(monitor);
SimpleFeatureSource featureSource = wfs.getFeatureSource(typename);
return adaptee.cast(featureSource);
return adaptee.cast(featureSource);
}
if (adaptee.isAssignableFrom(FeatureStore.class)) {
WFSDataStore wfs = parent.getDS(monitor);
SimpleFeatureSource featureSource = wfs.getFeatureSource(typename);
if( featureSource instanceof FeatureStore){
if (featureSource instanceof FeatureStore) {
return adaptee.cast(featureSource);
}
else {
} else {
return null; // write access not available
}
}
return super.resolve(adaptee, monitor);
}
/*

/**
* @see org.locationtech.udig.catalog.IResolve#canResolve(java.lang.Class)
*/
public <T> boolean canResolve( Class<T> adaptee ) {
if (adaptee == null){
@Override
public <T> boolean canResolve(Class<T> adaptee) {
if (adaptee == null) {
return false;
}
if (adaptee.isAssignableFrom(SimpleFeatureSource.class)){
if (adaptee.isAssignableFrom(SimpleFeatureSource.class)) {
return true;
}
if (adaptee.isAssignableFrom(SimpleFeatureStore.class)) {
Expand All @@ -124,23 +137,24 @@ public <T> boolean canResolve( Class<T> adaptee ) {
WFSGeoResourceInfo wfsInfo = (WFSGeoResourceInfo) info;
return wfsInfo.isWritable();
}
if( service.getID().toString().indexOf("1.1.0") != -1){
if (service.getID().toString().indexOf("1.1.0") != -1) { //$NON-NLS-1$
return false; // 1.1.0 not writable yet
}
else {
} else {
return true;
}
}
return (adaptee.isAssignableFrom(IGeoResourceInfo.class)
|| adaptee.isAssignableFrom(WFSDataStore.class) || adaptee
.isAssignableFrom(IService.class))
|| super.canResolve(adaptee);
|| adaptee.isAssignableFrom(WFSDataStore.class)
|| adaptee.isAssignableFrom(IService.class)) || super.canResolve(adaptee);
}

@Override
public WFSGeoResourceInfo getInfo( IProgressMonitor monitor ) throws IOException {
public WFSGeoResourceInfo getInfo(IProgressMonitor monitor) throws IOException {
return (WFSGeoResourceInfo) super.getInfo(monitor);
}
protected WFSGeoResourceInfo createInfo( IProgressMonitor monitor ) throws IOException {

@Override
protected WFSGeoResourceInfo createInfo(IProgressMonitor monitor) throws IOException {
if (getStatus() == Status.BROKEN) {
return null; // could not connect
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2012, Refractions Research Inc.
/**
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2012, Refractions Research Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -17,60 +17,53 @@
import java.util.Set;
import java.util.TreeSet;

import org.locationtech.udig.catalog.IGeoResourceInfo;
import org.locationtech.udig.ui.graphics.Glyph;

import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.data.QueryCapabilities;
import org.geotools.data.ResourceInfo;
import org.geotools.data.wfs.WFSDataStore;
import org.locationtech.udig.catalog.IGeoResourceInfo;
import org.locationtech.udig.ui.graphics.Glyph;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

class WFSGeoResourceInfo extends IGeoResourceInfo {

/**
*
*/
private final WFSGeoResourceImpl wfsResource;

CoordinateReferenceSystem crs = null;

private boolean writable = false;

WFSGeoResourceInfo(WFSGeoResourceImpl wfsGeoResourceImpl) throws IOException {
wfsResource = wfsGeoResourceImpl;
WFSDataStore ds = wfsResource.parent.getDS(null);

FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = ds
.getFeatureSource(wfsResource.typename);

writable = featureSource instanceof FeatureStore;

ResourceInfo resourceInfo = featureSource.getInfo();
SimpleFeatureType ft = null;
try {
ft = ds.getSchema(wfsResource.typename);
} catch (Exception crippled) {
// unable to handle the describe feature type response for this
// typeName
// unable to handle the describe feature type response for this typeName
if (WfsPlugin.getDefault().isDebugging()) {
crippled.printStackTrace();
}
}
bounds = resourceInfo.getBounds();

// relax bounds for wfs ...
// bounds = ReferencedEnvelopeCache.getReferencedEnvelope( crs );


description = resourceInfo.getDescription();
title = resourceInfo.getTitle();

crs = resourceInfo.getCRS();
if (crs == null && ft != null) {
crs = ft.getCoordinateReferenceSystem();
}

name = wfsResource.typename;
schema = resourceInfo.getSchema();
if (schema == null) {
Expand All @@ -84,21 +77,22 @@ class WFSGeoResourceInfo extends IGeoResourceInfo {
schema = null;
}
}
Set<String> tags = new TreeSet<String>();
Set<String> tags = new TreeSet<>();
try {
tags.addAll(resourceInfo.getKeywords());
} catch (Throwable t) {
WfsPlugin.trace("Could not retrieve keywords", t); //$NON-NLS-1$
// no keywords for you
}
tags.addAll(Arrays.asList(new String[]{"wfs", wfsResource.typename})); //$NON-NLS-1$
tags.addAll(Arrays.asList(new String[] { "wfs", wfsResource.typename })); //$NON-NLS-1$
keywords = tags.toArray(new String[0]);
icon = Glyph.icon(ft);
}

/*
/**
* @see org.locationtech.udig.catalog.IGeoResourceInfo#getCRS()
*/
@Override
public CoordinateReferenceSystem getCRS() {
if (crs != null)
return crs;
Expand Down
Loading