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/03/07 10:09:29 UTC
[40/57] [abbrv] [OLINGO-186] client-side implementation of commons
Edm interfaces completed: some refactoring on server-side performed to
extract common abstract implementation
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java
index cd92170..be8b35b 100644
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java
@@ -18,51 +18,55 @@
*/
package org.apache.olingo.odata4.server.core.edm.provider;
+import java.util.Iterator;
import java.util.List;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget;
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.EdmException;
+import org.apache.olingo.odata4.commons.core.edm.AbstractEdmBindingTarget;
import org.apache.olingo.odata4.server.api.edm.provider.BindingTarget;
import org.apache.olingo.odata4.server.api.edm.provider.NavigationPropertyBinding;
-import org.apache.olingo.odata4.server.api.edm.provider.Target;
+import org.apache.olingo.odata4.commons.api.edm.Target;
-public abstract class EdmBindingTargetImpl extends EdmNamedImpl implements EdmBindingTarget {
+public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget {
- private BindingTarget target;
- private EdmEntityContainer container;
+ private final BindingTarget target;
- public EdmBindingTargetImpl(final EdmProviderImpl edm, final EdmEntityContainer container,
- final BindingTarget target) {
- super(edm, target.getName());
- this.container = container;
+ public EdmBindingTargetImpl(final Edm edm, final EdmEntityContainer container, final BindingTarget target) {
+ super(edm, container, target.getName(), target.getType());
this.target = target;
}
@Override
public EdmBindingTarget getRelatedBindingTarget(final String path) {
EdmBindingTarget bindingTarget = null;
- List<NavigationPropertyBinding> navigationPropertyBindings = target.getNavigationPropertyBindings();
+
+ final List<NavigationPropertyBinding> navigationPropertyBindings = target.getNavigationPropertyBindings();
if (navigationPropertyBindings != null) {
- for (NavigationPropertyBinding binding : navigationPropertyBindings) {
+ boolean found = false;
+ for (final Iterator<NavigationPropertyBinding> itor = navigationPropertyBindings.iterator();
+ itor.hasNext() && !found;) {
+
+ final NavigationPropertyBinding binding = itor.next();
if (binding.getPath().equals(path)) {
- Target providerTarget = binding.getTarget();
- EdmEntityContainer entityContainer = edm.getEntityContainer(providerTarget.getEntityContainer());
+ final Target providerTarget = binding.getTarget();
+ final EdmEntityContainer entityContainer = edm.getEntityContainer(providerTarget.getEntityContainer());
if (entityContainer == null) {
throw new EdmException("Cant find entity container with name: " + providerTarget.getEntityContainer());
}
- String targetName = providerTarget.getTargetName();
+ final String targetName = providerTarget.getTargetName();
bindingTarget = entityContainer.getEntitySet(targetName);
if (bindingTarget == null) {
bindingTarget = entityContainer.getSingleton(targetName);
- if (bindingTarget != null) {
- break;
- } else {
+ if (bindingTarget == null) {
throw new EdmException("Cant find target with name: " + targetName);
}
+
+ found = true;
} else {
- break;
+ found = true;
}
}
}
@@ -70,19 +74,4 @@ public abstract class EdmBindingTargetImpl extends EdmNamedImpl implements EdmBi
return bindingTarget;
}
-
- @Override
- public EdmEntityContainer getEntityContainer() {
- return container;
- }
-
- @Override
- public EdmEntityType getEntityType() {
- EdmEntityType type = edm.getEntityType(target.getType());
- if (type == null) {
- throw new EdmException("Can´t find entity type : " + target.getType() + "for entity set: " + target.getName());
- }
- return type;
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java
index 33e4a25..e409d09 100644
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java
@@ -18,34 +18,41 @@
*/
package org.apache.olingo.odata4.server.core.edm.provider;
-import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
+import java.util.Map;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
+import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
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.AbstractEdmComplexType;
+import org.apache.olingo.odata4.commons.core.edm.EdmStructuredTypeHelper;
import org.apache.olingo.odata4.server.api.edm.provider.ComplexType;
-public class EdmComplexTypeImpl extends EdmStructuralTypeImpl implements EdmComplexType {
+public class EdmComplexTypeImpl extends AbstractEdmComplexType {
- public EdmComplexTypeImpl(final EdmProviderImpl edm, final FullQualifiedName name, final ComplexType complexType) {
- super(edm, name, complexType, EdmTypeKind.COMPLEX);
+ private final EdmStructuredTypeHelper helper;
+
+ public static EdmComplexTypeImpl getInstance(
+ final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
+
+ final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, name, complexType);
+ instance.baseType = instance.buildBaseType(complexType.getBaseType());
+
+ return instance;
+ }
+
+ private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
+ super(edm, name, complexType.getBaseType());
+ this.helper = new EdmStructuredTypeHelperImpl(edm, complexType);
}
@Override
- public EdmComplexType getBaseType() {
- return (EdmComplexType) baseType;
+ protected Map<String, EdmProperty> getProperties() {
+ return helper.getProperties();
}
@Override
- protected EdmStructuralType buildBaseType(final FullQualifiedName baseTypeName) {
- EdmComplexType baseType = null;
- if (baseTypeName != null) {
- baseType = edm.getComplexType(baseTypeName);
- if (baseType == null) {
- throw new EdmException("Can't find base type with name: " + baseTypeName + " for complex type: " + getName());
- }
- }
- return baseType;
+ protected Map<String, EdmNavigationProperty> getNavigationProperties() {
+ return helper.getNavigationProperties();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmElementImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmElementImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmElementImpl.java
deleted file mode 100644
index c0d5277..0000000
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmElementImpl.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.EdmElement;
-
-public abstract class EdmElementImpl extends EdmNamedImpl implements EdmElement {
-
- public EdmElementImpl(final EdmProviderImpl edm, final String name) {
- super(edm, name);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java
index 2e2b8ff..9bc32fc 100644
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java
@@ -18,17 +18,14 @@
*/
package org.apache.olingo.odata4.server.core.edm.provider;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.olingo.odata4.commons.api.ODataException;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.EdmActionImport;
-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.EdmFunctionImport;
import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
-import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.core.edm.AbstractEdmEntityContainer;
import org.apache.olingo.odata4.server.api.edm.provider.ActionImport;
import org.apache.olingo.odata4.server.api.edm.provider.EdmProvider;
import org.apache.olingo.odata4.server.api.edm.provider.EntityContainerInfo;
@@ -36,100 +33,78 @@ 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.Singleton;
-public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityContainer {
+public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
- private final FullQualifiedName entityContainerName;
private final EdmProvider provider;
- private final Map<String, EdmSingleton> singletons = new HashMap<String, EdmSingleton>();
- private final Map<String, EdmEntitySet> entitySets = new HashMap<String, EdmEntitySet>();
- private final Map<String, EdmActionImport> actionImports = new HashMap<String, EdmActionImport>();
- private final Map<String, EdmFunctionImport> functionImports = new HashMap<String, EdmFunctionImport>();
-
- public EdmEntityContainerImpl(final EdmProviderImpl edm, final EdmProvider provider,
- final EntityContainerInfo entityContainerInfo) {
- super(edm, entityContainerInfo.getContainerName().getName());
+
+ public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider,
+ final EntityContainerInfo entityContainerInfo) {
+
+ super(edm, entityContainerInfo.getContainerName());
this.provider = provider;
- entityContainerName = entityContainerInfo.getContainerName();
}
@Override
- public String getNamespace() {
- return entityContainerName.getNamespace();
- }
+ protected EdmSingleton createSingleton(final String singletonName) {
+ EdmSingleton singleton = null;
- @Override
- public EdmSingleton getSingleton(final String singletonName) {
- EdmSingleton singleton = singletons.get(singletonName);
- if (singleton == null) {
- try {
- Singleton providerSingleton = provider.getSingleton(entityContainerName, singletonName);
- if (providerSingleton != null) {
- singleton = new EdmSingletonImpl(edm, this, providerSingleton);
- if (singleton != null) {
- singletons.put(singletonName, singleton);
- }
- }
- } catch (ODataException e) {
- throw new EdmException(e);
+ try {
+ final Singleton providerSingleton = provider.getSingleton(entityContainerName, singletonName);
+ if (providerSingleton != null) {
+ singleton = new EdmSingletonImpl(edm, this, providerSingleton);
}
+ } catch (ODataException e) {
+ throw new EdmException(e);
}
+
return singleton;
}
@Override
- public EdmEntitySet getEntitySet(final String entitySetName) {
- EdmEntitySet entitySet = entitySets.get(entitySetName);
- if (entitySet == null) {
- try {
- EntitySet providerEntitySet = provider.getEntitySet(entityContainerName, entitySetName);
- if (providerEntitySet != null) {
- entitySet = new EdmEntitySetImpl(edm, this, providerEntitySet);
- if (entitySet != null) {
- entitySets.put(entitySetName, entitySet);
- }
- }
- } catch (ODataException e) {
- throw new EdmException(e);
+ protected EdmEntitySet createEntitySet(final String entitySetName) {
+ EdmEntitySet entitySet = null;
+
+ try {
+ final EntitySet providerEntitySet = provider.getEntitySet(entityContainerName, entitySetName);
+ if (providerEntitySet != null) {
+ entitySet = new EdmEntitySetImpl(edm, this, providerEntitySet);
}
+ } catch (ODataException e) {
+ throw new EdmException(e);
}
+
return entitySet;
}
@Override
- public EdmActionImport getActionImport(final String actionImportName) {
- EdmActionImport actionImport = actionImports.get(actionImportName);
- if (actionImport == null) {
- try {
- ActionImport providerImport = provider.getActionImport(entityContainerName, actionImportName);
- if (providerImport != null) {
- actionImport = new EdmActionImportImpl(edm, actionImportName, this, providerImport);
- if (actionImport != null) {
- actionImports.put(actionImportName, actionImport);
- }
- }
- } catch (ODataException e) {
- throw new EdmException(e);
+ protected EdmActionImport createActionImport(final String actionImportName) {
+ EdmActionImport actionImport = null;
+
+ try {
+ final ActionImport providerImport = provider.getActionImport(entityContainerName, actionImportName);
+ if (providerImport != null) {
+ actionImport = new EdmActionImportImpl(edm, this, actionImportName, providerImport);
}
+ } catch (ODataException e) {
+ throw new EdmException(e);
}
+
return actionImport;
}
@Override
- public EdmFunctionImport getFunctionImport(final String functionImportName) {
- EdmFunctionImport functionImport = functionImports.get(functionImportName);
- if (functionImport == null) {
- try {
- FunctionImport providerImport = provider.getFunctionImport(entityContainerName, functionImportName);
- if (providerImport != null) {
- functionImport = new EdmFunctionImportImpl(edm, functionImportName, this, providerImport);
- if (functionImport != null) {
- functionImports.put(functionImportName, functionImport);
- }
- }
- } catch (ODataException e) {
- throw new EdmException(e);
+ protected EdmFunctionImport createFunctionImport(final String functionImportName) {
+ EdmFunctionImport functionImport = null;
+
+ try {
+ final FunctionImport providerImport = provider.getFunctionImport(entityContainerName, functionImportName);
+ if (providerImport != null) {
+ functionImport = new EdmFunctionImportImpl(edm, this, functionImportName, providerImport);
}
+ } catch (ODataException e) {
+ throw new EdmException(e);
}
+
return functionImport;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java
index d724a5d..7305b1e 100644
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java
@@ -18,13 +18,14 @@
*/
package org.apache.olingo.odata4.server.core.edm.provider;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet;
import org.apache.olingo.odata4.server.api.edm.provider.EntitySet;
public class EdmEntitySetImpl extends EdmBindingTargetImpl implements EdmEntitySet {
- public EdmEntitySetImpl(final EdmProviderImpl edm, final EdmEntityContainer container, final EntitySet entitySet) {
+ public EdmEntitySetImpl(final Edm edm, final EdmEntityContainer container, final EntitySet entitySet) {
super(edm, container, entitySet);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImpl.java
deleted file mode 100644
index 0d167b7..0000000
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.EdmEntitySetInfo;
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata4.server.api.edm.provider.EntitySet;
-
-public class EdmEntitySetInfoImpl implements EdmEntitySetInfo {
-
- private final EntityContainer entityContainer;
- private final EntitySet set;
-
- public EdmEntitySetInfoImpl(final EntityContainer entityContainer, final EntitySet set) {
- this.entityContainer = entityContainer;
- this.set = set;
- }
-
- @Override
- public String getEntityContainerName() {
- return entityContainer.getName();
- }
-
- @Override
- public String getEntitySetName() {
- return set.getName();
- }
-
- @Override
- public URI getEntitySetUri() {
- throw new EdmException("Not yet implemented");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java
index 557dd01..41b8ea9 100644
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java
@@ -19,101 +19,69 @@
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.Edm;
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.EdmStructuralType;
+import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
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.AbstractEdmEntityType;
+import org.apache.olingo.odata4.commons.core.edm.EdmStructuredTypeHelper;
import org.apache.olingo.odata4.server.api.edm.provider.EntityType;
import org.apache.olingo.odata4.server.api.edm.provider.PropertyRef;
-public class EdmEntityTypeImpl extends EdmStructuralTypeImpl implements EdmEntityType {
+public class EdmEntityTypeImpl extends AbstractEdmEntityType {
- private EntityType entityType;
- private final List<String> keyPredicateNames = new ArrayList<String>();
- private final HashMap<String, EdmKeyPropertyRef> keyPropertyRefs = new HashMap<String, EdmKeyPropertyRef>();
- private final EdmEntityType entityBaseType;
- private ArrayList<EdmKeyPropertyRef> keyPropertyRefsList;
+ private final EdmStructuredTypeHelper helper;
- public EdmEntityTypeImpl(final EdmProviderImpl edm, final FullQualifiedName name, final EntityType entityType) {
- super(edm, name, entityType, EdmTypeKind.ENTITY);
- this.entityType = entityType;
- if (baseType == null) {
- entityBaseType = null;
- List<PropertyRef> key = entityType.getKey();
+ private final EntityType entityType;
+
+ public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName name,
+ final EntityType entityType) {
+
+ final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, name, entityType);
+ instance.baseType = instance.buildBaseType(entityType.getBaseType());
+
+ if (instance.baseType == null) {
+ 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) {
- EdmKeyPropertyRef edmKeyRef = new EdmKeyPropertyRefImpl(this, ref);
- if (ref.getAlias() != null) {
- keyPredicateNames.add(ref.getAlias());
- keyPropertyRefs.put(ref.getAlias(), edmKeyRef);
- } else {
- keyPredicateNames.add(ref.getPropertyName());
- keyPropertyRefs.put(ref.getPropertyName(), edmKeyRef);
- }
+ edmKey.add(new EdmKeyPropertyRefImpl(instance, ref));
}
+ instance.setEdmKeyPropertyRef(edmKey);
}
} else {
- entityBaseType = (EdmEntityType) baseType;
+ instance.entityBaseType = (EdmEntityType) instance.baseType;
}
+ return instance;
}
- @Override
- public boolean hasStream() {
- return entityType.hasStream();
- }
-
- @Override
- public EdmEntityType getBaseType() {
- return entityBaseType;
- }
-
- @Override
- public List<String> getKeyPredicateNames() {
- if (keyPredicateNames.isEmpty() && baseType != null) {
- return entityBaseType.getKeyPredicateNames();
- }
- return keyPredicateNames;
- }
+ private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) {
+ super(edm, name, entityType.getBaseType(), entityType.hasStream());
- @Override
- public List<EdmKeyPropertyRef> getKeyPropertyRefs() {
- if (keyPropertyRefsList == null) {
- keyPropertyRefsList = new ArrayList<EdmKeyPropertyRef>(keyPropertyRefs.values());
- }
- if (keyPropertyRefsList.isEmpty() && entityBaseType != null) {
- return entityBaseType.getKeyPropertyRefs();
- }
- return keyPropertyRefsList;
+ this.helper = new EdmStructuredTypeHelperImpl(edm, entityType);
+ this.entityType = entityType;
}
@Override
- public EdmKeyPropertyRef getKeyPropertyRef(final String keyPredicateName) {
- EdmKeyPropertyRef edmKeyPropertyRef = keyPropertyRefs.get(keyPredicateName);
- if (edmKeyPropertyRef == null && entityBaseType != null) {
- return entityBaseType.getKeyPropertyRef(keyPredicateName);
- }
- return edmKeyPropertyRef;
+ protected Map<String, EdmProperty> getProperties() {
+ return helper.getProperties();
}
@Override
- protected EdmStructuralType buildBaseType(final FullQualifiedName baseTypeName) {
- EdmEntityType baseType = null;
- if (baseTypeName != null) {
- baseType = edm.getEntityType(baseTypeName);
- if (baseType == null) {
- throw new EdmException("Cannot find base type with name: " + baseTypeName + " for entity type: " + getName());
- }
- }
- return baseType;
+ protected Map<String, EdmNavigationProperty> getNavigationProperties() {
+ return helper.getNavigationProperties();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
deleted file mode 100644
index 5de9cf2..0000000
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * 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/bae3d847/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTypeImpl.java
new file mode 100644
index 0000000..4e88b49
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTypeImpl.java
@@ -0,0 +1,61 @@
+/*
+ * 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.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.FullQualifiedName;
+import org.apache.olingo.odata4.commons.core.edm.AbstractEdmEnumType;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.server.api.edm.provider.EnumType;
+
+public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType {
+
+ private final EdmPrimitiveType underlyingType;
+
+ private final EnumType enumType;
+
+ public EdmEnumTypeImpl(final EdmProviderImpl edm, final FullQualifiedName enumName, final EnumType enumType) {
+ super(edm, enumName, enumType.isFlags());
+
+ if (enumType.getUnderlyingType() == null) {
+ this.underlyingType = EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance();
+ } else {
+ this.underlyingType = EdmPrimitiveTypeKind.valueOf(
+ enumType.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance();
+ // TODO: Should we validate that the underlying type is of byte, sbyte, in16, int32 or int64?
+ }
+
+ this.enumType = enumType;
+ }
+
+ @Override
+ public EdmPrimitiveType getUnderlyingType() {
+ return underlyingType;
+ }
+
+ @Override
+ protected List<? extends EdmMember> getMembers() {
+ return enumType.getMembers();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
index 61f513a..f2e3cf2 100644
--- 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
@@ -18,6 +18,7 @@
*/
package org.apache.olingo.odata4.server.core.edm.provider;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
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;
@@ -27,9 +28,13 @@ import org.apache.olingo.odata4.server.api.edm.provider.Function;
public class EdmFunctionImpl extends EdmOperationImpl implements EdmFunction {
- private Function function;
+ private final Function function;
- public EdmFunctionImpl(final EdmProviderImpl edm, final FullQualifiedName name, final Function function) {
+ public static EdmFunctionImpl getInstance(final Edm edm, final FullQualifiedName name, final Function function) {
+ return EdmOperationImpl.getInstance(new EdmFunctionImpl(edm, name, function));
+ }
+
+ private EdmFunctionImpl(final Edm edm, final FullQualifiedName name, final Function function) {
super(edm, name, function, EdmTypeKind.FUNCTION);
this.function = function;
}
@@ -41,7 +46,7 @@ public class EdmFunctionImpl extends EdmOperationImpl implements EdmFunction {
@Override
public EdmReturnType getReturnType() {
- EdmReturnType returnType = super.getReturnType();
+ final EdmReturnType returnType = super.getReturnType();
if (returnType == null) {
throw new EdmException("ReturnType for a function must not be null");
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
index 487ae51..f4e06f1 100644
--- 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
@@ -19,6 +19,7 @@
package org.apache.olingo.odata4.server.core.edm.provider;
import java.util.List;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
@@ -29,9 +30,10 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm
private final FunctionImport functionImport;
- public EdmFunctionImportImpl(final EdmProviderImpl edm, final String name, final EdmEntityContainer container,
- final FunctionImport functionImport) {
- super(edm, name, container, functionImport);
+ public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
+ final FunctionImport functionImport) {
+
+ super(edm, container, name, functionImport);
this.functionImport = functionImport;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
deleted file mode 100644
index 025d919..0000000
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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/bae3d847/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
index 6bff7e3..06351ac 100644
--- 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
@@ -19,20 +19,15 @@
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.commons.core.edm.AbstractEdmKeyPropertyRef;
import org.apache.olingo.odata4.server.api.edm.provider.PropertyRef;
-public class EdmKeyPropertyRefImpl implements EdmKeyPropertyRef {
+public class EdmKeyPropertyRefImpl extends AbstractEdmKeyPropertyRef {
- private PropertyRef ref;
- private EdmEntityType edmEntityType;
- private EdmProperty property;
+ private final PropertyRef ref;
public EdmKeyPropertyRefImpl(final EdmEntityType edmEntityType, final PropertyRef ref) {
- this.edmEntityType = edmEntityType;
+ super(edmEntityType);
this.ref = ref;
}
@@ -50,40 +45,4 @@ public class EdmKeyPropertyRefImpl implements EdmKeyPropertyRef {
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/bae3d847/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
deleted file mode 100644
index b42e39b..0000000
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImpl.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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/bae3d847/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
deleted file mode 100644
index 2526e07..0000000
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImpl.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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/bae3d847/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
index c452d8e..3399467 100644
--- 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
@@ -20,35 +20,24 @@ 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.commons.api.edm.Edm;
+import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.odata4.commons.core.edm.AbstractEdmNavigationProperty;
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 {
+public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty {
private final NavigationProperty navigationProperty;
- private EdmEntityType typeImpl;
- private EdmNavigationProperty partnerNavigationProperty;
- public EdmNavigationPropertyImpl(final EdmProviderImpl edm, final NavigationProperty navigationProperty) {
+ public EdmNavigationPropertyImpl(final Edm 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;
+ protected FullQualifiedName getTypeFQN() {
+ return navigationProperty.getType();
}
@Override
@@ -62,29 +51,13 @@ public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavi
}
@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;
+ protected String internatGetPartner() {
+ return navigationProperty.getPartner();
}
@Override
public String getReferencingPropertyName(final String referencedPropertyName) {
- List<ReferentialConstraint> referentialConstraints = navigationProperty.getReferentialConstraints();
+ final List<ReferentialConstraint> referentialConstraints = navigationProperty.getReferentialConstraints();
if (referentialConstraints != null) {
for (ReferentialConstraint constraint : referentialConstraints) {
if (constraint.getReferencedProperty().equals(referencedPropertyName)) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
index 4806682..73f440b 100644
--- 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
@@ -19,92 +19,49 @@
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.Edm;
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.commons.core.edm.AbstractEdmOperation;
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 {
+public abstract class EdmOperationImpl extends AbstractEdmOperation {
- private final Map<String, EdmParameter> parameters = new HashMap<String, EdmParameter>();
- private final Operation operation;
- private EdmReturnType returnType;
- private List<String> parameterNames;
+ protected final Operation operation;
- 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();
+ protected static <T extends EdmOperationImpl> T getInstance(final T instance) {
+ final List<Parameter> providerParameters = instance.operation.getParameters();
if (providerParameters != null) {
+ final List<EdmParameter> _parameters = new ArrayList<EdmParameter>(providerParameters.size());
for (Parameter parameter : providerParameters) {
- parameters.put(parameter.getName(), new EdmParameterImpl(edm, parameter));
+ _parameters.add(new EdmParameterImpl(instance.edm, parameter));
}
+ instance.setParameters(_parameters);
}
- }
-
- @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());
- }
- }
+ final EntitySetPath entitySetPath = instance.operation.getEntitySetPath();
+ if (entitySetPath != null && entitySetPath.getPath() != null) {
+ instance.setEntitySetPath(entitySetPath.getPath());
}
- 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");
- }
+ instance.setIsBound(instance.operation.isBound());
+ if (instance.operation.getReturnType() != null) {
+ instance.setReturnType(new EdmReturnTypeImpl(instance.edm, instance.operation.getReturnType()));
}
- return returnedEntitySet;
- }
- @Override
- public EdmReturnType getReturnType() {
- if (returnType == null && operation.getReturnType() != null) {
- returnType = new EdmReturnTypeImpl(edm, operation.getReturnType());
- }
- return returnType;
+ return instance;
}
- @Override
- public boolean isBound() {
- return operation.isBound();
- }
+ protected EdmOperationImpl(final Edm edm, final FullQualifiedName name, final Operation operation,
+ final EdmTypeKind kind) {
+ super(edm, name, kind);
+ this.operation = operation;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
index 41159ce..51ea5f7 100644
--- 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
@@ -18,45 +18,16 @@
*/
package org.apache.olingo.odata4.server.core.edm.provider;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
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;
+import org.apache.olingo.odata4.commons.core.edm.AbstractEdmOperationImport;
-public abstract class EdmOperationImportImpl extends EdmNamedImpl implements EdmOperationImport {
+public abstract class EdmOperationImportImpl extends AbstractEdmOperationImport {
- private final OperationImport operationImport;
- private final EdmEntityContainer container;
- private EdmEntitySet returnedEntitySet;
+ public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
+ final OperationImport operationImport) {
- public EdmOperationImportImpl(final EdmProviderImpl edm, final String name, final EdmEntityContainer container,
- final OperationImport operationImport) {
- super(edm, name);
- this.container = container;
- this.operationImport = operationImport;
+ super(edm, container, name, operationImport.getEntitySet());
}
-
- @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/bae3d847/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
index 3ae417b..47679f6 100644
--- 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
@@ -18,55 +18,21 @@
*/
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.Edm;
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.commons.core.edm.AbstractEdmParameter;
import org.apache.olingo.odata4.server.api.edm.provider.Parameter;
-public class EdmParameterImpl extends EdmElementImpl implements EdmParameter {
+public class EdmParameterImpl extends AbstractEdmParameter {
private final Parameter parameter;
- private EdmType typeImpl;
- public EdmParameterImpl(final EdmProviderImpl edm, final Parameter parameter) {
- super(edm, parameter.getName());
+ public EdmParameterImpl(final Edm edm, final Parameter parameter) {
+ super(edm, parameter.getName(), parameter.getType());
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();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
index 4882a29..46381fd 100644
--- 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
@@ -18,52 +18,25 @@
*/
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.Edm;
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.commons.core.edm.AbstractEdmProperty;
import org.apache.olingo.odata4.server.api.edm.provider.Property;
-public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
+public class EdmPropertyImpl extends AbstractEdmProperty implements EdmProperty {
private final Property property;
- private final boolean isPrimitive;
- private EdmType propertyType;
- public EdmPropertyImpl(final EdmProviderImpl edm, final Property property) {
+ public EdmPropertyImpl(final Edm 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;
+ protected FullQualifiedName getTypeFQN() {
+ return property.getType();
}
@Override
@@ -82,11 +55,6 @@ public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
}
@Override
- public boolean isPrimitive() {
- return isPrimitive;
- }
-
- @Override
public Boolean isNullable() {
return property.getNullable();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
index 49a14fc..f2ded8c 100644
--- 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
@@ -50,7 +50,9 @@ import org.apache.olingo.odata4.server.api.edm.provider.TypeDefinition;
public class EdmProviderImpl extends AbstractEdmImpl {
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) {
@@ -76,7 +78,7 @@ public class EdmProviderImpl extends AbstractEdmImpl {
try {
EnumType enumType = provider.getEnumType(enumName);
if (enumType != null) {
- return new EdmEnumImpl(this, enumName, enumType);
+ return new EdmEnumTypeImpl(this, enumName, enumType);
}
return null;
} catch (ODataException e) {
@@ -102,7 +104,7 @@ public class EdmProviderImpl extends AbstractEdmImpl {
try {
EntityType entityType = provider.getEntityType(entityTypeName);
if (entityType != null) {
- return new EdmEntityTypeImpl(this, entityTypeName, entityType);
+ return EdmEntityTypeImpl.getInstance(this, entityTypeName, entityType);
}
return null;
} catch (ODataException e) {
@@ -113,9 +115,9 @@ public class EdmProviderImpl extends AbstractEdmImpl {
@Override
public EdmComplexType createComplexType(final FullQualifiedName complexTypeName) {
try {
- ComplexType complexType = provider.getComplexType(complexTypeName);
+ final ComplexType complexType = provider.getComplexType(complexTypeName);
if (complexType != null) {
- return new EdmComplexTypeImpl(this, complexTypeName, complexType);
+ return EdmComplexTypeImpl.getInstance(this, complexTypeName, complexType);
}
return null;
} catch (ODataException e) {
@@ -125,32 +127,32 @@ 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) {
actions = provider.getActions(actionName);
- if (actions != null) {
- actionsMap.put(actionName, actions);
- } else {
+ if (actions == null) {
return null;
+ } else {
+ actionsMap.put(actionName, actions);
}
}
- 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 (action.isBound()) {
+ final List<Parameter> parameters = action.getParameters();
+ final Parameter parameter = parameters.get(0);
if (bindingParameterTypeName.equals(parameter.getType())
- && isBindingParameterCollection.booleanValue() == parameter.isCollection()) {
- actionImpl = new EdmActionImpl(this, actionName, action);
- break;
+ && isBindingParameterCollection.booleanValue() == parameter.isCollection()) {
+
+ return EdmActionImpl.getInstance(this, actionName, action);
}
}
}
- return actionImpl;
+ return null;
} catch (ODataException e) {
throw new EdmException(e);
}
@@ -158,46 +160,43 @@ 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) {
functions = provider.getFunctions(functionName);
- if (functions != null) {
- functionsMap.put(functionName, functions);
- } else {
+ if (functions == null) {
return null;
+ } else {
+ functionsMap.put(functionName, functions);
}
}
- List<String> parameterNamesCopy = parameterNames;
- if (parameterNamesCopy == null) {
- parameterNamesCopy = Collections.emptyList();
- }
- EdmFunctionImpl functionImpl = null;
+ final List<String> parameterNamesCopy = parameterNames == null? Collections.<String>emptyList(): parameterNames;
for (Function function : functions) {
- if (function.isBound() == true) {
+ if (function.isBound()) {
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);
+ 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) {
- List<String> providerParameterNames = new ArrayList<String>();
+ final 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 EdmFunctionImpl.getInstance(this, functionName, function);
}
}
}
}
}
- return functionImpl;
+ return null;
} catch (ODataException e) {
throw new EdmException(e);
}
@@ -210,9 +209,9 @@ public class EdmProviderImpl extends AbstractEdmImpl {
@Override
protected Map<String, String> createAliasToNamespaceInfo() {
- Map<String, String> aliasToNamespaceInfos = new HashMap<String, String>();
+ final Map<String, String> aliasToNamespaceInfos = new HashMap<String, String>();
try {
- List<AliasInfo> aliasInfos = provider.getAliasInfos();
+ final List<AliasInfo> aliasInfos = provider.getAliasInfos();
if (aliasInfos != null) {
for (AliasInfo info : aliasInfos) {
aliasToNamespaceInfos.put(info.getAlias(), info.getNamespace());
@@ -230,21 +229,19 @@ public class EdmProviderImpl extends AbstractEdmImpl {
List<Action> actions = actionsMap.get(actionName);
if (actions == null) {
actions = provider.getActions(actionName);
- if (actions != null) {
- actionsMap.put(actionName, actions);
- } else {
+ if (actions == null) {
return null;
+ } else {
+ actionsMap.put(actionName, actions);
}
}
- EdmActionImpl actionImpl = null;
// Search for first unbound action
for (Action action : actions) {
- if (action.isBound() == false) {
- actionImpl = new EdmActionImpl(this, actionName, action);
- break;
+ if (!action.isBound()) {
+ return EdmActionImpl.getInstance(this, actionName, action);
}
}
- return actionImpl;
+ return null;
} catch (ODataException e) {
throw new EdmException(e);
}
@@ -262,13 +259,9 @@ public class EdmProviderImpl extends AbstractEdmImpl {
return null;
}
}
- List<String> parameterNamesCopy = parameterNames;
- if (parameterNamesCopy == null) {
- parameterNamesCopy = Collections.emptyList();
- }
- EdmFunctionImpl functionImpl = null;
+ final List<String> parameterNamesCopy = parameterNames == null? Collections.<String>emptyList(): parameterNames;
for (Function function : functions) {
- if (function.isBound() == false) {
+ if (!function.isBound()) {
List<Parameter> providerParameters = function.getParameters();
if (providerParameters == null) {
providerParameters = Collections.emptyList();
@@ -280,13 +273,12 @@ public class EdmProviderImpl extends AbstractEdmImpl {
}
if (parameterNamesCopy.containsAll(functionParameterNames)) {
- functionImpl = new EdmFunctionImpl(this, functionName, function);
- break;
+ return EdmFunctionImpl.getInstance(this, functionName, function);
}
}
}
}
- return functionImpl;
+ return null;
} catch (ODataException e) {
throw new EdmException(e);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bae3d847/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
index e94d8a0..19700af 100644
--- 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
@@ -18,56 +18,20 @@
*/
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.AbstractEdmImpl;
-import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
+import org.apache.olingo.odata4.commons.core.edm.AbstractEdmReturnType;
import org.apache.olingo.odata4.server.api.edm.provider.ReturnType;
-public class EdmReturnTypeImpl implements EdmReturnType {
+public class EdmReturnTypeImpl extends AbstractEdmReturnType {
- private final AbstractEdmImpl edm;
private final ReturnType returnType;
- private EdmType typeImpl;
- public EdmReturnTypeImpl(final AbstractEdmImpl edm, final ReturnType returnType) {
- this.edm = edm;
+ public EdmReturnTypeImpl(final Edm edm, final ReturnType returnType) {
+ super(edm, returnType.getType());
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();
}