@Override public boolean test( PropertyDescriptor propertyDescriptor ) { boolean supported = isSupported( propertyDescriptor.valueType() ); if( !supported ) { LOGGER.warn( "Unsupported Property type: " + propertyDescriptor ); } return supported; }
@Override public void exportDataSources() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException { for ( ServiceReference<DataSource> dataSource : dataSources ) { ModuleDescriptor module = spi.moduleOf( dataSource ); EntityDescriptor descriptor = module.entityDescriptor( DataSourceConfiguration.class.getName() ); List<MBeanAttributeInfo> attributes = new ArrayList<>(); Map<String, AccessibleObject> properties = new LinkedHashMap<>(); descriptor.state().properties().forEach(persistentProperty -> { if ( !persistentProperty.isImmutable() ) { String propertyName = persistentProperty.qualifiedName().name(); String type = persistentProperty.valueType().primaryType().getName(); attributes.add( new MBeanAttributeInfo( propertyName, type, propertyName, true, true, type.equals( "java.lang.Boolean" ) ) ); properties.put( propertyName, persistentProperty.accessor() ); } } ); List<MBeanOperationInfo> operations = new ArrayList<>(); operations.add( new MBeanOperationInfo( "restart", "Restart DataSource", new MBeanParameterInfo[ 0 ], "void", MBeanOperationInfo.ACTION_INFO ) ); String mbeanName = dataSource.identity().toString(); MBeanInfo mbeanInfo = new MBeanInfo( DataSourceConfiguration.class.getName(), mbeanName, attributes.toArray( new MBeanAttributeInfo[ attributes.size() ] ), null, operations.toArray( new MBeanOperationInfo[ operations.size() ] ), null ); Object mbean = new ConfigurableDataSource( dataSourceService, mbeanInfo, mbeanName, properties ); ObjectName configurableDataSourceName = new ObjectName( "Polygene:application=" + application.name() + ",class=Datasource,name=" + mbeanName ); server.registerMBean( mbean, configurableDataSourceName ); configurationNames.add( configurableDataSourceName ); } }
@Override public void exportDataSources() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException { for ( ServiceReference<DataSource> dataSource : dataSources ) { ModuleDescriptor module = spi.moduleOf( dataSource ); EntityDescriptor descriptor = module.entityDescriptor( DataSourceConfiguration.class.getName() ); List<MBeanAttributeInfo> attributes = new ArrayList<>(); Map<String, AccessibleObject> properties = new LinkedHashMap<>(); descriptor.state().properties().forEach(persistentProperty -> { if ( !persistentProperty.isImmutable() ) { String propertyName = persistentProperty.qualifiedName().name(); String type = persistentProperty.valueType().primaryType().getName(); attributes.add( new MBeanAttributeInfo( propertyName, type, propertyName, true, true, type.equals( "java.lang.Boolean" ) ) ); properties.put( propertyName, persistentProperty.accessor() ); } } ); List<MBeanOperationInfo> operations = new ArrayList<>(); operations.add( new MBeanOperationInfo( "restart", "Restart DataSource", new MBeanParameterInfo[ 0 ], "void", MBeanOperationInfo.ACTION_INFO ) ); String mbeanName = dataSource.identity().toString(); MBeanInfo mbeanInfo = new MBeanInfo( DataSourceConfiguration.class.getName(), mbeanName, attributes.toArray( new MBeanAttributeInfo[ attributes.size() ] ), null, operations.toArray( new MBeanOperationInfo[ operations.size() ] ), null ); Object mbean = new ConfigurableDataSource( dataSourceService, mbeanInfo, mbeanName, properties ); ObjectName configurableDataSourceName = new ObjectName( "Polygene:application=" + application.name() + ",class=Datasource,name=" + mbeanName ); server.registerMBean( mbean, configurableDataSourceName ); configurationNames.add( configurableDataSourceName ); } }
value = doDeserialize( module, property.valueType(), valueNode );
value = doDeserialize( module, property.valueType(), messagePackValue );
private void serializePropertyTypes( final EntityDescriptor entityDescriptor, final Graph graph, final URI entityTypeUri ) { ValueFactory values = graph.getValueFactory(); // Properties entityDescriptor.state().properties().forEach( persistentProperty -> { URI propertyURI = values.createURI( persistentProperty.qualifiedName().toURI() ); graph.add( propertyURI, Rdfs.DOMAIN, entityTypeUri ); graph.add( propertyURI, Rdfs.TYPE, Rdfs.PROPERTY ); // TODO Support more types URI type = dataTypes.get( persistentProperty.valueType().primaryType().getName() ); if( type != null ) { graph.add( propertyURI, Rdfs.RANGE, type ); } } ); } }
ValueType valueType = persistentProperty.valueType(); Class<?> primaryType = valueType.primaryType(); if( Number.class.isAssignableFrom( primaryType ) )
value = doDeserialize( module, property.valueType(), jsonValue );
private void serializeProperty( PropertyDescriptor persistentProperty, Object property, Resource subject, Graph graph, boolean includeNonQueryable ) { if( !( includeNonQueryable || persistentProperty.queryable() ) ) { return; // Skip non-queryable } ValueType valueType = persistentProperty.valueType(); final ValueFactory valueFactory = graph.getValueFactory(); String propertyURI = persistentProperty.qualifiedName().toURI(); URI predicate = valueFactory.createURI( propertyURI ); String baseURI = propertyURI.substring( 0, propertyURI.indexOf( '#' ) ) + "/"; if( valueType instanceof ValueCompositeType ) { serializeValueComposite( subject, predicate, (ValueComposite) property, valueType, graph, baseURI, includeNonQueryable ); } else { String stringProperty = serializer.serialize( Serializer.Options.NO_TYPE_INFO, property ); final Literal object = valueFactory.createLiteral( stringProperty ); graph.add( subject, predicate, object ); } }
value = doDeserialize( module, property.valueType(), jsonValue );
@Override public Object propertyValueOf( QualifiedName stateName ) { try { ValueType valueType = entityDescriptor.state().findPropertyModelByQualifiedName( stateName ).valueType(); JsonValue jsonValue = state.getJsonObject( JSONKeys.VALUE ).get( stateName.name() ); return serialization.fromJson( module, valueType, jsonValue ); } catch( SerializationException e ) { throw new EntityStoreException( e ); } }
@Override public Object propertyValueOf( QualifiedName stateName ) { try { ValueType valueType = entityDescriptor.state().findPropertyModelByQualifiedName( stateName ).valueType(); JsonValue jsonValue = state.getJsonObject( JSONKeys.VALUE ).get( stateName.name() ); return serialization.fromJson( module, valueType, jsonValue ); } catch( SerializationException e ) { throw new EntityStoreException( e ); } }
@Test public void genericsAreResolvedOnValueCompositeProperties() { ValueDescriptor descriptor = module.typeLookup().lookupValueModel( SomeState.class ); assertThat( descriptor.state().findPropertyModelByName( "list" ).valueType(), equalTo( CollectionType.listOf( ValueType.STRING ) ) ); assertThat( descriptor.state().findPropertyModelByName( "map" ).valueType(), equalTo( MapType.of( ValueType.STRING, ValueType.INTEGER ) ) ); } }
Object value = jsonSerialization.fromJson( module, property.valueType(), jsonValue ); properties.put( property.qualifiedName(), value );
private Object createParametersComposite( RestForm form, Class<?> argType ) { ValueBuilder<?> vb = vbf.newValueBuilderWithState( argType, descriptor -> { FormField field = form.field( descriptor.qualifiedName().name() ); if( field == null ) { return null; } Class<?> propertyType = descriptor.valueType().primaryType(); Property<String> value = field.value(); if( value == null ) { return null; } return convertPropertyValue( value.get(), propertyType ); }, descriptor -> null, descriptor -> null, descriptor -> null ); return vb.newInstance(); }
.valueType(); if( type instanceof ValueCompositeType )
return deserializer.deserialize( module, propertyDescriptor.valueType(), value );
return deserializer.deserialize( module, propertyDescriptor.valueType(), value );