public static NxsDataset instanciate(final URI destination, final boolean withWriteAccess) throws NoResultException { NxsDataset dataset = null; String filePath = destination.getPath(); if (filePath != null) { try { dataset = new NxsDataset(new File(filePath), withWriteAccess); String fragment = destination.getFragment(); if (fragment != null && !fragment.isEmpty()) { IGroup group = dataset.getRootGroup(); try { String path = URLDecoder.decode(fragment, "UTF-8"); for (IContainer container : group.findAllContainerByPath(path)) { if (container.getModelType().equals(ModelType.Group)) { dataset.mRootPhysical = (IGroup) container; break; } } } catch (UnsupportedEncodingException e) { Factory.getLogger().log(Level.WARNING, e.getMessage()); } } } catch (Exception e) { throw new NoResultException(e); } } return dataset; }
@Override public IGroup getGroup(String shortName) { if (shortName != null) { for (IGroup group : groupList) { if (shortName.equals(group.getName())) { return group; } } } return null; }
@Override public String toString() { StringBuffer buffer = new StringBuffer(); IGroup parent = getParentGroup(); buffer.append( "Group " + getShortName() + " (parent = " + ((parent == null) ? "Nobody" : parent.getName()) + ")"); return buffer.toString(); }
@Override public IDataset getDataset() { if (dataset == null) { IGroup root = getRootGroup(); if (root == null) { return null; } else { return root.getDataset(); } } else { return dataset; } }
@Override public IGroup getGroupWithAttribute(final String attributeName, final String value) { List<IGroup> groups = getGroupList(); IAttribute attr; for (IGroup group : groups) { attr = group.getAttribute(attributeName); if (attr.getStringValue().equals(value)) { return group; } } return null; }
@Override public IGroup getGroupWithAttribute(String attributeName, String value) { if (name != null) { for (IGroup group : groupList) { IAttribute attribute = group.getAttribute(name); if (attribute != null) { if (StringUtils.isSameString(value, attribute.getStringValue())) { return group; } } } } return null; }
@Override public void addSubgroup(IGroup group) { if ((group instanceof EdfGroup) && (!groupList.contains(group))) { groupList.add((EdfGroup) group); objectList.add((EdfGroup) group); group.setParent(this); } }
@Override public void setDimensions(String dimString) { IGroup parent = getParentGroup(); List<String> dimNames = java.util.Arrays.asList(dimString.split(" ")); List<IDataItem> items = parent.getDataItemList(); for (IDataItem item : items) { IAttribute attr = item.getAttribute("axis"); if (attr != null) { try { IDimension dim = new BasicDimension(item.getName(), item.getData(), false, item.isUnlimited(), false); if ("*".equals(dimString)) { setDimension(dim, attr.getNumericValue().intValue()); } else if (dimNames.contains(attr.getName())) { setDimension(dim, attr.getNumericValue().intValue()); } } catch (IOException e) { e.printStackTrace(); } } } }
@Override public IGroup createGroup(IGroup parent, String shortName) { ArchivingGroup group = null; if ((shortName != null) && !shortName.isEmpty()) { if (parent != null) { if (parent instanceof ArchivingGroup) { group = new ArchivingGroup( NAME, (ArchivingDataset) parent.getDataset(), (ArchivingGroup) parent, shortName); } } else { group = new ArchivingGroup(NAME, null, null, shortName); } } return group; }
@Override public boolean removeGroup(final IGroup group) { return removeGroup(group.getShortName()); }
@Override public void addSubgroup(final IGroup group) { group.setParent(this); groupMap.put(group.getShortName(), group); }