Skip to content

Commit 47cc555

Browse files
committed
App selector
1 parent 7ba4ecc commit 47cc555

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

framework/src/main/kotlin/com/neva/javarel/framework/api/rest/Controller.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.neva.javarel.framework.api.rest
22

33
import com.neva.javarel.communication.rest.api.UrlGenerator
44
import com.neva.javarel.foundation.api.injection.Osgi
5+
import com.neva.javarel.framework.api.structure.App
56
import com.neva.javarel.presentation.asset.api.Asset
67
import com.neva.javarel.presentation.view.api.View
78
import com.neva.javarel.resource.api.ResourceResolver
@@ -15,6 +16,9 @@ abstract class Controller {
1516
@Inject
1617
protected lateinit var guard: Guard
1718

19+
@Osgi
20+
protected lateinit var app: App
21+
1822
@Osgi
1923
protected lateinit var dbAdmin: DatabaseAdmin
2024

@@ -37,7 +41,8 @@ abstract class Controller {
3741

3842
protected val context: Map<String, Any> by lazy {
3943
mapOf(
40-
"guard" to guard
44+
"guard" to guard,
45+
"app" to app
4146
)
4247
}
4348

framework/src/main/kotlin/com/neva/javarel/framework/api/structure/App.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package com.neva.javarel.framework.api.structure
22

33
interface App {
44

5-
val modules: Set<Module>
5+
val modules: List<Module>
66

77
}

framework/src/main/kotlin/com/neva/javarel/framework/impl/structure/MultiModuleApp.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.neva.javarel.framework.impl.structure
22

3-
import com.google.common.collect.Sets
43
import com.neva.javarel.framework.api.structure.App
54
import com.neva.javarel.framework.api.structure.Module
65
import org.apache.felix.scr.annotations.*
@@ -16,10 +15,10 @@ class MultiModuleApp : App {
1615
policy = ReferencePolicy.DYNAMIC,
1716
policyOption = ReferencePolicyOption.GREEDY
1817
)
19-
private val allModules = Sets.newConcurrentHashSet<Module>(TreeSet<Module>({ m1, m2 -> m1.priority.compareTo(m2.priority) }))
18+
private val allModules = Collections.synchronizedSortedSet(TreeSet<Module>({ m1, m2 -> m1.priority.compareTo(m2.priority) }))
2019

21-
override val modules: Set<Module>
22-
get() = allModules.toSet()
20+
override val modules: List<Module>
21+
get() = allModules.toList()
2322

2423
protected fun bindModule(module: Module) {
2524
allModules.add(module)

presentation/view/pebble/src/main/kotlin/com/neva/javarel/presentation/view/pebble/functions/ServiceFunction.kt

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ import com.neva.javarel.presentation.view.api.ViewException
55

66
class ServiceFunction(val osgiUtils: OsgiUtils) : BaseFunction() {
77

8+
companion object {
9+
const val CLASS_ARG = "class"
10+
}
11+
12+
override fun getArgumentNames(): MutableList<String> {
13+
return mutableListOf(CLASS_ARG)
14+
}
15+
816
override fun execute(args: Map<String, Any>): Any {
9-
val serviceClass = firstArgument(args) as String
17+
val serviceClass = args.get(CLASS_ARG) as String?
18+
if (serviceClass.isNullOrBlank()) {
19+
throw ViewException("OSGi service class cannot be empty.")
20+
}
21+
22+
val service = osgiUtils.serviceOf<Any>(serviceClass!!)
23+
if (service == null) {
24+
throw ViewException("OSGi service '$serviceClass' cannot be found.")
25+
}
1026

11-
return osgiUtils.serviceOf(serviceClass) ?: throw ViewException("OSGi service '$serviceClass' cannot be found.")
27+
return service
1228
}
1329

1430
}

0 commit comments

Comments
 (0)