public static Iterable<OProperty<?>> parseProperties( XMLEventReader2 reader, StartElement2 propertiesElement) { List<OProperty<?>> rt = new ArrayList<OProperty<?>>(); while (reader.hasNext()) { XMLEvent2 event = reader.nextEvent(); if (event.isEndElement() && event.asEndElement().getName().equals(propertiesElement.getName())) { return rt; } if (event.isStartElement() && event.asStartElement().getName().getNamespaceURI().equals(NS_DATASERVICES)) { String name = event.asStartElement().getName().getLocalPart(); Attribute2 typeAttribute = event.asStartElement().getAttributeByName(M_TYPE); Attribute2 nullAttribute = event.asStartElement().getAttributeByName(M_NULL); boolean isNull = nullAttribute != null && "true".equals(nullAttribute.getValue()); OProperty<?> op = null; String type = null; boolean isComplexType = false; if (typeAttribute != null) { type = typeAttribute.getValue(); EdmType et = EdmType.get(type); isComplexType = !et.isSimple(); } if (isComplexType) { op = OProperties.complex( name, type, isNull ? null : Enumerable.create(parseProperties(reader, event.asStartElement())) .toList()); } else { op = OProperties.parse(name, type, isNull ? null : reader.getElementText()); } rt.add(op); } } throw new RuntimeException(); }
private EdmFunctionImport.Builder parseEdmFunctionImport( XMLEventReader2 reader, String schemaNamespace, StartElement2 functionImportElement) { String name = functionImportElement.getAttributeByName("Name").getValue(); String entitySet = getAttributeValueIfExists(functionImportElement, "EntitySet"); Attribute2 returnTypeAttr = functionImportElement.getAttributeByName("ReturnType"); String returnType = returnTypeAttr != null ? returnTypeAttr.getValue() : null; List<EdmAnnotation<?>> annotElements = new ArrayList<EdmAnnotation<?>>(); // strict parsing boolean isCollection = returnType != null && returnType.matches("^Collection\\(.*\\)$"); if (isCollection) { returnType = returnType.substring(11, returnType.length() - 1); } String httpMethod = getAttributeValueIfExists(functionImportElement, new QName2(NS_METADATA, "HttpMethod")); List<EdmFunctionParameter.Builder> parameters = new ArrayList<EdmFunctionParameter.Builder>(); while (reader.hasNext()) { XMLEvent2 event = reader.nextEvent(); if (event.isStartElement()) { if (isElement( event, EDM2006_PARAMETER, EDM2007_PARAMETER, EDM2008_1_PARAMETER, EDM2008_9_PARAMETER, EDM2009_8_PARAMETER, EDM2009_11_PARAMETER)) { StartElement2 paramStartElement = event.asStartElement(); EdmFunctionParameter.Builder functionParameter = parseEdmFunctionParameter(reader, paramStartElement); parameters.add(functionParameter); } else { EdmAnnotation<?> anElement = getAnnotationElements(event, reader); if (anElement != null) { annotElements.add(anElement); } } } if (isEndElement(event, functionImportElement.getName())) { return EdmFunctionImport.newBuilder() .setName(name) .setEntitySetName(entitySet) .setReturnTypeName(returnType) .setIsCollection(isCollection) .setHttpMethod(httpMethod) .addParameters(parameters) .setAnnotations(getAnnotations(functionImportElement)) .setAnnotationElements(annotElements); } } throw new UnsupportedOperationException(); }
protected List<EdmAnnotation<?>> getAnnotations(StartElement2 element) { // extract Annotation attributes try { Enumerable<Attribute2> atts = element.getAttributes(); List<EdmAnnotation<?>> annots = new ArrayList<EdmAnnotation<?>>(); for (Attribute2 att : atts) { QName2 q = att.getName(); if (isExtensionNamespace(q.getNamespaceUri())) { // a user extension annots.add( EdmAnnotation.attribute( q.getNamespaceUri(), q.getPrefix(), q.getLocalPart(), att.getValue())); } } return annots; } catch (Exception ex) { // not all of the xml parsing implementations implement getAttributes() yet. return null; } }
private EdmFunctionParameter.Builder parseEdmFunctionParameter( XMLEventReader2 reader, StartElement2 paramStartElement) { List<EdmAnnotation<?>> annotElements = new ArrayList<EdmAnnotation<?>>(); Attribute2 modeAttribute = paramStartElement.getAttributeByName("Mode"); String nullableS = getAttributeValueIfExists(paramStartElement, "Nullable"); String maxLength = getAttributeValueIfExists(paramStartElement, "MaxLength"); String precision = getAttributeValueIfExists(paramStartElement, "Precision"); String scale = getAttributeValueIfExists(paramStartElement, "Scale"); while (reader.hasNext()) { XMLEvent2 event = reader.nextEvent(); if (event.isStartElement()) { EdmAnnotation<?> anElement = getAnnotationElements(event, reader); if (anElement != null) { annotElements.add(anElement); } } if (isEndElement(event, paramStartElement.getName())) { return EdmFunctionParameter.newBuilder() .setName(paramStartElement.getAttributeByName("Name").getValue()) .setType( EdmType.newDeferredBuilder( paramStartElement.getAttributeByName("Type").getValue(), dataServices)) .setMode(modeAttribute != null ? Mode.valueOf(modeAttribute.getValue()) : null) .setNullable(nullableS == null ? null : "true".equalsIgnoreCase(nullableS)) .setMaxLength( maxLength == null ? null : maxLength.equals("Max") ? Integer.MAX_VALUE : Integer.parseInt(maxLength)) .setPrecision(precision == null ? null : Integer.parseInt(precision)) .setScale(scale == null ? null : Integer.parseInt(scale)) .setAnnotations(getAnnotations(paramStartElement)) .setAnnotationElements(annotElements); } } throw new UnsupportedOperationException(); }