public List<ResourceName> queryMDS(PackageName packageName) { MDSInstance mdsInstance; List<ResourceName> resources = new ArrayList<ResourceName>(); try { mdsInstance = storeInitializer.getMDSInstance(); packageName = (packageName == null) ? PackageName.createPackageName("/") : packageName; NameCondition condition = ConditionFactory.createNameCondition(packageName.getAbsoluteName(), "%"); ResourceQuery query = QueryFactory.createResourceQuery(mdsInstance, condition); Iterator<QueryResult> contents = query.execute(); if (contents == null) { return resources; } while (contents.hasNext()) { QueryResult result = contents.next(); if (result.getResultType() == QueryResult.ResultType.PACKAGE_RESULT) { PackageResult pack = (PackageResult) result; resources.add(pack.getPackageName()); } else { DocumentResult doc = (DocumentResult) result; resources.add(doc.getDocumentName()); } } return resources; } catch (MDSAccessException e) { throw new IllegalArgumentException("Could not connect to MDS, check login data", e); } catch (InvalidReferenceException e) { throw new IllegalArgumentException("Could not find/read " + packageName, e); } catch (InvalidReferenceTypeException e) { throw new IllegalArgumentException("No correct type!", e); } }