Skip to content

Package: Attribute

Attribute

nameinstructionbranchcomplexitylinemethod
isAssociation()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model.metamodel;
16:
17: import cz.cvut.kbss.jopa.NonJPA;
18: import cz.cvut.kbss.jopa.UnusedJPA;
19: import cz.cvut.kbss.jopa.model.IRI;
20: import cz.cvut.kbss.jopa.model.annotations.CascadeType;
21: import cz.cvut.kbss.jopa.model.annotations.ParticipationConstraint;
22:
23: /**
24: * Represents an attribute of a Java type.
25: *
26: * @param <X> The represented type that contains the attribute
27: * @param <Y> The type of the represented attribute
28: */
29: public interface Attribute<X, Y> extends FieldSpecification<X, Y> {
30:
31: enum PersistentAttributeType {
32: /**
33: * Corresponds to datatype properties
34: */
35: @NonJPA
36: DATA,
37:
38: /**
39: * Corresponds to object properties
40: */
41: @NonJPA
42: OBJECT,
43:
44: /**
45: * Corresponds to annotation properties
46: */
47: @NonJPA
48: ANNOTATION
49: }
50:
51: /**
52: * Return the persistent attribute type for the attribute.
53: *
54: * @return persistent attribute type
55: */
56: PersistentAttributeType getPersistentAttributeType();
57:
58: /**
59: * Return the java.lang.reflect.Member for the represented attribute.
60: *
61: * @return corresponding java.lang.reflect.Member
62: */
63: @UnusedJPA
64: java.lang.reflect.Member getJavaMember();
65:
66: /**
67: * Returns the {@link IRI} identifier of the property mapped by this attribute.
68: *
69: * @return Property IRI
70: */
71: @NonJPA
72: IRI getIRI();
73:
74: /**
75: * Return the set of cascade types specified for this attribute.
76: *
77: * @return corresponding array of cascade types. This method returns an empty array if no cascade type is specified.
78: * @throws IllegalArgumentException if getPersistentAttributeType() returns DATA or ANNOTATION.
79: */
80: @NonJPA
81: CascadeType[] getCascadeTypes();
82:
83: /**
84: * Is the attribute an association.
85: *
86: * @return boolean indicating whether the attribute corresponds to an association
87: */
88: default boolean isAssociation() {
89: return getPersistentAttributeType().equals(PersistentAttributeType.OBJECT);
90: }
91:
92: /**
93: * Whether the attribute can be without value.
94: * <p>
95: * Note that if {@link #getConstraints()} contains {@link ParticipationConstraint}s, this property should be
96: * ignored.
97: *
98: * @return boolean indicating whether the attribute can be empty
99: */
100: boolean isNonEmpty();
101:
102: /**
103: * Does the attribute contain values in lexical form.
104: * <p>
105: * Applies only to datatype and annotation properties, object properties cannot be in lexical form.
106: *
107: * @return Boolean indicating whether the attribute contains values in lexical form
108: */
109: boolean isLexicalForm();
110:
111: /**
112: * Gets the explicitly specified identifier of the attribute datatype.
113: * <p>
114: * Note that the returned value may be {@code null} in case the datatype is not explicitly specified and automatic
115: * datatype resolution provided by the underlying OntoDriver is used. {@code null} is also returned for object property
116: * attributes, as this does not apply to them.
117: *
118: * @return Datatype identifier, possibly {@code null}
119: */
120: String getDatatype();
121:
122: /**
123: * Does the attribute represent simple literals.
124: * <p>
125: * Simple literals are stored as {@code xsd:string}, i.e., strings without language tag.
126: * <p>
127: * Applies only to datatype and annotation properties, object properties cannot be simple literals.
128: *
129: * @return Boolean indicating whether the attribute represents simple literals.
130: */
131: boolean isSimpleLiteral();
132:
133: /**
134: * Indicates whether a language is specified for this attribute.
135: * <p>
136: * Note that language applies only to String-based data or annotation property attribute values, for which {@code
137: * rdfs:langString} values will be read and its language tag compared to the one required.
138: * <p>
139: * Also note that if the attribute is a simple literal or in lexical form only, it has no language and this method
140: * will return false.
141: *
142: * @return Boolean indicating whether language is specified for this attribute
143: */
144: boolean hasLanguage();
145:
146: /**
147: * Gets the language configured for this attribute.
148: * <p>
149: * Note that language applies only to String-based data or annotation property attribute values, for which {@code
150: * rdfs:langString} values will be read and its language tag compared to the one required.
151: * <p>
152: * If no language is specified directly for the attribute, persistence unit-level language setting is used.
153: *
154: * @return Language configured for this attribute, {@code null} if none is set
155: * @see #hasLanguage()
156: */
157: String getLanguage();
158:
159: /**
160: * Returns participation constraints specified for this attribute.
161: *
162: * @return Array of participation constraints
163: */
164: ParticipationConstraint[] getConstraints();
165: }