private String findCandidateTypes( ModuleDescriptor module ) { return Stream.concat( Stream.of( module.layer() ), module.layer().usedLayers().layers() ) .flatMap( LayerDescriptor::modules ) .map( ModuleDescriptor::typeLookup ) .flatMap( this::descriptors ) .filter( type -> compositeType.equals( type.primaryType().getName() ) ) .map( descriptor -> { Class<?> primarytype = descriptor.primaryType(); String typeName = primarytype.getName(); return "\t\t[ " + typeName + "] in [" + descriptor.module().name() + "] with visibility " + descriptor.visibility(); } ) .distinct() .collect( joining( NL, "\tInvisible " + metaType + " types are:" + NL, "" ) ); }
private String getCompositeName( Composite composite ) { return PolygeneAPI.FUNCTION_DESCRIPTOR_FOR.apply( composite ).types().findFirst().get().getName(); } }
public void setCompositeDescriptor( CompositeDescriptor descriptor ) { this.primaryType = descriptor.primaryType(); this.instanceTypes = descriptor.mixinTypes().collect( Collectors.toList() ); this.isEntity = descriptor instanceof EntityDescriptor; this.isService = descriptor instanceof ServiceDescriptor; }
private String formatVisibleTypes( TypeLookup typeLookup ) { return descriptors( typeLookup ) .map( descriptor -> { String moduleName = descriptor.module().name(); String typeName = descriptor.primaryType().getName(); return "\t\t[" + typeName + "] in [" + moduleName + "]"; } ) .sorted() .distinct() .collect( joining( NL, "\tVisible " + metaType + " types are:" + NL, "" ) ); }
public JsonObjectBuilder toJson() { JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add( "type", descriptor().primaryType().getName() ); builder.add( "visibility", descriptor().visibility().name() ); { JsonArrayBuilder typesBuilder = Json.createArrayBuilder(); descriptor().types().forEach( type -> typesBuilder.add( type.getName() ) ); builder.add( "types", typesBuilder ); } { JsonArrayBuilder mixinsBuilder = Json.createArrayBuilder(); mixins().forEach( mixin -> mixinsBuilder.add( mixin.toJson() ) ); builder.add( "mixins", mixinsBuilder ); } return builder; } }
private Object doGuessDeserialize( ModuleDescriptor module, ValueType valueType, Node xml ) { // TODO Could do better by detecting <collection/>, <map/> and <value/> Optional<String> typeInfo = getTypeInfo( xml ); if( typeInfo.isPresent() ) { StatefulAssociationCompositeDescriptor descriptor = statefulCompositeDescriptorFor( module, typeInfo.get() ); if( descriptor != null ) { return deserializeStatefulAssociationValue( ( (CompositeDescriptor) descriptor ).module(), descriptor.valueType(), xml ); } } throw new SerializationException( "Don't know how to deserialize " + valueType + " from " + xml ); }
private ScriptEngine createNewEngine() { Scripting scripting = descriptor.metaInfo( Scripting.class ); ScriptEngine engine = getScriptEngine( scripting ); String scriptName = descriptor.primaryType().getName().replaceAll( "\\.", "/" ) + scripting.extension(); try( BufferedReader reader = new BufferedReader( new InputStreamReader( getClass().getClassLoader().getResourceAsStream( scriptName ) ) ) ) { engine.eval( reader ); } catch( IOException e ) { throw new ScriptException( "Unable to load " + scriptName + " for " + descriptor, e ); } catch( javax.script.ScriptException e ) { throw new ScriptException( "Unable to parse " + scriptName + ".", e ); } return engine; }
injectionTypes = acd.mixinTypes().filter( thisType::isAssignableFrom );
private String formatVisibleTypes( TypeLookup typeLookup ) { return descriptors( typeLookup ) .map( descriptor -> { String moduleName = descriptor.module().name(); String typeName = descriptor.primaryType().getName(); return "\t\t[" + typeName + "] in [" + moduleName + "]"; } ) .sorted() .distinct() .collect( joining( NL, "\tVisible " + metaType + " types are:" + NL, "" ) ); }
if( descriptor != null ) return deserializeStatefulAssociationValue( ( (CompositeDescriptor) descriptor ).module(), descriptor.valueType(), mapValue );
private String findCandidateTypes( ModuleDescriptor module ) { return Stream.concat( Stream.of( module.layer() ), module.layer().usedLayers().layers() ) .flatMap( LayerDescriptor::modules ) .map( ModuleDescriptor::typeLookup ) .flatMap( this::descriptors ) .filter( type -> compositeType.equals( type.primaryType().getName() ) ) .map( descriptor -> { Class<?> primarytype = descriptor.primaryType(); String typeName = primarytype.getName(); return "\t\t[ " + typeName + "] in [" + descriptor.module().name() + "] with visibility " + descriptor.visibility(); } ) .distinct() .collect( joining( NL, "\tInvisible " + metaType + " types are:" + NL, "" ) ); }
private String getCompositeName( Composite composite ) { return PolygeneAPI.FUNCTION_DESCRIPTOR_FOR.apply( composite ).types().findFirst().get().getName(); } }
@SuppressWarnings( "unchecked" ) private <T> T doGuessDeserialize( ModuleDescriptor module, ValueType valueType, JsonValue json ) { switch( json.getValueType() ) { case OBJECT: JsonObject object = (JsonObject) json; String typeInfo = object.getString( settings.getTypeInfoPropertyName(), valueType.primaryType().getName() ); StatefulAssociationCompositeDescriptor descriptor = statefulCompositeDescriptorFor( module, typeInfo ); if( descriptor != null ) { return (T) deserializeStatefulAssociationValue( ( (CompositeDescriptor) descriptor ).module(), descriptor.valueType(), object ); } default: throw new SerializationException( "Don't know how to deserialize " + valueType + " from " + json ); } }
public void setCompositeDescriptor( CompositeDescriptor descriptor ) { this.primaryType = descriptor.primaryType(); this.instanceTypes = descriptor.mixinTypes().collect( Collectors.toList() ); this.isEntity = descriptor instanceof EntityDescriptor; this.isService = descriptor instanceof ServiceDescriptor; }
private String getCompositeName( Composite composite ) { return PolygeneAPI.FUNCTION_DESCRIPTOR_FOR.apply( composite ).types().findFirst().get().getName(); }
@SuppressWarnings( "unchecked" ) private <T> T doGuessDeserialize( ModuleDescriptor module, ValueType valueType, JsonValue json ) { switch( json.getValueType() ) { case OBJECT: JsonObject object = (JsonObject) json; String typeInfo = object.getString( settings.getTypeInfoPropertyName(), valueType.primaryType().getName() ); StatefulAssociationCompositeDescriptor descriptor = statefulCompositeDescriptorFor( module, typeInfo ); if( descriptor != null ) { return (T) deserializeStatefulAssociationValue( ( (CompositeDescriptor) descriptor ).module(), descriptor.valueType(), object ); } default: throw new SerializationException( "Don't know how to deserialize " + valueType + " from " + json ); } }
private String getCompositeName( Composite composite ) { return PolygeneAPI.FUNCTION_DESCRIPTOR_FOR.apply( composite ).types().findFirst().get().getName(); }
public SimpleLogConcern( @This Composite composite ) { this.composite = composite; Class<?> type = PolygeneAPI.FUNCTION_DESCRIPTOR_FOR.apply( composite ).types().findFirst().orElse( null ); category = type.getName(); }
protected static String compositeDescriptorToString( LayerDescriptor layer, ModuleDescriptor module, CompositeDescriptor descriptor ) { return DESCRIPTOR_COMPONENT_SEPARATOR_START + layer.name() + DESCRIPTOR_COMPONENT_SEPARATOR_END + DESCRIPTOR_COMPONENT_SEPARATOR_START + module.name() + DESCRIPTOR_COMPONENT_SEPARATOR_END + DESCRIPTOR_COMPONENT_SEPARATOR_START + descriptor.types().map( Object::toString ).collect( Collectors.joining( DESCRIPTOR_TYPE_SEPARATOR ) ) + DESCRIPTOR_COMPONENT_SEPARATOR_END; }
@Override public boolean visitEnter( Object visited ) { boolean thisResult = true; if( visited instanceof LayerDescriptor ) { thisResult = ( (LayerDescriptor) visited ).name().equals( layerName ); } else if( visited instanceof ModuleDescriptor ) { thisResult = ( (ModuleDescriptor) visited ).name().equals( moduleName ); } else if( descriptorClass.isAssignableFrom( visited.getClass() ) ) { CompositeDescriptor desc = (CompositeDescriptor) visited; Set<String> names = desc.types().map( Class::getName ).collect( Collectors.toSet() ); if( classNames.equals( names ) ) { result[ 0 ] = desc; thisResult = false; } } return thisResult; }