http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/LayerAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/LayerAssemblyImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/LayerAssemblyImpl.java new file mode 100644 index 0000000..8853f92 --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/LayerAssemblyImpl.java @@ -0,0 +1,625 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * Copyright (c) 2012, Paul Merlin. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import org.qi4j.api.activation.Activator; +import org.qi4j.api.common.MetaInfo; +import org.qi4j.api.common.Visibility; +import org.qi4j.api.service.ServiceImporter; +import org.qi4j.api.structure.Layer; +import org.qi4j.bootstrap.ApplicationAssembly; +import org.qi4j.bootstrap.AssemblyVisitor; +import org.qi4j.bootstrap.EntityAssembly; +import org.qi4j.bootstrap.EntityDeclaration; +import org.qi4j.bootstrap.ImportedServiceAssembly; +import org.qi4j.bootstrap.ImportedServiceDeclaration; +import org.qi4j.bootstrap.LayerAssembly; +import org.qi4j.bootstrap.ModuleAssembly; +import org.qi4j.bootstrap.ObjectAssembly; +import org.qi4j.bootstrap.ObjectDeclaration; +import org.qi4j.bootstrap.ServiceAssembly; +import org.qi4j.bootstrap.ServiceDeclaration; +import org.qi4j.bootstrap.TransientAssembly; +import org.qi4j.bootstrap.TransientDeclaration; +import org.qi4j.bootstrap.ValueAssembly; +import org.qi4j.bootstrap.ValueDeclaration; +import org.qi4j.functional.Specification; + +/** + * Assembly of a Layer. From here you can create more ModuleAssemblies for + * the Layer that is being assembled. It is also here that you define + * what other Layers this Layer is using by calling {@link org.qi4j.runtime.bootstrap.LayerAssemblyImpl#uses()}. + */ +public final class LayerAssemblyImpl + implements LayerAssembly +{ + private final ApplicationAssembly applicationAssembly; + private final HashMap<String, ModuleAssemblyImpl> moduleAssemblies; + private final Set<LayerAssembly> uses; + + private String name; + private final MetaInfo metaInfo = new MetaInfo(); + private final List<Class<? extends Activator<Layer>>> activators = new ArrayList<>(); + + public LayerAssemblyImpl( ApplicationAssembly applicationAssembly, String name ) + { + this.applicationAssembly = applicationAssembly; + this.name = name; + + moduleAssemblies = new LinkedHashMap<>(); + uses = new LinkedHashSet<>(); + } + + @Override + public ModuleAssembly module( String name ) + { + if( name != null ) + { + ModuleAssemblyImpl existing = moduleAssemblies.get( name ); + if( existing != null ) + { + return existing; + } + } + ModuleAssemblyImpl moduleAssembly = new ModuleAssemblyImpl( this, name ); + moduleAssemblies.put( name, moduleAssembly ); + return moduleAssembly; + } + + @Override + public ApplicationAssembly application() + { + return applicationAssembly; + } + + @Override + public LayerAssembly setName( String name ) + { + this.name = name; + return this; + } + + @Override + public LayerAssembly setMetaInfo( Object info ) + { + metaInfo.set( info ); + return this; + } + + @Override + public LayerAssembly uses( LayerAssembly... layerAssembly ) + throws IllegalArgumentException + { + uses.addAll( Arrays.asList( layerAssembly ) ); + return this; + } + + @Override + @SafeVarargs + public final LayerAssembly withActivators( Class<? extends Activator<Layer>>... activators ) + { + this.activators.addAll( Arrays.asList( activators ) ); + return this; + } + + @Override + public <ThrowableType extends Throwable> void visit( AssemblyVisitor<ThrowableType> visitor ) + throws ThrowableType + { + visitor.visitLayer( this ); + for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() ) + { + moduleAssembly.visit( visitor ); + } + } + + @Override + public EntityDeclaration entities( Specification<? super EntityAssembly> specification ) + { + final List<EntityDeclaration> declarations = new ArrayList<>(); + + for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() ) + { + declarations.add( moduleAssembly.entities( specification ) ); + } + + return new EntityDeclaration() + { + @Override + public EntityDeclaration setMetaInfo( Object info ) + { + for( EntityDeclaration declaration : declarations ) + { + declaration.setMetaInfo( info ); + } + return this; + } + + @Override + public EntityDeclaration visibleIn( Visibility visibility ) + { + for( EntityDeclaration declaration : declarations ) + { + declaration.visibleIn( visibility ); + } + return this; + } + + @Override + public EntityDeclaration withConcerns( Class<?>... concerns ) + { + for( EntityDeclaration declaration : declarations ) + { + declaration.withConcerns( concerns ); + } + return this; + } + + @Override + public EntityDeclaration withSideEffects( Class<?>... sideEffects ) + { + for( EntityDeclaration declaration : declarations ) + { + declaration.withSideEffects( sideEffects ); + } + return this; + } + + @Override + public EntityDeclaration withMixins( Class<?>... mixins ) + { + for( EntityDeclaration declaration : declarations ) + { + declaration.withMixins( mixins ); + } + return this; + } + + @Override + public EntityDeclaration withTypes( Class<?>... types ) + { + for( EntityDeclaration declaration : declarations ) + { + declaration.withTypes( types ); + } + return this; + } + }; + } + + @Override + public ServiceDeclaration services( Specification<? super ServiceAssembly> specification ) + { + final List<ServiceDeclaration> declarations = new ArrayList<>(); + + for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() ) + { + declarations.add( moduleAssembly.services( specification ) ); + } + + return new ServiceDeclaration() + { + @Override + public ServiceDeclaration setMetaInfo( Object serviceAttribute ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.setMetaInfo( serviceAttribute ); + } + return this; + } + + @Override + public ServiceDeclaration visibleIn( Visibility visibility ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.visibleIn( visibility ); + } + return this; + } + + @Override + public ServiceDeclaration withConcerns( Class<?>... concerns ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.withConcerns( concerns ); + } + return this; + } + + @Override + public ServiceDeclaration withSideEffects( Class<?>... sideEffects ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.withSideEffects( sideEffects ); + } + return this; + } + + @Override + public ServiceDeclaration withMixins( Class<?>... mixins ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.withMixins( mixins ); + } + return this; + } + + @Override + public ServiceDeclaration withTypes( Class<?>... types ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.withTypes( types ); + } + return this; + } + + @Override + @SafeVarargs + public final ServiceDeclaration withActivators( Class<? extends Activator<?>>... activators ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.withActivators( activators ); + } + return this; + } + + @Override + public ServiceDeclaration identifiedBy( String identity ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.identifiedBy( identity ); + } + return this; + } + + @Override + public ServiceDeclaration taggedWith( String... tags ) + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.taggedWith( tags ); + } + return this; + } + + @Override + public ServiceDeclaration instantiateOnStartup() + { + for( ServiceDeclaration declaration : declarations ) + { + declaration.instantiateOnStartup(); + } + + return this; + } + }; + } + + @Override + public TransientDeclaration transients( Specification<? super TransientAssembly> specification ) + { + final List<TransientDeclaration> declarations = new ArrayList<>(); + + for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() ) + { + declarations.add( moduleAssembly.transients( specification ) ); + } + + return new TransientDeclaration() + { + @Override + public TransientDeclaration setMetaInfo( Object info ) + { + for( TransientDeclaration declaration : declarations ) + { + declaration.setMetaInfo( info ); + } + return this; + } + + @Override + public TransientDeclaration visibleIn( Visibility visibility ) + { + for( TransientDeclaration declaration : declarations ) + { + declaration.visibleIn( visibility ); + } + return this; + } + + @Override + public TransientDeclaration withConcerns( Class<?>... concerns ) + { + for( TransientDeclaration declaration : declarations ) + { + declaration.withConcerns( concerns ); + } + return this; + } + + @Override + public TransientDeclaration withSideEffects( Class<?>... sideEffects ) + { + for( TransientDeclaration declaration : declarations ) + { + declaration.withSideEffects( sideEffects ); + } + return this; + } + + @Override + public TransientDeclaration withMixins( Class<?>... mixins ) + { + for( TransientDeclaration declaration : declarations ) + { + declaration.withMixins( mixins ); + } + return this; + } + + @Override + public TransientDeclaration withTypes( Class<?>... types ) + { + for( TransientDeclaration declaration : declarations ) + { + declaration.withTypes( types ); + } + return this; + } + }; + } + + @Override + public ValueDeclaration values( Specification<? super ValueAssembly> specification ) + { + final List<ValueDeclaration> declarations = new ArrayList<>(); + + for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() ) + { + declarations.add( moduleAssembly.values( specification ) ); + } + return new ValueDeclaration() + { + @Override + public ValueDeclaration setMetaInfo( Object info ) + { + for( ValueDeclaration declaration : declarations ) + { + declaration.setMetaInfo( info ); + } + return this; + } + + @Override + public ValueDeclaration visibleIn( Visibility visibility ) + { + for( ValueDeclaration declaration : declarations ) + { + declaration.visibleIn( visibility ); + } + return this; + } + + @Override + public ValueDeclaration withConcerns( Class<?>... concerns ) + { + for( ValueDeclaration declaration : declarations ) + { + declaration.withConcerns( concerns ); + } + return this; + } + + @Override + public ValueDeclaration withSideEffects( Class<?>... sideEffects ) + { + for( ValueDeclaration declaration : declarations ) + { + declaration.withSideEffects( sideEffects ); + } + return this; + } + + @Override + public ValueDeclaration withMixins( Class<?>... mixins ) + { + for( ValueDeclaration declaration : declarations ) + { + declaration.withMixins( mixins ); + } + return this; + } + + @Override + public ValueDeclaration withTypes( Class<?>... types ) + { + for( ValueDeclaration declaration : declarations ) + { + declaration.withTypes( types ); + } + return this; + } + }; + } + + @Override + public ObjectDeclaration objects( Specification<? super ObjectAssembly> specification ) + { + final List<ObjectDeclaration> declarations = new ArrayList<>(); + + for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() ) + { + declarations.add( moduleAssembly.objects( specification ) ); + } + return new ObjectDeclaration() + { + @Override + public ObjectDeclaration setMetaInfo( Object info ) + { + for( ObjectDeclaration declaration : declarations ) + { + declaration.setMetaInfo( info ); + } + return this; + } + + @Override + public ObjectDeclaration visibleIn( Visibility visibility ) + throws IllegalStateException + { + for( ObjectDeclaration declaration : declarations ) + { + declaration.visibleIn( visibility ); + } + return this; + } + }; + } + + @Override + public ImportedServiceDeclaration importedServices( Specification<? super ImportedServiceAssembly> specification ) + { + final List<ImportedServiceDeclaration> declarations = new ArrayList<>(); + + for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() ) + { + declarations.add( moduleAssembly.importedServices( specification ) ); + } + return new ImportedServiceDeclaration() + { + + @Override + public ImportedServiceDeclaration importOnStartup() + { + for( ImportedServiceDeclaration declaration : declarations ) + { + declaration.importOnStartup(); + } + return this; + } + + @Override + public ImportedServiceDeclaration visibleIn( Visibility visibility ) + { + for( ImportedServiceDeclaration declaration : declarations ) + { + declaration.visibleIn( visibility ); + } + return this; + } + + @Override + public ImportedServiceDeclaration importedBy( Class<? extends ServiceImporter> serviceImporterClass ) + { + for( ImportedServiceDeclaration declaration : declarations ) + { + declaration.importedBy( serviceImporterClass ); + } + return this; + } + + @Override + public ImportedServiceDeclaration identifiedBy( String identity ) + { + for( ImportedServiceDeclaration declaration : declarations ) + { + declaration.identifiedBy( identity ); + } + return this; + } + + @Override + public ImportedServiceDeclaration taggedWith( String... tags ) + { + for( ImportedServiceDeclaration declaration : declarations ) + { + declaration.taggedWith( tags ); + } + return this; + } + + @Override + public ImportedServiceDeclaration setMetaInfo( Object serviceAttribute ) + { + for( ImportedServiceDeclaration declaration : declarations ) + { + declaration.setMetaInfo( serviceAttribute ); + } + return this; + } + + @Override + @SafeVarargs + public final ImportedServiceDeclaration withActivators( Class<? extends Activator<?>>... activators ) + { + for( ImportedServiceDeclaration declaration : declarations ) + { + declaration.withActivators( activators ); + } + return this; + } + + }; + } + + Collection<ModuleAssemblyImpl> moduleAssemblies() + { + return moduleAssemblies.values(); + } + + Set<LayerAssembly> uses() + { + return uses; + } + + public MetaInfo metaInfo() + { + return metaInfo; + } + + @Override + public String name() + { + return name; + } + + public List<Class<? extends Activator<Layer>>> activators() + { + return activators; + } + + @Override + public final String toString() + { + return "LayerAssembly [" + name + "]"; + } +}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ModuleAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ModuleAssemblyImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ModuleAssemblyImpl.java new file mode 100644 index 0000000..1f470dc --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ModuleAssemblyImpl.java @@ -0,0 +1,635 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * Copyright (c) 2012, Paul Merlin. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.qi4j.api.activation.Activator; +import org.qi4j.api.common.MetaInfo; +import org.qi4j.api.common.Visibility; +import org.qi4j.api.composite.TransientComposite; +import org.qi4j.api.entity.EntityComposite; +import org.qi4j.api.entity.Identity; +import org.qi4j.api.service.DuplicateServiceIdentityException; +import org.qi4j.api.service.ServiceImporter; +import org.qi4j.api.structure.Module; +import org.qi4j.api.type.HasTypes; +import org.qi4j.api.type.MatchTypeSpecification; +import org.qi4j.api.value.ValueComposite; +import org.qi4j.bootstrap.AssemblyException; +import org.qi4j.bootstrap.AssemblySpecifications; +import org.qi4j.bootstrap.AssemblyVisitor; +import org.qi4j.bootstrap.ConfigurationDeclaration; +import org.qi4j.bootstrap.EntityAssembly; +import org.qi4j.bootstrap.EntityDeclaration; +import org.qi4j.bootstrap.ImportedServiceAssembly; +import org.qi4j.bootstrap.ImportedServiceDeclaration; +import org.qi4j.bootstrap.LayerAssembly; +import org.qi4j.bootstrap.MetaInfoDeclaration; +import org.qi4j.bootstrap.MixinDeclaration; +import org.qi4j.bootstrap.ModuleAssembly; +import org.qi4j.bootstrap.ObjectAssembly; +import org.qi4j.bootstrap.ObjectDeclaration; +import org.qi4j.bootstrap.ServiceAssembly; +import org.qi4j.bootstrap.ServiceDeclaration; +import org.qi4j.bootstrap.TransientAssembly; +import org.qi4j.bootstrap.TransientDeclaration; +import org.qi4j.bootstrap.ValueAssembly; +import org.qi4j.bootstrap.ValueDeclaration; +import org.qi4j.functional.Iterables; +import org.qi4j.functional.Specification; +import org.qi4j.functional.Specifications; +import org.qi4j.runtime.activation.ActivatorsModel; +import org.qi4j.runtime.composite.TransientModel; +import org.qi4j.runtime.composite.TransientsModel; +import org.qi4j.runtime.entity.EntitiesModel; +import org.qi4j.runtime.entity.EntityModel; +import org.qi4j.runtime.object.ObjectModel; +import org.qi4j.runtime.object.ObjectsModel; +import org.qi4j.runtime.service.ImportedServiceModel; +import org.qi4j.runtime.service.ImportedServicesModel; +import org.qi4j.runtime.service.ServiceModel; +import org.qi4j.runtime.service.ServicesModel; +import org.qi4j.runtime.structure.ModuleModel; +import org.qi4j.runtime.value.ValueModel; +import org.qi4j.runtime.value.ValuesModel; + +import static org.qi4j.functional.Iterables.first; +import static org.qi4j.functional.Iterables.iterable; + +/** + * Assembly of a Module. This is where you register all objects, Composites, + * Services. Each "add" method returns a declaration that you can use to add + * additional information and metadata. If you call an "add" method with many + * parameters then the declared metadata will apply to all types in the method + * call. + */ +public final class ModuleAssemblyImpl + implements ModuleAssembly +{ + private final LayerAssembly layerAssembly; + private String name; + private final MetaInfo metaInfo = new MetaInfo(); + private final List<Class<? extends Activator<Module>>> activators = new ArrayList<>(); + + private final List<ServiceAssemblyImpl> serviceAssemblies = new ArrayList<>(); + private final Map<Class<?>, ImportedServiceAssemblyImpl> importedServiceAssemblies = new LinkedHashMap<>(); + private final Map<Class<? extends EntityComposite>, EntityAssemblyImpl> entityAssemblies = new LinkedHashMap<>(); + private final Map<Class<? extends ValueComposite>, ValueAssemblyImpl> valueAssemblies = new LinkedHashMap<>(); + private final Map<Class<? extends TransientComposite>, TransientAssemblyImpl> transientAssemblies = new LinkedHashMap<>(); + private final Map<Class<?>, ObjectAssemblyImpl> objectAssemblies = new LinkedHashMap<>(); + + private final MetaInfoDeclaration metaInfoDeclaration = new MetaInfoDeclaration(); + + public ModuleAssemblyImpl( LayerAssembly layerAssembly, String name ) + { + this.layerAssembly = layerAssembly; + this.name = name; + } + + @Override + public LayerAssembly layer() + { + return layerAssembly; + } + + @Override + public ModuleAssembly module( String layerName, String moduleName ) + { + return layerAssembly.application().module( layerName, moduleName ); + } + + @Override + public ModuleAssembly setName( String name ) + { + this.name = name; + return this; + } + + @Override + public String name() + { + return name; + } + + public ModuleAssembly setMetaInfo( Object info ) + { + metaInfo.set( info ); + return this; + } + + @Override + @SafeVarargs + public final ModuleAssembly withActivators( Class<? extends Activator<Module>>... activators ) + { + this.activators.addAll( Arrays.asList( activators ) ); + return this; + } + + @Override + @SuppressWarnings( {"raw", "unchecked"} ) + public ValueDeclaration values( Class<?>... valueTypes ) + { + List<ValueAssemblyImpl> assemblies = new ArrayList<>(); + + for( Class valueType : valueTypes ) + { + if( valueAssemblies.containsKey( valueType ) ) + { + assemblies.add( valueAssemblies.get( valueType ) ); + } + else + { + ValueAssemblyImpl valueAssembly = new ValueAssemblyImpl( valueType ); + valueAssemblies.put( valueType, valueAssembly ); + assemblies.add( valueAssembly ); + } + } + + return new ValueDeclarationImpl( assemblies ); + } + + @Override + public ValueDeclaration values( Specification<? super ValueAssembly> specification ) + { + List<ValueAssemblyImpl> assemblies = new ArrayList<>(); + for( ValueAssemblyImpl transientAssembly : valueAssemblies.values() ) + { + if( specification.satisfiedBy( transientAssembly ) ) + { + assemblies.add( transientAssembly ); + } + } + + return new ValueDeclarationImpl( assemblies ); + } + + @Override + @SuppressWarnings( {"raw", "unchecked"} ) + public TransientDeclaration transients( Class<?>... transientTypes ) + { + List<TransientAssemblyImpl> assemblies = new ArrayList<>(); + + for( Class valueType : transientTypes ) + { + if( transientAssemblies.containsKey( valueType ) ) + { + assemblies.add( transientAssemblies.get( valueType ) ); + } + else + { + TransientAssemblyImpl transientAssembly = new TransientAssemblyImpl( valueType ); + transientAssemblies.put( valueType, transientAssembly ); + assemblies.add( transientAssembly ); + } + } + + return new TransientDeclarationImpl( assemblies ); + } + + @Override + public TransientDeclaration transients( Specification<? super TransientAssembly> specification ) + { + List<TransientAssemblyImpl> assemblies = new ArrayList<>(); + for( TransientAssemblyImpl transientAssembly : transientAssemblies.values() ) + { + if( specification.satisfiedBy( transientAssembly ) ) + { + assemblies.add( transientAssembly ); + } + } + + return new TransientDeclarationImpl( assemblies ); + } + + @Override + @SuppressWarnings( {"raw", "unchecked"} ) + public EntityDeclaration entities( Class<?>... entityTypes ) + { + List<EntityAssemblyImpl> assemblies = new ArrayList<>(); + + for( Class entityType : entityTypes ) + { + if( entityAssemblies.containsKey( entityType ) ) + { + assemblies.add( entityAssemblies.get( entityType ) ); + } + else + { + EntityAssemblyImpl entityAssembly = new EntityAssemblyImpl( entityType ); + entityAssemblies.put( entityType, entityAssembly ); + assemblies.add( entityAssembly ); + } + } + + return new EntityDeclarationImpl( assemblies ); + } + + @Override + public EntityDeclaration entities( Specification<? super EntityAssembly> specification ) + { + List<EntityAssemblyImpl> assemblies = new ArrayList<>(); + for( EntityAssemblyImpl entityAssembly : entityAssemblies.values() ) + { + if( specification.satisfiedBy( entityAssembly ) ) + { + assemblies.add( entityAssembly ); + } + } + + return new EntityDeclarationImpl( assemblies ); + } + + @Override + public ConfigurationDeclaration configurations( Class<?>... configurationTypes ) + { + List<EntityAssemblyImpl> entityAssemblyList = new ArrayList<>(); + + for( Class entityType : configurationTypes ) + { + if( this.entityAssemblies.containsKey( entityType ) ) + { + entityAssemblyList.add( this.entityAssemblies.get( entityType ) ); + } + else + { + EntityAssemblyImpl entityAssembly = new EntityAssemblyImpl( entityType ); + this.entityAssemblies.put( entityType, entityAssembly ); + entityAssemblyList.add( entityAssembly ); + } + } + + List<ValueAssemblyImpl> valueAssemblyList = new ArrayList<>(); + + for( Class valueType : configurationTypes ) + { + if( valueAssemblies.containsKey( valueType ) ) + { + valueAssemblyList.add( valueAssemblies.get( valueType ) ); + } + else + { + ValueAssemblyImpl valueAssembly = new ValueAssemblyImpl( valueType ); + valueAssemblies.put( valueType, valueAssembly ); + valueAssemblyList.add( valueAssembly ); + valueAssembly.types.add( Identity.class ); + } + } + + return new ConfigurationDeclarationImpl( entityAssemblyList, valueAssemblyList ); + } + + @Override + public ConfigurationDeclaration configurations( Specification<HasTypes> specification ) + { + Specification<HasTypes> isConfigurationComposite = new MatchTypeSpecification( Identity.class ); + specification = Specifications.and( specification, isConfigurationComposite ); + List<EntityAssemblyImpl> entityAssmblyList = new ArrayList<>(); + for( EntityAssemblyImpl entityAssembly : entityAssemblies.values() ) + { + if( specification.satisfiedBy( entityAssembly ) ) + { + entityAssmblyList.add( entityAssembly ); + } + } + List<ValueAssemblyImpl> valueAssemblyList = new ArrayList<>(); + for( ValueAssemblyImpl transientAssembly : valueAssemblies.values() ) + { + if( specification.satisfiedBy( transientAssembly ) ) + { + valueAssemblyList.add( transientAssembly ); + } + } + return new ConfigurationDeclarationImpl( entityAssmblyList, valueAssemblyList ); + } + + @Override + public ObjectDeclaration objects( Class<?>... objectTypes ) + throws AssemblyException + { + List<ObjectAssemblyImpl> assemblies = new ArrayList<>(); + + for( Class<?> objectType : objectTypes ) + { + if( objectType.isInterface() ) + { + throw new AssemblyException( "Interfaces can not be Zest Objects." ); + } + if( objectAssemblies.containsKey( objectType ) ) + { + assemblies.add( objectAssemblies.get( objectType ) ); + } + else + { + ObjectAssemblyImpl objectAssembly = new ObjectAssemblyImpl( objectType ); + objectAssemblies.put( objectType, objectAssembly ); + assemblies.add( objectAssembly ); + } + } + + return new ObjectDeclarationImpl( assemblies ); + } + + @Override + public ObjectDeclaration objects( Specification<? super ObjectAssembly> specification ) + { + List<ObjectAssemblyImpl> assemblies = new ArrayList<>(); + for( ObjectAssemblyImpl objectAssembly : objectAssemblies.values() ) + { + if( specification.satisfiedBy( objectAssembly ) ) + { + assemblies.add( objectAssembly ); + } + } + + return new ObjectDeclarationImpl( assemblies ); + } + + @Override + public ServiceDeclaration addServices( Class<?>... serviceTypes ) + { + List<ServiceAssemblyImpl> assemblies = new ArrayList<>(); + + for( Class<?> serviceType : serviceTypes ) + { + ServiceAssemblyImpl serviceAssembly = new ServiceAssemblyImpl( serviceType ); + serviceAssemblies.add( serviceAssembly ); + assemblies.add( serviceAssembly ); + } + + return new ServiceDeclarationImpl( assemblies ); + } + + @Override + public ServiceDeclaration services( Class<?>... serviceTypes ) + { + List<ServiceAssemblyImpl> assemblies = new ArrayList<>(); + + for( Class<?> serviceType : serviceTypes ) + { + if( Iterables.matchesAny( AssemblySpecifications.types( serviceType ), serviceAssemblies ) ) + { + Iterables.addAll( assemblies, Iterables.filter( AssemblySpecifications.types( serviceType ), serviceAssemblies ) ); + } + else + { + ServiceAssemblyImpl serviceAssembly = new ServiceAssemblyImpl( serviceType ); + serviceAssemblies.add( serviceAssembly ); + assemblies.add( serviceAssembly ); + } + } + + return new ServiceDeclarationImpl( assemblies ); + } + + @Override + public ServiceDeclaration services( Specification<? super ServiceAssembly> specification ) + { + List<ServiceAssemblyImpl> assemblies = new ArrayList<>(); + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + if( specification.satisfiedBy( serviceAssembly ) ) + { + assemblies.add( serviceAssembly ); + } + } + + return new ServiceDeclarationImpl( assemblies ); + } + + @Override + public ImportedServiceDeclaration importedServices( Class<?>... serviceTypes ) + { + List<ImportedServiceAssemblyImpl> assemblies = new ArrayList<>(); + + for( Class<?> serviceType : serviceTypes ) + { + if( importedServiceAssemblies.containsKey( serviceType ) ) + { + assemblies.add( importedServiceAssemblies.get( serviceType ) ); + } + else + { + ImportedServiceAssemblyImpl serviceAssembly = new ImportedServiceAssemblyImpl( serviceType, this ); + importedServiceAssemblies.put( serviceType, serviceAssembly ); + assemblies.add( serviceAssembly ); + } + } + + return new ImportedServiceDeclarationImpl( assemblies ); + } + + @Override + public ImportedServiceDeclaration importedServices( Specification<? super ImportedServiceAssembly> specification ) + { + List<ImportedServiceAssemblyImpl> assemblies = new ArrayList<>(); + for( ImportedServiceAssemblyImpl objectAssembly : importedServiceAssemblies.values() ) + { + if( specification.satisfiedBy( objectAssembly ) ) + { + assemblies.add( objectAssembly ); + } + } + + return new ImportedServiceDeclarationImpl( assemblies ); + } + + @Override + public <T> MixinDeclaration<T> forMixin( Class<T> mixinType ) + { + return metaInfoDeclaration.on( mixinType ); + } + + @Override + public <ThrowableType extends Throwable> void visit( AssemblyVisitor<ThrowableType> visitor ) + throws ThrowableType + { + visitor.visitModule( this ); + + for( TransientAssemblyImpl compositeDeclaration : transientAssemblies.values() ) + { + visitor.visitComposite( new TransientDeclarationImpl( iterable( compositeDeclaration ) ) ); + } + + for( EntityAssemblyImpl entityDeclaration : entityAssemblies.values() ) + { + visitor.visitEntity( new EntityDeclarationImpl( iterable( entityDeclaration ) ) ); + } + + for( ObjectAssemblyImpl objectDeclaration : objectAssemblies.values() ) + { + visitor.visitObject( new ObjectDeclarationImpl( iterable( objectDeclaration ) ) ); + } + + for( ServiceAssemblyImpl serviceDeclaration : serviceAssemblies ) + { + visitor.visitService( new ServiceDeclarationImpl( iterable( serviceDeclaration ) ) ); + } + + for( ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values() ) + { + visitor.visitImportedService( new ImportedServiceDeclarationImpl( iterable( importedServiceDeclaration ) ) ); + } + + for( ValueAssemblyImpl valueDeclaration : valueAssemblies.values() ) + { + visitor.visitValue( new ValueDeclarationImpl( iterable( valueDeclaration ) ) ); + } + } + + ModuleModel assembleModule( AssemblyHelper helper ) + throws AssemblyException + { + List<TransientModel> transientModels = new ArrayList<>(); + List<ObjectModel> objectModels = new ArrayList<>(); + List<ValueModel> valueModels = new ArrayList<>(); + List<ServiceModel> serviceModels = new ArrayList<>(); + List<ImportedServiceModel> importedServiceModels = new ArrayList<>(); + + if( name == null ) + { + throw new AssemblyException( "Module must have name set" ); + } + + for( TransientAssemblyImpl compositeDeclaration : transientAssemblies.values() ) + { + transientModels.add( compositeDeclaration.newTransientModel( metaInfoDeclaration, helper ) ); + } + + for( ValueAssemblyImpl valueDeclaration : valueAssemblies.values() ) + { + valueModels.add( valueDeclaration.newValueModel( metaInfoDeclaration, helper ) ); + } + + List<EntityModel> entityModels = new ArrayList<>(); + for( EntityAssemblyImpl entityDeclaration : entityAssemblies.values() ) + { + entityModels.add( entityDeclaration.newEntityModel( metaInfoDeclaration, + metaInfoDeclaration, + metaInfoDeclaration, + metaInfoDeclaration, + helper ) ); + } + + for( ObjectAssemblyImpl objectDeclaration : objectAssemblies.values() ) + { + objectDeclaration.addObjectModel( objectModels ); + } + + for( ServiceAssemblyImpl serviceDeclaration : serviceAssemblies ) + { + if( serviceDeclaration.identity == null ) + { + serviceDeclaration.identity = generateId( serviceDeclaration.types() ); + } + + serviceModels.add( serviceDeclaration.newServiceModel( metaInfoDeclaration, helper ) ); + } + + for( ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values() ) + { + importedServiceDeclaration.addImportedServiceModel( importedServiceModels ); + } + + ModuleModel moduleModel = new ModuleModel( name, + metaInfo, + new ActivatorsModel<>( activators ), + new TransientsModel( transientModels ), + new EntitiesModel( entityModels ), + new ObjectsModel( objectModels ), + new ValuesModel( valueModels ), + new ServicesModel( serviceModels ), + new ImportedServicesModel( importedServiceModels ) ); + + // Check for duplicate service identities + Set<String> identities = new HashSet<>(); + for( ServiceModel serviceModel : serviceModels ) + { + String identity = serviceModel.identity(); + if( identities.contains( identity ) ) + { + throw new DuplicateServiceIdentityException( + "Duplicated service identity: " + identity + " in module " + moduleModel.name() + ); + } + identities.add( identity ); + } + for( ImportedServiceModel serviceModel : importedServiceModels ) + { + String identity = serviceModel.identity(); + if( identities.contains( identity ) ) + { + throw new DuplicateServiceIdentityException( + "Duplicated service identity: " + identity + " in module " + moduleModel.name() + ); + } + identities.add( identity ); + } + + for( ImportedServiceModel importedServiceModel : importedServiceModels ) + { + boolean found = false; + for( ObjectModel objectModel : objectModels ) + { + if( first( objectModel.types() ).equals( importedServiceModel.serviceImporter() ) ) + { + found = true; + break; + } + } + if( !found ) + { + @SuppressWarnings( "raw" ) + Class<? extends ServiceImporter> serviceFactoryType = importedServiceModel.serviceImporter(); + ObjectModel objectModel = new ObjectModel( serviceFactoryType, Visibility.module, new MetaInfo() ); + objectModels.add( objectModel ); + } + } + + return moduleModel; + } + + private String generateId( Iterable<Class<?>> serviceTypes ) + { + // Find service identity that is not yet used + Class<?> serviceType = serviceTypes.iterator() + .next(); // Use the first Iterable, which *SHOULD* be the main serviceType + int idx = 0; + String id = serviceType.getSimpleName(); + boolean invalid; + do + { + invalid = false; + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + if( serviceAssembly.identity() != null && serviceAssembly.identity().equals( id ) ) + { + idx++; + id = serviceType.getSimpleName() + "_" + idx; + invalid = true; + break; + } + } + } + while( invalid ); + return id; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ObjectAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ObjectAssemblyImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ObjectAssemblyImpl.java new file mode 100644 index 0000000..71475aa --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ObjectAssemblyImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import java.lang.reflect.Modifier; +import java.util.List; +import org.qi4j.api.common.InvalidApplicationException; +import org.qi4j.api.common.MetaInfo; +import org.qi4j.api.common.Visibility; +import org.qi4j.api.composite.Composite; +import org.qi4j.bootstrap.ObjectAssembly; +import org.qi4j.functional.Iterables; +import org.qi4j.runtime.object.ObjectModel; + +/** + * Assembly of an Object. + */ +public final class ObjectAssemblyImpl + implements ObjectAssembly +{ + private Class<?> objectType; + MetaInfo metaInfo = new MetaInfo(); + Visibility visibility = Visibility.module; + + public ObjectAssemblyImpl( Class<?> clazz ) + { + // best try to find out if the class is a concrete class + if( clazz.isEnum() || + ( !Composite.class.isAssignableFrom( clazz ) && Modifier.isAbstract( clazz.getModifiers() ) ) ) + { + throw new IllegalArgumentException( "Declared objects must be concrete classes: " + clazz ); + } + this.objectType = clazz; + } + + @Override + public Iterable<Class<?>> types() + { + return Iterables.<Class<?>>iterable( objectType ); + } + + void addObjectModel( List<ObjectModel> objectModels ) + { + try + { + ObjectModel objectModel = new ObjectModel( objectType, visibility, metaInfo ); + objectModels.add( objectModel ); + } + catch( Throwable e ) + { + throw new InvalidApplicationException( "Could not register " + objectType.getName(), e ); + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ObjectDeclarationImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ObjectDeclarationImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ObjectDeclarationImpl.java new file mode 100644 index 0000000..c06032e --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ObjectDeclarationImpl.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import org.qi4j.api.common.Visibility; +import org.qi4j.bootstrap.ObjectDeclaration; + +/** + * Declaration of an Object. Created by {@link org.qi4j.runtime.bootstrap.ModuleAssemblyImpl#objects(Class[])}. + */ +public final class ObjectDeclarationImpl + implements ObjectDeclaration +{ + private final Iterable<ObjectAssemblyImpl> assemblies; + + public ObjectDeclarationImpl( Iterable<ObjectAssemblyImpl> assemblies ) + { + this.assemblies = assemblies; + } + + @Override + public ObjectDeclaration setMetaInfo( Object info ) + { + for( ObjectAssemblyImpl assembly : assemblies ) + { + assembly.metaInfo.set( info ); + } + return this; + } + + @Override + public ObjectDeclaration visibleIn( Visibility visibility ) + throws IllegalStateException + { + for( ObjectAssemblyImpl assembly : assemblies ) + { + assembly.visibility = visibility; + } + return this; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/OrAppliesToFilter.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/OrAppliesToFilter.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/OrAppliesToFilter.java new file mode 100644 index 0000000..e50b748 --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/OrAppliesToFilter.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import java.lang.reflect.Method; +import org.qi4j.api.common.AppliesToFilter; + +/** + * JAVADOC + */ +final class OrAppliesToFilter + implements AppliesToFilter +{ + private final AppliesToFilter left; + private final AppliesToFilter right; + + OrAppliesToFilter( AppliesToFilter left, AppliesToFilter right ) + { + this.left = left; + this.right = right; + } + + @Override + public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass ) + { + return left.appliesTo( method, mixin, compositeType, fragmentClass ) || + right.appliesTo( method, mixin, compositeType, fragmentClass ); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ServiceAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ServiceAssemblyImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ServiceAssemblyImpl.java new file mode 100644 index 0000000..1adbfe6 --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ServiceAssemblyImpl.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * Copyright (c) 2012, Paul Merlin. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.qi4j.runtime.bootstrap; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import org.qi4j.api.activation.Activator; +import org.qi4j.api.activation.Activators; +import org.qi4j.api.common.InvalidApplicationException; +import org.qi4j.api.service.ServiceComposite; +import org.qi4j.api.util.Annotations; +import org.qi4j.api.util.Classes; +import org.qi4j.bootstrap.ServiceAssembly; +import org.qi4j.bootstrap.StateDeclarations; +import org.qi4j.functional.Function; +import org.qi4j.functional.Iterables; +import org.qi4j.runtime.activation.ActivatorsModel; +import org.qi4j.runtime.service.ServiceModel; + +/** + * Assembly of a Service. + */ +public final class ServiceAssemblyImpl extends CompositeAssemblyImpl + implements ServiceAssembly +{ + String identity; + boolean instantiateOnStartup = false; + List<Class<? extends Activator<?>>> activators = new ArrayList<>(); + + public ServiceAssemblyImpl( Class<?> serviceType ) + { + super( serviceType ); + // The composite must always implement ServiceComposite, as a marker interface + if( !ServiceComposite.class.isAssignableFrom( serviceType ) ) + { + types.add( ServiceComposite.class ); + } + } + + @Override + public String identity() + { + return identity; + } + + @SuppressWarnings( {"raw", "unchecked"} ) + ServiceModel newServiceModel( StateDeclarations stateDeclarations, AssemblyHelper helper ) + { + try + { + buildComposite( helper, stateDeclarations ); + List<Class<? extends Activator<?>>> activatorClasses = Iterables.toList( + Iterables.<Class<? extends Activator<?>>>flatten( activators, activatorsDeclarations( types ) ) ); + return new ServiceModel( types, visibility, metaInfo, + new ActivatorsModel( activatorClasses ), + mixinsModel, stateModel, compositeMethodsModel, + identity, instantiateOnStartup ); + } + catch( Exception e ) + { + throw new InvalidApplicationException( "Could not register " + types, e ); + } + } + + private Iterable<Class<? extends Activator<?>>> activatorsDeclarations( Iterable<? extends Class<?>> typess ) + { + // Find activator declarations + ArrayList<Type> allTypes = new ArrayList<>(); + for( Class<?> type : typess ) + { + Iterable<Type> types = Classes.typesOf( type ); + Iterables.addAll( allTypes, types ); + } + // Find all activators and flattern them into an iterable + Function<Type, Iterable<Class<? extends Activator<?>>>> function = new Function<Type, Iterable<Class<? extends Activator<?>>>>() + { + @Override + public Iterable<Class<? extends Activator<?>>> map( Type type ) + { + Activators activators = Annotations.annotationOn( type, Activators.class ); + if( activators == null ) + { + return Iterables.empty(); + } + else + { + return Iterables.iterable( activators.value() ); + } + } + }; + Iterable<Class<? extends Activator<?>>> flatten = Iterables.flattenIterables( Iterables.map( function, allTypes ) ); + return Iterables.toList( flatten ); + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ServiceDeclarationImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ServiceDeclarationImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ServiceDeclarationImpl.java new file mode 100644 index 0000000..34e1f6d --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ServiceDeclarationImpl.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * Copyright (c) 2012, Paul Merlin. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import java.util.ArrayList; +import java.util.List; +import org.qi4j.api.activation.Activator; +import org.qi4j.api.common.Visibility; +import org.qi4j.api.service.qualifier.ServiceTags; +import org.qi4j.bootstrap.ServiceDeclaration; + +import static java.util.Arrays.asList; + +/** + * Declaration of a Service. Created by {@link org.qi4j.runtime.bootstrap.ModuleAssemblyImpl#services(Class[])}. + */ +public final class ServiceDeclarationImpl + implements ServiceDeclaration +{ + private final Iterable<ServiceAssemblyImpl> serviceAssemblies; + + public ServiceDeclarationImpl( Iterable<ServiceAssemblyImpl> serviceAssemblies ) + { + this.serviceAssemblies = serviceAssemblies; + } + + @Override + public ServiceDeclaration visibleIn( Visibility visibility ) + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + serviceAssembly.visibility = visibility; + } + return this; + } + + @Override + public ServiceDeclaration identifiedBy( String identity ) + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + serviceAssembly.identity = identity; + } + return this; + } + + @Override + public ServiceDeclaration taggedWith( String... tags ) + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + ServiceTags previousTags = serviceAssembly.metaInfo.get( ServiceTags.class ); + if( previousTags != null ) + { + List<String> tagList = new ArrayList<>(); + tagList.addAll( asList( previousTags.tags() ) ); + tagList.addAll( asList( tags ) ); + serviceAssembly.metaInfo.set( new ServiceTags( tagList.toArray( new String[ tagList.size() ] ) ) ); + } + else + { + serviceAssembly.metaInfo.set( new ServiceTags( tags ) ); + } + } + + return this; + } + + @Override + public ServiceDeclaration instantiateOnStartup() + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + serviceAssembly.instantiateOnStartup = true; + } + return this; + } + + @Override + public ServiceDeclaration setMetaInfo( Object serviceAttribute ) + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + serviceAssembly.metaInfo.set( serviceAttribute ); + } + return this; + } + + @Override + public ServiceDeclaration withConcerns( Class<?>... concerns ) + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + serviceAssembly.concerns.addAll( asList( concerns ) ); + } + return this; + } + + @Override + public ServiceDeclaration withSideEffects( Class<?>... sideEffects ) + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + serviceAssembly.sideEffects.addAll( asList( sideEffects ) ); + } + return this; + } + + @Override + public ServiceDeclaration withMixins( Class<?>... mixins ) + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + serviceAssembly.mixins.addAll( asList( mixins ) ); + } + return this; + } + + @Override + public ServiceDeclaration withTypes( Class<?>... types ) + { + for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) + { + serviceAssembly.types.addAll( asList( types ) ); + } + return this; + } + + @Override + @SafeVarargs + public final ServiceDeclaration withActivators( Class<? extends Activator<?>>... activators ) + { + for ( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) { + serviceAssembly.activators.addAll( asList( activators ) ); + } + return this; + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TransientAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TransientAssemblyImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TransientAssemblyImpl.java new file mode 100644 index 0000000..dfc9721 --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TransientAssemblyImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import org.qi4j.api.common.InvalidApplicationException; +import org.qi4j.api.composite.TransientComposite; +import org.qi4j.bootstrap.StateDeclarations; +import org.qi4j.bootstrap.TransientAssembly; +import org.qi4j.runtime.composite.TransientModel; + +/** + * Declaration of a TransientComposite. + */ +public final class TransientAssemblyImpl extends CompositeAssemblyImpl + implements TransientAssembly +{ + public TransientAssemblyImpl( Class<?> transientType ) + { + super( transientType ); + + // The composite must always implement TransientComposite, as a marker interface + if( !TransientComposite.class.isAssignableFrom( transientType ) ) + { + types.add( TransientComposite.class ); + } + + // If type is a class, register it as a mixin + if( !transientType.isInterface() ) + { + mixins.add( transientType ); + } + } + + TransientModel newTransientModel( StateDeclarations stateDeclarations, AssemblyHelper helper ) + { + try + { + buildComposite( helper, stateDeclarations ); + TransientModel transientModel = new TransientModel( + types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel ); + + return transientModel; + } + catch( Exception e ) + { + throw new InvalidApplicationException( "Could not register " + types, e ); + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TransientDeclarationImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TransientDeclarationImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TransientDeclarationImpl.java new file mode 100644 index 0000000..9a9154f --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TransientDeclarationImpl.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import org.qi4j.api.common.Visibility; +import org.qi4j.bootstrap.TransientDeclaration; + +import static java.util.Arrays.asList; + +/** + * Declaration of a Composite. Created by {@link org.qi4j.bootstrap.ModuleAssembly#transients(Class[])}. + */ +public final class TransientDeclarationImpl + implements TransientDeclaration +{ + private final Iterable<TransientAssemblyImpl> assemblies; + + public TransientDeclarationImpl( Iterable<TransientAssemblyImpl> assemblies ) + { + this.assemblies = assemblies; + } + + @Override + public TransientDeclaration setMetaInfo( Object info ) + { + for( TransientAssemblyImpl assembly : assemblies ) + { + assembly.metaInfo.set( info ); + } + return this; + } + + @Override + public TransientDeclaration visibleIn( Visibility visibility ) + { + for( TransientAssemblyImpl assembly : assemblies ) + { + assembly.visibility = visibility; + } + return this; + } + + @Override + public TransientDeclaration withConcerns( Class<?>... concerns ) + { + for( TransientAssemblyImpl assembly : assemblies ) + { + assembly.concerns.addAll( asList( concerns ) ); + } + return this; + } + + @Override + public TransientDeclaration withSideEffects( Class<?>... sideEffects ) + { + for( TransientAssemblyImpl assembly : assemblies ) + { + assembly.sideEffects.addAll( asList( sideEffects ) ); + } + return this; + } + + @Override + public TransientDeclaration withMixins( Class<?>... mixins ) + { + for( TransientAssemblyImpl assembly : assemblies ) + { + assembly.mixins.addAll( asList( mixins ) ); + } + return this; + } + + @Override + public TransientDeclaration withTypes( Class<?>... types ) + { + for( TransientAssemblyImpl assembly : assemblies ) + { + assembly.types.addAll( asList( types ) ); + } + return this; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TypeCheckAppliesToFilter.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TypeCheckAppliesToFilter.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TypeCheckAppliesToFilter.java new file mode 100644 index 0000000..dee1993 --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TypeCheckAppliesToFilter.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import java.lang.reflect.Method; +import org.qi4j.api.common.AppliesToFilter; + +/** + * JAVADOC + */ +final class TypeCheckAppliesToFilter + implements AppliesToFilter +{ + @SuppressWarnings( "raw" ) + private final Class type; + + @SuppressWarnings( "raw" ) + TypeCheckAppliesToFilter( Class type ) + { + this.type = type; + } + + @Override + @SuppressWarnings( "unchecked" ) + public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass ) + { + return type.isAssignableFrom( compositeType ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TypedFragmentAppliesToFilter.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TypedFragmentAppliesToFilter.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TypedFragmentAppliesToFilter.java new file mode 100644 index 0000000..e007697 --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/TypedFragmentAppliesToFilter.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import java.lang.reflect.Method; +import org.qi4j.api.common.AppliesToFilter; + +/** + * JAVADOC + */ +final class TypedFragmentAppliesToFilter + implements AppliesToFilter +{ + @Override + public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass ) + { + return method.getDeclaringClass().isAssignableFrom( fragmentClass ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ValueAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ValueAssemblyImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ValueAssemblyImpl.java new file mode 100644 index 0000000..605efa1 --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ValueAssemblyImpl.java @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2007-2011, Rickard Ãberg. All Rights Reserved. + * Copyright (c) 2014, Paul Merlin. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.runtime.bootstrap; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Member; +import org.qi4j.api.association.Association; +import org.qi4j.api.association.GenericAssociationInfo; +import org.qi4j.api.association.ManyAssociation; +import org.qi4j.api.association.NamedAssociation; +import org.qi4j.api.common.InvalidApplicationException; +import org.qi4j.api.common.MetaInfo; +import org.qi4j.api.common.Optional; +import org.qi4j.api.common.QualifiedName; +import org.qi4j.api.common.UseDefaults; +import org.qi4j.api.constraint.Constraint; +import org.qi4j.api.property.GenericPropertyInfo; +import org.qi4j.api.property.Property; +import org.qi4j.api.util.Annotations; +import org.qi4j.api.util.Classes; +import org.qi4j.api.value.ValueComposite; +import org.qi4j.bootstrap.StateDeclarations; +import org.qi4j.bootstrap.ValueAssembly; +import org.qi4j.runtime.association.AssociationModel; +import org.qi4j.runtime.association.AssociationsModel; +import org.qi4j.runtime.association.ManyAssociationModel; +import org.qi4j.runtime.association.ManyAssociationsModel; +import org.qi4j.runtime.association.NamedAssociationModel; +import org.qi4j.runtime.association.NamedAssociationsModel; +import org.qi4j.runtime.composite.StateModel; +import org.qi4j.runtime.composite.ValueConstraintsInstance; +import org.qi4j.runtime.composite.ValueConstraintsModel; +import org.qi4j.runtime.property.PropertyModel; +import org.qi4j.runtime.value.ValueModel; +import org.qi4j.runtime.value.ValueStateModel; + +import static org.qi4j.api.util.Annotations.isType; +import static org.qi4j.api.util.Classes.typeOf; +import static org.qi4j.functional.Iterables.filter; +import static org.qi4j.functional.Iterables.first; + +/** + * Declaration of a ValueComposite. + */ +public final class ValueAssemblyImpl + extends CompositeAssemblyImpl + implements ValueAssembly +{ + private AssociationsModel associationsModel; + private ManyAssociationsModel manyAssociationsModel; + private NamedAssociationsModel namedAssociationsModel; + + public ValueAssemblyImpl( Class<?> compositeType ) + { + super( compositeType ); + // The composite must always implement ValueComposite, as a marker interface + if( !ValueComposite.class.isAssignableFrom( compositeType ) ) + { + types.add( ValueComposite.class ); + } + } + + @Override + protected StateModel createStateModel() + { + return new ValueStateModel( propertiesModel, associationsModel, manyAssociationsModel, namedAssociationsModel ); + } + + ValueModel newValueModel( + StateDeclarations stateDeclarations, + AssemblyHelper helper + ) + { + try + { + associationsModel = new AssociationsModel(); + manyAssociationsModel = new ManyAssociationsModel(); + namedAssociationsModel = new NamedAssociationsModel(); + buildComposite( helper, stateDeclarations ); + + ValueModel valueModel = new ValueModel( + types, visibility, metaInfo, mixinsModel, (ValueStateModel) stateModel, compositeMethodsModel ); + + return valueModel; + } + catch( Exception e ) + { + throw new InvalidApplicationException( "Could not register " + types, e ); + } + } + + @Override + protected void addStateFor( AccessibleObject accessor, + Iterable<Class<? extends Constraint<?, ?>>> constraintClasses + ) + { + String stateName = QualifiedName.fromAccessor( accessor ).name(); + + if( registeredStateNames.contains( stateName ) ) + { + return; // Skip already registered names + } + + Class<?> accessorType = Classes.RAW_CLASS.map( typeOf( accessor ) ); + if( Property.class.isAssignableFrom( accessorType ) ) + { + propertiesModel.addProperty( newPropertyModel( accessor, constraintClasses ) ); + registeredStateNames.add( stateName ); + } + else if( Association.class.isAssignableFrom( accessorType ) ) + { + associationsModel.addAssociation( newAssociationModel( accessor, constraintClasses ) ); + registeredStateNames.add( stateName ); + } + else if( ManyAssociation.class.isAssignableFrom( accessorType ) ) + { + manyAssociationsModel.addManyAssociation( newManyAssociationModel( accessor, constraintClasses ) ); + registeredStateNames.add( stateName ); + } + else if( NamedAssociation.class.isAssignableFrom( accessorType ) ) + { + namedAssociationsModel.addNamedAssociation( newNamedAssociationModel( accessor, constraintClasses ) ); + registeredStateNames.add( stateName ); + } + } + + @Override + protected PropertyModel newPropertyModel( AccessibleObject accessor, + Iterable<Class<? extends Constraint<?, ?>>> constraintClasses + ) + { + Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor ); + boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null; + ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericPropertyInfo.propertyTypeOf( accessor ), ( (Member) accessor ) + .getName(), optional, constraintClasses, accessor ); + ValueConstraintsInstance valueConstraintsInstance = null; + if( valueConstraintsModel.isConstrained() ) + { + valueConstraintsInstance = valueConstraintsModel.newInstance(); + } + MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor ); + boolean useDefaults = metaInfo.get( UseDefaults.class ) != null || stateDeclarations.useDefaults( accessor ); + Object initialValue = stateDeclarations.initialValueOf( accessor ); + return new PropertyModel( accessor, true, useDefaults, valueConstraintsInstance, metaInfo, initialValue ); + } + + public AssociationModel newAssociationModel( AccessibleObject accessor, + Iterable<Class<? extends Constraint<?, ?>>> constraintClasses + ) + { + Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor ); + boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null; + + // Constraints for Association references + ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo + .associationTypeOf( accessor ), ( (Member) accessor ).getName(), optional, constraintClasses, accessor ); + ValueConstraintsInstance valueConstraintsInstance = null; + if( valueConstraintsModel.isConstrained() ) + { + valueConstraintsInstance = valueConstraintsModel.newInstance(); + } + + // Constraints for the Association itself + valueConstraintsModel = constraintsFor( annotations, Association.class, ( (Member) accessor ).getName(), optional, constraintClasses, accessor ); + ValueConstraintsInstance associationValueConstraintsInstance = null; + if( valueConstraintsModel.isConstrained() ) + { + associationValueConstraintsInstance = valueConstraintsModel.newInstance(); + } + + MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor ); + AssociationModel associationModel = new AssociationModel( accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo ); + return associationModel; + } + + public ManyAssociationModel newManyAssociationModel( AccessibleObject accessor, + Iterable<Class<? extends Constraint<?, ?>>> constraintClasses + ) + { + Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor ); + boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null; + + // Constraints for entities in ManyAssociation + ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo + .associationTypeOf( accessor ), ( (Member) accessor ).getName(), optional, constraintClasses, accessor ); + ValueConstraintsInstance valueConstraintsInstance = null; + if( valueConstraintsModel.isConstrained() ) + { + valueConstraintsInstance = valueConstraintsModel.newInstance(); + } + + // Constraints for the ManyAssociation itself + valueConstraintsModel = constraintsFor( annotations, ManyAssociation.class, ( (Member) accessor ).getName(), optional, constraintClasses, accessor ); + ValueConstraintsInstance manyValueConstraintsInstance = null; + if( valueConstraintsModel.isConstrained() ) + { + manyValueConstraintsInstance = valueConstraintsModel.newInstance(); + } + MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor ); + ManyAssociationModel associationModel = new ManyAssociationModel( accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo ); + return associationModel; + } + + public NamedAssociationModel newNamedAssociationModel( AccessibleObject accessor, + Iterable<Class<? extends Constraint<?, ?>>> constraintClasses + ) + { + Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor ); + boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null; + + // Constraints for entities in NamedAssociation + ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo + .associationTypeOf( accessor ), ( (Member) accessor ).getName(), optional, constraintClasses, accessor ); + ValueConstraintsInstance valueConstraintsInstance = null; + if( valueConstraintsModel.isConstrained() ) + { + valueConstraintsInstance = valueConstraintsModel.newInstance(); + } + + // Constraints for the NamedAssociation itself + valueConstraintsModel = constraintsFor( annotations, NamedAssociation.class, ( (Member) accessor ).getName(), optional, constraintClasses, accessor ); + ValueConstraintsInstance namedValueConstraintsInstance = null; + if( valueConstraintsModel.isConstrained() ) + { + namedValueConstraintsInstance = valueConstraintsModel.newInstance(); + } + MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor ); + NamedAssociationModel associationModel = new NamedAssociationModel( accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo ); + return associationModel; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ValueDeclarationImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ValueDeclarationImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ValueDeclarationImpl.java new file mode 100644 index 0000000..22169bf --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/bootstrap/ValueDeclarationImpl.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2007, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.bootstrap; + +import org.qi4j.api.common.Visibility; +import org.qi4j.bootstrap.ValueDeclaration; + +import static java.util.Arrays.asList; + +/** + * Declaration of a ValueComposite. + */ +public final class ValueDeclarationImpl + implements ValueDeclaration +{ + private final Iterable<ValueAssemblyImpl> assemblies; + + public ValueDeclarationImpl( Iterable<ValueAssemblyImpl> assemblies ) + { + this.assemblies = assemblies; + } + + @Override + public ValueDeclaration setMetaInfo( Object info ) + { + for( ValueAssemblyImpl assembly : assemblies ) + { + assembly.metaInfo.set( info ); + } + return this; + } + + @Override + public ValueDeclaration visibleIn( Visibility visibility ) + { + for( ValueAssemblyImpl assembly : assemblies ) + { + assembly.visibility = visibility; + } + return this; + } + + @Override + public ValueDeclaration withConcerns( Class<?>... concerns ) + { + for( ValueAssemblyImpl assembly : assemblies ) + { + assembly.concerns.addAll( asList( concerns ) ); + } + return this; + } + + @Override + public ValueDeclaration withSideEffects( Class<?>... sideEffects ) + { + for( ValueAssemblyImpl assembly : assemblies ) + { + assembly.sideEffects.addAll( asList( sideEffects ) ); + } + return this; + } + + @Override + public ValueDeclaration withMixins( Class<?>... mixins ) + { + for( ValueAssemblyImpl assembly : assemblies ) + { + assembly.mixins.addAll( asList( mixins ) ); + } + return this; + } + + @Override + public ValueDeclaration withTypes( Class<?>... types ) + { + for( ValueAssemblyImpl assembly : assemblies ) + { + assembly.types.addAll( asList( types ) ); + } + return this; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractConstraintModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractConstraintModel.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractConstraintModel.java new file mode 100644 index 0000000..d9ffbbd --- /dev/null +++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractConstraintModel.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2008, Rickard Ãberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.runtime.composite; + +import java.lang.annotation.Annotation; +import org.qi4j.api.constraint.ConstraintDescriptor; +import org.qi4j.functional.Visitable; +import org.qi4j.functional.Visitor; + +/** + * JAVADOC + */ +public abstract class AbstractConstraintModel + implements ConstraintDescriptor, Visitable<ConstraintDescriptor> +{ + protected final Annotation annotation; + + public AbstractConstraintModel( Annotation annotation ) + { + this.annotation = annotation; + } + + @Override + public Annotation annotation() + { + return annotation; + } + + public abstract ConstraintInstance<?, ?> newInstance(); + + @Override + public <ThrowableType extends Throwable> boolean accept( Visitor<? super ConstraintDescriptor, ThrowableType> modelVisitor ) + throws ThrowableType + { + return modelVisitor.visit( this ); + } +} \ No newline at end of file
