Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit dba51aa Signed-off-by: David Joos <david.joos@bosch-si.com>
- Loading branch information
David Joos
committed
May 28, 2020
1 parent
dba51aa
commit 362e086
Showing
43 changed files
with
7,362 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
* Copyright (c) 2017 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.json; | ||
|
||
import java.net.URI; | ||
import java.text.MessageFormat; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.NotThreadSafe; | ||
|
||
/** | ||
* Thrown if a {@link JsonPointer} was in an invalid format. | ||
*/ | ||
public final class JsonPointerInvalidException extends JsonRuntimeException { | ||
|
||
/** | ||
* Error code of this exception. | ||
*/ | ||
public static final String ERROR_CODE = "json.pointer.invalid"; | ||
|
||
private static final String DEFAULT_DESCRIPTION = "Check, for example, if the JSON Pointer is not empty."; | ||
|
||
private static final String MULTIPLE_SLASHES_DESCRIPTION = | ||
"Consecutive slashes in JSON pointers are not supported."; | ||
|
||
private static final String OUTER_SLASHES_DESCRIPTION = | ||
"Leading or trailing slashes in JSON pointers are not supported."; | ||
|
||
private static final String NO_SLASHES_NO_CONTROL_CHARACTERS_DESCRIPTION = | ||
"Neither slashes nor any control characters are allowed at any place in your JSON Pointer. Please check!"; | ||
|
||
private static final long serialVersionUID = -6773700329225961931L; | ||
|
||
private JsonPointerInvalidException(@Nullable final String message, | ||
@Nullable final String description, | ||
@Nullable final Throwable cause, | ||
@Nullable final URI href) { | ||
|
||
super(ERROR_CODE, message, description, cause, href); | ||
} | ||
|
||
/** | ||
* Returns a builder for fluently creating instances of {@code JsonPointerInvalidException}s.. | ||
* | ||
* @return a new builder for JsonPointerInvalidException objects. | ||
*/ | ||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* Returns a new builder already containing a generic message that consecutive slashes are not supported for JSON | ||
* pointers. | ||
* | ||
* @param jsonPointer The JSON pointer containing the consecutive slashes. | ||
* @return a builder for {@code JsonPointerInvalidException} objects. | ||
*/ | ||
static JsonExceptionBuilder<JsonPointerInvalidException> newBuilderForConsecutiveSlashes( | ||
final CharSequence jsonPointer) { | ||
return new Builder() | ||
.jsonPointer(jsonPointer) | ||
.description(MULTIPLE_SLASHES_DESCRIPTION); | ||
} | ||
|
||
/** | ||
* Returns a new builder already containing a generic message that leading or trailing slashes are not supported for JSON | ||
* pointers. | ||
* | ||
* @param jsonPointer The JSON pointer containing the leading and/or trailing slashes. | ||
* @return a builder for {@code JsonPointerInvalidException} objects. | ||
*/ | ||
public static JsonExceptionBuilder<JsonPointerInvalidException> newBuilderForOuterSlashes( | ||
final CharSequence jsonPointer) { | ||
return new Builder() | ||
.jsonPointer(jsonPointer) | ||
.description(OUTER_SLASHES_DESCRIPTION); | ||
} | ||
|
||
/** | ||
* Returns a new builder already containing a generic message that slashes and control characters are not supported for JSON | ||
* pointers. | ||
* | ||
* @param jsonPointer The JSON pointer containing the slashes or control characters. | ||
* @return a builder for {@code JsonPointerInvalidException} objects. | ||
*/ | ||
public static JsonExceptionBuilder<JsonPointerInvalidException> newBuilderForNoSlashesAndControlChars( | ||
final CharSequence jsonPointer) { | ||
return new Builder() | ||
.jsonPointer(jsonPointer) | ||
.description(NO_SLASHES_NO_CONTROL_CHARACTERS_DESCRIPTION); | ||
} | ||
|
||
/** | ||
* Returns a new builder containing the given message for the given JSON pointers. | ||
* | ||
* @param jsonPointer The JSON pointer the message is about. | ||
* @param description The description to be in the exception. | ||
* @return a builder for {@code JsonPointerInvalidException} objects. | ||
*/ | ||
public static JsonExceptionBuilder<JsonPointerInvalidException> newBuilderWithDescription( | ||
final CharSequence jsonPointer, final String description) { | ||
return new Builder() | ||
.jsonPointer(jsonPointer) | ||
.description(description); | ||
} | ||
|
||
|
||
/** | ||
* Returns a new builder already containing a default message that the JSON pointer is no valid. | ||
* | ||
* @param jsonPointer The JSON pointer the message is about. | ||
* @return a builder for {@code JsonPointerInvalidException} objects. | ||
*/ | ||
public static JsonExceptionBuilder<JsonPointerInvalidException> newBuilderWithoutDescription( | ||
final CharSequence jsonPointer) { | ||
return new Builder() | ||
.jsonPointer(jsonPointer) | ||
.description(DEFAULT_DESCRIPTION); | ||
} | ||
|
||
/** | ||
* A mutable builder for a {@code JsonPointerInvalidException}. | ||
*/ | ||
@NotThreadSafe | ||
public static final class Builder extends AbstractJsonExceptionBuilder<JsonPointerInvalidException> { | ||
|
||
private Builder() { | ||
super(ERROR_CODE); | ||
description(DEFAULT_DESCRIPTION); | ||
} | ||
|
||
/** | ||
* Sets a message which points to the name of the invalid JSON pointer. Thus if this method is called, {@link | ||
* #message(String)} should not be called. | ||
* | ||
* @param jsonPointerString the string representation of the invalid JSON pointer. | ||
* @return this builder to allow method chaining. | ||
*/ | ||
public Builder jsonPointer(@Nullable final CharSequence jsonPointerString) { | ||
message(MessageFormat.format("The JSON pointer <{0}> is invalid!", jsonPointerString)); | ||
return this; | ||
} | ||
|
||
@Override | ||
protected JsonPointerInvalidException doBuild(final String errorCode, | ||
@Nullable final String message, | ||
@Nullable final String description, | ||
@Nullable final Throwable cause, | ||
@Nullable final URI href) { | ||
|
||
return new JsonPointerInvalidException(message, description, cause, href); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2017 Contributors to the Eclipse Foundation | ||
~ | ||
~ See the NOTICE file(s) distributed with this work for additional | ||
~ information regarding copyright ownership. | ||
~ | ||
~ This program and the accompanying materials are made available under the | ||
~ terms of the Eclipse Public License 2.0 which is available at | ||
~ http://www.eclipse.org/legal/epl-2.0 | ||
~ | ||
~ SPDX-License-Identifier: EPL-2.0 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.eclipse.ditto</groupId> | ||
<artifactId>ditto-model</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>ditto-model-base</artifactId> | ||
<packaging>bundle</packaging> | ||
<name>Eclipse Ditto :: Model :: Base</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test-jar</goal> | ||
</goals> | ||
<configuration> | ||
<includes> | ||
<include>org/eclipse/ditto/model/base/assertions/*</include> | ||
</includes> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Import-Package> | ||
!org.eclipse.ditto.utils.jsr305.annotations, | ||
org.eclipse.ditto.* | ||
</Import-Package> | ||
<Export-Package> | ||
org.eclipse.ditto.model.base.* | ||
</Export-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>com.github.siom79.japicmp</groupId> | ||
<artifactId>japicmp-maven-plugin</artifactId> | ||
<configuration> | ||
<parameter> | ||
<excludes> | ||
<!-- Don't add excludes here before checking with the whole Ditto team --> | ||
<!--<exclude></exclude>--> | ||
</excludes> | ||
</parameter> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>9</source> | ||
<target>9</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.