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