[OLINGO-422] Minor refactoring for EdmxReference*

This commit is contained in:
Michael Bolz 2014-10-16 10:51:52 +02:00
parent 7f86b264f0
commit 2fbab6524e
7 changed files with 173 additions and 214 deletions

View File

@ -19,28 +19,75 @@
package org.apache.olingo.server.api.edmx;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* POJO for Edmx Reference.
*/
public interface EdmxReference {
public class EdmxReference {
private final URI uri;
private final List<EdmxReferenceInclude> edmxIncludes;
private final List<EdmxReferenceIncludeAnnotation> edmxIncludeAnnotations;
/**
* Get URI for the Reference
* @return
* Create reference with given uri
*
* @param uri of reference
*/
URI getUri();
public EdmxReference(URI uri) {
this.uri = uri;
edmxIncludes = new ArrayList<EdmxReferenceInclude>();
edmxIncludeAnnotations = new ArrayList<EdmxReferenceIncludeAnnotation>();
}
/**
* Get URI for the reference
* @return uri for the reference
*/
public URI getUri() {
return uri;
}
/**
* edmx:Include elements that specify the schemas to include from the target document
*
* @return list of {@link EdmxReferenceInclude} in reference or null if none specified
*/
List<EdmxReferenceInclude> getIncludes();
public List<EdmxReferenceInclude> getIncludes() {
return Collections.unmodifiableList(edmxIncludes);
}
/**
* Add include element to current list.
*
* @param include to be added
* @return this EdmxReference object
*/
public EdmxReference addInclude(EdmxReferenceInclude include) {
edmxIncludes.add(include);
return this;
}
/**
* edmx:IncludeAnnotations elements that specify the annotations to include from the target document.
*
* @return List of {@link EdmxReferenceIncludeAnnotation} or null if none specified
*/
List<EdmxReferenceIncludeAnnotation> getIncludeAnnotations();
public List<EdmxReferenceIncludeAnnotation> getIncludeAnnotations() {
return Collections.unmodifiableList(edmxIncludeAnnotations);
}
/**
* Add include annotation element to current list.
*
* @param includeAnnotation to be added
* @return this EdmxReference object
*/
public EdmxReference addIncludeAnnotation(EdmxReferenceIncludeAnnotation includeAnnotation) {
edmxIncludeAnnotations.add(includeAnnotation);
return this;
}
}

View File

@ -21,14 +21,41 @@ package org.apache.olingo.server.api.edmx;
/**
* edmx:Include elements that specify the schemas to include from the target document.
*/
public interface EdmxReferenceInclude {
/**
* @return Namespace of the include
*/
String getNamespace();
public class EdmxReferenceInclude {
private final String namespace;
private final String alias;
/**
* Create include with given namespace and alias.
*
* @param namespace of include
* @param alias of include
*/
public EdmxReferenceInclude(String namespace, String alias) {
this.namespace = namespace;
this.alias = alias;
}
/**
* Create include with given namespace and empty (<code>NULL</code>) alias.
*
* @param namespace of include
*/
public EdmxReferenceInclude(String namespace) {
this(namespace, null);
}
/**
* @return Namespace of the include
*/
public String getNamespace() {
return namespace;
}
/**
* @return alias of the include if one defined; null otherwise
*/
String getAlias();
public String getAlias() {
return alias;
}
}

View File

@ -19,21 +19,75 @@
package org.apache.olingo.server.api.edmx;
/**
*
* POJO for Edmx Reference Include Annotation.
*/
public interface EdmxReferenceIncludeAnnotation {
/**
public class EdmxReferenceIncludeAnnotation {
private final String termNamespace;
private String qualifier;
private String targetNamespace;
/**
* Create include annotation with given termNamespace and empty qualifier and targetNamespace.
*
* @param termNamespace of include annotation
*/
public EdmxReferenceIncludeAnnotation(String termNamespace) {
this(termNamespace, null, null);
}
/**
* Create include annotation with given termNamespace, qualifier and targetNamespace.
*
* @param termNamespace of include annotation
* @param qualifier of include annotation
* @param targetNamespace of include annotation
*/
public EdmxReferenceIncludeAnnotation(String termNamespace, String qualifier, String targetNamespace) {
this.termNamespace = termNamespace;
this.qualifier = qualifier;
this.targetNamespace = targetNamespace;
}
/**
* @return TermNamespace of the include annotation
*/
String getTermNamespace();
public String getTermNamespace() {
return termNamespace;
}
/**
* @return Qualifier if one defined; null otherwise
*/
String getQualifier();
public String getQualifier() {
return qualifier;
}
/**
* Set qualifier for this include annotation.
*
* @param qualifier for include annotation
* @return this include annotation
*/
public EdmxReferenceIncludeAnnotation setQualifier(String qualifier) {
this.qualifier = qualifier;
return this;
}
/**
* @return targetNamespace if defined; null otherwise
*/
String getTargetNamespace();
public String getTargetNamespace() {
return targetNamespace;
}
/**
* Set target namespace for this include annotation.
*
* @param targetNamespace for include annotation
* @return this include annotation
*/
public EdmxReferenceIncludeAnnotation setTargetNamespace(String targetNamespace) {
this.targetNamespace = targetNamespace;
return this;
}
}

View File

@ -1,65 +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.server.core.edmx;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.edmx.EdmxReferenceInclude;
import org.apache.olingo.server.api.edmx.EdmxReferenceIncludeAnnotation;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class EdmxReferenceImpl implements EdmxReference {
private final URI uri;
private final List<EdmxReferenceInclude> edmxIncludes;
private final List<EdmxReferenceIncludeAnnotation> edmxIncludeAnnotations;
public EdmxReferenceImpl(URI uri) {
this.uri = uri;
edmxIncludes = new ArrayList<EdmxReferenceInclude>();
edmxIncludeAnnotations = new ArrayList<EdmxReferenceIncludeAnnotation>();
}
@Override
public URI getUri() {
return uri;
}
@Override
public List<EdmxReferenceInclude> getIncludes() {
return Collections.unmodifiableList(edmxIncludes);
}
public void addInclude(EdmxReferenceInclude include) {
edmxIncludes.add(include);
}
@Override
public List<EdmxReferenceIncludeAnnotation> getIncludeAnnotations() {
return Collections.unmodifiableList(edmxIncludeAnnotations);
}
public void addIncludeAnnotation(EdmxReferenceIncludeAnnotation includeAnnotation) {
edmxIncludeAnnotations.add(includeAnnotation);
}
}

View File

@ -1,55 +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.server.core.edmx;
import org.apache.olingo.server.api.edmx.EdmxReferenceIncludeAnnotation;
/**
*/
public class EdmxReferenceIncludeAnnotationImpl implements EdmxReferenceIncludeAnnotation {
private final String termNamespace;
private final String qualifier;
private final String targetNamespace;
public EdmxReferenceIncludeAnnotationImpl(String termNamespace, String qualifier, String targetNamespace) {
this.termNamespace = termNamespace;
this.qualifier = qualifier;
this.targetNamespace = targetNamespace;
}
public EdmxReferenceIncludeAnnotationImpl(String termNamespace) {
this(termNamespace, null, null);
}
@Override
public String getTermNamespace() {
return termNamespace;
}
@Override
public String getQualifier() {
return qualifier;
}
@Override
public String getTargetNamespace() {
return targetNamespace;
}
}

View File

@ -1,47 +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.server.core.edmx;
import org.apache.olingo.server.api.edmx.EdmxReferenceInclude;
/**
*/
public class EdmxReferenceIncludeImpl implements EdmxReferenceInclude {
private final String namespace;
private final String alias;
public EdmxReferenceIncludeImpl(String namespace, String alias) {
this.namespace = namespace;
this.alias = alias;
}
public EdmxReferenceIncludeImpl(String namespace) {
this(namespace, null);
}
@Override
public String getNamespace() {
return namespace;
}
@Override
public String getAlias() {
return alias;
}
}

View File

@ -64,9 +64,7 @@ import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.edmx.EdmxReferenceInclude;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.core.ServiceMetadataImpl;
import org.apache.olingo.server.core.edmx.EdmxReferenceImpl;
import org.apache.olingo.server.core.edmx.EdmxReferenceIncludeAnnotationImpl;
import org.apache.olingo.server.core.edmx.EdmxReferenceIncludeImpl;
import org.apache.olingo.server.api.edmx.EdmxReferenceIncludeAnnotation;
import org.junit.Test;
public class MetadataDocumentTest {
@ -85,51 +83,51 @@ public class MetadataDocumentTest {
ODataSerializer serializer = OData.newInstance().createSerializer(ODataFormat.XML);
List<EdmxReference> edmxReferences = new ArrayList<EdmxReference>();
EdmxReferenceImpl reference = new EdmxReferenceImpl(URI.create("http://example.com"));
EdmxReference reference = new EdmxReference(URI.create("http://example.com"));
edmxReferences.add(reference);
EdmxReferenceImpl referenceWithInclude = new EdmxReferenceImpl(
EdmxReference referenceWithInclude = new EdmxReference(
URI.create("http://localhost/odata/odata/v4.0/referenceWithInclude"));
EdmxReferenceInclude include = new EdmxReferenceIncludeImpl("Org.OData.Core.V1", "Core");
EdmxReferenceInclude include = new EdmxReferenceInclude("Org.OData.Core.V1", "Core");
referenceWithInclude.addInclude(include);
edmxReferences.add(referenceWithInclude);
EdmxReferenceImpl referenceWithTwoIncludes = new EdmxReferenceImpl(
EdmxReference referenceWithTwoIncludes = new EdmxReference(
URI.create("http://localhost/odata/odata/v4.0/referenceWithTwoIncludes"));
referenceWithTwoIncludes.addInclude(new EdmxReferenceIncludeImpl("Org.OData.Core.2", "Core2"));
referenceWithTwoIncludes.addInclude(new EdmxReferenceIncludeImpl("Org.OData.Core.3", "Core3"));
referenceWithTwoIncludes.addInclude(new EdmxReferenceInclude("Org.OData.Core.2", "Core2"));
referenceWithTwoIncludes.addInclude(new EdmxReferenceInclude("Org.OData.Core.3", "Core3"));
edmxReferences.add(referenceWithTwoIncludes);
EdmxReferenceImpl referenceWithIncludeAnnos = new EdmxReferenceImpl(
EdmxReference referenceWithIncludeAnnos = new EdmxReference(
URI.create("http://localhost/odata/odata/v4.0/referenceWithIncludeAnnos"));
referenceWithIncludeAnnos.addIncludeAnnotation(
new EdmxReferenceIncludeAnnotationImpl("TermNs.2", "Q.2", "TargetNS.2"));
new EdmxReferenceIncludeAnnotation("TermNs.2", "Q.2", "TargetNS.2"));
referenceWithIncludeAnnos.addIncludeAnnotation(
new EdmxReferenceIncludeAnnotationImpl("TermNs.3", "Q.3","TargetNS.3"));
new EdmxReferenceIncludeAnnotation("TermNs.3", "Q.3","TargetNS.3"));
edmxReferences.add(referenceWithIncludeAnnos);
EdmxReferenceImpl referenceWithAll = new EdmxReferenceImpl(
EdmxReference referenceWithAll = new EdmxReference(
URI.create("http://localhost/odata/odata/v4.0/referenceWithAll"));
referenceWithAll.addInclude(new EdmxReferenceIncludeImpl("ReferenceWithAll.1", "Core1"));
referenceWithAll.addInclude(new EdmxReferenceIncludeImpl("ReferenceWithAll.2", "Core2"));
referenceWithAll.addInclude(new EdmxReferenceInclude("ReferenceWithAll.1", "Core1"));
referenceWithAll.addInclude(new EdmxReferenceInclude("ReferenceWithAll.2", "Core2"));
referenceWithAll.addIncludeAnnotation(
new EdmxReferenceIncludeAnnotationImpl("ReferenceWithAllTermNs.4", "Q.4", "TargetNS.4"));
new EdmxReferenceIncludeAnnotation("ReferenceWithAllTermNs.4", "Q.4", "TargetNS.4"));
referenceWithAll.addIncludeAnnotation(
new EdmxReferenceIncludeAnnotationImpl("ReferenceWithAllTermNs.5", "Q.5", "TargetNS.5"));
new EdmxReferenceIncludeAnnotation("ReferenceWithAllTermNs.5", "Q.5", "TargetNS.5"));
edmxReferences.add(referenceWithAll);
EdmxReferenceImpl referenceWithAllAndNull = new EdmxReferenceImpl(
EdmxReference referenceWithAllAndNull = new EdmxReference(
URI.create("http://localhost/odata/odata/v4.0/referenceWithAllAndNull"));
referenceWithAllAndNull.addInclude(new EdmxReferenceIncludeImpl("referenceWithAllAndNull.1"));
referenceWithAllAndNull.addInclude(new EdmxReferenceIncludeImpl("referenceWithAllAndNull.2", null));
referenceWithAllAndNull.addInclude(new EdmxReferenceInclude("referenceWithAllAndNull.1"));
referenceWithAllAndNull.addInclude(new EdmxReferenceInclude("referenceWithAllAndNull.2", null));
referenceWithAllAndNull.addIncludeAnnotation(
new EdmxReferenceIncludeAnnotationImpl("ReferenceWithAllTermNs.4"));
new EdmxReferenceIncludeAnnotation("ReferenceWithAllTermNs.4"));
referenceWithAllAndNull.addIncludeAnnotation(
new EdmxReferenceIncludeAnnotationImpl("ReferenceWithAllTermAndNullNs.5", "Q.5", null));
new EdmxReferenceIncludeAnnotation("ReferenceWithAllTermAndNullNs.5", "Q.5", null));
referenceWithAllAndNull.addIncludeAnnotation(
new EdmxReferenceIncludeAnnotationImpl("ReferenceWithAllTermAndNullNs.6", null, "TargetNS"));
new EdmxReferenceIncludeAnnotation("ReferenceWithAllTermAndNullNs.6", null, "TargetNS"));
referenceWithAllAndNull.addIncludeAnnotation(
new EdmxReferenceIncludeAnnotationImpl("ReferenceWithAllTermAndNullNs.7", null, null));
new EdmxReferenceIncludeAnnotation("ReferenceWithAllTermAndNullNs.7", null, null));
edmxReferences.add(referenceWithAllAndNull);
ServiceMetadata serviceMetadata = new ServiceMetadataImpl(ODataServiceVersion.V40,
@ -299,9 +297,9 @@ public class MetadataDocumentTest {
*/
private List<EdmxReference> getEdmxReferences() {
List<EdmxReference> edmxReferences = new ArrayList<EdmxReference>();
EdmxReferenceImpl reference = new EdmxReferenceImpl(
EdmxReference reference = new EdmxReference(
URI.create("http://docs.oasis-open.org/odata/odata/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml"));
EdmxReferenceInclude include = new EdmxReferenceIncludeImpl("Org.OData.Core.V1", "Core");
EdmxReferenceInclude include = new EdmxReferenceInclude("Org.OData.Core.V1", "Core");
reference.addInclude(include);
edmxReferences.add(reference);
return edmxReferences;