Skip to content

Package: LayeredResourceFileSystem

LayeredResourceFileSystem

nameinstructionbranchcomplexitylinemethod
LayeredResourceFileSystem(List, FileSystemProvidersProvider)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
as(As.Type)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
as(Class)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
asMany(As.Type)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
asMany(Class)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createDecoratorFile(ResourceFile)
M: 2 C: 37
95%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 8
89%
M: 0 C: 1
100%
findFileByPath(String)
M: 19 C: 47
71%
M: 3 C: 3
50%
M: 3 C: 1
25%
M: 6 C: 13
68%
M: 0 C: 1
100%
getRoot()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
maybeAs(As.Type)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
maybeAs(Class)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.filesystem.basic.layered;
28:
29: import javax.annotation.CheckForNull;
30: import javax.annotation.Nonnull;
31: import java.util.IdentityHashMap;
32: import java.util.List;
33: import java.util.ListIterator;
34: import java.io.IOException;
35: import it.tidalwave.util.As;
36: import it.tidalwave.northernwind.core.model.ResourceFile;
37: import it.tidalwave.northernwind.core.model.ResourceFileSystemProvider;
38: import it.tidalwave.northernwind.core.model.spi.DecoratedResourceFileSystem;
39: import it.tidalwave.northernwind.frontend.filesystem.basic.FileSystemProvidersProvider;
40: import lombok.RequiredArgsConstructor;
41: import lombok.experimental.Delegate;
42: import lombok.extern.slf4j.Slf4j;
43:
44: /***********************************************************************************************************************
45: *
46: * @author Fabrizio Giudici
47: *
48: **********************************************************************************************************************/
49: @RequiredArgsConstructor @Slf4j
50: public class LayeredResourceFileSystem implements DecoratedResourceFileSystem
51: {
52: @Nonnull
53: private final List<ResourceFileSystemProvider> delegates;
54:
55: private final FileSystemProvidersProvider fileSystemProvidersProvider;
56:
57: private final IdentityHashMap<ResourceFile, ResourceFile> delegateLightWeightMap = new IdentityHashMap<>();
58:
59: @Delegate
60: private final As asSupport = As.forObject(this);
61:
62: /*******************************************************************************************************************
63: *
64: * {@inheritDoc}
65: *
66: ******************************************************************************************************************/
67: @Override @Nonnull
68: public ResourceFile getRoot()
69: {
70: return findFileByPath("");
71: }
72:
73: /*******************************************************************************************************************
74: *
75: * {@inheritDoc}
76: *
77: ******************************************************************************************************************/
78: @Override @CheckForNull
79: public ResourceFile findFileByPath (@Nonnull final String name)
80: {
81: log.trace("findResource({})", name);
82: ResourceFile result = null;
83:
84: // FIXME: move to init!
85:• if (fileSystemProvidersProvider != null)
86: {
87: delegates.clear();
88: final var fileSystemProviders = fileSystemProvidersProvider.getFileSystemProviders();
89: delegates.addAll(fileSystemProviders);
90: }
91:
92: for (final ListIterator<? extends ResourceFileSystemProvider> i = delegates.listIterator(delegates.size());
93:• i.hasPrevious(); )
94: {
95: try
96: {
97: final var fileSystem = i.previous().getFileSystem();
98: final var fileObject = fileSystem.findFileByPath(name);
99:
100:• if (fileObject != null)
101: {
102: log.trace(">>>> fileSystem: {}, fileObject: {}", fileSystem, fileObject.getPath());
103: result = createDecoratorFile(fileObject);
104: break;
105: }
106: }
107: catch (IOException e)
108: {
109: log.warn("", e);
110: }
111: }
112:
113: log.trace(">>>> returning {}", result);
114:
115: return result;
116: }
117:
118: /*******************************************************************************************************************
119: *
120: * {@inheritDoc}
121: *
122: ******************************************************************************************************************/
123: @Override @Nonnull
124: public synchronized ResourceFile createDecoratorFile (@Nonnull final ResourceFile delegateFile)
125: {
126:• if (delegateFile == null)
127: {
128: return null;
129: }
130:
131: var decorator = delegateLightWeightMap.get(delegateFile);
132:
133:• if (decorator == null)
134: {
135:• decorator = (delegateFile.isData() ? new DecoratorResourceFile(this, delegateFile)
136: : new DecoratorResourceFolder(this,
137: delegates,
138: delegateFile.getPath(),
139: delegateFile));
140: delegateLightWeightMap.put(delegateFile, decorator);
141: }
142:
143: return decorator;
144: }
145: }