[OLINGO-575] Edm cleanup part 1

This commit is contained in:
Christian Amend 2015-03-25 17:19:42 +01:00
parent 3a6293b6a5
commit 4d059b94d6
23 changed files with 57 additions and 130 deletions

View File

@ -27,6 +27,7 @@ public class FunctionImport extends OperationImport {
private FullQualifiedName function;
//Default include in service document is false for function imports
private boolean includeInServiceDocument;
@Override

View File

@ -26,9 +26,7 @@ public abstract class OperationImport extends AbstractEdmItem implements Named,
private static final long serialVersionUID = -8928186067970681061L;
protected String name;
protected String entitySet;
protected final List<Annotation> annotations = new ArrayList<Annotation>();
public String getName() {

View File

@ -1,24 +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.commons.core.edm.provider;
import org.apache.olingo.commons.api.edm.EdmAnnotatable;
public interface EdmAnnotationHelper extends EdmAnnotatable {
}

View File

@ -22,12 +22,13 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotatable;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.provider.Annotatable;
import org.apache.olingo.commons.api.edm.provider.Annotation;
public class EdmAnnotationHelperImpl implements EdmAnnotationHelper {
public class EdmAnnotationHelperImpl implements EdmAnnotatable {
private final Edm edm;

View File

@ -63,13 +63,9 @@ import org.apache.olingo.commons.core.edm.annotation.EdmUrlRefImpl;
public class EdmAnnotationImpl implements EdmAnnotation {
private final Edm edm;
private final Annotation annotation;
private final EdmAnnotationHelper helper;
private final EdmAnnotationHelperImpl helper;
private EdmTerm term;
private EdmAnnotationExpression expression;
public EdmAnnotationImpl(final Edm edm, final Annotation annotation) {

View File

@ -38,7 +38,7 @@ import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
public abstract class EdmBindingTargetImpl extends EdmNamedImpl implements EdmBindingTarget {
private final BindingTarget target;
private final EdmAnnotationHelper helper;
private final EdmAnnotationHelperImpl helper;
private final EdmEntityContainer container;
private List<EdmNavigationPropertyBinding> navigationPropertyBindings;

View File

@ -35,13 +35,12 @@ import org.apache.olingo.commons.api.edm.provider.ComplexType;
public class EdmComplexTypeImpl extends EdmStructuredTypeImpl implements EdmComplexType {
private final EdmStructuredTypeHelper helper;
private final EdmStructuredTypeHelperImpl helper;
private EdmAnnotationHelper annotationHelper;
private EdmAnnotationHelperImpl annotationHelper;
public static EdmComplexTypeImpl getInstance(
final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
return new EdmComplexTypeImpl(edm, name, complexType);
}

View File

@ -47,7 +47,7 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
private final EdmProvider provider;
private EntityContainer container;
private EdmAnnotationHelper helper;
private EdmAnnotationHelperImpl helper;
protected final FullQualifiedName entityContainerName;
private final FullQualifiedName parentContainerName;

View File

@ -39,10 +39,10 @@ import org.apache.olingo.commons.api.edm.provider.PropertyRef;
public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntityType {
private final EdmStructuredTypeHelper helper;
private final EdmStructuredTypeHelperImpl helper;
private EntityType entityType;
private boolean baseTypeChecked = false;
private EdmAnnotationHelper annotationHelper;
private EdmAnnotationHelperImpl annotationHelper;
private final boolean hasStream;
protected EdmEntityType entityBaseType;
private final List<String> keyPredicateNames = new ArrayList<String>();

View File

@ -19,10 +19,10 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.olingo.commons.api.edm.Edm;
@ -55,8 +55,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
private final String uriPrefix;
private final String uriSuffix;
private List<String> memberNames;
private List<EdmMember> members;
private Map<String, EdmMember> membersMap;
private LinkedHashMap<String, EdmMember> membersMap;
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final EnumType enumType) {
super(edm, enumName, EdmTypeKind.ENUM);
@ -81,14 +80,11 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
public EdmPrimitiveType getUnderlyingType() {
return underlyingType;
}
@Override
public EdmMember getMember(final String name) {
if (membersMap == null) {
membersMap = new LinkedHashMap<String, EdmMember>();
for (final EdmMember member : getMembers()) {
membersMap.put(member.getName(), member);
}
createEdmMembers();
}
return membersMap.get(name);
}
@ -96,12 +92,20 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
@Override
public List<String> getMemberNames() {
if (memberNames == null) {
memberNames = new ArrayList<String>();
for (final EdmMember member : getMembers()) {
createEdmMembers();
}
return memberNames;
}
private void createEdmMembers() {
membersMap = new LinkedHashMap<String, EdmMember>();
memberNames = new ArrayList<String>();
if (enumType.getMembers() != null) {
for (final EnumMember member : enumType.getMembers()) {
membersMap.put(member.getName(), new EdmMemberImpl(edm, getFullQualifiedName(), member));
memberNames.add(member.getName());
}
}
return memberNames;
}
@Override
@ -186,6 +190,13 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
return result.toString();
}
private Collection<EdmMember> getMembers() {
if(membersMap == null){
createEdmMembers();
}
return membersMap.values();
}
@Override
public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
@ -242,15 +253,4 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
public FullQualifiedName getAnnotationsTargetFQN() {
return getFullQualifiedName();
}
protected List<EdmMember> getMembers() {
if (members == null) {
members = new ArrayList<EdmMember>(enumType.getMembers().size());
for (EnumMember member : enumType.getMembers()) {
members.add(new EdmMemberImpl(edm, getFullQualifiedName(), member));
}
}
return members;
}
}

View File

@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.edm.provider.EnumMember;
public class EdmMemberImpl extends EdmNamedImpl implements EdmMember {
private final EdmAnnotationHelper helper;
private final EdmAnnotationHelperImpl helper;
private final FullQualifiedName enumFQN;
private final EnumMember member;

View File

@ -37,8 +37,8 @@ public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavi
private final FullQualifiedName structuredTypeName;
private final NavigationProperty navigationProperty;
private final EdmAnnotationHelperImpl helper;
private List<EdmReferentialConstraint> referentialConstraints;
private final EdmAnnotationHelper helper;
private EdmEntityType typeImpl;
private EdmNavigationProperty partnerNavigationProperty;

View File

@ -40,7 +40,7 @@ import org.apache.olingo.commons.api.edm.provider.Parameter;
public abstract class EdmOperationImpl extends EdmTypeImpl implements EdmOperation {
protected final Operation operation;
protected final EdmAnnotationHelper helper;
protected final EdmAnnotationHelperImpl helper;
private final Map<String, EdmParameter> parameters = new LinkedHashMap<String, EdmParameter>();
private String entitySetPath;
private boolean isBound;

View File

@ -36,7 +36,7 @@ public abstract class EdmOperationImportImpl extends EdmNamedImpl implements Edm
protected final EdmEntityContainer container;
private final Target entitySet;
private EdmEntitySet returnedEntitySet;
private final EdmAnnotationHelper helper;
private final EdmAnnotationHelperImpl helper;
public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container,
final OperationImport operationImport) {

View File

@ -33,7 +33,7 @@ import org.apache.olingo.commons.api.edm.provider.Parameter;
public class EdmParameterImpl extends EdmElementImpl implements EdmParameter {
private final Parameter parameter;
private final EdmAnnotationHelper helper;
private final EdmAnnotationHelperImpl helper;
private final EdmTypeInfo typeInfo;
private EdmType typeImpl;

View File

@ -36,7 +36,7 @@ public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
private final FullQualifiedName structuredTypeName;
private final Property property;
private final EdmTypeInfo typeInfo;
private EdmAnnotationHelper helper;
private EdmAnnotationHelperImpl helper;
private EdmType propertyType;
public EdmPropertyImpl(final Edm edm, final FullQualifiedName structuredTypeName, final Property property) {

View File

@ -28,10 +28,9 @@ import org.apache.olingo.commons.api.edm.provider.ReferentialConstraint;
public class EdmReferentialConstraintImpl implements EdmReferentialConstraint {
private final EdmAnnotationHelper helper;
private final EdmAnnotationHelperImpl helper;
private final ReferentialConstraint constraint;
public EdmReferentialConstraintImpl(final Edm edm, final ReferentialConstraint constraint) {
this.constraint = constraint;
this.helper = new EdmAnnotationHelperImpl(edm, constraint);

View File

@ -1,35 +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.commons.core.edm.provider;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.commons.api.edm.EdmProperty;
import java.util.Map;
public interface EdmStructuredTypeHelper {
Map<String, EdmProperty> getProperties();
Map<String, EdmNavigationProperty> getNavigationProperties();
boolean isOpenType();
boolean isAbstract();
}

View File

@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.edm.provider.StructuralType;
import java.util.LinkedHashMap;
import java.util.Map;
public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
public class EdmStructuredTypeHelperImpl {
private final Edm edm;
private final FullQualifiedName structuredTypeName;
@ -44,7 +44,6 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
this.structuredType = structuredType;
}
@Override
public Map<String, EdmProperty> getProperties() {
if (properties == null) {
properties = new LinkedHashMap<String, EdmProperty>();
@ -57,7 +56,6 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
return properties;
}
@Override
public Map<String, EdmNavigationProperty> getNavigationProperties() {
if (navigationProperties == null) {
navigationProperties = new LinkedHashMap<String, EdmNavigationProperty>();
@ -71,12 +69,10 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
return navigationProperties;
}
@Override
public boolean isOpenType() {
return structuredType.isOpenType();
}
@Override
public boolean isAbstract() {
return structuredType.isAbstract();
}

View File

@ -37,19 +37,12 @@ import org.slf4j.LoggerFactory;
public class EdmTermImpl extends EdmNamedImpl implements EdmTerm {
private static final Logger LOG = LoggerFactory.getLogger(EdmTermImpl.class);
private final Term term;
private final FullQualifiedName fqn;
private final EdmTypeInfo typeInfo;
private final EdmAnnotationHelper helper;
private final EdmAnnotationHelperImpl helper;
private EdmType termType;
private EdmTerm baseTerm;
private List<Class<?>> appliesTo;
public EdmTermImpl(final Edm edm, final String namespace, final Term term) {

View File

@ -37,25 +37,16 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefinition {
private TypeDefinition typeDefinition;
private final EdmPrimitiveType edmPrimitiveTypeInstance;
private final EdmAnnotationHelper helper;
private FullQualifiedName typeDefinitionName;
private EdmPrimitiveType edmPrimitiveTypeInstance;
private final EdmAnnotationHelperImpl helper;
public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName,
final TypeDefinition typeDefinition) {
super(edm, typeDefinitionName.getName());
this.typeDefinitionName = typeDefinitionName;
this.typeDefinition = typeDefinition;
try {
if (typeDefinition.getUnderlyingType() == null) {
throw new EdmException("Underlying Type for type definition: "
+ typeDefinitionName.getFullQualifiedNameAsString() + " must not be null.");
}
this.edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType()));
} catch (IllegalArgumentException e) {
throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
}
this.helper = new EdmAnnotationHelperImpl(edm, typeDefinition);
}
@ -76,6 +67,18 @@ public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefini
@Override
public EdmPrimitiveType getUnderlyingType() {
if(edmPrimitiveTypeInstance == null){
try {
if (typeDefinition.getUnderlyingType() == null) {
throw new EdmException("Underlying Type for type definition: "
+ typeDefinitionName.getFullQualifiedNameAsString() + " must not be null.");
}
this.edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType()));
} catch (IllegalArgumentException e) {
throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
}
}
return edmPrimitiveTypeInstance;
}

View File

@ -26,7 +26,6 @@ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
public class EdmTypeImpl extends EdmNamedImpl implements EdmType {
protected final FullQualifiedName typeName;
protected final EdmTypeKind kind;
public EdmTypeImpl(final Edm edm, final FullQualifiedName typeName, final EdmTypeKind kind) {

View File

@ -251,6 +251,7 @@ public class ContainerProvider {
} else if (name.equals("ESInvisible")) {
return new EntitySet()
.setName("ESInvisible")
.setIncludeInServiceDocument(false)
.setType(EntityTypeProvider.nameETAllPrim);
} else if (name.equals("ESServerSidePaging")) {