feat: 自動でインスタンスを生成できるように

This commit is contained in:
usbharu 2024-09-26 00:05:29 +09:00
parent ed26581655
commit 722ad284b0
Signed by: usbharu
GPG Key ID: 95CBCF7046307B77
8 changed files with 112 additions and 94 deletions

View File

@ -1,6 +1,7 @@
package dev.usbharu.activitystreams.impl.model.activity package dev.usbharu.activitystreams.impl.model.activity
import dev.usbharu.activitystreams.model.ImageOrLink import dev.usbharu.activitystreams.model.ImageOrLink
import dev.usbharu.activitystreams.model.JsonLdWrapper
import dev.usbharu.activitystreams.model.ObjectOrLink import dev.usbharu.activitystreams.model.ObjectOrLink
import dev.usbharu.activitystreams.model.UriOrLink import dev.usbharu.activitystreams.model.UriOrLink
import dev.usbharu.activitystreams.model.activity.Create import dev.usbharu.activitystreams.model.activity.Create
@ -12,39 +13,40 @@ import java.time.Duration
import java.time.OffsetDateTime import java.time.OffsetDateTime
class CreateImpl( class CreateImpl(
override var type: List<URI>, override var type: List<URI> = emptyList(),
override var `object`: ObjectOrLink?, override var `object`: ObjectOrLink? = null,
override var actor: List<ObjectOrLink>, override var actor: List<ObjectOrLink> = emptyList(),
override var target: List<ObjectOrLink>, override var target: List<ObjectOrLink> = emptyList(),
override var result: ObjectOrLink?, override var result: ObjectOrLink? = null,
override var origin: ObjectOrLink?, override var origin: ObjectOrLink? = null,
override var instrument: ObjectOrLink?, override var instrument: ObjectOrLink? = null,
override var attachment: List<ObjectOrLink>, override var attachment: List<ObjectOrLink> = emptyList(),
override var attributedTo: List<ObjectOrLink>, override var attributedTo: List<ObjectOrLink> = emptyList(),
override var audience: List<ObjectOrLink>, override var audience: List<ObjectOrLink> = emptyList(),
override var content: LangString?, override var content: LangString? = null,
override var context: List<ObjectOrLink>, override var context: List<ObjectOrLink> = emptyList(),
override var name: LangString?, override var name: LangString? = null,
override var endTime: OffsetDateTime?, override var endTime: JsonLdWrapper<OffsetDateTime>? = null,
override var generator: List<ObjectOrLink>, override var generator: List<ObjectOrLink> = emptyList(),
override var icon: List<ImageOrLink>, override var icon: List<ImageOrLink> = emptyList(),
override var image: List<ImageOrLink>, override var image: List<ImageOrLink> = emptyList(),
override var inReplyTo: List<ObjectOrLink>, override var inReplyTo: List<ObjectOrLink> = emptyList(),
override var location: ObjectOrLink?, override var location: ObjectOrLink? = null,
override var preview: ObjectOrLink?, override var preview: ObjectOrLink? = null,
override var published: OffsetDateTime?, override var published: JsonLdWrapper<OffsetDateTime>? = null,
override var replies: Collection?, override var replies: Collection? = null,
override var startTime: OffsetDateTime?, override var startTime: JsonLdWrapper<OffsetDateTime>? = null,
override var summary: LangString?, override var summary: LangString? = null,
override var tag: List<ObjectOrLink>, override var tag: List<ObjectOrLink> = emptyList(),
override var updated: OffsetDateTime?, override var updated: JsonLdWrapper<OffsetDateTime>? = null,
override var url: List<UriOrLink>, override var url: List<UriOrLink> = emptyList(),
override var to: List<ObjectOrLink>, override var to: List<ObjectOrLink> = emptyList(),
override var bto: List<ObjectOrLink>, override var bto: List<ObjectOrLink> = emptyList(),
override var cc: List<ObjectOrLink>, override var cc: List<ObjectOrLink> = emptyList(),
override var bcc: List<ObjectOrLink>, override var bcc: List<ObjectOrLink> = emptyList(),
override var mediaType: MimeMediaType?, override var mediaType: MimeMediaType? = null,
override var duration: Duration?, override var duration: JsonLdWrapper<Duration>? = null,
override var id: URI?, override var id: URI? = null,
override var source: ObjectOrLink? override var source: ObjectOrLink? = null,
override var value: Any? = null,
) : Create ) : Create

View File

@ -1,6 +1,7 @@
package dev.usbharu.activitystreams.impl.model.actor package dev.usbharu.activitystreams.impl.model.actor
import dev.usbharu.activitystreams.model.ImageOrLink import dev.usbharu.activitystreams.model.ImageOrLink
import dev.usbharu.activitystreams.model.JsonLdWrapper
import dev.usbharu.activitystreams.model.ObjectOrLink import dev.usbharu.activitystreams.model.ObjectOrLink
import dev.usbharu.activitystreams.model.UriOrLink import dev.usbharu.activitystreams.model.UriOrLink
import dev.usbharu.activitystreams.model.actor.Person import dev.usbharu.activitystreams.model.actor.Person
@ -12,50 +13,51 @@ import java.time.Duration
import java.time.OffsetDateTime import java.time.OffsetDateTime
class PersonImpl( class PersonImpl(
override var type: List<URI>, override var type: List<URI> = emptyList(),
override var attachment: List<ObjectOrLink>, override var attachment: List<ObjectOrLink> = emptyList(),
override var attributedTo: List<ObjectOrLink>, override var attributedTo: List<ObjectOrLink> = emptyList(),
override var audience: List<ObjectOrLink>, override var audience: List<ObjectOrLink> = emptyList(),
override var content: LangString?, override var content: LangString? = null,
override var context: List<ObjectOrLink>, override var context: List<ObjectOrLink> = emptyList(),
override var name: LangString?, override var name: LangString? = null,
override var endTime: OffsetDateTime?, override var endTime: JsonLdWrapper<OffsetDateTime>? = null,
override var generator: List<ObjectOrLink>, override var generator: List<ObjectOrLink> = emptyList(),
override var icon: List<ImageOrLink>, override var icon: List<ImageOrLink> = emptyList(),
override var image: List<ImageOrLink>, override var image: List<ImageOrLink> = emptyList(),
override var inReplyTo: List<ObjectOrLink>, override var inReplyTo: List<ObjectOrLink> = emptyList(),
override var location: ObjectOrLink?, override var location: ObjectOrLink? = null,
override var preview: ObjectOrLink?, override var preview: ObjectOrLink? = null,
override var published: OffsetDateTime?, override var published: JsonLdWrapper<OffsetDateTime>? = null,
override var replies: Collection?, override var replies: Collection? = null,
override var startTime: OffsetDateTime?, override var startTime: JsonLdWrapper<OffsetDateTime>? = null,
override var summary: LangString?, override var summary: LangString? = null,
override var tag: List<ObjectOrLink>, override var tag: List<ObjectOrLink> = emptyList(),
override var updated: OffsetDateTime?, override var updated: JsonLdWrapper<OffsetDateTime>? = null,
override var url: List<UriOrLink>, override var url: List<UriOrLink> = emptyList(),
override var to: List<ObjectOrLink>, override var to: List<ObjectOrLink> = emptyList(),
override var bto: List<ObjectOrLink>, override var bto: List<ObjectOrLink> = emptyList(),
override var cc: List<ObjectOrLink>, override var cc: List<ObjectOrLink> = emptyList(),
override var bcc: List<ObjectOrLink>, override var bcc: List<ObjectOrLink> = emptyList(),
override var mediaType: MimeMediaType?, override var mediaType: MimeMediaType? = null,
override var duration: Duration?, override var duration: JsonLdWrapper<Duration>? = null,
override var id: URI?, override var id: URI? = null,
override var source: ObjectOrLink?, override var source: ObjectOrLink? = null,
override var endpoints: List<URI>, override var endpoints: List<URI> = emptyList(),
override var following: URI?, override var following: URI? = null,
override var followers: URI?, override var followers: URI? = null,
override var inbox: URI?, override var inbox: URI? = null,
override var outbox: URI?, override var outbox: URI? = null,
override var liked: URI?, override var liked: URI? = null,
override var shared: URI?, override var shared: URI? = null,
override var likes: URI?, override var likes: URI? = null,
override var oauthAuthorizationEndpoint: URI?, override var oauthAuthorizationEndpoint: URI? = null,
override var oauthTokenEndpoint: URI?, override var oauthTokenEndpoint: URI? = null,
override var preferredUsername: String?, override var preferredUsername: String? = null,
override var provideClientKey: URI?, override var provideClientKey: URI? = null,
override var proxyUrl: URI?, override var proxyUrl: URI? = null,
override var sharedInbox: URI?, override var sharedInbox: URI? = null,
override var signClientKey: URI?, override var signClientKey: URI? = null,
override var streams: URI?, override var streams: URI? = null,
override var alsoKnownAs: List<URI> override var alsoKnownAs: List<URI> = emptyList(),
override var value: Any? = null
) : Person ) : Person

View File

@ -1,10 +1,16 @@
package dev.usbharu.activitystreams.impl.type package dev.usbharu.activitystreams.impl.type
import dev.usbharu.activitystreams.impl.model.activity.CreateImpl
import dev.usbharu.activitystreams.model.JsonLd import dev.usbharu.activitystreams.model.JsonLd
import java.net.URI import java.net.URI
class TypeFactory { class TypeFactory {
fun factory(uri: String): List<JsonLd> {
val map = mutableMapOf<URI, () -> JsonLd>(
URI.create("https://www.w3.org/ns/activitystreams#Create") to { CreateImpl() }
)
fun factory(uri: URI): JsonLd? {
return map[uri]?.invoke()
} }
} }

View File

@ -5,5 +5,5 @@ import java.net.URI
interface JsonLd { interface JsonLd {
var type: List<URI> var type: List<URI>
var id: URI? var id: URI?
var value: Any var value: Any?
} }

View File

@ -0,0 +1,7 @@
package dev.usbharu.activitystreams.model
import java.net.URI
class JsonLdWrapper<T>(override var type: List<URI>, override var id: URI?, value: T?) : JsonLd {
override var value: Any? = value
}

View File

@ -1,11 +1,9 @@
package dev.usbharu.activitystreams.model.core package dev.usbharu.activitystreams.model.core
import dev.usbharu.activitystreams.model.ImageOrLink import dev.usbharu.activitystreams.model.*
import dev.usbharu.activitystreams.model.JsonLd
import dev.usbharu.activitystreams.model.ObjectOrLink
import dev.usbharu.activitystreams.model.UriOrLink
import dev.usbharu.activitystreams.model.other.LangString import dev.usbharu.activitystreams.model.other.LangString
import dev.usbharu.activitystreams.model.other.MimeMediaType import dev.usbharu.activitystreams.model.other.MimeMediaType
import java.net.URI
import java.time.Duration import java.time.Duration
import java.time.OffsetDateTime import java.time.OffsetDateTime
@ -16,25 +14,25 @@ interface Object : ObjectOrLink, JsonLd {
var content: LangString? var content: LangString?
var context: List<ObjectOrLink> var context: List<ObjectOrLink>
var name: LangString? var name: LangString?
var endTime: OffsetDateTime? var endTime: JsonLdWrapper<OffsetDateTime>?
var generator: List<ObjectOrLink> var generator: List<ObjectOrLink>
var icon: List<ImageOrLink> var icon: List<ImageOrLink>
var image: List<ImageOrLink> var image: List<ImageOrLink>
var inReplyTo: List<ObjectOrLink> var inReplyTo: List<ObjectOrLink>
var location: ObjectOrLink? var location: ObjectOrLink?
var preview: ObjectOrLink? var preview: ObjectOrLink?
var published: OffsetDateTime? var published: JsonLdWrapper<OffsetDateTime>?
var replies: Collection? var replies: Collection?
var startTime: OffsetDateTime? var startTime: JsonLdWrapper<OffsetDateTime>?
var summary: LangString? var summary: LangString?
var tag: List<ObjectOrLink> var tag: List<ObjectOrLink>
var updated: OffsetDateTime? var updated: JsonLdWrapper<OffsetDateTime>?
var url: List<UriOrLink> var url: List<UriOrLink>
var to: List<ObjectOrLink> var to: List<ObjectOrLink>
var bto: List<ObjectOrLink> var bto: List<ObjectOrLink>
var cc: List<ObjectOrLink> var cc: List<ObjectOrLink>
var bcc: List<ObjectOrLink> var bcc: List<ObjectOrLink>
var mediaType: MimeMediaType? var mediaType: MimeMediaType?
var duration: Duration? var duration: JsonLdWrapper<Duration>?
var source: ObjectOrLink? var source: ObjectOrLink?
} }

View File

@ -1,8 +1,9 @@
package dev.usbharu.activitystreams.model.other package dev.usbharu.activitystreams.model.other
import dev.usbharu.activitystreams.model.JsonLd
import java.util.Locale import java.util.Locale
interface LangString : Map<String, String> { interface LangString : Map<String, String>,JsonLd {
fun getValue(): String? fun getValue(): String?
fun getValueByLanguageTag(locale: Locale): String? fun getValueByLanguageTag(locale: Locale): String?
} }

View File

@ -1,4 +1,6 @@
package dev.usbharu.activitystreams.model.other package dev.usbharu.activitystreams.model.other
interface MimeMediaType { import dev.usbharu.activitystreams.model.JsonLd
interface MimeMediaType : JsonLd {
} }