http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/BootstrapException.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/BootstrapException.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/BootstrapException.java new file mode 100644 index 0000000..e590d0a --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/BootstrapException.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +/** + * This exception is thrown if no ApplicationFactory provider can be found + */ +public class BootstrapException + extends RuntimeException +{ + public BootstrapException( String message ) + { + super( message ); + } + + public BootstrapException( String message, Throwable cause ) + { + super( message, cause ); + } +}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ClassScanner.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ClassScanner.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ClassScanner.java new file mode 100644 index 0000000..5850e95 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ClassScanner.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.CodeSource; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +/** + * Scan classpath for classes that matches given criteria. Useful for automated assemblies with lots of similar classes. + */ +public class ClassScanner +{ + private static final ValidClass VALID_CLASS_PREDICATE = new ValidClass(); + + /** + * Get all classes from the same package of the given class, and recursively in all subpackages. + * <p> + * This only works if the seed class is loaded from a file: URL. Jar files are possible as well. Abstract classes + * are not included in the results. For further filtering use e.g. Stream.filter. + * </p> + * @param seedClass starting point for classpath scanning + * + * @return Stream of all concrete classes in the same package as the seedclass, and also all classes in subpackages. + */ + public static Stream<? extends Class<?>> findClasses( final Class<?> seedClass ) + { + CodeSource codeSource = seedClass.getProtectionDomain().getCodeSource(); + if( codeSource == null ) + { + return Stream.of(); + } + + URL location = codeSource.getLocation(); + + if( !location.getProtocol().equals( "file" ) ) + { + throw new IllegalArgumentException( + "Can only enumerate classes from file system locations. URL is:" + location ); + } + + final File file; + try + { + file = new File( location.toURI().getPath() ); + } + catch( URISyntaxException e ) + { + throw new IllegalArgumentException( + "The file location of codebase is invalid. Can not convert to URI. URL is:" + location ); + } + + if( file.getName().endsWith( ".jar" ) ) + { + try + { + final String packageName = seedClass.getPackage().getName().replace( '.', '/' ); + + JarFile jarFile = new JarFile( file ); + List<JarEntry> entries = Collections.list( jarFile.entries() ); + try + { + return entries.stream() + .filter( jarEntry -> jarEntry.getName().startsWith( packageName ) + && jarEntry.getName().endsWith( ".class" ) ) + .map( jarEntry -> + { + String name = jarEntry.getName(); + name = name.substring( 0, name.length() - 6 ); + name = name.replace( '/', '.' ); + try + { + return seedClass.getClassLoader().loadClass( name ); + } + catch( ClassNotFoundException e ) + { + return null; + } + } ) + .filter( VALID_CLASS_PREDICATE ); + } + finally + { + jarFile.close(); + } + } + catch( IOException e ) + { + throw new IllegalArgumentException( "Could not open jar file " + file, e ); + } + } + else + { + final File path = new File( file, seedClass.getPackage().getName().replace( '.', File.separatorChar ) ); + Stream<File> classFiles = findFiles( path, candidate -> candidate.getName().endsWith( ".class" ) ); + return classFiles + .map( classFile -> + { + String fileName = classFile.getAbsolutePath().substring( file.toString().length() + 1 ); + fileName = fileName.replace( File.separatorChar, '.' ).substring( 0, fileName.length() - 6 ); + try + { + return seedClass.getClassLoader().loadClass( fileName ); + } + catch( ClassNotFoundException e ) + { + return null; + } + } ) + .filter( VALID_CLASS_PREDICATE ); + } + } + + /** + * Useful specification for filtering classes based on a regular expression matching the class names. + * <p> + * Example: matches(".*Model") -> match only class names that end with Model + * </p> + * + * @param regex The regular expression to be matched. + * + * @return regex class name specification + */ + public static Predicate<Class<?>> matches( String regex ) + { + final Pattern pattern = Pattern.compile( regex ); + return aClass -> pattern.matcher( aClass.getName() ).matches(); + } + + private static Stream<File> findFiles( File directory, final Predicate<File> filter ) + { + File[] listedFiles = directory.listFiles(); + if( listedFiles == null ) + { + return Stream.of(); + } + return Stream.concat( Stream.of( listedFiles ).filter( filter ), + Stream.of( listedFiles ) + .filter( File::isDirectory ) + .map( dir -> findFiles( dir, filter ) ) + .flatMap( Function.identity() ) ); + } + + private static class ValidClass + implements Predicate<Class<?>> + { + @Override + public boolean test( Class<?> item ) + { + return ( item.isInterface() || !Modifier.isAbstract( item.getModifiers() ) ) + && ( !item.isEnum() && !item.isAnonymousClass() ); + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ConfigurationAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ConfigurationAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ConfigurationAssembly.java new file mode 100644 index 0000000..c827e04 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ConfigurationAssembly.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.type.HasTypes; + +/** + * This represents the assembly information of a single ConfigurationComposite in a Module. + */ +public interface ConfigurationAssembly + extends HasTypes +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ConfigurationDeclaration.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ConfigurationDeclaration.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ConfigurationDeclaration.java new file mode 100644 index 0000000..080cbb7 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ConfigurationDeclaration.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.common.Visibility; + +/** + * Fluent API for declaring configurations. Instances + * of this API are acquired by calling {@link ModuleAssembly#configurations(Class[])}. + */ +public interface ConfigurationDeclaration +{ + /** + * Set additional metainfo for this configuration declaration. + * + * @param info metainfo that can be retrieved from the CompositeDescriptor. + * + * @return This instance for a fluid DSL + */ + ConfigurationDeclaration setMetaInfo( Object info ); + + /** + * Set visibility for declared entities. + * + * @param visibility The {@link Visibility} that this ConfigurationComposite will have. + * + * @return This instance for a fluid DSL + */ + ConfigurationDeclaration visibleIn( Visibility visibility ); + + /** + * Declare additional concerns for these configurations. + * + * @param concerns The concerns that are to be added to the ConfigurationComposite beyond the statically declared ones. + * + * @return This instance for a fluid DSL + */ + ConfigurationDeclaration withConcerns( Class<?>... concerns ); + + /** + * Declare additional side-effects for these configurations. + * + * @param sideEffects The sideeffects that are to be added to the ConfigurationComposite beyond the statically declared ones. + * + * @return This instance for a fluid DSL + */ + ConfigurationDeclaration withSideEffects( Class<?>... sideEffects ); + + /** + * Declare additional mixins for these configurations. + * <p> + * This can be useful to override any default mixins from the configuration interface. + * </p> + * @param mixins The mixins that are to be added to the ConfigurationComposite beyond the statically declared ones. + * + * @return This instance for a fluid DSL + */ + ConfigurationDeclaration withMixins( Class<?>... mixins ); + + /** + * Declare additional interfaces for these declared interfaces. + * <p> + * This can be useful to add types that the Configuration should implement, but + * which you do not want to include in the entity interface itself. + * </p> + * @param types list of interfaces to add + * + * @return This instance for a fluid DSL + */ + ConfigurationDeclaration withTypes( Class<?>... types ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java new file mode 100644 index 0000000..88c84f1 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.PolygeneAPI; +import org.apache.polygene.api.structure.Application; +import org.apache.polygene.api.structure.ApplicationDescriptor; +import org.apache.polygene.spi.PolygeneSPI; + +/** + * Main bootstrap class for starting Polygene and creating new applications. + * <p> + * Instantiate this and call one of the factory methods to get started. + * </p> + * <p> + * This class will use the Service Loader mechanism in Java to try to locate a runtime that implements + * the PolygeneRuntime interface. This avoids a direct dependency from the bootstrap to the runtime. + * </p> + */ +public final class Energy4Java +{ + private PolygeneRuntime runtime; + + public Energy4Java( RuntimeFactory runtimeFactory ) + { + this( runtimeFactory.createRuntime() ); + } + + public Energy4Java() + { + this( new RuntimeFactory.StandaloneApplicationRuntimeFactory().createRuntime() ); + } + + public Energy4Java( PolygeneRuntime runtime ) + { + if( runtime == null ) + { + throw new BootstrapException( "Can not create Polygene without a Polygene Runtime." ); + } + this.runtime = runtime; + } + + public ApplicationDescriptor newApplicationModel( ApplicationAssembler assembler ) + throws AssemblyException + { + ApplicationAssembly assembly = assembler.assemble( runtime.applicationAssemblyFactory() ); + + if( assembly == null ) + { + throw new AssemblyException( "Application assembler did not return any ApplicationAssembly" ); + } + + try + { + ApplicationModelFactory modelFactory = runtime.applicationModelFactory(); + return modelFactory.newApplicationModel( assembly ); + } + catch( RuntimeException e ) + { + throw new AssemblyException( "Unable to create Application Model.", e ); + } + } + + public Application newApplication( ApplicationAssembler assembler, Object... importedServiceInstances ) + throws AssemblyException + { + ApplicationDescriptor model = newApplicationModel( assembler ); + return model.newInstance( runtime.spi(), importedServiceInstances ); + } + + public PolygeneSPI spi() + { + return runtime.spi(); + } + + public PolygeneAPI api() + { + return runtime.spi(); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/EntityAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/EntityAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/EntityAssembly.java new file mode 100644 index 0000000..7a3ce0a --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/EntityAssembly.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.type.HasTypes; + +/** + * This represents the assembly information of a single EntityComposite in a Module. + */ +public interface EntityAssembly + extends HasTypes +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/EntityDeclaration.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/EntityDeclaration.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/EntityDeclaration.java new file mode 100644 index 0000000..32f7e60 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/EntityDeclaration.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.common.Visibility; + +/** + * Fluent API for declaring entities. Instances + * of this API are acquired by calling {@link ModuleAssembly#entities(Class[])}. + */ +public interface EntityDeclaration +{ + /** + * Set additional metainfo for this entity declaration. + * + * @param info metainfo that can be retrieved from the EntityDescriptor. + * + * @return This instance for a fluid DSL + */ + EntityDeclaration setMetaInfo( Object info ); + + /** + * Set visibility for declared entities. + * + * @param visibility The {@link Visibility} that this EntityComposite will have. + * + * @return This instance for a fluid DSL + */ + EntityDeclaration visibleIn( Visibility visibility ); + + /** + * Declare additional concerns for these entities. + * + * @param concerns The concerns that are to be added to the EntityComposite beyond the statically declared ones. + * + * @return This instance for a fluid DSL + */ + EntityDeclaration withConcerns( Class<?>... concerns ); + + /** + * Declare additional side-effects for these entitites. + * + * @param sideEffects The sideeffects that are to be added to the EntityComposite beyond the statically declared ones. + * + * @return This instance for a fluid DSL + */ + EntityDeclaration withSideEffects( Class<?>... sideEffects ); + + /** + * Declare additional mixins for these entities. + * <p> + * This can be useful to override any default mixins from the entity interface. + * </p> + * @param mixins The mixins that are to be added to the EntityComposite beyond the statically declared ones. + * + * @return This instance for a fluid DSL + */ + EntityDeclaration withMixins( Class<?>... mixins ); + + /** + * Declare additional interfaces for these declared interfaces. + * <p> + * This can be useful to add types that the entities should implement, but + * which you do not want to include in the entity interface itself. + * </p> + * @param types list of interfaces to add + * + * @return This instance for a fluid DSL + */ + EntityDeclaration withTypes( Class<?>... types ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ImportedServiceAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ImportedServiceAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ImportedServiceAssembly.java new file mode 100644 index 0000000..057c179 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ImportedServiceAssembly.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.type.HasTypes; + +/** + * This represents the assembly information of a single imported service in a Module. + */ +public interface ImportedServiceAssembly + extends HasTypes +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ImportedServiceDeclaration.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ImportedServiceDeclaration.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ImportedServiceDeclaration.java new file mode 100644 index 0000000..8d143e9 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ImportedServiceDeclaration.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.activation.Activator; +import org.apache.polygene.api.common.Visibility; +import org.apache.polygene.api.service.ServiceImporter; +import org.apache.polygene.api.service.importer.InstanceImporter; +import org.apache.polygene.api.service.importer.NewObjectImporter; +import org.apache.polygene.api.service.importer.ServiceInstanceImporter; +import org.apache.polygene.api.service.importer.ServiceSelectorImporter; + +/** + * Fluent API for declaring imported services. Instances + * of this API are acquired by calling {@link ModuleAssembly#importedServices(Class[])}. + */ +public interface ImportedServiceDeclaration +{ + // Convenience constants for common service importers + public static final Class<? extends ServiceImporter> INSTANCE = InstanceImporter.class; + public static final Class<? extends ServiceImporter> NEW_OBJECT = NewObjectImporter.class; + public static final Class<? extends ServiceImporter> SERVICE_SELECTOR = ServiceSelectorImporter.class; + public static final Class<? extends ServiceImporter> SERVICE_IMPORTER = ServiceInstanceImporter.class; + + ImportedServiceDeclaration visibleIn( Visibility visibility ); + + ImportedServiceDeclaration importedBy( Class<? extends ServiceImporter> serviceImporterClass ); + + ImportedServiceDeclaration identifiedBy( String identity ); + + ImportedServiceDeclaration taggedWith( String... tags ); + + ImportedServiceDeclaration setMetaInfo( Object serviceAttribute ); + + ImportedServiceDeclaration importOnStartup(); + + /** + * Set the imported service activators. Activators are executed in order around + * the ServiceReference activation and passivation. + * + * @param activators the imported service activators + * @return the assembly + */ + @SuppressWarnings( { "unchecked","varargs" } ) + ImportedServiceDeclaration withActivators( Class<? extends Activator<?>>... activators ); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/InjectionException.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/InjectionException.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/InjectionException.java new file mode 100644 index 0000000..47d88ca --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/InjectionException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +/** + * Thrown by the Polygene runtime if a dependency can not be injected. + */ +public class InjectionException + extends RuntimeException +{ + public InjectionException( String s ) + { + super( s ); + } + + public InjectionException( String s, Throwable throwable ) + { + super( s, throwable ); + } + + public InjectionException( Throwable throwable ) + { + super( throwable ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/InvalidInjectionException.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/InvalidInjectionException.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/InvalidInjectionException.java new file mode 100644 index 0000000..4b9c3cb --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/InvalidInjectionException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +/** + * Thrown by the Polygene runtime if a dependency injection declaration is invalid. + */ +public class InvalidInjectionException + extends Exception +{ + public InvalidInjectionException( String s ) + { + super( s ); + } + + public InvalidInjectionException( String s, Throwable throwable ) + { + super( s, throwable ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/LayerAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/LayerAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/LayerAssembly.java new file mode 100644 index 0000000..6afbf26 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/LayerAssembly.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import java.util.function.Predicate; +import org.apache.polygene.api.activation.Activator; +import org.apache.polygene.api.structure.Layer; + +/** + * Fluid API for declaring a layer in an application. This is obtained by calling {@link ApplicationAssembly#layer(String)}. + */ +public interface LayerAssembly +{ + /** + * Get an assembly for a particular Module. If this is called many times with the same name, then the same module + * is affected. + * + * @param name The name of the Module to retrieve or create. + * + * @return The ModuleAssembly for the Module. + */ + ModuleAssembly module( String name ); + + ApplicationAssembly application(); + + String name(); + + LayerAssembly setName( String name ); + + LayerAssembly setMetaInfo( Object info ); + + LayerAssembly uses( LayerAssembly... layerAssembly ); + + /** + * Set the layer activators. Activators are executed in order around the + * Layer activation and passivation. + * + * @param activators the layer activators + * @return the assembly + */ + @SuppressWarnings( { "unchecked","varargs" } ) + LayerAssembly withActivators( Class<? extends Activator<Layer>>... activators ); + + <ThrowableType extends Throwable> void visit( AssemblyVisitor<ThrowableType> visitor ) + throws ThrowableType; + + /** + * Given a Specification for EntityAssembly's, returns a EntityDeclaration that can + * be used to work with all of the assemblies in this Layer matched by the specification. + * + * @param specification The Specification that specifies the EntityComposite types of interest. + * + * @return An EntityDeclaration for the specified EntityComposite types. + */ + EntityDeclaration entities( Predicate<? super EntityAssembly> specification ); + + /** + * Given a Specification for ServiceAssembly's, returns a ServiceDeclaration that can + * be used to work with all of the assemblies in this Layer matched by the specification. + * + * @param specification The Specification that specifies the ServiceComposite types of interest. + * + * @return An ServiceDeclaration for the specified ServiceComposite types. + */ + ServiceDeclaration services( Predicate<? super ServiceAssembly> specification ); + + /** + * Given a Specification for TransientAssembly's, returns a TransientDeclaration that can + * be used to work with all of the assemblies in this Layer matched by the specification. + * + * @param specification The Specification that specifies the TransientComposite types of interest. + * + * @return An TransientDeclaration for the specified TransientComposite types. + */ + TransientDeclaration transients( Predicate<? super TransientAssembly> specification ); + + /** + * Given a Specification for ValueAssembly's, returns a ValueDeclaration that can + * be used to work with all of the assemblies in this Layer matched by the specification. + * + * @param specification The Specification that specifies the ValueComposite types of interest. + * + * @return An ValueDeclaration for the specified ValueComposite types. + */ + ValueDeclaration values( Predicate<? super ValueAssembly> specification ); + + /** + * Given a Specification for ObjectAssembly's, returns a ObjectDeclaration that can + * be used to work with all of the assemblies in this Layer matched by the specification. + * + * @param specification The Specification that specifies the Object types of interest. + * + * @return An ObjectDeclaration for the specified Object types. + */ + ObjectDeclaration objects( Predicate<? super ObjectAssembly> specification ); + + /** + * Given a Specification for ImportedServiceAssembly's, returns a ImportedServiceDeclaration that can + * be used to work with all of the assemblies in this Layer matched by the specification. + * + * @param specification The Specification that specifies the Imported Service types of interest. + * + * @return An ImportedServiceDeclaration for the specified Imported Service types. + */ + ImportedServiceDeclaration importedServices( Predicate<? super ImportedServiceAssembly> specification ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/LayerName.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/LayerName.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/LayerName.java new file mode 100644 index 0000000..36e6435 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/LayerName.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +/** + * Set the name of the layer + */ +public final class LayerName + implements Assembler +{ + private final String name; + + public LayerName( String name ) + { + this.name = name; + } + + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.layer().setName( name ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ManyAssociationDeclarations.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ManyAssociationDeclarations.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ManyAssociationDeclarations.java new file mode 100644 index 0000000..4c39a99 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ManyAssociationDeclarations.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import java.lang.reflect.AccessibleObject; +import org.apache.polygene.api.common.MetaInfo; + +/** + * This provides declared {@link org.apache.polygene.api.association.ManyAssociation} information that the runtime can use. + */ +public interface ManyAssociationDeclarations +{ + MetaInfo metaInfoFor( AccessibleObject accessor ); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/MetaInfoDeclaration.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/MetaInfoDeclaration.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/MetaInfoDeclaration.java new file mode 100644 index 0000000..2967fe5 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/MetaInfoDeclaration.java @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.HashMap; +import java.util.Map; +import org.apache.polygene.api.common.MetaInfo; +import org.apache.polygene.api.property.Property; + +/** + * Declaration of a Property or Association. + */ +public final class MetaInfoDeclaration + implements StateDeclarations, AssociationDeclarations, ManyAssociationDeclarations, NamedAssociationDeclarations +{ + Map<Class<?>, InfoHolder<?>> mixinPropertyDeclarations = new HashMap<>(); + + public MetaInfoDeclaration() + { + } + + public <T> MixinDeclaration<T> on( Class<T> mixinType ) + { + @SuppressWarnings( "unchecked" ) + InfoHolder<T> propertyDeclarationHolder = (InfoHolder<T>) mixinPropertyDeclarations.get( mixinType ); + if( propertyDeclarationHolder == null ) + { + propertyDeclarationHolder = new InfoHolder<>( mixinType ); + mixinPropertyDeclarations.put( mixinType, propertyDeclarationHolder ); + } + return propertyDeclarationHolder; + } + + @Override + public MetaInfo metaInfoFor( AccessibleObject accessor ) + { + for( Map.Entry<Class<?>, InfoHolder<?>> entry : mixinPropertyDeclarations.entrySet() ) + { + InfoHolder<?> holder = entry.getValue(); + MetaInfo metaInfo = holder.metaInfoFor( accessor ); + if( metaInfo != null ) + { + Class<?> mixinType = entry.getKey(); + return metaInfo.withAnnotations( mixinType ) + .withAnnotations( accessor ) + .withAnnotations( accessor instanceof Method ? ( (Method) accessor ).getReturnType() : ( (Field) accessor ) + .getType() ); + } + } + // TODO is this code reached at all?? + Class<?> declaringType = ( (Member) accessor ).getDeclaringClass(); + return new MetaInfo().withAnnotations( declaringType ) + .withAnnotations( accessor ) + .withAnnotations( accessor instanceof Method ? ( (Method) accessor ).getReturnType() : ( (Field) accessor ).getType() ); + } + + @Override + public Object initialValueOf( AccessibleObject accessor ) + { + for( InfoHolder<?> propertyDeclarationHolder : mixinPropertyDeclarations.values() ) + { + final Object initialValue = propertyDeclarationHolder.initialValueOf( accessor ); + if( initialValue != null ) + { + return initialValue; + } + } + return null; + } + + @Override + public boolean useDefaults( AccessibleObject accessor ) + { + for( InfoHolder<?> propertyDeclarationHolder : mixinPropertyDeclarations.values() ) + { + final boolean useDefaults = propertyDeclarationHolder.useDefaults( accessor ); + if( useDefaults ) + { + return useDefaults; + } + } + return false; + } + + private static class InfoHolder<T> + implements InvocationHandler, StateDeclarations, MixinDeclaration<T> + { + private final static class MethodInfo + { + Object initialValue; + boolean useDefaults; + MetaInfo metaInfo; + + private MethodInfo( MetaInfo metaInfo ) + { + this.metaInfo = metaInfo; + } + } + + private final Class<T> mixinType; + private final Map<AccessibleObject, MethodInfo> methodInfos = new HashMap<>(); + // temporary holder + private MetaInfo metaInfo = null; + + private InfoHolder( Class<T> mixinType ) + { + this.mixinType = mixinType; + } + + @Override + @SuppressWarnings( "raw" ) + public Object invoke( Object o, Method method, Object[] objects ) + throws Throwable + { + final MethodInfo methodInfo = new MethodInfo( metaInfo ); + methodInfo.useDefaults = true; + methodInfos.put( method, methodInfo ); + metaInfo = null; // reset + final Class<?> returnType = method.getReturnType(); + try + { + return Proxy.newProxyInstance( returnType.getClassLoader(), new Class[]{ returnType }, + ( o1, method1, objects1 ) -> { + if( method1.getName().equals( "set" ) ) + { + methodInfo.initialValue = objects1[ 0 ]; + } + return null; + } ); + } + catch( IllegalArgumentException e ) + { + throw new IllegalArgumentException( + "Only methods with " + Property.class.getName() + " as return type can have declareDefaults()" ); + } + } + + public MethodInfo matches( AccessibleObject accessor ) + { + return methodInfos.get( accessor ); + } + + @Override + public MetaInfo metaInfoFor( AccessibleObject accessor ) + { + final MethodInfo methodInfo = matches( accessor ); + if( methodInfo == null ) + { + return null; + } + return methodInfo.metaInfo; + } + + @Override + public Object initialValueOf( AccessibleObject accessor ) + { + final MethodInfo methodInfo = matches( accessor ); + if( methodInfo == null ) + { + return null; + } + return methodInfo.initialValue; + } + + @Override + public boolean useDefaults( AccessibleObject accessor ) + { + final MethodInfo methodInfo = matches( accessor ); + if( methodInfo == null ) + { + return false; + } + return methodInfo.useDefaults; + } + + // DSL Interface + + @Override + @SuppressWarnings( "raw" ) + public T declareDefaults() + { + return mixinType.cast( + Proxy.newProxyInstance( mixinType.getClassLoader(), new Class[]{ mixinType }, this ) ); + } + + @Override + public MixinDeclaration<T> setMetaInfo( Object info ) + { + if( metaInfo == null ) + { + metaInfo = new MetaInfo(); + } + metaInfo.set( info ); + return this; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/MixinDeclaration.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/MixinDeclaration.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/MixinDeclaration.java new file mode 100644 index 0000000..90e22f4 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/MixinDeclaration.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +/** + * Fluent API for declaring information about properties + * + * @param <T> Parameterized mixin type + */ +public interface MixinDeclaration<T> +{ + T declareDefaults(); + + MixinDeclaration<T> setMetaInfo( Object info ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java new file mode 100644 index 0000000..47c3729 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import java.util.function.Predicate; +import org.apache.polygene.api.activation.Activator; +import org.apache.polygene.api.structure.Module; +import org.apache.polygene.api.type.HasTypes; + +/** + * The ModuleAssembly is used to register any information about * what the module should contain, such as composites, + * entities and services. + * <p> + * Use the methods and the fluent API's to declare how the module should be constructed. + * </p> + */ +public interface ModuleAssembly +{ + /** + * Access the layer assembly for this module. + * + * @return The Layer containing this Module. + */ + LayerAssembly layer(); + + /** + * Get an assembly for a particular Module. If this is called many times with the same names, then the same module + * is affected. + * + * @param layerName The name of the Layer + * @param moduleName The name of the Module to retrieve or create. + * + * @return The ModuleAssembly for the Module. + */ + ModuleAssembly module( String layerName, String moduleName ); + + /** + * Set the name of this module. + * + * @param name The name that this Module should have. + * + * @return This instance to support the fluid DSL of bootstrap. + */ + ModuleAssembly setName( String name ); + + /** + * Access the currently set name for this module. + * + * @return The name of this Module. + */ + String name(); + + ModuleAssembly setMetaInfo( Object info ); + + /** + * Set the module activators. Activators are executed in order around the + * Module activation and passivation. + * + * @param activators the module activators + * + * @return the assembly + */ + @SuppressWarnings( { "unchecked", "varargs" } ) + ModuleAssembly withActivators( Class<? extends Activator<Module>>... activators ); + + /** + * Declare a list of TransientComposites for this Module. Use the TransientDeclaration that is returned to + * declare further settings. Note that the TransientDeclaration works on all of the types specified. + * + * @param transientTypes The types that specifies the Transient types. + * + * @return An TransientDeclaration for the specified Transient types. + */ + TransientDeclaration transients( Class<?>... transientTypes ); + + /** + * Given a Specification for TransientAssembly's, returns a TransientDeclaration that can + * be used to work with all of the assemblies matched by the specification. + * + * @param specification The Specification that specifies the TransientComposite types of interest. + * + * @return An TransientDeclaration for the specified TransientComposite types. + */ + TransientDeclaration transients( Predicate<? super TransientAssembly> specification ); + + /** + * Declare a list of ValueComposites for this Module. Use the ValueDeclaration that is returned to + * declare further settings. Note that the ValueDeclaration works on all of the types specified. + * + * @param valueTypes The types that specifies the Value types. + * + * @return An ValueDeclaration for the specified Value types. + */ + ValueDeclaration values( Class<?>... valueTypes ); + + /** + * Given a Specification for ValueAssembly's, returns a ValueDeclaration that can + * be used to work with all of the assemblies matched by the specification. + * + * @param specification The Specification that specifies the ValueComposite types of interest. + * + * @return An ValueDeclaration for the specified ValueComposite types. + */ + ValueDeclaration values( Predicate<? super ValueAssembly> specification ); + + /** + * Declare a list of EntityComposites for this Module. Use the EntityDeclaration that is returned to + * declare further settings. Note that the EntityDeclaration works on all of the types specified. + * + * @param entityTypes The types that specifies the Entity types. + * + * @return An EntityDeclaration for the specified Entity types. + */ + EntityDeclaration entities( Class<?>... entityTypes ); + + /** + * Given a Specification for EntityAssembly's, returns a EntityDeclaration that can + * be used to work with all of the assemblies matched by the specification. + * + * @param specification The Specification that specifies the EntityComposite types of interest. + * + * @return An EntityDeclaration for the specified EntityComposite types. + */ + EntityDeclaration entities( Predicate<? super EntityAssembly> specification ); + + /** + * Declare a list of Configuration Composites for this Module. Use the ConfigurationDeclaration that is returned to + * declare further settings. Note that the ConfigurationDeclaration works on all of the types specified. + * + * @param configurationTypes The types that specifies the Configuration types. + * + * @return An ConfigurationDeclaration for the specified Configuration types. + */ + ConfigurationDeclaration configurations( Class<?>... configurationTypes ); + + /** + * Given a Specification for ConfigurationAssembly's, returns a ConfigurationDeclaration that can + * be used to work with all of the assemblies matched by the specification. + * + * @param specification The Specification that specifies the ConfigurationComposite types of interest. + * + * @return An ConfigurationDeclaration for the specified EntityComposite types. + */ + ConfigurationDeclaration configurations( Predicate<HasTypes> specification ); + + /** + * Declare a list of object classes for this Module. Use the ObjectDeclaration that is returned to + * declare further settings. Note that the ObjectDeclaration works on all of the types specified. + * + * @param objectTypes The types that specifies the Object types. + * + * @return An ObjectDeclaration for the specified Object types. + * + * @throws AssemblyException on invalid assembly + */ + ObjectDeclaration objects( Class<?>... objectTypes ) + throws AssemblyException; + + /** + * Given a Specification for ObjectAssembly's, returns a ObjectDeclaration that can + * be used to work with all of the assemblies matched by the specification. + * + * @param specification The Specification that specifies the Object types of interest. + * + * @return An ObjectDeclaration for the specified Object types. + */ + ObjectDeclaration objects( Predicate<? super ObjectAssembly> specification ); + + /** + * Create a list of ServiceComposites for this Module. Use the ServiceDeclaration that is returned to + * declare further settings. This will always create new assemblies for the specified types, instead + * of potentially working on already declared types like the services(...) method. + * + * @param serviceTypes The types that specifies the Service types. + * + * @return An ServiceDeclaration for the specified Service types. + */ + ServiceDeclaration addServices( Class<?>... serviceTypes ); + + /** + * Declare a list of ServiceComposites for this Module. Use the ServiceDeclaration that is returned to + * declare further settings. Note that the ServiceDeclaration works on all of the types specified. + * + * @param serviceTypes The types that specifies the Service types. + * + * @return An ServiceDeclaration for the specified Service types. + */ + ServiceDeclaration services( Class<?>... serviceTypes ); + + /** + * Given a Specification for ServiceAssembly's, returns a ServiceDeclaration that can + * be used to work with all of the assemblies matched by the specification. + * + * @param specification The Specification that specifies the ServiceComposite types of interest. + * + * @return An ServiceDeclaration for the specified ServiceComposite types. + */ + ServiceDeclaration services( Predicate<? super ServiceAssembly> specification ); + + /** + * Declare a list of imported services for this Module. Use the ImportedServiceDeclaration that is returned to + * declare further settings. Note that the ImportedServiceDeclaration works on all of the types specified. + * + * @param serviceTypes The types that specifies the Imported Service types. + * + * @return An ImportedServiceDeclaration for the specified Imported Service types. + */ + ImportedServiceDeclaration importedServices( Class<?>... serviceTypes ); + + /** + * Given a Specification for ImportedServiceAssembly's, returns a ImportedServiceDeclaration that can + * be used to work with all of the assemblies matched by the specification. + * + * @param specification The Specification that specifies the Imported Service types of interest. + * + * @return An ImportedServiceDeclaration for the specified Imported Service types. + */ + ImportedServiceDeclaration importedServices( Predicate<? super ImportedServiceAssembly> specification ); + + <T> MixinDeclaration<T> forMixin( Class<T> mixinType ); + + public <ThrowableType extends Throwable> void visit( AssemblyVisitor<ThrowableType> visitor ) + throws ThrowableType; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleName.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleName.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleName.java new file mode 100644 index 0000000..72ba9ce --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleName.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +/** + * Set the name of the module + */ +public final class ModuleName + implements Assembler +{ + private final String name; + + public ModuleName( String name ) + { + this.name = name; + } + + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.setName( name ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/NamedAssociationDeclarations.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/NamedAssociationDeclarations.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/NamedAssociationDeclarations.java new file mode 100644 index 0000000..bc8a8ea --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/NamedAssociationDeclarations.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import java.lang.reflect.AccessibleObject; +import org.apache.polygene.api.common.MetaInfo; + +/** + * This provides declared {@link org.apache.polygene.api.association.NamedAssociation} information that the runtime can use. + */ +public interface NamedAssociationDeclarations +{ + MetaInfo metaInfoFor( AccessibleObject accessor ); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ObjectAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ObjectAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ObjectAssembly.java new file mode 100644 index 0000000..281fd6e --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ObjectAssembly.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.type.HasTypes; + +/** + * This represents the assembly information of a single object type in a Module. + */ +public interface ObjectAssembly + extends HasTypes +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ObjectDeclaration.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ObjectDeclaration.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ObjectDeclaration.java new file mode 100644 index 0000000..3587443 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ObjectDeclaration.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.common.Visibility; + +/** + * Fluent API for declaring objects.Instances + * of this API are acquired by calling {@link ModuleAssembly#objects(Class[])}. + */ +public interface ObjectDeclaration +{ + ObjectDeclaration setMetaInfo( Object info ); + + ObjectDeclaration visibleIn( Visibility visibility ) + throws IllegalStateException; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/RuntimeFactory.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/RuntimeFactory.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/RuntimeFactory.java new file mode 100644 index 0000000..f12b999 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/RuntimeFactory.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +/** + * Polygene runtime factory. + */ +public interface RuntimeFactory +{ + PolygeneRuntime createRuntime(); + + /** + * Standalone application Polygene runtime factory. + */ + public final class StandaloneApplicationRuntimeFactory + implements RuntimeFactory + { + @Override + public PolygeneRuntime createRuntime() + { + ClassLoader loader = getClass().getClassLoader(); + try + { + Class<? extends PolygeneRuntime> runtimeClass = loadRuntimeClass( loader ); + return runtimeClass.newInstance(); + } + catch( ClassNotFoundException e ) + { + System.err.println( "Polygene Runtime jar is not present in the classpath." ); + } + catch( InstantiationException | IllegalAccessException e ) + { + System.err.println( "Invalid Polygene Runtime class. If you are providing your own Polygene Runtime, please " + + "contact [email protected] mailing list for assistance." ); + } + return null; + } + + @SuppressWarnings( { "unchecked" } ) + private Class<? extends PolygeneRuntime> loadRuntimeClass( ClassLoader loader ) + throws ClassNotFoundException + { + return (Class<? extends PolygeneRuntime>) loader.loadClass( "org.apache.polygene.runtime.PolygeneRuntimeImpl" ); + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ServiceAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ServiceAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ServiceAssembly.java new file mode 100644 index 0000000..5a889de --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ServiceAssembly.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.identity.Identifiable; +import org.apache.polygene.api.type.HasTypes; + +/** + * This represents the assembly information of a single ServiceComposite in a Module. + */ +public interface ServiceAssembly extends HasTypes, Identifiable +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ServiceDeclaration.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ServiceDeclaration.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ServiceDeclaration.java new file mode 100644 index 0000000..8dad610 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ServiceDeclaration.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.activation.Activator; +import org.apache.polygene.api.common.Visibility; + +/** + * Fluent API for declaring services hosted in Polygene. Instances + * of this API are acquired by calling {@link ModuleAssembly#services(Class[])}. + */ +public interface ServiceDeclaration +{ + ServiceDeclaration setMetaInfo( Object serviceAttribute ); + + ServiceDeclaration visibleIn( Visibility visibility ); + + ServiceDeclaration withConcerns( Class<?>... concerns ); + + ServiceDeclaration withSideEffects( Class<?>... sideEffects ); + + ServiceDeclaration withMixins( Class<?>... mixins ); + + ServiceDeclaration withTypes( Class<?>... types ); + + ServiceDeclaration identifiedBy( String identity ); + + ServiceDeclaration taggedWith( String... tags ); + + ServiceDeclaration instantiateOnStartup(); + + /** + * Set the service activators. Activators are executed in order around the + * ServiceReference activation and passivation. + * + * @param activators the service activators + * @return the assembly + */ + @SuppressWarnings( { "unchecked","varargs" } ) + ServiceDeclaration withActivators( Class<? extends Activator<?>>... activators ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java new file mode 100644 index 0000000..18717dd --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.PolygeneAPI; +import org.apache.polygene.api.activation.ActivationException; +import org.apache.polygene.api.composite.TransientBuilderFactory; +import org.apache.polygene.api.object.ObjectFactory; +import org.apache.polygene.api.service.ServiceFinder; +import org.apache.polygene.api.structure.Application; +import org.apache.polygene.api.structure.Module; +import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; +import org.apache.polygene.api.value.ValueBuilderFactory; + +/** + * Base class for Assembler that creates an Application + * with one Layer and one Module. Create a subclass of this + * and implement the {@link Assembler#assemble(ModuleAssembly)} method. + * Once the SingletonAssembler is instantiated it will have created and activated + * an Application which can be accessed from {@link org.apache.polygene.bootstrap.SingletonAssembler#application()}. + * You can also easily access any resources specific for the single Module, such as the TransientBuilderFactory. + */ +public abstract class SingletonAssembler + implements Assembler +{ + private Energy4Java zest; + private Application applicationInstance; + private final Module moduleInstance; + + /** + * Creates a Polygene Runtime instance containing one Layer with one Module. + * The Layer will be named "Layer 1" and the Module will be named "Module 1". It is possible to add + * additional layers and modules via the Assembler interface that must be implemented in the subclass of this + * class. + * + * @throws AssemblyException Either if the model can not be created from the disk, or some inconsistency in + * the programming model makes it impossible to create it. + * @throws ActivationException If the automatic {@code activate()} method is throwing this Exception.. + */ + public SingletonAssembler() + throws AssemblyException, ActivationException + { +// START SNIPPET: actual + zest = new Energy4Java(); + applicationInstance = zest.newApplication( + applicationFactory -> applicationFactory.newApplicationAssembly( SingletonAssembler.this ) + ); + + try + { + beforeActivation( applicationInstance ); + applicationInstance.activate(); + } + catch( Exception e ) + { + if( e instanceof ActivationException ) + { + throw ( (ActivationException) e ); + } + throw new ActivationException( "Could not activate application", e ); + } +// START SNIPPET: actual + + moduleInstance = applicationInstance.findModule( "Layer 1", "Module 1" ); + } + + public final PolygeneAPI runtime() + { + return zest.spi(); + } + + public final Application application() + { + return applicationInstance; + } + + public final Module module() + { + return moduleInstance; + } + + protected void beforeActivation( Application application ) + throws Exception + { + } + + protected UnitOfWorkFactory unitOfWorkFactory() + { + return moduleInstance.unitOfWorkFactory(); + } + + protected ServiceFinder serviceFinder() + { + return moduleInstance.serviceFinder(); + } + + protected ValueBuilderFactory valueBuilderFactory() + { + return moduleInstance.valueBuilderFactory(); + } + + protected TransientBuilderFactory transientBuilderFactory() + { + return moduleInstance.transientBuilderFactory(); + } + + protected ObjectFactory objectFactory() + { + return moduleInstance.objectFactory(); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/StateDeclarations.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/StateDeclarations.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/StateDeclarations.java new file mode 100644 index 0000000..79d2834 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/StateDeclarations.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import java.lang.reflect.AccessibleObject; +import org.apache.polygene.api.common.MetaInfo; + +/** + * This provides declared {@link org.apache.polygene.api.property.Property} information that the runtime can use. + */ +public interface StateDeclarations +{ + MetaInfo metaInfoFor( AccessibleObject accessor ); + + Object initialValueOf( AccessibleObject accessor ); + + boolean useDefaults( AccessibleObject accessor ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/TransientAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/TransientAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/TransientAssembly.java new file mode 100644 index 0000000..42aab6d --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/TransientAssembly.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.type.HasTypes; + +/** + * This represents the assembly information of a single TransientComposite in a Module. + */ +public interface TransientAssembly + extends HasTypes +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/TransientDeclaration.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/TransientDeclaration.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/TransientDeclaration.java new file mode 100644 index 0000000..04a1942 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/TransientDeclaration.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.polygene.bootstrap; + +import org.apache.polygene.api.common.Visibility; + +/** + * Fluent API for declaring TransientComposites. Instances + * of this API are acquired by calling {@link ModuleAssembly#transients(Class[])}. + */ +public interface TransientDeclaration +{ + TransientDeclaration setMetaInfo( Object info ); + + TransientDeclaration visibleIn( Visibility visibility ); + + TransientDeclaration withConcerns( Class<?>... concerns ); + + TransientDeclaration withSideEffects( Class<?>... sideEffects ); + + TransientDeclaration withMixins( Class<?>... mixins ); + + TransientDeclaration withTypes( Class<?>... roles ); +}
