[OLINGO-169] First huge import from ODataJClient: for the moment, it just build (no tests yet) and dummy Edm interfaces are used instead of the ones from commons-api

This commit is contained in:
Francesco Chicchiriccò 2014-02-21 17:25:07 +01:00
parent f094e109d7
commit 4f927e7640
253 changed files with 16024 additions and 198 deletions

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,11 @@
<artifactId>olingo-odata4-commons-api-incubating</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,201 @@
/*
* 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.odata4.client.api;
import org.apache.olingo.odata4.client.api.http.HttpUriRequestFactory;
import org.apache.olingo.odata4.client.api.http.HttpClientFactory;
import java.io.Serializable;
import java.util.concurrent.ExecutorService;
import org.apache.olingo.odata4.client.api.format.ODataFormat;
import org.apache.olingo.odata4.client.api.format.ODataMediaFormat;
import org.apache.olingo.odata4.client.api.format.ODataPubFormat;
import org.apache.olingo.odata4.client.api.format.ODataValueFormat;
/**
* Configuration wrapper.
*/
public interface Configuration extends Serializable {
/**
* Gets the configured OData format for AtomPub exchanges. If this configuration parameter doesn't exist the
* JSON_FULL_METADATA format will be used as default.
*
* @return configured OData format for AtomPub if specified; JSON_FULL_METADATA format otherwise.
* @see ODataPubFormat#JSON_FULL_METADATA
*/
ODataPubFormat getDefaultPubFormat();
/**
* Sets the default OData format for AtomPub exchanges.
*
* @param format default format.
*/
void setDefaultPubFormat(ODataPubFormat format);
/**
* Gets the configured OData format. This value depends on what is returned from <tt>getDefaultPubFormat()</tt>.
*
* @return configured OData format
* @see #getDefaultPubFormat()
*/
ODataFormat getDefaultFormat();
/**
* Gets the configured OData value format. If this configuration parameter doesn't exist the TEXT format will be used
* as default.
*
* @return configured OData value format if specified; TEXT format otherwise.
* @see ODataValueFormat#TEXT
*/
ODataValueFormat getDefaultValueFormat();
/**
* Sets the default OData value format.
*
* @param format default format.
*/
void setDefaultValueFormat(ODataValueFormat format);
/**
* Gets the configured OData media format. If this configuration parameter doesn't exist the APPLICATION_OCTET_STREAM
* format will be used as default.
*
* @return configured OData media format if specified; APPLICATION_OCTET_STREAM format otherwise.
* @see ODataMediaFormat#WILDCARD
*/
ODataMediaFormat getDefaultMediaFormat();
/**
* Sets the default OData media format.
*
* @param format default format.
*/
void setDefaultMediaFormat(ODataMediaFormat format);
/**
* Gets the HttpClient factory to be used for executing requests.
*
* @return provided implementation (if configured via <tt>setHttpClientFactory</tt> or default.
* @see DefaultHttpClientFactory
*/
HttpClientFactory getHttpClientFactory();
/**
* Sets the HttpClient factory to be used for executing requests.
*
* @param factory implementation of <tt>HttpClientFactory</tt>.
* @see HttpClientFactory
*/
void setHttpClientFactory(HttpClientFactory factory);
/**
* Gets the HttpUriRequest factory for generating requests to be executed.
*
* @return provided implementation (if configured via <tt>setHttpUriRequestFactory</tt> or default.
* @see DefaultHttpUriRequestFactory
*/
HttpUriRequestFactory getHttpUriRequestFactory();
/**
* Sets the HttpUriRequest factory generating requests to be executed.
*
* @param factory implementation of <tt>HttpUriRequestFactory</tt>.
* @see HttpUriRequestFactory
*/
void setHttpUriRequestFactory(HttpUriRequestFactory factory);
/**
* Gets whether <tt>PUT</tt>, <tt>MERGE</tt>, <tt>PATCH</tt>, <tt>DELETE</tt> HTTP methods need to be translated to
* <tt>POST</tt> with additional <tt>X-HTTTP-Method</tt> header.
*
* @return whether <tt>X-HTTTP-Method</tt> header is to be used
*/
boolean isUseXHTTPMethod();
/**
* Sets whether <tt>PUT</tt>, <tt>MERGE</tt>, <tt>PATCH</tt>, <tt>DELETE</tt> HTTP methods need to be translated to
* <tt>POST</tt> with additional <tt>X-HTTTP-Method</tt> header.
*
* @param value 'TRUE' to use tunneling.
*/
void setUseXHTTPMethod(boolean value);
/**
* Checks whether URIs contain entity key between parentheses (standard) or instead as additional segment. Example:
* http://services.odata.org/V4/OData/OData.svc/Products(0) or http://services.odata.org/V4/OData/OData.svc/Products/0
*
* @return whether URIs shall be built with entity key between parentheses (standard) or instead as additional
* segment.
*/
boolean isKeyAsSegment();
/**
* Sets whether URIs shall be built with entity key between parentheses (standard) or instead as additional segment.
* Example: http://services.odata.org/V4/OData/OData.svc/Products(0) or
* http://services.odata.org/V4/OData/OData.svc/Products/0
*
* @param value 'TRUE' to use this feature.
*/
void setKeyAsSegment(boolean value);
/**
* Checks whether Gzip compression (e.g. support for <tt>Accept-Encoding: gzip</tt> and
* <tt>Content-Encoding: gzip</tt> HTTP headers) is enabled.
*
* @return whether HTTP Gzip compression is enabled
*/
boolean isGzipCompression();
/**
* Sets Gzip compression (e.g. support for <tt>Accept-Encoding: gzip</tt> and
* <tt>Content-Encoding: gzip</tt> HTTP headers) enabled or disabled.
*
* @param value whether to use Gzip compression.
*/
void setGzipCompression(boolean value);
/**
* Checks whether chunk HTTP encoding is being used.
*
* @return whether chunk HTTP encoding is being used
*/
boolean isUseChuncked();
/**
* Sets chunk HTTP encoding enabled or disabled.
*
* @param value whether to use chunk HTTP encoding.
*/
void setUseChuncked(boolean value);
/**
* Retrieves request executor service.
*
* @return request executor service.
*/
ExecutorService getExecutor();
/**
* Sets request executor service.
*
* @param executorService new executor services.
*/
void setExecutor(ExecutorService executorService);
}

View File

@ -0,0 +1,217 @@
/*
* 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.odata4.client.api;
import javax.xml.XMLConstants;
/**
* Constant values related to the OData protocol.
*/
public class Constants {
// Other stuff
public final static String UTF8 = "UTF-8";
public final static String NAME = "name";
public final static String PROPERTIES = "properties";
// XML namespaces and prefixes
public final static String NS_ATOM = "http://www.w3.org/2005/Atom";
public static final String NS_GEORSS = "http://www.georss.org/georss";
public static final String NS_GML = "http://www.opengis.net/gml";
public static final String XMLNS_DATASERVICES = XMLConstants.XMLNS_ATTRIBUTE + ":d";
public static final String PREFIX_DATASERVICES = "d:";
public static final String XMLNS_METADATA = XMLConstants.XMLNS_ATTRIBUTE + ":m";
public static final String PREFIX_METADATA = "m:";
public static final String XMLNS_GEORSS = XMLConstants.XMLNS_ATTRIBUTE + ":georss";
public static final String PREFIX_GEORSS = "georss:";
public static final String XMLNS_GML = XMLConstants.XMLNS_ATTRIBUTE + ":gml";
public static final String PREFIX_GML = "gml:";
/**
* Edit link rel value.
*/
public static final String EDIT_LINK_REL = "edit";
/**
* Self link rel value.
*/
public static final String SELF_LINK_REL = "self";
public static final String NEXT_LINK_REL = "next";
// XML elements and attributes
public static final String ELEM_PROPERTIES = PREFIX_METADATA + PROPERTIES;
public static final String ELEM_ELEMENT = "element";
public final static String ATTR_TYPE = "type";
public static final String ATTR_M_TYPE = PREFIX_METADATA + ATTR_TYPE;
public static final String ATTR_NULL = PREFIX_METADATA + "null";
public static final String ATTR_XMLBASE = "xml:base";
public static final String ATTR_REL = "rel";
public static final String ATTR_HREF = "href";
public static final String ATTR_METADATA = "metadata";
public static final String ATTR_TITLE = "title";
public static final String ATTR_TARGET = "target";
public static final String ELEM_COLLECTION = "collection";
public static final String ATTR_SRSNAME = PREFIX_GML + "srsName";
public static final String ELEM_POINT = PREFIX_GML + "Point";
public static final String ELEM_MULTIPOINT = PREFIX_GML + "MultiPoint";
public static final String ELEM_POINTMEMBERS = PREFIX_GML + "pointMembers";
public static final String ELEM_LINESTRING = PREFIX_GML + "LineString";
public static final String ELEM_MULTILINESTRING = PREFIX_GML + "MultiCurve";
public static final String ELEM_LINESTRINGMEMBERS = PREFIX_GML + "curveMembers";
public static final String ELEM_POLYGON = PREFIX_GML + "Polygon";
public static final String ELEM_POLYGON_EXTERIOR = PREFIX_GML + "exterior";
public static final String ELEM_POLYGON_INTERIOR = PREFIX_GML + "interior";
public static final String ELEM_POLYGON_LINEARRING = PREFIX_GML + "LinearRing";
public static final String ELEM_MULTIPOLYGON = PREFIX_GML + "MultiSurface";
public static final String ELEM_SURFACEMEMBERS = PREFIX_GML + "surfaceMembers";
public static final String ELEM_GEOCOLLECTION = PREFIX_GML + "MultiGeometry";
public static final String ELEM_GEOMEMBERS = PREFIX_GML + "geometryMembers";
public static final String ELEM_POS = PREFIX_GML + "pos";
public static final String ELEM_POSLIST = PREFIX_GML + "posList";
public static final String ELEM_PROPERTY = "property";
public static final String ELEM_URI = "uri";
// JSON stuff
public final static String JSON_METADATA = "odata.metadata";
public final static String JSON_TYPE = "odata.type";
public final static String JSON_ETAG = "odata.etag";
public final static String JSON_MEDIA_ETAG = "odata.mediaETag";
public final static String JSON_ID = "odata.id";
public final static String JSON_READ_LINK = "odata.readLink";
public final static String JSON_EDIT_LINK = "odata.editLink";
public final static String JSON_MEDIAREAD_LINK = "odata.mediaReadLink";
public final static String JSON_MEDIAEDIT_LINK = "odata.mediaEditLink";
public final static String JSON_MEDIA_CONTENT_TYPE = "odata.mediaContentType";
public final static String JSON_NAVIGATION_LINK_SUFFIX = "@odata.navigationLinkUrl";
public final static String JSON_BIND_LINK_SUFFIX = "@odata.bind";
public final static String JSON_ASSOCIATION_LINK_SUFFIX = "@odata.associationLinkUrl";
public final static String JSON_MEDIAEDIT_LINK_SUFFIX = "@odata.mediaEditLink";
public final static String JSON_VALUE = "value";
public final static String JSON_URL = "url";
public final static String JSON_COORDINATES = "coordinates";
public final static String JSON_GEOMETRIES = "geometries";
public final static String JSON_CRS = "crs";
public final static String JSON_GIS_URLPREFIX = "http://www.opengis.net/def/crs/EPSG/0/";
// Atom stuff
public final static String ATOM_ELEM_ENTRY = "entry";
public final static String ATOM_ELEM_FEED = "feed";
public final static String ATOM_ELEM_CATEGORY = "category";
public final static String ATOM_ELEM_ID = "id";
public final static String ATOM_ELEM_LINK = "link";
public final static String ATOM_ELEM_CONTENT = "content";
public static final String ATOM_ELEM_TITLE = "title";
public static final String ATOM_ELEM_SUMMARY = "summary";
public static final String ATOM_ELEM_UPDATED = "updated";
public static final String ATOM_ELEM_AUTHOR = "author";
public static final String ATOM_ELEM_AUTHOR_NAME = "name";
public static final String ATOM_ELEM_AUTHOR_URI = "uri";
public static final String ATOM_ELEM_AUTHOR_EMAIL = "email";
public static final String ATOM_ELEM_ACTION = PREFIX_METADATA + "action";
public static final String ATOM_ELEM_INLINE = PREFIX_METADATA + "inline";
public static final String ATOM_ATTR_TITLE = "atom:title";
public static final String ATOM_ATTR_TERM = "term";
public static final String ATOM_ATTR_SCHEME = "scheme";
public static final String ATOM_ATTR_SRC = "src";
public static final String ATOM_ATTR_ETAG = PREFIX_METADATA + "etag";
public static final String ATOM_ATTR_COUNT = PREFIX_METADATA + "count";
}

View File

@ -18,27 +18,41 @@
*/
package org.apache.olingo.odata4.client.api;
//TODO: Exceptionhandling
public abstract class ODataClient {
import org.apache.olingo.odata4.client.api.data.ODataDeserializer;
import org.apache.olingo.odata4.client.api.data.ODataReader;
import org.apache.olingo.odata4.client.api.data.ODataSerializer;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
private static final String IMPLEMENTATION = "org.apache.olingo.odata4.client.core.ODataClientImpl";
public interface ODataClient {
public static ODataClient create() {
ODataClient instance;
ODataServiceVersion getServiceVersion();
try {
final Class<?> clazz = Class.forName(ODataClient.IMPLEMENTATION);
//ODataHeaders getVersionHeaders();
Configuration getConfiguration();
/*
* We explicitly do not use the singleton pattern to keep the server state free
* and avoid class loading issues also during hot deployment.
*/
final Object object = clazz.newInstance();
instance = (ODataClient) object;
// URIBuilder getURIBuilder(String serviceRoot);
//
// FilterFactory getFilterFactory();
//
ODataSerializer getSerializer();
//
ODataDeserializer getDeserializer();
} catch (final Exception e) {
throw new RuntimeException(e);
}
return instance;
}
ODataReader getReader();
// ODataWriter getWriter();
//
// ODataBinder getBinder();
//
// ODataObjectFactory getObjectFactory();
//
// RetrieveRequestFactory getRetrieveRequestFactory();
//
// CUDRequestFactory getCUDRequestFactory();
//
// StreamedRequestFactory getStreamedRequestFactory();
//
// InvokeRequestFactory<?, ?, ?, ?, ?, ?, ?, ?> getInvokeRequestFactory();
//
// BatchRequestFactory getBatchRequestFactory();
}

View File

@ -0,0 +1,67 @@
/*
* 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.odata4.client.api;
/**
* OData error.
*/
public interface ODataError {
/**
* Gets error code.
*
* @return error code.
*/
String getCode();
/**
* Gets error message language.
*
* @return error message language.
*/
String getMessageLang();
/**
* Gets error message.
*
* @return error message.
*/
String getMessageValue();
/**
* Gets inner error message.
*
* @return inner error message.
*/
String getInnerErrorMessage();
/**
* Gets inner error type.
*
* @return inner error type.
*/
String getInnerErrorType();
/**
* Gets inner error stack-trace.
*
* @return inner error stack-trace
*/
String getInnerErrorStacktrace();
}

View File

@ -0,0 +1,90 @@
/*
* 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.odata4.client.api.data;
import java.io.InputStream;
import java.io.Serializable;
import org.apache.olingo.odata4.client.api.edm.Edmx;
import org.w3c.dom.Element;
/**
* Utility class for serialization.
*/
public interface ODataDeserializer extends Serializable {
Edmx toMetadata(InputStream input);
/**
* Gets the ServiceDocumentResource object represented by the given InputStream.
*
* @param input stream to be de-serialized.
* @param format OData service document format.
* @return ServiceDocumentResource object.
*/
// ServiceDocument toServiceDocument(InputStream input, ODataFormat format);
/**
* Gets a feed object from the given InputStream.
*
* @param <T> reference class type
* @param input stream to be de-serialized.
* @param reference reference class (AtomFeed.class, JSONFeed.class).
* @return FeedResource instance.
*/
// <T extends Feed> T toFeed(InputStream input, Class<T> reference);
/**
* Gets an entry object from the given InputStream.
*
* @param <T> reference class type
* @param input stream to be de-serialized.
* @param reference reference class (AtomEntry.class, JSONV3Entry.class).
* @return EntryResource instance.
*/
// <T extends Entry> T toEntry(InputStream input, Class<T> reference);
/**
* Gets a DOM representation of the given InputStream.
*
* @param input stream to be de-serialized.
* @param format OData format.
* @return DOM.
*/
// Element toPropertyDOM(InputStream input, ODataFormat format);
/**
* Gets a list of links from the given InputStream.
*
* @param input stream to be de-serialized.
* @param format OData format.
* @return de-serialized links.
*/
// LinkCollection toLinkCollection(InputStream input, ODataFormat format);
/**
* Gets the ODataError object represented by the given InputStream.
*
* @param input stream to be parsed and de-serialized.
* @param isXML 'TRUE' if the error is represented by XML; 'FALSE' otherwise.
* @return
*/
// ODataError toODataError(InputStream input, boolean isXML);
/**
* Parses the given input into a DOM tree.
*
* @param input stream to be parsed and de-serialized.
* @return DOM tree
*/
Element toDOM(InputStream input);
}

View File

@ -0,0 +1,102 @@
/*
* 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.odata4.client.api.data;
import java.io.InputStream;
import java.io.Serializable;
import org.apache.olingo.odata4.client.api.ODataError;
import org.apache.olingo.odata4.client.api.edm.EdmMetadata;
/**
* OData reader.
* <br/>
* Use this class to de-serialize an OData response body.
* <br/>
* This class provides method helpers to de-serialize an entire feed, a set of entities and a single entity as well.
*/
public interface ODataReader extends Serializable {
/**
* Parses a stream into metadata representation.
*
* @param input stream to de-serialize.
* @return metadata representation.
*/
EdmMetadata readMetadata(InputStream input);
/**
* Parses an OData service document.
*
* @param input stream to de-serialize.
* @param format de-serialize as XML or JSON
* @return List of URIs.
*/
//ODataServiceDocument readServiceDocument(InputStream input, ODataFormat format);
/**
* De-Serializes a stream into an OData entity set.
*
* @param input stream to de-serialize.
* @param format de-serialize as AtomFeed or JSONFeed
* @return de-serialized entity set.
*/
//ODataEntitySet readEntitySet(InputStream input, ODataPubFormat format);
/**
* Parses a stream taking care to de-serializes the first OData entity found.
*
* @param input stream to de-serialize.
* @param format de-serialize as AtomEntry or JSONEntry
* @return entity de-serialized.
*/
//ODataEntity readEntity(InputStream input, ODataPubFormat format);
/**
* Parses a stream taking care to de-serialize the first OData entity property found.
*
* @param input stream to de-serialize.
* @param format de-serialize as XML or JSON
* @return OData entity property de-serialized.
*/
//ODataProperty readProperty(InputStream input, ODataFormat format);
/**
* Parses a $links request response.
*
* @param input stream to de-serialize.
* @param format de-serialize as XML or JSON
* @return List of URIs.
*/
//ODataLinkCollection readLinks(InputStream input, ODataFormat format);
/**
* Parses a stream into an OData error.
*
* @param inputStream stream to de-serialize.
* @param isXML 'TRUE' if the error is in XML format.
* @return OData error.
*/
// ODataError readError(InputStream inputStream, boolean isXML);
/**
* Parses a stream into the object type specified by the given reference.
*
* @param <T> expected object type.
* @param src input stream.
* @param format format
* @param reference reference.
* @return read object.
*/
//<T> T read(InputStream src, String format, Class<T> reference);
}

View File

@ -0,0 +1,120 @@
/**
* 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.odata4.client.api.data;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.Writer;
import org.apache.olingo.odata4.client.api.format.ODataFormat;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Utility class for serialization.
*/
public interface ODataSerializer extends Serializable {
/**
* Writes <tt>FeedResource</tt> object onto the given stream.
*
* @param <T> feed resource type.
* @param obj object to be streamed.
* @param out output stream.
*/
// <T extends Feed> void feed(T obj, OutputStream out);
/**
* Writes <tt>FeedResource</tt> object by the given writer.
*
* @param <T> feed resource type.
* @param obj object to be streamed.
* @param writer writer.
*/
// <T extends Feed> void feed(T obj, Writer writer);
/**
* Writes <tt>EntryResource</tt> object onto the given stream.
*
* @param <T> entry resource type.
* @param obj object to be streamed.
* @param out output stream.
*/
// <T extends Entry> void entry(T obj, OutputStream out);
/**
* Writes <tt>EntryResource</tt> object by the given writer.
*
* @param <T> entry resource type.
* @param obj object to be streamed.
* @param writer writer.
*/
// <T extends Entry> void entry(T obj, Writer writer);
/**
* Writes entry content onto the given stream.
*
* @param element element to be streamed.
* @param format streaming format.
* @param out output stream.
*/
// void property(Element element, ODataFormat format, OutputStream out);
/**
* Writes entry content by the given writer.
*
* @param element element to be streamed.
* @param format streaming format.
* @param writer writer.
*/
// void property(Element element, ODataFormat format, Writer writer);
/**
* Writes OData link onto the given stream.
*
* @param link OData link to be streamed.
* @param format streaming format.
* @param out output stream.
*/
// void link(ODataLink link, ODataFormat format, OutputStream out);
/**
* Writes OData link by the given writer.
*
* @param link OData link to be streamed.
* @param format streaming format.
* @param writer writer.
*/
// void link(ODataLink link, ODataFormat format, Writer writer);
/**
* Writes DOM object onto the given stream.
*
* @param content DOM to be streamed.
* @param out output stream.
*/
void dom(Node content, OutputStream out);
/**
* Writes DOM object by the given writer.
*
* @param content DOM to be streamed.
* @param writer writer.
*/
void dom(Node content, Writer writer);
}

View File

@ -0,0 +1,32 @@
/*
* 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.odata4.client.api.edm;
import java.util.List;
public interface ComplexType {
String getName();
void setName(String name);
public abstract List<? extends Property> getProperties();
public abstract Property getProperty(String name);
}

View File

@ -0,0 +1,59 @@
/*
* 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.odata4.client.api.edm;
import java.util.List;
/**
* Entry point for access information about EDM metadata.
*/
public interface EdmMetadata {
/**
* Checks whether the given key is a valid namespace or alias in the EdM metadata document.
*
* @param key namespace or alias
* @return true if key is valid namespace or alias
*/
boolean isNsOrAlias(String key);
/**
* Returns the Schema at the specified position in the EdM metadata document.
*
* @param index index of the Schema to return
* @return the Schema at the specified position in the EdM metadata document
*/
Schema getSchema(final int index);
/**
* Returns the Schema with the specified key (namespace or alias) in the EdM metadata document.
*
* @param key namespace or alias
* @return the Schema with the specified key in the EdM metadata document
*/
Schema getSchema(final String key);
/**
* Returns all Schema objects defined in the EdM metadata document.
*
* @return all Schema objects defined in the EdM metadata document
*/
List<? extends Schema> getSchemas();
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface Edmx {
}

View File

@ -0,0 +1,24 @@
/*
* 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.odata4.client.api.edm;
public interface EntityContainer {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface EntityKey {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface EntitySet {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface EntityType {
}

View File

@ -0,0 +1,42 @@
/*
* 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.odata4.client.api.edm;
import java.util.List;
public interface EnumType {
String getName();
void setName(String name);
String getUnderlyingType();
void setUnderlyingType(String underlyingType);
boolean isFlags();
void setFlags(boolean flags);
List<? extends Member> getMembers();
Member getMember(String name);
Member getMember(Integer value);
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface FunctionImport {
}

View File

@ -16,10 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.odata4.client.core;
package org.apache.olingo.odata4.client.api.edm;
import org.apache.olingo.odata4.client.api.ODataClient;
public interface Member {
public class ODataClientImpl extends ODataClient {
String getName();
Integer getValue();
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface NavigationProperty {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface NavigationPropertyBinding {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface OnDelete {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface Parameter {
}

View File

@ -0,0 +1,24 @@
/*
* 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.odata4.client.api.edm;
public interface Property {
String getName();
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm;
public interface PropertyRef {
}

View File

@ -0,0 +1,79 @@
/*
* 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.odata4.client.api.edm;
import org.apache.olingo.odata4.client.api.edm.v3.Annotations;
import java.util.List;
public interface Schema {
String getNamespace();
void setNamespace(String namespace);
String getAlias();
void setAlias(String alias);
List<? extends EntityType> getEntityTypes();
List<? extends EnumType> getEnumTypes();
EnumType getEnumType(String name);
List<? extends Annotations> getAnnotationsList();
Annotations getAnnotationsList(String target);
List<? extends ComplexType> getComplexTypes();
List<? extends EntityContainer> getEntityContainers();
/**
* Gets default entity container.
*
* @return default entity container.
*/
EntityContainer getDefaultEntityContainer();
/**
* Gets entity container with the given name.
*
* @param name name.
* @return entity container.
*/
EntityContainer getEntityContainer(String name);
/**
* Gets entity type with the given name.
*
* @param name name.
* @return entity type.
*/
EntityType getEntityType(String name);
/**
* Gets complex type with the given name.
*
* @param name name.
* @return complex type.
*/
ComplexType getComplexType(String name);
}

View File

@ -0,0 +1,24 @@
/*
* 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.odata4.client.api.edm.v3;
public interface Annotations {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface Association {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface AssociationEnd {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface AssociationSet {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface AssociationSetEnd {
}

View File

@ -0,0 +1,27 @@
/*
* 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.odata4.client.api.edm.v3;
public enum ParameterMode {
In,
Out,
InOut
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface PropertyValue {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface ReferentialConstraint {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface TypeAnnotation {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface Using {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface ValueAnnotation {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v3;
public interface ValueTerm {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface Action {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface ActionImport {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface Annotation {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface Annotations {
}

View File

@ -0,0 +1,37 @@
/*
* 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.odata4.client.api.edm.v4;
public enum CSDLElement {
ActionImport,
ComplexType,
EntityContainer,
EntitySet,
EntityType,
EnumType,
FunctionImport,
Member,
NavigationProperty,
Property,
Singleton,
Term,
TypeDefinition
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface Include {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface IncludeAnnotations {
}

View File

@ -0,0 +1,28 @@
/*
* 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.odata4.client.api.edm.v4;
public enum OnDeleteAction {
Cascade,
None,
SetNull,
SetDefault;
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface Reference {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface ReferentialConstraint {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface ReturnType {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface Singleton {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface Term {
}

View File

@ -0,0 +1,23 @@
/*
* 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.odata4.client.api.edm.v4;
public interface TypeDefinition {
}

View File

@ -0,0 +1,97 @@
/*
* 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.odata4.client.api.format;
import org.apache.http.entity.ContentType;
/**
* Available formats to be used in various contexts.
*/
public enum ODataFormat {
/**
* JSON format with no metadata.
*/
JSON_NO_METADATA(ContentType.APPLICATION_JSON.getMimeType() + ";odata=nometadata"),
/**
* JSON format with minimal metadata (default).
*/
JSON(ContentType.APPLICATION_JSON.getMimeType() + ";odata=minimalmetadata"),
/**
* JSON format with no metadata.
*/
JSON_FULL_METADATA(ContentType.APPLICATION_JSON.getMimeType() + ";odata=fullmetadata"),
/**
* XML format.
*/
XML(ContentType.APPLICATION_XML.getMimeType());
private final String format;
ODataFormat(final String format) {
this.format = format;
}
/**
* Gets format as a string.
*
* @return format as a string.
*/
@Override
public String toString() {
return format;
}
/**
* Gets OData format from its string representation.
*
* @param format string representation of the format.
* @return OData format.
*/
public static ODataFormat fromString(final String format) {
ODataFormat result = null;
final StringBuffer _format = new StringBuffer();
final String[] parts = format.split(";");
_format.append(parts[0]);
if (ContentType.APPLICATION_JSON.getMimeType().equals(parts[0])) {
if (parts.length > 1) {
_format.append(';').append(parts[1]);
} else {
result = ODataFormat.JSON;
}
}
if (result == null) {
final String candidate = _format.toString();
for (ODataFormat value : values()) {
if (candidate.equals(value.toString())) {
result = value;
}
}
}
if (result == null) {
throw new IllegalArgumentException("Unsupported format: " + format);
}
return result;
}
}

View File

@ -0,0 +1,71 @@
/*
* 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.odata4.client.api.format;
import org.apache.http.entity.ContentType;
/**
* Available formats for media.
*/
public enum ODataMediaFormat {
CHARSET_PARAMETER("charset"),
MEDIA_TYPE_WILDCARD("*"),
WILDCARD("*/*"),
APPLICATION_XML(ContentType.APPLICATION_XML.getMimeType()),
APPLICATION_ATOM_XML(ContentType.APPLICATION_ATOM_XML.getMimeType()),
APPLICATION_XHTML_XML(ContentType.APPLICATION_XHTML_XML.getMimeType()),
APPLICATION_SVG_XML(ContentType.APPLICATION_SVG_XML.getMimeType()),
APPLICATION_JSON(ContentType.APPLICATION_JSON.getMimeType()),
APPLICATION_FORM_URLENCODED(ContentType.APPLICATION_FORM_URLENCODED.getMimeType()),
MULTIPART_FORM_DATA(ContentType.MULTIPART_FORM_DATA.getMimeType()),
APPLICATION_OCTET_STREAM(ContentType.APPLICATION_OCTET_STREAM.getMimeType()),
TEXT_PLAIN(ContentType.TEXT_PLAIN.getMimeType()),
TEXT_XML(ContentType.TEXT_XML.getMimeType()),
TEXT_HTML(ContentType.TEXT_HTML.getMimeType());
private final String format;
private ODataMediaFormat(final String format) {
this.format = format;
}
@Override
public String toString() {
return format;
}
public static ODataMediaFormat fromFormat(final String format) {
final String _format = format.split(";")[0];
ODataMediaFormat result = null;
for (ODataMediaFormat value : values()) {
if (_format.equals(value.toString())) {
result = value;
}
}
if (result == null) {
throw new IllegalArgumentException("Unsupported format: " + format);
}
return result;
}
}

View File

@ -0,0 +1,97 @@
/*
* 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.odata4.client.api.format;
import org.apache.http.entity.ContentType;
/**
* Available formats for AtomPub exchange.
*/
public enum ODataPubFormat {
/**
* JSON format with no metadata.
*/
JSON_NO_METADATA(ContentType.APPLICATION_JSON.getMimeType() + ";odata=nometadata"),
/**
* JSON format with minimal metadata (default).
*/
JSON(ContentType.APPLICATION_JSON.getMimeType() + ";odata=minimalmetadata"),
/**
* JSON format with no metadata.
*/
JSON_FULL_METADATA(ContentType.APPLICATION_JSON.getMimeType() + ";odata=fullmetadata"),
/**
* Atom format.
*/
ATOM(ContentType.APPLICATION_ATOM_XML.getMimeType());
private final String format;
ODataPubFormat(final String format) {
this.format = format;
}
/**
* Gets format as a string.
*
* @return format as a string.
*/
@Override
public String toString() {
return format;
}
/**
* Gets OData format from its string representation.
*
* @param format string representation of the format.
* @return OData format.
*/
public static ODataPubFormat fromString(final String format) {
ODataPubFormat result = null;
final StringBuffer _format = new StringBuffer();
final String[] parts = format.split(";");
_format.append(parts[0]);
if (ContentType.APPLICATION_JSON.getMimeType().equals(parts[0])) {
if (parts.length > 1 && parts[1].startsWith("odata=")) {
_format.append(';').append(parts[1]);
} else {
result = ODataPubFormat.JSON;
}
}
if (result == null) {
final String candidate = _format.toString();
for (ODataPubFormat value : values()) {
if (candidate.equals(value.toString())) {
result = value;
}
}
}
if (result == null) {
throw new IllegalArgumentException("Unsupported format: " + format);
}
return result;
}
}

View File

@ -0,0 +1,76 @@
/*
* 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.odata4.client.api.format;
import org.apache.http.entity.ContentType;
/**
* Available formats for property values.
*/
public enum ODataValueFormat {
/**
* Application octet stream.
*/
STREAM(ContentType.APPLICATION_OCTET_STREAM.getMimeType()),
/**
* Plain text format.
*/
TEXT(ContentType.TEXT_PLAIN.getMimeType());
private final String format;
ODataValueFormat(final String format) {
this.format = format;
}
/**
* Gets format as a string.
*
* @return format as a string.
*/
@Override
public String toString() {
return format;
}
/**
* Gets format from its string representation.
*
* @param format string representation of the format.
* @return OData format.
*/
public static ODataValueFormat fromString(final String format) {
final String _format = format.split(";")[0];
ODataValueFormat result = null;
for (ODataValueFormat value : values()) {
if (_format.equals(value.toString())) {
result = value;
}
}
if (result == null) {
throw new IllegalArgumentException("Unsupported format: " + format);
}
return result;
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.odata4.client.api.http;
/**
* A client-side processing runtime exception.
*
* The exception is thrown during HTTP request invocation processing, to signal a failure to process the HTTP request or
* response. The exception message or nested {@link Throwable} cause SHOULD contain additional information about the
* reason of the processing failure.
*/
public class HttpClientException extends RuntimeException {
private static final long serialVersionUID = -4232431597816056514L;
/**
* Constructs a new client-side runtime exception with the specified cause and a detail message of
* {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of
* {@code cause}). This constructor is useful for runtime exceptions that are little more than wrappers for other
* throwables.
*
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null}
* value is permitted, and indicates that the cause is nonexistent or unknown.)
*/
public HttpClientException(final Throwable cause) {
super(cause);
}
/**
* Constructs a new client-side runtime exception with the specified detail message and cause.
* <br/>
* Note that the detail message associated with {@code cause} is <i>not</i>
* automatically incorporated in this runtime exception's detail message.
*
* @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null}
* value is permitted, and indicates that the cause is nonexistent or unknown.)
*/
public HttpClientException(final String message, final Throwable cause) {
super(message, cause);
}
/**
* Constructs a new client-side runtime exception with the specified detail message. The cause is not initialized, and
* may subsequently be initialized by a call to {@link #initCause}.
*
* @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
*/
public HttpClientException(final String message) {
super(message);
}
}

View File

@ -0,0 +1,30 @@
/*
* 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.odata4.client.api.http;
import java.net.URI;
import org.apache.http.client.HttpClient;
/**
* Interface used by ODataRequest implementations to instantiate HttpClient.
*/
public interface HttpClientFactory {
HttpClient createHttpClient(HttpMethod method, URI uri);
}

View File

@ -0,0 +1,33 @@
/*
* 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.odata4.client.api.http;
/**
* Supported HTTP methods.
*/
public enum HttpMethod {
GET,
POST,
PUT,
PATCH,
MERGE,
DELETE;
}

View File

@ -0,0 +1,30 @@
/*
* 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.odata4.client.api.http;
import java.net.URI;
import org.apache.http.client.methods.HttpUriRequest;
/**
* Interface used by ODataRequest implementations to create the HttpUriRequest.
*/
public interface HttpUriRequestFactory {
HttpUriRequest createHttpUriRequest(HttpMethod method, URI uri);
}

View File

@ -0,0 +1,36 @@
/*
* 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.odata4.client.api.http;
import org.apache.http.HttpStatus;
/**
* Exception to be thrown when trying to read content with HTTP status 204.
*/
public class NoContentException extends HttpClientException {
private static final long serialVersionUID = 7947066635285809192L;
/**
* Constructs a new client-side runtime exception, with fixed message.
*/
public NoContentException() {
super("No content found when HTTP status is " + HttpStatus.SC_NO_CONTENT);
}
}

View File

@ -46,6 +46,20 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
@ -58,6 +72,19 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>aalto-xml</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>

View File

@ -0,0 +1,209 @@
/*
* 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.odata4.client.core;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.olingo.odata4.client.api.Configuration;
import org.apache.olingo.odata4.client.api.http.HttpClientFactory;
import org.apache.olingo.odata4.client.api.http.HttpUriRequestFactory;
import org.apache.olingo.odata4.client.api.format.ODataFormat;
import org.apache.olingo.odata4.client.api.format.ODataMediaFormat;
import org.apache.olingo.odata4.client.api.format.ODataPubFormat;
import org.apache.olingo.odata4.client.api.format.ODataValueFormat;
import org.apache.olingo.odata4.client.core.http.DefaultHttpClientFactory;
import org.apache.olingo.odata4.client.core.http.DefaultHttpUriRequestFactory;
public abstract class AbstractConfiguration implements Configuration {
private static final String DEFAULT_PUB_FORMAT = "pubFormat";
private static final String DEFAULT_VALUE_FORMAT = "valueFormat";
private static final String DEFAULT_MEDIA_FORMAT = "valueFormat";
private static final String HTTP_CLIENT_FACTORY = "httpClientFactory";
private static final String HTTP_URI_REQUEST_FACTORY = "httpUriRequestFactory";
private static final String USE_XHTTP_METHOD = "useHTTPMethod";
private static final String KEY_AS_SEGMENT = "keyAsSegment";
private static final String GZIP_COMPRESSION = "gzipCompression";
private static final String CHUNKING = "chunking";
private final Map<String, Object> CONF = new HashMap<String, Object>();
private transient ExecutorService executor = Executors.newFixedThreadPool(10);
/**
* Gets given configuration property.
*
* @param key key value of the property to be retrieved.
* @param defaultValue default value to be used in case of the given key doesn't exist.
* @return property value if exists; default value if does not exist.
*/
private Object getProperty(final String key, final Object defaultValue) {
return CONF.containsKey(key) ? CONF.get(key) : defaultValue;
}
/**
* Sets new configuration property.
*
* @param key configuration property key.
* @param value configuration property value.
* @return given value.
*/
private Object setProperty(final String key, final Object value) {
return CONF.put(key, value);
}
@Override
public ODataPubFormat getDefaultPubFormat() {
return ODataPubFormat.valueOf(
getProperty(DEFAULT_PUB_FORMAT, ODataPubFormat.JSON_FULL_METADATA.name()).toString());
}
@Override
public void setDefaultPubFormat(final ODataPubFormat format) {
setProperty(DEFAULT_PUB_FORMAT, format.name());
}
@Override
public ODataFormat getDefaultFormat() {
ODataFormat format;
switch (getDefaultPubFormat()) {
case ATOM:
format = ODataFormat.XML;
break;
case JSON_FULL_METADATA:
format = ODataFormat.JSON_FULL_METADATA;
break;
case JSON_NO_METADATA:
format = ODataFormat.JSON_NO_METADATA;
break;
case JSON:
default:
format = ODataFormat.JSON;
}
return format;
}
@Override
public ODataValueFormat getDefaultValueFormat() {
return ODataValueFormat.valueOf(
getProperty(DEFAULT_VALUE_FORMAT, ODataValueFormat.TEXT.name()).toString());
}
@Override
public void setDefaultValueFormat(final ODataValueFormat format) {
setProperty(DEFAULT_VALUE_FORMAT, format.name());
}
@Override
public ODataMediaFormat getDefaultMediaFormat() {
return ODataMediaFormat.valueOf(
getProperty(DEFAULT_VALUE_FORMAT, ODataMediaFormat.APPLICATION_OCTET_STREAM.name()).toString());
}
@Override
public void setDefaultMediaFormat(final ODataMediaFormat format) {
setProperty(DEFAULT_MEDIA_FORMAT, format.name());
}
@Override
public HttpClientFactory getHttpClientFactory() {
return (HttpClientFactory) getProperty(HTTP_CLIENT_FACTORY, new DefaultHttpClientFactory());
}
@Override
public void setHttpClientFactory(final HttpClientFactory factory) {
setProperty(HTTP_CLIENT_FACTORY, factory);
}
@Override
public HttpUriRequestFactory getHttpUriRequestFactory() {
return (HttpUriRequestFactory) getProperty(HTTP_URI_REQUEST_FACTORY, new DefaultHttpUriRequestFactory());
}
@Override
public void setHttpUriRequestFactory(final HttpUriRequestFactory factory) {
setProperty(HTTP_URI_REQUEST_FACTORY, factory);
}
@Override
public boolean isUseXHTTPMethod() {
return (Boolean) getProperty(USE_XHTTP_METHOD, false);
}
@Override
public void setUseXHTTPMethod(final boolean value) {
setProperty(USE_XHTTP_METHOD, value);
}
@Override
public boolean isKeyAsSegment() {
return (Boolean) getProperty(KEY_AS_SEGMENT, false);
}
@Override
public void setKeyAsSegment(final boolean value) {
setProperty(KEY_AS_SEGMENT, value);
}
@Override
public boolean isGzipCompression() {
return (Boolean) getProperty(GZIP_COMPRESSION, false);
}
@Override
public void setGzipCompression(final boolean value) {
setProperty(GZIP_COMPRESSION, value);
}
@Override
public boolean isUseChuncked() {
return (Boolean) getProperty(CHUNKING, true);
}
@Override
public void setUseChuncked(final boolean value) {
setProperty(CHUNKING, value);
}
@Override
public ExecutorService getExecutor() {
return executor;
}
@Override
public void setExecutor(final ExecutorService executorService) {
executor = executorService;
}
}

View File

@ -0,0 +1,37 @@
/*
* 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.odata4.client.core;
import org.apache.olingo.odata4.client.api.ODataClient;
import org.apache.olingo.odata4.client.core.data.ODataGeospatialValue;
import org.apache.olingo.odata4.client.core.data.ODataPrimitiveValue;
abstract class AbstractODataClient implements ODataClient {
private static final long serialVersionUID = 7269096702397630265L;
public ODataPrimitiveValue.Builder getPrimitiveValueBuilder() {
return new ODataPrimitiveValue.Builder(this);
}
public ODataGeospatialValue.Builder getGeospatialValueBuilder() {
return new ODataGeospatialValue.Builder(this);
}
}

View File

@ -0,0 +1,34 @@
/*
* 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.odata4.client.core;
public final class ODataClientFactory {
public static ODataV3Client getV3() {
return new ODataV3Client();
}
public static ODataV4Client getV4() {
return new ODataV4Client();
}
private ODataClientFactory() {
// empty constructory for static utility class
}
}

View File

@ -0,0 +1,138 @@
/*
* 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.odata4.client.core;
import org.apache.olingo.odata4.client.core.data.impl.v3.ODataDeserializerImpl;
import org.apache.olingo.odata4.client.core.data.impl.v3.ODataReaderImpl;
import org.apache.olingo.odata4.client.core.data.impl.v3.ODataSerializerImpl;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
public class ODataV3Client extends AbstractODataClient {
private static final long serialVersionUID = -1655712193243609209L;
private final V3Configuration configuration = new V3Configuration();
// private final V3FilterFactory filterFactory = new V3FilterFactory();
//
private final ODataDeserializerImpl deserializer = new ODataDeserializerImpl(this);
//
private final ODataSerializerImpl serializer = new ODataSerializerImpl(this);
private final ODataReaderImpl reader = new ODataReaderImpl(this);
// private final ODataWriterImpl writer = new ODataWriterImpl(this);
//
// private final ODataBinderImpl binder = new ODataBinderImpl(this);
//
// private final ODataObjectFactoryImpl objectFactory = new ODataObjectFactoryImpl(this);
//
// private final V3RetrieveRequestFactory retrieveReqFact = new V3RetrieveRequestFactory(this);
//
// private final V3CUDRequestFactory cudReqFact = new V3CUDRequestFactory(this);
//
// private final V3StreamedRequestFactory streamedReqFact = new V3StreamedRequestFactory(this);
//
// private final V3InvokeRequestFactory invokeReqFact = new V3InvokeRequestFactory(this);
//
// private final V3BatchRequestFactory batchReqFact = new V3BatchRequestFactory(this);
@Override
public ODataServiceVersion getServiceVersion() {
return ODataServiceVersion.V30;
}
// @Override
// public ODataHeaders getVersionHeaders() {
// final ODataHeaders odataHeaders = new ODataHeaders();
// odataHeaders.setHeader(ODataHeaders.HeaderName.minDataServiceVersion, ODataVersion.V3.toString());
// odataHeaders.setHeader(ODataHeaders.HeaderName.maxDataServiceVersion, ODataVersion.V3.toString());
// odataHeaders.setHeader(ODataHeaders.HeaderName.dataServiceVersion, ODataVersion.V3.toString());
// return odataHeaders;
// }
@Override
public V3Configuration getConfiguration() {
return configuration;
}
// @Override
// public V3URIBuilder getURIBuilder(final String serviceRoot) {
// return new V3URIBuilder(configuration, serviceRoot);
// }
//
// @Override
// public V3FilterFactory getFilterFactory() {
// return filterFactory;
// }
//
@Override
public ODataDeserializerImpl getDeserializer() {
return deserializer;
}
@Override
public ODataSerializerImpl getSerializer() {
return serializer;
}
@Override
public ODataReaderImpl getReader() {
return reader;
}
// @Override
// public ODataWriterImpl getWriter() {
// return writer;
// }
//
// @Override
// public ODataBinderImpl getBinder() {
// return binder;
// }
//
// @Override
// public ODataObjectFactoryImpl getObjectFactory() {
// return objectFactory;
// }
//
// @Override
// public V3RetrieveRequestFactory getRetrieveRequestFactory() {
// return retrieveReqFact;
// }
//
// @Override
// public V3CUDRequestFactory getCUDRequestFactory() {
// return cudReqFact;
// }
//
// @Override
// public V3StreamedRequestFactory getStreamedRequestFactory() {
// return streamedReqFact;
// }
//
// @Override
// public V3InvokeRequestFactory getInvokeRequestFactory() {
// return invokeReqFact;
// }
//
// @Override
// public V3BatchRequestFactory getBatchRequestFactory() {
// return batchReqFact;
// }
}

View File

@ -0,0 +1,137 @@
/*
* 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.odata4.client.core;
import org.apache.olingo.odata4.client.core.data.impl.v4.ODataDeserializerImpl;
import org.apache.olingo.odata4.client.core.data.impl.v4.ODataReaderImpl;
import org.apache.olingo.odata4.client.core.data.impl.v4.ODataSerializerImpl;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
public class ODataV4Client extends AbstractODataClient {
private static final long serialVersionUID = -6653176125573631964L;
private final V4Configuration configuration = new V4Configuration();
// private final V4FilterFactory filterFactory = new V4FilterFactory();
//
private final ODataDeserializerImpl deserializer = new ODataDeserializerImpl(this);
//
private final ODataSerializerImpl serializer = new ODataSerializerImpl(this);
private final ODataReaderImpl reader = new ODataReaderImpl(this);
// private final ODataWriterImpl writer = new ODataWriterImpl(this);
//
// private final ODataBinderImpl binder = new ODataBinderImpl(this);
//
// private final ODataObjectFactoryImpl objectFactory = new ODataObjectFactoryImpl(this);
//
// private final V4RetrieveRequestFactory retrieveReqFact = new V4RetrieveRequestFactory(this);
//
// private final V4CUDRequestFactory cudReqFact = new V4CUDRequestFactory(this);
//
// private final V4StreamedRequestFactory streamedReqFact = new V4StreamedRequestFactory(this);
//
// private final V4InvokeRequestFactory invokeReqFact = new V4InvokeRequestFactory(this);
//
// private final V4BatchRequestFactory batchReqFact = new V4BatchRequestFactory(this);
@Override
public ODataServiceVersion getServiceVersion() {
return ODataServiceVersion.V40;
}
//
// @Override
// public ODataHeaders getVersionHeaders() {
// final ODataHeaders odataHeaders = new ODataHeaders();
// odataHeaders.setHeader(ODataHeaders.HeaderName.maxDataServiceVersion, ODataVersion.V4.toString());
// odataHeaders.setHeader(ODataHeaders.HeaderName.dataServiceVersion, ODataVersion.V4.toString());
// return odataHeaders;
// }
@Override
public V4Configuration getConfiguration() {
return configuration;
}
// @Override
// public URIBuilder getURIBuilder(final String serviceRoot) {
// return new V4URIBuilder(configuration, serviceRoot);
// }
//
// @Override
// public V4FilterFactory getFilterFactory() {
// return filterFactory;
// }
@Override
public ODataDeserializerImpl getDeserializer() {
return deserializer;
}
@Override
public ODataSerializerImpl getSerializer() {
return serializer;
}
@Override
public ODataReaderImpl getReader() {
return reader;
}
// @Override
// public ODataWriterImpl getWriter() {
// return writer;
// }
//
// @Override
// public ODataBinderImpl getBinder() {
// return binder;
// }
//
// @Override
// public ODataObjectFactoryImpl getObjectFactory() {
// return objectFactory;
// }
//
// @Override
// public V4RetrieveRequestFactory getRetrieveRequestFactory() {
// return retrieveReqFact;
// }
//
// @Override
// public V4CUDRequestFactory getCUDRequestFactory() {
// return cudReqFact;
// }
//
// @Override
// public V4StreamedRequestFactory getStreamedRequestFactory() {
// return streamedReqFact;
// }
//
// @Override
// public V4InvokeRequestFactory getInvokeRequestFactory() {
// return invokeReqFact;
// }
//
// @Override
// public V4BatchRequestFactory getBatchRequestFactory() {
// return batchReqFact;
// }
}

View File

@ -0,0 +1,29 @@
/*
* 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.odata4.client.core;
public class V3Configuration extends AbstractConfiguration {
private static final long serialVersionUID = -8719958537946884777L;
protected V3Configuration() {
super();
}
}

View File

@ -0,0 +1,29 @@
/*
* 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.odata4.client.core;
public class V4Configuration extends AbstractConfiguration {
private static final long serialVersionUID = -1134213707190176857L;
protected V4Configuration() {
super();
}
}

View File

@ -0,0 +1,288 @@
/*
* 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.odata4.client.core.data;
import java.math.BigDecimal;
import java.net.URI;
import java.util.UUID;
import org.apache.olingo.odata4.client.core.data.geospatial.Geospatial;
import org.apache.olingo.odata4.client.core.data.geospatial.GeospatialCollection;
import org.apache.olingo.odata4.client.core.data.geospatial.LineString;
import org.apache.olingo.odata4.client.core.data.geospatial.MultiLineString;
import org.apache.olingo.odata4.client.core.data.geospatial.MultiPoint;
import org.apache.olingo.odata4.client.core.data.geospatial.MultiPolygon;
import org.apache.olingo.odata4.client.core.data.geospatial.Point;
import org.apache.olingo.odata4.client.core.data.geospatial.Polygon;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
/**
* Represent the primitive types of the Entity Data Model (EDM).
*
* @see http://dl.windowsazure.com/javadoc/com/microsoft/windowsazure/services/table/models/EdmType.html
* <p>
* For an overview of the available EDM primitive data types and names, see the <a
* href="http://www.odata.org/developers/protocols/overview#AbstractTypeSystem">Primitive Data Types</a> section of the
* <a href="http://www.odata.org/developers/protocols/overview">OData Protocol Overview</a>.
* </p>
* <p>
* The Abstract Type System used to define the primitive types supported by OData is defined in detail in <a
* href="http://msdn.microsoft.com/en-us/library/dd541474.aspx">[MC-CSDL] (section 2.2.1).</a>
* </p>
*/
public enum EdmSimpleType {
/**
* The absence of a value.
*/
Null(Void.class),
/**
* An array of bytes.
*/
Binary(byte[].class),
/**
* A Boolean value.
*/
Boolean(Boolean.class),
/**
* Unsigned 8-bit integer value.
*/
Byte(Integer.class),
/**
* A signed 8-bit integer value.
*/
SByte(Byte.class),
/**
* A 64-bit value expressed as Coordinated Universal Time (UTC).
*/
DateTime(new ODataServiceVersion[]{ODataServiceVersion.V30}, ODataTimestamp.class, "yyyy-MM-dd'T'HH:mm:ss"),
/**
* Date without a time-zone offset.
*/
Date(new ODataServiceVersion[]{ODataServiceVersion.V40}, ODataTimestamp.class, "yyyy-MM-dd"),
/**
* Date and time as an Offset in minutes from GMT.
*/
DateTimeOffset(ODataTimestamp.class, "yyyy-MM-dd'T'HH:mm:ss"),
/**
* The time of day with values ranging from 0:00:00.x to 23:59:59.y, where x and y depend upon the precision.
*/
Time(new ODataServiceVersion[]{ODataServiceVersion.V30}, ODataDuration.class),
/**
* The time of day with values ranging from 0:00:00.x to 23:59:59.y, where x and y depend upon the precision.
*/
TimeOfDay(new ODataServiceVersion[]{ODataServiceVersion.V40}, ODataDuration.class),
/**
* Signed duration in days, hours, minutes, and (sub)seconds.
*/
Duration(new ODataServiceVersion[]{ODataServiceVersion.V40}, ODataDuration.class),
/**
* Numeric values with fixed precision and scale.
*/
Decimal(BigDecimal.class, "#.#######################"),
/**
* A floating point number with 7 digits precision.
*/
Single(Float.class, "#.#######E0"),
/**
* A 64-bit double-precision floating point value.
*/
Double(Double.class, "#.#######################E0"),
// --- Geospatial ---
Geography(Geospatial.class),
GeographyPoint(Point.class),
GeographyLineString(LineString.class),
GeographyPolygon(Polygon.class),
GeographyMultiPoint(MultiPoint.class),
GeographyMultiLineString(MultiLineString.class),
GeographyMultiPolygon(MultiPolygon.class),
GeographyCollection(GeospatialCollection.class),
Geometry(Geospatial.class),
GeometryPoint(Point.class),
GeometryLineString(LineString.class),
GeometryPolygon(Polygon.class),
GeometryMultiPoint(MultiPoint.class),
GeometryMultiLineString(MultiLineString.class),
GeometryMultiPolygon(MultiPolygon.class),
GeometryCollection(GeospatialCollection.class),
/**
* A 128-bit globally unique identifier.
*/
Guid(UUID.class),
/**
* A 16-bit integer value.
*/
Int16(Short.class),
/**
* A 32-bit integer value.
*/
Int32(Integer.class),
/**
* A 64-bit integer value.
*/
Int64(Long.class),
/**
* A UTF-16-encoded value. String values may be up to 64 KB in size.
*/
String(String.class),
/**
* Resource stream (for media entities).
*/
Stream(URI.class);
private final Class<?> clazz;
private final String pattern;
private final ODataServiceVersion[] versions;
/**
* Constructor (all OData versions).
*
* @param clazz type.
*/
EdmSimpleType(final Class<?> clazz) {
this(ODataServiceVersion.values(), clazz, null);
}
/**
* Constructor.
*
* @param versions supported OData versions.
* @param clazz type.
*/
EdmSimpleType(final ODataServiceVersion[] versions, final Class<?> clazz) {
this(versions, clazz, null);
}
/**
* Constructor (all OData versions).
*
* @param clazz type.
* @param pattern pattern.
*/
EdmSimpleType(final Class<?> clazz, final String pattern) {
this(ODataServiceVersion.values(), clazz, pattern);
}
/**
* Constructor.
*
* @param versions supported OData versions.
* @param clazz type.
* @param pattern pattern.
*/
EdmSimpleType(final ODataServiceVersion[] versions, final Class<?> clazz, final String pattern) {
this.clazz = clazz;
this.pattern = pattern;
this.versions = versions.clone();
}
/**
* Gets pattern.
*
* @return pattern.
*/
public String pattern() {
return pattern;
}
/**
* Gets corresponding java type.
*
* @return java type.
*/
public Class<?> javaType() {
return this.clazz;
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
return namespace() + "." + name();
}
/**
* Checks if is a geospatial type.
*
* @return <tt>true</tt> if is geospatial type; <tt>false</tt> otherwise.
*/
public boolean isGeospatial() {
return name().startsWith("Geo");
}
/**
* Checks if the given type is a geospatial type.
*
* @param type type.
* @return <tt>true</tt> if is geospatial type; <tt>false</tt> otherwise.
*/
public static boolean isGeospatial(final String type) {
return type != null && type.startsWith(namespace() + ".Geo");
}
/**
* Gets <tt>EdmSimpleType</tt> from string.
*
* @param value string value type.
* @return <tt>EdmSimpleType</tt> object.
*/
public static EdmSimpleType fromValue(final String value) {
final String noNsValue = value.substring(4);
for (EdmSimpleType edmSimpleType : EdmSimpleType.values()) {
if (edmSimpleType.name().equals(noNsValue)) {
return edmSimpleType;
}
}
throw new IllegalArgumentException(value);
}
/**
* Gets <tt>EdmSimpleType</tt> from object instance.
*
* @param workingVersion OData version.
* @param obj object.
* @return <tt>EdmSimpleType</tt> object.
*/
public static EdmSimpleType fromObject(final ODataServiceVersion workingVersion, final Object obj) {
for (EdmSimpleType edmSimpleType : EdmSimpleType.values()) {
if (edmSimpleType.javaType().equals(obj.getClass())) {
return edmSimpleType == DateTimeOffset || edmSimpleType == DateTime || edmSimpleType == Date
? ((ODataTimestamp) obj).isOffset()
? DateTimeOffset : workingVersion == ODataServiceVersion.V30 ? DateTime : Date
: edmSimpleType;
}
}
throw new IllegalArgumentException(obj.getClass().getSimpleName() + " is not a simple type");
}
/**
* Gets namespace.
*
* @return namespace.
*/
public static String namespace() {
return "Edm";
}
public ODataServiceVersion[] getSupportedVersions() {
return versions.clone();
}
}

View File

@ -0,0 +1,98 @@
/*
* 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.odata4.client.core.data;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* OData collection property value.
*/
public class ODataCollectionValue extends ODataValue implements Iterable<ODataValue> {
private static final long serialVersionUID = -3665659846001987187L;
/**
* Type name;
*/
private final String typeName;
/**
* Values.
*/
private final List<ODataValue> values = new ArrayList<ODataValue>();
/**
* Constructor.
*
* @param typeName type name.
*/
public ODataCollectionValue(final String typeName) {
this.typeName = typeName;
}
/**
* Adds a value to the collection.
*
* @param value value to be added.
*/
public void add(final ODataValue value) {
if (value.isPrimitive() || value.isComplex()) {
values.add(value);
}
}
/**
* Value iterator.
*
* @return value iterator.
*/
@Override
public Iterator<ODataValue> iterator() {
return values.iterator();
}
/**
* Gets value type name.
*
* @return value type name.
*/
public String getTypeName() {
return typeName;
}
/**
* Gets collection size.
*
* @return collection size.
*/
public int size() {
return values.size();
}
/**
* Checks if collection is empty.
*
* @return 'TRUE' if empty; 'FALSE' otherwise.
*/
public boolean isEmpty() {
return values.isEmpty();
}
}

View File

@ -0,0 +1,97 @@
/*
* 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.odata4.client.core.data;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* OData complex property value.
*/
public class ODataComplexValue extends ODataValue implements Iterable<ODataProperty> {
private static final long serialVersionUID = -1878555027714020431L;
/**
* Type name.
*/
private final String typeName;
/**
* Complex type fields.
*/
private final Map<String, ODataProperty> fields = new LinkedHashMap<String, ODataProperty>();
/**
* Constructor.
*
* @param typeName type name.
*/
public ODataComplexValue(final String typeName) {
this.typeName = typeName;
}
/**
* Adds field to the complex type.
*
* @param field field to be added.
*/
public void add(final ODataProperty field) {
fields.put(field.getName(), field);
}
/**
* Gets field.
*
* @param name name of the field to be retrieved.
* @return requested field.
*/
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();
}
/**
* Gest value type name.
*
* @return value type name.
*/
public String getTypeName() {
return typeName;
}
/**
* Gets number of fields.
*
* @return number of fields.
*/
public int size() {
return fields.size();
}
}

View File

@ -0,0 +1,80 @@
/*
* 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.odata4.client.core.data;
import java.io.Serializable;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* Helper class for handling time (as duration) primitive values.
*
* @see com.msopentech.odatajclient.engine.data.metadata.edm.EdmSimpleType#TIME
* @see Duration
*/
public final class ODataDuration implements Serializable {
private static final long serialVersionUID = 778404231943967899L;
private final Duration duration;
public ODataDuration(final String input) {
try {
final DatatypeFactory dtFactory = DatatypeFactory.newInstance();
this.duration = dtFactory.newDuration(input);
} catch (DatatypeConfigurationException e) {
throw new IllegalArgumentException("Could not parse '" + input + "' as Duration", e);
}
}
public ODataDuration(final Duration duration) {
this.duration = duration;
}
public Duration getDuration() {
return duration;
}
/**
* {@inheritDoc }
*/
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
/**
* {@inheritDoc }
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
return this.duration.toString();
}
}

View File

@ -0,0 +1,488 @@
/**
* 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.odata4.client.core.data;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.olingo.odata4.client.api.Constants;
import org.apache.olingo.odata4.client.api.ODataClient;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
import org.apache.olingo.odata4.client.core.data.geospatial.Geospatial;
import org.apache.olingo.odata4.client.core.data.geospatial.GeospatialCollection;
import org.apache.olingo.odata4.client.core.data.geospatial.LineString;
import org.apache.olingo.odata4.client.core.data.geospatial.MultiLineString;
import org.apache.olingo.odata4.client.core.data.geospatial.MultiPoint;
import org.apache.olingo.odata4.client.core.data.geospatial.MultiPolygon;
import org.apache.olingo.odata4.client.core.data.geospatial.Point;
import org.apache.olingo.odata4.client.core.data.geospatial.Polygon;
import org.apache.olingo.odata4.client.core.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class ODataGeospatialValue extends ODataPrimitiveValue {
private static final long serialVersionUID = -3984105137562291082L;
/**
* Geospatial value builder.
*/
public static class Builder extends AbstractBuilder {
private final ODataGeospatialValue ogv;
/**
* Constructor.
*/
public Builder(final ODataClient client) {
super(client);
this.ogv = new ODataGeospatialValue(client);
}
/**
* Sets the given value provided as a DOM tree.
*
* @param tree value.
* @return the current builder.
*/
public Builder setTree(final Element tree) {
this.ogv.tree = tree;
return this;
}
/**
* Sets the actual object value.
*
* @param value value.
* @return the current builder.
*/
public <T extends Geospatial> Builder setValue(final T value) {
this.ogv.value = value;
return this;
}
/**
* Sets actual value type.
*
* @param type type.
* @return the current builder.
*/
public Builder setType(final EdmSimpleType type) {
isSupported(type);
if (!type.isGeospatial()) {
throw new IllegalArgumentException(
"Use " + ODataPrimitiveValue.class.getSimpleName() + " for non-geospatial types");
}
if (type == EdmSimpleType.Geography || type == EdmSimpleType.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.");
}
this.ogv.type = type;
return this;
}
/**
* Builds the geospatial value.
*
* @return <tt>ODataGeospatialValue</tt> object.
*/
public ODataGeospatialValue build() {
if (this.ogv.tree == null && this.ogv.value == null) {
throw new IllegalArgumentException("Must provide either tree or value");
}
if (this.ogv.tree != null && this.ogv.value != null) {
throw new IllegalArgumentException("Cannot provide both tree and value");
}
if (this.ogv.type == null) {
throw new IllegalArgumentException("Must provide geospatial type");
}
if (this.ogv.tree != null) {
this.ogv.value = this.ogv.parseTree(this.ogv.tree, this.ogv.type);
}
if (this.ogv.value != null) {
this.ogv.tree = this.ogv.parseGeospatial((Geospatial) this.ogv.value);
}
return this.ogv;
}
}
/**
* DOM tree.
*/
private Element tree;
/**
* Protected constructor, need to use the builder to instantiate this class.
*
* @see Builder
*/
protected ODataGeospatialValue(final ODataClient client) {
super(client);
}
private Geospatial.Dimension getDimension() {
Geospatial.Dimension dimension;
switch (this.type) {
case Geography:
case GeographyCollection:
case GeographyLineString:
case GeographyMultiLineString:
case GeographyPoint:
case GeographyMultiPoint:
case GeographyPolygon:
case GeographyMultiPolygon:
dimension = Geospatial.Dimension.GEOGRAPHY;
break;
default:
dimension = Geospatial.Dimension.GEOMETRY;
}
return dimension;
}
private List<Point> parsePoints(final NodeList posList) {
final List<Point> result = new ArrayList<Point>();
for (int i = 0; i < posList.getLength(); i++) {
final String[] pointInfo = posList.item(i).getTextContent().split(" ");
final Point point = new Point(getDimension());
point.setX(Double.valueOf(pointInfo[0]));
point.setY(Double.valueOf(pointInfo[1]));
result.add(point);
}
return result;
}
private LineString parseLineString(final Element element) {
return new LineString(getDimension(),
parsePoints(element.getElementsByTagName(Constants.ELEM_POS)));
}
private Polygon parsePolygon(final Element element) {
List<Point> extPoints = null;
final Element exterior =
(Element) element.getElementsByTagName(Constants.ELEM_POLYGON_EXTERIOR).item(0);
if (exterior != null) {
extPoints = parsePoints(
((Element) exterior.getElementsByTagName(Constants.ELEM_POLYGON_LINEARRING).item(0)).
getElementsByTagName(Constants.ELEM_POS));
}
List<Point> intPoints = null;
final Element interior =
(Element) element.getElementsByTagName(Constants.ELEM_POLYGON_INTERIOR).item(0);
if (interior != null) {
intPoints = parsePoints(
((Element) interior.getElementsByTagName(Constants.ELEM_POLYGON_LINEARRING).item(0)).
getElementsByTagName(Constants.ELEM_POS));
}
return new Polygon(getDimension(), intPoints, extPoints);
}
/**
* Parses given tree as geospatial value.
*/
private Geospatial parseTree(final Element tree, final EdmSimpleType type) {
Geospatial value;
switch (type) {
case GeographyPoint:
case GeometryPoint:
value = parsePoints(tree.getElementsByTagName(Constants.ELEM_POS)).get(0);
break;
case GeographyMultiPoint:
case GeometryMultiPoint:
final Element pMembs =
(Element) tree.getElementsByTagName(Constants.ELEM_POINTMEMBERS).item(0);
final List<Point> points = pMembs == null
? Collections.<Point>emptyList()
: parsePoints(pMembs.getElementsByTagName(Constants.ELEM_POS));
value = new MultiPoint(getDimension(), points);
break;
case GeographyLineString:
case GeometryLineString:
value = parseLineString(tree);
break;
case GeographyMultiLineString:
case GeometryMultiLineString:
final Element mlMembs =
(Element) tree.getElementsByTagName(Constants.ELEM_LINESTRINGMEMBERS).item(0);
final List<LineString> lineStrings;
if (mlMembs == null) {
lineStrings = Collections.<LineString>emptyList();
} else {
lineStrings = new ArrayList<LineString>();
final NodeList lineStringNodes = mlMembs.getElementsByTagName(Constants.ELEM_LINESTRING);
for (int i = 0; i < lineStringNodes.getLength(); i++) {
lineStrings.add(parseLineString((Element) lineStringNodes.item(i)));
}
}
value = new MultiLineString(getDimension(), lineStrings);
break;
case GeographyPolygon:
case GeometryPolygon:
value = parsePolygon(tree);
break;
case GeographyMultiPolygon:
case GeometryMultiPolygon:
final Element mpMembs =
(Element) tree.getElementsByTagName(Constants.ELEM_SURFACEMEMBERS).item(0);
final List<Polygon> polygons;
if (mpMembs == null) {
polygons = Collections.<Polygon>emptyList();
} else {
polygons = new ArrayList<Polygon>();
final NodeList polygonNodes = mpMembs.getElementsByTagName(Constants.ELEM_POLYGON);
for (int i = 0; i < polygonNodes.getLength(); i++) {
polygons.add(parsePolygon((Element) polygonNodes.item(i)));
}
}
value = new MultiPolygon(getDimension(), polygons);
break;
case GeographyCollection:
case GeometryCollection:
final Element cMembs =
(Element) tree.getElementsByTagName(Constants.ELEM_GEOMEMBERS).item(0);
final List<Geospatial> geospatials;
if (cMembs == null) {
geospatials = Collections.<Geospatial>emptyList();
} else {
geospatials = new ArrayList<Geospatial>();
for (Node geom : XMLUtils.getChildNodes(cMembs, Node.ELEMENT_NODE)) {
geospatials.add(
parseTree((Element) geom, XMLUtils.simpleTypeForNode(getDimension(), geom)));
}
}
value = new GeospatialCollection(getDimension(), geospatials);
break;
default:
value = null;
}
return value;
}
private void parsePoints(final Element parent, final Iterator<Point> itor, final boolean wrap) {
while (itor.hasNext()) {
final Point point = itor.next();
final Element pos = parent.getOwnerDocument().
createElementNS(Constants.NS_GML, Constants.ELEM_POS);
pos.appendChild(parent.getOwnerDocument().createTextNode(
Double.toString(point.getX()) + " " + point.getY()));
final Element appendable;
if (wrap) {
final Element epoint = parent.getOwnerDocument().
createElementNS(Constants.NS_GML, Constants.ELEM_POINT);
parent.appendChild(epoint);
appendable = epoint;
} else {
appendable = parent;
}
appendable.appendChild(pos);
}
}
private void parseLineStrings(final Element parent, final Iterator<LineString> itor, final boolean wrap) {
while (itor.hasNext()) {
final LineString lineString = itor.next();
final Element appendable;
if (wrap) {
final Element eLineString = parent.getOwnerDocument().
createElementNS(Constants.NS_GML, Constants.ELEM_LINESTRING);
parent.appendChild(eLineString);
appendable = eLineString;
} else {
appendable = parent;
}
parsePoints(appendable, lineString.iterator(), false);
}
}
private void parsePolygons(final Element parent, final Iterator<Polygon> itor, final boolean wrap) {
while (itor.hasNext()) {
final Polygon polygon = itor.next();
final Element appendable;
if (wrap) {
final Element ePolygon = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON);
parent.appendChild(ePolygon);
appendable = ePolygon;
} else {
appendable = parent;
}
if (!polygon.getExterior().isEmpty()) {
final Element exterior = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_EXTERIOR);
appendable.appendChild(exterior);
final Element linearRing = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_LINEARRING);
exterior.appendChild(linearRing);
parsePoints(linearRing, polygon.getExterior().iterator(), false);
}
if (!polygon.getInterior().isEmpty()) {
final Element interior = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_INTERIOR);
appendable.appendChild(interior);
final Element linearRing = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_LINEARRING);
interior.appendChild(linearRing);
parsePoints(linearRing, polygon.getInterior().iterator(), false);
}
}
}
private Element parseGeospatial(final Geospatial value) {
final DocumentBuilder builder;
try {
builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new IllegalStateException("Failure initializing Geospatial DOM tree", e);
}
final Document doc = builder.newDocument();
final Element tree;
switch (value.getEdmSimpleType()) {
case GeographyPoint:
case GeometryPoint:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_POINT);
parsePoints(tree, Collections.singleton((Point) value).iterator(), false);
break;
case GeometryMultiPoint:
case GeographyMultiPoint:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_MULTIPOINT);
final Element pMembs = doc.createElementNS(Constants.NS_GML, Constants.ELEM_POINTMEMBERS);
tree.appendChild(pMembs);
parsePoints(pMembs, ((MultiPoint) value).iterator(), true);
break;
case GeometryLineString:
case GeographyLineString:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_LINESTRING);
parseLineStrings(tree, Collections.singleton((LineString) value).iterator(), false);
break;
case GeometryMultiLineString:
case GeographyMultiLineString:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_MULTILINESTRING);
final Element mlMembs =
doc.createElementNS(Constants.NS_GML, Constants.ELEM_LINESTRINGMEMBERS);
tree.appendChild(mlMembs);
parseLineStrings(mlMembs, ((MultiLineString) value).iterator(), true);
break;
case GeographyPolygon:
case GeometryPolygon:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_POLYGON);
parsePolygons(tree, Collections.singleton(((Polygon) value)).iterator(), false);
break;
case GeographyMultiPolygon:
case GeometryMultiPolygon:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_MULTIPOLYGON);
final Element mpMembs =
doc.createElementNS(Constants.NS_GML, Constants.ELEM_SURFACEMEMBERS);
tree.appendChild(mpMembs);
parsePolygons(mpMembs, ((MultiPolygon) value).iterator(), true);
break;
case GeographyCollection:
case GeometryCollection:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_GEOCOLLECTION);
final Element gMembs =
doc.createElementNS(Constants.NS_GML, Constants.ELEM_GEOMEMBERS);
tree.appendChild(gMembs);
final Iterator<Geospatial> itor = ((GeospatialCollection) value).iterator();
while (itor.hasNext()) {
final Geospatial geospatial = itor.next();
gMembs.appendChild(doc.importNode(parseGeospatial(geospatial), true));
}
break;
default:
tree = null;
}
return tree;
}
public Element toTree() {
return this.tree;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ODataGeospatialValue other = (ODataGeospatialValue) obj;
return this.tree.isEqualNode(other.tree);
}
@Override
public String toString() {
final StringWriter writer = new StringWriter();
client.getSerializer().dom(this.tree, writer);
return writer.toString();
}
}

View File

@ -0,0 +1,30 @@
/*
* 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.odata4.client.core.data;
/**
* Marker interface for any OData domain object that can be returned by an operation invocation.
*
* @see ODataEntitySet
* @see ODataEntity
* @see ODataProperty
* @see ODataNoContent
*/
public interface ODataInvokeResult {
}

View File

@ -0,0 +1,376 @@
/*
* 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.odata4.client.core.data;
import java.math.BigDecimal;
import java.net.URI;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.UUID;
import javax.xml.datatype.Duration;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.odata4.client.api.ODataClient;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
import org.apache.olingo.odata4.client.core.data.ODataDuration;
import org.apache.olingo.odata4.client.core.data.ODataTimestamp;
import org.apache.olingo.odata4.client.core.data.ODataValue;
/**
* OData primitive property value.
*/
public class ODataPrimitiveValue extends ODataValue {
private static final long serialVersionUID = 2841837627899878223L;
protected abstract static class AbstractBuilder {
private final ODataClient client;
/**
* Constructor.
*/
public AbstractBuilder(final ODataClient client) {
this.client = client;
}
public AbstractBuilder isSupported(final EdmSimpleType type) {
if (type != null && !ArrayUtils.contains(type.getSupportedVersions(), client.getServiceVersion())) {
throw new IllegalArgumentException(String.format(
"Type %s not supported by the current OData working version", type.toString()));
}
return this;
}
}
/**
* Primitive value builder.
*/
public static class Builder extends AbstractBuilder {
private final ODataPrimitiveValue opv;
/**
* Constructor.
*/
public Builder(final ODataClient client) {
super(client);
this.opv = new ODataPrimitiveValue(client);
}
/**
* Sets the given value provided as a text.
*
* @param text value.
* @return the current builder.
*/
public Builder setText(final String text) {
this.opv.text = text;
return this;
}
/**
* Sets the actual object value.
*
* @param value value.
* @return the current builder.
*/
public Builder setValue(final Object value) {
this.opv.value = value;
return this;
}
/**
* Sets actual value type.
*
* @param type type.
* @return the current builder.
*/
public Builder setType(final EdmSimpleType type) {
isSupported(type);
if (type == EdmSimpleType.Stream) {
throw new IllegalArgumentException(String.format(
"Cannot build a primitive value for %s", EdmSimpleType.Stream.toString()));
}
this.opv.type = type;
return this;
}
/**
* Builds the primitive value.
*
* @return <code>ODataPrimitiveValue</code> object.
*/
public ODataPrimitiveValue build() {
if (this.opv.text == null && this.opv.value == null) {
throw new IllegalArgumentException("Must provide either text or value");
}
if (this.opv.text != null && this.opv.value != null) {
throw new IllegalArgumentException("Cannot provide both text and value");
}
if (this.opv.type == null) {
this.opv.type = EdmSimpleType.String;
}
if (this.opv.type.isGeospatial()) {
throw new IllegalArgumentException(
"Use " + ODataGeospatialValue.class.getSimpleName() + " for geospatial types");
}
if (this.opv.value instanceof Timestamp) {
this.opv.value = ODataTimestamp.getInstance(this.opv.type, (Timestamp) this.opv.value);
} else if (this.opv.value instanceof Date) {
this.opv.value = ODataTimestamp.getInstance(this.opv.type,
new Timestamp(((Date) this.opv.value).getTime()));
}
if (this.opv.value instanceof Duration) {
this.opv.value = new ODataDuration((Duration) this.opv.value);
}
if (this.opv.value != null && !this.opv.type.javaType().isAssignableFrom(this.opv.value.getClass())) {
throw new IllegalArgumentException("Provided value is not compatible with " + this.opv.type.toString());
}
if (this.opv.text != null) {
this.opv.parseText();
}
if (this.opv.value != null) {
this.opv.formatValue();
}
return this.opv;
}
}
protected ODataClient client;
/**
* Text value.
*/
private String text;
/**
* Actual value.
*/
protected Object value;
/**
* Value type.
*/
protected EdmSimpleType type;
/**
* Protected constructor, need to use the builder to instantiate this class.
*
* @see Builder
*/
protected ODataPrimitiveValue(final ODataClient client) {
super();
this.client = client;
}
/**
* Parses given text as object value.
*/
private void parseText() {
switch (this.type) {
case Null:
this.value = null;
break;
case Binary:
this.value = Base64.decodeBase64(this.toString());
break;
case SByte:
this.value = Byte.parseByte(this.toString());
break;
case Boolean:
this.value = Boolean.parseBoolean(this.toString());
break;
case Date:
case DateTime:
case DateTimeOffset:
this.value = ODataTimestamp.parse(this.type, this.toString());
break;
case Time:
case TimeOfDay:
this.value = new ODataDuration(this.toString());
break;
case Decimal:
this.value = new BigDecimal(this.toString());
break;
case Single:
this.value = Float.parseFloat(this.toString());
break;
case Double:
this.value = Double.parseDouble(this.toString());
break;
case Guid:
this.value = UUID.fromString(this.toString());
break;
case Int16:
this.value = Short.parseShort(this.toString());
break;
case Byte:
case Int32:
this.value = Integer.parseInt(this.toString());
break;
case Int64:
this.value = Long.parseLong(this.toString());
break;
case Stream:
this.value = URI.create(this.toString());
break;
case String:
this.value = this.toString();
break;
default:
}
}
/**
* Format given value as text.
*/
private void formatValue() {
switch (this.type) {
case Null:
this.text = StringUtils.EMPTY;
break;
case Binary:
this.text = Base64.encodeBase64String(this.<byte[]>toCastValue());
break;
case SByte:
this.text = this.<Byte>toCastValue().toString();
break;
case Boolean:
this.text = this.<Boolean>toCastValue().toString();
break;
case Date:
case DateTime:
case DateTimeOffset:
this.text = this.<ODataTimestamp>toCastValue().toString();
break;
case Time:
case TimeOfDay:
this.text = this.<ODataDuration>toCastValue().toString();
break;
case Decimal:
this.text = new DecimalFormat(this.type.pattern()).format(this.<BigDecimal>toCastValue());
break;
case Single:
this.text = new DecimalFormat(this.type.pattern()).format(this.<Float>toCastValue());
break;
case Double:
this.text = new DecimalFormat(this.type.pattern()).format(this.<Double>toCastValue());
break;
case Guid:
this.text = this.<UUID>toCastValue().toString();
break;
case Int16:
this.text = this.<Short>toCastValue().toString();
break;
case Byte:
case Int32:
this.text = this.<Integer>toCastValue().toString();
break;
case Int64:
this.text = this.<Long>toCastValue().toString();
break;
case Stream:
this.text = this.<URI>toCastValue().toASCIIString();
break;
case String:
this.text = this.<String>toCastValue();
break;
default:
}
}
/**
* Gets type name.
*
* @return type name.
*/
public String getTypeName() {
return type.toString();
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
return this.text;
}
/**
* Gets actual primitive value.
*
* @return
*/
public Object toValue() {
return this.value;
}
/**
* Casts primitive value.
*
* @param <T> cast.
* @return casted value.
*/
@SuppressWarnings("unchecked")
public <T> T toCastValue() {
return (T) type.javaType().cast(toValue());
}
}

View File

@ -0,0 +1,192 @@
/*
* 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.odata4.client.core.data;
import java.io.Serializable;
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;
/**
* OData entity property.
*/
public class ODataProperty implements Serializable, ODataInvokeResult {
/**
* Property type.
*/
public enum PropertyType {
/**
* Primitive.
*/
PRIMITIVE,
/**
* Collection
*/
COLLECTION,
/**
* Complex.
*/
COMPLEX,
/**
* Empty type (possibly, no type information could be retrieved).
*/
EMPTY
}
private static final long serialVersionUID = 926939448778950450L;
/**
* Property name.
*/
private final String name;
/**
* Property value.
*/
private ODataValue value;
/**
* Constructor.
*
* @param name property name.
* @param value property value.
*/
ODataProperty(final String name, final ODataValue value) {
this.name = name;
this.value = value;
}
/**
* Returns property name.
*
* @return property name.
*/
public String getName() {
return name;
}
/**
* Returns property value.
*
* @return property value.
*/
public ODataValue getValue() {
return value;
}
/**
* Updates property value.
*
* @param value property value that replaces current.
*/
public void setValue(final ODataValue value) {
this.value = value;
}
/**
* Checks if has null value.
*
* @return 'TRUE' if has null value; 'FALSE' otherwise.
*/
public boolean hasNullValue() {
return this.value == null;
}
/**
* Checks if has primitive value.
*
* @return 'TRUE' if has primitive value; 'FALSE' otherwise.
*/
public boolean hasPrimitiveValue() {
return !hasNullValue() && this.value.isPrimitive();
}
/**
* Gets primitive value.
*
* @return primitive value if exists; null otherwise.
*/
public ODataPrimitiveValue getPrimitiveValue() {
return hasPrimitiveValue() ? this.value.asPrimitive() : null;
}
/**
* Checks if has complex value.
*
* @return 'TRUE' if has complex value; 'FALSE' otherwise.
*/
public boolean hasComplexValue() {
return !hasNullValue() && this.value.isComplex();
}
/**
* Gets complex value.
*
* @return complex value if exists; null otherwise.
*/
public ODataComplexValue getComplexValue() {
return hasComplexValue() ? this.value.asComplex() : null;
}
/**
* Checks if has collection value.
*
* @return 'TRUE' if has collection value; 'FALSE' otherwise.
*/
public boolean hasCollectionValue() {
return !hasNullValue() && this.value.isCollection();
}
/**
* Gets collection value.
*
* @return collection value if exists; null otherwise.
*/
public ODataCollectionValue getCollectionValue() {
return hasCollectionValue() ? this.value.asCollection() : null;
}
/**
* {@inheritDoc }
*/
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
/**
* {@inheritDoc }
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}

View File

@ -0,0 +1,141 @@
/*
* 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.odata4.client.core.data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* Helper class for handling datetime and datetime-offset primitive values.
*
* @see com.msopentech.odatajclient.engine.data.metadata.edm.EdmSimpleType#DATE_TIME
* @see com.msopentech.odatajclient.engine.data.metadata.edm.EdmSimpleType#DATE_TIME_OFFSET
*/
public final class ODataTimestamp implements Serializable {
private static final long serialVersionUID = 4053990618660356004L;
private final SimpleDateFormat sdf;
private final Timestamp timestamp;
private String timezone;
private final boolean offset;
public static ODataTimestamp getInstance(final EdmSimpleType type, final Timestamp timestamp) {
return new ODataTimestamp(new SimpleDateFormat(type.pattern()),
new Date(timestamp.getTime()), timestamp.getNanos(), type == EdmSimpleType.DateTimeOffset);
}
public static ODataTimestamp parse(final EdmSimpleType type, final String input) {
final ODataTimestamp instance;
final String[] dateParts = input.split("\\.");
final SimpleDateFormat sdf = new SimpleDateFormat(type.pattern());
final boolean isOffset = type == EdmSimpleType.DateTimeOffset;
try {
final Date date = sdf.parse(dateParts[0]);
if (dateParts.length > 1) {
int idx = dateParts[1].indexOf('+');
if (idx == -1) {
idx = dateParts[1].indexOf('-');
}
if (idx == -1) {
instance = new ODataTimestamp(sdf, date, Integer.parseInt(dateParts[1]), isOffset);
} else {
instance = new ODataTimestamp(sdf, date,
Integer.parseInt(dateParts[1].substring(0, idx)), dateParts[1].substring(idx), isOffset);
}
} else {
instance = new ODataTimestamp(sdf, date, isOffset);
}
} catch (Exception e) {
throw new IllegalArgumentException("Cannot parse " + type.pattern(), e);
}
return instance;
}
private ODataTimestamp(final SimpleDateFormat sdf, final Date date, final boolean offset) {
this.sdf = sdf;
this.timestamp = new Timestamp(date.getTime());
this.offset = offset;
}
private ODataTimestamp(final SimpleDateFormat sdf, final Date date, final int nanos, final boolean offset) {
this(sdf, date, offset);
this.timestamp.setNanos(nanos);
}
private ODataTimestamp(
final SimpleDateFormat sdf, final Date date, final int nanos, final String timezone, final boolean offset) {
this(sdf, date, nanos, offset);
this.timezone = timezone;
}
public Timestamp getTimestamp() {
return timestamp;
}
public String getTimezone() {
return timezone;
}
public boolean isOffset() {
return offset;
}
/**
* {@inheritDoc }
*/
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj, "sdf");
}
/**
* {@inheritDoc }
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this, "sdf");
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
final StringBuilder formatted = new StringBuilder().append(sdf.format(timestamp));
if (timestamp.getNanos() > 0) {
formatted.append('.').append(String.valueOf(timestamp.getNanos()));
}
if (StringUtils.isNotBlank(timezone)) {
formatted.append(timezone);
}
return formatted.toString();
}
}

View File

@ -0,0 +1,111 @@
/*
* 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.odata4.client.core.data;
import java.io.Serializable;
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;
/**
* Abstract representation of an OData entity property value.
*/
public abstract class ODataValue implements Serializable {
private static final long serialVersionUID = 7445422004232581877L;
/**
* Check is is a primitive value.
*
* @return 'TRUE' if primitive; 'FALSE' otherwise.
*/
public boolean isPrimitive() {
return (this instanceof ODataPrimitiveValue);
}
/**
* Casts to primitive value.
*
* @return primitive value.
*/
public ODataPrimitiveValue asPrimitive() {
return isPrimitive() ? (ODataPrimitiveValue) this : null;
}
/**
* Check is is a complex value.
*
* @return 'TRUE' if complex; 'FALSE' otherwise.
*/
public boolean isComplex() {
return (this instanceof ODataComplexValue);
}
/**
* Casts to complex value.
*
* @return complex value.
*/
public ODataComplexValue asComplex() {
return isComplex() ? (ODataComplexValue) this : null;
}
/**
* Check is is a collection value.
*
* @return 'TRUE' if collection; 'FALSE' otherwise.
*/
public boolean isCollection() {
return (this instanceof ODataCollectionValue);
}
/**
* Casts to collection value.
*
* @return collection value.
*/
public ODataCollectionValue asCollection() {
return isCollection() ? (ODataCollectionValue) this : null;
}
/**
* {@inheritDoc }
*/
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
/**
* {@inheritDoc }
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}

View File

@ -0,0 +1,75 @@
/*
* 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.odata4.client.core.data.geospatial;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Abstract base class for all Geometries that are composed out of other geospatial elements.
*/
public abstract class ComposedGeospatial<T extends Geospatial> extends Geospatial implements Iterable<T> {
private static final long serialVersionUID = 8796254901098541307L;
protected final List<T> geospatials;
/**
* Constructor.
*
* @param dimension dimension.
* @param type type.
* @param geospatials geospatials info.
*/
protected ComposedGeospatial(final Dimension dimension, final Type type, final List<T> geospatials) {
super(dimension, type);
this.geospatials = new ArrayList<T>();
if (geospatials != null) {
this.geospatials.addAll(geospatials);
}
}
/**
* {@inheritDoc }
*/
@Override
public Iterator<T> iterator() {
return this.geospatials.iterator();
}
/**
* Checks if is empty.
*
* @return 'TRUE' if is empty; 'FALSE' otherwise.
*/
public boolean isEmpty() {
return geospatials.isEmpty();
}
/**
* {@inheritDoc }
*/
@Override
public void setSrid(final Integer srid) {
for (Geospatial geospatial : this.geospatials) {
geospatial.setSrid(srid);
}
}
}

View File

@ -0,0 +1,156 @@
/*
* 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.odata4.client.core.data.geospatial;
import java.io.Serializable;
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.odata4.client.core.data.EdmSimpleType;
/**
* Base class for all geospatial info.
*/
public abstract class Geospatial implements Serializable {
public enum Dimension {
GEOMETRY,
GEOGRAPHY;
}
public enum Type {
/**
* The OGIS geometry type number for points.
*/
POINT,
/**
* The OGIS geometry type number for lines.
*/
LINESTRING,
/**
* The OGIS geometry type number for polygons.
*/
POLYGON,
/**
* The OGIS geometry type number for aggregate points.
*/
MULTIPOINT,
/**
* The OGIS geometry type number for aggregate lines.
*/
MULTILINESTRING,
/**
* The OGIS geometry type number for aggregate polygons.
*/
MULTIPOLYGON,
/**
* The OGIS geometry type number for feature collections.
*/
GEOSPATIALCOLLECTION;
}
protected final Dimension dimension;
protected final Type type;
/**
* Null value means it is expected to vary per instance.
*/
protected Integer srid;
/**
* Constructor.
*
* @param dimension dimension.
* @param type type.
*/
protected Geospatial(final Dimension dimension, final Type type) {
this.dimension = dimension;
this.type = type;
}
/**
* Gets dimension.
*
* @return dimension.
* @see Dimension
*/
public Dimension getDimension() {
return dimension;
}
/**
* Gets type.
*
* @return type.
* @see Type
*/
public Type getType() {
return type;
}
/**
* Gets s-rid.
*
* @return s-rid.
*/
public Integer getSrid() {
return srid;
}
/**
* Sets s-rid.
*
* @param srid s-rid.
*/
public void setSrid(final Integer srid) {
this.srid = srid;
}
public abstract EdmSimpleType getEdmSimpleType();
/**
* {@inheritDoc }
*/
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
/**
* {@inheritDoc }
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.odata4.client.core.data.geospatial;
import java.util.List;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
/**
* Wrapper for a collection of geospatials info.
*/
public class GeospatialCollection extends ComposedGeospatial<Geospatial> {
private static final long serialVersionUID = -9181547636133878977L;
/**
* Constructor.
*
* @param dimension dimension.
* @param geospatials geospatials info.
*/
public GeospatialCollection(final Dimension dimension, final List<Geospatial> geospatials) {
super(dimension, Type.GEOSPATIALCOLLECTION, geospatials);
}
@Override
public EdmSimpleType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? EdmSimpleType.GeographyCollection
: EdmSimpleType.GeometryCollection;
}
}

View File

@ -0,0 +1,38 @@
/*
* 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.odata4.client.core.data.geospatial;
import java.util.List;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
public class LineString extends ComposedGeospatial<Point> {
private static final long serialVersionUID = 3207958185407535907L;
public LineString(final Dimension dimension, final List<Point> points) {
super(dimension, Type.LINESTRING, points);
}
@Override
public EdmSimpleType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? EdmSimpleType.GeographyLineString
: EdmSimpleType.GeometryLineString;
}
}

View File

@ -0,0 +1,38 @@
/*
* 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.odata4.client.core.data.geospatial;
import java.util.List;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
public class MultiLineString extends ComposedGeospatial<LineString> {
private static final long serialVersionUID = -5042414471218124125L;
public MultiLineString(final Dimension dimension, final List<LineString> lineStrings) {
super(dimension, Type.MULTILINESTRING, lineStrings);
}
@Override
public EdmSimpleType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? EdmSimpleType.GeographyMultiLineString
: EdmSimpleType.GeometryMultiLineString;
}
}

View File

@ -0,0 +1,38 @@
/*
* 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.odata4.client.core.data.geospatial;
import java.util.List;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
public class MultiPoint extends ComposedGeospatial<Point> {
private static final long serialVersionUID = 4951011255142116129L;
public MultiPoint(final Dimension dimension, final List<Point> points) {
super(dimension, Type.MULTIPOINT, points);
}
@Override
public EdmSimpleType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? EdmSimpleType.GeographyMultiPoint
: EdmSimpleType.GeometryMultiPoint;
}
}

View File

@ -0,0 +1,38 @@
/*
* 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.odata4.client.core.data.geospatial;
import java.util.List;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
public class MultiPolygon extends ComposedGeospatial<Polygon> {
private static final long serialVersionUID = -160184788048512883L;
public MultiPolygon(final Dimension dimension, final List<Polygon> polygons) {
super(dimension, Type.MULTIPOLYGON, polygons);
}
@Override
public EdmSimpleType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? EdmSimpleType.GeographyMultiPolygon
: EdmSimpleType.GeometryMultiPolygon;
}
}

View File

@ -0,0 +1,77 @@
/*
* 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.odata4.client.core.data.geospatial;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
public class Point extends Geospatial {
private static final long serialVersionUID = 4917380107331557828L;
/**
* The X coordinate of the point. In most long/lat systems, this is the longitude.
*/
private double x;
/**
* The Y coordinate of the point. In most long/lat systems, this is the latitude.
*/
private double y;
/**
* The Z coordinate of the point. In most long/lat systems, this is a radius from the center of the earth, or the
* height / elevation over the ground.
*/
private double z;
public Point(final Dimension dimension) {
super(dimension, Type.POINT);
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
@Override
public EdmSimpleType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? EdmSimpleType.GeographyPoint
: EdmSimpleType.GeometryPoint;
}
}

View File

@ -0,0 +1,72 @@
/*
* 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.odata4.client.core.data.geospatial;
import java.util.List;
import org.apache.olingo.odata4.client.core.data.EdmSimpleType;
/**
* Polygon.
*/
public class Polygon extends Geospatial {
private static final long serialVersionUID = 7797602503445391678L;
final ComposedGeospatial<Point> interior;
final ComposedGeospatial<Point> exterior;
/**
* Constructor.
*
* @param dimension dimension.
* @param interior interior points.
* @param exterior exterior points.
*/
public Polygon(final Dimension dimension, final List<Point> interior, final List<Point> exterior) {
super(dimension, Type.POLYGON);
this.interior = new MultiPoint(dimension, interior);
this.exterior = new MultiPoint(dimension, exterior);
}
/**
* Gest interior points.
*
* @return interior points.
*/
public ComposedGeospatial<Point> getInterior() {
return interior;
}
/**
* Gets exterior points.
*
* @return exterior points.I
*/
public ComposedGeospatial<Point> getExterior() {
return exterior;
}
@Override
public EdmSimpleType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? EdmSimpleType.GeographyPolygon
: EdmSimpleType.GeometryPolygon;
}
}

View File

@ -0,0 +1,69 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
import java.io.IOException;
import org.apache.olingo.odata4.client.api.ODataClient;
import org.apache.olingo.odata4.client.core.edm.v4.ReturnTypeImpl;
import org.apache.olingo.odata4.client.core.edm.v4.annotation.ConstExprConstruct;
public abstract class AbstractEdmDeserializer<T> extends JsonDeserializer<T> {
protected ODataClient client;
protected boolean isAnnotationConstExprConstruct(final JsonParser jp) throws IOException {
return ConstExprConstruct.Type.fromString(jp.getCurrentName()) != null;
}
protected ConstExprConstruct parseAnnotationConstExprConstruct(final JsonParser jp) throws IOException {
final ConstExprConstruct constExpr = new ConstExprConstruct();
constExpr.setType(ConstExprConstruct.Type.fromString(jp.getCurrentName()));
constExpr.setValue(jp.nextTextValue());
return constExpr;
}
protected ReturnTypeImpl parseReturnType(final JsonParser jp, final String elementName) throws IOException {
ReturnTypeImpl returnType;
if (elementName.equals(((FromXmlParser) jp).getStaxReader().getLocalName())) {
returnType = new ReturnTypeImpl();
returnType.setType(jp.nextTextValue());
} else {
jp.nextToken();
returnType = jp.getCodec().readValue(jp, ReturnTypeImpl.class);
}
return returnType;
}
protected abstract T doDeserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException;
@Override
public T deserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException, JsonProcessingException {
client = (ODataClient) ctxt.findInjectableValue(ODataClient.class.getName(), null, null);
return doDeserialize(jp, ctxt);
}
}

View File

@ -0,0 +1,83 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.aalto.stax.InputFactoryImpl;
import com.fasterxml.aalto.stax.OutputFactoryImpl;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.IOException;
import org.apache.olingo.odata4.client.api.ODataClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
abstract class AbstractJacksonTool {
protected static final Logger LOG = LoggerFactory.getLogger(AbstractJacksonTool.class);
protected final ODataClient client;
protected AbstractJacksonTool(final ODataClient client) {
this.client = client;
}
protected ObjectMapper getObjectMapper() {
final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setInjectableValues(new InjectableValues.Std().addValue(ODataClient.class, client));
mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
mapper.getSerializationConfig().withAttribute(ODataClient.class, client),
mapper.getSerializerFactory()));
return mapper;
}
protected XmlMapper getXmlMapper() {
final XmlMapper xmlMapper = new XmlMapper(
new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
xmlMapper.setInjectableValues(new InjectableValues.Std().addValue(ODataClient.class, client));
xmlMapper.addHandler(new DeserializationProblemHandler() {
@Override
public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser jp,
final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName)
throws IOException, JsonProcessingException {
// skip any unknown property
LOG.warn("Skipping unknown property {}", propertyName);
ctxt.getParser().skipChildren();
return true;
}
});
return xmlMapper;
}
}

View File

@ -0,0 +1,177 @@
/*
* 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.odata4.client.core.data.impl;
import java.io.InputStream;
import org.apache.olingo.odata4.client.api.ODataClient;
import org.apache.olingo.odata4.client.api.data.ODataDeserializer;
import org.apache.olingo.odata4.client.core.utils.XMLUtils;
import org.w3c.dom.Element;
public abstract class AbstractODataDeserializer extends AbstractJacksonTool implements ODataDeserializer {
private static final long serialVersionUID = -4244158979195609909L;
// private final AtomDeserializer atomDeserializer;
public AbstractODataDeserializer(final ODataClient client) {
super(client);
// this.atomDeserializer = new AtomDeserializer(client);
}
// @Override
// @SuppressWarnings("unchecked")
// public <T extends Feed> T toFeed(final InputStream input, final Class<T> reference) {
// T entry;
//
// if (AtomFeed.class.equals(reference)) {
// entry = (T) toAtomFeed(input);
// } else {
// entry = (T) toJSONFeed(input);
// }
//
// return entry;
// }
//
// @Override
// @SuppressWarnings("unchecked")
// public <T extends Entry> T toEntry(final InputStream input, final Class<T> reference) {
// T entry;
//
// if (AtomEntry.class.equals(reference)) {
// entry = (T) toAtomEntry(input);
//
// } else {
// entry = (T) toJSONEntry(input);
// }
//
// return entry;
// }
//
// @Override
// public Element toPropertyDOM(final InputStream input, final ODataFormat format) {
// return format == ODataFormat.XML
// ? toPropertyDOMFromXML(input)
// : toPropertyDOMFromJSON(input);
// }
//
// @Override
// public LinkCollection toLinkCollection(final InputStream input, final ODataFormat format) {
// return format == ODataFormat.XML
// ? toLinkCollectionFromXML(input)
// : toLinkCollectionFromJSON(input);
// }
//
// @Override
// public ODataError toODataError(final InputStream input, final boolean isXML) {
// return isXML
// ? toODataErrorFromXML(input)
// : toODataErrorFromJSON(input);
// }
//
@Override
public Element toDOM(final InputStream input) {
return XMLUtils.PARSER.deserialize(input);
}
//
// /*
// * ------------------ Protected methods ------------------
// */
// protected AtomFeed toAtomFeed(final InputStream input) {
// try {
// return atomDeserializer.feed(toDOM(input));
// } catch (Exception e) {
// throw new IllegalArgumentException("While deserializing Atom feed", e);
// }
// }
//
// protected AtomEntry toAtomEntry(final InputStream input) {
// try {
// return atomDeserializer.entry(toDOM(input));
// } catch (Exception e) {
// throw new IllegalArgumentException("While deserializing Atom entry", e);
// }
// }
//
// protected JSONFeed toJSONFeed(final InputStream input) {
// try {
// return getObjectMapper().readValue(input, JSONFeed.class);
// } catch (IOException e) {
// throw new IllegalArgumentException("While deserializing JSON feed", e);
// }
// }
//
// protected abstract AbstractJSONEntry toJSONEntry(final InputStream input);
//
// protected Element toPropertyDOMFromXML(final InputStream input) {
// return toDOM(input);
// }
//
// protected Element toPropertyDOMFromJSON(final InputStream input) {
// try {
// return getObjectMapper().readValue(input, JSONProperty.class).getContent();
// } catch (IOException e) {
// throw new IllegalArgumentException("While deserializing JSON property", e);
// }
// }
//
// protected XMLLinkCollection toLinkCollectionFromXML(final InputStream input) {
// final Element root = toDOM(input);
//
// final NodeList uris = root.getOwnerDocument().getElementsByTagName(ODataConstants.ELEM_URI);
//
// final List<URI> links = new ArrayList<URI>();
// for (int i = 0; i < uris.getLength(); i++) {
// links.add(URI.create(uris.item(i).getTextContent()));
// }
//
// final NodeList next = root.getElementsByTagName(ODataConstants.NEXT_LINK_REL);
// final XMLLinkCollection linkCollection = next.getLength() > 0
// ? new XMLLinkCollection(URI.create(next.item(0).getTextContent()))
// : new XMLLinkCollection();
// linkCollection.setLinks(links);
//
// return linkCollection;
// }
//
// protected JSONLinkCollection toLinkCollectionFromJSON(final InputStream input) {
// try {
// return getObjectMapper().readValue(input, JSONLinkCollection.class);
// } catch (IOException e) {
// throw new IllegalArgumentException("While deserializing JSON $links", e);
// }
// }
//
// protected XMLODataError toODataErrorFromXML(final InputStream input) {
// try {
// final XmlMapper xmlMapper = new XmlMapper(
// new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
// return xmlMapper.readValue(input, XMLODataError.class);
// } catch (Exception e) {
// throw new IllegalArgumentException("While deserializing XML error", e);
// }
// }
//
// protected JSONODataError toODataErrorFromJSON(final InputStream input) {
// try {
// return getObjectMapper().readValue(input, JSONODataErrorBundle.class).getError();
// } catch (IOException e) {
// throw new IllegalArgumentException("While deserializing JSON error", e);
// }
// }
}

View File

@ -0,0 +1,138 @@
/*
* 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.odata4.client.core.data.impl;
import org.apache.olingo.odata4.client.api.ODataClient;
import org.apache.olingo.odata4.client.api.data.ODataReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractODataReader implements ODataReader {
private static final long serialVersionUID = -1988865870981207079L;
/**
* Logger.
*/
protected static final Logger LOG = LoggerFactory.getLogger(AbstractODataReader.class);
protected final ODataClient client;
protected AbstractODataReader(final ODataClient client) {
this.client = client;
}
// @Override
// public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
// return client.getBinder().getODataEntitySet(
// client.getDeserializer().toFeed(input, ResourceFactory.feedClassForFormat(format)));
// }
//
// @Override
// public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
// return client.getBinder().getODataEntity(
// client.getDeserializer().toEntry(input, ResourceFactory.entryClassForFormat(format)));
// }
//
// @Override
// public ODataProperty readProperty(final InputStream input, final ODataFormat format) {
// final Element property = client.getDeserializer().toPropertyDOM(input, format);
//
// // The ODataProperty object is used either for actual entity properties and for invoke result
// // (when return type is neither an entity nor a collection of entities).
// // Such formats are mostly the same except for collections: an entity property looks like
// // <aproperty m:type="Collection(AType)">
// // <element>....</element>
// // </aproperty>
// //
// // while an invoke result with returnType="Collection(AnotherType)" looks like
// // <functionImportName>
// // <element m:type="AnotherType">...</element>
// // <functionImportName>
// //
// // The code below is meant for "normalizing" the latter into
// // <functionImportName m:type="Collection(AnotherType)">
// // <element m:type="AnotherType">...</element>
// // <functionImportName>
// final String type = property.getAttribute(ODataConstants.ATTR_M_TYPE);
// final NodeList elements = property.getElementsByTagName(ODataConstants.ELEM_ELEMENT);
// if (StringUtils.isBlank(type) && elements != null && elements.getLength() > 0) {
// final Node elementType = elements.item(0).getAttributes().getNamedItem(ODataConstants.ATTR_M_TYPE);
// if (elementType != null) {
// property.setAttribute(ODataConstants.ATTR_M_TYPE, "Collection(" + elementType.getTextContent() + ")");
// }
// }
//
// return client.getBinder().getProperty(property);
// }
//
// @Override
// public ODataLinkCollection readLinks(final InputStream input, final ODataFormat format) {
// return client.getBinder().getLinkCollection(
// client.getDeserializer().toLinkCollection(input, format));
// }
//
// @Override
// public ODataError readError(final InputStream inputStream, final boolean isXML) {
// return client.getDeserializer().toODataError(inputStream, isXML);
// }
//
// @Override
// @SuppressWarnings("unchecked")
// public <T> T read(final InputStream src, final String format, final Class<T> reference) {
// Object res;
//
// try {
// if (ODataEntitySetIterator.class.isAssignableFrom(reference)) {
// res = new ODataEntitySetIterator(client, src, ODataPubFormat.fromString(format));
// } else if (ODataEntitySet.class.isAssignableFrom(reference)) {
// res = readEntitySet(src, ODataPubFormat.fromString(format));
// } else if (ODataEntity.class.isAssignableFrom(reference)) {
// res = readEntity(src, ODataPubFormat.fromString(format));
// } else if (ODataProperty.class.isAssignableFrom(reference)) {
// res = readProperty(src, ODataFormat.fromString(format));
// } else if (ODataLinkCollection.class.isAssignableFrom(reference)) {
// res = readLinks(src, ODataFormat.fromString(format));
// } else if (ODataValue.class.isAssignableFrom(reference)) {
// res = client.getPrimitiveValueBuilder().
// setType(ODataValueFormat.fromString(format) == ODataValueFormat.TEXT
// ? EdmSimpleType.String : EdmSimpleType.Stream).
// setText(IOUtils.toString(src)).
// build();
// } else if (AbstractEdmMetadata.class.isAssignableFrom(reference)) {
// res = readMetadata(src);
// } else if (ODataServiceDocument.class.isAssignableFrom(reference)) {
// res = readServiceDocument(src, ODataFormat.fromString(format));
// } else if (ODataError.class.isAssignableFrom(reference)) {
// res = readError(src, !format.toString().contains("json"));
// } else {
// throw new IllegalArgumentException("Invalid reference type " + reference);
// }
// } catch (Exception e) {
// LOG.warn("Cast error", e);
// res = null;
// } finally {
// if (!ODataEntitySetIterator.class.isAssignableFrom(reference)) {
// IOUtils.closeQuietly(src);
// }
// }
//
// return (T) res;
// }
}

View File

@ -0,0 +1,160 @@
/*
* 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.odata4.client.core.data.impl;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import org.apache.olingo.odata4.client.api.ODataClient;
import org.apache.olingo.odata4.client.api.data.ODataSerializer;
import org.apache.olingo.odata4.client.core.utils.XMLUtils;
import org.w3c.dom.Node;
public abstract class AbstractODataSerializer extends AbstractJacksonTool implements ODataSerializer {
private static final long serialVersionUID = -357777648541325363L;
// private final AtomSerializer atomSerializer;
public AbstractODataSerializer(final ODataClient client) {
super(client);
// this.atomSerializer = new AtomSerializer(client);
}
// @Override
// public <T extends Feed> void feed(final T obj, final OutputStream out) {
// feed(obj, new OutputStreamWriter(out));
// }
//
// @Override
// public <T extends Feed> void feed(final T obj, final Writer writer) {
// if (obj instanceof AtomFeed) {
// atom((AtomFeed) obj, writer);
// } else {
// json((JSONFeed) obj, writer);
// }
// }
//
// @Override
// public <T extends Entry> void entry(final T obj, final OutputStream out) {
// entry(obj, new OutputStreamWriter(out));
// }
//
// @Override
// public <T extends Entry> void entry(final T obj, final Writer writer) {
// if (obj instanceof AtomEntry) {
// atom((AtomEntry) obj, writer);
// } else {
// json((JSONEntry) obj, writer);
// }
// }
//
// @Override
// public void property(final Element element, final ODataFormat format, final OutputStream out) {
// property(element, format, new OutputStreamWriter(out));
// }
//
// @Override
// public void property(final Element element, final ODataFormat format, final Writer writer) {
// if (format == ODataFormat.XML) {
// dom(element, writer);
// } else {
// json(element, writer);
// }
// }
//
// @Override
// public void link(final ODataLink link, final ODataFormat format, final OutputStream out) {
// link(link, format, new OutputStreamWriter(out));
// }
//
// @Override
// public void link(final ODataLink link, final ODataFormat format, final Writer writer) {
// if (format == ODataFormat.XML) {
// xmlLink(link, writer);
// } else {
// jsonLink(link, writer);
// }
// }
//
@Override
public void dom(final Node content, final OutputStream out) {
dom(content, new OutputStreamWriter(out));
}
@Override
public void dom(final Node content, final Writer writer) {
XMLUtils.PARSER.serialize(content, writer);
}
//
// /*
// * ------------------ Protected methods ------------------
// */
// protected <T extends AbstractPayloadObject> void atom(final T obj, final Writer writer) {
// try {
// dom(atomSerializer.serialize(obj), writer);
// } catch (Exception e) {
// throw new IllegalArgumentException("While serializing Atom object", e);
// }
// }
//
// protected <T extends AbstractPayloadObject> void json(final T obj, final Writer writer) {
// try {
// getObjectMapper().writeValue(writer, obj);
// } catch (IOException e) {
// throw new IllegalArgumentException("While serializing JSON object", e);
// }
// }
//
// protected void json(final Element element, final Writer writer) {
// try {
// final JSONProperty property = new JSONProperty();
// property.setContent(element);
// getObjectMapper().writeValue(writer, property);
// } catch (IOException e) {
// throw new IllegalArgumentException("While serializing JSON property", e);
// }
// }
//
// protected void xmlLink(final ODataLink link, final Writer writer) {
// try {
// final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
// final Document doc = builder.newDocument();
// final Element uri = doc.createElementNS(
// client.getWorkingVersion().getNamespaceMap().get(ODataVersion.NS_DATASERVICES),
// ODataConstants.ELEM_URI);
// uri.appendChild(doc.createTextNode(link.getLink().toASCIIString()));
//
// dom(uri, writer);
// } catch (Exception e) {
// throw new IllegalArgumentException("While serializing XML link", e);
// }
// }
//
// protected void jsonLink(final ODataLink link, final Writer writer) {
// final ObjectMapper mapper = getObjectMapper();
// final ObjectNode uri = mapper.createObjectNode();
// uri.put(ODataConstants.JSON_URL, link.getLink().toASCIIString());
//
// try {
// mapper.writeValue(writer, uri);
// } catch (Exception e) {
// throw new IllegalArgumentException("While serializing JSON link", e);
// }
// }
}

View File

@ -0,0 +1,81 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import java.io.IOException;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.olingo.odata4.client.core.edm.AbstractComplexType;
import org.apache.olingo.odata4.client.core.edm.v4.AnnotationImpl;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
public class ComplexTypeDeserializer extends AbstractEdmDeserializer<AbstractComplexType> {
@Override
protected AbstractComplexType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException, JsonProcessingException {
final AbstractComplexType complexType = ODataServiceVersion.V30 == client.getServiceVersion()
? new org.apache.olingo.odata4.client.core.edm.v3.ComplexTypeImpl()
: new org.apache.olingo.odata4.client.core.edm.v4.ComplexTypeImpl();
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME) {
if ("Name".equals(jp.getCurrentName())) {
complexType.setName(jp.nextTextValue());
} else if ("Abstract".equals(jp.getCurrentName())) {
((org.apache.olingo.odata4.client.core.edm.v4.ComplexTypeImpl) complexType).
setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("BaseType".equals(jp.getCurrentName())) {
((org.apache.olingo.odata4.client.core.edm.v4.ComplexTypeImpl) complexType).
setBaseType(jp.nextTextValue());
} else if ("OpenType".equals(jp.getCurrentName())) {
((org.apache.olingo.odata4.client.core.edm.v4.ComplexTypeImpl) complexType).
setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("Property".equals(jp.getCurrentName())) {
jp.nextToken();
if (complexType instanceof org.apache.olingo.odata4.client.core.edm.v3.ComplexTypeImpl) {
((org.apache.olingo.odata4.client.core.edm.v3.ComplexTypeImpl) complexType).
getProperties().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v3.PropertyImpl.class));
} else {
((org.apache.olingo.odata4.client.core.edm.v4.ComplexTypeImpl) complexType).
getProperties().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v4.PropertyImpl.class));
}
} else if ("NavigationProperty".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.ComplexTypeImpl) complexType).
getNavigationProperties().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v4.NavigationPropertyImpl.class));
} else if ("Annotation".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.ComplexTypeImpl) complexType).
setAnnotation(jp.getCodec().readValue(jp, AnnotationImpl.class));
}
}
}
return complexType;
}
}

View File

@ -0,0 +1,100 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import java.io.IOException;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.olingo.odata4.client.core.edm.AbstractEntityContainer;
import org.apache.olingo.odata4.client.core.edm.v3.AssociationSetImpl;
import org.apache.olingo.odata4.client.core.edm.v4.ActionImportImpl;
import org.apache.olingo.odata4.client.core.edm.v4.AnnotationImpl;
import org.apache.olingo.odata4.client.core.edm.v4.SingletonImpl;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
@SuppressWarnings("rawtypes")
public class EntityContainerDeserializer extends AbstractEdmDeserializer<AbstractEntityContainer> {
@Override
protected AbstractEntityContainer doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException, JsonProcessingException {
final AbstractEntityContainer entityContainer = ODataServiceVersion.V30 == client.getServiceVersion()
? new org.apache.olingo.odata4.client.core.edm.v3.EntityContainerImpl()
: new org.apache.olingo.odata4.client.core.edm.v4.EntityContainerImpl();
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME) {
if ("Name".equals(jp.getCurrentName())) {
entityContainer.setName(jp.nextTextValue());
} else if ("Extends".equals(jp.getCurrentName())) {
entityContainer.setExtends(jp.nextTextValue());
} else if ("LazyLoadingEnabled".equals(jp.getCurrentName())) {
entityContainer.setLazyLoadingEnabled(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("IsDefaultEntityContainer".equals(jp.getCurrentName())) {
entityContainer.setDefaultEntityContainer(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("EntitySet".equals(jp.getCurrentName())) {
jp.nextToken();
if (entityContainer instanceof org.apache.olingo.odata4.client.core.edm.v3.EntityContainerImpl) {
((org.apache.olingo.odata4.client.core.edm.v3.EntityContainerImpl) entityContainer).
getEntitySets().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v3.EntitySetImpl.class));
} else {
((org.apache.olingo.odata4.client.core.edm.v4.EntityContainerImpl) entityContainer).
getEntitySets().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v4.EntitySetImpl.class));
}
} else if ("AssociationSet".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v3.EntityContainerImpl) entityContainer).
getAssociationSets().add(jp.getCodec().readValue(jp, AssociationSetImpl.class));
} else if ("Singleton".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.EntityContainerImpl) entityContainer).
getSingletons().add(jp.getCodec().readValue(jp, SingletonImpl.class));
} else if ("ActionImport".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.EntityContainerImpl) entityContainer).
getActionImports().add(jp.getCodec().readValue(jp, ActionImportImpl.class));
} else if ("FunctionImport".equals(jp.getCurrentName())) {
jp.nextToken();
if (entityContainer instanceof org.apache.olingo.odata4.client.core.edm.v3.EntityContainerImpl) {
((org.apache.olingo.odata4.client.core.edm.v3.EntityContainerImpl) entityContainer).
getFunctionImports().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v3.FunctionImportImpl.class));
} else {
((org.apache.olingo.odata4.client.core.edm.v4.EntityContainerImpl) entityContainer).
getFunctionImports().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v4.FunctionImportImpl.class));
}
} else if ("Annotation".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.EntityContainerImpl) entityContainer).
setAnnotation(jp.getCodec().readValue(jp, AnnotationImpl.class));
}
}
}
return entityContainer;
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import java.io.IOException;
import org.apache.olingo.odata4.client.core.edm.EntityKeyImpl;
import org.apache.olingo.odata4.client.core.edm.PropertyRefImpl;
public class EntityKeyDeserializer extends AbstractEdmDeserializer<EntityKeyImpl> {
@Override
protected EntityKeyImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException, JsonProcessingException {
final EntityKeyImpl entityKey = new EntityKeyImpl();
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME && "PropertyRef".equals(jp.getCurrentName())) {
jp.nextToken();
entityKey.getPropertyRefs().add(jp.getCodec().readValue(jp, PropertyRefImpl.class));
}
}
return entityKey;
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import java.io.IOException;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.olingo.odata4.client.core.edm.AbstractEntitySet;
import org.apache.olingo.odata4.client.core.edm.v4.AnnotationImpl;
import org.apache.olingo.odata4.client.core.edm.v4.NavigationPropertyBindingImpl;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
public class EntitySetDeserializer extends AbstractEdmDeserializer<AbstractEntitySet> {
@Override
protected AbstractEntitySet doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException, JsonProcessingException {
final AbstractEntitySet entitySet = ODataServiceVersion.V30 == client.getServiceVersion()
? new org.apache.olingo.odata4.client.core.edm.v3.EntitySetImpl()
: new org.apache.olingo.odata4.client.core.edm.v4.EntitySetImpl();
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME) {
if ("Name".equals(jp.getCurrentName())) {
entitySet.setName(jp.nextTextValue());
} else if ("EntityType".equals(jp.getCurrentName())) {
entitySet.setEntityType(jp.nextTextValue());
} else if ("IncludeInServiceDocument".equals(jp.getCurrentName())) {
((org.apache.olingo.odata4.client.core.edm.v4.EntitySetImpl) entitySet).
setIncludeInServiceDocument(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("NavigationPropertyBinding".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.EntitySetImpl) entitySet).
getNavigationPropertyBindings().add(
jp.getCodec().readValue(jp, NavigationPropertyBindingImpl.class));
} else if ("Annotation".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.EntitySetImpl) entitySet).
setAnnotation(jp.getCodec().readValue(jp, AnnotationImpl.class));
}
}
}
return entitySet;
}
}

View File

@ -0,0 +1,90 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import java.io.IOException;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.olingo.odata4.client.core.edm.AbstractEntityType;
import org.apache.olingo.odata4.client.core.edm.EntityKeyImpl;
import org.apache.olingo.odata4.client.core.edm.v4.AnnotationImpl;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
public class EntityTypeDeserializer extends AbstractEdmDeserializer<AbstractEntityType> {
@Override
protected AbstractEntityType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException, JsonProcessingException {
final AbstractEntityType entityType = ODataServiceVersion.V30 == client.getServiceVersion()
? new org.apache.olingo.odata4.client.core.edm.v3.EntityTypeImpl()
: new org.apache.olingo.odata4.client.core.edm.v4.EntityTypeImpl();
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME) {
if ("Name".equals(jp.getCurrentName())) {
entityType.setName(jp.nextTextValue());
} else if ("Abstract".equals(jp.getCurrentName())) {
entityType.setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("BaseType".equals(jp.getCurrentName())) {
entityType.setBaseType(jp.nextTextValue());
} else if ("OpenType".equals(jp.getCurrentName())) {
entityType.setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("HasStream".equals(jp.getCurrentName())) {
entityType.setHasStream(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("Key".equals(jp.getCurrentName())) {
jp.nextToken();
entityType.setKey(jp.getCodec().readValue(jp, EntityKeyImpl.class));
} else if ("Property".equals(jp.getCurrentName())) {
jp.nextToken();
if (entityType instanceof org.apache.olingo.odata4.client.core.edm.v3.EntityTypeImpl) {
((org.apache.olingo.odata4.client.core.edm.v3.EntityTypeImpl) entityType).
getProperties().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v3.PropertyImpl.class));
} else {
((org.apache.olingo.odata4.client.core.edm.v4.EntityTypeImpl) entityType).
getProperties().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v4.PropertyImpl.class));
}
} else if ("NavigationProperty".equals(jp.getCurrentName())) {
jp.nextToken();
if (entityType instanceof org.apache.olingo.odata4.client.core.edm.v3.EntityTypeImpl) {
((org.apache.olingo.odata4.client.core.edm.v3.EntityTypeImpl) entityType).
getNavigationProperties().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v3.NavigationPropertyImpl.class));
} else {
((org.apache.olingo.odata4.client.core.edm.v4.EntityTypeImpl) entityType).
getNavigationProperties().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v4.NavigationPropertyImpl.class));
}
} else if ("Annotation".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.EntityTypeImpl) entityType).
setAnnotation(jp.getCodec().readValue(jp, AnnotationImpl.class));
}
}
}
return entityType;
}
}

View File

@ -0,0 +1,71 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import java.io.IOException;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.olingo.odata4.client.core.edm.AbstractEnumType;
import org.apache.olingo.odata4.client.core.edm.v4.AnnotationImpl;
import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
public class EnumTypeDeserializer extends AbstractEdmDeserializer<AbstractEnumType> {
@Override
protected AbstractEnumType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException, JsonProcessingException {
final AbstractEnumType enumType = ODataServiceVersion.V30 == client.getServiceVersion()
? new org.apache.olingo.odata4.client.core.edm.v3.EnumTypeImpl()
: new org.apache.olingo.odata4.client.core.edm.v4.EnumTypeImpl();
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME) {
if ("Name".equals(jp.getCurrentName())) {
enumType.setName(jp.nextTextValue());
} else if ("UnderlyingType".equals(jp.getCurrentName())) {
enumType.setUnderlyingType(jp.nextTextValue());
} else if ("IsFlags".equals(jp.getCurrentName())) {
enumType.setFlags(BooleanUtils.toBoolean(jp.nextTextValue()));
} else if ("Member".equals(jp.getCurrentName())) {
jp.nextToken();
if (enumType instanceof org.apache.olingo.odata4.client.core.edm.v3.EnumTypeImpl) {
((org.apache.olingo.odata4.client.core.edm.v3.EnumTypeImpl) enumType).
getMembers().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v3.MemberImpl.class));
} else {
((org.apache.olingo.odata4.client.core.edm.v4.EnumTypeImpl) enumType).
getMembers().add(jp.getCodec().readValue(jp,
org.apache.olingo.odata4.client.core.edm.v4.MemberImpl.class));
}
} else if ("Annotation".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.odata4.client.core.edm.v4.EnumTypeImpl) enumType).
setAnnotation(jp.getCodec().readValue(jp, AnnotationImpl.class));
}
}
}
return enumType;
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.odata4.client.core.data.impl;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
class InjectableSerializerProvider extends DefaultSerializerProvider {
private static final long serialVersionUID = 3432260063063739646L;
public InjectableSerializerProvider(
final SerializerProvider src, final SerializationConfig config, final SerializerFactory factory) {
super(src, config, factory);
}
@Override
public InjectableSerializerProvider createInstance(
final SerializationConfig config, final SerializerFactory factory) {
return this;
}
}

Some files were not shown because too many files have changed in this diff Show More