[OLINGO-575] Merge abstract with single impl classes
This commit is contained in:
parent
8955af75ce
commit
394d0f8169
|
@ -1,112 +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.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* OData collection property value.
|
||||
*
|
||||
* @param <OV> The actual ODataValue interface.
|
||||
*/
|
||||
public abstract class AbstractODataCollectionValue<OV extends ODataValue>
|
||||
extends AbstractODataValue implements ODataCollectionValue<OV> {
|
||||
|
||||
/**
|
||||
* Values.
|
||||
*/
|
||||
protected final List<OV> values = new ArrayList<OV>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param typeName type name.
|
||||
*/
|
||||
public AbstractODataCollectionValue(final String typeName) {
|
||||
super(typeName == null || typeName.startsWith("Collection(") ? typeName : "Collection(" + typeName + ")");
|
||||
}
|
||||
|
||||
protected abstract ODataCollectionValue<OV> getThis();
|
||||
|
||||
/**
|
||||
* Adds a value to the collection.
|
||||
*
|
||||
* @param value value to be added.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ODataCollectionValue<OV> add(final ODataValue value) {
|
||||
values.add((OV) value);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Value iterator.
|
||||
*
|
||||
* @return value iterator.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<OV> iterator() {
|
||||
return values.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets collection size.
|
||||
*
|
||||
* @return collection size.
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if collection is empty.
|
||||
*
|
||||
* @return 'TRUE' if empty; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return values.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> asJavaCollection() {
|
||||
final List<Object> result = new ArrayList<Object>();
|
||||
for (OV value : values) {
|
||||
if (value.isPrimitive()) {
|
||||
result.add(value.asPrimitive().toValue());
|
||||
} else if (value.isComplex()) {
|
||||
result.add(value.asComplex().asJavaMap());
|
||||
} else if (value.isCollection()) {
|
||||
result.add(value.asCollection().asJavaCollection());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,114 +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.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* OData complex property value.
|
||||
*
|
||||
* @param <OP> The actual ODataProperty interface.
|
||||
*/
|
||||
public abstract class AbstractODataComplexValue<OP extends ODataProperty>
|
||||
extends AbstractODataValue implements ODataComplexValue<OP> {
|
||||
|
||||
/**
|
||||
* Complex type fields.
|
||||
*/
|
||||
protected final Map<String, OP> fields = new LinkedHashMap<String, OP>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param typeName type name.
|
||||
*/
|
||||
public AbstractODataComplexValue(final String typeName) {
|
||||
super(typeName);
|
||||
}
|
||||
|
||||
protected abstract ODataComplexValue<OP> getThis();
|
||||
|
||||
/**
|
||||
* Adds field to the complex type.
|
||||
*
|
||||
* @param field field to be added.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ODataComplexValue<OP> add(final ODataProperty field) {
|
||||
fields.put(field.getName(), (OP) field);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets field.
|
||||
*
|
||||
* @param name name of the field to be retrieved.
|
||||
* @return requested field.
|
||||
*/
|
||||
@Override
|
||||
public OP get(final String name) {
|
||||
return fields.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Complex property fields iterator.
|
||||
*
|
||||
* @return fields iterator.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<OP> iterator() {
|
||||
return fields.values().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number of fields.
|
||||
*
|
||||
* @return number of fields.
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return fields.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> asJavaMap() {
|
||||
final Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||
for (Map.Entry<String, OP> entry : fields.entrySet()) {
|
||||
Object value = null;
|
||||
if (entry.getValue().hasPrimitiveValue()) {
|
||||
value = entry.getValue().getPrimitiveValue().toValue();
|
||||
} else if (entry.getValue().hasComplexValue()) {
|
||||
value = entry.getValue().getValue().asComplex().asJavaMap();
|
||||
} else if (entry.getValue().hasCollectionValue()) {
|
||||
value = entry.getValue().getValue().asCollection().asJavaCollection();
|
||||
}
|
||||
|
||||
result.put(entry.getKey(), value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,276 +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.domain;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataPayload;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* OData entity.
|
||||
*/
|
||||
public abstract class AbstractODataEntity extends AbstractODataPayload implements ODataEntity {
|
||||
|
||||
private final FullQualifiedName typeName;
|
||||
|
||||
/**
|
||||
* ETag.
|
||||
*/
|
||||
private String eTag;
|
||||
|
||||
/**
|
||||
* Media entity flag.
|
||||
*/
|
||||
private boolean mediaEntity = false;
|
||||
|
||||
/**
|
||||
* In case of media entity, media content type.
|
||||
*/
|
||||
private String mediaContentType;
|
||||
|
||||
/**
|
||||
* In case of media entity, media content source.
|
||||
*/
|
||||
private URI mediaContentSource;
|
||||
|
||||
/**
|
||||
* Media ETag.
|
||||
*/
|
||||
private String mediaETag;
|
||||
|
||||
/**
|
||||
* Edit link.
|
||||
*/
|
||||
private URI editLink;
|
||||
|
||||
/**
|
||||
* Navigation links (might contain in-line entities or entity sets).
|
||||
*/
|
||||
private final List<ODataLink> navigationLinks = new ArrayList<ODataLink>();
|
||||
|
||||
/**
|
||||
* Association links.
|
||||
*/
|
||||
private final List<ODataLink> associationLinks = new ArrayList<ODataLink>();
|
||||
|
||||
/**
|
||||
* Media edit links.
|
||||
*/
|
||||
private final List<ODataLink> mediaEditLinks = new ArrayList<ODataLink>();
|
||||
|
||||
/**
|
||||
* Operations (legacy, functions, actions).
|
||||
*/
|
||||
private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
|
||||
|
||||
public AbstractODataEntity(final FullQualifiedName typeName) {
|
||||
super(typeName == null ? null : typeName.toString());
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getETag() {
|
||||
return eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setETag(final String eTag) {
|
||||
this.eTag = eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataOperation getOperation(final String title) {
|
||||
ODataOperation result = null;
|
||||
for (ODataOperation operation : operations) {
|
||||
if (title.equals(operation.getTitle())) {
|
||||
result = operation;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets operations.
|
||||
*
|
||||
* @return operations.
|
||||
*/
|
||||
@Override
|
||||
public List<ODataOperation> getOperations() {
|
||||
return operations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty getProperty(final String name) {
|
||||
ODataProperty result = null;
|
||||
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
for (ODataProperty property : getProperties()) {
|
||||
if (name.equals(property.getName())) {
|
||||
result = property;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLink(final ODataLink link) {
|
||||
boolean result = false;
|
||||
|
||||
switch (link.getType()) {
|
||||
case ASSOCIATION:
|
||||
result = associationLinks.contains(link) ? false : associationLinks.add(link);
|
||||
break;
|
||||
|
||||
case ENTITY_NAVIGATION:
|
||||
case ENTITY_SET_NAVIGATION:
|
||||
result = navigationLinks.contains(link) ? false : navigationLinks.add(link);
|
||||
break;
|
||||
|
||||
case MEDIA_EDIT:
|
||||
result = mediaEditLinks.contains(link) ? false : mediaEditLinks.add(link);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeLink(final ODataLink link) {
|
||||
return associationLinks.remove(link) || navigationLinks.remove(link);
|
||||
}
|
||||
|
||||
private ODataLink getLink(final List<ODataLink> links, final String name) {
|
||||
ODataLink result = null;
|
||||
for (ODataLink link : links) {
|
||||
if (name.equals(link.getName())) {
|
||||
result = link;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLink getNavigationLink(final String name) {
|
||||
return getLink(navigationLinks, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ODataLink> getNavigationLinks() {
|
||||
return navigationLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLink getAssociationLink(final String name) {
|
||||
return getLink(associationLinks, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ODataLink> getAssociationLinks() {
|
||||
return associationLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLink getMediaEditLink(final String name) {
|
||||
return getLink(mediaEditLinks, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ODataLink> getMediaEditLinks() {
|
||||
return mediaEditLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getEditLink() {
|
||||
return editLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEditLink(final URI editLink) {
|
||||
this.editLink = editLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getLink() {
|
||||
return super.getLink() == null ? getEditLink() : super.getLink();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return super.getLink() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMediaEntity() {
|
||||
return mediaEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaEntity(final boolean isMediaEntity) {
|
||||
mediaEntity = isMediaEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMediaContentType() {
|
||||
return mediaContentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaContentType(final String mediaContentType) {
|
||||
this.mediaContentType = mediaContentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getMediaContentSource() {
|
||||
return mediaContentSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaContentSource(final URI mediaContentSource) {
|
||||
this.mediaContentSource = mediaContentSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMediaETag() {
|
||||
return mediaETag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaETag(final String eTag) {
|
||||
mediaETag = eTag;
|
||||
}
|
||||
}
|
|
@ -1,46 +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.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkType;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
|
||||
public abstract class AbstractODataObjectFactory implements ODataObjectFactory {
|
||||
|
||||
protected final ODataServiceVersion version;
|
||||
|
||||
public AbstractODataObjectFactory(final ODataServiceVersion version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataInlineEntitySet newDeepInsertEntitySet(final String name, final ODataEntitySet entitySet) {
|
||||
return new ODataInlineEntitySet(version, null, ODataLinkType.ENTITY_SET_NAVIGATION, name, entitySet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataInlineEntity newDeepInsertEntity(final String name, final ODataEntity entity) {
|
||||
return new ODataInlineEntity(version, null, ODataLinkType.ENTITY_NAVIGATION, name, entity);
|
||||
}
|
||||
}
|
|
@ -1,212 +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.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractODataPrimitiveValue extends AbstractODataValue implements ODataPrimitiveValue {
|
||||
|
||||
public static abstract class AbstractBuilder implements Builder {
|
||||
|
||||
private final ODataServiceVersion version;
|
||||
|
||||
public AbstractBuilder(final ODataServiceVersion version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
protected abstract AbstractODataPrimitiveValue getInstance();
|
||||
|
||||
@Override
|
||||
public AbstractBuilder setType(final EdmType type) {
|
||||
EdmPrimitiveTypeKind primitiveTypeKind = null;
|
||||
if (type != null) {
|
||||
if (type.getKind() != EdmTypeKind.PRIMITIVE) {
|
||||
throw new IllegalArgumentException(String.format("Provided type %s is not primitive", type));
|
||||
}
|
||||
primitiveTypeKind = EdmPrimitiveTypeKind.valueOf(type.getName());
|
||||
}
|
||||
return setType(primitiveTypeKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBuilder setType(final EdmPrimitiveTypeKind type) {
|
||||
if (type != null && !type.getSupportedVersions().contains(version)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Type %s not supported by OData version %s", type.toString(), version));
|
||||
}
|
||||
if (type == EdmPrimitiveTypeKind.Stream) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));
|
||||
}
|
||||
if (type == EdmPrimitiveTypeKind.Geography || type == EdmPrimitiveTypeKind.Geometry) {
|
||||
throw new IllegalArgumentException(
|
||||
type + "is not an instantiable type. "
|
||||
+ "An entity can declare a property to be of type Geometry. "
|
||||
+ "An instance of an entity MUST NOT have a value of type Geometry. "
|
||||
+ "Each value MUST be of some subtype.");
|
||||
}
|
||||
|
||||
getInstance().typeKind = type == null ? EdmPrimitiveTypeKind.String : type;
|
||||
getInstance().type = EdmPrimitiveTypeFactory.getInstance(getInstance().typeKind);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBuilder setValue(final Object value) {
|
||||
getInstance().value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue build() {
|
||||
if (getInstance().type == null) {
|
||||
setType(EdmPrimitiveTypeKind.String);
|
||||
}
|
||||
return getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildBoolean(final Boolean value) {
|
||||
return setType(EdmPrimitiveTypeKind.Boolean).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildInt16(final Short value) {
|
||||
return setType(EdmPrimitiveTypeKind.Int16).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildInt32(final Integer value) {
|
||||
return setType(EdmPrimitiveTypeKind.Int32).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildInt64(final Long value) {
|
||||
return setType(EdmPrimitiveTypeKind.Int64).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildSingle(final Float value) {
|
||||
return setType(EdmPrimitiveTypeKind.Single).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildDouble(final Double value) {
|
||||
return setType(EdmPrimitiveTypeKind.Double).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildString(final String value) {
|
||||
return setType(EdmPrimitiveTypeKind.String).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildGuid(final UUID value) {
|
||||
return setType(EdmPrimitiveTypeKind.Guid).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildBinary(final byte[] value) {
|
||||
return setType(EdmPrimitiveTypeKind.Binary).setValue(value).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Type kind.
|
||||
*/
|
||||
private EdmPrimitiveTypeKind typeKind;
|
||||
|
||||
/**
|
||||
* Type.
|
||||
*/
|
||||
private EdmPrimitiveType type;
|
||||
|
||||
/**
|
||||
* Actual value.
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
protected AbstractODataPrimitiveValue() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return typeKind.getFullQualifiedName().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveTypeKind getTypeKind() {
|
||||
return typeKind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toCastValue(final Class<T> reference) throws EdmPrimitiveTypeException {
|
||||
if (value == null) {
|
||||
return null;
|
||||
} else if (typeKind.isGeospatial()) {
|
||||
return reference.cast(value);
|
||||
} else {
|
||||
// TODO: set facets
|
||||
return type.valueOfString(type.valueToString(value,
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (value == null) {
|
||||
return "";
|
||||
} else if (typeKind.isGeospatial()) {
|
||||
return value.toString();
|
||||
} else {
|
||||
try {
|
||||
// TODO: set facets
|
||||
return type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,136 +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.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
public abstract class AbstractODataProperty implements ODataProperty {
|
||||
|
||||
/**
|
||||
* Property name.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Property value.
|
||||
*/
|
||||
private final ODataValue value;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name property name.
|
||||
* @param value property value.
|
||||
*/
|
||||
public AbstractODataProperty(final String name, final ODataValue value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property name.
|
||||
*
|
||||
* @return property name.
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property value.
|
||||
*
|
||||
* @return property value.
|
||||
*/
|
||||
@Override
|
||||
public ODataValue getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has null value.
|
||||
*
|
||||
* @return 'TRUE' if has null value; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNullValue() {
|
||||
return value == null || value.isPrimitive() && value.asPrimitive().toValue() == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has primitive value.
|
||||
*
|
||||
* @return 'TRUE' if has primitive value; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPrimitiveValue() {
|
||||
return !hasNullValue() && value.isPrimitive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets primitive value.
|
||||
*
|
||||
* @return primitive value if exists; null otherwise.
|
||||
*/
|
||||
@Override
|
||||
public ODataPrimitiveValue getPrimitiveValue() {
|
||||
return hasPrimitiveValue() ? value.asPrimitive() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has complex value.
|
||||
*
|
||||
* @return 'TRUE' if has complex value; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasComplexValue() {
|
||||
return !hasNullValue() && value.isComplex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has collection value.
|
||||
*
|
||||
* @return 'TRUE' if has collection value; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCollectionValue() {
|
||||
return !hasNullValue() && value.isCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
|
@ -18,21 +18,29 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ODataCollectionValueImpl extends AbstractODataCollectionValue<ODataValue> implements ODataValue {
|
||||
public class ODataCollectionValueImpl<OV extends ODataValue> extends AbstractODataValue
|
||||
implements ODataCollectionValue<OV>, ODataValue {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param typeName type name.
|
||||
*/
|
||||
public ODataCollectionValueImpl(final String typeName) {
|
||||
super(typeName);
|
||||
super(typeName == null || typeName.startsWith("Collection(") ? typeName : "Collection(" + typeName + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ODataCollectionValueImpl getThis() {
|
||||
return this;
|
||||
}
|
||||
|
@ -74,4 +82,53 @@ public class ODataCollectionValueImpl extends AbstractODataCollectionValue<OData
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Values.
|
||||
*/
|
||||
protected final List<OV> values = new ArrayList<OV>();
|
||||
|
||||
/**
|
||||
* Adds a value to the collection.
|
||||
*
|
||||
* @param value value to be added.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ODataCollectionValue<OV> add(final ODataValue value) {
|
||||
values.add((OV) value);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Value iterator.
|
||||
*
|
||||
* @return value iterator.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<OV> iterator() {
|
||||
return values.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets collection size.
|
||||
*
|
||||
* @return collection size.
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if collection is empty.
|
||||
*
|
||||
* @return 'TRUE' if empty; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return values.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
|
@ -26,11 +27,13 @@ import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
|||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ODataComplexValueImpl extends AbstractODataComplexValue<ODataProperty> implements ODataLinkedComplexValue {
|
||||
public class ODataComplexValueImpl extends AbstractODataValue implements ODataComplexValue<ODataProperty>,
|
||||
ODataLinkedComplexValue {
|
||||
|
||||
/**
|
||||
* Navigation links (might contain in-line entities or entity sets).
|
||||
|
@ -44,11 +47,21 @@ public class ODataComplexValueImpl extends AbstractODataComplexValue<ODataProper
|
|||
|
||||
private final List<ODataAnnotation> annotations = new ArrayList<ODataAnnotation>();
|
||||
|
||||
/**
|
||||
* Complex type fields.
|
||||
*/
|
||||
private final Map<String, ODataProperty> fields = new LinkedHashMap<String, ODataProperty>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param typeName type name.
|
||||
*/
|
||||
public ODataComplexValueImpl(final String typeName) {
|
||||
super(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
protected ODataComplexValue<ODataProperty> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
@ -158,4 +171,48 @@ public class ODataComplexValueImpl extends AbstractODataComplexValue<ODataProper
|
|||
return annotations;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds field to the complex type.
|
||||
*
|
||||
* @param field field to be added.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ODataComplexValue<ODataProperty> add(final ODataProperty field) {
|
||||
fields.put(field.getName(), field);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets field.
|
||||
*
|
||||
* @param name name of the field to be retrieved.
|
||||
* @return requested field.
|
||||
*/
|
||||
@Override
|
||||
public ODataProperty get(final String name) {
|
||||
return fields.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Complex property fields iterator.
|
||||
*
|
||||
* @return fields iterator.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<ODataProperty> iterator() {
|
||||
return fields.values().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number of fields.
|
||||
*
|
||||
* @return number of fields.
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return fields.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,24 +22,255 @@ import java.net.URI;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataPayload;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataSingleton;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
|
||||
public class ODataEntityImpl extends AbstractODataEntity implements ODataSingleton {
|
||||
public class ODataEntityImpl extends AbstractODataPayload implements ODataEntity, ODataSingleton {
|
||||
|
||||
/**
|
||||
* Entity id.
|
||||
*/
|
||||
private URI id;
|
||||
/**
|
||||
* ETag.
|
||||
*/
|
||||
private String eTag;
|
||||
/**
|
||||
* Media entity flag.
|
||||
*/
|
||||
private boolean mediaEntity = false;
|
||||
/**
|
||||
* In case of media entity, media content type.
|
||||
*/
|
||||
private String mediaContentType;
|
||||
/**
|
||||
* In case of media entity, media content source.
|
||||
*/
|
||||
private URI mediaContentSource;
|
||||
/**
|
||||
* Media ETag.
|
||||
*/
|
||||
private String mediaETag;
|
||||
/**
|
||||
* Edit link.
|
||||
*/
|
||||
private URI editLink;
|
||||
|
||||
private final List<ODataProperty> properties = new ArrayList<ODataProperty>();
|
||||
|
||||
private final List<ODataAnnotation> annotations = new ArrayList<ODataAnnotation>();
|
||||
|
||||
private final FullQualifiedName typeName;
|
||||
/**
|
||||
* Navigation links (might contain in-line entities or entity sets).
|
||||
*/
|
||||
private final List<ODataLink> navigationLinks = new ArrayList<ODataLink>();
|
||||
/**
|
||||
* Association links.
|
||||
*/
|
||||
private final List<ODataLink> associationLinks = new ArrayList<ODataLink>();
|
||||
/**
|
||||
* Media edit links.
|
||||
*/
|
||||
private final List<ODataLink> mediaEditLinks = new ArrayList<ODataLink>();
|
||||
/**
|
||||
* Operations (legacy, functions, actions).
|
||||
*/
|
||||
private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
|
||||
|
||||
public ODataEntityImpl(final FullQualifiedName typeName) {
|
||||
super(typeName);
|
||||
super(typeName == null ? null : typeName.toString());
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getETag() {
|
||||
return eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setETag(final String eTag) {
|
||||
this.eTag = eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataOperation getOperation(final String title) {
|
||||
ODataOperation result = null;
|
||||
for (ODataOperation operation : operations) {
|
||||
if (title.equals(operation.getTitle())) {
|
||||
result = operation;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets operations.
|
||||
*
|
||||
* @return operations.
|
||||
*/
|
||||
@Override
|
||||
public List<ODataOperation> getOperations() {
|
||||
return operations;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ODataProperty getProperty(final String name) {
|
||||
ODataProperty result = null;
|
||||
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
for (ODataProperty property : getProperties()) {
|
||||
if (name.equals(property.getName())) {
|
||||
result = property;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLink(final ODataLink link) {
|
||||
boolean result = false;
|
||||
|
||||
switch (link.getType()) {
|
||||
case ASSOCIATION:
|
||||
result = associationLinks.contains(link) ? false : associationLinks.add(link);
|
||||
break;
|
||||
|
||||
case ENTITY_NAVIGATION:
|
||||
case ENTITY_SET_NAVIGATION:
|
||||
result = navigationLinks.contains(link) ? false : navigationLinks.add(link);
|
||||
break;
|
||||
|
||||
case MEDIA_EDIT:
|
||||
result = mediaEditLinks.contains(link) ? false : mediaEditLinks.add(link);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeLink(final ODataLink link) {
|
||||
return associationLinks.remove(link) || navigationLinks.remove(link);
|
||||
}
|
||||
|
||||
private ODataLink getLink(final List<ODataLink> links, final String name) {
|
||||
ODataLink result = null;
|
||||
for (ODataLink link : links) {
|
||||
if (name.equals(link.getName())) {
|
||||
result = link;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLink getNavigationLink(final String name) {
|
||||
return getLink(navigationLinks, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ODataLink> getNavigationLinks() {
|
||||
return navigationLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLink getAssociationLink(final String name) {
|
||||
return getLink(associationLinks, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ODataLink> getAssociationLinks() {
|
||||
return associationLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLink getMediaEditLink(final String name) {
|
||||
return getLink(mediaEditLinks, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ODataLink> getMediaEditLinks() {
|
||||
return mediaEditLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getEditLink() {
|
||||
return editLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEditLink(final URI editLink) {
|
||||
this.editLink = editLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getLink() {
|
||||
return super.getLink() == null ? getEditLink() : super.getLink();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return super.getLink() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMediaEntity() {
|
||||
return mediaEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaEntity(final boolean isMediaEntity) {
|
||||
mediaEntity = isMediaEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMediaContentType() {
|
||||
return mediaContentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaContentType(final String mediaContentType) {
|
||||
this.mediaContentType = mediaContentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getMediaContentSource() {
|
||||
return mediaContentSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaContentSource(final URI mediaContentSource) {
|
||||
this.mediaContentSource = mediaContentSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMediaETag() {
|
||||
return mediaETag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaETag(final String eTag) {
|
||||
mediaETag = eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,11 +283,6 @@ public class ODataEntityImpl extends AbstractODataEntity implements ODataSinglet
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty getProperty(final String name) {
|
||||
return (ODataProperty) super.getProperty(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ODataProperty> getProperties() {
|
||||
return properties;
|
||||
|
@ -66,5 +292,4 @@ public class ODataEntityImpl extends AbstractODataEntity implements ODataSinglet
|
|||
public List<ODataAnnotation> getAnnotations() {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
|
@ -37,10 +39,22 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
|||
|
||||
import java.net.URI;
|
||||
|
||||
public class ODataObjectFactoryImpl extends AbstractODataObjectFactory implements ODataObjectFactory {
|
||||
public class ODataObjectFactoryImpl implements ODataObjectFactory {
|
||||
|
||||
protected final ODataServiceVersion version;
|
||||
|
||||
public ODataObjectFactoryImpl(final ODataServiceVersion version) {
|
||||
super(version);
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataInlineEntitySet newDeepInsertEntitySet(final String name, final ODataEntitySet entitySet) {
|
||||
return new ODataInlineEntitySet(version, null, ODataLinkType.ENTITY_SET_NAVIGATION, name, entitySet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataInlineEntity newDeepInsertEntity(final String name, final ODataEntity entity) {
|
||||
return new ODataInlineEntity(version, null, ODataLinkType.ENTITY_NAVIGATION, name, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,32 +18,199 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
|
||||
public class ODataPrimitiveValueImpl extends AbstractODataPrimitiveValue implements ODataValue {
|
||||
import java.util.UUID;
|
||||
|
||||
public static class BuilderImpl extends AbstractBuilder {
|
||||
public class ODataPrimitiveValueImpl extends AbstractODataValue implements ODataValue, ODataPrimitiveValue {
|
||||
|
||||
public static class BuilderImpl implements Builder {
|
||||
|
||||
private final ODataPrimitiveValueImpl instance;
|
||||
|
||||
public BuilderImpl(final ODataServiceVersion version) {
|
||||
super(version);
|
||||
this.version = version;
|
||||
instance = new ODataPrimitiveValueImpl();
|
||||
}
|
||||
|
||||
private final ODataServiceVersion version;
|
||||
|
||||
@Override
|
||||
protected AbstractODataPrimitiveValue getInstance() {
|
||||
public BuilderImpl setType(final EdmType type) {
|
||||
EdmPrimitiveTypeKind primitiveTypeKind = null;
|
||||
if (type != null) {
|
||||
if (type.getKind() != EdmTypeKind.PRIMITIVE) {
|
||||
throw new IllegalArgumentException(String.format("Provided type %s is not primitive", type));
|
||||
}
|
||||
primitiveTypeKind = EdmPrimitiveTypeKind.valueOf(type.getName());
|
||||
}
|
||||
return setType(primitiveTypeKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuilderImpl setType(final EdmPrimitiveTypeKind type) {
|
||||
if (type != null && !type.getSupportedVersions().contains(version)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Type %s not supported by OData version %s", type.toString(), version));
|
||||
}
|
||||
if (type == EdmPrimitiveTypeKind.Stream) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));
|
||||
}
|
||||
if (type == EdmPrimitiveTypeKind.Geography || type == EdmPrimitiveTypeKind.Geometry) {
|
||||
throw new IllegalArgumentException(
|
||||
type + "is not an instantiable type. "
|
||||
+ "An entity can declare a property to be of type Geometry. "
|
||||
+ "An instance of an entity MUST NOT have a value of type Geometry. "
|
||||
+ "Each value MUST be of some subtype.");
|
||||
}
|
||||
|
||||
instance.typeKind = type == null ? EdmPrimitiveTypeKind.String : type;
|
||||
instance.type = EdmPrimitiveTypeFactory.getInstance(instance.typeKind);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuilderImpl setValue(final Object value) {
|
||||
instance.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue build() {
|
||||
if (instance.type == null) {
|
||||
setType(EdmPrimitiveTypeKind.String);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValueImpl build() {
|
||||
return (ODataPrimitiveValueImpl) super.build();
|
||||
public ODataPrimitiveValue buildBoolean(final Boolean value) {
|
||||
return setType(EdmPrimitiveTypeKind.Boolean).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildInt16(final Short value) {
|
||||
return setType(EdmPrimitiveTypeKind.Int16).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildInt32(final Integer value) {
|
||||
return setType(EdmPrimitiveTypeKind.Int32).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildInt64(final Long value) {
|
||||
return setType(EdmPrimitiveTypeKind.Int64).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildSingle(final Float value) {
|
||||
return setType(EdmPrimitiveTypeKind.Single).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildDouble(final Double value) {
|
||||
return setType(EdmPrimitiveTypeKind.Double).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildString(final String value) {
|
||||
return setType(EdmPrimitiveTypeKind.String).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildGuid(final UUID value) {
|
||||
return setType(EdmPrimitiveTypeKind.Guid).setValue(value).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue buildBinary(final byte[] value) {
|
||||
return setType(EdmPrimitiveTypeKind.Binary).setValue(value).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Type kind.
|
||||
*/
|
||||
private EdmPrimitiveTypeKind typeKind;
|
||||
|
||||
/**
|
||||
* Type.
|
||||
*/
|
||||
private EdmPrimitiveType type;
|
||||
|
||||
/**
|
||||
* Actual value.
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
protected ODataPrimitiveValueImpl() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return typeKind.getFullQualifiedName().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveTypeKind getTypeKind() {
|
||||
return typeKind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toCastValue(final Class<T> reference) throws EdmPrimitiveTypeException {
|
||||
if (value == null) {
|
||||
return null;
|
||||
} else if (typeKind.isGeospatial()) {
|
||||
return reference.cast(value);
|
||||
} else {
|
||||
// TODO: set facets
|
||||
return type.valueOfString(type.valueToString(value,
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (value == null) {
|
||||
return "";
|
||||
} else if (typeKind.isGeospatial()) {
|
||||
return value.toString();
|
||||
} else {
|
||||
try {
|
||||
// TODO: set facets
|
||||
return type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotatable;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
|
@ -31,20 +34,98 @@ import org.apache.olingo.commons.api.domain.ODataValue;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ODataPropertyImpl extends AbstractODataProperty implements ODataProperty, ODataAnnotatable, ODataValuable {
|
||||
public class ODataPropertyImpl implements ODataProperty, ODataAnnotatable, ODataValuable {
|
||||
|
||||
private final ODataValuable valuable;
|
||||
|
||||
private final List<ODataAnnotation> annotations = new ArrayList<ODataAnnotation>();
|
||||
private final String name;
|
||||
private final ODataValue value;
|
||||
private final ODataValuable valuable;
|
||||
|
||||
public ODataPropertyImpl(final String name, final org.apache.olingo.commons.api.domain.ODataValue value) {
|
||||
super(name, value);
|
||||
valuable = new ODataValuableImpl((ODataValue) value);
|
||||
public ODataPropertyImpl(final String name, final ODataValue value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.valuable = new ODataValuableImpl(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property name.
|
||||
*
|
||||
* @return property name.
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property value.
|
||||
*
|
||||
* @return property value.
|
||||
*/
|
||||
@Override
|
||||
public ODataValue getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has null value.
|
||||
*
|
||||
* @return 'TRUE' if has null value; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNullValue() {
|
||||
return value == null || value.isPrimitive() && value.asPrimitive().toValue() == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has primitive value.
|
||||
*
|
||||
* @return 'TRUE' if has primitive value; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPrimitiveValue() {
|
||||
return !hasNullValue() && value.isPrimitive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets primitive value.
|
||||
*
|
||||
* @return primitive value if exists; null otherwise.
|
||||
*/
|
||||
@Override
|
||||
public ODataPrimitiveValue getPrimitiveValue() {
|
||||
return hasPrimitiveValue() ? value.asPrimitive() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has complex value.
|
||||
*
|
||||
* @return 'TRUE' if has complex value; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasComplexValue() {
|
||||
return !hasNullValue() && value.isComplex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has collection value.
|
||||
*
|
||||
* @return 'TRUE' if has collection value; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCollectionValue() {
|
||||
return !hasNullValue() && value.isCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataValue getValue() {
|
||||
return valuable.getValue();
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,5 +166,4 @@ public class ODataPropertyImpl extends AbstractODataProperty implements ODataPro
|
|||
+ ", annotations=" + annotations
|
||||
+ '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue