if (ATTR_PAGE_SIZE.equals(attr)) {
if (value < Integer.MAX_VALUE && value > 0 && Volume.isValidPageSize((int) value)) {
pageSize = (int) value;
} else {
throw new InvalidVolumeSpecificationException("Invalid pageSize " + specification);
}
} else if (ATTR_INITIAL_PAGES.equals(attr)) {
initialPages = value;
} else if (ATTR_EXTENSION_PAGES.equals(attr)) {
extensionPages = value;
} else if (ATTR_MAXIMUM_PAGES.equals(attr)) {
maximumPages = value;
} else if (ATTR_INITIAL_SIZE.equals(attr)) {
initialSize = value;
} else if (ATTR_EXTENSION_SIZE.equals(attr)) {
extensionSize = value;
} else if (ATTR_MAXIMUM_SIZE.equals(attr)) {
maximumSize = value;
} else {
bad = true;
}
if (bad || innerTokenizer.hasMoreTokens()) {
throw new InvalidVolumeSpecificationException("Unknown attribute " + attr + " in "
+ specification);
}
}
}
int n = 0;
if (readOnly) {
n++;
}
if (create) {
n++;
}
if (createOnly) {
n++;
}
if (n > 1) {
throw new InvalidVolumeSpecificationException(specification + ": readOnly, create and createOnly "
+ "attributes are mutually exclusive");
}
//
// Allows size specification in bytes rather than pages.
//
if (pageSize > 0) {
if (initialPages == -1 && initialSize > 0) {
initialPages = (initialSize + (pageSize - 1)) / pageSize;
}
if (extensionPages == -1 && extensionSize > 0) {
extensionPages = (extensionSize + (pageSize - 1)) / pageSize;
}
if (maximumPages == -1 && maximumSize > 0) {
maximumPages = (maximumSize + (pageSize - 1)) / pageSize;
}
}
// Validate initial, maximum and extension sizes
if (maximumPages <= 0) {
maximumPages = initialPages;
}
if (create || createOnly) {
if (initialPages < 1 || initialPages > Long.MAX_VALUE / pageSize) {
throw new InvalidVolumeSpecificationException("Invalid initial page count: " + initialPages);
}
if (extensionPages < 0 || extensionPages > Long.MAX_VALUE / pageSize) {
throw new InvalidVolumeSpecificationException("Invalid extension page count: " + extensionPages);
}
if (maximumPages < initialPages || maximumPages > Long.MAX_VALUE / pageSize) {
throw new InvalidVolumeSpecificationException("Invalid maximum page count: " + maximumPages);
}
}
} catch (final NumberFormatException nfe) {
throw new InvalidVolumeSpecificationException(specification + ": invalid number");
} catch (final NoSuchElementException nste) {
throw new InvalidVolumeSpecificationException(specification + ": " + nste);
}
}