Adapters in JDAS

The reason for having the adapters package in JDAS is so that getting objects of specific types from the JAXB generated classes is easier. So for example for the registry code I want to get all sources that have a query_uri that has the server url at the start. The two methods below illustrate without adapters and the same method with adapters:

private List<SOURCE> getDas1SourcesForServerUrl(String serverUrl) {
// SOURCES newSources=new SOURCES();
List<SOURCE> serverSources = new ArrayList<SOURCE>();
List<SOURCE> sourceList = storedSources.getSOURCE();
for (SOURCE source : sourceList) {
List<Object> objects = source.getMAINTAINEROrVERSION();
for (Object object : objects) {
if (object instanceof VERSION) {
System.out.println("version found");
VERSION version = (VERSION) object;
for (Object object1 : version
.getCOORDINATESOrCAPABILITYOrPROP()) {
if (object1 instanceof CAPABILITY) {
CAPABILITY cap = (CAPABILITY) object1;
if (cap.getQueryUri().startsWith(serverUrl)) {
System.out
.println("server url found "
+ serverUrl + "in "
+ cap.getQueryUri());
serverSources.add(source);
break;
}
}
System.out.println("serverUrl found" + source.getUri());
}
}
}
}
return sourceList;
}

with adapters:
public List<SOURCE> getSourcesForServerUrl(String serverUrl) {
List<SOURCE> serverSources = new ArrayList<SOURCE>();
List<SOURCE> sourceList = storedSources.getSOURCE();
for (SOURCE source : sourceList) {
try {
SourceAdapter sourceA = new SourceAdapter(source);
List<VersionAdapter> versionAdapters = sourceA.getVersion();
for (VersionAdapter vA : versionAdapters) {
List<CAPABILITY> caps = vA.getCapabilities();
if (caps.size() > 0) {
if (caps.get(0).getQueryUri().startsWith(serverUrl)) {
serverSources.add(source);
}
}
}
} catch (ValidationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return serverSources;
}

although its not much shorter I’m sure you will agree it is easier to read.

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: