private static int getIntegerAttribute(Attributes attrs, String name, int defValue) throws ParseException { String stringValue = attrs.getValue(name); if (stringValue == null) { return defValue; } try { return Integer.parseInt(stringValue); } catch (NumberFormatException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidIntegerAttribute, e); pe.setInternalReason("Invalid integer in value of attribute " + name + ": '" + stringValue + "'"); throw pe; } }
private static int getIntegerAttribute(Attributes attrs, String name, int defValue) throws ParseException { String stringValue = attrs.getValue(name); if (stringValue == null) { return defValue; } try { return Integer.parseInt(stringValue); } catch (NumberFormatException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidIntegerAttribute, e); pe.setInternalReason("Invalid integer in value of attribute " + name + ": '" + stringValue + "'"); throw pe; } }
private static int getIntegerAttribute(Attributes attrs, String name, int defValue) throws ParseException { String stringValue = attrs.getValue(name); if (stringValue == null) { return defValue; } try { return Integer.parseInt(stringValue); } catch (NumberFormatException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidIntegerAttribute, e); pe.setInternalReason("Invalid integer in value of attribute " + name + ": '" + stringValue + "'"); throw pe; } }
@Override public void processAttribute(String namespace, String localName, String value) throws ParseException { if (namespace.equals("")) { if (localName.equals("specialized")) { if ("true".equals(value) || "1".equals(value)) { isSpecialized = true; } else if ("false".equals(value) || "0".equals(value)) { isSpecialized = false; } else { ParseException pe = new ParseException(CoreErrorDomain.ERR.invalidBooleanAttribute); pe.setInternalReason( "Invalid boolean value for attribute: 'specialized'"); throw pe; } } } }
@Override public void processAttribute(String namespace, String localName, String value) throws ParseException { if (namespace.equals("")) { if (localName.equals("specialized")) { if ("true".equals(value) || "1".equals(value)) { isSpecialized = true; } else if ("false".equals(value) || "0".equals(value)) { isSpecialized = false; } else { ParseException pe = new ParseException(CoreErrorDomain.ERR.invalidBooleanAttribute); pe.setInternalReason( "Invalid boolean value for attribute: 'specialized'"); throw pe; } } } }
@Override public void processAttribute(String namespace, String localName, String value) throws ParseException { if (namespace.equals("")) { if (localName.equals("specialized")) { if ("true".equals(value) || "1".equals(value)) { isSpecialized = true; } else if ("false".equals(value) || "0".equals(value)) { isSpecialized = false; } else { ParseException pe = new ParseException(CoreErrorDomain.ERR.invalidBooleanAttribute); pe.setInternalReason( "Invalid boolean value for attribute: 'specialized'"); throw pe; } } } }
public BatchOperationHandler(ExtensionProfile profile, Attributes attrs) throws ParseException { super(profile, BatchOperation.class); String operationType = attrs.getValue("type"); BatchOperationType op = BatchOperationType.forName(operationType); if (op == null) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidBatchOperationType); pe.setInternalReason("Invalid type for batch:operation: '" + operationType + "'"); throw pe; } type = op; } }
public BatchOperationHandler(ExtensionProfile profile, Attributes attrs) throws ParseException { super(profile, BatchOperation.class); String operationType = attrs.getValue("type"); BatchOperationType op = BatchOperationType.forName(operationType); if (op == null) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidBatchOperationType); pe.setInternalReason("Invalid type for batch:operation: '" + operationType + "'"); throw pe; } type = op; } }
public BatchOperationHandler(ExtensionProfile profile, Attributes attrs) throws ParseException { super(profile, BatchOperation.class); String operationType = attrs.getValue("type"); BatchOperationType op = BatchOperationType.forName(operationType); if (op == null) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidBatchOperationType); pe.setInternalReason("Invalid type for batch:operation: '" + operationType + "'"); throw pe; } type = op; } }
public BatchInterruptedElementHandler(ExtensionProfile extProfile, Attributes attrs) throws ParseException { super(extProfile, BatchInterrupted.class); totalCount = getIntegerAttribute(attrs, "parsed", 0); successCount = getIntegerAttribute(attrs, "success", 0); errorCount = getIntegerAttribute(attrs, "error", 0); reason = attrs.getValue("reason"); String contentTypeString = attrs.getValue("content-type"); if (contentTypeString != null) { try { contentType = new ContentType(contentTypeString); } catch (IllegalArgumentException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidContentType, e); pe.setInternalReason("Invalid content type: '" + contentTypeString + "'"); throw pe; } } }
public BatchInterruptedElementHandler(ExtensionProfile extProfile, Attributes attrs) throws ParseException { super(extProfile, BatchInterrupted.class); totalCount = getIntegerAttribute(attrs, "parsed", 0); successCount = getIntegerAttribute(attrs, "success", 0); errorCount = getIntegerAttribute(attrs, "error", 0); reason = attrs.getValue("reason"); String contentTypeString = attrs.getValue("content-type"); if (contentTypeString != null) { try { contentType = new ContentType(contentTypeString); } catch (IllegalArgumentException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidContentType, e); pe.setInternalReason("Invalid content type: '" + contentTypeString + "'"); throw pe; } } }
public BatchInterruptedElementHandler(ExtensionProfile extProfile, Attributes attrs) throws ParseException { super(extProfile, BatchInterrupted.class); totalCount = getIntegerAttribute(attrs, "parsed", 0); successCount = getIntegerAttribute(attrs, "success", 0); errorCount = getIntegerAttribute(attrs, "error", 0); reason = attrs.getValue("reason"); String contentTypeString = attrs.getValue("content-type"); if (contentTypeString != null) { try { contentType = new ContentType(contentTypeString); } catch (IllegalArgumentException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidContentType, e); pe.setInternalReason("Invalid content type: '" + contentTypeString + "'"); throw pe; } } }
/** * Gets the value of a byte attribute and remove it from the list. * * @param name attribute name or <code>null</code> for text content * @param required indicates attribute is required * @param defaultValue the default value for an optional attribute (used if * not present) * @return the byte value of this attribute * @exception ParseException if required is set and the attribute * is not defined, or if the attribute value is not a valid byte */ public byte consumeByte(String name, boolean required, byte defaultValue) throws ParseException { String value = consume(name, required); if (value == null) { return defaultValue; } try { return Byte.parseByte(value); } catch (NumberFormatException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidByteAttribute); pe.setInternalReason("Invalid byte value for attribute: '" + name + "'"); throw pe; } }
/** * Gets the value of a long attribute and remove it from the list. * * @param name attribute name or <code>null</code> for text content * @param required indicates attribute is required * @param defaultValue the default value for an optional attribute (used * if not present) * @return the long value of this attribute * @exception ParseException if required is set and the attribute * is not defined, or if the attribute value is not a valid long */ public long consumeLong(String name, boolean required, long defaultValue) throws ParseException { String value = consume(name, required); if (value == null) { return defaultValue; } try { return Long.parseLong(value); } catch (NumberFormatException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidLongAttribute, e); pe.setInternalReason("Invalid long value for attribute: '" + name + "'"); throw pe; } }
/** * Gets the value of a big integer attribute and remove it from the list. * * @param name attribute name or <code>null</code> for text content * @param required indicates attribute is required * @param defaultValue the default value for an optional attribute (used if * not present) * @return the big integer value of this attribute * @exception ParseException if required is set and the attribute * is not defined, or if the attribute value is not a valid big integer */ public BigInteger consumeBigInteger(String name, boolean required, BigInteger defaultValue) throws ParseException { String value = consume(name, required); if (value == null) { return defaultValue; } try { return new BigInteger(value); } catch (NumberFormatException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidBigIntegerAttribute); pe.setInternalReason("Invalid big integer value for attribute: '" + name + "'"); throw pe; } }
@Override protected void consumeAttributes(AttributeHelper helper) throws ParseException { href = helper.consume("href", false); defaultScheme = helper.consume("scheme", false); String fixedValue = helper.consume("fixed", false); if (fixedValue != null) { if ("yes".equals(fixedValue)) { fixed = true; } else if ("no".equals(fixedValue)) { fixed = false; } else { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidFixedAttribute); pe.setInternalReason("Invalid value for fixed attribute:" + fixedValue); throw pe; } } }
@Override protected void consumeAttributes(AttributeHelper helper) throws ParseException { href = helper.consume("href", false); defaultScheme = helper.consume("scheme", false); String fixedValue = helper.consume("fixed", false); if (fixedValue != null) { if ("yes".equals(fixedValue)) { fixed = true; } else if ("no".equals(fixedValue)) { fixed = false; } else { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidFixedAttribute); pe.setInternalReason("Invalid value for fixed attribute:" + fixedValue); throw pe; } } }
@Override protected void consumeAttributes(AttributeHelper helper) throws ParseException { href = helper.consume("href", false); defaultScheme = helper.consume("scheme", false); String fixedValue = helper.consume("fixed", false); if (fixedValue != null) { if ("yes".equals(fixedValue)) { fixed = true; } else if ("no".equals(fixedValue)) { fixed = false; } else { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidFixedAttribute); pe.setInternalReason("Invalid value for fixed attribute:" + fixedValue); throw pe; } } }
/** Checks whether all required extensions are present. */ protected void checkRequiredExtensions(ExtensionManifest profManifest) throws ParseException { for (ExtensionDescription extDescription : profManifest.supportedExtensions .values()) { if (extDescription.isRequired()) { Class<? extends Extension> extClass = extDescription.getExtensionClass(); boolean found = (extDescription.isRepeatable() ? repeatingExtensionMap .containsKey(extClass) : nonRepeatingExtensionMap .containsKey(extClass)); if (!found) { ParseException pe = new ParseException( CoreErrorDomain.ERR.missingExtensionElement); pe.setInternalReason("Required extension element " + extDescription.getNamespace().getUri() + ":" + extDescription.getLocalName() + " not found."); throw pe; } } } }
/** Checks whether all required extensions are present. */ protected void checkRequiredExtensions(ExtensionManifest profManifest) throws ParseException { for (ExtensionDescription extDescription : profManifest.supportedExtensions .values()) { if (extDescription.isRequired()) { Class<? extends Extension> extClass = extDescription.getExtensionClass(); boolean found = (extDescription.isRepeatable() ? repeatingExtensionMap .containsKey(extClass) : nonRepeatingExtensionMap .containsKey(extClass)); if (!found) { ParseException pe = new ParseException( CoreErrorDomain.ERR.missingExtensionElement); pe.setInternalReason("Required extension element " + extDescription.getNamespace().getUri() + ":" + extDescription.getLocalName() + " not found."); throw pe; } } } }