@Override protected T initialValue() { return module.instance().newTransient( type ); }
protected final StatefulAssociationCompositeDescriptor statefulCompositeDescriptorFor( ModuleDescriptor module, String typeName ) { StatefulAssociationCompositeDescriptor descriptor = null; try { descriptor = module.valueDescriptor( typeName ); } catch( AmbiguousTypeException ex ) { } if( descriptor == null ) { try { descriptor = module.entityDescriptor( typeName ); } catch( AmbiguousTypeException ex ) { } } return descriptor; } }
@Override public final String toString() { return descriptor.name(); }
protected NoSuchCompositeTypeException( String metaType, String compositeType, ModuleDescriptor module ) { super( NL + "\tCould not find any visible " + metaType + " of type [" + compositeType + "] in module [" + module.name() + "]." ); this.metaType = metaType; this.compositeType = compositeType; this.moduleName = module.name(); visibleTypes = formatVisibleTypes( module.typeLookup() ); candidateTypes = findCandidateTypes( module ); }
private List<ValueDescriptor> getAllValues() { return allValues.computeIfAbsent( () -> concat( module.valueComposites(), concat( concat( module.layer().visibleValues( layer ), module.layer().visibleValues( application ) ), module.layer().usedLayers().layers() .flatMap( layer1 -> layer1.visibleValues( application ) ) ) ).collect( toList() ) ); }
@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 ); } }
private void decorateModuleInfo( Throwable throwable, String methodName ) { StackTraceElement[] trace = throwable.getStackTrace(); // Only add originating Module/Layer/ if( trace[0].getClassName().startsWith( "method " )) { return; } StackTraceElement[] newTrace = new StackTraceElement[ trace.length + 1 ]; String message = "method \"" + methodName + "\" of " + this.toString() + " in module [" + module.name() + "] of layer [" + module.layer().name() + "]"; String compositeName = this.toString(); newTrace[ 0 ] = new StackTraceElement( message, "", "", 0 ); System.arraycopy( trace, 0, newTrace, 1, trace.length ); throwable.setStackTrace( newTrace ); }
@Override public <T> EntityBuilder<T> newEntityBuilder( Class<T> type, Identity identity ) throws NoSuchEntityTypeException { EntityDescriptor model = module.typeLookup().lookupEntityModel( type ); if( model == null ) { throw new NoSuchEntityTypeException( type.getName(), module ); } ModuleDescriptor modelModule = model.module(); EntityStore entityStore = ( (ModuleSpi) modelModule.instance() ).entityStore(); // Generate id if necessary if( identity == null ) { IdentityGenerator idGen = ( (ModuleSpi) modelModule.instance() ).identityGenerator(); identity = idGen.generate( model.types().findFirst().orElse( null ) ); } EntityBuilder<T> builder; builder = new EntityBuilderInstance<>( model, this, uow.getEntityStoreUnitOfWork( entityStore ), identity ); return builder; }
if( clazz.equals( TransientBuilderFactory.class ) ) return context.module().instance(); return context.module().instance(); return context.module().instance(); return context.module().instance().unitOfWorkFactory(); return context.module().instance(); return context.module().instance(); return context.module().instance(); return context.module().layer().instance(); return context.module().layer(); return context.module().layer().instance().application(); return context.module().layer().instance().application().descriptor(); return (( ApplicationInstance) context.module().layer().instance().application()).runtime();
@Test public void givenListOfValueCompositesAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = serialization.serialize( valueCompositesList() ); System.out.println( output ); ValueCompositeType valueType = module.valueDescriptor( SomeValue.class.getName() ).valueType(); CollectionType collectionType = CollectionType.listOf( valueType ); List<SomeValue> value = serialization.deserialize( module, collectionType, output ); assertEquals( valueCompositesList(), value ); }
@Override public void initialize() { Logger logger = LoggerFactory.getLogger( getClass() ); ResourceBundle defaultRequestWriters = ResourceBundle.getBundle( "org.apache.polygene.library.rest.client.rest-client" ); String requestWriterClasses = defaultRequestWriters.getString( "requestwriters" ); logger.info( "Using request writers:"+requestWriterClasses ); for (String className : requestWriterClasses.split( "," )) { try { Class writerClass = module.descriptor().classLoader().loadClass( className.trim() ); RequestWriter requestWriter = (RequestWriter) module.newObject( writerClass ); registerRequestWriter(requestWriter); } catch (ClassNotFoundException e) { logger.warn( "Could not register request writer "+className, e ); } } }
@Override public <T> T get( Class<T> type, Identity identity ) throws NoSuchEntityTypeException, NoSuchEntityException { Iterable<EntityDescriptor> models = module.typeLookup().lookupEntityModels( type ); if( !models.iterator().hasNext() ) { throw new NoSuchEntityTypeException( type.getName(), module ); } return uow.get( EntityReference.create( identity ), this, models, type ); }
private List<? extends ModelDescriptor> getAllServices() { return allServices.computeIfAbsent( () -> concat( concat( module.serviceComposites(), concat( concat( module.layer().visibleServices( layer ), module.layer().visibleServices( application ) ), module.layer().usedLayers().layers() .flatMap( layer -> layer.visibleServices( application ) ) ) ), concat( module.importedServices(), concat( concat( module.layer().visibleServices( layer ), module.layer().visibleServices( application ) ), module.layer().usedLayers().layers() .flatMap( layer -> layer.visibleServices( application ) ) ) ) ).collect( toList() ) ); }
private List<ObjectDescriptor> getAllObjects() { return allObjects.computeIfAbsent( () -> concat( module.objects(), concat( concat( module.layer().visibleObjects( layer ), module.layer().visibleObjects( application ) ), module.layer().usedLayers().layers() .flatMap( layer -> layer.visibleObjects( application ) ) ) ).collect( toList() ) ); }
private List<EntityDescriptor> getAllEntities() { return allEntities.computeIfAbsent( () -> concat( module.entityComposites(), concat( concat( module.layer().visibleEntities( layer ), module.layer().visibleEntities( application ) ), module.layer().usedLayers().layers() .flatMap( layer -> layer.visibleEntities( application ) ) ) ).collect( toList() ) ); }
private List<TransientDescriptor> getAllTransients() { return allTransients.computeIfAbsent( () -> concat( module.transientComposites(), concat( concat( module.layer().visibleTransients( layer ), module.layer().visibleTransients( application ) ), module.layer().usedLayers().layers() .flatMap( layer -> layer.visibleTransients( application ) ) ) ).collect( toList() ) ); }
public LayerDescriptor layer() { return compositeModel.module().layer(); }
@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 String getMessage() { String typeNames = typesString(); String primary = primaryType == null ? "" : " primary: " + primaryType.toGenericString() + NL; String methodName = memberString(); String message = super.getMessage() == null ? "" : " message: " + super.getMessage() + NL; String fragment = fragmentClass == null ? "" : " fragmentClass: " + fragmentClass.getName() + NL; String valueType = this.valueType == null ? "" : " valueType: " + this.valueType.getTypeName() + NL; String module = this.module == null ? "" : " layer: " + this.module.layer().name() + NL + " module: " + this.module.name() + NL; return message + module + primary + fragment + methodName + valueType + typeNames; }
protected NoSuchCompositeTypeException( String metaType, String compositeType, ModuleDescriptor module ) { super( NL + "\tCould not find any visible " + metaType + " of type [" + compositeType + "] in module [" + module.name() + "]." ); this.metaType = metaType; this.compositeType = compositeType; this.moduleName = module.name(); visibleTypes = formatVisibleTypes( module.typeLookup() ); candidateTypes = findCandidateTypes( module ); }