You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/03/12 10:53:54 UTC
[1/3] [OLINGO-168] Enhance Edm for Service Document serialization
Repository: incubator-olingo-odata4
Updated Branches:
refs/heads/olingo167 [created] 44aadbd68
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
new file mode 100644
index 0000000..2342eae
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.edm.provider;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataException;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmActionImport;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.EdmSchema;
+import org.apache.olingo.commons.api.edm.EdmSingleton;
+import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.edm.provider.Action;
+import org.apache.olingo.server.api.edm.provider.ActionImport;
+import org.apache.olingo.server.api.edm.provider.AliasInfo;
+import org.apache.olingo.server.api.edm.provider.ComplexType;
+import org.apache.olingo.server.api.edm.provider.EdmProvider;
+import org.apache.olingo.server.api.edm.provider.EntityContainer;
+import org.apache.olingo.server.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.server.api.edm.provider.EntitySet;
+import org.apache.olingo.server.api.edm.provider.EntityType;
+import org.apache.olingo.server.api.edm.provider.EnumType;
+import org.apache.olingo.server.api.edm.provider.Function;
+import org.apache.olingo.server.api.edm.provider.FunctionImport;
+import org.apache.olingo.server.api.edm.provider.Schema;
+import org.apache.olingo.server.api.edm.provider.Singleton;
+import org.apache.olingo.server.api.edm.provider.Term;
+import org.apache.olingo.server.api.edm.provider.TypeDefinition;
+import org.junit.Before;
+import org.junit.Test;
+
+public class EdmSchemaImplTest {
+
+ private EdmSchema schema;
+ private Edm edm;
+
+ @Before
+ public void before() {
+ EdmProvider provider = new LocalProvider();
+ edm = new EdmProviderImpl(provider);
+ schema = edm.getSchemas().get(0);
+
+ }
+
+ @Test
+ public void initialSchemaTest() {
+ EdmProvider provider = mock(EdmProvider.class);
+ edm = new EdmProviderImpl(provider);
+ edm.getSchemas();
+ }
+
+ @Test
+ public void emptySchemaTest() throws Exception {
+ ArrayList<Schema> schemas = new ArrayList<Schema>();
+ Schema providerSchema = new Schema();
+ schemas.add(providerSchema );
+ EdmProvider provider = mock(EdmProvider.class);
+ when(provider.getSchemas()).thenReturn(schemas);
+ edm = new EdmProviderImpl(provider);
+ edm.getSchemas();
+ }
+
+ @Test
+ public void basicGetters() {
+ assertEquals("namespace", schema.getNamespace());
+ assertEquals("alias", schema.getAlias());
+ }
+
+ @Test
+ public void getTypeDefinitions(){
+ List<EdmTypeDefinition> typeDefinitions = schema.getTypeDefinitions();
+ assertNotNull(typeDefinitions);
+ assertEquals(2, typeDefinitions.size());
+
+ for(EdmTypeDefinition def : typeDefinitions){
+ assertTrue(def == edm.getTypeDefinition(new FullQualifiedName("namespace", def.getName())));
+ }
+ }
+
+ @Test
+ public void getEnumTypes() {
+ List<EdmEnumType> enumTypes = schema.getEnumTypes();
+ assertNotNull(enumTypes);
+ assertEquals(2, enumTypes.size());
+
+ for (EdmEnumType enumType : enumTypes) {
+ assertTrue(enumType == edm.getEnumType(new FullQualifiedName("namespace", enumType.getName())));
+ }
+ }
+
+ @Test
+ public void getEntityTypes() {
+ List<EdmEntityType> entityTypes = schema.getEntityTypes();
+ assertNotNull(entityTypes);
+ assertEquals(2, entityTypes.size());
+
+ for (EdmEntityType entityType : entityTypes) {
+ assertTrue(entityType == edm.getEntityType(new FullQualifiedName("namespace", entityType.getName())));
+ }
+ }
+
+ @Test
+ public void getComplexTypes() {
+ List<EdmComplexType> complexTypes = schema.getComplexTypes();
+ assertNotNull(complexTypes);
+ assertEquals(2, complexTypes.size());
+
+ for (EdmComplexType complexType : complexTypes) {
+ assertTrue(complexType == edm.getComplexType(new FullQualifiedName("namespace", complexType.getName())));
+ }
+ }
+
+ @Test
+ public void getActions() {
+ List<EdmAction> actions = schema.getActions();
+ assertNotNull(actions);
+ assertEquals(2, actions.size());
+
+ for (EdmAction action : actions) {
+ assertTrue(action == edm.getAction(new FullQualifiedName("namespace", action.getName()), null, null));
+ }
+ }
+
+ @Test
+ public void getFunctions() {
+ List<EdmFunction> functions = schema.getFunctions();
+ assertNotNull(functions);
+ assertEquals(2, functions.size());
+
+ for (EdmFunction function : functions) {
+ FullQualifiedName functionName = new FullQualifiedName("namespace", function.getName());
+ assertTrue(function == edm.getFunction(functionName, null, null, null));
+ }
+ }
+
+ @Test
+ public void getContainer() {
+ EdmEntityContainer container = schema.getEntityContainer();
+ assertNotNull(container);
+
+ List<EdmEntitySet> entitySets = container.getEntitySets();
+ assertNotNull(entitySets);
+ assertEquals(2, entitySets.size());
+ for (EdmEntitySet obj : entitySets) {
+ assertNotNull(obj.getEntityType());
+ }
+
+ List<EdmSingleton> singletons = container.getSingletons();
+ assertNotNull(singletons);
+ assertEquals(2, singletons.size());
+ for (EdmSingleton obj : singletons) {
+ assertNotNull(obj.getEntityType());
+ }
+
+ List<EdmActionImport> actionImports = container.getActionImports();
+ assertNotNull(actionImports);
+ assertEquals(2, actionImports.size());
+ for (EdmActionImport obj : actionImports) {
+ assertNotNull(obj.getAction());
+ }
+
+ List<EdmFunctionImport> functionImports = container.getFunctionImports();
+ assertNotNull(functionImports);
+ assertEquals(2, functionImports.size());
+ for (EdmFunctionImport obj : functionImports) {
+ assertNotNull(obj.getFunctionFqn());
+ }
+
+ assertTrue(container == edm.getEntityContainer(new FullQualifiedName(schema.getNamespace(), container.getName())));
+ assertTrue(container == edm.getEntityContainer(null));
+ }
+
+ private class LocalProvider extends EdmProvider {
+
+ public EnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public TypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public List<Action> getActions(final FullQualifiedName actionName) throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public List<Function> getFunctions(final FullQualifiedName functionName) throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public Term getTerm(final FullQualifiedName termName) throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
+ throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public Singleton getSingleton(final FullQualifiedName entityContainer, final String singletonName)
+ throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public ActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
+ throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public FunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName)
+ throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public EntityContainerInfo getEntityContainerInfo(final FullQualifiedName entityContainerName)
+ throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public List<AliasInfo> getAliasInfos() throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+
+ public List<Schema> getSchemas() throws ODataException {
+ Schema providerSchema = new Schema();
+ providerSchema.setNamespace("namespace");
+ providerSchema.setAlias("alias");
+ EntityContainer container = new EntityContainer().setName("container");
+
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ entitySets.add(new EntitySet().setName("entitySetName")
+ .setType(new FullQualifiedName("namespace", "entityType1")));
+ entitySets
+ .add(new EntitySet().setName("entitySetName2").setType(new FullQualifiedName("namespace", "entityType2")));
+ container.setEntitySets(entitySets);
+
+ List<Singleton> singletons = new ArrayList<Singleton>();
+ singletons.add(new Singleton().setName("singletonName")
+ .setType(new FullQualifiedName("namespace", "entityType1")));
+ singletons
+ .add(new Singleton().setName("singletonName2").setType(new FullQualifiedName("namespace", "entityType2")));
+ container.setSingletons(singletons);
+
+ List<ActionImport> actionImports = new ArrayList<ActionImport>();
+ actionImports.add(new ActionImport().setName("actionImportName").setAction(
+ new FullQualifiedName("namespace", "action1")));
+ actionImports.add(new ActionImport().setName("actionImportName2").setAction(
+ new FullQualifiedName("namespace", "action2")));
+ container.setActionImports(actionImports);
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ functionImports.add(new FunctionImport().setName("functionImportName").setFunction(
+ new FullQualifiedName("namespace", "function1")));
+ functionImports.add(new FunctionImport().setName("functionImportName2").setFunction(
+ new FullQualifiedName("namespace", "function2")));
+ container.setFunctionImports(functionImports);
+ providerSchema.setEntityContainer(container);
+
+ List<TypeDefinition> typeDefinitions = new ArrayList<TypeDefinition>();
+ typeDefinitions.add(new TypeDefinition().setName("typeDefinition1"));
+ typeDefinitions.add(new TypeDefinition().setName("typeDefinition2"));
+ providerSchema.setTypeDefinitions(typeDefinitions);
+
+ List<EnumType> enumTypes = new ArrayList<EnumType>();
+ enumTypes.add(new EnumType().setName("enumType1"));
+ enumTypes.add(new EnumType().setName("enumType2"));
+ providerSchema.setEnumTypes(enumTypes);
+
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ entityTypes.add(new EntityType().setName("entityType1"));
+ entityTypes.add(new EntityType().setName("entityType2"));
+ providerSchema.setEntityTypes(entityTypes);
+
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ complexTypes.add(new ComplexType().setName("complexType1"));
+ complexTypes.add(new ComplexType().setName("complexType2"));
+ providerSchema.setComplexTypes(complexTypes);
+
+ List<Action> actions = new ArrayList<Action>();
+ actions.add(new Action().setName("action1"));
+ actions.add(new Action().setName("action2"));
+ providerSchema.setActions(actions);
+
+ List<Function> functions = new ArrayList<Function>();
+ functions.add(new Function().setName("function1"));
+ functions.add(new Function().setName("function2"));
+ providerSchema.setFunctions(functions);
+ ArrayList<Schema> schemas = new ArrayList<Schema>();
+ schemas.add(providerSchema);
+ return schemas;
+ }
+
+ public EntityContainer getEntityContainer() throws ODataException {
+ throw new RuntimeException("Provider must not be called in the schema case");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
index 7de5ed3..9b57bdb 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
@@ -69,7 +69,8 @@ public class EdmTypeDefinitionImplTest {
FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
TypeDefinition providerTypeDef =
new TypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("wrong", "wrong"));
- new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
+ EdmTypeDefinitionImpl def = new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
+ def.getUnderlyingType();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/StringUtils.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/StringUtils.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/StringUtils.java
new file mode 100644
index 0000000..b7d8e2c
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/StringUtils.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.testutil;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
+public class StringUtils {
+
+ public static String inputStreamToString(final InputStream in, final boolean preserveLineBreaks) {
+ try {
+ final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
+ final StringBuilder stringBuilder = new StringBuilder();
+ String line = null;
+
+ while ((line = bufferedReader.readLine()) != null) {
+ stringBuilder.append(line);
+ if (preserveLineBreaks) {
+ stringBuilder.append("\n");
+ }
+ }
+
+ bufferedReader.close();
+
+ final String result = stringBuilder.toString();
+
+ return result;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 3421ff1..c5645e8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,7 @@
<jackson.version>2.3.2</jackson.version>
<antlr.version>4.1</antlr.version>
-
+
<sl4j.version>1.7.6</sl4j.version>
</properties>
[2/3] [OLINGO-168] Enhance Edm for Service Document serialization
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/CircleStreamBuffer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/CircleStreamBuffer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/CircleStreamBuffer.java
new file mode 100644
index 0000000..6784f87
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/CircleStreamBuffer.java
@@ -0,0 +1,327 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Circular stream buffer to write/read into/from one single buffer.
+ * With support of {@link InputStream} and {@link OutputStream} access to buffered data.
+ *
+ *
+ */
+public class CircleStreamBuffer {
+
+ private static final int NEW_BUFFER_RESIZE_FACTOR = 2;
+ private static final int READ_EOF = -1;
+ private static final int DEFAULT_CAPACITY = 8192;
+ private static final int MAX_CAPACITY = DEFAULT_CAPACITY * 32;
+
+ private int currentAllocateCapacity = DEFAULT_CAPACITY;
+
+ private boolean writeMode = true;
+ private boolean writeClosed = false;
+ private boolean readClosed = false;
+
+ private Queue<ByteBuffer> bufferQueue = new LinkedBlockingQueue<ByteBuffer>();
+ private ByteBuffer currentWriteBuffer;
+
+ private InternalInputStream inStream;
+ private InternalOutputStream outStream;
+
+ /**
+ * Creates a {@link CircleStreamBuffer} with default buffer size.
+ */
+ public CircleStreamBuffer() {
+ this(DEFAULT_CAPACITY);
+ }
+
+ /**
+ * Create a {@link CircleStreamBuffer} with given buffer size in bytes.
+ *
+ * @param bufferSize
+ */
+ public CircleStreamBuffer(final int bufferSize) {
+ currentAllocateCapacity = bufferSize;
+ createNewWriteBuffer();
+ inStream = new InternalInputStream(this);
+ outStream = new InternalOutputStream(this);
+ }
+
+ /**
+ * Get {@link InputStream} for data read access.
+ *
+ * @return the stream
+ */
+ public InputStream getInputStream() {
+ return inStream;
+ }
+
+ /**
+ * Get {@link OutputStream} for write data.
+ *
+ * @return the stream
+ */
+ public OutputStream getOutputStream() {
+ return outStream;
+ }
+
+ // #############################################
+ // #
+ // # Common parts
+ // #
+ // #############################################
+
+ /**
+ * Closes the write (input) part of the {@link CircleStreamBuffer}.
+ * After this call the buffer can only be read out.
+ */
+ public void closeWrite() {
+ writeClosed = true;
+ }
+
+ /**
+ * Closes the read (output) part of the {@link CircleStreamBuffer}.
+ * After this call it is possible to write into the buffer (but can never be read out).
+ */
+ public void closeRead() {
+ readClosed = true;
+ // clear references to byte buffers
+ ByteBuffer buffer = bufferQueue.poll();
+ while (buffer != null) {
+ buffer.clear();
+ buffer = bufferQueue.poll();
+ }
+ }
+
+ /**
+ * Closes write and read part (and hence the complete buffer).
+ */
+ public void close() {
+ closeWrite();
+ closeRead();
+ }
+
+ private int remaining() throws IOException {
+ if (writeMode) {
+ return currentWriteBuffer.remaining();
+ } else {
+ ByteBuffer toRead = getReadBuffer();
+ if (toRead == null) {
+ return 0;
+ }
+ return toRead.remaining();
+ }
+ }
+
+ // #############################################
+ // #
+ // # Reading parts
+ // #
+ // #############################################
+
+ private ByteBuffer getReadBuffer() throws IOException {
+ if (readClosed) {
+ throw new IOException("Tried to read from closed stream.");
+ }
+
+ boolean next = false;
+ ByteBuffer tmp = null;
+ if (writeMode) {
+ writeMode = false;
+ next = true;
+ } else {
+ tmp = bufferQueue.peek();
+ if (tmp != null && !tmp.hasRemaining()) {
+ tmp = bufferQueue.poll();
+ next = true;
+ }
+ }
+
+ if (next) {
+ tmp = bufferQueue.peek();
+ if (tmp != null) {
+ tmp.flip();
+ }
+ tmp = getReadBuffer();
+ }
+
+ return tmp;
+ }
+
+ private int read(final byte[] b, final int off, final int len) throws IOException {
+ ByteBuffer readBuffer = getReadBuffer();
+ if (readBuffer == null) {
+ return READ_EOF;
+ }
+
+ int toReadLength = readBuffer.remaining();
+ if (len < toReadLength) {
+ toReadLength = len;
+ }
+ readBuffer.get(b, off, toReadLength);
+ return toReadLength;
+ }
+
+ private int read() throws IOException {
+ ByteBuffer readBuffer = getReadBuffer();
+ if (readBuffer == null) {
+ return READ_EOF;
+ }
+
+ return readBuffer.get();
+ }
+
+ // #############################################
+ // #
+ // # Writing parts
+ // #
+ // #############################################
+
+ private void write(final byte[] data, final int off, final int len) throws IOException {
+ ByteBuffer writeBuffer = getWriteBuffer(len);
+ writeBuffer.put(data, off, len);
+ }
+
+ private ByteBuffer getWriteBuffer(final int size) throws IOException {
+ if (writeClosed) {
+ throw new IOException("Tried to write into closed stream.");
+ }
+
+ if (writeMode) {
+ if (remaining() < size) {
+ createNewWriteBuffer(size);
+ }
+ } else {
+ writeMode = true;
+ createNewWriteBuffer();
+ }
+
+ return currentWriteBuffer;
+ }
+
+ private void write(final int b) throws IOException {
+ ByteBuffer writeBuffer = getWriteBuffer(1);
+ writeBuffer.put((byte) b);
+ }
+
+ private void createNewWriteBuffer() {
+ createNewWriteBuffer(currentAllocateCapacity);
+ }
+
+ /**
+ * Creates a new buffer (per {@link #allocateBuffer(int)}) with the requested capacity as minimum capacity, add the
+ * new allocated
+ * buffer to the {@link #bufferQueue} and set it as {@link #currentWriteBuffer}.
+ *
+ * @param requestedCapacity minimum capacity for new allocated buffer
+ */
+ private void createNewWriteBuffer(final int requestedCapacity) {
+ ByteBuffer b = allocateBuffer(requestedCapacity);
+ bufferQueue.add(b);
+ currentWriteBuffer = b;
+ }
+
+ /**
+ *
+ * @param requestedCapacity
+ * @return the buffer
+ */
+ private ByteBuffer allocateBuffer(final int requestedCapacity) {
+ int allocateCapacity = requestedCapacity;
+ if (allocateCapacity < currentAllocateCapacity) {
+ allocateCapacity = currentAllocateCapacity * NEW_BUFFER_RESIZE_FACTOR;
+ }
+ if (allocateCapacity > MAX_CAPACITY) {
+ allocateCapacity = MAX_CAPACITY;
+ }
+ // update current
+ currentAllocateCapacity = allocateCapacity;
+ return ByteBuffer.allocate(allocateCapacity);
+ }
+
+ // #############################################
+ // #
+ // # Inner classes (streams)
+ // #
+ // #############################################
+
+ /**
+ *
+ */
+ private static class InternalInputStream extends InputStream {
+
+ private final CircleStreamBuffer inBuffer;
+
+ public InternalInputStream(final CircleStreamBuffer csBuffer) {
+ inBuffer = csBuffer;
+ }
+
+ @Override
+ public int available() throws IOException {
+ return inBuffer.remaining();
+ }
+
+ @Override
+ public int read() throws IOException {
+ return inBuffer.read();
+ }
+
+ @Override
+ public int read(final byte[] b, final int off, final int len) throws IOException {
+ return inBuffer.read(b, off, len);
+ }
+
+ @Override
+ public void close() throws IOException {
+ inBuffer.closeRead();
+ }
+ }
+
+ /**
+ *
+ */
+ private static class InternalOutputStream extends OutputStream {
+ private final CircleStreamBuffer outBuffer;
+
+ public InternalOutputStream(final CircleStreamBuffer csBuffer) {
+ outBuffer = csBuffer;
+ }
+
+ @Override
+ public void write(final int b) throws IOException {
+ outBuffer.write(b);
+ }
+
+ @Override
+ public void write(final byte[] b, final int off, final int len) throws IOException {
+ outBuffer.write(b, off, len);
+ }
+
+ @Override
+ public void close() throws IOException {
+ outBuffer.closeWrite();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataJsonSerializer.java
new file mode 100644
index 0000000..57a0d84
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataJsonSerializer.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+
+import org.apache.olingo.commons.api.ODataRuntimeException;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.EdmSingleton;
+import org.apache.olingo.server.api.ODataSerializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
+
+public class ODataJsonSerializer implements ODataSerializer {
+
+ private static final Logger log = LoggerFactory.getLogger(ODataJsonSerializer.class);
+
+ private static final String DEFAULT_CHARSET = "UTF-8";
+
+ public static final String ODATA_CONTEXT = "@odata.context";
+ public static final String METADATA = "$metadata";
+ public static final String VALUE = "value";
+ public static final String NAME = "name";
+ public static final String URL = "url";
+ public static final String KIND = "kind";
+
+ public static final String FUNCTION_IMPORT = "FunctionImport";
+ public static final String SINGLETON = "Singleton";
+ public static final String SERVICE_DOCUMENT = "ServiceDocument";
+
+ @Override
+ public InputStream metadata(Edm edm) {
+ throw new ODataRuntimeException("Metadata in JSON format not supported!");
+ }
+
+ @Override
+ public InputStream serviceDocument(Edm edm, String serviceRoot) {
+ CircleStreamBuffer buffer;
+ BufferedWriter writer;
+ JsonFactory factory;
+ JsonGenerator gen = null;
+
+ try {
+ buffer = new CircleStreamBuffer();
+ writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET));
+ factory = new JsonFactory();
+ gen = factory.createGenerator(writer);
+
+ gen.setPrettyPrinter(new DefaultPrettyPrinter());
+
+ gen.writeStartObject();
+
+ Object metadataUri = serviceRoot + "/" + METADATA;
+ gen.writeObjectField(ODATA_CONTEXT, metadataUri);
+ gen.writeArrayFieldStart(VALUE);
+
+ writeEntitySets(gen, edm);
+ writeFunctionImports(gen, edm);
+ writeSingletons(gen, edm);
+
+ gen.close();
+
+// writer.flush();
+// buffer.closeWrite();
+
+ return buffer.getInputStream();
+
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ throw new ODataRuntimeException(e);
+ } finally {
+ if (gen != null) {
+ try {
+ gen.close();
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e);
+ }
+ }
+ }
+ }
+
+ private void writeEntitySets(JsonGenerator gen, Edm edm) throws JsonGenerationException, IOException {
+ EdmEntityContainer container = edm.getEntityContainer(null);
+
+ for (EdmEntitySet edmEntitySet : container.getEntitySets()) {
+ if (edmEntitySet.isIncludeInServiceDocument()) {
+ gen.writeStartObject();
+ gen.writeObjectField(NAME, edmEntitySet.getName());
+ gen.writeObjectField(URL, edmEntitySet.getName());
+ gen.writeEndObject();
+ }
+ }
+ }
+
+ private void writeFunctionImports(JsonGenerator gen, Edm edm) throws JsonGenerationException, IOException {
+ EdmEntityContainer container = edm.getEntityContainer(null);
+
+ for (EdmFunctionImport edmFunctionImport : container.getFunctionImports()) {
+ if (edmFunctionImport.isIncludeInServiceDocument()) {
+ gen.writeStartObject();
+ gen.writeObjectField(NAME, edmFunctionImport.getName());
+ gen.writeObjectField(URL, edmFunctionImport.getName());
+ gen.writeObjectField(KIND, FUNCTION_IMPORT);
+ gen.writeEndObject();
+ }
+ }
+ }
+
+ private void writeSingletons(JsonGenerator gen, Edm edm) throws JsonGenerationException, IOException {
+ EdmEntityContainer container = edm.getEntityContainer(null);
+
+ for (EdmSingleton edmSingleton : container.getSingletons()) {
+ gen.writeStartObject();
+ gen.writeObjectField(NAME, edmSingleton.getName());
+ gen.writeObjectField(URL, edmSingleton.getName());
+ gen.writeObjectField(KIND, SINGLETON);
+ gen.writeEndObject();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataSerializerImpl.java
new file mode 100644
index 0000000..3950e0c
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataSerializerImpl.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core;
+
+import java.io.InputStream;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.server.api.ODataSerializer;
+
+public class ODataSerializerImpl implements ODataSerializer {
+
+ @Override
+ public InputStream metadata(Edm edm) {
+ return null;
+ }
+
+ @Override
+ public InputStream serviceDocument(Edm edm, String serviceRoot) {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataServerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataServerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataServerImpl.java
new file mode 100644
index 0000000..a634b2e
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataServerImpl.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core;
+
+import org.apache.olingo.commons.api.ODataRuntimeException;
+import org.apache.olingo.server.api.ODataFormat;
+import org.apache.olingo.server.api.ODataSerializer;
+import org.apache.olingo.server.api.ODataServer;
+
+public class ODataServerImpl extends ODataServer {
+
+ @Override
+ public ODataSerializer getSerializer(ODataFormat format) {
+ ODataSerializer serializer;
+ switch (format) {
+ case JSON:
+ serializer = new ODataJsonSerializer();
+ break;
+ case XML:
+ serializer = new ODataSerializerImpl();
+ break;
+ default:
+ throw new ODataRuntimeException("Unsupported format: " + format);
+ }
+
+ return serializer;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java
index d423525..991d348 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java
@@ -28,10 +28,9 @@ public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmAc
private final ActionImport actionImport;
- public EdmActionImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
- final ActionImport actionImport) {
+ public EdmActionImportImpl(final Edm edm, final EdmEntityContainer container, final ActionImport actionImport) {
- super(edm, container, name, actionImport);
+ super(edm, container, actionImport);
this.actionImport = actionImport;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImpl.java
index baa0591..4199e08 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImpl.java
@@ -1,23 +1,25 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.server.core.edm.provider;
+import java.util.List;
+
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmActionImport;
@@ -25,9 +27,11 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.commons.api.edm.EdmSingleton;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.core.edm.AbstractEdmEntityContainer;
import org.apache.olingo.server.api.edm.provider.ActionImport;
import org.apache.olingo.server.api.edm.provider.EdmProvider;
+import org.apache.olingo.server.api.edm.provider.EntityContainer;
import org.apache.olingo.server.api.edm.provider.EntityContainerInfo;
import org.apache.olingo.server.api.edm.provider.EntitySet;
import org.apache.olingo.server.api.edm.provider.FunctionImport;
@@ -36,14 +40,22 @@ import org.apache.olingo.server.api.edm.provider.Singleton;
public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
private final EdmProvider provider;
+ private EntityContainer container;
public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider,
- final EntityContainerInfo entityContainerInfo) {
+ final EntityContainerInfo entityContainerInfo) {
super(edm, entityContainerInfo.getContainerName());
this.provider = provider;
}
+ public EdmEntityContainerImpl(Edm edm, EdmProvider provider, FullQualifiedName containerFQN,
+ EntityContainer entityContainer) {
+ super(edm, containerFQN);
+ this.provider = provider;
+ this.container = entityContainer;
+ }
+
@Override
protected EdmSingleton createSingleton(final String singletonName) {
EdmSingleton singleton = null;
@@ -83,7 +95,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
try {
final ActionImport providerImport = provider.getActionImport(entityContainerName, actionImportName);
if (providerImport != null) {
- actionImport = new EdmActionImportImpl(edm, this, actionImportName, providerImport);
+ actionImport = new EdmActionImportImpl(edm, this, providerImport);
}
} catch (ODataException e) {
throw new EdmException(e);
@@ -99,7 +111,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
try {
final FunctionImport providerImport = provider.getFunctionImport(entityContainerName, functionImportName);
if (providerImport != null) {
- functionImport = new EdmFunctionImportImpl(edm, this, functionImportName, providerImport);
+ functionImport = new EdmFunctionImportImpl(edm, this, providerImport);
}
} catch (ODataException e) {
throw new EdmException(e);
@@ -108,4 +120,77 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
return functionImport;
}
+ @Override
+ protected void loadAllEntitySets() {
+ loadContainer();
+ List<EntitySet> providerEntitySets = container.getEntitySets();
+ if (providerEntitySets != null) {
+ for (EntitySet entitySet : providerEntitySets) {
+ if (!entitySets.containsKey(entitySet.getName())) {
+ EdmEntitySetImpl impl = new EdmEntitySetImpl(edm, this, entitySet);
+ entitySets.put(impl.getName(), impl);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void loadAllFunctionImports() {
+ loadContainer();
+ List<FunctionImport> providerFuctionImports = container.getFunctionImports();
+ if (providerFuctionImports != null) {
+ for (FunctionImport functionImport : providerFuctionImports) {
+ String functionName = functionImport.getName();
+ if (!functionImports.containsKey(functionName)) {
+ EdmFunctionImportImpl impl = new EdmFunctionImportImpl(edm, this, functionImport);
+ functionImports.put(functionName, impl);
+ }
+ }
+ }
+
+ }
+
+ @Override
+ protected void loadAllSingletons() {
+ loadContainer();
+ List<Singleton> providerSingletons = container.getSingletons();
+ if (providerSingletons != null) {
+ for (Singleton singleton : providerSingletons) {
+ if (!singletons.containsKey(singleton.getName())) {
+ EdmSingletonImpl impl = new EdmSingletonImpl(edm, this, singleton);
+ singletons.put(singleton.getName(), impl);
+ }
+ }
+ }
+
+ }
+
+ @Override
+ protected void loadAllActionImports() {
+ loadContainer();
+ List<ActionImport> providerActionImports = container.getActionImports();
+ if (providerActionImports != null) {
+ for (ActionImport actionImport : providerActionImports) {
+ if (!actionImports.containsKey(actionImport.getName())) {
+ EdmActionImportImpl impl = new EdmActionImportImpl(edm, this, actionImport);
+ actionImports.put(actionImport.getName(), impl);
+ }
+ }
+ }
+
+ }
+
+ private void loadContainer() {
+ if (container == null) {
+ try {
+ container = provider.getEntityContainer();
+ if (container == null) {
+ // TODO: Should we throw an exception here?
+ container = new EntityContainer().setName(this.getName());
+ }
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImpl.java
index d5de2c5..492095b 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImpl.java
@@ -25,8 +25,15 @@ import org.apache.olingo.server.api.edm.provider.EntitySet;
public class EdmEntitySetImpl extends EdmBindingTargetImpl implements EdmEntitySet {
+ private EntitySet entitySet;
+
public EdmEntitySetImpl(final Edm edm, final EdmEntityContainer container, final EntitySet entitySet) {
super(edm, container, entitySet);
+ this.entitySet = entitySet;
}
+ @Override
+ public boolean isIncludeInServiceDocument() {
+ return entitySet.isIncludeInServiceDocument();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java
index 8437384..8bb8c2d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java
@@ -24,7 +24,6 @@ import java.util.Map;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.commons.api.edm.EdmProperty;
@@ -38,8 +37,6 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
private final EdmStructuredTypeHelper helper;
- private final EntityType entityType;
-
public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName name,
final EntityType entityType) {
@@ -50,9 +47,6 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
instance.entityBaseType = null;
final List<PropertyRef> key = entityType.getKey();
- if (key == null && !entityType.isAbstract()) {
- throw new EdmException("Non-Abstract entity types must define a key.");
- }
if (key != null) {
final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>();
for (PropertyRef ref : key) {
@@ -71,7 +65,6 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
super(edm, name, entityType.getBaseType(), entityType.hasStream());
this.helper = new EdmStructuredTypeHelperImpl(edm, entityType);
- this.entityType = entityType;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEnumTypeImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEnumTypeImpl.java
index cb263c7..faceb0e 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEnumTypeImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEnumTypeImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.server.core.edm.provider;
import java.util.List;
+import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmMember;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
@@ -34,7 +35,7 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType
private final EnumType enumType;
- public EdmEnumTypeImpl(final EdmProviderImpl edm, final FullQualifiedName enumName, final EnumType enumType) {
+ public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final EnumType enumType) {
super(edm, enumName, enumType.isFlags());
if (enumType.getUnderlyingType() == null) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java
index e91b105..e9a06c5 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java
@@ -1,18 +1,18 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -24,16 +24,16 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmFunction;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.server.api.edm.provider.FunctionImport;
public class EdmFunctionImportImpl extends EdmOperationImportImpl implements EdmFunctionImport {
private final FunctionImport functionImport;
- public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
- final FunctionImport functionImport) {
+ public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final FunctionImport functionImport) {
- super(edm, container, name, functionImport);
+ super(edm, container, functionImport);
this.functionImport = functionImport;
}
@@ -42,4 +42,13 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm
return edm.getFunction(functionImport.getFunction(), null, null, parameterNames);
}
+ @Override
+ public boolean isIncludeInServiceDocument() {
+ return functionImport.isIncludeInServiceDocument();
+ }
+
+ @Override
+ public FullQualifiedName getFunctionFqn() {
+ return functionImport.getFunction();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImpl.java
index 9d6546c..e1d0f4c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImpl.java
@@ -1,18 +1,18 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -59,9 +59,27 @@ public abstract class EdmOperationImpl extends AbstractEdmOperation {
}
protected EdmOperationImpl(final Edm edm, final FullQualifiedName name, final Operation operation,
- final EdmTypeKind kind) {
+ final EdmTypeKind kind) {
super(edm, name, kind);
this.operation = operation;
}
+
+ @Override
+ public FullQualifiedName getBindingParameterTypeFqn() {
+ if (isBound()) {
+ Parameter bindingParameter = operation.getParameters().get(0);
+ return bindingParameter.getType();
+ }
+ return null;
+ }
+
+ @Override
+ public Boolean isBindingParameterTypeCollection() {
+ if (isBound()) {
+ Parameter bindingParameter = operation.getParameters().get(0);
+ return bindingParameter.isCollection();
+ }
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImportImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImportImpl.java
index a6371df..f2badd7 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImportImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmOperationImportImpl.java
@@ -1,18 +1,18 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -25,9 +25,8 @@ import org.apache.olingo.server.api.edm.provider.OperationImport;
public abstract class EdmOperationImportImpl extends AbstractEdmOperationImport {
- public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
- final OperationImport operationImport) {
-
- super(edm, container, name, operationImport.getEntitySet());
+ public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container,
+ final OperationImport operationImport) {
+ super(edm, container, operationImport.getName(), operationImport.getEntitySet());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
index 1d240ad..e4cf9b2 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
@@ -1,18 +1,18 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -32,6 +32,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmSchema;
import org.apache.olingo.commons.api.edm.EdmServiceMetadata;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -45,6 +46,7 @@ import org.apache.olingo.server.api.edm.provider.EntityType;
import org.apache.olingo.server.api.edm.provider.EnumType;
import org.apache.olingo.server.api.edm.provider.Function;
import org.apache.olingo.server.api.edm.provider.Parameter;
+import org.apache.olingo.server.api.edm.provider.Schema;
import org.apache.olingo.server.api.edm.provider.TypeDefinition;
public class EdmProviderImpl extends AbstractEdmImpl {
@@ -127,8 +129,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
@Override
public EdmAction createBoundAction(final FullQualifiedName actionName,
- final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) {
-
+ final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) {
+
try {
List<Action> actions = actionsMap.get(actionName);
if (actions == null) {
@@ -145,8 +147,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
final List<Parameter> parameters = action.getParameters();
final Parameter parameter = parameters.get(0);
if (bindingParameterTypeName.equals(parameter.getType())
- && isBindingParameterCollection.booleanValue() == parameter.isCollection()) {
-
+ && isBindingParameterCollection.booleanValue() == parameter.isCollection()) {
+
return EdmActionImpl.getInstance(this, actionName, action);
}
@@ -160,9 +162,9 @@ public class EdmProviderImpl extends AbstractEdmImpl {
@Override
public EdmFunction createBoundFunction(final FullQualifiedName functionName,
- final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection,
- final List<String> parameterNames) {
-
+ final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection,
+ final List<String> parameterNames) {
+
try {
List<Function> functions = functionsMap.get(functionName);
if (functions == null) {
@@ -173,7 +175,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
functionsMap.put(functionName, functions);
}
}
- final List<String> parameterNamesCopy = parameterNames == null? Collections.<String>emptyList(): parameterNames;
+ final List<String> parameterNamesCopy =
+ parameterNames == null ? Collections.<String> emptyList() : parameterNames;
for (Function function : functions) {
if (function.isBound()) {
List<Parameter> providerParameters = function.getParameters();
@@ -182,8 +185,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
}
final Parameter bindingParameter = providerParameters.get(0);
if (bindingParameterTypeName.equals(bindingParameter.getType())
- && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) {
-
+ && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) {
+
if (parameterNamesCopy.size() == providerParameters.size() - 1) {
final List<String> providerParameterNames = new ArrayList<String>();
for (int i = 1; i < providerParameters.size(); i++) {
@@ -259,7 +262,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
return null;
}
}
- final List<String> parameterNamesCopy = parameterNames == null? Collections.<String>emptyList(): parameterNames;
+ final List<String> parameterNamesCopy =
+ parameterNames == null ? Collections.<String> emptyList() : parameterNames;
for (Function function : functions) {
if (!function.isBound()) {
List<Parameter> providerParameters = function.getParameters();
@@ -284,4 +288,16 @@ public class EdmProviderImpl extends AbstractEdmImpl {
}
}
+ @Override
+ protected List<EdmSchema> createSchemas() {
+ try {
+ List<EdmSchema> schemas = new ArrayList<EdmSchema>();
+ for (Schema schema : provider.getSchemas()) {
+ schemas.add(new EdmSchemaImpl(this, provider, schema));
+ }
+ return schemas;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImpl.java
new file mode 100644
index 0000000..af98a41
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImpl.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.edm.provider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.core.edm.AbstractEdmSchemaImpl;
+import org.apache.olingo.server.api.edm.provider.Action;
+import org.apache.olingo.server.api.edm.provider.ComplexType;
+import org.apache.olingo.server.api.edm.provider.EdmProvider;
+import org.apache.olingo.server.api.edm.provider.EntityType;
+import org.apache.olingo.server.api.edm.provider.EnumType;
+import org.apache.olingo.server.api.edm.provider.Function;
+import org.apache.olingo.server.api.edm.provider.Schema;
+import org.apache.olingo.server.api.edm.provider.TypeDefinition;
+
+public class EdmSchemaImpl extends AbstractEdmSchemaImpl {
+
+ private final Schema schema;
+ private final Edm edm;
+ private final EdmProvider provider;
+
+ public EdmSchemaImpl(Edm edm, EdmProvider provider, Schema schema) {
+ super(schema.getNamespace(), schema.getAlias());
+ this.edm = edm;
+ this.provider = provider;
+ this.schema = schema;
+ }
+
+ @Override
+ protected EdmEntityContainer createEntityContainer() {
+ if (schema.getEntityContainer() != null) {
+ FullQualifiedName containerFQN =
+ new FullQualifiedName(namespace, schema.getEntityContainer().getName());
+ return new EdmEntityContainerImpl(edm, provider, containerFQN, schema.getEntityContainer());
+ }
+ return null;
+ }
+
+ @Override
+ protected List<EdmTypeDefinition> createTypeDefinitions() {
+ List<EdmTypeDefinition> typeDefinitions = new ArrayList<EdmTypeDefinition>();
+ List<TypeDefinition> providerTypeDefinitions = schema.getTypeDefinitions();
+ if (providerTypeDefinitions != null) {
+ for (TypeDefinition def : providerTypeDefinitions) {
+ typeDefinitions.add(new EdmTypeDefinitionImpl(edm, new FullQualifiedName("namespace", def.getName()), def));
+ }
+ }
+ return typeDefinitions;
+ }
+
+ @Override
+ protected List<EdmEnumType> createEnumTypes() {
+ List<EdmEnumType> enumTypes = new ArrayList<EdmEnumType>();
+ List<EnumType> providerEnumTypes = schema.getEnumTypes();
+ if (providerEnumTypes != null) {
+ for (EnumType enumType : providerEnumTypes) {
+ enumTypes.add(new EdmEnumTypeImpl(edm, new FullQualifiedName(namespace, enumType.getName()), enumType));
+ }
+ }
+ return enumTypes;
+ }
+
+ @Override
+ protected List<EdmEntityType> createEntityTypes() {
+ List<EdmEntityType> entityTypes = new ArrayList<EdmEntityType>();
+ List<EntityType> providerEntityTypes = schema.getEntityTypes();
+ if (providerEntityTypes != null) {
+ for (EntityType entityType : providerEntityTypes) {
+ entityTypes.add(EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName(namespace, entityType.getName()),
+ entityType));
+ }
+ }
+ return entityTypes;
+ }
+
+ @Override
+ protected List<EdmComplexType> createComplexTypes() {
+ List<EdmComplexType> complexTypes = new ArrayList<EdmComplexType>();
+ List<ComplexType> providerComplexTypes = schema.getComplexTypes();
+ if (providerComplexTypes != null) {
+ for (ComplexType complexType : providerComplexTypes) {
+ complexTypes.add(EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName(namespace, complexType.getName()),
+ complexType));
+ }
+ }
+ return complexTypes;
+ }
+
+ @Override
+ protected List<EdmAction> createActions() {
+ List<EdmAction> actions = new ArrayList<EdmAction>();
+ List<Action> providerActions = schema.getActions();
+ if (providerActions != null) {
+ for (Action action : providerActions) {
+ actions.add(EdmActionImpl.getInstance(edm, new FullQualifiedName(namespace, action.getName()), action));
+ }
+ }
+ return actions;
+ }
+
+ @Override
+ protected List<EdmFunction> createFunctions() {
+ List<EdmFunction> functions = new ArrayList<EdmFunction>();
+ List<Function> providerFunctions = schema.getFunctions();
+ if (providerFunctions != null) {
+ for (Function function : providerFunctions) {
+ functions.add(EdmFunctionImpl.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function));
+ }
+ }
+ return functions;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImpl.java
index 0eec8c5..1c6fb0b 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImpl.java
@@ -1,18 +1,18 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -34,21 +34,22 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition implements
private EdmPrimitiveType edmPrimitiveTypeInstance;
public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName,
- final TypeDefinition typeDefinition) {
+ final TypeDefinition typeDefinition) {
super(edm, typeDefinitionName);
this.typeDefinition = typeDefinition;
- // TODO: Should we check for edmNamespace in the underlying type name?
- try {
- edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.valueOf(
- typeDefinition.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance();
- } catch (IllegalArgumentException e) {
- throw new EdmException("Invalid underlying type: " + typeDefinitionName, e);
- }
}
@Override
public EdmPrimitiveType getUnderlyingType() {
+ if (edmPrimitiveTypeInstance == null) {
+ try {
+ edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.valueOf(
+ typeDefinition.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance();
+ } catch (IllegalArgumentException e) {
+ throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
+ }
+ }
return edmPrimitiveTypeInstance;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/test/java/org/apache/olingo/server/core/ServiceDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/ServiceDocumentTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/ServiceDocumentTest.java
new file mode 100644
index 0000000..8d08820
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/ServiceDocumentTest.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.EdmSingleton;
+import org.apache.olingo.server.api.ODataFormat;
+import org.apache.olingo.server.api.ODataSerializer;
+import org.apache.olingo.server.api.ODataServer;
+import org.apache.olingo.server.core.testutil.StringUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ServiceDocumentTest {
+
+ private Edm edm;
+
+ @Before
+ public void before() {
+
+ EdmEntitySet edmEntitySet1 = mock(EdmEntitySet.class);
+ when(edmEntitySet1.getName()).thenReturn("entitySetName1");
+ when(edmEntitySet1.isIncludeInServiceDocument()).thenReturn(true);
+
+ EdmEntitySet edmEntitySet2 = mock(EdmEntitySet.class);
+ when(edmEntitySet2.getName()).thenReturn("entitySetName2");
+ when(edmEntitySet2.isIncludeInServiceDocument()).thenReturn(true);
+
+ EdmEntitySet edmEntitySet3 = mock(EdmEntitySet.class);
+ when(edmEntitySet3.getName()).thenReturn("entitySetName3");
+ when(edmEntitySet3.isIncludeInServiceDocument()).thenReturn(false);
+
+ List<EdmEntitySet> entitySets = new ArrayList<EdmEntitySet>();
+ entitySets.add(edmEntitySet1);
+ entitySets.add(edmEntitySet2);
+ entitySets.add(edmEntitySet3);
+
+ EdmFunctionImport functionImport1 = mock(EdmFunctionImport.class);
+ when(functionImport1.getName()).thenReturn("functionImport1");
+ when(functionImport1.isIncludeInServiceDocument()).thenReturn(true);
+
+ EdmFunctionImport functionImport2 = mock(EdmFunctionImport.class);
+ when(functionImport2.getName()).thenReturn("functionImport2");
+ when(functionImport2.isIncludeInServiceDocument()).thenReturn(true);
+
+ EdmFunctionImport functionImport3 = mock(EdmFunctionImport.class);
+ when(functionImport3.getName()).thenReturn("functionImport3");
+ when(functionImport3.isIncludeInServiceDocument()).thenReturn(false);
+
+ List<EdmFunctionImport> functionImports = new ArrayList<EdmFunctionImport>();
+ functionImports.add(functionImport1);
+ functionImports.add(functionImport2);
+ functionImports.add(functionImport3);
+
+ EdmSingleton singleton1 = mock(EdmSingleton.class);
+ when(singleton1.getName()).thenReturn("singleton1");
+
+ EdmSingleton singleton2 = mock(EdmSingleton.class);
+ when(singleton2.getName()).thenReturn("singleton2");
+
+ EdmSingleton singleton3 = mock(EdmSingleton.class);
+ when(singleton3.getName()).thenReturn("singleton3");
+
+ List<EdmSingleton> singletons = new ArrayList<EdmSingleton>();
+ singletons.add(singleton1);
+ singletons.add(singleton2);
+ singletons.add(singleton3);
+
+ EdmEntityContainer edmEntityContainer = mock(EdmEntityContainer.class);
+ when(edmEntityContainer.getEntitySets()).thenReturn(entitySets);
+ when(edmEntityContainer.getFunctionImports()).thenReturn(functionImports);
+ when(edmEntityContainer.getSingletons()).thenReturn(singletons);
+
+ edm = mock(Edm.class);
+ when(edm.getEntityContainer(null)).thenReturn(edmEntityContainer);
+ }
+
+ @Test
+ public void writeServiceDocumentJson() throws Exception {
+ String serviceRoot = "http://localhost:8080/odata.svc";
+
+ ODataServer server = ODataServer.newInstance();
+ assertNotNull(server);
+
+ ODataSerializer serializer = server.getSerializer(ODataFormat.JSON);
+ assertNotNull(serializer);
+
+ InputStream result = serializer.serviceDocument(edm, serviceRoot);
+ assertNotNull(result);
+ String jsonString = StringUtils.inputStreamToString(result, true);
+
+ assertTrue(jsonString.contains("entitySetName1"));
+ assertTrue(jsonString.contains("entitySetName2"));
+ assertFalse(jsonString.contains("entitySetName3"));
+
+ assertTrue(jsonString.contains("functionImport1"));
+ assertTrue(jsonString.contains("functionImport2"));
+ assertFalse(jsonString.contains("functionImport3"));
+
+ assertTrue(jsonString.contains("singleton1"));
+ assertTrue(jsonString.contains("singleton2"));
+ assertTrue(jsonString.contains("singleton3"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
index dfd9871..97be017 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
@@ -1,18 +1,18 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -52,8 +52,8 @@ public class EdmActionImportImplTest {
FullQualifiedName actionFqn = new FullQualifiedName("namespace", "actionName");
FullQualifiedName entityContainerFqn = new FullQualifiedName("namespace", "containerName");
Target target = new Target().setEntityContainer(entityContainerFqn).setTargetName("entitySetName");
- ActionImport providerActionImport
- = new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target);
+ ActionImport providerActionImport =
+ new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target);
EdmProviderImpl edm = mock(EdmProviderImpl.class);
container = mock(EdmEntityContainer.class);
@@ -63,7 +63,7 @@ public class EdmActionImportImplTest {
entitySet = mock(EdmEntitySet.class);
when(container.getEntitySet("entitySetName")).thenReturn(entitySet);
- actionImport = new EdmActionImportImpl(edm, container, "actionImportName", providerActionImport);
+ actionImport = new EdmActionImportImpl(edm, container, providerActionImport);
}
@Test
@@ -87,8 +87,8 @@ public class EdmActionImportImplTest {
public void getReturnedEntitySetNonExistingContainer() {
Target target = new Target();
ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target);
- EdmActionImport actionImport
- = new EdmActionImportImpl(mock(EdmProviderImpl.class), container, "actionImportName", providerActionImport);
+ EdmActionImport actionImport =
+ new EdmActionImportImpl(mock(EdmProviderImpl.class), container, providerActionImport);
actionImport.getReturnedEntitySet();
}
@@ -98,7 +98,7 @@ public class EdmActionImportImplTest {
ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target);
EdmProviderImpl edm = mock(EdmProviderImpl.class);
when(edm.getEntityContainer(null)).thenReturn(container);
- EdmActionImport actionImport = new EdmActionImportImpl(edm, container, "actionImportName", providerActionImport);
+ EdmActionImport actionImport = new EdmActionImportImpl(edm, container, providerActionImport);
actionImport.getReturnedEntitySet();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
index 9372de5..d813a27 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
@@ -26,6 +26,9 @@ import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.EdmActionImport;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
@@ -36,6 +39,7 @@ import org.apache.olingo.commons.api.edm.EdmSingleton;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.server.api.edm.provider.ActionImport;
import org.apache.olingo.server.api.edm.provider.EdmProvider;
+import org.apache.olingo.server.api.edm.provider.EntityContainer;
import org.apache.olingo.server.api.edm.provider.EntityContainerInfo;
import org.apache.olingo.server.api.edm.provider.EntitySet;
import org.apache.olingo.server.api.edm.provider.FunctionImport;
@@ -57,6 +61,110 @@ public class EdmEntityContainerImplTest {
new EntityContainerInfo().setContainerName(new FullQualifiedName("space", "name"));
container = new EdmEntityContainerImpl(edm, provider, entityContainerInfo);
}
+
+ @Test
+ public void getAllEntitySetInitial(){
+ List<EdmEntitySet> entitySets = container.getEntitySets();
+ assertNotNull(entitySets);
+ assertEquals(2, entitySets.size());
+ }
+
+ @Test
+ public void getAllEntitySetsAfterOneWasAlreadyLoaded(){
+ EdmEntitySet entitySet = container.getEntitySet("entitySetName");
+ List<EdmEntitySet> entitySets = container.getEntitySets();
+ assertNotNull(entitySets);
+ assertEquals(2, entitySets.size());
+ boolean contained = false;
+ for(EdmEntitySet es: entitySets){
+ //Already loaded entity set must be the same
+ if(es.getName().equals("entitySetName")){
+ assertTrue(entitySet == es);
+ contained = true;
+ }
+ }
+ if(!contained){
+ fail("Should have found entity set in this list.");
+ }
+ }
+
+ @Test
+ public void getAllSingletonsInitial(){
+ List<EdmSingleton> singletons = container.getSingletons();
+ assertNotNull(singletons);
+ assertEquals(2, singletons.size());
+ }
+
+ @Test
+ public void getAllSingletonsAfterOneWasAlreadyLoaded(){
+ EdmSingleton singleton = container.getSingleton("singletonName");
+ List<EdmSingleton> singletons = container.getSingletons();
+ assertNotNull(singletons);
+ assertEquals(2, singletons.size());
+ boolean contained = false;
+ for(EdmSingleton s: singletons){
+ //Already loaded singleton must be the same
+ if(s.getName().equals("singletonName")){
+ assertTrue(singleton == s);
+ contained = true;
+ }
+ }
+ if(!contained){
+ fail("Should have found singleton in this list.");
+ }
+ }
+
+ @Test
+ public void getAllActionImportsInitial(){
+ List<EdmActionImport> actionImports = container.getActionImports();
+ assertNotNull(actionImports);
+ assertEquals(2, actionImports.size());
+ }
+
+ @Test
+ public void getAllActionImportsAfterOneWasAlreadyLoaded(){
+ EdmActionImport actionImport = container.getActionImport("actionImportName");
+ List<EdmActionImport> actionImports = container.getActionImports();
+ assertNotNull(actionImports);
+ assertEquals(2, actionImports.size());
+ boolean contained = false;
+ for(EdmActionImport ai: actionImports){
+ //Already loaded action import must be the same
+ if(ai.getName().equals("actionImportName")){
+ assertTrue(actionImport == ai);
+ contained = true;
+ }
+ }
+ if(!contained){
+ fail("Should have found action import in this list.");
+ }
+ }
+
+ @Test
+ public void getAllFunctionImportsInitial(){
+ List<EdmFunctionImport> functionImports = container.getFunctionImports();
+ assertNotNull(functionImports);
+ assertEquals(2, functionImports.size());
+ }
+
+ @Test
+ public void getAllFunctionImportsAfterOneWasAlreadyLoaded(){
+ EdmFunctionImport functionImport = container.getFunctionImport("functionImportName");
+ List<EdmFunctionImport> functionImports = container.getFunctionImports();
+ assertNotNull(functionImports);
+ assertEquals(2, functionImports.size());
+ boolean contained = false;
+ for(EdmFunctionImport fi: functionImports){
+ //Already loaded function import must be the same
+ if(fi.getName().equals("functionImportName")){
+ assertTrue(functionImport == fi);
+ contained = true;
+ }
+ }
+ if(!contained){
+ fail("Should have found function import in this list.");
+ }
+ }
@Test
public void checkEdmExceptionConversion() throws Exception {
@@ -190,7 +298,7 @@ public class EdmEntityContainerImplTest {
public ActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
throws ODataException {
if (actionImportName != null) {
- return new ActionImport().setName("singletonName");
+ return new ActionImport().setName("actionImportName");
}
return null;
}
@@ -199,9 +307,35 @@ public class EdmEntityContainerImplTest {
public FunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName)
throws ODataException {
if (functionImportName != null) {
- return new FunctionImport().setName("singletonName");
+ return new FunctionImport().setName("functionImportName");
}
return null;
}
+
+ @Override
+ public EntityContainer getEntityContainer() throws ODataException {
+ EntityContainer container = new EntityContainer();
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ entitySets.add(new EntitySet().setName("entitySetName"));
+ entitySets.add(new EntitySet().setName("entitySetName2"));
+ container.setEntitySets(entitySets );
+
+ List<Singleton> singletons = new ArrayList<Singleton>();
+ singletons.add(new Singleton().setName("singletonName"));
+ singletons.add(new Singleton().setName("singletonName2"));
+ container.setSingletons(singletons );
+
+ List<ActionImport> actionImports = new ArrayList<ActionImport>();
+ actionImports.add(new ActionImport().setName("actionImportName"));
+ actionImports.add(new ActionImport().setName("actionImportName2"));
+ container.setActionImports(actionImports );
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ functionImports.add(new FunctionImport().setName("functionImportName"));
+ functionImports.add(new FunctionImport().setName("functionImportName2"));
+ container.setFunctionImports(functionImports );
+
+ return container;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
index dde8f3e..6bcc6bd 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
@@ -244,13 +244,6 @@ public class EdmEntityTypeImplTest {
assertTrue(property == typeWithBaseType.getProperty("nav2"));
}
- @Test(expected = EdmException.class)
- public void noKeyOnTypeWithoutBaseTypeMustResultInException() {
- EdmProviderImpl edm = mock(EdmProviderImpl.class);
- EntityType entityType = new EntityType().setName("n");
- EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
- }
-
@Test
public void abstractTypeDoesNotNeedKey() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java
index d0cd1db..4f4b302 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java
@@ -72,9 +72,9 @@ public class EdmFunctionImportImplTest {
when(provider.getFunctionImport(containerName, functionImportName)).thenReturn(functionImportProvider);
final EdmFunctionImport functionImport =
- new EdmFunctionImportImpl(edm, entityContainer, "test", functionImportProvider);
+ new EdmFunctionImportImpl(edm, entityContainer, functionImportProvider);
assertEquals(functionImportName, entityContainer.getFunctionImport(functionImportName).getName());
- assertEquals("test", functionImport.getName());
+ assertEquals("functionImport", functionImport.getName());
final EdmFunction function = functionImport.getFunction(Collections.<String> emptyList());
assertEquals(functionName.getNamespace(), function.getNamespace());
assertEquals(functionName.getName(), function.getName());
[3/3] git commit: [OLINGO-168] Enhance Edm for Service Document
serialization
Posted by ch...@apache.org.
[OLINGO-168] Enhance Edm for Service Document serialization
Also implemented a first version of the service document serializer. This
has still to be moved into the commons core.
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/commit/44aadbd6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/tree/44aadbd6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/diff/44aadbd6
Branch: refs/heads/olingo167
Commit: 44aadbd686ab9c5ece1c842d66ed9cc87c73d43e
Parents: 897db8e
Author: Christian Amend <ch...@apache.org>
Authored: Wed Mar 12 10:50:29 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Mar 12 10:50:29 2014 +0100
----------------------------------------------------------------------
.../olingo/client/api/edm/xml/v4/Parameter.java | 3 +
.../olingo/client/core/edm/EdmActionImpl.java | 1 -
.../olingo/client/core/edm/EdmClientImpl.java | 11 +
.../client/core/edm/EdmEntityContainerImpl.java | 118 +++++--
.../client/core/edm/EdmEntitySetImpl.java | 7 +
.../client/core/edm/EdmFunctionImportImpl.java | 30 +-
.../client/core/edm/EdmOperationImpl.java | 19 ++
.../olingo/client/core/edm/EdmSchemaImpl.java | 163 +++++++++
.../client/core/edm/v3/EdmEntitySetProxy.java | 6 +
.../core/edm/v3/EdmFunctionImportProxy.java | 13 +
.../client/core/edm/v3/EdmOperationProxy.java | 12 +
.../client/core/edm/xml/v4/ParameterImpl.java | 12 +
.../commons/api/ODataRuntimeException.java | 37 ++
.../org/apache/olingo/commons/api/edm/Edm.java | 6 +
.../commons/api/edm/EdmEntityContainer.java | 52 ++-
.../olingo/commons/api/edm/EdmEntitySet.java | 5 +
.../commons/api/edm/EdmFunctionImport.java | 10 +
.../olingo/commons/api/edm/EdmOperation.java | 10 +
.../olingo/commons/api/edm/EdmSchema.java | 70 ++++
.../commons/api/edm/FullQualifiedName.java | 26 +-
.../core/edm/AbstractEdmEntityContainer.java | 71 +++-
.../commons/core/edm/AbstractEdmImpl.java | 157 ++++++---
.../commons/core/edm/AbstractEdmSchemaImpl.java | 128 +++++++
.../commons/core/edm/EdmImplCachingTest.java | 21 ++
.../commons/core/edm/EdmImplCallCreateTest.java | 12 +
.../apache/olingo/server/api/ODataFormat.java | 23 ++
.../olingo/server/api/ODataSerializer.java | 31 ++
.../apache/olingo/server/api/ODataServer.java | 48 +++
.../server/api/edm/provider/EdmProvider.java | 8 +
lib/server-core/pom.xml | 135 ++++----
.../olingo/server/core/CircleStreamBuffer.java | 327 ++++++++++++++++++
.../olingo/server/core/ODataJsonSerializer.java | 147 ++++++++
.../olingo/server/core/ODataSerializerImpl.java | 38 +++
.../olingo/server/core/ODataServerImpl.java | 45 +++
.../core/edm/provider/EdmActionImportImpl.java | 5 +-
.../edm/provider/EdmEntityContainerImpl.java | 107 +++++-
.../core/edm/provider/EdmEntitySetImpl.java | 7 +
.../core/edm/provider/EdmEntityTypeImpl.java | 7 -
.../core/edm/provider/EdmEnumTypeImpl.java | 3 +-
.../edm/provider/EdmFunctionImportImpl.java | 31 +-
.../core/edm/provider/EdmOperationImpl.java | 36 +-
.../edm/provider/EdmOperationImportImpl.java | 23 +-
.../core/edm/provider/EdmProviderImpl.java | 54 +--
.../server/core/edm/provider/EdmSchemaImpl.java | 139 ++++++++
.../edm/provider/EdmTypeDefinitionImpl.java | 33 +-
.../olingo/server/core/ServiceDocumentTest.java | 133 ++++++++
.../edm/provider/EdmActionImportImplTest.java | 28 +-
.../provider/EdmEntityContainerImplTest.java | 138 +++++++-
.../edm/provider/EdmEntityTypeImplTest.java | 7 -
.../edm/provider/EdmFunctionImportImplTest.java | 4 +-
.../core/edm/provider/EdmSchemaImplTest.java | 337 +++++++++++++++++++
.../edm/provider/EdmTypeDefinitionImplTest.java | 3 +-
.../server/core/testutil/StringUtils.java | 52 +++
pom.xml | 2 +-
54 files changed, 2672 insertions(+), 279 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/Parameter.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/Parameter.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/Parameter.java
index 0b8b975..7c1d331 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/Parameter.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/Parameter.java
@@ -21,4 +21,7 @@ package org.apache.olingo.client.api.edm.xml.v4;
public interface Parameter extends org.apache.olingo.client.api.edm.xml.CommonParameter {
String getSrid();
+
+ //TODO: Has this to be moved into CommonParameter?
+ boolean isCollection();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImpl.java
index acbfce9..8340ec6 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImpl.java
@@ -33,5 +33,4 @@ public class EdmActionImpl extends EdmOperationImpl implements EdmAction {
private EdmActionImpl(final Edm edm, final FullQualifiedName name, final Action action) {
super(edm, name, action, EdmTypeKind.ACTION);
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java
index 332e673..62f7d36 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java
@@ -18,6 +18,7 @@
*/
package org.apache.olingo.client.core.edm;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -52,6 +53,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmSchema;
import org.apache.olingo.commons.api.edm.EdmServiceMetadata;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -368,4 +370,13 @@ public class EdmClientImpl extends AbstractEdmImpl {
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
+
+ @Override
+ protected List<EdmSchema> createSchemas() {
+ List<EdmSchema> schemas = new ArrayList<EdmSchema>();
+ for(Schema schema : xmlMetadata.getSchemas()){
+ schemas.add(new EdmSchemaImpl(this, xmlMetadata, schema));
+ }
+ return schemas;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java
index fdbbed2..eeccd95 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java
@@ -1,23 +1,25 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.core.edm;
+import java.util.List;
+
import org.apache.olingo.client.api.UnsupportedInV3Exception;
import org.apache.olingo.client.api.edm.xml.CommonFunctionImport;
import org.apache.olingo.client.api.edm.xml.EntityContainer;
@@ -46,7 +48,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
private final XMLMetadata xmlMetadata;
public EdmEntityContainerImpl(final Edm edm, final FullQualifiedName entityContainerName,
- final EntityContainer xmlEntityContainer, final XMLMetadata xmlMetadata) {
+ final EntityContainer xmlEntityContainer, final XMLMetadata xmlMetadata) {
super(edm, entityContainerName);
@@ -61,13 +63,13 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
}
final Singleton singleton = ((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).
- getSingleton(singletonName);
+ getSingleton(singletonName);
if (singleton == null) {
throw new EdmException("Singleton named '" + singletonName + "' not found in " + entityContainerName);
}
return new EdmSingletonImpl(edm, this, singletonName,
- new EdmTypeInfo(singleton.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
- singleton);
+ new EdmTypeInfo(singleton.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
+ singleton);
}
@Override
@@ -79,21 +81,20 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
if (entitySet instanceof org.apache.olingo.client.api.edm.xml.v4.EntitySet) {
return new EdmEntitySetImpl(edm, this, entitySetName,
- new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
- (org.apache.olingo.client.api.edm.xml.v4.EntitySet) entitySet);
+ new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
+ (org.apache.olingo.client.api.edm.xml.v4.EntitySet) entitySet);
} else {
return new EdmEntitySetProxy(edm, this, entitySetName,
- new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
- xmlMetadata);
+ new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
+ xmlMetadata);
}
}
@Override
protected EdmActionImport createActionImport(final String actionImportName) {
if (xmlEntityContainer instanceof org.apache.olingo.client.api.edm.xml.v4.EntityContainer) {
- final ActionImport actionImport
- = ((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).
- getActionImport(actionImportName);
+ final ActionImport actionImport = ((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).
+ getActionImport(actionImportName);
if (actionImport == null) {
throw new EdmException("ActionImport named '" + actionImportName + "' not found in " + entityContainerName);
}
@@ -116,10 +117,89 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
if (functionImport instanceof org.apache.olingo.client.api.edm.xml.v4.FunctionImport) {
return new EdmFunctionImportImpl(edm, this, functionImportName,
- (org.apache.olingo.client.api.edm.xml.v4.FunctionImport) functionImport);
+ (org.apache.olingo.client.api.edm.xml.v4.FunctionImport) functionImport);
} else {
return new EdmFunctionImportProxy(edm, this, functionImportName,
+ (org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport);
+ }
+ }
+
+ @Override
+ protected void loadAllEntitySets() {
+ List<? extends EntitySet> localEntitySets = xmlEntityContainer.getEntitySets();
+ if (localEntitySets != null) {
+ for (EntitySet entitySet : localEntitySets) {
+ EdmEntitySet edmSet;
+ if (entitySet instanceof org.apache.olingo.client.api.edm.xml.v4.EntitySet) {
+ edmSet = new EdmEntitySetImpl(edm, this, entitySet.getName(),
+ new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
+ (org.apache.olingo.client.api.edm.xml.v4.EntitySet) entitySet);
+ } else {
+ edmSet = new EdmEntitySetProxy(edm, this, entitySet.getName(),
+ new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
+ xmlMetadata);
+ }
+ entitySets.put(edmSet.getName(), edmSet);
+ }
+ }
+
+ }
+
+ @Override
+ protected void loadAllFunctionImports() {
+ List<? extends CommonFunctionImport> localFunctionImports = xmlEntityContainer.getFunctionImports();
+ if (localFunctionImports != null) {
+ for (CommonFunctionImport functionImport : localFunctionImports) {
+ EdmFunctionImport edmFunctionImport;
+ if (functionImport instanceof org.apache.olingo.client.api.edm.xml.v4.FunctionImport) {
+ edmFunctionImport = new EdmFunctionImportImpl(edm, this, functionImport.getName(),
+ (org.apache.olingo.client.api.edm.xml.v4.FunctionImport) functionImport);
+ } else {
+ edmFunctionImport = new EdmFunctionImportProxy(edm, this, functionImport.getName(),
(org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport);
+ }
+ functionImports.put(edmFunctionImport.getName(), edmFunctionImport);
+ }
+ }
+ }
+
+ @Override
+ protected void loadAllSingletons() {
+ if (!(xmlEntityContainer instanceof org.apache.olingo.client.api.edm.xml.v4.EntityContainer)) {
+ throw new UnsupportedInV3Exception();
+ }
+
+ List<Singleton> localSingletons =
+ ((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).getSingletons();
+ if (localSingletons != null) {
+ for (Singleton singleton : localSingletons) {
+ singletons.put(singleton.getName(), new EdmSingletonImpl(edm, this, singleton.getName(),
+ new EdmTypeInfo(singleton.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
+ singleton));
+ }
+ }
+ }
+
+ @Override
+ protected void loadAllActionImports() {
+ if (xmlEntityContainer instanceof org.apache.olingo.client.api.edm.xml.v4.EntityContainer) {
+ List<ActionImport> localActionImports =
+ ((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).getActionImports();
+ if (actionImports != null) {
+ for (ActionImport actionImport : localActionImports) {
+ actionImports.put(actionImport.getName(), new EdmActionImportImpl(edm, this, actionImport.getName(),
+ actionImport));
+ }
+ }
+ } else {
+ @SuppressWarnings("unchecked")
+ List<FunctionImport> localFunctionImports = (List<FunctionImport>) xmlEntityContainer.getFunctionImports();
+ if (localFunctionImports != null) {
+ for (FunctionImport functionImport : localFunctionImports) {
+ actionImports.put(functionImport.getName(), new EdmActionImportProxy(edm, this, functionImport.getName(),
+ functionImport));
+ }
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntitySetImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntitySetImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntitySetImpl.java
index 3708a45..ec9af77 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntitySetImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntitySetImpl.java
@@ -26,10 +26,17 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
public class EdmEntitySetImpl extends EdmBindingTargetImpl implements EdmEntitySet {
+ private EntitySet entitySet;
+
public EdmEntitySetImpl(final Edm edm, final EdmEntityContainer container, final String name,
final FullQualifiedName type, final EntitySet entitySet) {
super(edm, container, name, type, entitySet);
+ this.entitySet = entitySet;
}
+ @Override
+ public boolean isIncludeInServiceDocument() {
+ return entitySet.isIncludeInServiceDocument();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java
index d3004cb..edc1861 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -26,13 +26,14 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmFunction;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
public class EdmFunctionImportImpl extends EdmOperationImportImpl implements EdmFunctionImport {
private final FunctionImport functionImport;
public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
- final FunctionImport functionImport) {
+ final FunctionImport functionImport) {
super(edm, container, name, functionImport.getEntitySet());
this.functionImport = functionImport;
@@ -41,8 +42,17 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm
@Override
public EdmFunction getFunction(final List<String> parameterNames) {
return edm.getFunction(
- new EdmTypeInfo(functionImport.getFunction(), container.getNamespace()).getFullQualifiedName(),
- null, null, parameterNames);
+ new EdmTypeInfo(functionImport.getFunction(), container.getNamespace()).getFullQualifiedName(),
+ null, null, parameterNames);
}
+ @Override
+ public boolean isIncludeInServiceDocument() {
+ return functionImport.isIncludeInServiceDocument();
+ }
+
+ @Override
+ public FullQualifiedName getFunctionFqn() {
+ return new FullQualifiedName(functionImport.getFunction());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java
index 67f9e94..667dafe 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.client.api.edm.xml.CommonParameter;
+import org.apache.olingo.client.api.edm.xml.v4.Parameter;
import org.apache.olingo.client.api.edm.xml.v4.Action;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmParameter;
@@ -58,4 +59,22 @@ public abstract class EdmOperationImpl extends AbstractEdmOperation {
super(edm, name, kind);
this.operation = operation;
}
+
+ @Override
+ public FullQualifiedName getBindingParameterTypeFqn() {
+ if (isBound()) {
+ Parameter bindingParameter = operation.getParameters().get(0);
+ return new FullQualifiedName(getNamespace(), bindingParameter.getName());
+ }
+ return null;
+ }
+
+ @Override
+ public Boolean isBindingParameterTypeCollection() {
+ if (isBound()) {
+ Parameter bindingParameter = operation.getParameters().get(0);
+ return bindingParameter.isCollection();
+ }
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java
new file mode 100644
index 0000000..40f31b7
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.edm;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.client.api.edm.xml.ComplexType;
+import org.apache.olingo.client.api.edm.xml.EntityContainer;
+import org.apache.olingo.client.api.edm.xml.EntityType;
+import org.apache.olingo.client.api.edm.xml.EnumType;
+import org.apache.olingo.client.api.edm.xml.Schema;
+import org.apache.olingo.client.api.edm.xml.XMLMetadata;
+import org.apache.olingo.client.api.edm.xml.v3.FunctionImport;
+import org.apache.olingo.client.api.edm.xml.v4.Action;
+import org.apache.olingo.client.api.edm.xml.v4.Function;
+import org.apache.olingo.client.api.edm.xml.v4.TypeDefinition;
+import org.apache.olingo.client.core.edm.v3.EdmFunctionProxy;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.core.edm.AbstractEdmSchemaImpl;
+
+public class EdmSchemaImpl extends AbstractEdmSchemaImpl {
+
+ private final Edm edm;
+ private final XMLMetadata xmlMetadata;
+ private final Schema schema;
+
+ public EdmSchemaImpl(Edm edm, XMLMetadata xmlMetadata, Schema schema) {
+ super(schema.getNamespace(), schema.getAlias());
+ this.edm = edm;
+ this.xmlMetadata = xmlMetadata;
+ this.schema = schema;
+ }
+
+ @Override
+ protected EdmEntityContainer createEntityContainer() {
+ EntityContainer defaultContainer = schema.getDefaultEntityContainer();
+ if (defaultContainer != null) {
+ FullQualifiedName entityContainerName = new FullQualifiedName(schema.getNamespace(), defaultContainer.getName());
+ return new EdmEntityContainerImpl(edm, entityContainerName, defaultContainer, xmlMetadata);
+ }
+ return null;
+ }
+
+ @Override
+ protected List<EdmTypeDefinition> createTypeDefinitions() {
+ List<EdmTypeDefinition> typeDefinitions = new ArrayList<EdmTypeDefinition>();
+ if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) {
+ List<TypeDefinition> providerTypeDefinitions =
+ ((org.apache.olingo.client.api.edm.xml.v4.Schema) schema).getTypeDefinitions();
+ if (providerTypeDefinitions != null) {
+ for (TypeDefinition def : providerTypeDefinitions) {
+ typeDefinitions.add(new EdmTypeDefinitionImpl(edm, new FullQualifiedName("namespace", def.getName()), def));
+ }
+ }
+ }
+ return typeDefinitions;
+ }
+
+ @Override
+ protected List<EdmEnumType> createEnumTypes() {
+ List<EdmEnumType> enumTypes = new ArrayList<EdmEnumType>();
+ List<EnumType> providerEnumTypes = schema.getEnumTypes();
+ if (providerEnumTypes != null) {
+ for (EnumType enumType : providerEnumTypes) {
+ enumTypes.add(new EdmEnumTypeImpl(edm, new FullQualifiedName(namespace, enumType.getName()), enumType));
+ }
+ }
+ return enumTypes;
+ }
+
+ @Override
+ protected List<EdmEntityType> createEntityTypes() {
+ List<EdmEntityType> entityTypes = new ArrayList<EdmEntityType>();
+ List<? extends EntityType> providerEntityTypes = schema.getEntityTypes();
+ if (providerEntityTypes != null) {
+ for (EntityType entityType : providerEntityTypes) {
+ entityTypes.add(EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName(namespace, entityType.getName()),
+ entityType));
+ }
+ }
+ return entityTypes;
+ }
+
+ @Override
+ protected List<EdmComplexType> createComplexTypes() {
+ List<EdmComplexType> complexTypes = new ArrayList<EdmComplexType>();
+ List<? extends ComplexType> providerComplexTypes = schema.getComplexTypes();
+ if (providerComplexTypes != null) {
+ for (ComplexType complexType : providerComplexTypes) {
+ complexTypes.add(EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName(namespace, complexType.getName()),
+ complexType));
+ }
+ }
+ return complexTypes;
+ }
+
+ @Override
+ protected List<EdmAction> createActions() {
+ List<EdmAction> actions = new ArrayList<EdmAction>();
+ if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) {
+ List<Action> providerActions = ((org.apache.olingo.client.api.edm.xml.v4.Schema) schema).getActions();
+ if (providerActions != null) {
+ for (Action action : providerActions) {
+ actions.add(EdmActionImpl.getInstance(edm, new FullQualifiedName(namespace, action.getName()), action));
+ }
+ }
+ }
+ return actions;
+ }
+
+ @Override
+ protected List<EdmFunction> createFunctions() {
+ List<EdmFunction> functions = new ArrayList<EdmFunction>();
+ if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) {
+ List<Function> providerFunctions = ((org.apache.olingo.client.api.edm.xml.v4.Schema) schema).getFunctions();
+ if (providerFunctions != null) {
+ for (Function function : providerFunctions) {
+ functions.add(
+ EdmFunctionImpl.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function));
+ }
+ return functions;
+ }
+ } else {
+ for (EntityContainer providerContainer : schema.getEntityContainers()) {
+ @SuppressWarnings("unchecked")
+ List<FunctionImport> providerFunctions = (List<FunctionImport>) providerContainer.getFunctionImports();
+ if (providerFunctions != null) {
+ for (FunctionImport function : providerFunctions) {
+ functions.add(
+ EdmFunctionProxy.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function));
+ }
+ }
+
+ }
+ }
+ return functions;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java
index d3e0312..0cc0ff8 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java
@@ -99,4 +99,10 @@ public class EdmEntitySetProxy extends AbstractEdmBindingTarget implements EdmEn
return entityContainer.getEntitySet(targetEntitySet);
}
+ @Override
+ public boolean isIncludeInServiceDocument() {
+ //V3 states that all entity sets are included in the service document
+ return true;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java
index c7d1de2..077c753 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java
@@ -27,6 +27,7 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmFunction;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
public class EdmFunctionImportProxy extends EdmOperationImportImpl implements EdmFunctionImport {
@@ -45,4 +46,16 @@ public class EdmFunctionImportProxy extends EdmOperationImportImpl implements Ed
new EdmTypeInfo(functionImport.getName(), container.getNamespace()).getFullQualifiedName(),
null, null, parameterNames);
}
+
+ @Override
+ public boolean isIncludeInServiceDocument() {
+ //V3 states that all function imports are included in the service document
+ return true;
+ }
+
+ @Override
+ public FullQualifiedName getFunctionFqn() {
+ //TODO: Is this right for V3?
+ return new FullQualifiedName(container.getNamespace(), getName());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmOperationProxy.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmOperationProxy.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmOperationProxy.java
index 2876bb2..353e916 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmOperationProxy.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmOperationProxy.java
@@ -62,4 +62,16 @@ public class EdmOperationProxy extends AbstractEdmOperation {
this.functionImport = functionImport;
}
+ @Override
+ public FullQualifiedName getBindingParameterTypeFqn() {
+ //Not relevant for V3
+ return null;
+ }
+
+ @Override
+ public Boolean isBindingParameterTypeCollection() {
+ //Not relevant for V3
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ParameterImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ParameterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ParameterImpl.java
index 990cef0..be93eb9 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ParameterImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ParameterImpl.java
@@ -26,6 +26,8 @@ public class ParameterImpl extends AbstractParameter implements Parameter {
private static final long serialVersionUID = -1067642515116697747L;
private String srid;
+
+ private boolean isCollection;
@Override
public String getSrid() {
@@ -36,4 +38,14 @@ public class ParameterImpl extends AbstractParameter implements Parameter {
this.srid = srid;
}
+ //TODO: fill during metadata parsing
+ @Override
+ public boolean isCollection() {
+ return isCollection;
+ }
+
+ public void setCollection(boolean isCollection) {
+ this.isCollection = isCollection;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataRuntimeException.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataRuntimeException.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataRuntimeException.java
new file mode 100644
index 0000000..849e509
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataRuntimeException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api;
+
+public class ODataRuntimeException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ODataRuntimeException(String msg) {
+ super(msg);
+ }
+
+ public ODataRuntimeException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+ public ODataRuntimeException(Exception e) {
+ super(e);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java
index d9ee17b..c7aeff0 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java
@@ -26,6 +26,12 @@ import java.util.List;
* Interface representing a Entity Data Model as described in the Conceptual Schema Definition.
*/
public interface Edm {
+
+ /**
+ * This method DOES NOT support lazy loading. All schemas are loaded completely!
+ * @return all schemas defined for this EDM
+ */
+ List<EdmSchema> getSchemas();
/**
* Get entity container by full qualified name.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java
index d30d700..00afbc8 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java
@@ -1,26 +1,28 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.api.edm;
+import java.util.List;
+
/**
* A CSDL EntityContainer element.
- *
+ *
* <br/>
* EdmEntityContainer hold the information of EntitySets, Singletons, ActionImports and FunctionImports contained
*/
@@ -33,7 +35,7 @@ public interface EdmEntityContainer extends EdmNamed {
/**
* Get contained Singleton by name.
- *
+ *
* @param name
* @return {@link EdmSingleton}
*/
@@ -41,7 +43,7 @@ public interface EdmEntityContainer extends EdmNamed {
/**
* Get contained EntitySet by name.
- *
+ *
* @param name
* @return {@link EdmEntitySet}
*/
@@ -49,7 +51,7 @@ public interface EdmEntityContainer extends EdmNamed {
/**
* Get contained ActionImport by name.
- *
+ *
* @param name
* @return {@link EdmActionImport}
*/
@@ -57,10 +59,34 @@ public interface EdmEntityContainer extends EdmNamed {
/**
* Get contained FunctionImport by name.
- *
+ *
* @param name
* @return {@link EdmFunctionImport}
*/
EdmFunctionImport getFunctionImport(String name);
+ /**
+ * This method <b>DOES NOT</b> support lazy loading
+ * @return returns all entity sets for this container.
+ */
+ List<EdmEntitySet> getEntitySets();
+
+ /**
+ * This method <b>DOES NOT</b> support lazy loading
+ * @return returns all function imports for this container.
+ */
+ List<EdmFunctionImport> getFunctionImports();
+
+ /**
+ * This method <b>DOES NOT</b> support lazy loading
+ * @return returns all singletons for this container.
+ */
+ List<EdmSingleton> getSingletons();
+
+ /**
+ * This method <b>DOES NOT</b> support lazy loading
+ * @return returns all action imports for this container.
+ */
+ List<EdmActionImport> getActionImports();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySet.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySet.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySet.java
index 3e7b66f..d75e564 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySet.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySet.java
@@ -26,4 +26,9 @@ package org.apache.olingo.commons.api.edm;
*/
public interface EdmEntitySet extends EdmBindingTarget {
+ /**
+ * @return true if entity set must be included in the service document
+ */
+ boolean isIncludeInServiceDocument();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java
index 31b1c2c..96c6678 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java
@@ -26,5 +26,15 @@ import java.util.List;
public interface EdmFunctionImport extends EdmOperationImport {
EdmFunction getFunction(List<String> parameterNames);
+
+ /**
+ * @return the Fullqualified name for the function as specified in the metadata
+ */
+ FullQualifiedName getFunctionFqn();
+
+ /**
+ * @return true if the function import must be included in the service document
+ */
+ boolean isIncludeInServiceDocument();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java
index c653411..28c1985 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java
@@ -54,4 +54,14 @@ public interface EdmOperation extends EdmType {
*/
boolean isBound();
+ /**
+ * @return the fullqualified type name of the binding parameter
+ */
+ FullQualifiedName getBindingParameterTypeFqn();
+
+ /**
+ * @return true if binding parameter is of type collection.
+ */
+ Boolean isBindingParameterTypeCollection();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java
new file mode 100644
index 0000000..d5c8a2d
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api.edm;
+
+import java.util.List;
+
+/**
+ * A csdl schema element
+ */
+public interface EdmSchema {
+
+ /**
+ * @return the namespace for this schema
+ */
+ String getNamespace();
+
+ /**
+ * @return the alias for this schema. May be null.
+ */
+ String getAlias();
+
+ /**
+ * @return all enum types for this schema
+ */
+ List<EdmEnumType> getEnumTypes();
+
+ /**
+ * @return all entity types for this schema
+ */
+ List<EdmEntityType> getEntityTypes();
+
+ /**
+ * @return all complex types for this schema
+ */
+ List<EdmComplexType> getComplexTypes();
+
+ /**
+ * @return all actions for this schema
+ */
+ List<EdmAction> getActions();
+
+ /**
+ * @return all functions for this schema
+ */
+ List<EdmFunction> getFunctions();
+
+ /**
+ * @return the entity container for this schema. May be null.
+ */
+ EdmEntityContainer getEntityContainer();
+
+ List<EdmTypeDefinition> getTypeDefinitions();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java
index f993c23..a439e72 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java
@@ -1,18 +1,18 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -40,6 +40,16 @@ public class FullQualifiedName {
}
/**
+ * @param namespace.name
+ */
+ public FullQualifiedName(final String namespaceAndName) {
+ fqn = namespaceAndName;
+ String[] split = namespaceAndName.split(".");
+ namespace = split[0];
+ name = split[1];
+ }
+
+ /**
* @return namespace
*/
public String getNamespace() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java
index 5d108cb..aba62ba 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java
@@ -1,24 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.core.edm;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.olingo.commons.api.edm.Edm;
@@ -33,13 +35,17 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements
protected final FullQualifiedName entityContainerName;
- private final Map<String, EdmSingleton> singletons = new HashMap<String, EdmSingleton>();
+ protected final Map<String, EdmSingleton> singletons = new HashMap<String, EdmSingleton>();
+ private boolean allSingletonsLoaded = false;
- private final Map<String, EdmEntitySet> entitySets = new HashMap<String, EdmEntitySet>();
+ protected final Map<String, EdmEntitySet> entitySets = new HashMap<String, EdmEntitySet>();
+ private boolean allEntitySetsLoaded = false;
- private final Map<String, EdmActionImport> actionImports = new HashMap<String, EdmActionImport>();
+ protected final Map<String, EdmActionImport> actionImports = new HashMap<String, EdmActionImport>();
+ private boolean allActionImportsLoaded = false;
- private final Map<String, EdmFunctionImport> functionImports = new HashMap<String, EdmFunctionImport>();
+ protected final Map<String, EdmFunctionImport> functionImports = new HashMap<String, EdmFunctionImport>();
+ private boolean allFunctionImportsLoaded = false;
public AbstractEdmEntityContainer(final Edm edm, final FullQualifiedName entityContainerName) {
super(edm, entityContainerName.getName());
@@ -99,4 +105,47 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements
return functionImport;
}
+ @Override
+ public List<EdmEntitySet> getEntitySets() {
+ if (!allEntitySetsLoaded) {
+ loadAllEntitySets();
+ allEntitySetsLoaded = true;
+ }
+ return new ArrayList<EdmEntitySet>(entitySets.values());
+ }
+
+ protected abstract void loadAllEntitySets();
+
+ @Override
+ public List<EdmFunctionImport> getFunctionImports() {
+ if (!allFunctionImportsLoaded) {
+ loadAllFunctionImports();
+ allFunctionImportsLoaded = true;
+ }
+ return new ArrayList<EdmFunctionImport>(functionImports.values());
+ }
+
+ protected abstract void loadAllFunctionImports();
+
+ @Override
+ public List<EdmSingleton> getSingletons() {
+ if (!allSingletonsLoaded) {
+ loadAllSingletons();
+ allSingletonsLoaded = true;
+ }
+ return new ArrayList<EdmSingleton>(singletons.values());
+ }
+
+ protected abstract void loadAllSingletons();
+
+ @Override
+ public List<EdmActionImport> getActionImports() {
+ if (!allActionImportsLoaded) {
+ loadAllActionImports();
+ allActionImportsLoaded = true;
+ }
+ return new ArrayList<EdmActionImport>(actionImports.values());
+ }
+
+ protected abstract void loadAllActionImports();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmImpl.java
index 9890dac..b4c99d8 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmImpl.java
@@ -1,18 +1,18 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -29,43 +29,121 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmSchema;
import org.apache.olingo.commons.api.edm.EdmServiceMetadata;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
public abstract class AbstractEdmImpl implements Edm {
- private final Map<FullQualifiedName, EdmEntityContainer> entityContainers
- = new HashMap<FullQualifiedName, EdmEntityContainer>();
+ private final Map<FullQualifiedName, EdmEntityContainer> entityContainers =
+ new HashMap<FullQualifiedName, EdmEntityContainer>();
- private final Map<FullQualifiedName, EdmEnumType> enumTypes
- = new HashMap<FullQualifiedName, EdmEnumType>();
+ private final Map<FullQualifiedName, EdmEnumType> enumTypes = new HashMap<FullQualifiedName, EdmEnumType>();
- private final Map<FullQualifiedName, EdmTypeDefinition> typeDefinitions
- = new HashMap<FullQualifiedName, EdmTypeDefinition>();
+ private final Map<FullQualifiedName, EdmTypeDefinition> typeDefinitions =
+ new HashMap<FullQualifiedName, EdmTypeDefinition>();
- private final Map<FullQualifiedName, EdmEntityType> entityTypes
- = new HashMap<FullQualifiedName, EdmEntityType>();
+ private final Map<FullQualifiedName, EdmEntityType> entityTypes = new HashMap<FullQualifiedName, EdmEntityType>();
- private final Map<FullQualifiedName, EdmComplexType> complexTypes
- = new HashMap<FullQualifiedName, EdmComplexType>();
+ private final Map<FullQualifiedName, EdmComplexType> complexTypes = new HashMap<FullQualifiedName, EdmComplexType>();
- private final Map<FullQualifiedName, EdmAction> unboundActions
- = new HashMap<FullQualifiedName, EdmAction>();
+ private final Map<FullQualifiedName, EdmAction> unboundActions = new HashMap<FullQualifiedName, EdmAction>();
- private final Map<FunctionMapKey, EdmFunction> unboundFunctions
- = new HashMap<FunctionMapKey, EdmFunction>();
+ private final Map<FunctionMapKey, EdmFunction> unboundFunctions = new HashMap<FunctionMapKey, EdmFunction>();
- private final Map<ActionMapKey, EdmAction> boundActions
- = new HashMap<ActionMapKey, EdmAction>();
+ private final Map<ActionMapKey, EdmAction> boundActions = new HashMap<ActionMapKey, EdmAction>();
- private final Map<FunctionMapKey, EdmFunction> boundFunctions
- = new HashMap<FunctionMapKey, EdmFunction>();
+ private final Map<FunctionMapKey, EdmFunction> boundFunctions = new HashMap<FunctionMapKey, EdmFunction>();
private EdmServiceMetadata serviceMetadata;
private Map<String, String> aliasToNamespaceInfo;
-
+
+ private List<EdmSchema> schemas;
+
+ @Override
+ public List<EdmSchema> getSchemas() {
+ if (schemas == null) {
+ schemas = createSchemas();
+ if (schemas != null) {
+ aliasToNamespaceInfo = new HashMap<String, String>();
+ for (EdmSchema schema : schemas) {
+ String namespace = schema.getNamespace();
+ if (schema.getAlias() != null) {
+ aliasToNamespaceInfo.put(schema.getAlias(), namespace);
+ }
+
+ List<EdmEnumType> localEnumTypes = schema.getEnumTypes();
+ if (localEnumTypes != null) {
+ for (EdmEnumType enumType : localEnumTypes) {
+ enumTypes.put(new FullQualifiedName(namespace, enumType.getName()), enumType);
+ }
+ }
+
+ List<EdmTypeDefinition> localTypeDefinitions = schema.getTypeDefinitions();
+ if (localTypeDefinitions != null) {
+ for (EdmTypeDefinition typeDef : localTypeDefinitions) {
+ typeDefinitions.put(new FullQualifiedName(namespace, typeDef.getName()), typeDef);
+ }
+ }
+
+ List<EdmComplexType> localComplexTypes = schema.getComplexTypes();
+ if (localComplexTypes != null) {
+ for (EdmComplexType complexType : localComplexTypes) {
+ complexTypes.put(new FullQualifiedName(namespace, complexType.getName()), complexType);
+ }
+ }
+
+ List<EdmEntityType> localEntityTypes = schema.getEntityTypes();
+ if (localEntityTypes != null) {
+ for (EdmEntityType entityType : localEntityTypes) {
+ entityTypes.put(new FullQualifiedName(namespace, entityType.getName()), entityType);
+ }
+ }
+
+ List<EdmAction> localActions = schema.getActions();
+ if (localActions != null) {
+ for (EdmAction action : localActions) {
+ if (action.isBound()) {
+ ActionMapKey key = new ActionMapKey(new FullQualifiedName(namespace, action.getName()),
+ action.getBindingParameterTypeFqn(), action.isBindingParameterTypeCollection());
+ boundActions.put(key, action);
+ } else {
+ unboundActions.put(new FullQualifiedName(namespace, action.getName()), action);
+ }
+ }
+ }
+
+ List<EdmFunction> localFunctions = schema.getFunctions();
+ if (localFunctions != null) {
+ for (EdmFunction function : localFunctions) {
+ FunctionMapKey key =
+ new FunctionMapKey(new FullQualifiedName(namespace, function.getName()), function
+ .getBindingParameterTypeFqn(), function.isBindingParameterTypeCollection(), function
+ .getParameterNames());
+
+ if (function.isBound()) {
+ boundFunctions.put(key, function);
+ } else {
+ unboundFunctions.put(key, function);
+ }
+ }
+ }
+
+ EdmEntityContainer entityContainer = schema.getEntityContainer();
+ if(entityContainer != null){
+ entityContainers.put(new FullQualifiedName(namespace, entityContainer.getName()), entityContainer);
+ if(!entityContainers.containsKey(null)){
+ entityContainers.put(null, entityContainer);
+ }
+ }
+ }
+ }
+ }
+ return schemas;
+ }
+
@Override
public EdmEntityContainer getEntityContainer(final FullQualifiedName namespaceOrAliasFQN) {
final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN);
@@ -136,7 +214,7 @@ public abstract class AbstractEdmImpl implements Edm {
@Override
public EdmAction getAction(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
- final Boolean isBindingParameterCollection) {
+ final Boolean isBindingParameterCollection) {
EdmAction action = null;
@@ -166,15 +244,15 @@ public abstract class AbstractEdmImpl implements Edm {
@Override
public EdmFunction getFunction(final FullQualifiedName functionName,
- final FullQualifiedName bindingParameterTypeName,
- final Boolean isBindingParameterCollection, final List<String> parameterNames) {
+ final FullQualifiedName bindingParameterTypeName,
+ final Boolean isBindingParameterCollection, final List<String> parameterNames) {
EdmFunction function = null;
final FullQualifiedName functionFqn = resolvePossibleAlias(functionName);
if (bindingParameterTypeName == null) {
final FunctionMapKey key = new FunctionMapKey(
- functionFqn, bindingParameterTypeName, isBindingParameterCollection, parameterNames);
+ functionFqn, bindingParameterTypeName, isBindingParameterCollection, parameterNames);
function = unboundFunctions.get(key);
if (function == null) {
function = createUnboundFunction(functionFqn, parameterNames);
@@ -184,12 +262,12 @@ public abstract class AbstractEdmImpl implements Edm {
}
} else {
final FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName);
- final FunctionMapKey key
- = new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames);
+ final FunctionMapKey key =
+ new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames);
function = boundFunctions.get(key);
if (function == null) {
function = createBoundFunction(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection,
- parameterNames);
+ parameterNames);
if (function != null) {
boundFunctions.put(key, function);
}
@@ -241,12 +319,15 @@ public abstract class AbstractEdmImpl implements Edm {
protected abstract EdmFunction createUnboundFunction(FullQualifiedName functionName, List<String> parameterNames);
protected abstract EdmAction createBoundAction(FullQualifiedName actionName,
- FullQualifiedName bindingParameterTypeName,
- Boolean isBindingParameterCollection);
+ FullQualifiedName bindingParameterTypeName,
+ Boolean isBindingParameterCollection);
protected abstract EdmFunction createBoundFunction(FullQualifiedName functionName,
- FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection,
- List<String> parameterNames);
+ FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection,
+ List<String> parameterNames);
protected abstract EdmServiceMetadata createServiceMetadata();
+
+ protected abstract List<EdmSchema> createSchemas();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmSchemaImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmSchemaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmSchemaImpl.java
new file mode 100644
index 0000000..1346054
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmSchemaImpl.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.core.edm;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmSchema;
+import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
+
+public abstract class AbstractEdmSchemaImpl implements EdmSchema {
+
+ protected final String namespace;
+ private final String alias;
+ private List<EdmTypeDefinition> typeDefinitions;
+ private List<EdmEnumType> enumTypes;
+ private List<EdmEntityType> entityTypes;
+ private List<EdmComplexType> complexTypes;
+ private List<EdmAction> actions;
+ private List<EdmFunction> functions;
+ private EdmEntityContainer entityContainer;
+
+ public AbstractEdmSchemaImpl(String namespace, String alias) {
+ this.namespace = namespace;
+ this.alias = alias;
+ }
+
+ protected abstract EdmEntityContainer createEntityContainer();
+
+ protected abstract List<EdmTypeDefinition> createTypeDefinitions();
+
+ protected abstract List<EdmEnumType> createEnumTypes();
+
+ protected abstract List<EdmEntityType> createEntityTypes();
+
+ protected abstract List<EdmComplexType> createComplexTypes();
+
+ protected abstract List<EdmAction> createActions();
+
+ protected abstract List<EdmFunction> createFunctions();
+
+ @Override
+ public List<EdmTypeDefinition> getTypeDefinitions() {
+ if (typeDefinitions == null) {
+ typeDefinitions = createTypeDefinitions();
+ }
+ return typeDefinitions;
+ }
+
+ @Override
+ public List<EdmEnumType> getEnumTypes() {
+ if (enumTypes == null) {
+ enumTypes = createEnumTypes();
+ }
+ return enumTypes;
+ }
+
+ @Override
+ public List<EdmEntityType> getEntityTypes() {
+ if (entityTypes == null) {
+ entityTypes = createEntityTypes();
+ }
+ return entityTypes;
+ }
+
+ @Override
+ public List<EdmComplexType> getComplexTypes() {
+ if (complexTypes == null) {
+ complexTypes = createComplexTypes();
+ }
+ return complexTypes;
+ }
+
+ @Override
+ public List<EdmAction> getActions() {
+ if (actions == null) {
+ actions = createActions();
+ }
+ return actions;
+ }
+
+ @Override
+ public List<EdmFunction> getFunctions() {
+ if (functions == null) {
+ functions = createFunctions();
+ }
+ return functions;
+ }
+
+ @Override
+ public EdmEntityContainer getEntityContainer() {
+ if (entityContainer == null) {
+ entityContainer = createEntityContainer();
+ }
+ return entityContainer;
+ }
+
+ @Override
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public String getAlias() {
+ return alias;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java
index 00c8259..4eba1db 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java
@@ -37,6 +37,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmSchema;
import org.apache.olingo.commons.api.edm.EdmServiceMetadata;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -53,6 +54,18 @@ public class EdmImplCachingTest {
private Edm edm;
@Test
+ public void cacheSchema() {
+ List<EdmSchema> schemas = edm.getSchemas();
+ assertNotNull(schemas);
+
+ assertEquals(1, schemas.size());
+
+ List<EdmSchema> cachedSchemas = edm.getSchemas();
+ assertTrue(schemas == cachedSchemas );
+ assertEquals(schemas, schemas);
+ }
+
+ @Test
public void cacheEntityContainer() {
EdmEntityContainer entityContainer = edm.getEntityContainer(null);
assertNotNull(entityContainer);
@@ -385,5 +398,13 @@ public class EdmImplCachingTest {
}
return null;
}
+
+ @Override
+ public List<EdmSchema> createSchemas() {
+ List<EdmSchema> schemas = new ArrayList<EdmSchema>();
+ EdmSchema schema = mock(EdmSchema.class);
+ schemas.add(schema);
+ return schemas;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
index c908419..71e1acd 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
@@ -37,6 +37,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmSchema;
import org.apache.olingo.commons.api.edm.EdmServiceMetadata;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -53,6 +54,12 @@ public class EdmImplCallCreateTest {
private Edm edm;
@Test
+ public void callCreateSchemas() {
+ List<EdmSchema> schemas = edm.getSchemas();
+ assertNotNull(schemas);
+ }
+
+ @Test
public void callCreateEntityContainer() {
EdmEntityContainer entityContainer = edm.getEntityContainer(FQN);
assertNotNull(entityContainer);
@@ -264,5 +271,10 @@ public class EdmImplCallCreateTest {
}
return null;
}
+
+ @Override
+ public List<EdmSchema> createSchemas() {
+ return new ArrayList<EdmSchema>();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataFormat.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataFormat.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataFormat.java
new file mode 100644
index 0000000..f3d4bf3
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataFormat.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api;
+
+public enum ODataFormat {
+ XML, JSON
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataSerializer.java
new file mode 100644
index 0000000..a6cfe5d
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataSerializer.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api;
+
+import java.io.InputStream;
+
+import org.apache.olingo.commons.api.edm.Edm;
+
+public interface ODataSerializer {
+
+ InputStream metadata(Edm edm);
+
+ InputStream serviceDocument(Edm edm, String serviceRoot);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataServer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataServer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataServer.java
new file mode 100644
index 0000000..83d20fa
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataServer.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api;
+
+import org.apache.olingo.commons.api.ODataRuntimeException;
+
+
+public abstract class ODataServer {
+
+ private static final String IMPLEMENTATION = "org.apache.olingo.server.core.ODataServerImpl";
+
+ public static ODataServer newInstance(){
+ try {
+ final Class<?> clazz = Class.forName(ODataServer.IMPLEMENTATION);
+
+ /*
+ * We explicitly do not use the singleton pattern to keep the server state free
+ * and avoid class loading issues also during hot deployment.
+ */
+ final Object object = clazz.newInstance();
+ return (ODataServer) object;
+
+ } catch (final Exception e) {
+ //TODO: Change to ODataRuntimeExcfeption
+ throw new ODataRuntimeException(e);
+ }
+ }
+
+
+ public abstract ODataSerializer getSerializer(ODataFormat format);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-api/src/main/java/org/apache/olingo/server/api/edm/provider/EdmProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/edm/provider/EdmProvider.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/edm/provider/EdmProvider.java
index ae58c52..a2a78a3 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/edm/provider/EdmProvider.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/edm/provider/EdmProvider.java
@@ -179,4 +179,12 @@ public abstract class EdmProvider {
public List<Schema> getSchemas() throws ODataException {
return null;
}
+
+ /**
+ * Returns the entity container of this edm
+ * @return {@link EntityContainer} of this edm
+ */
+ public EntityContainer getEntityContainer() throws ODataException {
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/44aadbd6/lib/server-core/pom.xml
----------------------------------------------------------------------
diff --git a/lib/server-core/pom.xml b/lib/server-core/pom.xml
index 5f30cf5..bffe70b 100644
--- a/lib/server-core/pom.xml
+++ b/lib/server-core/pom.xml
@@ -10,75 +10,84 @@
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <artifactId>olingo-server-core-incubating</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
+ <artifactId>olingo-server-core-incubating</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
- <parent>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-lib-incubating</artifactId>
- <version>0.1.0-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-lib-incubating</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
- <dependencies>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-server-api-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-commons-core-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- </dependency>
- <dependency>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-runtime</artifactId>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-server-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-commons-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-runtime</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.6</version>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-deploy-plugin</artifactId>
- <configuration>
- <skip>false</skip>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-maven-plugin</artifactId>
- <version>${antlr.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>antlr4</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-maven-plugin</artifactId>
+ <version>${antlr.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>antlr4</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
<!--<arguments><argument>-atn</argument></arguments> -->
- <listener>true</listener>
- <visitor>true</visitor>
+ <listener>true</listener>
+ <visitor>true</visitor>
<!--maven antlr plugin has trouble with grammer import if the grammerfiles
are not directly inside src/main/antlr4, hence we have to set the libDirectory -->
- <libDirectory>src/main/antlr4/org/apache/olingo/server/core/uri/antlr</libDirectory>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <libDirectory>src/main/antlr4/org/apache/olingo/server/core/uri/antlr</libDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>