[OLINGO-786] Delete getAnnotations convenience method

This commit is contained in:
Christian Amend 2015-09-29 14:26:16 +02:00
parent c66b659224
commit addfe512cd
11 changed files with 6 additions and 180 deletions

View File

@ -6,9 +6,9 @@
* 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
@ -132,8 +132,8 @@ public class MetadataTestITCase extends AbstractTestITCase {
final EdmTerm scale = edm.getTerm(new FullQualifiedName("UoM.Scale"));
assertNotNull(scale);
final EdmAnnotation requiresTypeInScale = edm.getAnnotation(
scale.getFullQualifiedName(), edm.getTerm(new FullQualifiedName("Core.RequiresType")));
final EdmAnnotation requiresTypeInScale =
scale.getAnnotation(edm.getTerm(new FullQualifiedName("Core.RequiresType")));
assertNotNull(requiresTypeInScale);
assertEquals("Edm.Decimal", requiresTypeInScale.getExpression().asConstant().getValueAsString());

View File

@ -22,13 +22,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.olingo.commons.api.ex.ODataException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider;
import org.apache.olingo.commons.api.edm.provider.CsdlAction;
import org.apache.olingo.commons.api.edm.provider.CsdlActionImport;
import org.apache.olingo.commons.api.edm.provider.CsdlAliasInfo;
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotatable;
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotations;
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer;
@ -42,6 +40,7 @@ import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
import org.apache.olingo.commons.api.edm.provider.CsdlSingleton;
import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
import org.apache.olingo.commons.api.ex.ODataException;
public class ClientCsdlEdmProvider extends CsdlAbstractEdmProvider {
@ -200,13 +199,4 @@ public class ClientCsdlEdmProvider extends CsdlAbstractEdmProvider {
}
return null;
}
@Override
public CsdlAnnotatable getAnnotatable(FullQualifiedName annotatedName) throws ODataException {
final CsdlSchema schema = xmlSchemas.get(annotatedName.getNamespace());
if (schema != null) {
return schema.getAnnotatables().get(annotatedName.getName());
}
return null;
}
}

View File

@ -164,21 +164,4 @@ public interface Edm {
* @return {@link EdmAnnotations}
*/
EdmAnnotations getAnnotationGroup(FullQualifiedName targetName);
/**
* Get all {@link EdmAnnotation} by element FQN.
*
* @param annotatableName must not be null
* @return {@link EdmAnnotation}
*/
List<EdmAnnotation> getAnnotations(FullQualifiedName annotatableName);
/**
* Get {@link EdmAnnotation} by element FQN and term.
*
* @param annotatableName must not be null
* @param term <tt>edm:Annotation</tt> term
* @return {@link EdmAnnotation}
*/
EdmAnnotation getAnnotation(FullQualifiedName annotatableName, EdmTerm term);
}

View File

@ -112,9 +112,4 @@ public abstract class CsdlAbstractEdmProvider implements CsdlEdmProvider {
public CsdlAnnotations getAnnotationsGroup(final FullQualifiedName targetName) throws ODataException {
return null;
}
@Override
public CsdlAnnotatable getAnnotatable(final FullQualifiedName annotatedName) throws ODataException {
return null;
}
}

View File

@ -179,13 +179,4 @@ public interface CsdlEdmProvider {
* @throws ODataException the o data exception
*/
CsdlAnnotations getAnnotationsGroup(FullQualifiedName targetName) throws ODataException;
/**
* Gets annotatable.
*
* @param annotatedName full qualified name of annotatable
* @return Annotatable element by target name
* @throws ODataException the o data exception
*/
CsdlAnnotatable getAnnotatable(FullQualifiedName annotatedName) throws ODataException;
}

View File

@ -19,9 +19,7 @@
package org.apache.olingo.commons.api.edm.provider;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The type Csdl schema.
@ -54,8 +52,6 @@ public class CsdlSchema extends CsdlAbstractEdmItem implements CsdlAnnotatable {
private final List<CsdlAnnotation> annotations = new ArrayList<CsdlAnnotation>();
private Map<String, CsdlAnnotatable> annotatables;
/**
* Gets namespace.
*
@ -369,61 +365,4 @@ public class CsdlSchema extends CsdlAbstractEdmItem implements CsdlAnnotatable {
public List<CsdlAnnotation> getAnnotations() {
return annotations;
}
/**
* Gets annotatables.
*
* @return the annotatables
*/
public Map<String, CsdlAnnotatable> getAnnotatables() {
if (annotatables == null) {
annotatables = new HashMap<String, CsdlAnnotatable>();
for (CsdlAnnotations annotationGroup : getAnnotationGroups()) {
annotatables.put(null, annotationGroup);
}
for (CsdlAnnotation annotation : getAnnotations()) {
annotatables.put(annotation.getTerm(), annotation);
}
for (CsdlAction action : getActions()) {
annotatables.put(action.getName(), action);
}
for (CsdlComplexType complexType : getComplexTypes()) {
annotatables.put(complexType.getName(), complexType);
}
for (CsdlEntityType entityType : getEntityTypes()) {
annotatables.put(entityType.getName(), entityType);
}
for (CsdlEnumType enumType : getEnumTypes()) {
annotatables.put(enumType.getName(), enumType);
}
for (CsdlFunction function : getFunctions()) {
annotatables.put(function.getName(), function);
}
for (CsdlTerm term : getTerms()) {
annotatables.put(term.getName(), term);
}
for (CsdlTypeDefinition typedef : getTypeDefinitions()) {
annotatables.put(typedef.getName(), typedef);
}
if (entityContainer != null) {
annotatables.put(entityContainer.getName(), entityContainer);
for (CsdlAnnotation annotation : entityContainer.getAnnotations()) {
annotatables.put(annotation.getTerm(), annotation);
}
for (CsdlActionImport actionImport : entityContainer.getActionImports()) {
annotatables.put(actionImport.getName(), actionImport);
}
for (CsdlFunctionImport functionImport : entityContainer.getFunctionImports()) {
annotatables.put(functionImport.getName(), functionImport);
}
for (CsdlEntitySet entitySet : entityContainer.getEntitySets()) {
annotatables.put(entitySet.getName(), entitySet);
}
for (CsdlSingleton singleton : entityContainer.getSingletons()) {
annotatables.put(singleton.getName(), singleton);
}
}
}
return annotatables;
}
}

View File

@ -26,7 +26,6 @@ import java.util.Map;
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;
import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
@ -80,9 +79,6 @@ public abstract class AbstractEdm implements Edm {
private final Map<FullQualifiedName, EdmAnnotations> annotationGroups =
Collections.synchronizedMap(new HashMap<FullQualifiedName, EdmAnnotations>());
private final Map<FullQualifiedName, List<EdmAnnotation>> annotations =
Collections.synchronizedMap(new HashMap<FullQualifiedName, List<EdmAnnotation>>());
private Map<String, String> aliasToNamespaceInfo = Collections.synchronizedMap(new HashMap<String, String>());
private boolean aliasToNamespaceInfoCreated = false;
@ -311,33 +307,6 @@ public abstract class AbstractEdm implements Edm {
return _annotations;
}
@Override
public List<EdmAnnotation> getAnnotations(final FullQualifiedName annotatableName) {
final FullQualifiedName fqn = resolvePossibleAlias(annotatableName);
List<EdmAnnotation> _annotations = annotations.get(fqn);
if (_annotations == null) {
_annotations = createAnnotations(fqn);
if (_annotations != null) {
annotations.put(fqn, _annotations);
}
}
return _annotations;
}
@Override
public EdmAnnotation getAnnotation(final FullQualifiedName annotatableName, final EdmTerm term) {
final List<EdmAnnotation> _annotations = getAnnotations(annotatableName);
EdmAnnotation result = null;
if (_annotations != null) {
for (EdmAnnotation annotation : _annotations) {
if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) {
result = annotation;
}
}
}
return result;
}
private FullQualifiedName resolvePossibleAlias(final FullQualifiedName namespaceOrAliasFQN) {
if (!aliasToNamespaceInfoCreated) {
aliasToNamespaceInfo = createAliasToNamespaceInfo();
@ -446,10 +415,4 @@ public abstract class AbstractEdm implements Edm {
final EdmAnnotations annotationsGroup) {
annotationGroups.put(annotationsGroupName, annotationsGroup);
}
protected abstract List<EdmAnnotation> createAnnotations(FullQualifiedName annotatedName);
// public void cacheAnnotation(FullQualifiedName annotationsGroupName, EdmAnnotations annotationsGroup) {
// annotationGroups.put(annotationsGroupName, annotationsGroup);
// }
}

View File

@ -358,23 +358,4 @@ public class EdmProviderImpl extends AbstractEdm {
throw new EdmException(e);
}
}
@Override
protected List<EdmAnnotation> createAnnotations(final FullQualifiedName annotatedName) {
try {
CsdlAnnotatable providerAnnotatable = provider.getAnnotatable(annotatedName);
if (providerAnnotatable != null && providerAnnotatable.getAnnotations() != null) {
List<EdmAnnotation> result = new ArrayList<EdmAnnotation>();
for (CsdlAnnotation annotation : providerAnnotatable.getAnnotations()) {
// Load Term
getTerm(new FullQualifiedName(annotation.getTerm()));
result.add(new EdmAnnotationImpl(this, annotation));
}
return result;
}
return null;
} catch (ODataException e) {
throw new EdmException(e);
}
}
}

View File

@ -425,10 +425,5 @@ public class EdmImplCachingTest {
protected EdmAnnotations createAnnotationGroup(final FullQualifiedName target) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected List<EdmAnnotation> createAnnotations(final FullQualifiedName annotatedName) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
}

View File

@ -289,10 +289,5 @@ public class EdmImplCallCreateTest {
protected EdmAnnotations createAnnotationGroup(final FullQualifiedName targetName) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected List<EdmAnnotation> createAnnotations(final FullQualifiedName annotatedName) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
}

View File

@ -22,12 +22,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.olingo.commons.api.ex.ODataException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.CsdlAction;
import org.apache.olingo.commons.api.edm.provider.CsdlActionImport;
import org.apache.olingo.commons.api.edm.provider.CsdlAliasInfo;
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotatable;
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotations;
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
@ -42,6 +40,7 @@ import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
import org.apache.olingo.commons.api.edm.provider.CsdlSingleton;
import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
import org.apache.olingo.commons.api.ex.ODataException;
public class SchemaBasedEdmProvider implements CsdlEdmProvider {
private final List<CsdlSchema> edmSchemas = new ArrayList<CsdlSchema>();
@ -307,9 +306,4 @@ public class SchemaBasedEdmProvider implements CsdlEdmProvider {
public CsdlAnnotations getAnnotationsGroup(FullQualifiedName targetName) throws ODataException {
return null;
}
@Override
public CsdlAnnotatable getAnnotatable(FullQualifiedName annotatedName) throws ODataException {
return null;
}
}