private static void throwParseException(String value, Type type, Throwable cause) throws ODataUnmarshallingException { throw new ODataUnmarshallingException("This is not a valid " + type + " value: " + value, cause); }
private static void throwParseException(String value, Type type, Throwable cause) throws ODataUnmarshallingException { throw new ODataUnmarshallingException("This is not a valid " + type + " value: " + value, cause); }
private static ODataUnmarshallingException wrapInvocationTargetException( InvocationTargetException e) { if (e.getCause() != null) { return new ODataUnmarshallingException(e.getCause().getMessage(), e.getCause()); } else { return new ODataUnmarshallingException(e.getMessage(), e); } } }
private static ODataUnmarshallingException wrapInvocationTargetException( InvocationTargetException e) { if (e.getCause() != null) { return new ODataUnmarshallingException(e.getCause().getMessage(), e.getCause()); } else { return new ODataUnmarshallingException(e.getMessage(), e); } } }
protected void checkFeedMetadata(Element feedMetadataElement, String nodeLocalName) throws ODataUnmarshallingException { if (!nodeLocalName.equals(feedMetadataElement.getLocalName())) { throw new ODataUnmarshallingException("Wrong Feed metadata. Found: '" + feedMetadataElement.getLocalName() + "'. Expected: '" + nodeLocalName + "'"); } }
protected void checkFeedMetadata(Element feedMetadataElement, String nodeLocalName) throws ODataUnmarshallingException { if (!nodeLocalName.equals(feedMetadataElement.getLocalName())) { throw new ODataUnmarshallingException("Wrong Feed metadata. Found: '" + feedMetadataElement.getLocalName() + "'. Expected: '" + nodeLocalName + "'"); } }
public static void setFieldValue(Field field, Object entity, Object value) throws ODataUnmarshallingException { try { field.setAccessible(true); field.set(entity, value); LOG.debug("'{}' is set with '{}'", field.getName(), value); } catch (IllegalAccessException e) { throw new ODataUnmarshallingException(e.getMessage(), e); } }
private void throwValidationException(StringBuilder validationMessage) throws ODataUnmarshallingException { validationMessage.insert(0, "Cannot send null value for not nullable field(s) "); throw new ODataUnmarshallingException(validationMessage.delete(validationMessage. lastIndexOf(", "), validationMessage.length()).toString()); }
private void throwValidationException(StringBuilder validationMessage) throws ODataUnmarshallingException { validationMessage.insert(0, "Cannot send null value for not nullable field(s) "); throw new ODataUnmarshallingException(validationMessage.delete(validationMessage. lastIndexOf(", "), validationMessage.length()).toString()); }
public static void setFieldValue(Field field, Object entity, Object value) throws ODataUnmarshallingException { try { field.setAccessible(true); field.set(entity, value); LOG.debug("'{}' is set with '{}'", field.getName(), value); } catch (IllegalAccessException e) { throw new ODataUnmarshallingException(e.getMessage(), e); } }
private Document parseXML(String xml) throws ODataUnmarshallingException { try { return DOCBUILDER_FACTORY.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); } catch (SAXException e) { throw new ODataUnmarshallingException("Error while parsing XML", e); } catch (IOException | ParserConfigurationException e) { throw new ODataSystemException(e); } }
private Document parseXML(String xml) throws ODataUnmarshallingException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { return factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); } catch (SAXException e) { throw new ODataUnmarshallingException("Error while parsing XML", e); } catch (IOException | ParserConfigurationException e) { throw new ODataSystemException(e); } } }
private Document parseXML(String xml) throws ODataUnmarshallingException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { return factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); } catch (SAXException e) { throw new ODataUnmarshallingException("Error while parsing XML", e); } catch (IOException | ParserConfigurationException e) { throw new ODataSystemException(e); } } }
private Document parseXML(String xml) throws ODataUnmarshallingException { try { return DOCBUILDER_FACTORY.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); } catch (SAXException e) { throw new ODataUnmarshallingException("Error while parsing XML", e); } catch (IOException | ParserConfigurationException e) { throw new ODataSystemException(e); } }
private String processNavigationLink(Object entity, EntityType entityType, Element linkElement) throws ODataException { String propertyName = linkElement.getAttribute(REL).substring(getODataNavLinkRelationNSPrefix().length()); LOG.debug("Found link element for navigation property: {}", propertyName); StructuralProperty property = entityType.getStructuralProperty(propertyName); if (!(property instanceof NavigationProperty)) { throw new ODataUnmarshallingException("The request contains a navigation link '" + propertyName + "' but the entity type '" + entityType + "' does not contain a navigation property " + "with this name."); } processReferencedEntity(entity, entityType, linkElement); return propertyName; }
private String processNavigationLink(Object entity, EntityType entityType, Element linkElement) throws ODataException { String propertyName = linkElement.getAttribute(REL).substring(getODataNavLinkRelationNSPrefix().length()); LOG.debug("Found link element for navigation property: {}", propertyName); StructuralProperty property = entityType.getStructuralProperty(propertyName); if (!(property instanceof NavigationProperty)) { throw new ODataUnmarshallingException("The request contains a navigation link '" + propertyName + "' but the entity type '" + entityType + "' does not contain a navigation property " + "with this name."); } processReferencedEntity(entity, entityType, linkElement); return propertyName; }
private Object parsePropertyValueComplex(Element propertyElement, ComplexType complexType) throws ODataException { Object instance; try { instance = complexType.getJavaType().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new ODataUnmarshallingException("Error while instantiating instance of complex type: " + complexType.getFullyQualifiedName(), e); } NodeList nodes = propertyElement.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node instanceof Element) { setStructProperty(instance, complexType, (Element) node); } } return instance; }
private Object parsePropertyValueComplex(Element propertyElement, ComplexType complexType) throws ODataException { Object instance; try { instance = complexType.getJavaType().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new ODataUnmarshallingException("Error while instantiating instance of complex type: " + complexType.getFullyQualifiedName(), e); } NodeList nodes = propertyElement.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node instanceof Element) { setStructProperty(instance, complexType, (Element) node); } } return instance; }
private void assignParametersToAction(Map<String, Object> bodyParameters, Set<Parameter> actionParameters, Object actionObject) throws ODataUnmarshallingException { for (Parameter parameter : actionParameters) { Object bodyParameter = bodyParameters.get(parameter.getName()); if (bodyParameter == null && !parameter.isNullable()) { LOG.error("Error during setting a parameter to action object field"); throw new ODataUnmarshallingException("Assigning null to non nullable parameter"); } Field javaField = parameter.getJavaField(); ParameterTypeUtil.setParameter(actionObject, javaField, bodyParameter); } }
private Object processEntity(Element entryElement) throws ODataException { if (!entryElement.getNodeName().equals(ATOM_ENTRY)) { throw new ODataUnmarshallingException("Expected <entry> as the root element, but found: " + entryElement.getNodeName()); } EntityType entityType = getEntityType(entryElement); Object entity; try { Class<?> javaType = entityType.getJavaType(); LOG.debug("Creating new instance of type: {}", javaType.getName()); entity = javaType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new ODataUnmarshallingException("Error while instantiating entity of type: " + entityType.getFullyQualifiedName(), e); } setEntityProperties(entity, entityType, entryElement); setEntityNavigationProperties(entity, entityType, entryElement); ensureNonNullableCollectionArePresent(entityType); return entity; }