-
Notifications
You must be signed in to change notification settings - Fork 188
/
PrismSerializer.java
118 lines (104 loc) · 3.81 KB
/
PrismSerializer.java
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
/*
* Copyright (c) 2010-2016 Evolveum
*
* Licensed 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 com.evolveum.midpoint.prism;
import com.evolveum.midpoint.prism.xnode.RootXNode;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.exception.SchemaException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
/**
* Takes care of serializing prism objects and other beans, i.e. converts java form to
* lexical representation (XML/JSON/YAML strings, DOM tree) or intermediate one (XNode).
*
* @author mederly
*/
public interface PrismSerializer<T> {
/**
* Sets the name of the root element. Can be done either here or during call to serialize(..) methods.
*
* @param elementName Name of the root element
* @return Serializer with the root element name set.
*/
@NotNull
PrismSerializer<T> root(QName elementName);
/**
* Sets the item definition to be used during serialization.
* (Not much used.)
* @param itemDefinition
* @return
*/
@NotNull
PrismSerializer<T> definition(ItemDefinition itemDefinition);
/**
* Sets the context for the serialization operation, containing e.g. serialization options.
*
* @param context Context to be set.
* @return Serializer with the context set.
*/
@NotNull
PrismSerializer<T> context(@Nullable SerializationContext context);
/**
* Sets the serialization options (part of the context).
*
* @param options Options to be set.
* @return Serializer with the options set.
*/
@NotNull
PrismSerializer<T> options(@Nullable SerializationOptions options);
/**
* Serializes given prism item.
*
* @param item Item to be serialized.
* @return String/RootXNode representation of the item.
*/
@NotNull
T serialize(@NotNull Item<?, ?> item) throws SchemaException;
/**
* Serializes given prism value (property, reference, or container).
* Name of the root element is derived in the following way:
* 1. if explicit name is set (
* @param value Value to be serialized.
* @return String/RootXNode representation of the value.
*/
@NotNull
T serialize(@NotNull PrismValue value) throws SchemaException;
/**
* Serializes given prism value (property, reference, or container).
* @param value Value to be serialized.
* @param rootName Name of the root element. (Overrides other means of deriving the name.)
* @return String/RootXNode representation of the value.
*/
@NotNull
T serialize(@NotNull PrismValue value, QName rootName) throws SchemaException;
@NotNull
T serialize(@NotNull RootXNode xnode) throws SchemaException;
/**
* Serializes an atomic value - i.e. something that fits into a prism property (if such a property would exist).
*
* value Value to be serialized.
* elementName Element name to be used.
*
* BEWARE, currently works only for values that can be processed via PrismBeanConvertor - i.e. not for special
* cases like PolyStringType, ProtectedStringType, etc.
*/
T serialize(JAXBElement<?> value) throws SchemaException;
T serializeRealValue(Object value) throws SchemaException;
T serializeRealValue(Object value, QName rootName) throws SchemaException;
T serializeAnyData(Object value) throws SchemaException;
T serializeAnyData(Object value, QName rootName) throws SchemaException;
}