This commit is contained in:
usbharu 2024-10-02 15:02:15 +09:00
parent 3538e9e973
commit fb0d3c41b6
Signed by: usbharu
GPG Key ID: 8CB1087135660B8D
6 changed files with 42 additions and 7 deletions

View File

@ -1,12 +1,13 @@
package dev.usbharu.activitystreams.impl.builder package dev.usbharu.activitystreams.impl.builder
import dev.usbharu.activitystreams.impl.type.AbstractJsonObjectBuilder
import dev.usbharu.activitystreams.impl.type.BuilderContext import dev.usbharu.activitystreams.impl.type.BuilderContext
import dev.usbharu.activitystreams.impl.type.JsonObjectBuilder import dev.usbharu.activitystreams.impl.type.JsonObjectBuilder
import dev.usbharu.activitystreams.model.JsonLd import dev.usbharu.activitystreams.model.JsonLd
import java.net.URI import java.net.URI
open class JsonLdBuilder : JsonObjectBuilder<JsonLd> { open class JsonLdBuilder : AbstractJsonObjectBuilder<JsonLd>() {
override fun build(t: JsonLd, jsonObject: Map<String, Any>, builderContext: BuilderContext) { override fun internalBuild(t: JsonLd, jsonObject: Map<String, Any>, builderContext: BuilderContext) {
t.value = jsonObject["@value"] t.value = jsonObject["@value"]
t.id = jsonObject["@id"]?.toString()?.let { URI.create(it) } t.id = jsonObject["@id"]?.toString()?.let { URI.create(it) }
t.type = (jsonObject["@type"] as? List<String>).orEmpty().map { URI.create(it) } t.type = (jsonObject["@type"] as? List<String>).orEmpty().map { URI.create(it) }

View File

@ -1,13 +1,23 @@
package dev.usbharu.activitystreams.impl.builder package dev.usbharu.activitystreams.impl.builder
import dev.usbharu.activitystreams.impl.type.AbstractJsonObjectBuilder
import dev.usbharu.activitystreams.impl.type.BuilderContext import dev.usbharu.activitystreams.impl.type.BuilderContext
import dev.usbharu.activitystreams.impl.type.JsonObjectBuilder import dev.usbharu.activitystreams.impl.type.JsonObjectBuilder
import dev.usbharu.activitystreams.model.JsonLd import dev.usbharu.activitystreams.model.JsonLd
import dev.usbharu.activitystreams.model.core.Object import dev.usbharu.activitystreams.model.core.Object
import dev.usbharu.activitystreams.model.other.LangString
import java.net.URI
class ObjectBuilder : JsonObjectBuilder<Object> { open class ObjectBuilder : AbstractJsonObjectBuilder<Object>() {
override fun build(t: Object, jsonObject: Map<String, Any>, builderContext: BuilderContext) { override fun build(t: Object, jsonObject: Map<String, Any>, builderContext: BuilderContext) {
// t.name = // t.name =
} }
override fun internalBuild(t: Object, jsonObject: Map<String, Any>, builderContext: BuilderContext) {
val langString = builderContext.typeFactory().factory(URI.create("")) as LangString
builderContext.getBuilder(LangString::class.java)
.build(langString, jsonObject["https://www.w3.org/ns/activitystreams#name"], builderContext)
t.name =
}
} }

View File

@ -1,10 +1,16 @@
package dev.usbharu.activitystreams.impl.model.other package dev.usbharu.activitystreams.impl.model.other
import dev.usbharu.activitystreams.model.other.LangString import dev.usbharu.activitystreams.model.other.LangString
import java.net.URI
import java.util.* import java.util.*
class LangStringImpl(private val value: String?, private val map: Map<String, String>) : LangString { class LangStringImpl(
override fun getValue(): String? = value override var value: Any?,
private val map: Map<String, String>,
override var type: List<URI> = emptyList(),
override var id: URI? = null
) : LangString {
override fun getValue(): String? = value?.toString()
override fun getValueByLanguageTag(locale: Locale): String? = map[locale.toLanguageTag()] override fun getValueByLanguageTag(locale: Locale): String? = map[locale.toLanguageTag()]

View File

@ -0,0 +1,12 @@
package dev.usbharu.activitystreams.impl.type
abstract class AbstractJsonObjectBuilder<T : Any> : JsonObjectBuilder<T> {
override fun build(t: T, jsonObject: Map<String, Any>, builderContext: BuilderContext) {
val superclass = t.javaClass.superclass
if (superclass != Any::class.java) {
builderContext.getBuilder<T>(superclass).build(t, jsonObject, builderContext)
}
}
protected abstract fun internalBuild(t: T, jsonObject: Map<String, Any>, builderContext: BuilderContext)
}

View File

@ -1,7 +1,13 @@
package dev.usbharu.activitystreams.impl.type package dev.usbharu.activitystreams.impl.type
import dev.usbharu.activitystreams.model.JsonLd
class BuilderContext { class BuilderContext {
fun <T> getBuilder():JsonObjectBuilder<T>{ fun <T : Any> getBuilder(clazz: Class<in T>): JsonObjectBuilder<T> {
TODO()
}
fun typeFactory(): TypeFactory {
TODO() TODO()
} }
} }

View File

@ -1,6 +1,6 @@
package dev.usbharu.activitystreams.impl.type package dev.usbharu.activitystreams.impl.type
interface JsonObjectBuilder<T> { interface JsonObjectBuilder<T:Any> {
fun build(t: T, jsonObject: Map<String,Any>, builderContext: BuilderContext) fun build(t: T, jsonObject: Map<String,Any>, builderContext: BuilderContext)
} }
// todo Abstract classでスーパークラスのjsonobjectbuilderを自動で呼び出す部分を作る // todo Abstract classでスーパークラスのjsonobjectbuilderを自動で呼び出す部分を作る