-
Notifications
You must be signed in to change notification settings - Fork 14
/
Descriptor.java
166 lines (149 loc) · 6.03 KB
/
Descriptor.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
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
package cz.cvut.kbss.jopa.model.descriptors;
import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
import java.net.URI;
import java.util.Collection;
import java.util.Set;
/**
* Used to specify additional metadata for entities and their attributes.
* <p>
* Descriptors are composed in a hierarchical structure representing the object graph they describe.
*/
public interface Descriptor {
/**
* Gets contexts for this descriptor.
* <p>
* An empty result indicates the default context.
* <p>
* Note that for saving, there must be at most one context.
*
* @return Context URIs
*/
Set<URI> getContexts();
/**
* Adds the specified context to this descriptor.
* <p>
* Note that adding the default context removes all the previously added contexts, as they become obsolete.
*
* @param context Context to add, {@code null} indicates default context
* @return This instance
*/
Descriptor addContext(URI context);
/**
* Gets the language set for this descriptor.
*
* @return Language tag (e.g. en, cs), can be {@code null}, meaning any language is supported or the language tag
* has not been set (see {@link #hasLanguage()})
*/
String getLanguage();
/**
* Gets information about whether language tag has been set on this descriptor.
* <p>
* The language tag can be explicitly set to {@code null}, meaning any language is supported. This can be used to
* override PU-level language setting.
*
* @return {@code true} if a language tag has been set on this descriptor, {@code false} otherwise
*/
boolean hasLanguage();
/**
* Sets language tag of this descriptor.
* <p>
* Applies to any possible sub-descriptors as well.
*
* @param languageTag The language tag to use, possibly {@code null}, meaning no language preference should be used
* @return This instance
* @see #anyLanguage()
*/
Descriptor setLanguage(String languageTag);
/**
* Configures this descriptor to support any language tag (including no language tags).
* <p>
* This is useful for overriding previously set language tag expectations (either on PU level or parent descriptor
* level).
* <p>
* This does the same as calling {@link #setLanguage(String)} with {@code null} argument, but is more explicit.
*
* @return This instance
*/
Descriptor anyLanguage();
/**
* Gets attribute descriptors specified in this descriptor.
*
* @return Unmodifiable view of attribute descriptors
*/
Collection<Descriptor> getAttributeDescriptors();
/**
* Gets descriptor for the specified attribute.
*
* @param attribute Entity attribute, as specified by the application metamodel
* @return Descriptor
* @throws IllegalArgumentException If the descriptor is not available
*/
Descriptor getAttributeDescriptor(FieldSpecification<?, ?> attribute);
/**
* Gets contexts in which the property assertion(s) of the specified attribute are stored.
* <p>
* If none are specified for the attribute, contexts of this descriptor are returned.
* <p>
* Note that for saving a property assertion, there must be at most one context.
*
* @param attribute Entity attribute, as specified by the application model
* @return Context identifiers
*/
Set<URI> getAttributeContexts(FieldSpecification<?, ?> attribute);
/**
* Adds descriptor for the specified attribute.
* <p>
* If a descriptor already exists for the specified attribute, it is overridden by the new one.
*
* @param attribute The attribute to set descriptor for
* @param descriptor The descriptor to use
* @return This instance
*/
Descriptor addAttributeDescriptor(FieldSpecification<?, ?> attribute, Descriptor descriptor);
/**
* Adds repository context for the specified attribute.
* <p>
* This in effect means creating a descriptor (if it does not already exist) for the specified field and adding the
* specified context to it.
*
* @param attribute The attribute to set context for
* @param context The context to set
* @return This instance
* @see #addAttributeDescriptor(FieldSpecification, Descriptor)
*/
Descriptor addAttributeContext(FieldSpecification<?, ?> attribute, URI context);
/**
* Sets language to be used when working (retrieving, persisting) with values of the specified attribute.
* <p>
* Note that setting language in this manner will not have any effect on descriptors of the specified attribute
* previously retrieved from this descriptor.
*
* @param attribute The attribute concerned
* @param languageTag Language tag to use, possibly {@code null}
* @return This instance
*/
Descriptor setAttributeLanguage(FieldSpecification<?, ?> attribute, String languageTag);
/**
* Whether property assertion should be stored in the subject's context (default), or whether they should be stored
* together with the assertion value.
* <p>
* This applies to object references, literal values are always stored in the specified context.
*
* @return Whether property assertion is stored in the subject context
*/
boolean areAssertionsInSubjectContext();
/**
* Whether this descriptor overrides assertion context.
* <p>
* Assertions are typically stored in the subject context, even if their target is in a different context (see
* {@link #areAssertionsInSubjectContext()}). However, literal values have to be stored in the assertion context
* only, so descriptors of fields holding literal values can override the default assertion target context to use
* the field descriptor context for assertion as well.
*
* @return Boolean indicating whether assertion context is based on object descriptor
* @see #areAssertionsInSubjectContext()
*/
default boolean overridesAssertionContext() {
return false;
}
}