From 62f100148a9dd8c7389c0ced8e9dd08e8f687515 Mon Sep 17 00:00:00 2001 From: Christian Amend Date: Mon, 30 Mar 2015 15:14:40 +0200 Subject: [PATCH] [OLINGO-575] Finish Edm Refactoring --- .../ext/pojogen/AbstractPOJOGenMojo.java | 53 +++--- .../pojogen/NavPropertyBindingDetails.java | 53 +++--- .../apache/olingo/commons/api/edm/Edm.java | 9 + .../olingo/commons/api/edm/EdmSchema.java | 18 -- .../olingo/commons/core/edm/AbstractEdm.java | 166 +++++++++--------- .../core/edm/provider/EdmAnnotationsImpl.java | 38 ++-- .../core/edm/provider/EdmProviderImpl.java | 6 +- .../core/edm/provider/EdmSchemaImpl.java | 126 +++++++------ 8 files changed, 226 insertions(+), 243 deletions(-) diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java index 5caeafbf6..9321c6429 100644 --- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -112,12 +112,12 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { protected File mkPkgDir(final String path) { return StringUtils.isBlank(basePackage) - ? mkdir(path) - : mkdir(basePackage.replace('.', File.separatorChar) + File.separator + path); + ? mkdir(path) + : mkdir(basePackage.replace('.', File.separatorChar) + File.separator + path); } protected void writeFile(final String name, final File path, final VelocityContext ctx, final Template template, - final boolean append) throws MojoExecutionException { + final boolean append) throws MojoExecutionException { if (!path.exists()) { throw new IllegalArgumentException("Invalid base path '" + path.getAbsolutePath() + "'"); @@ -152,30 +152,30 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { } protected void parseObj(final File base, final String pkg, final String name, final String out) - throws MojoExecutionException { + throws MojoExecutionException { - parseObj(base, false, pkg, name, out, Collections.emptyMap()); + parseObj(base, false, pkg, name, out, Collections. emptyMap()); } protected void parseObj( - final File base, - final String pkg, - final String name, - final String out, - final Map objs) - throws MojoExecutionException { + final File base, + final String pkg, + final String name, + final String out, + final Map objs) + throws MojoExecutionException { parseObj(base, false, pkg, name, out, objs); } protected void parseObj( - final File base, - final boolean append, - final String pkg, - final String name, - final String out, - final Map objs) - throws MojoExecutionException { + final File base, + final boolean append, + final String pkg, + final String name, + final String out, + final Map objs) + throws MojoExecutionException { final VelocityContext ctx = newContext(); ctx.put("package", pkg); @@ -351,7 +351,8 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { } // write container and top entity sets into the base package - for (EdmEntityContainer container : schema.getEntityContainers()) { + EdmEntityContainer container = schema.getEntityContainer(); + if(container != null){ objs.clear(); objs.put("container", container); objs.put("namespace", schema.getNamespace()); diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java index 48bf288b8..75f2105f8 100644 --- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java @@ -60,21 +60,19 @@ public class NavPropertyBindingDetails { } private EdmBindingTarget getNavigationBindingDetails(final EdmStructuredType type) { - for (EdmSchema sc : edm.getSchemas()) { - for (EdmEntityContainer c : sc.getEntityContainers()) { - for (EdmEntitySet es : c.getEntitySets()) { - if (es.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) { - return es; - } - } - - for (EdmSingleton s : c.getSingletons()) { - if (s.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) { - return s; - } + EdmEntityContainer c = edm.getEntityContainer(); + if (c != null) { + for (EdmEntitySet es : c.getEntitySets()) { + if (es.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) { + return es; } } + for (EdmSingleton s : c.getSingletons()) { + if (s.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) { + return s; + } + } } throw new IllegalStateException("EntitySet for '" + type.getName() + "' not found"); @@ -83,26 +81,25 @@ public class NavPropertyBindingDetails { private EdmBindingTarget getNavigationBindingDetails( final EdmStructuredType sourceType, final EdmNavigationProperty property) { - for (EdmSchema sc : edm.getSchemas()) { - for (EdmEntityContainer c : sc.getEntityContainers()) { - for (EdmEntitySet es : c.getEntitySets()) { - if (es.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) { - for (EdmNavigationPropertyBinding binding : es.getNavigationPropertyBindings()) { - if (binding.getPath().equals(property.getName()) - || binding.getPath().endsWith("/" + property.getName())) { - return es.getRelatedBindingTarget(binding.getPath()); - } + EdmEntityContainer c = edm.getEntityContainer(); + if (c != null) { + for (EdmEntitySet es : c.getEntitySets()) { + if (es.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) { + for (EdmNavigationPropertyBinding binding : es.getNavigationPropertyBindings()) { + if (binding.getPath().equals(property.getName()) + || binding.getPath().endsWith("/" + property.getName())) { + return es.getRelatedBindingTarget(binding.getPath()); } } } + } - for (EdmSingleton s : c.getSingletons()) { - if (s.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) { - for (EdmNavigationPropertyBinding binding : s.getNavigationPropertyBindings()) { - if (binding.getPath().equals(property.getName()) - || binding.getPath().endsWith("/" + property.getName())) { - return s.getRelatedBindingTarget(binding.getPath()); - } + for (EdmSingleton s : c.getSingletons()) { + if (s.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) { + for (EdmNavigationPropertyBinding binding : s.getNavigationPropertyBindings()) { + if (binding.getPath().equals(property.getName()) + || binding.getPath().endsWith("/" + property.getName())) { + return s.getRelatedBindingTarget(binding.getPath()); } } } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java index 8790afb72..7b9376aa6 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java @@ -42,6 +42,15 @@ public interface Edm { */ EdmSchema getSchema(String namespace); + /** + * Get main entity container. + *
+ * See {@link EdmEntityContainer} for more information. + * + * @return {@link EdmEntityContainer} + */ + EdmEntityContainer getEntityContainer(); + /** * Get entity container by full qualified name. *
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java index 1f4667cc8..837514e9c 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java @@ -80,22 +80,4 @@ public interface EdmSchema extends EdmAnnotatable { */ EdmEntityContainer getEntityContainer(); - /** - * Returns the list of entity containers for this schema. - *
- * According to CSDL specifications, this method will always return a singleton list for OData 4.0, containing the - * same container as returned by {@link #getEntityContainer()}. - * - * @return the list of entity containers for this schema; singleton list for OData 4.0 - */ - List getEntityContainers(); - - /** - * Returns the entity container for the given name, or null if not found. - * - * @param name entity container full qualified name - * @return the entity container for the given name, or null if not found - */ - EdmEntityContainer getEntityContainer(FullQualifiedName name); - } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java index bc0b304e9..e865aa6b5 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java @@ -79,13 +79,17 @@ public abstract class AbstractEdm implements Edm { @Override public List getSchemas() { - initSchemas(); + if (schemaList == null) { + initSchemas(); + } return schemaList; } @Override public EdmSchema getSchema(final String namespace) { - initSchemas(); + if (schemas == null) { + initSchemas(); + } EdmSchema schema = schemas.get(namespace); if (schema == null) { @@ -99,93 +103,19 @@ public abstract class AbstractEdm implements Edm { } private void initSchemas() { + aliasToNamespaceInfo = new HashMap(); + schemas = createSchemas(); if (schemas == null) { - schemas = createSchemas(); - if (schemas != null) { - schemaList = Collections.unmodifiableList(new ArrayList(schemas.values())); - aliasToNamespaceInfo = new HashMap(); - for (EdmSchema schema : schemas.values()) { - final String namespace = schema.getNamespace(); - - if (schema.getAlias() != null) { - aliasToNamespaceInfo.put(schema.getAlias(), namespace); - } - - final List localEnumTypes = schema.getEnumTypes(); - if (localEnumTypes != null) { - for (EdmEnumType enumType : localEnumTypes) { - enumTypes.put(new FullQualifiedName(namespace, enumType.getName()), enumType); - } - } - - final List localTypeDefinitions = schema.getTypeDefinitions(); - if (localTypeDefinitions != null) { - for (EdmTypeDefinition typeDef : localTypeDefinitions) { - typeDefinitions.put(new FullQualifiedName(namespace, typeDef.getName()), typeDef); - } - } - - final List localComplexTypes = schema.getComplexTypes(); - if (localComplexTypes != null) { - for (EdmComplexType complexType : localComplexTypes) { - complexTypes.put(new FullQualifiedName(namespace, complexType.getName()), complexType); - } - } - - List localEntityTypes = schema.getEntityTypes(); - if (localEntityTypes != null) { - for (EdmEntityType entityType : localEntityTypes) { - entityTypes.put(new FullQualifiedName(namespace, entityType.getName()), entityType); - } - } - - final List localActions = schema.getActions(); - if (localActions != null) { - for (EdmAction action : localActions) { - final FullQualifiedName name = new FullQualifiedName(namespace, action.getName()); - if (action.isBound()) { - final ActionMapKey key = new ActionMapKey(name, - action.getBindingParameterTypeFqn(), action.isBindingParameterTypeCollection()); - boundActions.put(key, action); - } else { - unboundActions.put(name, action); - } - } - } - - final List localFunctions = schema.getFunctions(); - if (localFunctions != null) { - for (EdmFunction function : localFunctions) { - final FullQualifiedName name = new FullQualifiedName(namespace, function.getName()); - final FunctionMapKey key = new FunctionMapKey(name, - function.getBindingParameterTypeFqn(), function.isBindingParameterTypeCollection(), - function.getParameterNames()); - - if (function.isBound()) { - boundFunctions.put(key, function); - } else { - if (!unboundFunctionsByName.containsKey(name)) { - unboundFunctionsByName.put(name, new ArrayList()); - } - unboundFunctionsByName.get(name).add(function); - - unboundFunctionsByKey.put(key, function); - } - } - } - - final EdmEntityContainer entityContainer = schema.getEntityContainer(); - if (entityContainer != null) { - entityContainers.put(new FullQualifiedName(namespace, entityContainer.getName()), entityContainer); - if (!entityContainers.containsKey(null)) { - entityContainers.put(null, entityContainer); - } - } - } - } + schemas = Collections.emptyMap(); } + schemaList = Collections.unmodifiableList(new ArrayList(schemas.values())); } + @Override + public EdmEntityContainer getEntityContainer() { + return getEntityContainer(null); + } + @Override public EdmEntityContainer getEntityContainer(final FullQualifiedName namespaceOrAliasFQN) { final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); @@ -419,16 +349,43 @@ public abstract class AbstractEdm implements Edm { protected abstract Map createAliasToNamespaceInfo(); + public void cacheAliasNamespaceInfo(String alias, String namespace) { + if (aliasToNamespaceInfo == null) { + aliasToNamespaceInfo = new HashMap(); + } + aliasToNamespaceInfo.put(alias, namespace); + } + protected abstract EdmEntityContainer createEntityContainer(FullQualifiedName containerName); + public void cacheEntityContainer(FullQualifiedName containerFQN, EdmEntityContainer container) { + entityContainers.put(containerFQN, container); + } + protected abstract EdmEnumType createEnumType(FullQualifiedName enumName); + public void cacheEnumType(FullQualifiedName enumName, EdmEnumType enumType) { + enumTypes.put(enumName, enumType); + } + protected abstract EdmTypeDefinition createTypeDefinition(FullQualifiedName typeDefinitionName); + public void cacheTypeDefinition(FullQualifiedName typeDefName, EdmTypeDefinition typeDef) { + typeDefinitions.put(typeDefName, typeDef); + } + protected abstract EdmEntityType createEntityType(FullQualifiedName entityTypeName); + public void cacheEntityType(FullQualifiedName entityTypeName, EdmEntityType entityType) { + entityTypes.put(entityTypeName, entityType); + } + protected abstract EdmComplexType createComplexType(FullQualifiedName complexTypeName); + public void cacheComplexType(FullQualifiedName compelxTypeName, EdmComplexType complexType) { + complexTypes.put(compelxTypeName, complexType); + } + protected abstract EdmAction createUnboundAction(FullQualifiedName actionName); protected abstract List createUnboundFunctions(FullQualifiedName functionName); @@ -443,9 +400,48 @@ public abstract class AbstractEdm implements Edm { FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection, List parameterNames); + public void cacheFunction(FullQualifiedName functionName, EdmFunction function) { + final FunctionMapKey key = new FunctionMapKey(functionName, + function.getBindingParameterTypeFqn(), function.isBindingParameterTypeCollection(), + function.getParameterNames()); + + if (function.isBound()) { + boundFunctions.put(key, function); + } else { + if (!unboundFunctionsByName.containsKey(functionName)) { + unboundFunctionsByName.put(functionName, new ArrayList()); + } + unboundFunctionsByName.get(functionName).add(function); + + unboundFunctionsByKey.put(key, function); + } + } + + public void cacheAction(FullQualifiedName actionName, EdmAction action) { + if (action.isBound()) { + final ActionMapKey key = new ActionMapKey(actionName, + action.getBindingParameterTypeFqn(), action.isBindingParameterTypeCollection()); + boundActions.put(key, action); + } else { + unboundActions.put(actionName, action); + } + } + protected abstract EdmTerm createTerm(FullQualifiedName termName); + + public void cacheTerm(FullQualifiedName termName, EdmTerm term) { + terms.put(termName, term); + } protected abstract EdmAnnotations createAnnotationGroup(FullQualifiedName targetName); + + public void cacheAnnotationGroup(FullQualifiedName annotationsGroupName, EdmAnnotations annotationsGroup) { + annotationGroups.put(annotationsGroupName, annotationsGroup); + } protected abstract List createAnnotations(FullQualifiedName annotatedName); + +// public void cacheAnnotation(FullQualifiedName annotationsGroupName, EdmAnnotations annotationsGroup) { +// annotationGroups.put(annotationsGroupName, annotationsGroup); +// } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java index a779bf171..4de911c30 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -54,8 +54,8 @@ public class EdmAnnotationsImpl implements EdmAnnotations { EdmAnnotationsTarget _target = null; if (structured != null) { _target = path == null - ? structured - : structured.getStructuralProperty(path); + ? structured + : structured.getStructuralProperty(path); if (_target == null) { _target = structured.getNavigationProperty(path); } @@ -67,8 +67,8 @@ public class EdmAnnotationsImpl implements EdmAnnotations { EdmAnnotationsTarget _target = null; if (enumType != null) { _target = path == null - ? enumType - : enumType.getMember(path); + ? enumType + : enumType.getMember(path); } return _target; } @@ -80,23 +80,25 @@ public class EdmAnnotationsImpl implements EdmAnnotations { final FullQualifiedName base = new FullQualifiedName(splitted[0]); final String path = splitted.length > 1 ? splitted[1] : null; - final EdmEntityContainer baseEntityContainer = schema.getEntityContainer(base); - - target = baseEntityContainer == null? null: baseEntityContainer.getActionImport(path); + final EdmEntityContainer baseEntityContainer = schema.getEntityContainer(); + + target = baseEntityContainer == null ? null : baseEntityContainer.getActionImport(path); if (target == null) { target = getTarget(edm.getComplexType(base), path); if (target == null) { - target = baseEntityContainer; + if(baseEntityContainer != null && baseEntityContainer.getFullQualifiedName().equals(base)){ + target = baseEntityContainer; + } if (target == null) { - target = baseEntityContainer == null? null: baseEntityContainer.getEntitySet(path); + target = baseEntityContainer == null ? null : baseEntityContainer.getEntitySet(path); if (target == null) { target = getTarget(edm.getEntityType(base), path); if (target == null) { target = getTarget(edm.getEnumType(base), path); if (target == null) { - target = baseEntityContainer == null? null: baseEntityContainer.getFunctionImport(path); + target = baseEntityContainer == null ? null : baseEntityContainer.getFunctionImport(path); if (target == null) { - target = baseEntityContainer == null? null: baseEntityContainer.getSingleton(path); + target = baseEntityContainer == null ? null : baseEntityContainer.getSingleton(path); if (target == null) { target = edm.getTerm(base); if (target == null) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java index 3da053646..daa0e8771 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java @@ -317,11 +317,11 @@ public class EdmProviderImpl extends AbstractEdm { @Override protected Map createSchemas() { try { - final Map _schemas = new LinkedHashMap(); + final Map providerSchemas = new LinkedHashMap(); for (Schema schema : provider.getSchemas()) { - _schemas.put(schema.getNamespace(), new EdmSchemaImpl(this, provider, schema)); + providerSchemas.put(schema.getNamespace(), new EdmSchemaImpl(this, provider, schema)); } - return _schemas; + return providerSchemas; } catch (ODataException e) { throw new EdmException(e); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java index 7e09b2d24..ea44dc62c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmAction; import org.apache.olingo.commons.api.edm.EdmAnnotation; import org.apache.olingo.commons.api.edm.EdmAnnotations; @@ -50,7 +49,7 @@ import org.apache.olingo.commons.api.edm.provider.TypeDefinition; public class EdmSchemaImpl implements EdmSchema { private final Schema schema; - private final Edm edm; + private final EdmProviderImpl edm; private final EdmProvider provider; protected final String namespace; @@ -66,114 +65,80 @@ public class EdmSchemaImpl implements EdmSchema { private List annotations; private EdmEntityContainer entityContainer; - public EdmSchemaImpl(final Edm edm, final EdmProvider provider, final Schema schema) { + public EdmSchemaImpl(final EdmProviderImpl edm, final EdmProvider provider, final Schema schema) { this.edm = edm; this.provider = provider; this.schema = schema; this.namespace = schema.getNamespace(); this.alias = schema.getAlias(); + + if (alias != null) { + edm.cacheAliasNamespaceInfo(alias, namespace); + } + + enumTypes = createEnumTypes(); + typeDefinitions = createTypeDefinitions(); + entityTypes = createEntityTypes(); + complexTypes = createComplexTypes(); + actions = createActions(); + functions = createFunctions(); + entityContainer = createEntityContainer(); + annotationGroups = createAnnotationGroups(); + annotations = createAnnotations(); + terms = createTerms(); + } @Override public List getEnumTypes() { - if (enumTypes == null) { - enumTypes = createEnumTypes(); - } return Collections.unmodifiableList(enumTypes); } @Override public List getEntityTypes() { - if (entityTypes == null) { - entityTypes = createEntityTypes(); - } return Collections.unmodifiableList(entityTypes); } @Override public List getComplexTypes() { - if (complexTypes == null) { - complexTypes = createComplexTypes(); - } return Collections.unmodifiableList(complexTypes); } @Override public List getActions() { - if (actions == null) { - actions = createActions(); - } return Collections.unmodifiableList(actions); } @Override public List getFunctions() { - if (functions == null) { - functions = createFunctions(); - } return Collections.unmodifiableList(functions); } @Override public List getTypeDefinitions() { - if (typeDefinitions == null) { - typeDefinitions = createTypeDefinitions(); - } return Collections.unmodifiableList(typeDefinitions); } @Override public List getTerms() { - if (terms == null) { - terms = createTerms(); - } return Collections.unmodifiableList(terms); } @Override public List getAnnotationGroups() { - if (annotationGroups == null) { - annotationGroups = createAnnotationGroups(); - } return Collections.unmodifiableList(annotationGroups); } @Override public List getAnnotations() { - if (annotations == null) { - annotations = createAnnotations(); - } return Collections.unmodifiableList(annotations); } @Override public EdmEntityContainer getEntityContainer() { - if (entityContainer == null) { - entityContainer = createEntityContainer(); - } return entityContainer; } - @Override - public List getEntityContainers() { - if (getEntityContainer() == null) { - return Collections. emptyList(); - } else { - return Collections.unmodifiableList(Collections.singletonList(getEntityContainer())); - } - } - - @Override - public EdmEntityContainer getEntityContainer(final FullQualifiedName name) { - return getEntityContainer() == null - ? null - : name == null - ? getEntityContainer() - : name.equals(getEntityContainer().getFullQualifiedName()) - ? getEntityContainer() - : null; - } - @Override public String getNamespace() { return namespace; @@ -187,7 +152,10 @@ public class EdmSchemaImpl implements EdmSchema { protected EdmEntityContainer createEntityContainer() { if (schema.getEntityContainer() != null) { FullQualifiedName containerFQN = new FullQualifiedName(namespace, schema.getEntityContainer().getName()); - return new EdmEntityContainerImpl(edm, provider, containerFQN, schema.getEntityContainer()); + EdmEntityContainer impl = new EdmEntityContainerImpl(edm, provider, containerFQN, schema.getEntityContainer()); + edm.cacheEntityContainer(containerFQN, impl); + edm.cacheEntityContainer(null, impl); + return impl; } return null; } @@ -197,7 +165,10 @@ public class EdmSchemaImpl implements EdmSchema { final List providerTypeDefinitions = schema.getTypeDefinitions(); if (providerTypeDefinitions != null) { for (TypeDefinition def : providerTypeDefinitions) { - typeDefinitions.add(new EdmTypeDefinitionImpl(edm, new FullQualifiedName(namespace, def.getName()), def)); + FullQualifiedName typeDefName = new FullQualifiedName(namespace, def.getName()); + EdmTypeDefinitionImpl typeDefImpl = new EdmTypeDefinitionImpl(edm, typeDefName, def); + typeDefinitions.add(typeDefImpl); + edm.cacheTypeDefinition(typeDefName, typeDefImpl); } } return typeDefinitions; @@ -208,7 +179,10 @@ public class EdmSchemaImpl implements EdmSchema { final List providerEnumTypes = schema.getEnumTypes(); if (providerEnumTypes != null) { for (EnumType enumType : providerEnumTypes) { - enumTypes.add(new EdmEnumTypeImpl(edm, new FullQualifiedName(namespace, enumType.getName()), enumType)); + FullQualifiedName enumName = new FullQualifiedName(namespace, enumType.getName()); + EdmEnumType enumTypeImpl = new EdmEnumTypeImpl(edm, enumName, enumType); + enumTypes.add(enumTypeImpl); + edm.cacheEnumType(enumName, enumTypeImpl); } } return enumTypes; @@ -219,8 +193,10 @@ public class EdmSchemaImpl implements EdmSchema { final List providerEntityTypes = schema.getEntityTypes(); if (providerEntityTypes != null) { for (EntityType entityType : providerEntityTypes) { - entityTypes.add(new EdmEntityTypeImpl(edm, new FullQualifiedName(namespace, entityType.getName()), - entityType)); + FullQualifiedName entityTypeName = new FullQualifiedName(namespace, entityType.getName()); + EdmEntityTypeImpl entityTypeImpl = new EdmEntityTypeImpl(edm, entityTypeName, entityType); + entityTypes.add(entityTypeImpl); + edm.cacheEntityType(entityTypeName, entityTypeImpl); } } return entityTypes; @@ -231,8 +207,10 @@ public class EdmSchemaImpl implements EdmSchema { final List providerComplexTypes = schema.getComplexTypes(); if (providerComplexTypes != null) { for (ComplexType complexType : providerComplexTypes) { - complexTypes.add(new EdmComplexTypeImpl(edm, new FullQualifiedName(namespace, complexType.getName()), - complexType)); + FullQualifiedName comlexTypeName = new FullQualifiedName(namespace, complexType.getName()); + EdmComplexTypeImpl complexTypeImpl = new EdmComplexTypeImpl(edm, comlexTypeName, complexType); + complexTypes.add(complexTypeImpl); + edm.cacheComplexType(comlexTypeName, complexTypeImpl); } } return complexTypes; @@ -243,7 +221,10 @@ public class EdmSchemaImpl implements EdmSchema { final List providerActions = schema.getActions(); if (providerActions != null) { for (Action action : providerActions) { - actions.add(new EdmActionImpl(edm, new FullQualifiedName(namespace, action.getName()), action)); + FullQualifiedName actionName = new FullQualifiedName(namespace, action.getName()); + EdmActionImpl edmActionImpl = new EdmActionImpl(edm, actionName, action); + actions.add(edmActionImpl); + edm.cacheAction(actionName, edmActionImpl); } } return actions; @@ -254,7 +235,10 @@ public class EdmSchemaImpl implements EdmSchema { final List providerFunctions = schema.getFunctions(); if (providerFunctions != null) { for (Function function : providerFunctions) { - functions.add(new EdmFunctionImpl(edm, new FullQualifiedName(namespace, function.getName()), function)); + FullQualifiedName functionName = new FullQualifiedName(namespace, function.getName()); + EdmFunctionImpl functionImpl = new EdmFunctionImpl(edm, functionName, function); + functions.add(functionImpl); + edm.cacheFunction(functionName, functionImpl); } } return functions; @@ -265,7 +249,10 @@ public class EdmSchemaImpl implements EdmSchema { final List providerTerms = schema.getTerms(); if (providerTerms != null) { for (Term term : providerTerms) { - terms.add(new EdmTermImpl(edm, getNamespace(), term)); + FullQualifiedName termName = new FullQualifiedName(namespace, term.getName()); + EdmTermImpl termImpl = new EdmTermImpl(edm, getNamespace(), term); + terms.add(termImpl); + edm.cacheTerm(termName, termImpl); } } return terms; @@ -277,7 +264,15 @@ public class EdmSchemaImpl implements EdmSchema { schema.getAnnotationGroups(); if (providerAnnotations != null) { for (Annotations annotationGroup : providerAnnotations) { - annotationGroups.add(new EdmAnnotationsImpl(edm, this, annotationGroup)); + FullQualifiedName annotationsGroupName; + if (annotationGroup.getTarget().contains(".")) { + annotationsGroupName = new FullQualifiedName(annotationGroup.getTarget()); + } else { + annotationsGroupName = new FullQualifiedName(namespace, annotationGroup.getTarget()); + } + EdmAnnotationsImpl annotationsImpl = new EdmAnnotationsImpl(edm, this, annotationGroup); + annotationGroups.add(annotationsImpl); + edm.cacheAnnotationGroup(annotationsGroupName, annotationsImpl); } } return annotationGroups; @@ -289,7 +284,8 @@ public class EdmSchemaImpl implements EdmSchema { schema.getAnnotations(); if (providerAnnotations != null) { for (Annotation annotation : providerAnnotations) { - annotations.add(new EdmAnnotationImpl(edm, annotation)); + EdmAnnotationImpl annotationImpl = new EdmAnnotationImpl(edm, annotation); + annotations.add(annotationImpl); } } return annotations;