You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/02/19 11:30:07 UTC
[05/18] [OLINGO-170] Moved provider and implementation to server
module
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java
new file mode 100644
index 0000000..c4912d2
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
+import org.apache.olingo.odata4.commons.api.edm.EdmMember;
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmInt64;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.EnumType;
+
+public class EdmEnumImpl extends EdmNamedImpl implements EdmEnumType {
+
+ private final FullQualifiedName enumName;
+ private final EdmPrimitiveType edmPrimitiveTypeInstance;
+ private final EnumType enumType;
+ private final String uriPrefix;
+ private final String uriSuffix;
+ private List<String> memberNames;
+
+ public EdmEnumImpl(final EdmProviderImpl edm, final FullQualifiedName enumName, final EnumType enumType) {
+ super(edm, enumName.getName());
+ this.enumName = enumName;
+ this.enumType = enumType;
+ uriPrefix = enumName.getFullQualifiedNameAsString() + '\'';
+ uriSuffix = "'";
+ FullQualifiedName underlyingTypeName = enumType.getUnderlyingType();
+ if (underlyingTypeName == null) {
+ edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance();
+ } else {
+ edmPrimitiveTypeInstance =
+ EdmPrimitiveTypeKind.valueOf(underlyingTypeName.getName()).getEdmPrimitiveTypeInstance();
+ // TODO: Should we validate that the underlying type is of byte, sbyte, in16, int32 or int64?
+ }
+
+ }
+
+ @Override
+ public boolean isCompatible(final EdmPrimitiveType primitiveType) {
+ return equals(primitiveType);
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return edmPrimitiveTypeInstance.getDefaultType();
+ }
+
+ @Override
+ public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode) {
+ try {
+ valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, getDefaultType());
+ return true;
+ } catch (final EdmPrimitiveTypeException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+ if (value == null) {
+ if (isNullable != null && !isNullable) {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED");
+ }
+ return null;
+ }
+ return internalValueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ }
+
+ @Override
+ public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode) throws EdmPrimitiveTypeException {
+ if (value == null) {
+ if (isNullable != null && !isNullable) {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED");
+ }
+ return null;
+ }
+ return internalValueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ }
+
+ @Override
+ public String toUriLiteral(final String literal) {
+ return literal == null ? null :
+ uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix;
+ }
+
+ @Override
+ public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
+ if (literal == null) {
+ return null;
+ } else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) {
+ return literal;
+ } else if (literal.length() >= uriPrefix.length() + uriSuffix.length()
+ && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
+ return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
+ } else {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)");
+ }
+ }
+
+ @Override
+ public String getNamespace() {
+ return enumName.getNamespace();
+ }
+
+ @Override
+ public EdmTypeKind getKind() {
+ return EdmTypeKind.ENUM;
+ }
+
+ @Override
+ public EdmMember getMember(final String name) {
+ for (EdmMember member : enumType.getMembers()) {
+ if (member.getName().equals(name)) {
+ return member;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<String> getMemberNames() {
+ if (memberNames == null) {
+ memberNames = new ArrayList<String>();
+ for (final EdmMember member : enumType.getMembers()) {
+ memberNames.add(member.getName());
+ }
+ }
+ return memberNames;
+ }
+
+ @Override
+ public EdmPrimitiveType getUnderlyingType() {
+ return edmPrimitiveTypeInstance;
+ }
+
+ private <T> T internalValueOfString(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+ try {
+ return EdmInt64.convertNumber(parseEnumValue(value), returnType);
+ } catch (final IllegalArgumentException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
+ } catch (final ClassCastException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
+ }
+ }
+
+ private Long parseEnumValue(final String value) throws EdmPrimitiveTypeException {
+ Long result = null;
+ for (final String memberValue : value.split(",", enumType.isFlags() ? -1 : 1)) {
+ Long memberValueLong = null;
+ for (final EdmMember member : enumType.getMembers()) {
+ if (member.getName().equals(memberValue) || member.getValue().equals(memberValue)) {
+ memberValueLong = Long.decode(member.getValue());
+ }
+ }
+ if (memberValueLong == null) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
+ }
+ result = result == null ? memberValueLong : result | memberValueLong;
+ }
+ return result;
+ }
+
+ protected String internalValueToString(final Object value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+ if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
+ return constructEnumValue(((Number) value).longValue());
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
+ }
+ }
+
+ protected String constructEnumValue(final long value) throws EdmPrimitiveTypeException {
+ long remaining = value;
+ StringBuilder result = new StringBuilder();
+
+ for (final EdmMember member : enumType.getMembers()) {
+ final long memberValue = Long.parseLong(member.getValue());
+ if ((memberValue & remaining) == memberValue) {
+ if (result.length() > 0) {
+ result.append(',');
+ }
+ result.append(member.getName());
+ remaining ^= memberValue;
+ }
+ }
+
+ if (remaining != 0) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
+ }
+ return result.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImpl.java
new file mode 100644
index 0000000..0d7e2db
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImpl.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
+import org.apache.olingo.odata4.commons.api.edm.EdmReturnType;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.Function;
+
+public class EdmFunctionImpl extends EdmOperationImpl implements EdmFunction {
+
+ private Function function;
+
+ public EdmFunctionImpl(final EdmProviderImpl edm, final FullQualifiedName name, final Function function) {
+ super(edm, name, function, EdmTypeKind.FUNCTION);
+ this.function = function;
+ }
+
+ @Override
+ public boolean isComposable() {
+ return function.isComposable();
+ }
+
+ @Override
+ public EdmReturnType getReturnType() {
+ EdmReturnType returnType = super.getReturnType();
+ if (returnType == null) {
+ throw new EdmException("ReturnType for a function must not be null");
+ }
+ return returnType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImpl.java
new file mode 100644
index 0000000..42e04b9
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImpl.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.util.List;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
+import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata4.server.api.edm.provider.FunctionImport;
+
+public class EdmFunctionImportImpl extends EdmOperationImportImpl implements EdmFunctionImport {
+
+ private final FunctionImport functionImport;
+
+ public EdmFunctionImportImpl(final EdmProviderImpl edm, final String name, final EdmEntityContainer container,
+ final FunctionImport functionImport) {
+ super(edm, name, container, functionImport);
+ this.functionImport = functionImport;
+ }
+
+ @Override
+ public EdmFunction getFunction(final List<String> parameterNames) {
+ return edm.getFunction(functionImport.getFunction(), null, null, parameterNames);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImpl.java
new file mode 100644
index 0000000..de3927b
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImpl.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.net.URI;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImportInfo;
+import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata4.server.api.edm.provider.FunctionImport;
+
+public class EdmFunctionImportInfoImpl implements EdmFunctionImportInfo {
+
+ private EntityContainer entityContainer;
+ private FunctionImport functionImport;
+
+ public EdmFunctionImportInfoImpl(final EntityContainer entityContainer, final FunctionImport functionImport) {
+ this.entityContainer = entityContainer;
+ this.functionImport = functionImport;
+ }
+
+ @Override
+ public String getEntityContainerName() {
+ return entityContainer.getName();
+ }
+
+ @Override
+ public String getFunctionImportName() {
+ return functionImport.getName();
+ }
+
+ @Override
+ public URI getFunctionImportUri() {
+ throw new EdmException("Not yet implemented");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImpl.java
new file mode 100644
index 0000000..79eda0a
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImpl.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef;
+import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
+import org.apache.olingo.odata4.server.api.edm.provider.PropertyRef;
+
+public class EdmKeyPropertyRefImpl implements EdmKeyPropertyRef {
+
+ private PropertyRef ref;
+ private EdmEntityType edmEntityType;
+ private EdmProperty property;
+
+ public EdmKeyPropertyRefImpl(final EdmEntityType edmEntityType, final PropertyRef ref) {
+ this.edmEntityType = edmEntityType;
+ this.ref = ref;
+ }
+
+ @Override
+ public String getKeyPropertyName() {
+ return ref.getPropertyName();
+ }
+
+ @Override
+ public String getAlias() {
+ return ref.getAlias();
+ }
+
+ @Override
+ public String getPath() {
+ return ref.getPath();
+ }
+
+ @Override
+ public EdmProperty getProperty() {
+ if (property == null) {
+ if (ref.getAlias() == null) {
+ property = (EdmProperty) edmEntityType.getProperty(ref.getPropertyName());
+ if (property == null) {
+ throw new EdmException("Invalid key property ref specified. Can´t find property with name: "
+ + ref.getPropertyName());
+ }
+ } else {
+ if (ref.getPath() == null || ref.getPath().isEmpty()) {
+ throw new EdmException("Alias but no path specified for propertyRef");
+ }
+ String[] splitPath = ref.getPath().split("/");
+ EdmStructuralType structType = edmEntityType;
+ for (int i = 0; i < splitPath.length - 1; i++) {
+ EdmProperty property = (EdmProperty) structType.getProperty(splitPath[i]);
+ if (property == null) {
+ throw new EdmException("Invalid property ref specified. Can´t find property with name: "
+ + splitPath[i] + " at type: " + structType.getNamespace() + "." + structType.getName());
+ }
+ structType = (EdmStructuralType) property.getType();
+ }
+ property = (EdmProperty) structType.getProperty(splitPath[splitPath.length - 1]);
+ if (property == null) {
+ throw new EdmException("Invalid property ref specified. Can´t find property with name: "
+ + splitPath[splitPath.length - 1] + " at type: " + structType.getNamespace() + "."
+ + structType.getName());
+ }
+ }
+ }
+
+ return property;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImpl.java
new file mode 100644
index 0000000..10ecb85
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImpl.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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmMember;
+import org.apache.olingo.odata4.server.api.edm.provider.EnumMember;
+
+public class EdmMemberImpl extends EdmNamedImpl implements EdmMember {
+
+ private final EnumMember member;
+
+ public EdmMemberImpl(final EdmProviderImpl edm, final EnumMember member) {
+ super(edm, member.getName());
+ this.member = member;
+ }
+
+ @Override
+ public String getValue() {
+ return member.getValue();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImpl.java
new file mode 100644
index 0000000..86003da
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImpl.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmNamed;
+
+public abstract class EdmNamedImpl implements EdmNamed {
+
+ private String name;
+ protected EdmProviderImpl edm;
+
+ // TODO: ValidateName?
+ public EdmNamedImpl(final EdmProviderImpl edm, final String name) {
+ this.edm = edm;
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNavigationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNavigationPropertyImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNavigationPropertyImpl.java
new file mode 100644
index 0000000..9a85ba5
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNavigationPropertyImpl.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.util.List;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmElement;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.server.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata4.server.api.edm.provider.ReferentialConstraint;
+
+public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavigationProperty {
+
+ private final NavigationProperty navigationProperty;
+ private EdmEntityType typeImpl;
+ private EdmNavigationProperty partnerNavigationProperty;
+
+ public EdmNavigationPropertyImpl(final EdmProviderImpl edm, final NavigationProperty navigationProperty) {
+ super(edm, navigationProperty.getName());
+ this.navigationProperty = navigationProperty;
+ }
+
+ @Override
+ public EdmType getType() {
+ if (typeImpl == null) {
+ typeImpl = edm.getEntityType(navigationProperty.getType());
+ if (typeImpl == null) {
+ throw new EdmException("Cannot find type with name: " + navigationProperty.getType());
+ }
+ }
+ return typeImpl;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return navigationProperty.isCollection();
+ }
+
+ @Override
+ public Boolean isNullable() {
+ return navigationProperty.getNullable();
+ }
+
+ @Override
+ public EdmNavigationProperty getPartner() {
+ if (partnerNavigationProperty == null) {
+ String partner = navigationProperty.getPartner();
+ if (partner != null) {
+ EdmStructuralType type = (EdmStructuralType) getType();
+ EdmElement property = null;
+ String[] split = partner.split("/");
+ for (String element : split) {
+ property = type.getProperty(element);
+ if (property == null) {
+ throw new EdmException("Cannot find property with name: " + element + " at type " + type.getName());
+ }
+ type = (EdmStructuralType) property.getType();
+ }
+ partnerNavigationProperty = (EdmNavigationProperty) property;
+ }
+ }
+ return partnerNavigationProperty;
+ }
+
+ @Override
+ public String getReferencingPropertyName(final String referencedPropertyName) {
+ List<ReferentialConstraint> referentialConstraints = navigationProperty.getReferentialConstraints();
+ if (referentialConstraints != null) {
+ for (ReferentialConstraint constraint : referentialConstraints) {
+ if (constraint.getReferencedProperty().equals(referencedPropertyName)) {
+ return constraint.getProperty();
+ }
+ }
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImpl.java
new file mode 100644
index 0000000..80d6a0b
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImpl.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmOperation;
+import org.apache.olingo.odata4.commons.api.edm.EdmParameter;
+import org.apache.olingo.odata4.commons.api.edm.EdmReturnType;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.EntitySetPath;
+import org.apache.olingo.odata4.server.api.edm.provider.Operation;
+import org.apache.olingo.odata4.server.api.edm.provider.Parameter;
+
+public class EdmOperationImpl extends EdmTypeImpl implements EdmOperation {
+
+ private final Map<String, EdmParameter> parameters = new HashMap<String, EdmParameter>();
+ private final Operation operation;
+ private EdmReturnType returnType;
+ private List<String> parameterNames;
+
+ public EdmOperationImpl(final EdmProviderImpl edm, final FullQualifiedName name, final Operation operation,
+ final EdmTypeKind kind) {
+ super(edm, name, kind);
+ this.operation = operation;
+ List<Parameter> providerParameters = operation.getParameters();
+ if (providerParameters != null) {
+ for (Parameter parameter : providerParameters) {
+ parameters.put(parameter.getName(), new EdmParameterImpl(edm, parameter));
+ }
+ }
+ }
+
+ @Override
+ public EdmParameter getParameter(final String name) {
+ return parameters.get(name);
+ }
+
+ @Override
+ public List<String> getParameterNames() {
+ if (parameterNames == null) {
+ parameterNames = new ArrayList<String>();
+ List<Parameter> providerParameters = operation.getParameters();
+ if (providerParameters != null) {
+ for (Parameter parameter : providerParameters) {
+ parameterNames.add(parameter.getName());
+ }
+ }
+ }
+ return parameterNames;
+ }
+
+ @Override
+ public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) {
+ EntitySetPath entitySetPath = operation.getEntitySetPath();
+ EdmEntitySet returnedEntitySet = null;
+ if (bindingParameterEntitySet != null && entitySetPath != null && entitySetPath.getBindingParameter() != null
+ && entitySetPath.getPath() != null) {
+ EdmBindingTarget relatedBindingTarget =
+ bindingParameterEntitySet.getRelatedBindingTarget(entitySetPath.getPath());
+ if (relatedBindingTarget == null) {
+ throw new EdmException("Cannot find entity set with path: " + entitySetPath.getPath());
+ }
+ if (relatedBindingTarget instanceof EdmEntitySet) {
+ returnedEntitySet = (EdmEntitySet) relatedBindingTarget;
+ } else {
+ throw new EdmException("BindingTarget with name: " + relatedBindingTarget.getName() + " must be an entity set");
+ }
+
+ }
+ return returnedEntitySet;
+ }
+
+ @Override
+ public EdmReturnType getReturnType() {
+ if (returnType == null && operation.getReturnType() != null) {
+ returnType = new EdmReturnTypeImpl(edm, operation.getReturnType());
+ }
+ return returnType;
+ }
+
+ @Override
+ public boolean isBound() {
+ return operation.isBound();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImportImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImportImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImportImpl.java
new file mode 100644
index 0000000..7460725
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImportImpl.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmOperationImport;
+import org.apache.olingo.odata4.server.api.edm.provider.OperationImport;
+import org.apache.olingo.odata4.server.api.edm.provider.Target;
+
+public abstract class EdmOperationImportImpl extends EdmNamedImpl implements EdmOperationImport {
+
+ private final OperationImport operationImport;
+ private final EdmEntityContainer container;
+ private EdmEntitySet returnedEntitySet;
+
+ public EdmOperationImportImpl(final EdmProviderImpl edm, final String name, final EdmEntityContainer container,
+ final OperationImport operationImport) {
+ super(edm, name);
+ this.container = container;
+ this.operationImport = operationImport;
+ }
+
+ @Override
+ public EdmEntitySet getReturnedEntitySet() {
+ Target target = operationImport.getEntitySet();
+ if (target != null && returnedEntitySet == null) {
+ EdmEntityContainer entityContainer = edm.getEntityContainer(target.getEntityContainer());
+ if (entityContainer == null) {
+ throw new EdmException("Can´t find entity container with name: " + target.getEntityContainer());
+ }
+ returnedEntitySet = entityContainer.getEntitySet(target.getTargetName());
+ if (returnedEntitySet == null) {
+ throw new EdmException("Can´t find entity set with name: " + target.getTargetName());
+ }
+ }
+ return returnedEntitySet;
+ }
+
+ @Override
+ public EdmEntityContainer getEntityContainer() {
+ return container;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmParameterImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmParameterImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmParameterImpl.java
new file mode 100644
index 0000000..afebe29
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmParameterImpl.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmMapping;
+import org.apache.olingo.odata4.commons.api.edm.EdmParameter;
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.Parameter;
+
+public class EdmParameterImpl extends EdmElementImpl implements EdmParameter {
+
+ private final Parameter parameter;
+ private EdmType typeImpl;
+
+ public EdmParameterImpl(final EdmProviderImpl edm, final Parameter parameter) {
+ super(edm, parameter.getName());
+ this.parameter = parameter;
+ }
+
+ @Override
+ public EdmType getType() {
+ if (typeImpl == null) {
+ FullQualifiedName typeName = parameter.getType();
+ if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
+ try {
+ typeImpl = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance();
+ } catch (IllegalArgumentException e) {
+ throw new EdmException("Cannot find type with name: " + typeName, e);
+ }
+ } else {
+ typeImpl = edm.getComplexType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getEntityType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getEnumType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getTypeDefinition(typeName);
+ if (typeImpl == null) {
+ throw new EdmException("Cannot find type with name: " + typeName);
+ }
+ }
+ }
+ }
+ }
+ }
+ return typeImpl;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return parameter.isCollection();
+ }
+
+ @Override
+ public EdmMapping getMapping() {
+ return parameter.getMapping();
+ }
+
+ @Override
+ public Boolean isNullable() {
+ return parameter.getNullable();
+ }
+
+ @Override
+ public Integer getMaxLength() {
+ return parameter.getMaxLength();
+ }
+
+ @Override
+ public Integer getPrecision() {
+ return parameter.getPrecision();
+ }
+
+ @Override
+ public Integer getScale() {
+ return parameter.getScale();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmPropertyImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmPropertyImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmPropertyImpl.java
new file mode 100644
index 0000000..35da617
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmPropertyImpl.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmMapping;
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.Property;
+
+public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
+
+ private final Property property;
+ private final boolean isPrimitive;
+ private EdmType propertyType;
+
+ public EdmPropertyImpl(final EdmProviderImpl edm, final Property property) {
+ super(edm, property.getName());
+ this.property = property;
+ isPrimitive = EdmPrimitiveType.EDM_NAMESPACE.equals(property.getType().getNamespace());
+ }
+
+ @Override
+ public EdmType getType() {
+ if (propertyType == null) {
+ FullQualifiedName typeName = property.getType();
+ if (isPrimitive) {
+ try {
+ propertyType = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance();
+ } catch (IllegalArgumentException e) {
+ throw new EdmException("Cannot find type with name: " + typeName, e);
+ }
+ } else {
+ propertyType = edm.getComplexType(typeName);
+ if (propertyType == null) {
+ propertyType = edm.getEnumType(typeName);
+ if (propertyType == null) {
+ propertyType = edm.getTypeDefinition(typeName);
+ if (propertyType == null) {
+ throw new EdmException("Cannot find type with name: " + typeName);
+ }
+ }
+ }
+ }
+ }
+
+ return propertyType;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return property.isCollection();
+ }
+
+ @Override
+ public EdmMapping getMapping() {
+ return property.getMapping();
+ }
+
+ @Override
+ public String getMimeType() {
+ return property.getMimeType();
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return isPrimitive;
+ }
+
+ @Override
+ public Boolean isNullable() {
+ return property.getNullable();
+ }
+
+ @Override
+ public Integer getMaxLength() {
+ return property.getMaxLength();
+ }
+
+ @Override
+ public Integer getPrecision() {
+ return property.getPrecision();
+ }
+
+ @Override
+ public Integer getScale() {
+ return property.getScale();
+ }
+
+ @Override
+ public Boolean isUnicode() {
+ return property.isUnicode();
+ }
+
+ @Override
+ public String getDefaultValue() {
+ return property.getDefaultValue();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java
new file mode 100644
index 0000000..700f019
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java
@@ -0,0 +1,295 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata4.commons.api.ODataException;
+import org.apache.olingo.odata4.commons.api.edm.EdmAction;
+import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
+import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
+import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata;
+import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.core.edm.EdmImpl;
+import org.apache.olingo.odata4.server.api.edm.provider.Action;
+import org.apache.olingo.odata4.server.api.edm.provider.AliasInfo;
+import org.apache.olingo.odata4.server.api.edm.provider.ComplexType;
+import org.apache.olingo.odata4.server.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata4.server.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata4.server.api.edm.provider.EntityType;
+import org.apache.olingo.odata4.server.api.edm.provider.EnumType;
+import org.apache.olingo.odata4.server.api.edm.provider.Function;
+import org.apache.olingo.odata4.server.api.edm.provider.Parameter;
+import org.apache.olingo.odata4.server.api.edm.provider.TypeDefinition;
+
+public class EdmProviderImpl extends EdmImpl {
+
+ private final EdmProvider provider;
+ private final Map<FullQualifiedName, List<Action>> actionsMap = new HashMap<FullQualifiedName, List<Action>>();
+ private final Map<FullQualifiedName, List<Function>> functionsMap = new HashMap<FullQualifiedName, List<Function>>();
+
+ public EdmProviderImpl(final EdmProvider provider) {
+ this.provider = provider;
+
+ }
+
+ @Override
+ public EdmEntityContainer createEntityContainer(final FullQualifiedName containerName) {
+ try {
+ EntityContainerInfo entityContainerInfo = provider.getEntityContainerInfo(containerName);
+ if (entityContainerInfo != null) {
+ return new EdmEntityContainerImpl(this, provider, entityContainerInfo);
+ }
+ return null;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+ @Override
+ public EdmEnumType createEnumType(final FullQualifiedName enumName) {
+ try {
+ EnumType enumType = provider.getEnumType(enumName);
+ if (enumType != null) {
+ return new EdmEnumImpl(this, enumName, enumType);
+ }
+ return null;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+ @Override
+ public EdmTypeDefinition createTypeDefinition(final FullQualifiedName typeDefinitionName) {
+ try {
+ TypeDefinition typeDefinition = provider.getTypeDefinition(typeDefinitionName);
+ if (typeDefinition != null) {
+ return new EdmTypeDefinitionImpl(this, typeDefinitionName, typeDefinition);
+ }
+ return null;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+ @Override
+ public EdmEntityType createEntityType(final FullQualifiedName entityTypeName) {
+ try {
+ EntityType entityType = provider.getEntityType(entityTypeName);
+ if (entityType != null) {
+ return new EdmEntityTypeImpl(this, entityTypeName, entityType);
+ }
+ return null;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+ @Override
+ public EdmComplexType createComplexType(final FullQualifiedName complexTypeName) {
+ try {
+ ComplexType complexType = provider.getComplexType(complexTypeName);
+ if (complexType != null) {
+ return new EdmComplexTypeImpl(this, complexTypeName, complexType);
+ }
+ return null;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+ @Override
+ public EdmAction createBoundAction(final FullQualifiedName actionName,
+ final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) {
+ try {
+ List<Action> actions = actionsMap.get(actionName);
+ if (actions == null) {
+ actions = provider.getActions(actionName);
+ if (actions != null) {
+ actionsMap.put(actionName, actions);
+ } else {
+ return null;
+ }
+ }
+ EdmActionImpl actionImpl = null;
+ // Search for bound action where binding parameter matches
+ for (Action action : actions) {
+ if (action.isBound() == true) {
+ List<Parameter> parameters = action.getParameters();
+ Parameter parameter = parameters.get(0);
+ if (bindingParameterTypeName.equals(parameter.getType())
+ && isBindingParameterCollection.booleanValue() == parameter.isCollection()) {
+ actionImpl = new EdmActionImpl(this, actionName, action);
+ break;
+ }
+
+ }
+ }
+ return actionImpl;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+ @Override
+ public EdmFunction createBoundFunction(final FullQualifiedName functionName,
+ final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection,
+ final List<String> parameterNames) {
+ try {
+ List<Function> functions = functionsMap.get(functionName);
+ if (functions == null) {
+ functions = provider.getFunctions(functionName);
+ if (functions != null) {
+ functionsMap.put(functionName, functions);
+ } else {
+ return null;
+ }
+ }
+ List<String> parameterNamesCopy = parameterNames;
+ if (parameterNamesCopy == null) {
+ parameterNamesCopy = Collections.emptyList();
+ }
+ EdmFunctionImpl functionImpl = null;
+ for (Function function : functions) {
+ if (function.isBound() == true) {
+ List<Parameter> providerParameters = function.getParameters();
+ if (providerParameters == null || providerParameters.size() == 0) {
+ throw new EdmException("No parameter specified for bound function: " + functionName);
+ }
+ Parameter bindingParameter = providerParameters.get(0);
+ if (bindingParameterTypeName.equals(bindingParameter.getType())
+ && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) {
+ if (parameterNamesCopy.size() == providerParameters.size() - 1) {
+ List<String> providerParameterNames = new ArrayList<String>();
+ for (int i = 1; i < providerParameters.size(); i++) {
+ providerParameterNames.add(providerParameters.get(i).getName());
+ }
+ if (parameterNamesCopy.containsAll(providerParameterNames)) {
+ functionImpl = new EdmFunctionImpl(this, functionName, function);
+ break;
+ }
+ }
+ }
+ }
+ }
+ return functionImpl;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+ @Override
+ public EdmServiceMetadata createServiceMetadata() {
+ return new EdmServiceMetadataImpl(provider);
+ }
+
+ @Override
+ protected Map<String, String> createAliasToNamespaceInfo() {
+ Map<String, String> aliasToNamespaceInfos = new HashMap<String, String>();
+ try {
+ List<AliasInfo> aliasInfos = provider.getAliasInfos();
+ if (aliasInfos != null) {
+ for (AliasInfo info : aliasInfos) {
+ aliasToNamespaceInfos.put(info.getAlias(), info.getNamespace());
+ }
+ }
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ return aliasToNamespaceInfos;
+ }
+
+ @Override
+ protected EdmAction createUnboundAction(final FullQualifiedName actionName) {
+ try {
+ List<Action> actions = actionsMap.get(actionName);
+ if (actions == null) {
+ actions = provider.getActions(actionName);
+ if (actions != null) {
+ actionsMap.put(actionName, actions);
+ } else {
+ return null;
+ }
+ }
+ EdmActionImpl actionImpl = null;
+ // Search for first unbound action
+ for (Action action : actions) {
+ if (action.isBound() == false) {
+ actionImpl = new EdmActionImpl(this, actionName, action);
+ break;
+ }
+ }
+ return actionImpl;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+ @Override
+ protected EdmFunction createUnboundFunction(final FullQualifiedName functionName, final List<String> parameterNames) {
+ try {
+ List<Function> functions = functionsMap.get(functionName);
+ if (functions == null) {
+ functions = provider.getFunctions(functionName);
+ if (functions != null) {
+ functionsMap.put(functionName, functions);
+ } else {
+ return null;
+ }
+ }
+ List<String> parameterNamesCopy = parameterNames;
+ if (parameterNamesCopy == null) {
+ parameterNamesCopy = Collections.emptyList();
+ }
+ EdmFunctionImpl functionImpl = null;
+ for (Function function : functions) {
+ if (function.isBound() == false) {
+ List<Parameter> providerParameters = function.getParameters();
+ if (providerParameters == null) {
+ providerParameters = Collections.emptyList();
+ }
+ if (parameterNamesCopy.size() == providerParameters.size()) {
+ List<String> functionParameterNames = new ArrayList<String>();
+ for (Parameter parameter : providerParameters) {
+ functionParameterNames.add(parameter.getName());
+ }
+
+ if (parameterNamesCopy.containsAll(functionParameterNames)) {
+ functionImpl = new EdmFunctionImpl(this, functionName, function);
+ break;
+ }
+ }
+ }
+ }
+ return functionImpl;
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java
new file mode 100644
index 0000000..ceb1918
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.odata4.commons.api.edm.EdmReturnType;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.core.edm.EdmImpl;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.ReturnType;
+
+public class EdmReturnTypeImpl implements EdmReturnType {
+
+ private final EdmImpl edm;
+ private final ReturnType returnType;
+ private EdmType typeImpl;
+
+ public EdmReturnTypeImpl(final EdmImpl edm, final ReturnType returnType) {
+ this.edm = edm;
+ this.returnType = returnType;
+ }
+
+ @Override
+ public EdmType getType() {
+ if (typeImpl == null) {
+ FullQualifiedName typeName = returnType.getType();
+ if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
+ try {
+ typeImpl = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance();
+ } catch (IllegalArgumentException e) {
+ throw new EdmException("Cannot find type with name: " + typeName, e);
+ }
+ } else {
+ typeImpl = edm.getComplexType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getEntityType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getEnumType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getTypeDefinition(typeName);
+ if (typeImpl == null) {
+ throw new EdmException("Cant find type with name: " + typeName);
+ }
+ }
+ }
+ }
+ }
+ }
+ return typeImpl;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return returnType.isCollection();
+ }
+
+ @Override
+ public Boolean isNullable() {
+ return returnType.getNullable();
+ }
+
+ @Override
+ public Integer getMaxLength() {
+ return returnType.getMaxLength();
+ }
+
+ @Override
+ public Integer getPrecision() {
+ return returnType.getPrecision();
+ }
+
+ @Override
+ public Integer getScale() {
+ return returnType.getScale();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmServiceMetadataImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmServiceMetadataImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmServiceMetadataImpl.java
new file mode 100644
index 0000000..dc0b556
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmServiceMetadataImpl.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata4.commons.api.ODataException;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntitySetInfo;
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImportInfo;
+import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata;
+import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo;
+import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.odata4.server.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata4.server.api.edm.provider.EntitySet;
+import org.apache.olingo.odata4.server.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata4.server.api.edm.provider.Schema;
+import org.apache.olingo.odata4.server.api.edm.provider.Singleton;
+
+public class EdmServiceMetadataImpl implements EdmServiceMetadata {
+
+ private EdmProvider provider;
+ private ArrayList<EdmEntitySetInfo> entitySetInfos;
+ private ArrayList<EdmFunctionImportInfo> functionImportInfos;
+ private ArrayList<EdmSingletonInfo> singletonInfos;
+ private List<Schema> schemas;
+
+ public EdmServiceMetadataImpl(final EdmProvider provider) {
+ this.provider = provider;
+ }
+
+ @Override
+ public InputStream getMetadata() {
+ throw new RuntimeException("Not yet implemented");
+ }
+
+ @Override
+ public String getDataServiceVersion() {
+ return ODataServiceVersion.V40;
+ }
+
+ @Override
+ public List<EdmEntitySetInfo> getEntitySetInfos() {
+ if (entitySetInfos == null) {
+ try {
+ entitySetInfos = new ArrayList<EdmEntitySetInfo>();
+ if (schemas == null) {
+ schemas = provider.getSchemas();
+ if (schemas == null) {
+ throw new EdmException("Provider doe not define any schemas.");
+ }
+ }
+ for (Schema schema : schemas) {
+ EntityContainer entityContainer = schema.getEntityContainer();
+ if (entityContainer != null) {
+ List<EntitySet> entitySets = entityContainer.getEntitySets();
+ if (entitySets != null) {
+ for (EntitySet set : entitySets) {
+ entitySetInfos.add(new EdmEntitySetInfoImpl(entityContainer, set));
+ }
+ }
+ }
+ }
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+ return entitySetInfos;
+ }
+
+ @Override
+ public List<EdmSingletonInfo> getSingletonInfos() {
+ if (singletonInfos == null) {
+ try {
+ singletonInfos = new ArrayList<EdmSingletonInfo>();
+ if (schemas == null) {
+ schemas = provider.getSchemas();
+ if (schemas == null) {
+ throw new EdmException("Provider doe not define any schemas.");
+ }
+ }
+ for (Schema schema : schemas) {
+ EntityContainer entityContainer = schema.getEntityContainer();
+ if (entityContainer != null) {
+ List<Singleton> singletons = entityContainer.getSingletons();
+ if (singletons != null) {
+ for (Singleton singleton : singletons) {
+ singletonInfos.add(new EdmSingletonInfoImpl(entityContainer, singleton));
+ }
+ }
+ }
+ }
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+ return singletonInfos;
+ }
+
+ @Override
+ public List<EdmFunctionImportInfo> getFunctionImportInfos() {
+ if (functionImportInfos == null) {
+ try {
+ functionImportInfos = new ArrayList<EdmFunctionImportInfo>();
+ if (schemas == null) {
+ schemas = provider.getSchemas();
+ if (schemas == null) {
+ throw new EdmException("Provider doe not define any schemas.");
+ }
+ }
+ for (Schema schema : schemas) {
+ EntityContainer entityContainer = schema.getEntityContainer();
+ if (entityContainer != null) {
+ List<FunctionImport> functionImports = entityContainer.getFunctionImports();
+ if (functionImports != null) {
+ for (FunctionImport functionImport : functionImports) {
+ functionImportInfos.add(new EdmFunctionImportInfoImpl(entityContainer, functionImport));
+ }
+ }
+ }
+ }
+ } catch (ODataException e) {
+ throw new EdmException(e);
+ }
+ }
+ return functionImportInfos;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImpl.java
new file mode 100644
index 0000000..f98a328
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImpl.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
+import org.apache.olingo.odata4.server.api.edm.provider.Singleton;
+
+public class EdmSingletonImpl extends EdmBindingTargetImpl implements EdmSingleton {
+
+ public EdmSingletonImpl(final EdmProviderImpl edm, final EdmEntityContainer container, final Singleton singleton) {
+ super(edm, container, singleton);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImpl.java
new file mode 100644
index 0000000..1232d8c
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImpl.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.net.URI;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo;
+import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata4.server.api.edm.provider.Singleton;
+
+public class EdmSingletonInfoImpl implements EdmSingletonInfo {
+
+ private final EntityContainer entityContainer;
+ private final Singleton singleton;
+
+ public EdmSingletonInfoImpl(final EntityContainer entityContainer, final Singleton singleton) {
+ this.entityContainer = entityContainer;
+ this.singleton = singleton;
+ }
+
+ @Override
+ public String getEntityContainerName() {
+ return entityContainer.getName();
+ }
+
+ @Override
+ public String getSingletonName() {
+ return singleton.getName();
+ }
+
+ @Override
+ public URI getEntitySetUri() {
+ throw new EdmException("Not yet implemented");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuralTypeImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuralTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuralTypeImpl.java
new file mode 100644
index 0000000..94c668e
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuralTypeImpl.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmElement;
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata4.server.api.edm.provider.Property;
+import org.apache.olingo.odata4.server.api.edm.provider.StructuralType;
+
+public abstract class EdmStructuralTypeImpl extends EdmTypeImpl implements EdmStructuralType {
+
+ private final Map<String, EdmElement> properties = new HashMap<String, EdmElement>();
+ private ArrayList<String> navigationPropertyNames;
+ private ArrayList<String> propertyNames;
+ protected final EdmStructuralType baseType;
+ private final StructuralType structuralType;
+
+ public EdmStructuralTypeImpl(final EdmProviderImpl edm, final FullQualifiedName name,
+ final StructuralType structuralType, final EdmTypeKind kind) {
+ super(edm, name, kind);
+ this.structuralType = structuralType;
+ baseType = buildBaseType(structuralType.getBaseType());
+ buildProperties(structuralType.getProperties());
+ buildNavigationProperties(structuralType.getNavigationProperties());
+ }
+
+ private void buildNavigationProperties(final List<NavigationProperty> providerNavigationProperties) {
+ if (providerNavigationProperties != null) {
+ for (NavigationProperty navigationProperty : providerNavigationProperties) {
+ properties.put(navigationProperty.getName(), new EdmNavigationPropertyImpl(edm, navigationProperty));
+ }
+ }
+
+ }
+
+ private void buildProperties(final List<Property> providerProperties) {
+ if (providerProperties != null) {
+ for (Property property : providerProperties) {
+ properties.put(property.getName(), new EdmPropertyImpl(edm, property));
+ }
+ }
+
+ }
+
+ @Override
+ public EdmElement getProperty(final String name) {
+ EdmElement property = null;
+ if (baseType != null) {
+ property = baseType.getProperty(name);
+ }
+ if (property == null) {
+ property = properties.get(name);
+ }
+ return property;
+ }
+
+ @Override
+ public List<String> getPropertyNames() {
+ if (propertyNames == null) {
+ propertyNames = new ArrayList<String>();
+ if (baseType != null) {
+ propertyNames.addAll(baseType.getPropertyNames());
+ }
+ for (Property property : structuralType.getProperties()) {
+ propertyNames.add(property.getName());
+ }
+ }
+ return propertyNames;
+ }
+
+ @Override
+ public List<String> getNavigationPropertyNames() {
+ if (navigationPropertyNames == null) {
+ navigationPropertyNames = new ArrayList<String>();
+ if (baseType != null) {
+ navigationPropertyNames.addAll(baseType.getNavigationPropertyNames());
+ }
+ for (NavigationProperty navProperty : structuralType.getNavigationProperties()) {
+ navigationPropertyNames.add(navProperty.getName());
+ }
+ }
+ return navigationPropertyNames;
+ }
+
+ @Override
+ public boolean compatibleTo(final EdmType targetType) {
+ EdmStructuralType sourceType = this;
+ if (targetType == null) {
+ throw new EdmException("Target type must not be null");
+ }
+ while (sourceType.getName() != targetType.getName() ||
+ sourceType.getNamespace() != targetType.getNamespace()) {
+ sourceType = sourceType.getBaseType();
+ if (sourceType == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ protected abstract EdmStructuralType buildBaseType(FullQualifiedName baseTypeName);
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeDefinitionImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeDefinitionImpl.java
new file mode 100644
index 0000000..5e47b10
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeDefinitionImpl.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmException;
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.TypeDefinition;
+
+public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefinition {
+
+ private final FullQualifiedName typeDefinitionName;
+ private TypeDefinition typeDefinition;
+ private EdmPrimitiveType edmPrimitiveTypeInstance;
+
+ public EdmTypeDefinitionImpl(final EdmProviderImpl edm, final FullQualifiedName typeDefinitionName,
+ final TypeDefinition typeDefinition) {
+ super(edm, typeDefinitionName.getName());
+ this.typeDefinitionName = 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 boolean isCompatible(final EdmPrimitiveType primitiveType) {
+ return edmPrimitiveTypeInstance.isCompatible(primitiveType);
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return edmPrimitiveTypeInstance.getDefaultType();
+ }
+
+ @Override
+ public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode) {
+ return edmPrimitiveTypeInstance.validate(value, isNullable, maxLength, precision, scale, isUnicode);
+ }
+
+ @Override
+ public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+ return edmPrimitiveTypeInstance
+ .valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ }
+
+ @Override
+ public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode) throws EdmPrimitiveTypeException {
+ return edmPrimitiveTypeInstance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ }
+
+ @Override
+ public String toUriLiteral(final String literal) {
+ return edmPrimitiveTypeInstance.toUriLiteral(literal);
+ }
+
+ @Override
+ public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
+ return edmPrimitiveTypeInstance.fromUriLiteral(literal);
+ }
+
+ @Override
+ public String getNamespace() {
+ return typeDefinitionName.getNamespace();
+ }
+
+ @Override
+ public EdmTypeKind getKind() {
+ return EdmTypeKind.DEFINITION;
+ }
+
+ @Override
+ public EdmPrimitiveType getUnderlyingType() {
+ return edmPrimitiveTypeInstance;
+ }
+
+ @Override
+ public Integer getMaxLength() {
+ return typeDefinition.getMaxLength();
+ }
+
+ @Override
+ public Integer getPrecision() {
+ return typeDefinition.getPrecision();
+ }
+
+ @Override
+ public Integer getScale() {
+ return typeDefinition.getScale();
+ }
+
+ @Override
+ public Boolean isUnicode() {
+ return typeDefinition.getIsUnicode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImpl.java
new file mode 100644
index 0000000..dd83456
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImpl.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.odata4.server.core.edm.provider;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
+
+public abstract class EdmTypeImpl extends EdmNamedImpl implements EdmType {
+
+ private final EdmTypeKind kind;
+ private final String namespace;
+
+ public EdmTypeImpl(final EdmProviderImpl edm, final FullQualifiedName name, final EdmTypeKind kind) {
+ super(edm, name.getName());
+ namespace = name.getNamespace();
+ this.kind = kind;
+ }
+
+ @Override
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public EdmTypeKind getKind() {
+ return kind;
+ }
+
+}