本文整理汇总了Java中org.apache.olingo.odata2.api.edm.provider.Schema.setNamespace方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.setNamespace方法的具体用法?Java Schema.setNamespace怎么用?Java Schema.setNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.olingo.odata2.api.edm.provider.Schema
的用法示例。
在下文中一共展示了Schema.setNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeInvalidMetadata
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Test(expected = Exception.class)
public void writeInvalidMetadata() throws Exception {
disableLogging(this.getClass());
List<Schema> schemas = new ArrayList<Schema>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
annotationElements.add(new AnnotationElement().setText("hallo"));
Schema schema = new Schema().setAnnotationElements(annotationElements);
schema.setNamespace("http://namespace.com");
schemas.add(schema);
DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
OutputStreamWriter writer = null;
CircleStreamBuffer csb = new CircleStreamBuffer();
writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
}
示例2: getSchemas
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Override
public List<Schema> getSchemas() throws ODataMessageException {
final Schema schema = new Schema();
schema.setNamespace(NAMESPACE_1);
schema.setEntityTypes(Arrays.asList(
getEntityType(ET_KEY_IS_STRING),
getEntityType(ET_KEY_IS_INTEGER),
getEntityType(ET_COMPLEX_KEY),
getEntityType(ET_ALL_TYPES)));
schema.setComplexTypes(Arrays.asList(getComplexType(CT_ALL_TYPES)));
final EntityContainer entityContainer = new EntityContainer();
entityContainer.setName(ENTITY_CONTAINER_1).setDefaultEntityContainer(true);
entityContainer.setEntitySets(Arrays.asList(
getEntitySet(ENTITY_CONTAINER_1, ES_KEY_IS_STRING),
getEntitySet(ENTITY_CONTAINER_1, ES_KEY_IS_INTEGER),
getEntitySet(ENTITY_CONTAINER_1, ES_COMPLEX_KEY),
getEntitySet(ENTITY_CONTAINER_1, ES_ALL_TYPES),
getEntitySet(ENTITY_CONTAINER_1, ES_STRING_FACETS)));
schema.setEntityContainers(Arrays.asList(entityContainer));
return Arrays.asList(schema);
}
示例3: build
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
public Schema build() {
Schema s = new Schema();
s.setUsings(usings);
s.setEntityTypes(entityTypes);
s.setComplexTypes(complexTypes);
s.setAssociations(new ArrayList<Association>(name2Associations.values()));
s.setEntityContainers(entityContainers);
s.setAnnotationAttributes(annotationAttributes);
s.setAnnotationElements(annotationElements);
s.setNamespace(namespace);
return s;
}
示例4: createMockEdmSchema
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
public static Schema createMockEdmSchema() {
Schema schema = new Schema();
schema.setNamespace(NAMESPACE);
schema.setComplexTypes(createComplexTypes());
schema.setEntityContainers(createEntityContainer());
schema.setEntityTypes(createEntityTypes());
schema.setAssociations(createAssociations());
return schema;
}
示例5: writeValidMetadata
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Test
public void writeValidMetadata() throws Exception {
List<Schema> schemas = new ArrayList<Schema>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
annotationElements.add(new AnnotationElement().setName("test").setText("hallo"));
Schema schema = new Schema().setAnnotationElements(annotationElements);
schema.setNamespace("http://namespace.com");
schemas.add(schema);
DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
OutputStreamWriter writer = null;
CircleStreamBuffer csb = new CircleStreamBuffer();
writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
Map<String, String> prefixMap = new HashMap<String, String>();
prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
XMLUnit.setXpathNamespaceContext(ctx);
String metadata = StringHelper.inputStreamToString(csb.getInputStream());
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:test", metadata);
}
示例6: writeValidMetadata4
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Test
public void writeValidMetadata4() throws Exception {
List<Schema> schemas = new ArrayList<Schema>();
List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self"));
attributesElement1.add(new AnnotationAttribute().setName("href").setText("link"));
List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
schemaElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
Schema schema = new Schema().setAnnotationElements(schemaElements);
schema.setNamespace("http://namespace.com");
schemas.add(schema);
DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
OutputStreamWriter writer = null;
CircleStreamBuffer csb = new CircleStreamBuffer();
writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
String metadata = StringHelper.inputStreamToString(csb.getInputStream());
Map<String, String> prefixMap = new HashMap<String, String>();
prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
prefixMap.put("atom", "http://www.w3.org/2005/Atom");
NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
XMLUnit.setXpathNamespaceContext(ctx);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest2", metadata);
}
示例7: writeValidMetadata5
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Test
public void writeValidMetadata5() throws Exception {
List<Schema> schemas = new ArrayList<Schema>();
List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom"));
attributesElement1.add(new AnnotationAttribute().setName("href").setText("link").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom"));
List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
schemaElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
Schema schema = new Schema().setAnnotationElements(schemaElements);
schema.setNamespace("http://namespace.com");
schemas.add(schema);
DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
OutputStreamWriter writer = null;
CircleStreamBuffer csb = new CircleStreamBuffer();
writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
String metadata = StringHelper.inputStreamToString(csb.getInputStream());
Map<String, String> prefixMap = new HashMap<String, String>();
prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
prefixMap.put("atom", "http://www.w3.org/2005/Atom");
NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
XMLUnit.setXpathNamespaceContext(ctx);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest2", metadata);
}
示例8: getSchemas
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Override
public List<Schema> getSchemas() throws ODataException
{
List<Schema> schemas = new ArrayList<>();
Schema schema = new Schema();
schema.setNamespace(NAMESPACE);
fr.gael.dhus.database.object.User u = Security.getCurrentUser();
ArrayList<EntityType> entities = new ArrayList<>();
ArrayList<EntitySet> entitysets = new ArrayList<>();
ArrayList<Association> associations = new ArrayList<>();
ArrayList<AssociationSet> association_sets = new ArrayList<>();
List<FunctionImport> function_imports = new ArrayList<>();
for (AbstractEntitySet<?> entitySet: ENTITYSETS.values())
{
if (entitySet.isAuthorized(u))
{
entities.add(entitySet.getEntityType());
entitysets.add(entitySet.getEntitySet());
associations.addAll(entitySet.getAssociations());
association_sets.addAll(entitySet.getAssociationSets());
}
}
for (AbstractOperation op: OPERATIONS.values())
{
if (op.canExecute(u))
{
function_imports.add(op.getFunctionImport());
}
}
schema.setEntityTypes(entities);
schema.setComplexTypes(new ArrayList<>(COMPLEX_TYPES.values()));
schema.setAssociations(new ArrayList<>(associations));
EntityContainer entityContainer = new EntityContainer();
entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
entityContainer.setEntitySets(entitysets);
entityContainer.setAssociationSets(new ArrayList<>(association_sets));
entityContainer.setFunctionImports(function_imports);
schema.setEntityContainers(Collections.singletonList(entityContainer));
schemas.add(schema);
return schemas;
}
示例9: getEdmSchema
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Override
public Schema getEdmSchema() {
Schema schema = new Schema();
schema.setNamespace("salesordereprocessing");
return schema;
}
示例10: readSchema
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
private Schema readSchema(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_SCHEMA);
Schema schema = new Schema();
List<Using> usings = new ArrayList<Using>();
List<ComplexType> complexTypes = new ArrayList<ComplexType>();
List<EntityType> entityTypes = new ArrayList<EntityType>();
List<Association> associations = new ArrayList<Association>();
List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
schema.setNamespace(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_NAMESPACE));
inscopeMap.put(schema.getNamespace(), new HashSet<String>());
schema.setAlias(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_ALIAS));
schema.setAnnotationAttributes(readAnnotationAttribute(reader));
currentNamespace = schema.getNamespace();
while (reader.hasNext()
&& !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
&& XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
currentHandledStartTagName = reader.getLocalName();
if (XmlMetadataConstants.EDM_USING.equals(currentHandledStartTagName)) {
usings.add(readUsing(reader, schema.getNamespace()));
} else if (XmlMetadataConstants.EDM_ENTITY_TYPE.equals(currentHandledStartTagName)) {
entityTypes.add(readEntityType(reader));
} else if (XmlMetadataConstants.EDM_COMPLEX_TYPE.equals(currentHandledStartTagName)) {
complexTypes.add(readComplexType(reader));
} else if (XmlMetadataConstants.EDM_ASSOCIATION.equals(currentHandledStartTagName)) {
associations.add(readAssociation(reader));
} else if (XmlMetadataConstants.EDM_ENTITY_CONTAINER.equals(currentHandledStartTagName)) {
entityContainers.add(readEntityContainer(reader));
} else {
annotationElements.add(readAnnotationElement(reader));
}
}
}
if (schema.getAlias() != null) {
aliasNamespaceMap.put(schema.getAlias(), schema.getNamespace());
}
if (!annotationElements.isEmpty()) {
schema.setAnnotationElements(annotationElements);
}
schema.setUsings(usings).setEntityTypes(entityTypes).setComplexTypes(complexTypes).setAssociations(associations)
.setEntityContainers(entityContainers);
return schema;
}
示例11: writeValidMetadata2
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Test
public void writeValidMetadata2() throws Exception {
List<Schema> schemas = new ArrayList<Schema>();
List<AnnotationElement> childElements = new ArrayList<AnnotationElement>();
childElements
.add(new AnnotationElement().setName("schemaElementTest2").setText("text2").setNamespace("namespace1"));
List<AnnotationAttribute> elementAttributes = new ArrayList<AnnotationAttribute>();
elementAttributes.add(new AnnotationAttribute().setName("rel").setText("self"));
elementAttributes.add(new AnnotationAttribute().setName("href").setText("http://google.com").setPrefix("pre")
.setNamespace("namespaceForAnno"));
List<AnnotationElement> element3List = new ArrayList<AnnotationElement>();
element3List.add(new AnnotationElement().setName("schemaElementTest4").setText("text4").setAttributes(
elementAttributes));
childElements.add(new AnnotationElement().setName("schemaElementTest3").setText("text3").setPrefix("prefix")
.setNamespace("namespace2").setChildElements(element3List));
List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setText("text1").setChildElements(
childElements));
schemaElements.add(new AnnotationElement().setName("test"));
Schema schema = new Schema().setAnnotationElements(schemaElements);
schema.setNamespace("http://namespace.com");
schemas.add(schema);
DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
OutputStreamWriter writer = null;
CircleStreamBuffer csb = new CircleStreamBuffer();
writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
Map<String, String> prefixMap = new HashMap<String, String>();
prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
prefixMap.put("b", "namespace1");
prefixMap.put("prefix", "namespace2");
prefixMap.put("pre", "namespaceForAnno");
NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
XMLUnit.setXpathNamespaceContext(ctx);
String metadata = StringHelper.inputStreamToString(csb.getInputStream());
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:test", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:schemaElementTest1", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:schemaElementTest1/b:schemaElementTest2", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:schemaElementTest1/prefix:schemaElementTest3", metadata);
assertXpathExists(
"/edmx:Edmx/edmx:DataServices/a:Schema/a:schemaElementTest1/prefix:schemaElementTest3/" +
"a:schemaElementTest4[@rel=\"self\" and @pre:href=\"http://google.com\"]",
metadata);
}
示例12: writeValidMetadata3
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Test
public void writeValidMetadata3() throws Exception {
List<Schema> schemas = new ArrayList<Schema>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
annotationElements.add(new AnnotationElement().setName("test").setText("hallo)"));
Schema schema = new Schema().setAnnotationElements(annotationElements);
schema.setNamespace("http://namespace.com");
schemas.add(schema);
List<PropertyRef> keys = new ArrayList<PropertyRef>();
keys.add(new PropertyRef().setName("Id"));
Key key = new Key().setKeys(keys);
List<Property> properties = new ArrayList<Property>();
properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.String));
EntityType entityType = new EntityType().setName("testType").setKey(key).setProperties(properties);
entityType.setDocumentation(new Documentation());
List<PropertyRef> keys2 = new ArrayList<PropertyRef>();
keys2.add(new PropertyRef().setName("SecondId"));
Key key2 = new Key().setKeys(keys2);
List<Property> properties2 = new ArrayList<Property>();
properties2.add(new SimpleProperty().setName("SecondId").setType(EdmSimpleTypeKind.String));
EntityType entityType2 = new EntityType().setName("SecondTestType").setKey(key2).setProperties(properties2);
entityType2.setDocumentation(new Documentation().setSummary("Doc_TlDr").setLongDescription("Some long desc."));
List<EntityType> entityTypes = new ArrayList<EntityType>();
entityTypes.add(entityType);
entityTypes.add(entityType2);
schema.setEntityTypes(entityTypes);
DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
CircleStreamBuffer csb = new CircleStreamBuffer();
OutputStreamWriter writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
Map<String, String> prefixMap = new HashMap<String, String>();
prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
XMLUnit.setXpathNamespaceContext(ctx);
String metadata = StringHelper.inputStreamToString(csb.getInputStream());
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:test", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:EntityType[@Name=\"testType\"]", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/" +
"a:EntityType[@Name=\"SecondTestType\"]/a:Documentation/a:Summary", metadata);
}
示例13: writeValidMetadata6
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Test
public void writeValidMetadata6() throws Exception {
List<Schema> schemas = new ArrayList<Schema>();
List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom"));
attributesElement1.add(new AnnotationAttribute().setName("href").setText("link").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom"));
List<AnnotationElement> elementElements = new ArrayList<AnnotationElement>();
elementElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
elementElements.add(new AnnotationElement().setName("schemaElementTest3").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace(
"http://www.w3.org/2005/Atom").setAttributes(attributesElement1).setChildElements(elementElements));
Schema schema = new Schema().setAnnotationElements(schemaElements);
schema.setNamespace("http://namespace.com");
schemas.add(schema);
DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
OutputStreamWriter writer = null;
CircleStreamBuffer csb = new CircleStreamBuffer();
writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
String metadata = StringHelper.inputStreamToString(csb.getInputStream());
Map<String, String> prefixMap = new HashMap<String, String>();
prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
prefixMap.put("atom", "http://www.w3.org/2005/Atom");
NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
XMLUnit.setXpathNamespaceContext(ctx);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1/atom:schemaElementTest2",
metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1/atom:schemaElementTest3",
metadata);
}
示例14: writeWithPredefinedNamespaces
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
@Test
public void writeWithPredefinedNamespaces() throws Exception {
// prepare
List<Schema> schemas = new ArrayList<Schema>();
List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self").setPrefix("foo").setNamespace(
"http://www.foo.bar/Protocols/Data"));
attributesElement1.add(new AnnotationAttribute().setName("href").setText("link").setPrefix("foo").setNamespace(
"http://www.foo.bar/Protocols/Data"));
List<AnnotationElement> elementElements = new ArrayList<AnnotationElement>();
elementElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("foo").setNamespace(
"http://www.foo.bar/Protocols/Data").setAttributes(attributesElement1));
elementElements.add(new AnnotationElement().setName("schemaElementTest3").setPrefix("foo").setNamespace(
"http://www.foo.bar/Protocols/Data").setAttributes(attributesElement1));
List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("foo").setNamespace(
"http://www.foo.bar/Protocols/Data").setAttributes(attributesElement1).setChildElements(elementElements));
Schema schema = new Schema().setAnnotationElements(schemaElements);
schema.setNamespace("http://namespace.com");
schemas.add(schema);
// Execute
Map<String, String> predefinedNamespaces = new HashMap<String, String>();
predefinedNamespaces.put("foo", "http://www.foo.bar/Protocols/Data");
DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
OutputStreamWriter writer = null;
CircleStreamBuffer csb = new CircleStreamBuffer();
writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, predefinedNamespaces);
String metadata = StringHelper.inputStreamToString(csb.getInputStream());
// Verify
Map<String, String> prefixMap = new HashMap<String, String>();
prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
prefixMap.put("foo", "http://www.foo.bar/Protocols/Data");
NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
XMLUnit.setXpathNamespaceContext(ctx);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/foo:schemaElementTest1", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/foo:schemaElementTest1/foo:schemaElementTest2", metadata);
assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/foo:schemaElementTest1/foo:schemaElementTest3", metadata);
}
示例15: buildSchema
import org.apache.olingo.odata2.api.edm.provider.Schema; //导入方法依赖的package包/类
private void buildSchema() {
propertyRef = new PropertyRef();
propertyRef.setName("p1");
key = new Key();
key.setKeys(Arrays.asList(propertyRef));
property1 =
new SimpleProperty().setName(mapping[P1][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
new Mapping().setObject(mapping[P1][BACKEND]));
property2 =
new SimpleProperty().setName(mapping[P2][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
new Mapping().setObject(mapping[P2][BACKEND]));
property3 =
new SimpleProperty().setName(mapping[P3][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
new Mapping().setObject(mapping[P3][BACKEND]));
entityType = new EntityType();
entityType.setName(mapping[ENTITYTYPE][EDM]);
entityType.setKey(key);
entityType.setProperties(Arrays.asList(property1, property2, property3));
entityType.setMapping(new Mapping().setObject(mapping[ENTITYTYPE][BACKEND]));
entitySet = new EntitySet();
entitySet.setName(mapping[ENTITYSET][EDM]);
entitySet.setEntityType(new FullQualifiedName(NAMESPACE, mapping[ENTITYTYPE][EDM]));
entitySet.setMapping(new Mapping().setObject(mapping[ENTITYSET][BACKEND]));
entityContainer = new EntityContainer();
entityContainer.setDefaultEntityContainer(true);
entityContainer.setName(MAPPING_CONTAINER);
entityContainer.setEntitySets(Arrays.asList(entitySet));
schema = new Schema();
schema.setNamespace("mapping");
schema.setAlias(NAMESPACE);
schema.setEntityContainers(Arrays.asList(entityContainer));
schema.setEntityTypes(Arrays.asList(entityType));
schemas = Arrays.asList(schema);
}