Skip to content

Commit 584a93a

Browse files
committed
[refactor] Processed feedback review - java21 upgrade
1 parent 654f237 commit 584a93a

File tree

9 files changed

+107
-197
lines changed

9 files changed

+107
-197
lines changed

exist-core/src/main/java/org/exist/security/internal/RealmImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.exist.EXistException;
3030
import org.exist.config.Configuration;
3131
import org.exist.config.ConfigurationException;
32-
import org.exist.config.Reference;
3332
import org.exist.config.ReferenceImpl;
3433
import org.exist.security.AXSchemaType;
3534
import org.exist.security.AbstractAccount;
@@ -91,7 +90,7 @@ protected RealmImpl(final DBBroker broker, final SecurityManagerImpl sm, final C
9190

9291
//DBA group
9392
GROUP_DBA = new GroupImpl(broker, this, DBA_GROUP_ID, SecurityManager.DBA_GROUP);
94-
GROUP_DBA.setManagers(new ArrayList<>(Arrays.asList(new ReferenceImpl<>(sm, "getAccount", SecurityManager.DBA_USER))));
93+
GROUP_DBA.setManagers(new ArrayList<>(List.of(new ReferenceImpl<>(sm, "getAccount", SecurityManager.DBA_USER))));
9594
GROUP_DBA.setMetadataValue(EXistSchemaType.DESCRIPTION, "Database Administrators");
9695
sm.registerGroup(GROUP_DBA);
9796
registerGroup(GROUP_DBA);
@@ -105,11 +104,9 @@ protected RealmImpl(final DBBroker broker, final SecurityManagerImpl sm, final C
105104

106105
//guest group
107106
GROUP_GUEST = new GroupImpl(broker, this, GUEST_GROUP_ID, SecurityManager.GUEST_GROUP);
108-
GROUP_GUEST.setManagers(new ArrayList<>() {
109-
{
110-
add(new ReferenceImpl<>(sm, "getAccount", SecurityManager.DBA_USER));
111-
}
112-
});
107+
GROUP_GUEST.setManagers(new ArrayList<>(
108+
List.of(new ReferenceImpl<>(sm, "getAccount", SecurityManager.DBA_USER))
109+
));
113110
GROUP_GUEST.setMetadataValue(EXistSchemaType.DESCRIPTION, "Anonymous Users");
114111
sm.registerGroup(GROUP_GUEST);
115112
registerGroup(GROUP_GUEST);
@@ -268,7 +265,7 @@ public boolean deleteGroup(final Group group) throws PermissionDeniedException,
268265
}
269266

270267
@Override
271-
public Subject authenticate(final String accountName, Object credentials) throws AuthenticationException {
268+
public Subject authenticate(final String accountName, final Object credentials) throws AuthenticationException {
272269
final Account account = getAccount(accountName);
273270

274271
if(account == null) {

exist-core/src/main/java/org/exist/storage/NativeBroker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import javax.xml.stream.XMLStreamException;
8686
import java.io.*;
8787
import java.net.URI;
88+
import java.nio.charset.StandardCharsets;
8889
import java.nio.file.Files;
8990
import java.nio.file.Path;
9091
import java.nio.file.Paths;
@@ -722,7 +723,7 @@ private XmldbURI prepend(final XmldbURI uri) {
722723
.map(h -> h.resolve("etc").resolve(INIT_COLLECTION_CONFIG))
723724
.orElse(Paths.get("etc").resolve(INIT_COLLECTION_CONFIG));
724725
if (Files.exists(fInitCollectionConfig)) {
725-
return Files.readString(fInitCollectionConfig);
726+
return Files.readString(fInitCollectionConfig, UTF_8);
726727
}
727728

728729
// 2) fallback to attempting to load from classpath

exist-core/src/main/java/org/exist/xmldb/AbstractRemoteResource.java

Lines changed: 24 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,15 @@ public Properties getProperties() {
8282
}
8383

8484
@Override
85-
public Object getContent()
86-
throws XMLDBException {
87-
final Object res = getExtendedContent();
88-
if (res != null) {
89-
switch (res) {
90-
case byte[] bytes -> {
91-
return res;
92-
}
93-
case Path path1 -> {
94-
return readFile(path1);
95-
}
96-
case File file1 -> {
97-
return readFile(file1.toPath());
98-
}
99-
case InputSource source -> {
100-
return readFile(source);
101-
}
102-
case ContentFile contentFile1 -> {
103-
return contentFile1.getBytes();
104-
}
105-
default -> {
106-
}
107-
}
108-
}
109-
return res;
85+
public Object getContent() throws XMLDBException {
86+
return switch (getExtendedContent()) {
87+
case byte[] bytes -> bytes;
88+
case Path path -> readFile(path);
89+
case File file -> readFile(file.toPath());
90+
case InputSource inputSource -> readFile(inputSource);
91+
case ContentFile contentFile -> contentFile.getBytes();
92+
default -> null;
93+
};
11094
}
11195

11296
/**
@@ -119,49 +103,29 @@ public Object getContent()
119103
* @deprecated instead use {@link org.xmldb.api.base.Resource#getContent()}
120104
*/
121105
@Deprecated
122-
protected byte[] getData()
123-
throws XMLDBException {
124-
final Object res = getExtendedContent();
125-
if (res != null) {
126-
switch (res) {
127-
case Path path1 -> {
128-
return readFile(path1);
129-
}
130-
case File file1 -> {
131-
return readFile(file1.toPath());
132-
}
133-
case InputSource source -> {
134-
return readFile(source);
135-
}
136-
case String s -> {
137-
return s.getBytes(UTF_8);
138-
}
139-
case ContentFile contentFile1 -> {
140-
return contentFile1.getBytes();
141-
}
142-
default -> {
143-
}
144-
}
145-
}
146-
147-
return (byte[]) res;
106+
protected byte[] getData() throws XMLDBException {
107+
return switch (getExtendedContent()) {
108+
case Path path -> readFile(path);
109+
case File file -> readFile(file.toPath());
110+
case InputSource inputSource -> readFile(inputSource);
111+
case String string -> string.getBytes(UTF_8);
112+
case ContentFile contentFile -> contentFile.getBytes();
113+
case null, default -> null;
114+
};
148115
}
149116

150117
@Override
151-
public long getContentLength()
152-
throws XMLDBException {
118+
public long getContentLength() throws XMLDBException {
153119
return contentLen;
154120
}
155121

156122
@Override
157-
public Instant getCreationTime()
158-
throws XMLDBException {
123+
public Instant getCreationTime() throws XMLDBException {
159124
return dateCreated;
160125
}
161126

162127
@Override
163-
public Instant getLastModificationTime()
164-
throws XMLDBException {
128+
public Instant getLastModificationTime() throws XMLDBException {
165129
return dateModified;
166130
}
167131

@@ -182,8 +146,7 @@ public void setLastModificationTime(final Instant dateModified) throws XMLDBExce
182146
}
183147
}
184148

185-
public long getExtendedContentLength()
186-
throws XMLDBException {
149+
public long getExtendedContentLength() throws XMLDBException {
187150
return contentLen;
188151
}
189152

@@ -193,8 +156,7 @@ public String getMimeType() {
193156
}
194157

195158
@Override
196-
public Collection getParentCollection()
197-
throws XMLDBException {
159+
public Collection getParentCollection() throws XMLDBException {
198160
return collection;
199161
}
200162

@@ -203,8 +165,7 @@ public Permission getPermissions() {
203165
return permissions;
204166
}
205167

206-
protected boolean setContentInternal(final Object value)
207-
throws XMLDBException {
168+
protected boolean setContentInternal(final Object value) throws XMLDBException {
208169

209170
boolean wasSet = false;
210171
try {

exist-core/src/main/java/org/exist/xquery/XPathUtil.java

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -90,64 +90,41 @@ public static final Sequence javaObjectToXPath(Object obj, XQueryContext context
9090
}
9191

9292
public static final Sequence javaObjectToXPath(Object obj, XQueryContext context,
93-
boolean expandChars, final Expression expression) throws XPathException {
93+
boolean expandChars, final Expression expression) throws XPathException {
9494

95-
switch (obj) {
96-
case null -> {
97-
//return Sequence.EMPTY_SEQUENCE;
98-
return null;
99-
//return Sequence.EMPTY_SEQUENCE;
100-
}
101-
case Sequence sequence -> {
102-
return sequence;
103-
}
104-
case String s -> {
105-
final StringValue v = new StringValue(expression, s);
106-
return (expandChars ? v.expand() : v);
107-
}
108-
case Boolean b -> {
109-
return BooleanValue.valueOf(b);
110-
}
111-
case Float v -> {
112-
return new FloatValue(expression, v);
113-
}
114-
case Double v -> {
115-
return new DoubleValue(expression, v);
116-
}
117-
case Short aShort -> {
118-
return new IntegerValue(expression, aShort, Type.SHORT);
119-
}
120-
case Integer integer -> {
121-
return new IntegerValue(expression, integer, Type.INT);
122-
}
123-
case Long l -> {
124-
return new IntegerValue(expression, l, Type.LONG);
125-
}
126-
case BigInteger bigInteger -> {
127-
return new IntegerValue(expression, bigInteger);
128-
}
129-
case BigDecimal bigDecimal -> {
130-
return new DecimalValue(expression, bigDecimal);
131-
}
132-
case byte[] bytes -> {
133-
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new UnsynchronizedByteArrayInputStream(bytes), expression);
95+
return switch (obj) {
96+
case null -> null; //return Sequence.EMPTY_SEQUENCE;
97+
case Sequence sequence -> sequence;
98+
case String stringValue -> {
99+
final StringValue v = new StringValue(expression, stringValue);
100+
yield (expandChars ? v.expand() : v);
134101
}
102+
case Boolean booleanValue -> BooleanValue.valueOf(booleanValue);
103+
case Float floatValue -> new FloatValue(expression, floatValue);
104+
case Double doubleValue -> new DoubleValue(expression, doubleValue);
105+
case Short shortValue -> new IntegerValue(expression, shortValue, Type.SHORT);
106+
case Integer integerValue -> new IntegerValue(expression, integerValue, Type.INT);
107+
case Long longValue -> new IntegerValue(expression, longValue, Type.LONG);
108+
case BigInteger bigInteger -> new IntegerValue(expression, bigInteger);
109+
case BigDecimal bigDecimal -> new DecimalValue(expression, bigDecimal);
110+
case byte[] bytes ->
111+
BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(),
112+
new UnsynchronizedByteArrayInputStream(bytes), expression);
135113
case ResourceSet resourceSet -> {
136114
final Sequence seq = new AVLTreeNodeSet();
137115
try {
138116
final DBBroker broker = context.getBroker();
139-
for (final ResourceIterator it = ((ResourceSet) obj).getIterator(); it.hasMoreResources(); ) {
117+
for (final ResourceIterator it = resourceSet.getIterator(); it.hasMoreResources(); ) {
140118
seq.add(getNode(broker, (XMLResource) it.nextResource(), expression));
141119
}
142120
} catch (final XMLDBException xe) {
143121
throw new XPathException(expression, "Failed to convert ResourceSet to node: " + xe.getMessage());
144122
}
145-
return seq;
123+
yield seq;
146124

147125
}
148-
case XMLResource xmlResource -> {
149-
return getNode(context.getBroker(), xmlResource, expression);
150-
}
126+
case XMLResource xmlResource -> getNode(context.getBroker(), xmlResource, expression);
127+
151128
case Node node -> {
152129
context.pushDocumentContext();
153130
final DOMStreamer streamer = (DOMStreamer) SerializerPool.getInstance().borrowObject(DOMStreamer.class);
@@ -156,16 +133,14 @@ public static final Sequence javaObjectToXPath(Object obj, XQueryContext context
156133
builder.startDocument();
157134
final DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(expression, builder);
158135
streamer.setContentHandler(receiver);
159-
streamer.serialize((Node) obj, false);
160-
if (obj instanceof Document) {
161-
return builder.getDocument();
136+
streamer.serialize(node, false);
137+
if (node instanceof Document) {
138+
yield builder.getDocument();
162139
} else {
163-
return builder.getDocument().getNode(1);
140+
yield builder.getDocument().getNode(1);
164141
}
165142
} catch (final SAXException e) {
166-
throw new XPathException(expression,
167-
"Failed to transform node into internal model: "
168-
+ e.getMessage());
143+
throw new XPathException(expression, "Failed to transform node into internal model: " + e.getMessage());
169144
} finally {
170145
context.popDocumentContext();
171146
SerializerPool.getInstance().returnObject(streamer);
@@ -185,7 +160,7 @@ public static final Sequence javaObjectToXPath(Object obj, XQueryContext context
185160
for (Object o : objects) {
186161
seq.add((Item) javaObjectToXPath(o, context, expandChars, expression));
187162
}
188-
return seq;
163+
yield seq;
189164

190165
}
191166
case NodeList nodeList -> {
@@ -197,20 +172,17 @@ public static final Sequence javaObjectToXPath(Object obj, XQueryContext context
197172
final DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(expression, builder);
198173
streamer.setContentHandler(receiver);
199174
final ValueSequence seq = new ValueSequence();
200-
final NodeList nl = (NodeList) obj;
201175
int last = builder.getDocument().getLastNode();
202-
for (int i = 0; i < nl.getLength(); i++) {
203-
final Node n = nl.item(i);
176+
for (int i = 0; i < nodeList.getLength(); i++) {
177+
final Node n = nodeList.item(i);
204178
streamer.serialize(n, false);
205179
final NodeImpl created = builder.getDocument().getNode(last + 1);
206180
seq.add(created);
207181
last = builder.getDocument().getLastNode();
208182
}
209-
return seq;
183+
yield seq;
210184
} catch (final SAXException e) {
211-
throw new XPathException(expression,
212-
"Failed to transform node into internal model: "
213-
+ e.getMessage());
185+
throw new XPathException(expression, "Failed to transform node into internal model: " + e.getMessage());
214186
} finally {
215187
context.popDocumentContext();
216188
SerializerPool.getInstance().returnObject(streamer);
@@ -230,13 +202,12 @@ public static final Sequence javaObjectToXPath(Object obj, XQueryContext context
230202
for (Object arrayItem : array) {
231203
seq.add((Item) javaObjectToXPath(arrayItem, context, expandChars, expression));
232204
}
233-
return seq;
205+
yield seq;
234206

235207
}
236-
default -> {
237-
return new JavaObjectValue(obj);
238-
}
239-
}
208+
default -> new JavaObjectValue(obj);
209+
210+
};
240211
}
241212

242213
public static final int javaClassToXPath(Class<?> clazz) {

0 commit comments

Comments
 (0)