-
-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathDataManager.java
More file actions
189 lines (173 loc) · 8.18 KB
/
Copy pathDataManager.java
File metadata and controls
189 lines (173 loc) · 8.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.data;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.data.persistence.DataBuilder;
import org.spongepowered.api.data.persistence.DataContainer;
import org.spongepowered.api.data.persistence.DataContentUpdater;
import org.spongepowered.api.data.persistence.DataSerializable;
import org.spongepowered.api.data.persistence.DataTranslator;
import org.spongepowered.api.data.persistence.DataView;
import java.util.Optional;
/**
* A manager of the overall Data API. This handles the registration of
* {@link DataSerializable}s and their {@link DataBuilder}s,
* {@link DataRegistration}s, etc.
*
* <p>Note that this manager powers not just serialization and deserialization,
* but also powers a majority of the Data API.</p>
*/
public interface DataManager {
/**
* Registers a {@link DataBuilder} that will dynamically build
* the given {@link DataSerializable} from a {@link DataContainer}.
*
* <p>Builders may not always exist for a given {@link DataSerializable},
* nor is it guaranteed that a provided builder will function with all
* {@link DataContainer}s.
* </p>
*
* @param clazz The class of the {@link DataSerializable}
* @param builder The builder that can build the data serializable
* @param <T> The type of data serializable
*/
<T extends DataSerializable> void registerBuilder(Class<T> clazz, DataBuilder<T> builder);
/**
* Registers a {@link DataContentUpdater} for the desired
* {@link DataSerializable} such that any versioned data may be updated to
* newer versions for the most up to date {@link DataBuilder}.
*
* @param clazz The data serializable class
* @param updater The updater
* @param <T> The type of DataSerializable
*/
<T extends DataSerializable> void registerContentUpdater(Class<T> clazz, DataContentUpdater updater);
/**
* Gets a wrapped fake {@link DataContentUpdater} that may wrap several
* {@link DataContentUpdater}s to translate versioned data from the desired
* {@code fromVersion} to the {@code toVersion}. If the version jump is too
* great or a {@link DataContentUpdater} has not been registered to cover
* the complete jump, {@link Optional#empty()} may be returned.
*
* @param clazz The data serializable class
* @param fromVersion The version converting from
* @param toVersion The version converting to
* @param <T> The type of data serializable
* @return The content updater, if available
*/
<T extends DataSerializable> Optional<DataContentUpdater> wrappedContentUpdater(Class<T> clazz, int fromVersion, int toVersion);
/**
* Attempts to retrieve the {@link DataBuilder} for the desired
* {@link DataSerializable} class.
*
* <p>Builders may not always exist for a given {@link DataSerializable},
* nor is it guaranteed that a provided builder will function with all
* {@link DataContainer}s.</p>
*
* @param clazz The class of the data serializable
* @param <T> The type of data serializable
* @return The builder, if available
*/
<T extends DataSerializable> Optional<DataBuilder<T>> builder(Class<T> clazz);
/**
* Attempts to translate an instance of the {@link DataSerializable} from
* the provided {@link DataView}. If there is no {@link DataBuilder}
* registered for the provided {@link DataSerializable}, then
* {@link Optional#empty()} may be returned.
*
* @param clazz The class of the data serializable
* @param dataView The data view containing raw data
* @param <T> The type of data serializable
* @return The data serializable, if available
*/
<T extends DataSerializable> Optional<T> deserialize(Class<T> clazz, DataView dataView);
/**
* Registers the given {@link org.spongepowered.api.data.DataHolder.Immutable} class with it's
* associated {@link org.spongepowered.api.data.DataHolderBuilder.Immutable}. The builder can be used to
* create new instances of the given {@link org.spongepowered.api.data.DataHolder.Immutable} for data
* retrieval, data representation, etc.
*
* @param holderClass The class of the immutable data holder
* @param builder The builder instance of the immutable data holder
* @param <T> The type of immutable data holder
* @param <B> The type of immutable data builder
*/
<T extends DataHolder.Immutable<T>, B extends DataHolderBuilder.Immutable<T, B>> void register(Class<T> holderClass, B builder);
/**
* Registers a legacy {@code id} that is used by a previous version of
* {@link DataRegistration} from a plugin such that the custom data can
* be read by a plugin-data datastore.
*
* @param legacyId The legacy id
* @param dataStoreKey The dataStore key set in {@link org.spongepowered.api.data.persistence.DataStore.Builder#pluginData(ResourceKey)}
*/
void registerLegacyManipulatorIds(String legacyId, ResourceKey dataStoreKey);
/**
* Attempts to retrieve the builder for the given
* {@link org.spongepowered.api.data.DataHolder.Immutable}.
*
* <p>If the {@link org.spongepowered.api.data.DataHolder.Immutable} was not registered, multiple
* systems could fail to retrieve specific data.</p>
*
* @param holderClass The immutable data holder class
* @param <T> The type of immutable data holder
* @param <B> The type of immutable data builder
* @return The builder, if available
*/
<T extends DataHolder.Immutable<T>, B extends DataHolderBuilder.Immutable<T, B>> Optional<B> immutableBuilder(Class<T> holderClass);
/**
* Gets the desired {@link DataTranslator} for the provided class.
*
* @param objectClass The class of the object
* @param <T> The type of object
* @return The data translator, if available
*/
<T> Optional<DataTranslator<T>> translator(Class<T> objectClass);
/**
* Registers a {@link DataTranslator} for the desired class.
*
* @param objectClass The class of the object type being managed
* @param translator The translator for the desired class object
* @param <T> The type of object
*/
<T> void registerTranslator(Class<T> objectClass, DataTranslator<T> translator);
/**
* Creates a new {@link DataContainer} with a default
* {@link org.spongepowered.api.data.persistence.DataView.SafetyMode} of
* {@link org.spongepowered.api.data.persistence.DataView.SafetyMode#ALL_DATA_CLONED}.
*
* @return A new data container
*/
DataContainer createContainer();
/**
* Creates a new {@link DataContainer} with the provided
* {@link org.spongepowered.api.data.persistence.DataView.SafetyMode}.
*
* @param safety The safety mode to use
* @see org.spongepowered.api.data.persistence.DataView.SafetyMode
* @return A new data container with the provided safety mode
*/
DataContainer createContainer(DataView.SafetyMode safety);
}