READY
state. When the operation is started, the observable will enter the
35 | * RUNNING
state. Finally, depending on the operation outcome, the observable will always enter one of the
36 | * following states: SUCCEEDED
, FAILED
, REMOVED
or CANCELLED
. When
37 | * an exception was thrown during the operation, it will enter the FAILED
state. When the observable is a
38 | * {@link GluonObservableObject} and it is passed in as a parameter to the {@link DataProvider#removeObject(GluonObservableObject, ObjectDataRemover) remove method},
39 | * then the object will enter the REMOVED
state when the remove operation succeeded successfully. When the
40 | * operation was cancelled, the state of the observable will be changed to CANCELLED
. Signaling the
41 | * cancellation of an operation is done by throwing a {@link java.util.concurrent.CancellationException}. In all other
42 | * cases, the state will become SUCCEEDED
.
43 | */
44 | public enum ConnectState {
45 | /**
46 | * This is the initial state of a new GluonObservable object. It will remain
47 | * in the READY
state until the first synchronization operation is started.
48 | */
49 | READY,
50 | /**
51 | * A GluonObservable object in the RUNNING
state means that a
52 | * synchronization operation is currently in progress.
53 | */
54 | RUNNING,
55 | /**
56 | * A GluonObservable object in the FAILED
state signals that the last
57 | * executed synchronization operation failed. You can check the {@link GluonObservable#getException() exception}
58 | * to find out more about the reason of the failure.
59 | */
60 | FAILED,
61 | /**
62 | * A GluonObservable object in the SUCCEEDED
state signals that the last
63 | * executed synchronization operation completed successfully.
64 | */
65 | SUCCEEDED,
66 | /**
67 | * A GluonObservable object in the CANCELLED
state signals that the last
68 | * executed synchronization operation was cancelled. Cancellation is most likely caused
69 | * by a user that cancels an action that is required to proceed with the operation. For
70 | * example, when an operation requires an authenticated user, that operation is cancelled
71 | * when the user aborts the authentication process.
72 | */
73 | CANCELLED,
74 | /**
75 | * A GluonObservable object in the REMOVED
state signals that it is
76 | * successfully removed after executing the {@link DataProvider#removeObject(GluonObservableObject, ObjectDataRemover)} remove operation}.
77 | * The REMOVED
state is only applicable to {@link GluonObservableObject} because
78 | * a {@link GluonObservableList} can not be removed.
79 | */
80 | REMOVED
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/ConnectStateEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect;
28 |
29 | import javafx.beans.NamedArg;
30 | import javafx.event.Event;
31 | import javafx.event.EventType;
32 |
33 | public class ConnectStateEvent extends Event {
34 |
35 | /**
36 | * Common supertype for all worker state event types.
37 | */
38 | public static final EventTypenull
will be returned.
75 | *
76 | * @return the exception, if one has occurred; otherwise null.
77 | */
78 | Throwable getException();
79 |
80 | /**
81 | * Holds the exception that was thrown when a synchronization operation failed.
82 | *
83 | * @return the exception, if one has occurred; otherwise null.
84 | */
85 | ReadOnlyObjectPropertytargetClass
.
47 | *
48 | * @param targetClass The class defining the objects being converted from JSON.
49 | */
50 | public JsonInputConverter(ClasstargetClass
in the constructor equals to JsonObject.class, then this method will just return the
57 | * read JSON object directly instead of running the conversion. Otherwise, a {@link JsonConverter} will be used to
58 | * convert the JSON Object into the final object to return.
59 | *
60 | * @return An object converted from the JSON Object that was read from the InputStream.
61 | */
62 | @Override
63 | public T read() {
64 | try (JsonReader reader = JsonUtil.createJsonReader(getInputStream())) {
65 | JsonObject jsonObject = reader.readObject();
66 | if (JsonObject.class.isAssignableFrom(converter.getTargetClass())) {
67 | return (T) jsonObject;
68 | } else {
69 | return converter.readFromJson(jsonObject);
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/converter/JsonIterableInputConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.converter;
28 |
29 | import com.gluonhq.impl.connect.converter.JsonUtil;
30 |
31 | import javax.json.JsonArray;
32 | import javax.json.JsonObject;
33 | import javax.json.JsonReader;
34 | import java.util.Iterator;
35 |
36 | /**
37 | * An IterableInputConverter that converts a JSON Array read from an InputStream into an Iterator that can be used to
38 | * iterate over a list of objects. The actual conversion from JSON to an object is handled by an instance of
39 | * {@link JsonConverter}.
40 | *
41 | * @param targetClass
.
54 | *
55 | * The targetClass
can be any of the types listed below. All other types will be converted from
56 | * JSON by using a {@link JsonConverter}.
true
if the iteration has more elements, in this case if there are more elements to be
115 | * returned from the JSON Array that was read from the InputStream.
116 | *
117 | * @return true
if there are more items available in the Iterator, false
otherwise.
118 | */
119 | @Override
120 | public boolean hasNext() {
121 | return index < jsonArray.size();
122 | }
123 |
124 | /**
125 | * Returns an Iterator that loops over the items in the JSON Array that is read from the InputStream. This
126 | * implementation returns itself as the Iterator. Each element inside the JSON Array will be converted into the
127 | * correct object when the {@link #next} method is called.
128 | *
129 | * @return An Iterator that can be used to loop over the objects that are contained in the JSON Array that was read
130 | * from the InputStream.
131 | */
132 | @Override
133 | public IteratortargetClass
into JSON Objects and write them into the OutputStream.
54 | *
55 | * @param targetClass The class defining the objects being converted into JSON.
56 | */
57 | public JsonOutputConverter(ClasstargetClass
in the constructor equals to JsonObject.class, then this method will cast the provided
64 | * object into a JsonObject instance and write it directly to the OutputStream. Otherwise, a {@link JsonConverter}
65 | * will be used to convert the object into a JSON Object.
66 | *
67 | * @param t The object to convert into a JSON Object that will be written to the OutputStream.
68 | */
69 | @Override
70 | public void write(T t) {
71 | try (JsonWriter writer = writerFactory.createWriter(getOutputStream())) {
72 | JsonObject jsonObject;
73 | if (JsonObject.class.isAssignableFrom(converter.getTargetClass())) {
74 | jsonObject = (JsonObject) t;
75 | } else {
76 | jsonObject = converter.writeToJson(t);
77 | }
78 |
79 | if (LOG.isLoggable(Level.FINE)) {
80 | StringWriter stringWriter = new StringWriter();
81 | try (JsonWriter writer2 = writerFactory.createWriter(stringWriter)) {
82 | writer2.writeObject(jsonObject);
83 | LOG.log(Level.FINE, "Written JSON data: " + stringWriter.toString());
84 | }
85 | }
86 |
87 | writer.writeObject(jsonObject);
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/converter/OutputConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.converter;
28 |
29 | /**
30 | * An OutputConverter is a Converter that is able to write an object to a certain output source. The actual source is
31 | * not defined on this interface and is thus completely left open for the implementations to define.
32 | *
33 | * @param null
.
43 | *
44 | * @return A null
object.
45 | */
46 | @Override
47 | public Void read() {
48 | try (InputStream inputStream = getInputStream()) {
49 | int read;
50 | byte[] bytes = new byte[4096];
51 | while ((read = inputStream.read(bytes)) != -1) {
52 | // ignore read bytes
53 | }
54 | } catch (IOException ex) {
55 | LOGGER.log(Level.SEVERE, "Something went wrong while reading data from InputStream.", ex);
56 | }
57 |
58 | return null;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/converter/VoidOutputConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.converter;
28 |
29 | import java.io.IOException;
30 | import java.io.OutputStream;
31 | import java.util.logging.Level;
32 | import java.util.logging.Logger;
33 |
34 | /**
35 | * An OutputConverter that doesn't write anything to an OutputStream.
36 | */
37 | public class VoidOutputConverter extends OutputStreamOutputConverternull
.
45 | */
46 | @Override
47 | public void write(Void v) {
48 | try (OutputStream outputStream = getOutputStream()) {
49 | outputStream.close();
50 | } catch (IOException ex) {
51 | LOGGER.log(Level.SEVERE, "Something went wrong while closing OutputStream.", ex);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/converter/XmlInputConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.converter;
28 |
29 | import com.gluonhq.impl.connect.converter.ClassInspector;
30 | import java.io.IOException;
31 | import java.io.InputStream;
32 | import java.lang.reflect.InvocationTargetException;
33 | import java.lang.reflect.Method;
34 | import java.util.Map;
35 | import java.util.Set;
36 | import java.util.logging.Level;
37 | import java.util.logging.Logger;
38 | import javax.xml.parsers.DocumentBuilder;
39 | import javax.xml.parsers.DocumentBuilderFactory;
40 | import javax.xml.parsers.ParserConfigurationException;
41 | import org.w3c.dom.Document;
42 | import org.w3c.dom.Node;
43 | import org.w3c.dom.NodeList;
44 | import org.xml.sax.SAXException;
45 |
46 | /**
47 | * An InputConverter that converts a XML Object read from an InputStream into an object.
48 | *
49 | * @param targetClass
.
60 | *
61 | * @param targetClass The class defining the objects being converted from XML.
62 | */
63 | public XmlInputConverter(ClasstargetClass
.
70 | * Often, the XML returned by web services has the relevant information nested or wrapped in rootnodes.
71 | * If there is a 1-1 mapping between the data and the Object, we would end up with unused wrapper classes.
72 | * By specifying the name of the node that contains the relevant information, the wrapping data is ignored.
73 | *
74 | * @param targetClass The class defining the objects being converted from XML.
75 | * @param tag the nodename of the rootnode containing the relevant information.
76 | */
77 | public XmlInputConverter(Classcom.gluonhq.connect.converter
package contains classes that describe how to convert between Java
29 | * objects and a certain data format.
30 | */
31 | package com.gluonhq.connect.converter;
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | /**
28 | * The package containing the base classes of the Gluon Connect framework.
29 | */
30 | package com.gluonhq.connect;
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/provider/BaseRestProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.provider;
28 |
29 | import com.gluonhq.connect.source.RestDataSource;
30 |
31 | import java.util.List;
32 | import java.util.Map;
33 | import java.util.logging.Level;
34 | import java.util.logging.Logger;
35 |
36 | public class BaseRestProvider {
37 |
38 | private static final Logger LOG = Logger.getLogger(BaseRestProvider.class.getName());
39 |
40 | private static final String RESPONSE_HEADER_CONTENT_TYPE = "Content-Type";
41 |
42 | protected static final String CONTENT_TYPE_APPLICATION_JSON = "application/json";
43 | protected static final String CONTENT_TYPE_TEXT_PLAIN = "text/plain";
44 |
45 | protected final RestDataSource dataSource;
46 |
47 | public BaseRestProvider(RestDataSource dataSource) {
48 | this.dataSource = dataSource;
49 | }
50 |
51 | /**
52 | * Returns the rest data source that is used as the input and output data source.
53 | *
54 | * @return the rest data source being used as the input and output data source
55 | */
56 | public RestDataSource getRestDataSource() {
57 | return dataSource;
58 | }
59 |
60 | /**
61 | * Returns the first Content-Type response header from the rest data source. The value of the content type
62 | * can be null
when the response header is not provided by the HTTP response. Note that the method
63 | * {@link RestDataSource#getInputStream()} should already be called before calling this method.
64 | *
65 | * @return the Content-Type response header or null
if the response header is not provided
66 | */
67 | String getContentType() {
68 | String contentType = null;
69 |
70 | MapThe FileClient assists in using the {@link DataProvider} with files, that are located on the local file system, as 41 | * the data source. For instance, to read a file that contains json data, you can use the following code:
42 | * 43 | *44 | * FileClient fileClient = FileClient.create(new File("sample.json")); 45 | * JsonInputConverter<Sample> converter = new JsonInputConverter<>(Sample.class); 46 | * GluonObservableObject<Sample> sample = DataProvider.retrieveObject(fileClient.createObjectDataReader(converter)); 47 | *48 | */ 49 | public class FileClient { 50 | 51 | private File file; 52 | 53 | private FileClient(File file) { 54 | this.file = file; 55 | } 56 | 57 | /** 58 | * Create a FileClient builder using the specified file as a data source. 59 | * 60 | * @param file the file to be used as the data source 61 | * @return a FileClient that can be used together with the {@link DataProvider} 62 | */ 63 | public static FileClient create(File file) { 64 | return new FileClient(file); 65 | } 66 | 67 | /** 68 | * Build a FileDataSource that can be used as an InputDataSource to read from the file or an OutputDataSource to 69 | * write to the file. 70 | * 71 | * @return a FileDataSource that works with the file that was specified on this FileClient 72 | */ 73 | public FileDataSource createFileDataSource() { 74 | return new FileDataSource(file); 75 | } 76 | 77 | /** 78 | * Creates an instance of {@link ObjectDataReader} that can be passed directly in the 79 | * {@link DataProvider#retrieveObject(ObjectDataReader)} method. The object data reader will read the data from 80 | * the file that was specified on this FileClient and convert it into an object by using the specified 81 | *
converter
.
82 | *
83 | * @param converter the converter to use to convert the data read from the file into an object
84 | * @param converter
and writes the converted data into the file that was specified on
95 | * this FileClient.
96 | *
97 | * @param converter the converter to use to convert the object into data to write to the file
98 | * @param converter
.
131 | *
132 | * @param converter the converter to use to convert the data read from the file into a list of objects
133 | * @param observable
object. Otherwise, the value of the
49 | * observable
object will be set to null
. When the remove operation completed
50 | * successfully, the state of the provided observable
will be set to
51 | * {@link com.gluonhq.connect.ConnectState#REMOVED}.
52 | *
53 | * @param observable the observable object that needs to be removed
54 | * @return an optional containing an object that will ultimately be set on the provided GluonObservableObject
55 | * @throws IOException when an exception occurred during the removal process
56 | */
57 | Optionalobject
. The OutputStream of the specified data source will be set on the converter, before calling
70 | * the {@link OutputStreamOutputConverter#write(Object) write} method on the converter.
71 | *
72 | * @param object the object to write
73 | * @return the object that will ultimately be set on the GluonObservableObject
74 | * @throws IOException when an exception occurred during the write process
75 | */
76 | @Override
77 | public Optionalcom.gluonhq.connect.provider
package contains classes that provide convenience methods to map data
29 | * sources with a data format to give access to instances of {@link com.gluonhq.connect.GluonObservable}.
30 | */
31 | package com.gluonhq.connect.provider;
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/source/BasicInputDataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.source;
28 |
29 | import java.io.IOException;
30 | import java.io.InputStream;
31 |
32 | /**
33 | * An implementation of {@link InputDataSource} that takes any generic {@link java.io.InputStream InputStream} as its
34 | * source.
35 | */
36 | public class BasicInputDataSource implements InputDataSource {
37 |
38 | private InputStream inputStream;
39 |
40 | /**
41 | * Construct a BasicInputDataSource that uses the given inputStream
as its source.
42 | *
43 | * @param inputStream the input stream to use as the source for this input data source
44 | */
45 | public BasicInputDataSource(InputStream inputStream) {
46 | this.inputStream = inputStream;
47 | }
48 |
49 | @Override
50 | public InputStream getInputStream() throws IOException {
51 | return inputStream;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/source/BasicOutputDataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.source;
28 |
29 | import java.io.OutputStream;
30 |
31 | /**
32 | * An implementation of {@link OutputDataSource} that takes any generic{@link java.io.OutputStream OutputStream} as its
33 | * source.
34 | */
35 | public class BasicOutputDataSource implements OutputDataSource {
36 |
37 | private OutputStream outputStream;
38 |
39 | /**
40 | * Construct a BasicOutputDataSource that uses the given outputStream
as its source.
41 | *
42 | * @param outputStream the output stream to use as the source for this output data source
43 | */
44 | public BasicOutputDataSource(OutputStream outputStream) {
45 | this.outputStream = outputStream;
46 | }
47 |
48 | @Override
49 | public OutputStream getOutputStream() {
50 | return outputStream;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/source/FileDataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.source;
28 |
29 | import com.gluonhq.connect.provider.FileClient;
30 |
31 | import java.io.File;
32 | import java.io.FileInputStream;
33 | import java.io.FileOutputStream;
34 | import java.io.IOException;
35 | import java.io.InputStream;
36 | import java.io.OutputStream;
37 |
38 | /**
39 | * An implementation of {@link IODataSource} that can read from and write to a file.
40 | *
41 | * Attention: it is advised not to use this class directly, but rather construct it by creating a
42 | * {@link FileClient} and build the FileDataSource with the {@link FileClient#createFileDataSource()} method.
43 | */
44 | public class FileDataSource implements IODataSource {
45 |
46 | private final File file;
47 |
48 | /**
49 | * Create a new FileDataSource instance. The provided file will be used for reading
50 | * from and/or storing data into.
51 | *
52 | * @param file the file to use for reading the data from from or writing the data to
53 | */
54 | public FileDataSource(File file) {
55 | this.file = file;
56 | }
57 |
58 | /**
59 | * Returns the file that this data source is mapped to.
60 | *
61 | * @return the file that this data source will use for reading and writing data
62 | */
63 | public File getFile() {
64 | return file;
65 | }
66 |
67 | /**
68 | * Returns an InputStream that is able to read data from the file that was passed in when
69 | * constructing the FileDataSource.
70 | *
71 | * @return an InputStream that is able to read from the file
72 | * @throws IOException when the InputStream on the file could not be created
73 | */
74 | @Override
75 | public InputStream getInputStream() throws IOException {
76 | return new FileInputStream(file);
77 | }
78 |
79 | /**
80 | * Returns an OutputStream that is able to write data to the file that was passed in when
81 | * constructing the FileDataSource.
82 | *
83 | * @return an OutputStream that is able to write to the file
84 | * @throws IOException when the OutputStream on the file could not be created
85 | */
86 | @Override
87 | public OutputStream getOutputStream() throws IOException {
88 | return new FileOutputStream(file);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/source/IODataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.source;
28 |
29 | /**
30 | * The IODataSource is a convenience interface that extends from both {@link InputDataSource} and
31 | * {@link OutputDataSource} interfaces. This interface can be used where a data source is required
32 | * that can provide an InputStream as well as an OutputStream.
33 | */
34 | public interface IODataSource extends InputDataSource, OutputDataSource {
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/source/InputDataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.source;
28 |
29 | import java.io.IOException;
30 | import java.io.InputStream;
31 |
32 | /**
33 | * An InputDataSource is a class that returns an InputStream that acts as an input source to read data from. Some
34 | * possible sources can be: a file, a REST URL, a Gluon CloudLink object, ...
35 | */
36 | public interface InputDataSource {
37 |
38 | /**
39 | * Returns an InputStream that will be used as the source to read data from.
40 | *
41 | * @return an InputStream that is used as the source to read data from
42 | * @throws IOException when an exception occurred while getting the InputStream
43 | */
44 | InputStream getInputStream() throws IOException;
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/source/OutputDataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.connect.source;
28 |
29 | import java.io.IOException;
30 | import java.io.OutputStream;
31 |
32 | /**
33 | * An OutputDataSource is a class that returns an OutputStream that acts as an output source to write data to. Some
34 | * possible sources can be: a file, a REST URL, a Gluon Cloud object, ...
35 | */
36 | public interface OutputDataSource {
37 |
38 | /**
39 | * Returns the OutputStream that will be used as the source to write data to.
40 | *
41 | * @return an OutputStream that is used as the source to write data to
42 | * @throws IOException when an exception occurred while getting the OutputStream
43 | */
44 | OutputStream getOutputStream() throws IOException;
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/connect/source/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | /**
28 | * The com.gluonhq.connect.source
package contains classes that describe from what sources data can be
29 | * read from or written to.
30 | */
31 | package com.gluonhq.connect.source;
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/impl/connect/OAuth.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.impl.connect;
28 |
29 | import com.gluonhq.connect.MultiValuedMap;
30 |
31 | import javax.crypto.Mac;
32 | import javax.crypto.SecretKey;
33 | import javax.crypto.spec.SecretKeySpec;
34 | import java.io.UnsupportedEncodingException;
35 | import java.net.URLEncoder;
36 | import java.security.GeneralSecurityException;
37 | import java.util.Base64;
38 | import java.util.List;
39 | import java.util.Map;
40 | import java.util.TreeSet;
41 | import java.util.UUID;
42 |
43 | public class OAuth {
44 |
45 | public static final String SIGNATURE = "oauth_signature";
46 | public static final String NONCE = "oauth_nonce";
47 | public static final String VERSION = "oauth_version";
48 | public static final String CONSUMER_KEY = "oauth_consumer_key";
49 | public static final String SIGNATURE_METHOD = "oauth_signature_method";
50 | public static final String TIMESTAMP = "oauth_timestamp";
51 |
52 | public static String getHeader(String method, String url,
53 | MultiValuedMapInputStream
. When the logging level for this class is set
52 | * to {@link Level#FINE}, the JSON content of the InputStream will be written to a String and logged. Otherwise,
53 | * it will just create a JsonReader from a basic InputStreamReader
.
54 | * @param input the InputStream to read the JSON data from
55 | * @return a JsonReader to read the data from the InputStream
56 | */
57 | public static JsonReader createJsonReader(InputStream input) {
58 | Reader sourceReader;
59 | if (LOG.isLoggable(Level.FINE)) {
60 | String string;
61 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"))) {
62 | StringBuilder stringBuilder = new StringBuilder();
63 | String line;
64 | while ((line = reader.readLine()) != null) {
65 | stringBuilder.append(line);
66 | }
67 | string = stringBuilder.toString();
68 | sourceReader = new StringReader(string);
69 |
70 | LOG.fine("Read JSON data: " + string);
71 | } catch (IOException ex) {
72 | LOG.log(Level.SEVERE, "Something went wrong while reading plain text from inputstream.", ex);
73 | return null;
74 | }
75 | } else {
76 | sourceReader = new InputStreamReader(input);
77 | }
78 |
79 | return readerFactory.createReader(sourceReader);
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/gluonhq/impl/connect/event/ConnectEventDispatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Gluon
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | * * Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * * Neither the name of Gluon, any associated website, nor the
13 | * names of its contributors may be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | package com.gluonhq.impl.connect.event;
28 |
29 | import javafx.event.Event;
30 | import javafx.event.EventDispatchChain;
31 | import javafx.event.EventDispatcher;
32 | import javafx.event.EventHandler;
33 | import javafx.event.EventType;
34 |
35 | import java.util.HashMap;
36 | import java.util.Map;
37 |
38 | /**
39 | * An {@code EventDispatcher} which handles {@link com.gluonhq.connect.ConnectStateEvent}'s
40 | * registration and when used in an event dispatch chain it forwards the received
41 | * events to the appropriate registered handlers.
42 | */
43 | public class ConnectEventDispatcher