Skip to content

Method: isAssociation()

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