Integrate with the carpenter now it's in core

This commit is contained in:
Katelyn Baker 2017-07-03 16:33:20 +01:00
parent 9ab6a72ea8
commit 4dd37f009e
9 changed files with 163 additions and 154 deletions

View File

@ -113,7 +113,7 @@ data class Schema(val types: List<TypeNotation>) : DescribedType {
fun carpenterSchema(loaders : List<ClassLoader> = listOf<ClassLoader>(ClassLoader.getSystemClassLoader()))
: CarpenterSchemas
{
var rtn = CarpenterSchemas.newInstance()
val rtn = CarpenterSchemas.newInstance()
types.filterIsInstance<CompositeType>().forEach {
it.carpenterSchema(classLoaders = loaders, carpenterSchemas = rtn)
@ -250,7 +250,7 @@ sealed class TypeNotation : DescribedType {
}
}
abstract var name: String
abstract val name: String
abstract val label: String?
abstract val provides: List<String>
abstract val descriptor: Descriptor
@ -328,7 +328,7 @@ data class CompositeType(override var name: String, override val label: String?,
var isCreatable = true
provides.forEach {
if (name.equals(it)) {
if (name == it) {
isInterface = true
return@forEach
}
@ -366,7 +366,7 @@ data class CompositeType(override var name: String, override val label: String?,
}
}
data class RestrictedType(override var name: String, override val label: String?, override val provides: List<String>, val source: String, override val descriptor: Descriptor, val choices: List<Choice>) : TypeNotation() {
data class RestrictedType(override val name: String, override val label: String?, override val provides: List<String>, val source: String, override val descriptor: Descriptor, val choices: List<Choice>) : TypeNotation() {
companion object : DescribedTypeConstructor<RestrictedType> {
val DESCRIPTOR = UnsignedLong(6L or DESCRIPTOR_TOP_32BITS)
@ -409,7 +409,7 @@ data class RestrictedType(override var name: String, override val label: String?
}
}
data class Choice(var name: String, val value: String) : DescribedType {
data class Choice(val name: String, val value: String) : DescribedType {
companion object : DescribedTypeConstructor<Choice> {
val DESCRIPTOR = UnsignedLong(7L or DESCRIPTOR_TOP_32BITS)

View File

@ -1,7 +1,10 @@
package net.corda.core.serialization.carpenter
import net.corda.core.serialization.amqp.CompositeType
import net.corda.core.serialization.amqp.TypeNotation
/**********************************************************************************************************************/
data class CarpenterSchemas (
val carpenterSchemas : MutableList<Schema>,
val dependencies : MutableMap<String, Pair<TypeNotation, MutableList<String>>>,
@ -22,7 +25,61 @@ data class CarpenterSchemas (
dependencies.computeIfAbsent(dependant, { Pair(type, mutableListOf<String>()) }).second.add(dependee)
}
val size
get() = carpenterSchemas.size
}
/**********************************************************************************************************************/
abstract class MetaCarpenterBase (val schemas : CarpenterSchemas) {
private val cc = ClassCarpenter()
val objects = mutableMapOf<String, Class<*>>()
fun step (newObject : Schema) {
objects[newObject.name] = cc.build (newObject)
/* go over the list of everything that had a dependency on the newly
carpented class existing and remove it from their dependency list, If that
list is now empty we have no impediment to carpenting that class up */
schemas.dependsOn.remove(newObject.name)?.forEach { dependent ->
assert (newObject.name in schemas.dependencies[dependent]!!.second)
schemas.dependencies[dependent]?.second?.remove(newObject.name)
/* we're out of blockers so we can now create the type */
if (schemas.dependencies[dependent]?.second?.isEmpty() ?: false) {
(schemas.dependencies.remove (dependent)?.first as CompositeType).carpenterSchema (
classLoaders = listOf<ClassLoader> (
ClassLoader.getSystemClassLoader(),
cc.classloader),
carpenterSchemas = schemas)
}
}
}
abstract fun build()
}
/**********************************************************************************************************************/
class MetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) {
override fun build() {
while (schemas.carpenterSchemas.isNotEmpty()) {
val newObject = schemas.carpenterSchemas.removeAt(0)
step (newObject)
}
}
}
/**********************************************************************************************************************/
class TestMetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) {
override fun build() {
println ("TestMetaCarpenter::build")
if (schemas.carpenterSchemas.isEmpty()) return
step (schemas.carpenterSchemas.removeAt(0))
}
}
/**********************************************************************************************************************/

View File

@ -3,6 +3,8 @@ package net.corda.core.serialization.carpenter
import org.objectweb.asm.Type
import java.util.LinkedHashMap
/**********************************************************************************************************************/
/**
* A Schema represents a desired class.
*/
@ -29,6 +31,8 @@ abstract class Schema(
get() = name.replace(".", "/")
}
/**********************************************************************************************************************/
class ClassSchema(
name: String,
fields: Map<String, Class<out Any?>>,
@ -36,6 +40,8 @@ class ClassSchema(
interfaces: List<Class<*>> = emptyList()
) : Schema (name, fields, superclass, interfaces)
/**********************************************************************************************************************/
class InterfaceSchema(
name: String,
fields: Map<String, Class<out Any?>>,
@ -43,6 +49,8 @@ class InterfaceSchema(
interfaces: List<Class<*>> = emptyList()
) : Schema (name, fields, superclass, interfaces)
/**********************************************************************************************************************/
object CarpenterSchemaFactory {
fun newInstance (
name: String,
@ -54,3 +62,5 @@ object CarpenterSchemaFactory {
if (isInterface) InterfaceSchema (name, fields, superclass, interfaces)
else ClassSchema (name, fields, superclass, interfaces)
}
/**********************************************************************************************************************/

View File

@ -1,4 +1,4 @@
package net.corda.carpenter.test
package net.corda.core.serialization.carpenter.test
import net.corda.core.serialization.amqp.CompositeType
import net.corda.core.serialization.amqp.Field

View File

@ -1,11 +1,11 @@
package net.corda.carpenter
package net.corda.core.serialization.carpenter
import net.corda.core.serialization.carpenter.test.*
import net.corda.core.serialization.CordaSerializable
import net.corda.core.serialization.amqp.*
import org.junit.Test
import kotlin.test.assertEquals
import net.corda.carpenter.test.*
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@ -32,22 +32,22 @@ class CompositeMembers : AmqpCarpenterBase() {
val b = B(A(testA), testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
assert(obj.first is B)
assert(obj.obj is B)
val amqpObj = obj.first as B
val amqpObj = obj.obj as B
assertEquals(testB, amqpObj.b)
assertEquals(testA, amqpObj.a.a)
assertEquals(2, obj.second.schema.types.size)
assert(obj.second.schema.types[0] is CompositeType)
assert(obj.second.schema.types[1] is CompositeType)
assertEquals(2, obj.envelope.schema.types.size)
assert(obj.envelope.schema.types[0] is CompositeType)
assert(obj.envelope.schema.types[1] is CompositeType)
var amqpSchemaA: CompositeType? = null
var amqpSchemaB: CompositeType? = null
for (type in obj.second.schema.types) {
for (type in obj.envelope.schema.types) {
when (type.name.split ("$").last()) {
"A" -> amqpSchemaA = type as CompositeType
"B" -> amqpSchemaB = type as CompositeType
@ -71,7 +71,7 @@ class CompositeMembers : AmqpCarpenterBase() {
assertEquals("b", amqpSchemaB.fields[1].name)
assertEquals("int", amqpSchemaB.fields[1].type)
val metaSchema = obj.second.schema.carpenterSchema()
val metaSchema = obj.envelope.schema.carpenterSchema()
/* if we know all the classes there is nothing to really achieve here */
assert(metaSchema.carpenterSchemas.isEmpty())
@ -95,10 +95,10 @@ class CompositeMembers : AmqpCarpenterBase() {
val b = B(A(testA), testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val amqpSchema = obj.second.schema.curruptName(listOf (classTestName ("A")))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
val amqpSchema = obj.envelope.schema.curruptName(listOf (classTestName ("A")))
assert(obj.first is B)
assert(obj.obj is B)
amqpSchema.carpenterSchema()
}
@ -116,9 +116,9 @@ class CompositeMembers : AmqpCarpenterBase() {
val b = B(A(testA), testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
assert(obj.first is B)
assert(obj.obj is B)
val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("B")))
@ -146,9 +146,9 @@ class CompositeMembers : AmqpCarpenterBase() {
val b = B(A(testA), testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
assert(obj.first is B)
assert(obj.obj is B)
val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B")))
@ -207,9 +207,9 @@ class CompositeMembers : AmqpCarpenterBase() {
val c = C(B(testA, testB), testC)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(c))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(c))
assert(obj.first is C)
assert(obj.obj is C)
val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B")))
@ -233,9 +233,9 @@ class CompositeMembers : AmqpCarpenterBase() {
val c = C(B(testA, testB), testC)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(c))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(c))
assert(obj.first is C)
assert(obj.obj is C)
val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B")))
@ -259,9 +259,9 @@ class CompositeMembers : AmqpCarpenterBase() {
val c = C(B(testA, testB), testC)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(c))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(c))
assert(obj.first is C)
assert(obj.obj is C)
val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B")))
}
@ -284,9 +284,9 @@ class CompositeMembers : AmqpCarpenterBase() {
val b = B(A(testA), testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
assert(obj.first is B)
assert(obj.obj is B)
}
@Test
@ -302,9 +302,9 @@ class CompositeMembers : AmqpCarpenterBase() {
val b = B(A(testA), testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
assert(obj.first is B)
assert(obj.obj is B)
}
@Test
@ -320,9 +320,9 @@ class CompositeMembers : AmqpCarpenterBase() {
val b = B(A(testA), testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
assert(obj.first is B)
assert(obj.obj is B)
}
}

View File

@ -1,10 +1,11 @@
package net.corda.carpenter
package net.corda.core.serialization.carpenter
import net.corda.core.serialization.CordaSerializable
import net.corda.core.serialization.carpenter.MetaCarpenter
import net.corda.core.serialization.carpenter.test.*
import net.corda.core.serialization.amqp.*
import org.junit.Test
import net.corda.carpenter.test.*
import net.corda.carpenter.MetaCarpenter
import kotlin.test.*
/*******************************************************************************************************/
@ -52,11 +53,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(testJ, a.j)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
assert(obj.first is A)
assert(obj.obj is A)
val serSchema = obj.second.schema
val serSchema = obj.envelope.schema
assertEquals(2, serSchema.types.size)
@ -77,7 +78,7 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(curruptName(classTestName("A")), aSchema!!.name)
assertEquals(1, aSchema.interfaces.size)
assertEquals(net.corda.carpenter.J::class.java, aSchema.interfaces[0])
assertEquals(net.corda.core.serialization.carpenter.J::class.java, aSchema.interfaces[0])
val aBuilder = ClassCarpenter().build(aSchema)
@ -101,11 +102,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(testJ, a.j)
assertEquals(testJJ, a.jj)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
assert(obj.first is A)
assert(obj.obj is A)
val serSchema = obj.second.schema
val serSchema = obj.envelope.schema
assertEquals(2, serSchema.types.size)
@ -128,7 +129,7 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(aName, aSchema!!.name)
assertEquals(1, aSchema.interfaces.size)
assertEquals(net.corda.carpenter.J::class.java, aSchema.interfaces[0])
assertEquals(net.corda.core.serialization.carpenter.J::class.java, aSchema.interfaces[0])
val aBuilder = ClassCarpenter().build(aSchema)
@ -151,9 +152,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
val a = A(testI, testII)
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
assert(obj.first is A)
assert(obj.obj is A)
val serSchema = obj.second.schema
val serSchema = obj.envelope.schema
assertEquals(3, serSchema.types.size)
@ -178,8 +179,8 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(aName, aSchema!!.name)
assertEquals(2, aSchema.interfaces.size)
assert(net.corda.carpenter.I::class.java in aSchema.interfaces)
assert(net.corda.carpenter.II::class.java in aSchema.interfaces)
assert(net.corda.core.serialization.carpenter.I::class.java in aSchema.interfaces)
assert(net.corda.core.serialization.carpenter.II::class.java in aSchema.interfaces)
val aBuilder = ClassCarpenter().build(aSchema)
@ -204,9 +205,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
val a = A(testI, testIII)
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
assert(obj.first is A)
assert(obj.obj is A)
val serSchema = obj.second.schema
val serSchema = obj.envelope.schema
assertEquals(3, serSchema.types.size)
@ -228,8 +229,8 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(aName, aSchema!!.name)
assertEquals(2, aSchema.interfaces.size)
assert(net.corda.carpenter.I::class.java in aSchema.interfaces)
assert(net.corda.carpenter.III::class.java in aSchema.interfaces)
assert(net.corda.core.serialization.carpenter.I::class.java in aSchema.interfaces)
assert(net.corda.core.serialization.carpenter.III::class.java in aSchema.interfaces)
val aBuilder = ClassCarpenter().build(aSchema)
@ -256,11 +257,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
val a = A(testI)
val b = B(a, testIIII)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
assert(obj.first is B)
assert(obj.obj is B)
val serSchema = obj.second.schema
val serSchema = obj.envelope.schema
/*
* class A
@ -316,11 +317,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
val a = A(testI)
val b = B(a, testIIII)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b))
assert(obj.first is B)
assert(obj.obj is B)
val serSchema = obj.second.schema
val serSchema = obj.envelope.schema
/*
* The classes we're expecting to find:
@ -344,11 +345,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
val a = A(testI)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
assert(obj.first is A)
assert(obj.obj is A)
val serSchema = obj.second.schema
val serSchema = obj.envelope.schema
/*
* The classes we're expecting to find:
@ -402,9 +403,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
val a = A(testI, testII)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
val amqpSchema = obj.second.schema.curruptName(listOf(
val amqpSchema = obj.envelope.schema.curruptName(listOf(
classTestName("A"),
"${this.javaClass.`package`.name}.I",
"${this.javaClass.`package`.name}.II"))
@ -457,9 +458,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() {
val a = A(testI, testIII)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
val amqpSchema = obj.second.schema.curruptName(listOf(
val amqpSchema = obj.envelope.schema.curruptName(listOf(
classTestName("A"),
"${this.javaClass.`package`.name}.I",
"${this.javaClass.`package`.name}.III"))

View File

@ -1,9 +1,10 @@
package net.corda.carpenter
package net.corda.core.serialization.carpenter
import net.corda.carpenter.test.AmqpCarpenterBase
import net.corda.core.serialization.carpenter.test.AmqpCarpenterBase
import net.corda.core.serialization.carpenter.CarpenterSchemas
import net.corda.core.serialization.CordaSerializable
import net.corda.core.serialization.amqp.*
import net.corda.core.serialization.carpenter.CarpenterSchemas
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
@ -20,17 +21,17 @@ class MultiMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
var a = A(testA, testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
assert(obj.first is A)
val amqpObj = obj.first as A
assert(obj.obj is A)
val amqpObj = obj.obj as A
assertEquals(testA, amqpObj.a)
assertEquals(testB, amqpObj.b)
assertEquals(1, obj.second.schema.types.size)
assert(obj.second.schema.types[0] is CompositeType)
assertEquals(1, obj.envelope.schema.types.size)
assert(obj.envelope.schema.types[0] is CompositeType)
var amqpSchema = obj.second.schema.types[0] as CompositeType
var amqpSchema = obj.envelope.schema.types[0] as CompositeType
assertEquals(2, amqpSchema.fields.size)
assertEquals("a", amqpSchema.fields[0].name)
@ -64,17 +65,17 @@ class MultiMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
val a = A(testA, testB)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
assert(obj.first is A)
val amqpObj = obj.first as A
assert(obj.obj is A)
val amqpObj = obj.obj as A
assertEquals(testA, amqpObj.a)
assertEquals(testB, amqpObj.b)
assertEquals(1, obj.second.schema.types.size)
assert(obj.second.schema.types[0] is CompositeType)
assertEquals(1, obj.envelope.schema.types.size)
assert(obj.envelope.schema.types[0] is CompositeType)
val amqpSchema = obj.second.schema.types[0] as CompositeType
val amqpSchema = obj.envelope.schema.types[0] as CompositeType
assertEquals(2, amqpSchema.fields.size)
assertEquals("a", amqpSchema.fields[0].name)

View File

@ -1,9 +1,10 @@
package net.corda.carpenter
package net.corda.core.serialization.carpenter
import net.corda.carpenter.test.AmqpCarpenterBase
import net.corda.core.serialization.carpenter.test.AmqpCarpenterBase
import net.corda.core.serialization.carpenter.CarpenterSchemas
import net.corda.core.serialization.CordaSerializable
import net.corda.core.serialization.amqp.*
import net.corda.core.serialization.carpenter.CarpenterSchemas
import org.junit.Test
import kotlin.test.assertEquals
@ -84,7 +85,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
data class A(val a : Char)
val a = A(test)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
assert (obj.obj is A)
val amqpObj = obj.obj as A
@ -121,7 +122,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
@CordaSerializable
data class A(val a: Long)
var a = A(test)
val a = A(test)
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
@ -132,7 +133,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(1, obj.envelope.schema.types.size)
assert(obj.envelope.schema.types[0] is CompositeType)
var amqpSchema = obj.envelope.schema.types[0] as CompositeType
val amqpSchema = obj.envelope.schema.types[0] as CompositeType
assertEquals(1, amqpSchema.fields.size)
assertEquals("a", amqpSchema.fields[0].name)
@ -155,7 +156,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
@CordaSerializable
data class A(val a: Short)
var a = A(test)
val a = A(test)
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a))
@ -166,7 +167,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(1, obj.envelope.schema.types.size)
assert(obj.envelope.schema.types[0] is CompositeType)
var amqpSchema = obj.envelope.schema.types[0] as CompositeType
val amqpSchema = obj.envelope.schema.types[0] as CompositeType
assertEquals(1, amqpSchema.fields.size)
assertEquals("a", amqpSchema.fields[0].name)
@ -192,7 +193,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
var a = A (test)
val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise (a))
val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise (a))
assert (obj.obj is A)
val amqpObj = obj.obj as A
@ -282,4 +283,4 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() {
assertEquals(pinochio.getMethod("getA").invoke(p), amqpObj.a)
}
}
}

View File

@ -1,61 +0,0 @@
package net.corda.carpenter
import net.corda.core.serialization.carpenter.CarpenterSchemas
import net.corda.core.serialization.carpenter.Schema
import net.corda.core.serialization.amqp.CompositeType
/**********************************************************************************************************************/
abstract class MetaCarpenterBase (val schemas : CarpenterSchemas) {
private val cc = ClassCarpenter()
val objects = mutableMapOf<String, Class<*>>()
fun step (newObject : Schema) {
objects[newObject.name] = cc.build (newObject)
/* go over the list of everything that had a dependency on the newly
carpented class existing and remove it from their dependency list, If that
list is now empty we have no impediment to carpenting that class up */
schemas.dependsOn.remove(newObject.name)?.forEach { dependent ->
assert (newObject.name in schemas.dependencies[dependent]!!.second)
schemas.dependencies[dependent]?.second?.remove(newObject.name)
/* we're out of blockers so we can now create the type */
if (schemas.dependencies[dependent]?.second?.isEmpty() ?: false) {
(schemas.dependencies.remove (dependent)?.first as CompositeType).carpenterSchema (
classLoaders = listOf<ClassLoader> (
ClassLoader.getSystemClassLoader(),
cc.classloader),
carpenterSchemas = schemas)
}
}
}
abstract fun build()
}
/**********************************************************************************************************************/
class MetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) {
override fun build() {
while (schemas.carpenterSchemas.isNotEmpty()) {
val newObject = schemas.carpenterSchemas.removeAt(0)
step (newObject)
}
}
}
/**********************************************************************************************************************/
class TestMetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) {
override fun build() {
println ("TestMetaCarpenter::build")
if (schemas.carpenterSchemas.isEmpty()) return
step (schemas.carpenterSchemas.removeAt(0))
}
}
/**********************************************************************************************************************/