You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2013/08/28 16:02:14 UTC
[26/41] delete aggregated-sources directory which was created by
accident
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/ContentType.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/ContentType.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/ContentType.java
deleted file mode 100644
index 9890607..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/ContentType.java
+++ /dev/null
@@ -1,738 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.commons;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * Internally used {@link ContentType} for OData library.
- *
- * For more details on format and content of a {@link ContentType} see
- * <code>Media Type</code> format as defined in <code>RFC 2616 chapter 3.7 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html)</code>.
- * <pre>
- * <code>
- * media-type = type "/" subtype *( ";" parameter )
- * type = token
- * subtype = token
- * </code>
- * </pre>
- *
- * Especially for <code>Accept</code> Header as defined in
- * <code>RFC 2616 chapter 14.1 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)</code>:
- * <pre>
- * <code>
- * Accept = "Accept" ":"
- * #( media-range [ accept-params ] )
- * media-range = ( "* /*"
- * | ( type "/" "*" )
- * | ( type "/" subtype )
- * ) *( ";" parameter )
- * accept-params = ";" "q" "=" qvalue *( accept-extension )
- * accept-extension = ";" token [ "=" ( token | quoted-string ) ]
- * </code>
- * </pre>
- *
- * Especially for <code>Content-Type</code> Header as defined in
- * <code>RFC 2616 chapter 14.7 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)</code>:
- * <pre>
- * <code>
- * Content-Type = "Content-Type" ":" media-type
- * </code>
- * </pre>
- *
- * Once created a {@link ContentType} is <b>IMMUTABLE</b>.
- *
- *
- */
-public class ContentType {
-
- public enum ODataFormat {
- ATOM, XML, JSON, MIME, CUSTOM
- }
-
- private static final Set<String> KNOWN_MIME_TYPES = new HashSet<String>();
- static {
- KNOWN_MIME_TYPES.add("audio");
- KNOWN_MIME_TYPES.add("image");
- KNOWN_MIME_TYPES.add("video");
- KNOWN_MIME_TYPES.add("multipart");
- KNOWN_MIME_TYPES.add("text");
- }
-
- private static final char WHITESPACE_CHAR = ' ';
- private static final String PARAMETER_SEPARATOR = ";";
- private static final String TYPE_SUBTYPE_SEPARATOR = "/";
- private static final String MEDIA_TYPE_WILDCARD = "*";
- private static final String VERBOSE = "verbose";
-
- public static final String PARAMETER_CHARSET = "charset";
- public static final String PARAMETER_ODATA = "odata";
- public static final String PARAMETER_Q = "q";
- public static final String CHARSET_UTF_8 = "utf-8";
-
- public static final ContentType WILDCARD = new ContentType(MEDIA_TYPE_WILDCARD, MEDIA_TYPE_WILDCARD);
-
- public static final ContentType APPLICATION_XML = new ContentType("application", "xml", ODataFormat.XML);
- public static final ContentType APPLICATION_XML_CS_UTF_8 = ContentType.create(APPLICATION_XML, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_ATOM_XML = new ContentType("application", "atom+xml", ODataFormat.ATOM);
- public static final ContentType APPLICATION_ATOM_XML_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_ATOM_XML_ENTRY = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap("type", "entry"));
- public static final ContentType APPLICATION_ATOM_XML_ENTRY_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML_ENTRY, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_ATOM_XML_FEED = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap("type", "feed"));
- public static final ContentType APPLICATION_ATOM_XML_FEED_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML_FEED, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_ATOM_SVC = new ContentType("application", "atomsvc+xml", ODataFormat.ATOM);
- public static final ContentType APPLICATION_ATOM_SVC_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_SVC, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_JSON = new ContentType("application", "json", ODataFormat.JSON);
- public static final ContentType APPLICATION_JSON_ODATA_VERBOSE = ContentType.create(APPLICATION_JSON, PARAMETER_ODATA, VERBOSE);
- public static final ContentType APPLICATION_JSON_CS_UTF_8 = ContentType.create(APPLICATION_JSON, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_OCTET_STREAM = new ContentType("application", "octet-stream");
- public static final ContentType TEXT_PLAIN = new ContentType("text", "plain");
- public static final ContentType TEXT_PLAIN_CS_UTF_8 = ContentType.create(TEXT_PLAIN, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType MULTIPART_MIXED = new ContentType("multipart", "mixed");
-
- private String type;
- private String subtype;
- private Map<String, String> parameters;
- private ODataFormat odataFormat;
-
- private ContentType(final String type, final String subtype) {
- this(type, subtype, ODataFormat.CUSTOM, null);
- }
-
- private ContentType(final String type, final String subtype, final ODataFormat odataFormat) {
- this(type, subtype, odataFormat, null);
- }
-
- private ContentType(final String type, final String subtype, final ODataFormat odataFormat, final Map<String, String> parameters) {
- if ((type == null || MEDIA_TYPE_WILDCARD.equals(type)) && !MEDIA_TYPE_WILDCARD.equals(subtype)) {
- throw new IllegalArgumentException("Illegal combination of WILDCARD type with NONE WILDCARD subtype.");
- }
- this.odataFormat = odataFormat;
- this.type = validateType(type);
- this.subtype = validateType(subtype);
-
- if (parameters == null) {
- this.parameters = Collections.emptyMap();
- } else {
- this.parameters = new TreeMap<String, String>(new Comparator<String>() {
- @Override
- public int compare(final String o1, final String o2) {
- return o1.compareToIgnoreCase(o2);
- }
- });
- this.parameters.putAll(parameters);
- this.parameters.remove(PARAMETER_Q);
- }
- }
-
- private String validateType(final String type) {
- if (type == null || type.isEmpty()) {
- return MEDIA_TYPE_WILDCARD;
- }
- if (type.charAt(0) == WHITESPACE_CHAR || type.charAt(type.length() - 1) == WHITESPACE_CHAR) {
- throw new IllegalArgumentException("Illegal leading/trailing whitespace found for type '" + type + "'.");
- }
- return type;
- }
-
- /**
- * Validates if given <code>format</code> is parseable and can be used as input for
- * {@link #create(String)} method.
- * @param format to be validated string
- * @return <code>true</code> if format is parseable otherwise <code>false</code>
- */
- public static boolean isParseable(final String format) {
- try {
- return ContentType.create(format) != null;
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
-
- /**
- * Creates a content type from type and subtype
- * @param type
- * @param subtype
- * @return a new <code>ContentType</code> object
- */
- public static ContentType create(final String type, final String subtype) {
- return new ContentType(type, subtype, mapToODataFormat(type, subtype), null);
- }
-
- /**
- *
- * @param type
- * @param subtype
- * @param parameters
- * @return a new <code>ContentType</code> object
- */
- public static ContentType create(final String type, final String subtype, final Map<String, String> parameters) {
- return new ContentType(type, subtype, mapToODataFormat(type, subtype), parameters);
- }
-
- /**
- *
- * @param contentType
- * @param parameterKey
- * @param parameterValue
- * @return a new <code>ContentType</code> object
- */
- public static ContentType create(final ContentType contentType, final String parameterKey, final String parameterValue) {
- ContentType ct = new ContentType(contentType.type, contentType.subtype, contentType.odataFormat, contentType.parameters);
- ct.parameters.put(parameterKey, parameterValue);
- return ct;
- }
-
- /**
- * Create a {@link ContentType} based on given input string (<code>format</code>).
- *
- * Supported format is <code>Media Type</code> format as defined in <code>RFC 2616 chapter 3.7</code>.
- * This format is used as
- * <code>HTTP Accept HEADER</code> format as defined in <code>RFC 2616 chapter 14.1</code>
- * and
- * <code>HTTP Content-Type HEADER</code> format as defined in <code>RFC 2616 chapter 14.17</code>
- *
- * @param format a string in format as defined in <code>RFC 2616 section 3.7</code>
- * @return a new <code>ContentType</code> object
- * @throws IllegalArgumentException if input string is not parseable
- */
- public static ContentType create(final String format) {
- if (format == null) {
- throw new IllegalArgumentException("Parameter format MUST NOT be NULL.");
- }
-
- // split 'types' and 'parameters'
- String[] typesAndParameters = format.split(PARAMETER_SEPARATOR, 2);
- String types = typesAndParameters[0];
- String parameters = (typesAndParameters.length > 1 ? typesAndParameters[1] : null);
- //
- Map<String, String> parametersMap = parseParameters(parameters);
- //
- if (types.contains(TYPE_SUBTYPE_SEPARATOR)) {
- String[] tokens = types.split(TYPE_SUBTYPE_SEPARATOR);
- if (tokens.length == 2) {
- return create(tokens[0], tokens[1], parametersMap);
- } else {
- throw new IllegalArgumentException("Too many '" + TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'.");
- }
- } else {
- return create(types, MEDIA_TYPE_WILDCARD, parametersMap);
- }
- }
-
- /**
- * Create a list of {@link ContentType} based on given input strings (<code>contentTypes</code>).
- *
- * Supported format is <code>Media Type</code> format as defined in <code>RFC 2616 chapter 3.7</code>.
- * This format is used as
- * <code>HTTP Accept HEADER</code> format as defined in <code>RFC 2616 chapter 14.1</code>
- * and
- * <code>HTTP Content-Type HEADER</code> format as defined in <code>RFC 2616 chapter 14.17</code>.
- * <p>
- * If one of the given strings can not be parsed an exception is thrown (hence no list is returned with the parseable strings).
- * </p>
- *
- * @param contentTypeStrings a list of strings in format as defined in <code>RFC 2616 section 3.7</code>
- * @return a list of new <code>ContentType</code> object
- * @throws IllegalArgumentException if one of the given input string is not parseable this exceptions is thrown
- */
- public static List<ContentType> create(final List<String> contentTypeStrings) {
- List<ContentType> contentTypes = new ArrayList<ContentType>(contentTypeStrings.size());
- for (String contentTypeString : contentTypeStrings) {
- contentTypes.add(create(contentTypeString));
- }
- return contentTypes;
- }
-
- /**
- * Parses the given input string (<code>format</code>) and returns created
- * {@link ContentType} if input was valid or return <code>NULL</code> if
- * input was not parseable.
- *
- * For the definition of the supported format see {@link #create(String)}.
- *
- * @param format a string in format as defined in <code>RFC 2616 section 3.7</code>
- * @return a new <code>ContentType</code> object
- */
- public static ContentType parse(final String format) {
- try {
- return ContentType.create(format);
- } catch (IllegalArgumentException e) {
- return null;
- }
- }
-
- /**
- * Map combination of type/subtype to corresponding {@link ODataFormat}.
- *
- * @param type type which is used for mapping
- * @param subtype subtype which is used for mapping
- * @return corresponding {@link ODataFormat} or {@link ODataFormat#CUSTOM} if none specific format is available.
- */
- private static ODataFormat mapToODataFormat(final String type, final String subtype) {
- ODataFormat odataFormat = ODataFormat.CUSTOM;
- if (type.contains("application")) {
- if (subtype.contains("atom")) {
- odataFormat = ODataFormat.ATOM;
- } else if (subtype.contains("xml")) {
- odataFormat = ODataFormat.XML;
- } else if (subtype.contains("json")) {
- odataFormat = ODataFormat.JSON;
- }
- } else if (KNOWN_MIME_TYPES.contains(type)) {
- odataFormat = ODataFormat.MIME;
- }
- return odataFormat;
- }
-
- /**
- * Maps content of array into map.
- * Therefore it must be an combination of <code>key</code> followed by the <code>value</code> in the array.
- *
- * @param content content which is added to {@link Map}.
- * @return a new <code>ContentType</code> object
- */
- private static Map<String, String> parameterMap(final String... content) {
- Map<String, String> map = new HashMap<String, String>();
- for (int i = 0; i < content.length - 1; i += 2) {
- String key = content[i];
- String value = content[i + 1];
- map.put(key, value);
- }
- return map;
- }
-
- /**
- * Valid input are <code>;</code> separated <code>key=value</code> pairs
- * without spaces between key and value.
- *
- * <p>
- * See RFC 2616:
- * The type, subtype, and parameter attribute names are case-insensitive.
- * Parameter values might or might not be case-sensitive, depending on the
- * semantics of the parameter name. <b>Linear white space (LWS) MUST NOT be used
- * between the type and subtype, nor between an attribute and its value</b>.
- * </p>
- *
- * @param parameters
- * @return Map with keys mapped to values
- */
- private static Map<String, String> parseParameters(final String parameters) {
- Map<String, String> parameterMap = new HashMap<String, String>();
- if (parameters != null) {
- String[] splittedParameters = parameters.split(PARAMETER_SEPARATOR);
- for (String parameter : splittedParameters) {
- String[] keyValue = parameter.split("=");
- String key = keyValue[0].trim().toLowerCase(Locale.ENGLISH);
- if (isParameterAllowed(key)) {
- String value = keyValue.length > 1 ? keyValue[1] : null;
- if (value != null && isLws(value.charAt(0))) {
- throw new IllegalArgumentException("Value of parameter '" + key + "' starts with a LWS ('" + parameters + "').");
- }
- parameterMap.put(key, value);
- }
- }
- }
- return parameterMap;
- }
-
- /**
- * Validate if given character is a linear whitepace (includes <code>horizontal-tab, linefeed, carriage return and space</code>).
- *
- * @param character to be checked
- * @return <code>true</code> if character is a LWS, otherwise <code>false</code>.
- */
- private static boolean isLws(final char character) {
- switch (character) {
- case 9: // HT = <US-ASCII HT, horizontal-tab (9)>
- case 10: // LF = <US-ASCII LF, linefeed (10)>
- case 13: // CR = <US-ASCII CR, carriage return (13)>
- case 32: // SP = <US-ASCII SP, space (32)>
- return true;
- default:
- return false;
- }
- }
-
- private static boolean isParameterAllowed(final String key) {
- return key != null && !PARAMETER_Q.equals(key.toLowerCase(Locale.US));
- }
-
- /**
- * Ensure that charset parameter ({@link #PARAMETER_CHARSET}) is set on returned content type
- * if this {@link ContentType} is a <code>odata text related</code> content type (@see {@link #isContentTypeODataTextRelated()}).
- * If <code>this</code> {@link ContentType} has no charset parameter set a new {@link ContentType}
- * with given <code>defaultCharset</code> is created.
- * Otherwise if charset parameter is already set nothing is done.
- *
- * @param defaultCharset
- * @return ContentType
- */
- public ContentType receiveWithCharsetParameter(final String defaultCharset) {
- if (isContentTypeODataTextRelated()) {
- if (!parameters.containsKey(ContentType.PARAMETER_CHARSET)) {
- return ContentType.create(this, ContentType.PARAMETER_CHARSET, defaultCharset);
- }
- }
- return this;
- }
-
- /**
- *
- * @return <code>true</code> if this {@link ContentType} is text related (in the view of OData)
- */
- public boolean isContentTypeODataTextRelated() {
- return (ContentType.TEXT_PLAIN.equals(this)
- || (getODataFormat() == ODataFormat.XML)
- || (getODataFormat() == ODataFormat.ATOM)
- || (getODataFormat() == ODataFormat.JSON));
- }
-
- public String getType() {
- return type;
- }
-
- public String getSubtype() {
- return subtype;
- }
-
- /**
- *
- * @return parameters of this {@link ContentType} as unmodifiable map.
- */
- public Map<String, String> getParameters() {
- return Collections.unmodifiableMap(parameters);
- }
-
- @Override
- public int hashCode() {
- return 1;
- }
-
- /**
- * {@link ContentType}s are equal
- * <ul>
- * <li>if <code>type</code>, <code>subtype</code> and all <code>parameters</code> have the same value.</li>
- * <li>if <code>type</code> and/or <code>subtype</code> is set to "*" (in such a case the <code>parameters</code> are ignored).</li>
- * </ul>
- *
- * @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code>.
- */
- @Override
- public boolean equals(final Object obj) {
- // NULL validation is done in method 'isEqualWithoutParameters(obj)'
- Boolean compatible = isEqualWithoutParameters(obj);
-
- if (compatible == null) {
- ContentType other = (ContentType) obj;
-
- // parameter checks
- if (parameters == null) {
- if (other.parameters != null) {
- return false;
- }
- } else if (parameters.size() == other.parameters.size()) {
- Iterator<Entry<String, String>> entries = parameters.entrySet().iterator();
- Iterator<Entry<String, String>> otherEntries = other.parameters.entrySet().iterator();
- while (entries.hasNext()) {
- Entry<String, String> e = entries.next();
- Entry<String, String> oe = otherEntries.next();
-
- if (!areEqual(e.getKey(), oe.getKey())) {
- return false;
- }
- if (!areEqual(e.getValue(), oe.getValue())) {
- return false;
- }
- }
- } else {
- return false;
- }
- return true;
- } else {
- // all tests run
- return compatible.booleanValue();
- }
- }
-
- /**
- * {@link ContentType}s are <b>compatible</b>
- * <ul>
- * <li>if <code>type</code>, <code>subtype</code> have the same value.</li>
- * <li>if <code>type</code> and/or <code>subtype</code> is set to "*"</li>
- * </ul>
- * The set <code>parameters</code> are <b>always</b> ignored (for compare with parameters see {@link #equals(Object)}).
- *
- * @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code>.
- */
- public boolean isCompatible(final ContentType obj) {
- Boolean compatible = isEqualWithoutParameters(obj);
- if (compatible == null) {
- return true;
- }
- return compatible.booleanValue();
- }
-
- /**
- * Check equal without parameters.
- * It is possible that no decision about <code>equal/none equal</code> can be determined a <code>NULL</code> is returned.
- *
- * @param obj to checked object
- * @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code>
- * or <code>NULL</code> if no decision about <code>equal/none equal</code> could be determined.
- */
- private Boolean isEqualWithoutParameters(final Object obj) {
- // basic checks
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
-
- ContentType other = (ContentType) obj;
-
- // subtype checks
- if (subtype == null) {
- if (other.subtype != null) {
- return false;
- }
- } else if (!subtype.equals(other.subtype)) {
- if (!subtype.equals(MEDIA_TYPE_WILDCARD) && !other.subtype.equals(MEDIA_TYPE_WILDCARD)) {
- return false;
- }
- }
-
- // type checks
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- if (!type.equals(MEDIA_TYPE_WILDCARD) && !other.type.equals(MEDIA_TYPE_WILDCARD)) {
- return false;
- }
- }
-
- // if wildcards are set, content types are defined as 'equal'
- if (countWildcards() > 0 || other.countWildcards() > 0) {
- return true;
- }
-
- return null;
- }
-
- /**
- * Check whether both string are equal ignoring the case of the strings.
- *
- * @param first first string
- * @param second second string
- * @return <code>true</code> if both strings are equal (by ignoring the case), otherwise <code>false</code> is returned
- */
- private static boolean areEqual(final String first, final String second) {
- if (first == null) {
- if (second != null) {
- return false;
- }
- } else if (!first.equalsIgnoreCase(second)) {
- return false;
- }
- return true;
- }
-
- /**
- * Get {@link ContentType} as string as defined in RFC 2616 (http://www.ietf.org/rfc/rfc2616.txt - chapter 14.17: Content-Type)
- *
- * @return string representation of <code>ContentType</code> object
- */
- public String toContentTypeString() {
- StringBuilder sb = new StringBuilder();
- sb.append(type).append(TYPE_SUBTYPE_SEPARATOR).append(subtype);
- for (String key : parameters.keySet()) {
- if (isParameterAllowed(key)) {
- String value = parameters.get(key);
- sb.append(";").append(key).append("=").append(value);
- }
- }
- return sb.toString();
- }
-
- @Override
- public String toString() {
- return toContentTypeString();
- }
-
- public ODataFormat getODataFormat() {
- return odataFormat;
- }
-
- /**
- * Find best match between this {@link ContentType} and the {@link ContentType} in the list.
- * If a match (this {@link ContentType} is equal to a {@link ContentType} in list) is found either this or the {@link ContentType}
- * from the list is returned based on which {@link ContentType} has less "**" characters set
- * (checked with {@link #compareWildcardCounts(ContentType)}.
- * If no match (none {@link ContentType} in list is equal to this {@link ContentType}) is found <code>NULL</code> is returned.
- *
- * @param toMatchContentTypes list of {@link ContentType}s which are matches against this {@link ContentType}
- * @return best matched content type in list or <code>NULL</code> if none content type match to this content type instance
- */
- public ContentType match(final List<ContentType> toMatchContentTypes) {
- for (ContentType supportedContentType : toMatchContentTypes) {
- if (equals(supportedContentType)) {
- if (compareWildcardCounts(supportedContentType) < 0) {
- return this;
- } else {
- return supportedContentType;
- }
- }
- }
- return null;
- }
-
- /**
- * Find best match between this {@link ContentType} and the {@link ContentType} in the list ignoring all set parameters.
- * If a match (this {@link ContentType} is equal to a {@link ContentType} in list) is found either this or the {@link ContentType}
- * from the list is returned based on which {@link ContentType} has less "**" characters set
- * (checked with {@link #compareWildcardCounts(ContentType)}.
- * If no match (none {@link ContentType} in list is equal to this {@link ContentType}) is found <code>NULL</code> is returned.
- *
- * @param toMatchContentTypes list of {@link ContentType}s which are matches against this {@link ContentType}
- * @return best matched content type in list or <code>NULL</code> if none content type match to this content type instance
- */
- public ContentType matchCompatible(final List<ContentType> toMatchContentTypes) {
- for (ContentType supportedContentType : toMatchContentTypes) {
- if (isCompatible(supportedContentType)) {
- if (compareWildcardCounts(supportedContentType) < 0) {
- return this;
- } else {
- return supportedContentType;
- }
- }
- }
- return null;
- }
-
- /**
- * Check if a valid compatible match for this {@link ContentType} exists in given list.
- * Compatible in this case means that <b>all set parameters are ignored</b>.
- * For more detail what a valid match is see {@link #matchCompatible(List)}.
- *
- * @param toMatchContentTypes list of {@link ContentType}s which are matches against this {@link ContentType}
- * @return <code>true</code> if a compatible content type was found in given list
- * or <code>false</code> if none compatible content type match was found
- */
- public boolean hasCompatible(final List<ContentType> toMatchContentTypes) {
- return matchCompatible(toMatchContentTypes) != null;
- }
-
- /**
- * Check if a valid match for this {@link ContentType} exists in given list.
- * For more detail what a valid match is see {@link #match(List)}.
- *
- * @param toMatchContentTypes list of {@link ContentType}s which are matches against this {@link ContentType}
- * @return <code>true</code> if a matching content type was found in given list
- * or <code>false</code> if none matching content type match was found
- */
- public boolean hasMatch(final List<ContentType> toMatchContentTypes) {
- return match(toMatchContentTypes) != null;
- }
-
- /**
- * Compare wildcards counts/weights of both {@link ContentType}.
- *
- * The smaller {@link ContentType} has lesser weighted wildcards then the bigger {@link ContentType}.
- * As result this method returns this object weighted wildcards minus the given parameter object weighted wildcards.
- *
- * A type wildcard is weighted with <code>2</code> and a subtype wildcard is weighted with <code>1</code>.
- *
- * @param otherContentType {@link ContentType} to be compared to
- * @return this object weighted wildcards minus the given parameter object weighted wildcards.
- */
- public int compareWildcardCounts(final ContentType otherContentType) {
- return countWildcards() - otherContentType.countWildcards();
- }
-
- private int countWildcards() {
- int count = 0;
- if (MEDIA_TYPE_WILDCARD.equals(type)) {
- count += 2;
- }
- if (MEDIA_TYPE_WILDCARD.equals(subtype)) {
- count++;
- }
- return count;
- }
-
- /**
- *
- * @return <code>true</code> if <code>type</code> or <code>subtype</code> of this instance is a "*".
- */
- public boolean hasWildcard() {
- return (MEDIA_TYPE_WILDCARD.equals(type) || MEDIA_TYPE_WILDCARD.equals(subtype));
- }
-
- /**
- *
- * @return <code>true</code> if both <code>type</code> and <code>subtype</code> of this instance are a "*".
- */
- public boolean isWildcard() {
- return (MEDIA_TYPE_WILDCARD.equals(type) && MEDIA_TYPE_WILDCARD.equals(subtype));
- }
-
- public static List<ContentType> convert(final List<String> types) {
- List<ContentType> results = new ArrayList<ContentType>();
- for (String contentType : types) {
- results.add(ContentType.create(contentType));
- }
- return results;
- }
-
- /**
- * Check if a valid match for given content type formated string (<code>toMatch</code>) exists in given list.
- * Therefore the given content type formated string (<code>toMatch</code>) is converted into a {@link ContentType}
- * with a simple {@link #create(String)} call (during which an exception can occur).
- *
- * For more detail in general see {@link #hasMatch(List)} and for what a valid match is see {@link #match(List)}.
- *
- * @param toMatch content type formated string (<code>toMatch</code>) for which is checked if a match exists in given list
- * @param matchExamples list of {@link ContentType}s which are matches against content type formated string (<code>toMatch</code>)
- * @return <code>true</code> if a matching content type was found in given list
- * or <code>false</code> if none matching content type match was found
- */
- public static boolean match(final String toMatch, final ContentType... matchExamples) {
- ContentType toMatchContentType = ContentType.create(toMatch);
-
- return toMatchContentType.hasMatch(Arrays.asList(matchExamples));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/Decoder.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/Decoder.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/Decoder.java
deleted file mode 100644
index ddf3586..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/Decoder.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.commons;
-
-import java.io.UnsupportedEncodingException;
-
-/**
- * Decodes a Java String containing a percent-encoded UTF-8 String value
- * into a Java String (in its internal UTF-16 encoding).
- *
- */
-public class Decoder {
-
- /**
- * Decodes a percent-encoded UTF-8 String value into a Java String
- * (in its internal UTF-16 encoding).
- * @param value the encoded String
- * @return the Java String
- * @throws IllegalArgumentException if value contains characters not representing UTF-8 bytes
- * or ends with an unfinished percent-encoded character
- * @throws NumberFormatException if the two characters after a percent character
- * are not hexadecimal digits
- */
- public static String decode(final String value) throws IllegalArgumentException, NumberFormatException {
- if (value == null) {
- return value;
- }
-
- // Use a tiny finite-state machine to handle decoding on byte level.
- // There are only three states:
- // -2: normal bytes
- // -1: a byte representing the percent character has been read
- // >= 0: a byte representing the first half-byte of a percent-encoded byte has been read
- // The variable holding the state is also used to store the value of the first half-byte.
- byte[] result = new byte[value.length()];
- int position = 0;
- byte encodedPart = -2;
- for (final char c : value.toCharArray()) {
- if (c <= Byte.MAX_VALUE) {
- if (c == '%') {
- if (encodedPart == -2) {
- encodedPart = -1;
- } else {
- throw new IllegalArgumentException();
- }
- } else if (encodedPart == -1) {
- encodedPart = (byte) c;
- } else if (encodedPart >= 0) {
- final int i = Integer.parseInt(String.valueOf(new char[] { (char) encodedPart, c }), 16);
- if (i >= 0) {
- result[position++] = (byte) i;
- } else {
- throw new NumberFormatException();
- }
- encodedPart = -2;
- } else {
- result[position++] = (byte) c;
- }
- } else {
- throw new IllegalArgumentException();
- }
- }
-
- if (encodedPart >= 0) {
- throw new IllegalArgumentException();
- }
-
- try {
- return new String(result, 0, position, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new IllegalArgumentException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/Encoder.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/Encoder.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/Encoder.java
deleted file mode 100644
index 8739b62..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/commons/Encoder.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.commons;
-
-import java.io.UnsupportedEncodingException;
-
-/**
- * Encodes a Java String (in its internal UTF-16 encoding) into its
- * percent-encoded UTF-8 representation according to
- * <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>
- * (with consideration of its predecessor RFC 2396).
- *
- */
-public class Encoder {
-
- /**
- * Encodes a Java String (in its internal UTF-16 encoding) into its
- * percent-encoded UTF-8 representation according to
- * <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>,
- * suitable for parts of an OData path segment.
- * @param value the Java String
- * @return the encoded String
- */
- public static String encode(final String value) {
- return encoder.encodeInternal(value);
- }
-
- // OData has special handling for "'", so we allow that to remain unencoded.
- // Other sub-delims not used neither by JAX-RS nor by OData could be added
- // if the encoding is considered to be too aggressive.
- // RFC 3986 would also allow the gen-delims ":" and "@" to appear literally
- // in path-segment parts.
- private static final String ODATA_UNENCODED = "'";
-
- // Character classes from RFC 3986
- private final static String UNRESERVED = "-._~"; // + ALPHA + DIGIT
- // RFC 3986 says: "For consistency, URI producers and normalizers should
- // use uppercase hexadecimal digits for all percent-encodings."
- private final static String[] hex = { "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F", "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17", "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F", "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27", "%28", "%29", "%2A", "%2B", "%2C", "%2D", "%2E", "%2F", "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37", "%38", "%39", "%3A", "%3B", "%3C", "%3D", "%3E", "%3F", "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47", "%48", "%49", "%4A", "%4B", "%4C", "%4D", "%4E", "%4F", "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57", "%58", "%59", "%5A", "%5B", "%5C", "%5D", "%5E", "%5F", "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67", "%68", "%69", "%6A", "%6B", "%6C", "%6D", "%6E", "%6F", "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77", "%78", "%79", "%7A", "%7B", "%7C", "%7D", "%7E", "%7F", "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87", "%88"
,
- "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F", "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F", "%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7", "%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF", "%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7", "%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF", "%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7", "%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF", "%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7", "%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF", "%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7", "%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF", "%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7", "%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF" };
-
- private static final Encoder encoder = new Encoder(ODATA_UNENCODED);
-
- /** characters to remain unencoded in addition to {@link #UNRESERVED} */
- private final String unencoded;
-
- private Encoder(final String unencoded) {
- this.unencoded = unencoded == null ? "" : unencoded;
- }
-
- /**
- * <p>Returns the percent-encoded UTF-8 representation of a String.</p>
- * <p>In order to avoid producing percent-encoded CESU-8 (as described in
- * the Unicode Consortium's <a href="http://www.unicode.org/reports/tr26/">
- * Technical Report #26</a>), this is done in two steps:
- * <ol>
- * <li>Re-encode the characters from their Java-internal UTF-16 representations
- * into their UTF-8 representations.</li>
- * <li>Percent-encode each of the bytes in the UTF-8 representation.
- * This is possible on byte level because all characters that do not have
- * a <code>%xx</code> representation are represented in one byte in UTF-8.</li>
- * </ol></p>
- * @param input input String
- * @return encoded representation
- */
- private String encodeInternal(final String input) {
- StringBuilder resultStr = new StringBuilder();
-
- try {
- for (byte utf8Byte : input.getBytes("UTF-8")) {
- final char character = (char) utf8Byte;
- if (isUnreserved(character)) {
- resultStr.append(character);
- } else if (isUnencoded(character)) {
- resultStr.append(character);
- } else if (utf8Byte >= 0) {
- resultStr.append(hex[utf8Byte]);
- } else {
- // case UTF-8 continuation byte
- resultStr.append(hex[256 + utf8Byte]); // index adjusted for the usage of signed bytes
- }
- }
- } catch (final UnsupportedEncodingException e) { // should never happen; UTF-8 is always there
- return null;
- }
- return resultStr.toString();
- }
-
- private static boolean isUnreserved(final char character) {
- return 'A' <= character && character <= 'Z' // case A..Z
- || 'a' <= character && character <= 'z' // case a..z
- || '0' <= character && character <= '9' // case 0..9
- || UNRESERVED.indexOf(character) >= 0;
- }
-
- private boolean isUnencoded(final char character) {
- return unencoded.indexOf(character) >= 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfo.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfo.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfo.java
deleted file mode 100644
index ae3801a..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfo.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import java.io.IOException;
-
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-
-/**
- *
- */
-public interface DebugInfo {
-
- /**
- * Gets the name of this debug information part, useful as title.
- * @return the name
- */
- public String getName();
-
- /**
- * Appends the content of this debug information part
- * to the given JSON stream writer.
- * @param jsonStreamWriter a JSON stream writer
- */
- public void appendJson(JsonStreamWriter jsonStreamWriter) throws IOException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoBody.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoBody.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoBody.java
deleted file mode 100644
index cdd189f..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoBody.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.ep.BasicEntityProvider;
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-
-/**
- *
- */
-public class DebugInfoBody implements DebugInfo {
-
- private final ODataResponse response;
-
- public DebugInfoBody(final ODataResponse response) {
- this.response = response;
- }
-
- @Override
- public String getName() {
- return "Body";
- }
-
- @Override
- public void appendJson(final JsonStreamWriter jsonStreamWriter) throws IOException {
- final String contentType = response.getContentHeader();
- if (contentType.startsWith("image/")) {
- if (response.getEntity() instanceof InputStream) {
- jsonStreamWriter.stringValueRaw(Base64.encodeBase64String(getBinaryFromInputStream((InputStream) response.getEntity())));
- } else if (response.getEntity() instanceof String) {
- jsonStreamWriter.stringValueRaw(getContentString());
- } else {
- throw new ClassCastException("Unsupported content entity class: " + response.getEntity().getClass().getName());
- }
- } else if (contentType.startsWith(HttpContentType.APPLICATION_JSON)) {
- jsonStreamWriter.unquotedValue(getContentString());
- } else {
- jsonStreamWriter.stringValue(getContentString());
- }
- }
-
- private String getContentString() {
- String content;
- if (response.getEntity() instanceof String) {
- content = (String) response.getEntity();
- } else if (response.getEntity() instanceof InputStream) {
- content = getStringFromInputStream((InputStream) response.getEntity());
- } else {
- throw new ClassCastException("Unsupported content entity class: " + response.getEntity().getClass().getName());
- }
- return content;
- }
-
- private static byte[] getBinaryFromInputStream(final InputStream inputStream) {
- try {
- return new BasicEntityProvider().readBinary(inputStream);
- } catch (final EntityProviderException e) {
- return null;
- }
- }
-
- private static String getStringFromInputStream(final InputStream inputStream) {
- try {
- return new BasicEntityProvider().readText(inputStream);
- } catch (final EntityProviderException e) {
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoException.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoException.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoException.java
deleted file mode 100644
index ec2c9bf..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoException.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import java.io.IOException;
-import java.util.Locale;
-
-import org.apache.olingo.odata2.api.exception.ODataMessageException;
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-import org.apache.olingo.odata2.core.exception.MessageService;
-
-/**
- *
- */
-public class DebugInfoException implements DebugInfo {
-
- private final Exception exception;
- private final Locale locale;
-
- public DebugInfoException(final Exception exception, final Locale locale) {
- this.exception = exception;
- this.locale = locale;
- }
-
- @Override
- public String getName() {
- return "Stacktrace";
- }
-
- @Override
- public void appendJson(final JsonStreamWriter jsonStreamWriter) throws IOException {
- jsonStreamWriter.beginObject()
- .name("exceptions")
- .beginArray();
- Throwable throwable = exception;
- while (throwable != null) {
- jsonStreamWriter.beginObject()
- .namedStringValueRaw("class", throwable.getClass().getCanonicalName()).separator()
- .namedStringValue("message",
- throwable instanceof ODataMessageException ?
- MessageService.getMessage(locale, ((ODataMessageException) throwable).getMessageReference()).getText() :
- throwable.getLocalizedMessage())
- .separator();
-
- jsonStreamWriter.name("invocation");
- appendJsonStackTraceElement(jsonStreamWriter, throwable.getStackTrace()[0]);
-
- jsonStreamWriter.endObject();
- throwable = throwable.getCause();
- if (throwable != null) {
- jsonStreamWriter.separator();
- }
- }
- jsonStreamWriter.endArray();
- jsonStreamWriter.separator();
-
- jsonStreamWriter.name("stacktrace")
- .beginArray();
- boolean first = true;
- for (final StackTraceElement stackTraceElement : exception.getStackTrace()) {
- if (!first) {
- jsonStreamWriter.separator();
- }
- first = false;
- appendJsonStackTraceElement(jsonStreamWriter, stackTraceElement);
- }
- jsonStreamWriter.endArray();
- jsonStreamWriter.endObject();
- }
-
- private static void appendJsonStackTraceElement(final JsonStreamWriter jsonStreamWriter, final StackTraceElement stackTraceElement) throws IOException {
- jsonStreamWriter.beginObject()
- .namedStringValueRaw("class", stackTraceElement.getClassName()).separator()
- .namedStringValueRaw("method", stackTraceElement.getMethodName()).separator()
- .name("line").unquotedValue(Integer.toString(stackTraceElement.getLineNumber()))
- .endObject();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoRequest.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoRequest.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoRequest.java
deleted file mode 100644
index c99a3f3..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoRequest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-
-/**
- *
- */
-public class DebugInfoRequest implements DebugInfo {
-
- private final String method;
- private final URI uri;
- private final Map<String, List<String>> headers;
-
- public DebugInfoRequest(final String method, final URI uri, final Map<String, List<String>> headers) {
- this.method = method;
- this.uri = uri;
- this.headers = headers;
- }
-
- @Override
- public String getName() {
- return "Request";
- }
-
- @Override
- public void appendJson(final JsonStreamWriter jsonStreamWriter) throws IOException {
- jsonStreamWriter.beginObject()
- .namedStringValueRaw("method", method).separator()
- .namedStringValue("uri", uri.toString());
-
- if (!headers.isEmpty()) {
- jsonStreamWriter.separator()
- .name("headers")
- .beginObject();
- boolean first = true;
- for (final String name : headers.keySet()) {
- for (final String value : headers.get(name)) {
- if (!first) {
- jsonStreamWriter.separator();
- }
- first = false;
- jsonStreamWriter.namedStringValue(name, value);
- }
- }
- jsonStreamWriter.endObject();
- }
-
- jsonStreamWriter.endObject();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoResponse.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoResponse.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoResponse.java
deleted file mode 100644
index aa0d8da..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoResponse.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import java.io.IOException;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-
-/**
- *
- */
-public class DebugInfoResponse implements DebugInfo {
-
- private final HttpStatusCodes status;
- private final Map<String, String> headers;
-
- public DebugInfoResponse(final HttpStatusCodes status, final Map<String, String> headers) {
- this.status = status;
- this.headers = headers;
- }
-
- @Override
- public String getName() {
- return "Response";
- }
-
- @Override
- public void appendJson(final JsonStreamWriter jsonStreamWriter) throws IOException {
- jsonStreamWriter.beginObject();
-
- if (status != null) {
- jsonStreamWriter.name("status")
- .beginObject()
- .name("code").unquotedValue(Integer.toString(status.getStatusCode())).separator()
- .namedStringValueRaw("info", status.getInfo())
- .endObject();
- }
-
- if (!headers.isEmpty()) {
- if (status != null) {
- jsonStreamWriter.separator();
- }
-
- jsonStreamWriter.name("headers")
- .beginObject();
- boolean first = true;
- for (final String name : headers.keySet()) {
- if (!first) {
- jsonStreamWriter.separator();
- }
- first = false;
- jsonStreamWriter.namedStringValue(name, headers.get(name));
- }
- jsonStreamWriter.endObject();
- }
-
- jsonStreamWriter.endObject();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoRuntime.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoRuntime.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoRuntime.java
deleted file mode 100644
index 65ab05a..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoRuntime.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.processor.ODataContext.RuntimeMeasurement;
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-
-/**
- *
- */
-public class DebugInfoRuntime implements DebugInfo {
-
- private class RuntimeNode {
- protected String className;
- protected String methodName;
- protected long timeStarted;
- protected long timeStopped;
- protected List<RuntimeNode> children = new ArrayList<RuntimeNode>();
- public long memoryStarted;
- public long memoryStopped;
-
- protected RuntimeNode() {
- timeStarted = 0;
- timeStopped = Long.MAX_VALUE;
- memoryStarted = 0;
- memoryStopped = 0;
- }
-
- private RuntimeNode(final RuntimeMeasurement runtimeMeasurement) {
- className = runtimeMeasurement.getClassName();
- methodName = runtimeMeasurement.getMethodName();
- timeStarted = runtimeMeasurement.getTimeStarted();
- timeStopped = runtimeMeasurement.getTimeStopped();
- memoryStarted = runtimeMeasurement.getMemoryStarted();
- memoryStopped = runtimeMeasurement.getMemoryStopped();
- }
-
- protected boolean add(final RuntimeMeasurement runtimeMeasurement) {
- if (timeStarted <= runtimeMeasurement.getTimeStarted()
- && timeStopped != 0 && timeStopped >= runtimeMeasurement.getTimeStopped()) {
- for (RuntimeNode candidate : children) {
- if (candidate.add(runtimeMeasurement)) {
- return true;
- }
- }
- children.add(new RuntimeNode(runtimeMeasurement));
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Combines runtime measurements with identical class names and method
- * names into one measurement, assuming that they originate from a loop
- * or a similar construct where a summary measurement has been intended.
- */
- protected void combineRuntimeMeasurements() {
- RuntimeNode preceding = null;
- for (Iterator<RuntimeNode> iterator = children.iterator(); iterator.hasNext();) {
- final RuntimeNode child = iterator.next();
- if (preceding != null
- && preceding.timeStopped != 0 && child.timeStopped != 0
- && preceding.timeStopped <= child.timeStarted
- && preceding.children.isEmpty() && child.children.isEmpty()
- && preceding.methodName.equals(child.methodName)
- && preceding.className.equals(child.className)) {
- preceding.timeStarted = child.timeStarted - (preceding.timeStopped - preceding.timeStarted);
- preceding.timeStopped = child.timeStopped;
-
- preceding.memoryStarted = child.memoryStarted - (preceding.memoryStopped - preceding.memoryStarted);
- preceding.memoryStopped = child.memoryStopped;
-
- iterator.remove();
- } else {
- preceding = child;
- child.combineRuntimeMeasurements();
- }
- }
- }
- }
-
- private final RuntimeNode rootNode;
-
- public DebugInfoRuntime(final List<RuntimeMeasurement> runtimeMeasurements) {
- rootNode = new RuntimeNode();
- for (final RuntimeMeasurement runtimeMeasurement : runtimeMeasurements) {
- rootNode.add(runtimeMeasurement);
- }
- rootNode.combineRuntimeMeasurements();
- }
-
- @Override
- public String getName() {
- return "Runtime";
- }
-
- @Override
- public void appendJson(final JsonStreamWriter jsonStreamWriter) throws IOException {
- appendJsonChildren(jsonStreamWriter, rootNode);
- }
-
- private static void appendJsonNode(final JsonStreamWriter jsonStreamWriter, final RuntimeNode node) throws IOException {
- jsonStreamWriter.beginObject()
- .namedStringValueRaw("class", node.className).separator()
- .namedStringValueRaw("method", node.methodName).separator()
- .name("duration")
- .unquotedValue(node.timeStopped == 0 ? null :
- Long.toString((node.timeStopped - node.timeStarted) / 1000))
- .separator()
- .name("memory")
- .unquotedValue(node.memoryStopped == 0 ? null :
- Long.toString((node.memoryStopped - node.memoryStarted) / 1000))
- .separator()
- .name("children");
- appendJsonChildren(jsonStreamWriter, node);
- jsonStreamWriter.endObject();
- }
-
- private static void appendJsonChildren(final JsonStreamWriter jsonStreamWriter, final RuntimeNode node) throws IOException {
- jsonStreamWriter.beginArray();
- boolean first = true;
- for (final RuntimeNode childNode : node.children) {
- if (!first) {
- jsonStreamWriter.separator();
- }
- first = false;
- appendJsonNode(jsonStreamWriter, childNode);
- }
- jsonStreamWriter.endArray();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoUri.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoUri.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoUri.java
deleted file mode 100644
index d535ce5..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/DebugInfoUri.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import java.io.IOException;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.api.uri.expression.ExceptionVisitExpression;
-import org.apache.olingo.odata2.api.uri.expression.ExpressionParserException;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-import org.apache.olingo.odata2.core.uri.ExpandSelectTreeCreator;
-import org.apache.olingo.odata2.core.uri.ExpandSelectTreeNodeImpl;
-import org.apache.olingo.odata2.core.uri.expression.JsonVisitor;
-
-/**
- *
- */
-public class DebugInfoUri implements DebugInfo {
-
- private final UriInfo uriInfo;
- private final ExpressionParserException exception;
-
- public DebugInfoUri(final UriInfo uriInfo, final Exception exception) {
- this.uriInfo = uriInfo;
-
- Throwable candidate = exception;
- while (candidate != null && !(candidate instanceof ExpressionParserException)) {
- candidate = candidate.getCause();
- }
- this.exception = (ExpressionParserException) candidate;
- }
-
- @Override
- public String getName() {
- return "URI";
- }
-
- @Override
- public void appendJson(final JsonStreamWriter jsonStreamWriter) throws IOException {
- jsonStreamWriter.beginObject();
-
- if (exception != null) {
- jsonStreamWriter.name("error")
- .beginObject();
- if (exception.getFilterTree() != null) {
- jsonStreamWriter.namedStringValue("filter", exception.getFilterTree().getUriLiteral());
- }
- jsonStreamWriter.endObject();
- }
-
- if (uriInfo != null) {
- if (exception != null
- && (uriInfo.getFilter() != null || uriInfo.getOrderBy() != null
- || !uriInfo.getExpand().isEmpty() || !uriInfo.getSelect().isEmpty())) {
- jsonStreamWriter.separator();
- }
-
- final FilterExpression filter = uriInfo.getFilter();
- if (filter != null) {
- String filterString;
- try {
- filterString = (String) filter.accept(new JsonVisitor());
- } catch (final ExceptionVisitExpression e) {
- filterString = null;
- } catch (final ODataApplicationException e) {
- filterString = null;
- }
- jsonStreamWriter.name("filter").unquotedValue(filterString);
- if (uriInfo.getOrderBy() != null
- || !uriInfo.getExpand().isEmpty() || !uriInfo.getSelect().isEmpty()) {
- jsonStreamWriter.separator();
- }
- }
-
- final OrderByExpression orderBy = uriInfo.getOrderBy();
- if (orderBy != null) {
- String orderByString;
- try {
- orderByString = (String) orderBy.accept(new JsonVisitor());
- } catch (final ExceptionVisitExpression e) {
- orderByString = null;
- } catch (final ODataApplicationException e) {
- orderByString = null;
- }
- jsonStreamWriter.name("orderby").unquotedValue(orderByString);
- if (!uriInfo.getExpand().isEmpty() || !uriInfo.getSelect().isEmpty()) {
- jsonStreamWriter.separator();
- }
- }
-
- if (!uriInfo.getExpand().isEmpty() || !uriInfo.getSelect().isEmpty()) {
- String expandSelectString;
- try {
- ExpandSelectTreeCreator expandSelectCreator = new ExpandSelectTreeCreator(uriInfo.getSelect(), uriInfo.getExpand());
- final ExpandSelectTreeNodeImpl expandSelectTree = expandSelectCreator.create();
- expandSelectString = expandSelectTree.toJsonString();
- } catch (final EdmException e) {
- expandSelectString = null;
- }
- jsonStreamWriter.name("expand/select").unquotedValue(expandSelectString);
- }
- }
-
- jsonStreamWriter.endObject();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java
deleted file mode 100644
index 56b45d4..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.core.ep.util.CircleStreamBuffer;
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-import org.apache.olingo.odata2.core.exception.MessageService;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-/**
- * Wraps an OData response into an OData response containing additional
- * information useful for support purposes.
- *
- */
-public class ODataDebugResponseWrapper {
-
- public static final String ODATA_DEBUG_QUERY_PARAMETER = "odata-debug";
- public static final String ODATA_DEBUG_JSON = "json";
-
- private final ODataContext context;
- private final ODataResponse response;
- private final UriInfo uriInfo;
- private final Exception exception;
- private final boolean isJson;
-
- public ODataDebugResponseWrapper(final ODataContext context, final ODataResponse response, final UriInfo uriInfo, final Exception exception, final String debugValue) {
- this.context = context;
- this.response = response;
- this.uriInfo = uriInfo;
- this.exception = exception;
- isJson = ODATA_DEBUG_JSON.equals(debugValue);
- }
-
- public ODataResponse wrapResponse() {
- try {
- return ODataResponse.status(HttpStatusCodes.OK)
- .entity(isJson ? wrapInJson(createParts()) : null)
- .contentHeader(isJson ? HttpContentType.APPLICATION_JSON : null)
- .build();
- } catch (final ODataException e) {
- throw new ODataRuntimeException("Should not happen", e);
- } catch (final IOException e) {
- throw new ODataRuntimeException("Should not happen", e);
- }
- }
-
- private List<DebugInfo> createParts() throws ODataException {
- List<DebugInfo> parts = new ArrayList<DebugInfo>();
-
- // body
- if (response.getContentHeader() != null && response.getEntity() != null) {
- parts.add(new DebugInfoBody(response));
- }
-
- // request
- parts.add(new DebugInfoRequest(context.getHttpMethod(),
- context.getPathInfo().getRequestUri(),
- context.getRequestHeaders()));
-
- // response
- Map<String, String> responseHeaders = new HashMap<String, String>();
- for (final String name : response.getHeaderNames()) {
- responseHeaders.put(name, response.getHeader(name));
- }
- parts.add(new DebugInfoResponse(response.getStatus(), responseHeaders));
-
- // URI
- if (uriInfo != null
- && (uriInfo.getFilter() != null || uriInfo.getOrderBy() != null
- || !uriInfo.getExpand().isEmpty() || !uriInfo.getSelect().isEmpty())) {
- parts.add(new DebugInfoUri(uriInfo, exception));
- }
-
- // runtime measurements
- if (context.getRuntimeMeasurements() != null) {
- parts.add(new DebugInfoRuntime(context.getRuntimeMeasurements()));
- }
-
- // exceptions
- if (exception != null) {
- final Locale locale = MessageService.getSupportedLocale(context.getAcceptableLanguages(), Locale.ENGLISH);
- parts.add(new DebugInfoException(exception, locale));
- }
-
- return parts;
- }
-
- private InputStream wrapInJson(final List<DebugInfo> parts) throws IOException {
- CircleStreamBuffer csb = new CircleStreamBuffer();
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(csb.getOutputStream(), "UTF-8"));
- JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
- jsonStreamWriter.beginObject();
- boolean first = true;
- for (final DebugInfo part : parts) {
- if (!first) {
- jsonStreamWriter.separator();
- }
- first = false;
- jsonStreamWriter.name(part.getName().toLowerCase(Locale.ROOT));
- part.appendJson(jsonStreamWriter);
- }
- jsonStreamWriter.endObject();
- writer.flush();
- csb.closeWrite();
- return csb.getInputStream();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/AbstractSimpleType.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/AbstractSimpleType.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/AbstractSimpleType.java
deleted file mode 100644
index 3ba2472..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/AbstractSimpleType.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.edm;
-
-import org.apache.olingo.odata2.api.edm.Edm;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-
-/**
- * Abstract implementation of the EDM simple-type interface.
- *
- */
-public abstract class AbstractSimpleType implements EdmSimpleType {
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj || (obj != null && getClass() == obj.getClass());
- }
-
- @Override
- public int hashCode() {
- return getClass().hashCode();
- }
-
- @Override
- public String getNamespace() throws EdmException {
- return EDM_NAMESPACE;
- }
-
- @Override
- public EdmTypeKind getKind() {
- return EdmTypeKind.SIMPLE;
- }
-
- @Override
- public String getName() throws EdmException {
- final String name = getClass().getSimpleName();
- return name.startsWith(EDM_NAMESPACE) ? name.substring(3) : name;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return equals(simpleType);
- }
-
- @Override
- public boolean validate(final String value, final EdmLiteralKind literalKind, final EdmFacets facets) {
- try {
- valueOfString(value, literalKind, facets, getDefaultType());
- return true;
- } catch (final EdmSimpleTypeException e) {
- return false;
- }
- }
-
- @Override
- public final <T> T valueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- if (value == null) {
- if (facets == null || facets.isNullable() == null || facets.isNullable()) {
- return null;
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_NULL_NOT_ALLOWED);
- }
- }
-
- if (literalKind == null) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_KIND_MISSING);
- }
-
- return internalValueOfString(value, literalKind, facets, returnType);
- }
-
- protected abstract <T> T internalValueOfString(String value, EdmLiteralKind literalKind, EdmFacets facets, Class<T> returnType) throws EdmSimpleTypeException;
-
- @Override
- public final String valueToString(final Object value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value == null) {
- if (facets == null || facets.isNullable() == null || facets.isNullable()) {
- return null;
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_NULL_NOT_ALLOWED);
- }
- }
-
- if (literalKind == null) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_KIND_MISSING);
- }
-
- final String result = internalValueToString(value, literalKind, facets);
- return literalKind == EdmLiteralKind.URI ? toUriLiteral(result) : result;
- }
-
- protected abstract <T> String internalValueToString(T value, EdmLiteralKind literalKind, EdmFacets facets) throws EdmSimpleTypeException;
-
- @Override
- public String toUriLiteral(final String literal) throws EdmSimpleTypeException {
- return literal;
- }
-
- @Override
- public String toString() {
- try {
- return getNamespace() + Edm.DELIMITER + getName();
- } catch (final EdmException e) {
- return super.toString();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/Bit.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/Bit.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/Bit.java
deleted file mode 100644
index a20d2e5..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/Bit.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.edm;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the internal simple type Bit.
- *
- */
-public class Bit extends AbstractSimpleType {
-
- private static final Bit instance = new Bit();
-
- public static Bit getInstance() {
- return instance;
- }
-
- @Override
- public String getNamespace() throws EdmException {
- return SYSTEM_NAMESPACE;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Byte.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- return EdmSByte.getInstance().internalValueOfString(value, literalKind, facets, returnType);
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- return EdmSByte.getInstance().internalValueToString(value, literalKind, facets);
- }
-}