You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by tb...@apache.org on 2013/08/26 17:01:11 UTC
[2/2] git commit: support more than one standard edm namespace in
EdmParser
support more than one standard edm namespace in EdmParser
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/16e47542
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/16e47542
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/16e47542
Branch: refs/heads/master
Commit: 16e47542b9560cc925d80379343b190e23b18ffb
Parents: 5802caf
Author: Tamara Boehm <ta...@sap.com>
Authored: Thu Aug 22 13:18:21 2013 +0200
Committer: Tamara Boehm <ta...@sap.com>
Committed: Mon Aug 26 16:27:01 2013 +0200
----------------------------------------------------------------------
.../org/apache/olingo/odata2/api/edm/Edm.java | 5 +-
.../odata2/core/edm/parser/EdmParser.java | 106 +++++++++++--------
.../odata2/core/edm/parser/EdmParserTest.java | 44 +++++++-
3 files changed, 104 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/16e47542/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/Edm.java
----------------------------------------------------------------------
diff --git a/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/Edm.java b/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/Edm.java
index ef9652e..b91814f 100644
--- a/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/Edm.java
+++ b/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/Edm.java
@@ -25,7 +25,10 @@ package org.apache.olingo.odata2.api.edm;
*
*/
public interface Edm {
-
+
+ public static final String NAMESPACE_EDM_2006_04 = "http://schemas.microsoft.com/ado/2006/04/edm";
+ public static final String NAMESPACE_EDM_2007_05 = "http://schemas.microsoft.com/ado/2007/05/edm";
+ public static final String NAMESPACE_EDM_2008_01 = "http://schemas.microsoft.com/ado/2008/01/edm";
public static final String NAMESPACE_EDM_2008_09 = "http://schemas.microsoft.com/ado/2008/09/edm";
public static final String NAMESPACE_APP_2007 = "http://www.w3.org/2007/app";
public static final String NAMESPACE_ATOM_2005 = "http://www.w3.org/2005/Atom";
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/16e47542/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/parser/EdmParser.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/parser/EdmParser.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/parser/EdmParser.java
index ef15551..6c1875d 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/parser/EdmParser.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/parser/EdmParser.java
@@ -63,6 +63,7 @@ import org.apache.olingo.odata2.api.edm.provider.Schema;
import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
import org.apache.olingo.odata2.api.edm.provider.Using;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
+
import java.util.HashSet;
import java.util.Set;
@@ -79,6 +80,8 @@ public class EdmParser {
private List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
private String currentHandledStartTagName;
private String currentNamespace;
+ private String edmNamespace = Edm.NAMESPACE_EDM_2008_09;
+ private Set<String> edmNamespaces;
private final String DEFAULT_NAMESPACE = "";
public DataServices readMetadata(final XMLStreamReader reader, final boolean validate)
@@ -94,6 +97,8 @@ public class EdmParser {
if (reader.isStartElement()) {
extractNamespaces(reader);
if (EdmParserConstants.EDM_SCHEMA.equals(reader.getLocalName())) {
+ edmNamespace = reader.getNamespaceURI();
+ checkEdmNamespace();
schemas.add(readSchema(reader));
} else if (EdmParserConstants.EDM_DATA_SERVICES.equals(reader
.getLocalName())) {
@@ -114,7 +119,7 @@ public class EdmParser {
}
private Schema readSchema(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_SCHEMA);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_SCHEMA);
Schema schema = new Schema();
List<Using> usings = new ArrayList<Using>();
@@ -129,7 +134,7 @@ public class EdmParser {
schema.setAlias(reader.getAttributeValue(null, EdmParserConstants.EDM_SCHEMA_ALIAS));
schema.setAnnotationAttributes(readAnnotationAttribute(reader));
currentNamespace = schema.getNamespace();
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_SCHEMA.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_SCHEMA.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -159,7 +164,7 @@ public class EdmParser {
private Using readUsing(final XMLStreamReader reader, final String schemaNamespace)
throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_USING);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_USING);
Using using = new Using();
using.setNamespace(reader.getAttributeValue(null, EdmParserConstants.EDM_SCHEMA_NAMESPACE));
@@ -168,7 +173,7 @@ public class EdmParser {
using.setAnnotationAttributes(readAnnotationAttribute(reader));
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI())
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
&& EdmParserConstants.EDM_USING.equals(reader.getLocalName()))) {
reader.next();
@@ -188,7 +193,7 @@ public class EdmParser {
}
private EntityContainer readEntityContainer(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ENTITY_CONTAINER);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ENTITY_CONTAINER);
EntityContainer container = new EntityContainer();
List<EntitySet> entitySets = new ArrayList<EntitySet>();
List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
@@ -202,7 +207,7 @@ public class EdmParser {
container.setExtendz(reader.getAttributeValue(null, EdmParserConstants.EDM_CONTAINER_EXTENDZ));
container.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_CONTAINER.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_CONTAINER.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -225,7 +230,7 @@ public class EdmParser {
}
private FunctionImport readFunctionImport(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_FUNCTION_IMPORT);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_FUNCTION_IMPORT);
FunctionImport function = new FunctionImport();
List<FunctionImportParameter> functionParameters = new ArrayList<FunctionImportParameter>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
@@ -248,7 +253,7 @@ public class EdmParser {
function.setReturnType(returnType);
}
function.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_FUNCTION_IMPORT.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_FUNCTION_IMPORT.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -265,7 +270,7 @@ public class EdmParser {
}
private FunctionImportParameter readFunctionImportParameter(final XMLStreamReader reader) throws EntityProviderException, XMLStreamException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_FUNCTION_PARAMETER);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_FUNCTION_PARAMETER);
FunctionImportParameter functionParameter = new FunctionImportParameter();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
@@ -278,7 +283,7 @@ public class EdmParser {
functionParameter.setType(EdmSimpleTypeKind.valueOf(extractFQName(type).getName()));
functionParameter.setFacets(readFacets(reader));
functionParameter.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_FUNCTION_IMPORT.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_FUNCTION_IMPORT.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -290,7 +295,7 @@ public class EdmParser {
}
private AssociationSet readAssociationSet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION_SET);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ASSOCIATION_SET);
AssociationSet associationSet = new AssociationSet();
List<AssociationSetEnd> ends = new ArrayList<AssociationSetEnd>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
@@ -304,7 +309,7 @@ public class EdmParser {
.addContent(EdmParserConstants.EDM_ASSOCIATION).addContent(EdmParserConstants.EDM_ASSOCIATION_SET));
}
associationSet.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION_SET.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION_SET.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -329,7 +334,7 @@ public class EdmParser {
}
private EntitySet readEntitySet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ENTITY_SET);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ENTITY_SET);
EntitySet entitySet = new EntitySet();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
entitySet.setName(reader.getAttributeValue(null, EdmParserConstants.EDM_NAME));
@@ -342,7 +347,7 @@ public class EdmParser {
.addContent(EdmParserConstants.EDM_ENTITY_TYPE).addContent(EdmParserConstants.EDM_ENTITY_SET));
}
entitySet.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_SET.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_SET.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -354,14 +359,14 @@ public class EdmParser {
}
private Association readAssociation(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ASSOCIATION);
Association association = new Association();
association.setName(reader.getAttributeValue(null, EdmParserConstants.EDM_NAME));
List<AssociationEnd> associationEnds = new ArrayList<AssociationEnd>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
association.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -385,20 +390,20 @@ public class EdmParser {
}
private ReferentialConstraint readReferentialConstraint(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION_CONSTRAINT);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ASSOCIATION_CONSTRAINT);
ReferentialConstraint refConstraint = new ReferentialConstraint();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
refConstraint.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION_CONSTRAINT.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION_CONSTRAINT.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
currentHandledStartTagName = reader.getLocalName();
if (EdmParserConstants.EDM_ASSOCIATION_PRINCIPAL.equals(currentHandledStartTagName)) {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION_PRINCIPAL);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ASSOCIATION_PRINCIPAL);
refConstraint.setPrincipal(readReferentialConstraintRole(reader));
} else if (EdmParserConstants.EDM_ASSOCIATION_DEPENDENT.equals(currentHandledStartTagName)) {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION_DEPENDENT);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ASSOCIATION_DEPENDENT);
refConstraint.setDependent(readReferentialConstraintRole(reader));
} else {
annotationElements.add(readAnnotationElement(reader));
@@ -415,7 +420,7 @@ public class EdmParser {
List<PropertyRef> propertyRefs = new ArrayList<PropertyRef>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
rcRole.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI())
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
&& (EdmParserConstants.EDM_ASSOCIATION_PRINCIPAL.equals(reader.getLocalName()) || EdmParserConstants.EDM_ASSOCIATION_DEPENDENT.equals(reader.getLocalName())))) {
reader.next();
if (reader.isStartElement()) {
@@ -433,7 +438,7 @@ public class EdmParser {
}
private ComplexType readComplexType(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_COMPLEX_TYPE);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_COMPLEX_TYPE);
ComplexType complexType = new ComplexType();
List<Property> properties = new ArrayList<Property>();
@@ -447,7 +452,7 @@ public class EdmParser {
complexType.setAbstract("true".equalsIgnoreCase(reader.getAttributeValue(null, EdmParserConstants.EDM_ENTITY_TYPE_ABSTRACT)));
}
complexType.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_COMPLEX_TYPE.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_COMPLEX_TYPE.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -471,7 +476,7 @@ public class EdmParser {
}
private EntityType readEntityType(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ENTITY_TYPE);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ENTITY_TYPE);
EntityType entityType = new EntityType();
List<Property> properties = new ArrayList<Property>();
List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
@@ -493,7 +498,7 @@ public class EdmParser {
}
entityType.setCustomizableFeedMappings(readCustomizableFeedMappings(reader));
entityType.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_TYPE.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_TYPE.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
currentHandledStartTagName = reader.getLocalName();
@@ -520,17 +525,17 @@ public class EdmParser {
}
private Key readEntityTypeKey(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ENTITY_TYPE_KEY);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ENTITY_TYPE_KEY);
List<PropertyRef> keys = new ArrayList<PropertyRef>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
List<AnnotationAttribute> annotationAttributes = readAnnotationAttribute(reader);
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_TYPE_KEY.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_TYPE_KEY.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
currentHandledStartTagName = reader.getLocalName();
if (EdmParserConstants.EDM_PROPERTY_REF.equals(currentHandledStartTagName)) {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_PROPERTY_REF);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_PROPERTY_REF);
keys.add(readPropertyRef(reader));
} else {
annotationElements.add(readAnnotationElement(reader));
@@ -541,12 +546,12 @@ public class EdmParser {
}
private PropertyRef readPropertyRef(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_PROPERTY_REF);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_PROPERTY_REF);
PropertyRef propertyRef = new PropertyRef();
propertyRef.setName(reader.getAttributeValue(null, EdmParserConstants.EDM_NAME));
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
propertyRef.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_PROPERTY_REF.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_PROPERTY_REF.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -557,7 +562,7 @@ public class EdmParser {
}
private NavigationProperty readNavigationProperty(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_NAVIGATION_PROPERTY);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_NAVIGATION_PROPERTY);
NavigationProperty navProperty = new NavigationProperty();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
@@ -575,7 +580,7 @@ public class EdmParser {
navProperty.setFromRole(reader.getAttributeValue(null, EdmParserConstants.EDM_NAVIGATION_FROM_ROLE));
navProperty.setToRole(reader.getAttributeValue(null, EdmParserConstants.EDM_NAVIGATION_TO_ROLE));
navProperty.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_NAVIGATION_PROPERTY.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_NAVIGATION_PROPERTY.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -588,7 +593,7 @@ public class EdmParser {
}
private Property readProperty(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_PROPERTY);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_PROPERTY);
Property property;
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
String type = reader.getAttributeValue(null, EdmParserConstants.EDM_TYPE);
@@ -607,7 +612,7 @@ public class EdmParser {
property.setCustomizableFeedMappings(readCustomizableFeedMappings(reader));
property.setMimeType(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, EdmParserConstants.M_MIMETYPE));
property.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_PROPERTY.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_PROPERTY.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -707,7 +712,7 @@ public class EdmParser {
}
private AssociationEnd readAssociationEnd(final XMLStreamReader reader) throws EntityProviderException, XMLStreamException {
- reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION_END);
+ reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, EdmParserConstants.EDM_ASSOCIATION_END);
AssociationEnd associationEnd = new AssociationEnd();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
@@ -720,7 +725,7 @@ public class EdmParser {
}
associationEnd.setType(extractFQName(type));
associationEnd.setAnnotationAttributes(readAnnotationAttribute(reader));
- while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION_END.equals(reader.getLocalName()))) {
+ while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION_END.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
@@ -748,7 +753,7 @@ public class EdmParser {
List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
aElement.setName(reader.getLocalName());
String elementNamespace = reader.getNamespaceURI();
- if (!Edm.NAMESPACE_EDM_2008_09.equals(elementNamespace)) {
+ if (!edmNamespaces.contains(elementNamespace)) {
aElement.setPrefix(reader.getPrefix());
aElement.setNamespace(elementNamespace);
}
@@ -781,10 +786,12 @@ public class EdmParser {
private List<AnnotationAttribute> readAnnotationAttribute(final XMLStreamReader reader) {
List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
for (int i = 0; i < reader.getAttributeCount(); i++) {
- String namespace = reader.getAttributeNamespace(i);
- if (namespace != null && !isDefaultNamespace(namespace) && !mandatoryNamespaces.containsValue(namespace)) {
+ String attributeNamespace = reader.getAttributeNamespace(i);
+ if (attributeNamespace != null && !isDefaultNamespace(attributeNamespace)
+ && !mandatoryNamespaces.containsValue(attributeNamespace)
+ && !edmNamespaces.contains(attributeNamespace)) {
annotationAttributes.add(new AnnotationAttribute().setName(reader.getAttributeLocalName(i)).
- setPrefix(reader.getAttributePrefix(i)).setNamespace(reader.getAttributeNamespace(i)).setText(reader.getAttributeValue(i)));
+ setPrefix(reader.getAttributePrefix(i)).setNamespace(attributeNamespace).setText(reader.getAttributeValue(i)));
}
}
if (annotationAttributes.isEmpty()) {
@@ -797,13 +804,17 @@ public class EdmParser {
return namespace.isEmpty();
}
- private void checkAllMandatoryNamespacesAvailable() throws EntityProviderException {
+ private void checkMandatoryNamespacesAvailable() throws EntityProviderException {
if (!xmlNamespaceMap.containsValue(Edm.NAMESPACE_EDMX_2007_06)) {
throw new EntityProviderException(EntityProviderException.INVALID_NAMESPACE.addContent(Edm.NAMESPACE_EDMX_2007_06));
} else if (!xmlNamespaceMap.containsValue(Edm.NAMESPACE_M_2007_08)) {
throw new EntityProviderException(EntityProviderException.INVALID_NAMESPACE.addContent(Edm.NAMESPACE_EDMX_2007_06));
- } else if (!xmlNamespaceMap.containsValue(Edm.NAMESPACE_EDM_2008_09)) {
- throw new EntityProviderException(EntityProviderException.INVALID_NAMESPACE.addContent(Edm.NAMESPACE_EDMX_2007_06));
+ }
+ }
+
+ private void checkEdmNamespace() throws EntityProviderException {
+ if(!edmNamespaces.contains(edmNamespace)){
+ throw new EntityProviderException( EntityProviderException.INVALID_NAMESPACE.addContent(EdmParserConstants.EDM_SCHEMA));
}
}
@@ -952,7 +963,7 @@ public class EdmParser {
}
private void validate() throws EntityProviderException {
- checkAllMandatoryNamespacesAvailable();
+ checkMandatoryNamespacesAvailable();
validateEntityTypes();
validateComplexTypes();
validateRelationship();
@@ -964,7 +975,12 @@ public class EdmParser {
xmlNamespaceMap = new HashMap<String, String>();
mandatoryNamespaces = new HashMap<String, String>();
mandatoryNamespaces.put(Edm.PREFIX_EDMX, Edm.NAMESPACE_EDMX_2007_06);
- mandatoryNamespaces.put(Edm.PREFIX_EDM, Edm.NAMESPACE_EDM_2008_09);
mandatoryNamespaces.put(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08);
+ edmNamespaces = new HashSet<String>();
+ edmNamespaces.add(Edm.NAMESPACE_EDM_2006_04);
+ edmNamespaces.add(Edm.NAMESPACE_EDM_2007_05);
+ edmNamespaces.add(Edm.NAMESPACE_EDM_2008_01);
+ edmNamespaces.add(Edm.NAMESPACE_EDM_2008_09);
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/16e47542/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/parser/EdmParserTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/parser/EdmParserTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/parser/EdmParserTest.java
index da91133..e7e2428 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/parser/EdmParserTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/parser/EdmParserTest.java
@@ -85,6 +85,8 @@ public class EdmParserTest extends AbstractXmlProducerTestHelper {
private final String xml = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\" m:HasStream=\"true\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<Property Name=\"" + propertyNames[1] + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>" + "<Property Name=\"" + propertyNames[2] + "\" Type=\"RefScenario.c_Location\" Nullable=\"false\"/>" + "</EntityType>" + "<ComplexType Name=\"c_Location\">" + "<Property Name=\"Country\" Type=\"Edm.String\"/>" + "</ComplexType>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
+ private final String xml2 = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\" xmlns:prefix=\"namespace\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_01 + "\">" +"<prefix:schemaElement>text3</prefix:schemaElement>"+ "<EntityType Name= \"Employee\" m:HasStream=\"true\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<Property Name=\"" + propertyNames[1] + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>" + "<Property Name=\"" + propertyNames[2] + "\" Type=\"RefScenario.c_Location\" Nullable=\"false\"/>" + "</EntityType>" + "<ComplexType Name=\"c_Location\">" + "<Property Name=\"Country\" Type=\"Edm.String\"/>" + "</ComplexType>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
+
private final String xmlWithBaseType = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<Property Name=\"" + propertyNames[1] + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>" + "<Property Name=\"" + propertyNames[2] + "\" Type=\"RefScenario.c_Location\" Nullable=\"false\"/>" + "</EntityType>" + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">" + "</EntityType>" + "<ComplexType Name=\"c_Location\">" + "<Property Name=\"Country\" Type=\"Edm.String\"/>" + "</ComplexType>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
private final String xmlWithAssociation = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\"r_Employees\" ToRole=\"r_Manager\" />" + "</EntityType>" + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">" + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\"r_Manager\" ToRole=\"r_Employees\" />" + "</EntityType>" + "<Association Name=\"" + ASSOCIATION + "\">"
@@ -125,6 +127,39 @@ public class EdmParserTest extends AbstractXmlProducerTestHelper {
assertEquals("c_Location", schema.getComplexTypes().get(0).getName());
}
}
+
+ @Test
+ public void testOtherEdmNamespace() throws XMLStreamException, EntityProviderException {
+ int i = 0;
+ EdmParser parser = new EdmParser();
+ XMLStreamReader reader = createStreamReader(xml2);
+ DataServices result = parser.readMetadata(reader, true);
+ assertEquals("2.0", result.getDataServiceVersion());
+ for (Schema schema : result.getSchemas()) {
+ assertEquals(NAMESPACE, schema.getNamespace());
+ assertEquals(1, schema.getEntityTypes().size());
+ assertEquals("Employee", schema.getEntityTypes().get(0).getName());
+ for (PropertyRef propertyRef : schema.getEntityTypes().get(0).getKey().getKeys()) {
+ assertEquals("EmployeeId", propertyRef.getName());
+ }
+ for (Property property : schema.getEntityTypes().get(0).getProperties()) {
+ assertEquals(propertyNames[i], property.getName());
+ if ("Location".equals(property.getName())) {
+ ComplexProperty cProperty = (ComplexProperty) property;
+ assertEquals("c_Location", cProperty.getType().getName());
+ } else if ("EmployeeName".equals(property.getName())) {
+ assertNotNull(property.getCustomizableFeedMappings());
+ }
+ i++;
+ }
+ for (AnnotationElement annoElement : schema.getAnnotationElements()) {
+ assertEquals("prefix", annoElement.getPrefix());
+ assertEquals("namespace", annoElement.getNamespace());
+ assertEquals("schemaElement", annoElement.getName());
+ assertEquals("text3", annoElement.getText());
+ }
+ }
+ }
@Test
public void testBaseType() throws XMLStreamException, EntityProviderException {
@@ -636,9 +671,8 @@ public class EdmParserTest extends AbstractXmlProducerTestHelper {
@Test
public void testAnnotations() throws XMLStreamException, EntityProviderException {
- final String xmlWithAnnotations = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\" prefix1:href=\"http://google.de\" xmlns:prefix1=\"namespaceForAnno\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"EmployeeId\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<Property Name=\"EmployeeName\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\" annoPrefix:annoName=\"annoText\" xmlns:annoPrefix=\"http://annoNamespace\">" + "<propertyAnnoElement>text</propertyAnnoElement>" + "<propertyAnnoElement2 />" + "</Property>" + "</EntityType>" + "<schemaElementTest1>" + "<prefix:schemaElementTest2 xmlns:prefix=\"namespace\">text3" + "</prefix:schemaElementTest2>"
- + "<schemaElementTest3 rel=\"self\" pre:href=\"http://google.com\" xmlns:pre=\"namespaceForAnno\">text4</schemaElementTest3>" + " </schemaElementTest1>" + "</Schema>"
-
+ final String xmlWithAnnotations = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\" xmlns:annoPrefix=\"http://annoNamespace\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\" prefix1:href=\"http://foo.de\" xmlns:prefix1=\"namespaceForAnno\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"EmployeeId\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<Property Name=\"EmployeeName\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\" annoPrefix:annoName=\"annoText\">" + "<annoPrefix:propertyAnnoElement>text</annoPrefix:propertyAnnoElement>" + "<annoPrefix:propertyAnnoElement2 />" + "</Property>" + "</EntityType>" + "<annoPrefix:schemaElementTest1>" + "<prefix:schemaElementTest2 xmlns:prefix=\"namespace\">text3" + "</prefix:schemaElementTest2>"
+ + "<annoPrefix:schemaElementTest3 rel=\"self\" pre:href=\"http://foo.com\" xmlns:pre=\"namespaceForAnno\">text4</annoPrefix:schemaElementTest3>" + " </annoPrefix:schemaElementTest1>" + "</Schema>"
+ "</edmx:DataServices>" + "</edmx:Edmx>";
EdmParser parser = new EdmParser();
XMLStreamReader reader = createStreamReader(xmlWithAnnotations);
@@ -660,7 +694,7 @@ public class EdmParserTest extends AbstractXmlProducerTestHelper {
assertEquals("href", childAnnoElement.getAttributes().get(1).getName());
assertEquals("pre", childAnnoElement.getAttributes().get(1).getPrefix());
assertEquals("namespaceForAnno", childAnnoElement.getAttributes().get(1).getNamespace());
- assertEquals("http://google.com", childAnnoElement.getAttributes().get(1).getText());
+ assertEquals("http://foo.com", childAnnoElement.getAttributes().get(1).getText());
} else {
throw new EntityProviderException(null, "xmlWithAnnotations");
}
@@ -672,7 +706,7 @@ public class EdmParserTest extends AbstractXmlProducerTestHelper {
assertEquals("href", attr.getName());
assertEquals("prefix1", attr.getPrefix());
assertEquals("namespaceForAnno", attr.getNamespace());
- assertEquals("http://google.de", attr.getText());
+ assertEquals("http://foo.de", attr.getText());
for (Property property : entityType.getProperties()) {
if ("EmployeeName".equals(property.getName())) {
assertEquals(2, property.getAnnotationElements().size());