http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/formats/yaml/src/test/resources/configs/valid/test-with-prio.yaml ---------------------------------------------------------------------- diff --git a/modules/formats/yaml/src/test/resources/configs/valid/test-with-prio.yaml b/modules/formats/yaml/src/test/resources/configs/valid/test-with-prio.yaml new file mode 100644 index 0000000..05b5dbf --- /dev/null +++ b/modules/formats/yaml/src/test/resources/configs/valid/test-with-prio.yaml @@ -0,0 +1,39 @@ +# +# 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 current 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. +# +version: 1.0 +released: 2012-11-30 + +# tamaya specifics... +tamaya: + ordinal: 16784 + +# Connection parameters +connection: + url: jdbc:mysql://localhost:3306/db + poolSize: 5 + +# Protocols +protocols: + - http + - https + +# Users +users: + tom: passwd + bob: passwd \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/formats/yaml/src/test/resources/configs/valid/test.yaml ---------------------------------------------------------------------- diff --git a/modules/formats/yaml/src/test/resources/configs/valid/test.yaml b/modules/formats/yaml/src/test/resources/configs/valid/test.yaml new file mode 100644 index 0000000..697e9f3 --- /dev/null +++ b/modules/formats/yaml/src/test/resources/configs/valid/test.yaml @@ -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 current 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. +# +version: 1.0 +released: 2012-11-30 + +# Connection parameters +connection: + url: jdbc:mysql://localhost:3306/db + poolSize: 5 + +# Protocols +protocols: + - http + - https + +# Users +users: + tom: passwd + bob: passwd \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/pom.xml ---------------------------------------------------------------------- diff --git a/modules/injection-api/pom.xml b/modules/injection-api/pom.xml deleted file mode 100644 index 8db431e..0000000 --- a/modules/injection-api/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ -<!-- -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 current 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-extensions</artifactId> - <version>0.3-incubating-SNAPSHOT</version> - <relativePath>..</relativePath> - </parent> - <artifactId>tamaya-injection-api</artifactId> - <name>Apache Tamaya Injection Support API</name> - <packaging>bundle</packaging> - - <properties> - <jdkVersion>1.7</jdkVersion> - <geronimo-atinject-1.0-spec.version>1.0</geronimo-atinject-1.0-spec.version> - <geronimo-jcdi-1.1-spec.version>1.0</geronimo-jcdi-1.1-spec.version> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-atinject_1.0_spec</artifactId> - <version>${geronimo-atinject-1.0-spec.version}</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jcdi_1.1_spec</artifactId> - <version>${geronimo-jcdi-1.1-spec.version}</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Export-Package> - org.apache.tamaya.inject.api, - org.apache.tamaya.inject.spi - </Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/BaseDynamicValue.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/BaseDynamicValue.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/BaseDynamicValue.java deleted file mode 100644 index 2f8c559..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/BaseDynamicValue.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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.tamaya.inject.api; - - -import java.io.Serializable; - -/** - * <p>A accessor for a single configured value. This can be used to support values that may change during runtime, - * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a - * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit - * by client code. Similarly an instance also can ignore all later changes to the value.</p> - * - * <p>Types of this interface can be used as injection targets in injected beans or as template resiult on configuration - * templates.</p> - * - * <h3>Implementation Specification</h3> - * Implementation of this interface must be - * <ul> - * <li>Serializable, when also the item stored is serializable</li> - * <li>Thread safe</li> - * </ul> - * - * @param <T> The type of the value. - */ -public abstract class BaseDynamicValue<T> implements DynamicValue<T>, Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Performs a commit, if necessary, and returns the current value. - * - * @return the non-null value held by this {@code DynamicValue} - * @throws org.apache.tamaya.ConfigException if there is no value present - * @see DynamicValue#isPresent() - */ - public T commitAndGet() { - commit(); - return get(); - } - - /** - * Return {@code true} if there is a value present, otherwise {@code false}. - * - * @return {@code true} if there is a value present, otherwise {@code false} - */ - public boolean isPresent() { - return get() != null; - } - - - /** - * Return the value if present, otherwise return {@code other}. - * - * @param other the value to be returned if there is no value present, may - * be null - * @return the value, if present, otherwise {@code other} - */ - public T orElse(T other) { - T value = get(); - if (value == null) { - return other; - } - return value; - } - - /** - * Return the value if present, otherwise invoke {@code other} and return - * the result of that invocation. - * - * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value - * is present - * @return the value if present otherwise the result of {@code other.get()} - * @throws NullPointerException if value is not present and {@code other} is - * null - */ - public T orElseGet(ConfiguredItemSupplier<? extends T> other) { - T value = get(); - if (value == null) { - return other.get(); - } - return value; - } - - /** - * Return the contained value, if present, otherwise throw an exception - * to be created by the provided supplier. - * <p> - * NOTE A method reference to the exception constructor with an empty - * argument list can be used as the supplier. For example, - * {@code IllegalStateException::new} - * - * @param <X> Type of the exception to be thrown - * @param exceptionSupplier The supplier which will return the exception to - * be thrown - * @return the present value - * @throws X if there is no value present - * @throws NullPointerException if no value is present and - * {@code exceptionSupplier} is null - */ - public <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X { - T value = get(); - if (value == null) { - throw exceptionSupplier.get(); - } - return value; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java deleted file mode 100644 index 2484934..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.tamaya.inject.api; - - -import javax.enterprise.util.Nonbinding; -import javax.inject.Qualifier; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** todo The author of this should fix this invalid Javadoc. Oliver B. Fischer, 2015-12-27 */ -///** -// * Annotation to enable injection current a configured property or define the returned data for -// * a configuration template method. Hereby this annotation can be used in multiple ways and combined -// * with other annotations such as {@link ConfigDefault}, {@link WithConfigOperator}, {@link WithPropertyConverter}. -// * -// * Below the most simple variant current a configured class is given: -// * {@code -// * pubic class ConfiguredItem{ -// * -// * @ConfiguredProperty -// * private String aValue; -// * } -// * When this class is configured, e.g. by passing it to {@link org.apache.tamaya.Configuration#configure(Object)}, -// * the following is happening: -// * <ul> -// * <li>The current valid Configuration is evaluated by calling {@code Configuration cfg = ConfigurationProvider.getConfiguration();}</li> -// * <li>The current possible property keys are evaluated by calling {@code cfg.get("aValue");}</li> -// * <li>if not successful, and a @ConfigDefault annotation is present, the default value is used. -// * <li>If no value could be evaluated a ({@link org.apache.tamaya.ConfigException} is thrown.</li> -// * <li>On success, since no type conversion is involved, the value is injected.</li> -// * </ul> -// * -// * In the next example we explicitly define the property keys: -// * {@code -// * @ConfigDefaultSections("section1") -// * pubic class ConfiguredItem{ -// * -// * @ConfiguredProperty({"b", "[a.b.deprecated.keys]", "a"}) -// * @ConfigDefault("myDefaultValue") -// * private String aValue; -// * } -// * -// * Within this example we evaluate multiple possible keys (section1.b, a.b.deprecated.keys, section1.a). Evaluation is -// * aborted if a key could be successfully resolved. Hereby the ordering current the annotations define the ordering -// * current resolution, so in the example above -// * resolution equals to {@code "section1.b", "a.b.deprecated.keys", "section1.a"}. If no value has bee found, -// * the configured default {@code myDefaultValue} is returned. -// */ -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) -public @interface Config { - - /** - * Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys. - * - * @return the property names, not null. If missing the field or method name being injected is used by default. - */ - @Nonbinding - String[] value() default {}; - - /** - * The default value to be injected, if none of the configuration keys could be resolved. If no key has been - * resolved and no default value is defined, it is handled as a deployment error. Depending on the extension loaded - * default values can be fixed Strings or even themselves resolvable. For typed configuration of type T entries - * that are not Strings the default value must be a valid input to the corresponding - * {@link org.apache.tamaya.spi.PropertyConverter}. - * - * @return default value used in case resolution fails. - */ - @Nonbinding - String defaultValue() default ""; - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java deleted file mode 100644 index 1ed659e..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.tamaya.inject.api; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to control injection of a configured bean. The configuration keys - * to be resolved are basically determined by the {@link Config} - * annotation(s). When this annotation is added the injection systems tries to inject all - * fields found, also including fields not annotated with {@code @ConfigProperty}. - * Fields not to be injected ccan be annotated with {@code @NoConfig} to exclude them - * being eleceted for injection. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(value = { ElementType.TYPE }) -public @interface ConfigAutoInject {} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java deleted file mode 100644 index 2037de6..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.tamaya.inject.api; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** todo The author of this should fix this invalid Javadoc. Oliver B. Fischer, 2015-12-27 */ -///** -// * Annotation to control injection and resolution current a configured bean. The configuration keys -// * to be resolved are basically determined by the {@link org.apache.tamaya.inject.ConfigProperty} -// * annotation(s). Nevertheless these annotations can also have relative key names. This annotation allows -// * to define a configuration area that is prefixed to all relative configuration keys within the -// * corresponding class/template interface. -// */ -@Retention(RetentionPolicy.RUNTIME) -@Target(value = { ElementType.TYPE }) -public @interface ConfigDefaultSections { - - /** - * Allows to declare an section names that are prepended to resolve relative configuration keys. - * @return the section names to used for key resolution. - */ - String[] value() default {}; - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java deleted file mode 100644 index 5e57121..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.tamaya.inject.api; - -/** - * Represents a supplier of results. - * - * There is no requirement that a new or distinct result be returned each - * time the supplier is invoked. - * - * This is a functional interface, - * whose functional method is {@link #get()}. - * - * @param <T> the type of results supplied by this supplier - */ -//@FunctionalInterface -public interface ConfiguredItemSupplier<T> { - - /** - * Gets a result. - * - * @return a result - */ - T get(); -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java deleted file mode 100644 index 4cc29da..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.tamaya.inject.api; - -import java.beans.PropertyChangeListener; - - -/** - * <p>A accessor for a single configured value. This can be used to support values that may change during runtime, - * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a - * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit - * by client code. Similarly an instance also can ignore all later changes to the value.</p> - * - * <p>Types of this interface can be used as injection targets in injected beans or as template resiult on configuration - * templates.</p> - * - * <h3>Implementation Specification</h3> - * Implementation of this interface must be - * <ul> - * <li>Serializable, when also the item stored is serializable</li> - * <li>Thread safe</li> - * </ul> - * - * @param <T> The type of the value. - */ -public interface DynamicValue<T> { - - /** - * Performs a commit, if necessary, and returns the current value. - * - * @return the non-null value held by this {@code DynamicValue} - * @throws org.apache.tamaya.ConfigException if there is no value present - * - * @see DynamicValue#isPresent() - */ - T commitAndGet(); - - /** - * Commits a new value that has not been committed yet, make it the new value of the instance. On change any - * registered listeners will be triggered. - */ - void commit(); - - /** - * Access the {@link UpdatePolicy} used for updating this value. - * @return the update policy, never null. - */ - UpdatePolicy getUpdatePolicy(); - - /** - * Add a listener to be called as weak reference, when this value has been changed. - * @param l the listener, not null - */ - void addListener(PropertyChangeListener l); - - /** - * Removes a listener to be called, when this value has been changed. - * @param l the listner to be removed, not null - */ - void removeListener(PropertyChangeListener l); - - /** - * If a value is present in this {@code DynamicValue}, returns the value, - * otherwise throws {@code ConfigException}. - * - * @return the non-null value held by this {@code Optional} - * @throws org.apache.tamaya.ConfigException if there is no value present - * - * @see DynamicValue#isPresent() - */ - T get(); - - /** - * Method to check for and apply a new value. Depending on the {@link UpdatePolicy} - * the value is immediately or deferred visible (or it may even be ignored completely). - * @return true, if a new value has been detected. The value may not be visible depending on the current - * {@link UpdatePolicy} in place. - */ - boolean updateValue(); - - /** - * Evaluates the current value dynamically from the underlying configuration. - * @return the current actual value, or null. - */ - T evaluateValue(); - - /** - * Sets a new {@link UpdatePolicy}. - * @param updatePolicy the new policy, not null. - */ - void setUpdatePolicy(UpdatePolicy updatePolicy); - - /** - * Access a new value that has not yet been committed. - * @return the uncommitted new value, or null. - */ - T getNewValue(); - - /** - * Return {@code true} if there is a value present, otherwise {@code false}. - * - * @return {@code true} if there is a value present, otherwise {@code false} - */ - boolean isPresent(); - - /** - * Return the value if present, otherwise return {@code other}. - * - * @param other the value to be returned if there is no value present, may - * be null - * @return the value, if present, otherwise {@code other} - */ - T orElse(T other); - - /** - * Return the value if present, otherwise invoke {@code other} and return - * the result of that invocation. - * - * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value - * is present - * @return the value if present otherwise the result of {@code other.get()} - * @throws NullPointerException if value is not present and {@code other} is - * null - */ - T orElseGet(ConfiguredItemSupplier<? extends T> other); - - /** - * Return the contained value, if present, otherwise throw an exception - * to be created by the provided supplier. - * - * NOTE A method reference to the exception constructor with an empty - * argument list can be used as the supplier. For example, - * {@code IllegalStateException::new} - * - * @param <X> Type of the exception to be thrown - * @param exceptionSupplier The supplier which will return the exception to - * be thrown - * @return the present value - * @throws X if there is no value present - * @throws NullPointerException if no value is present and - * {@code exceptionSupplier} is null - */ - <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X; - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/InjectionUtils.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/InjectionUtils.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/InjectionUtils.java deleted file mode 100644 index a010e96..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/InjectionUtils.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.tamaya.inject.api; - -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.ListIterator; - -/** - * Utility class with several commonly used functions. - */ -public final class InjectionUtils { - - private InjectionUtils(){} - - - /** - * Collects all keys to be be accessed as defined by any annotations of type - * {@link ConfigDefaultSections}, {@link Config}. - * @param field the (optionally) annotated field instance - * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}. - */ - public static List<String> getKeys(Field field) { - ConfigDefaultSections areasAnnot = field.getDeclaringClass().getAnnotation(ConfigDefaultSections.class); - return InjectionUtils.evaluateKeys(field, areasAnnot, field.getAnnotation(Config.class)); - } - - /** - * Collects all keys to be be accessed as defined by any annotations of type - * {@link ConfigDefaultSections}, {@link Config}. - * @param method the (optionally) annotated method instance - * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}. - */ - public static List<String> getKeys(Method method) { - ConfigDefaultSections areasAnnot = method.getDeclaringClass().getAnnotation(ConfigDefaultSections.class); - return InjectionUtils.evaluateKeys(method, areasAnnot, method.getAnnotation(Config.class)); - } - - /** - * Evaluates all absolute configuration keys based on the member name found. - * - * @param member member to analyze. - * @param areasAnnot the (optional) annotation defining areas to be looked up. - * @return the list of current keys in order how they should be processed/looked up. - */ - public static List<String> evaluateKeys(Member member, ConfigDefaultSections areasAnnot) { - List<String> keys = new ArrayList<>(); - String name = member.getName(); - String mainKey; - if (name.startsWith("get") || name.startsWith("set")) { - mainKey = Character.toLowerCase(name.charAt(3)) + name.substring(4); - } else { - mainKey = Character.toLowerCase(name.charAt(0)) + name.substring(1); - } - keys.add(mainKey); - if (areasAnnot != null) { - // Add prefixed entries, including absolute (root) entry for "" area keys. - for (String area : areasAnnot.value()) { - if (!area.isEmpty()) { - keys.add(area + '.' + mainKey); - } - } - } else { // add package name - keys.add(member.getDeclaringClass().getName() + '.' + mainKey); - keys.add(member.getDeclaringClass().getSimpleName() + '.' + mainKey); - } - return keys; - } - - /** - * Evaluates all absolute configuration keys based on the annotations found in a class. - * - * @param member member to analyze. - * @param areasAnnot the (optional) annotation definining areas to be looked up. - * @param propertyAnnotation the annotation on field/method level that may defined one or - * several keys to be looked up (in absolute or relative form). - * @return the list current keys in order how they should be processed/looked up. - */ - public static List<String> evaluateKeys(Member member, ConfigDefaultSections areasAnnot, Config propertyAnnotation) { - if(propertyAnnotation==null){ - return evaluateKeys(member, areasAnnot); - } - List<String> keys = new ArrayList<>(Arrays.asList(propertyAnnotation.value())); - if (keys.isEmpty()) { - keys.add(member.getName()); - } - ListIterator<String> iterator = keys.listIterator(); - while (iterator.hasNext()) { - String next = iterator.next(); - if (next.startsWith("[") && next.endsWith("]")) { - // absolute key, strip away brackets, take key as is - iterator.set(next.substring(1, next.length() - 1)); - } else { - if (areasAnnot != null && areasAnnot.value().length>0) { - // Remove original entry, since it will be replaced with prefixed entries - iterator.remove(); - // Add prefixed entries, including absolute (root) entry for "" area keys. - for (String area : areasAnnot.value()) { - iterator.add(area.isEmpty() ? next : area + '.' + next); - } - } - } - } - return keys; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java deleted file mode 100644 index b9540fd..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.tamaya.inject.api; - -/** - * Available policies that describe how changes affecting configured values are published/reinjected - * for a {@link DynamicValue}. - * The policy also affects the cases were any configured listeners/listener methods are called for - * propagation current configuration changes. - */ -public enum LoadPolicy { - /** - * The configuration keys is evaluated once, when the owning component is loaded/configured, but never updated later. - */ - INITIAL, - /** - * The configuration keys is evaluated exactly once on its first access/use lazily, but never updated later. - * @see DynamicValue#get() - * @see DynamicValue#commitAndGet() - */ - LAZY, - /** - * The configuration value is evaluated evertime it is accessed. - */ - ALWAYS -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java deleted file mode 100644 index c5234d3..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.tamaya.inject.api; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This is a small marker annotations to inform Tamaya that the annotated element should never be injected with - * configured data. This is useful because by default Tamaya tries to lookup and inject configuration also by - * using property or method names without annotations. With that annotation none of these will be happen. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(value = { ElementType.FIELD, ElementType.METHOD }) -public @interface NoConfig { - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java deleted file mode 100644 index 231b9b9..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.tamaya.inject.api; - -/** - * Policy to control how new values are applied to a {@link DynamicValue}. - */ -public enum UpdatePolicy { - /** New values are applied immedately and registered listeners are informed about the change. */ - IMMEDEATE, - /** New values or not applied, but stored in the newValue property. Explcit call to DynamicValue#commit - of DynamicValue#commitAndGet are required to accept the change and inform the listeners about the change. - * Registered listeners will be informed, when the commit was performed explicitly. - */ - EXPLCIT, - /** - * New values are always immedately discarded, listeners are not triggered. - */ - NEVER, - /** - * All listeners are informed about the change encountered, but the value will not be applied. - */ - LOG_ONLY -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java deleted file mode 100644 index 6630e53..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.tamaya.inject.api; - -import org.apache.tamaya.ConfigOperator; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to define an configuration operator to be used before accessing a configured key. - * This allows filtering the current configuration, e.g. to realize views or ensure security - * constraints. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(value = {ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER}) -public @interface WithConfigOperator { - - /** - * Define a custom adapter that should be used to adapt the configuration entry injected. This overrides any - * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is - * registered, it is handled as a deployment error. - * @return adapter used to transform the configuration entry. - */ - Class<? extends ConfigOperator> value(); - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java deleted file mode 100644 index 499360c..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.tamaya.inject.api; - - -import org.apache.tamaya.spi.PropertyConverter; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to define a type adapter to be used before injecting a configured key, or for applying changes. - * This will override any other adapter for performing the type conversion before - * injecting the field keys. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(value = {ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) -public @interface WithPropertyConverter { - - /** - * Define a custom adapter or codec that should be used to adapt the configuration entry injected. This overrides any - * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is - * registered, it is handled as a deployment error. - * @return adapter used to change the configuration entry. - */ - Class<? extends PropertyConverter<?>> value(); - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java deleted file mode 100644 index b5d8bc3..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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. - */ -/** - * Common njection API. - */ -package org.apache.tamaya.inject.api; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java deleted file mode 100644 index 94c0091..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.tamaya.inject.spi; - -import org.apache.tamaya.Configuration; - -import java.lang.reflect.Field; -import java.util.Collection; - -/** - * Abstract model of an field used to inject configuration. - */ -public interface ConfiguredField { - - /** - * Get the field's type. - * @return the field type, never null. - */ - Class<?> getType(); - - /** - * Get a list of all target keys for the given field. The first resolvable key normally determines the - * configuration value injected. - * @return a list of evaluated keys. - */ - Collection<String> getConfiguredKeys(); - - /** - * Get the field's name. - * @return the name, not null. - */ - String getName(); - - /** - * Get the field's full signature. - * @return the signature, not null. - */ - String getSignature(); - - /** - * Get the annotated field. - * @return the field, not null. - */ - Field getAnnotatedField(); - - /** - * Actually calls the annotated method on the instance, hereby passing the configuration values evaluated. - * @param instance the instance, not null. - * @param config the configuration, not null. - */ - void configure(Object instance, Configuration config); -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java deleted file mode 100644 index 128946e..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.tamaya.inject.spi; - -import org.apache.tamaya.Configuration; - -import java.lang.reflect.Method; -import java.util.Collection; - -/** - * Abstract model of an method used to inject configuration. - */ -public interface ConfiguredMethod { - - /** - * Get the key required to be evaluated. - * @return the configured keys. - */ - Collection<String> getConfiguredKeys(); - - /** - * Get the methods input parameter types. - * @return the method param types, not null. - */ - Class<?>[] getParameterTypes(); - - /** - * Get the underlying method reflection type. - * @return the method element. - */ - Method getAnnotatedMethod(); - - /** - * Get the method's name, e.g. {@code setName}. - * @return the name, never null. - */ - String getName(); - - /** - * Get the methods signature, e.g. {@code void setName(String)}. - * @return he signature, never null. - */ - String getSignature(); - - /** - * This method actually configures the given method on a instance of its parent type. - * This evaluates the initial key closure and applies changes on the field. - * - * @param instance the target instance, not null. - * @param config the configuration, not null. - * @throws org.apache.tamaya.ConfigException if evaluation or conversion failed. - */ - void configure(Object instance, Configuration config); -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java ---------------------------------------------------------------------- diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java deleted file mode 100644 index 0f81dc7..0000000 --- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.tamaya.inject.spi; - -import org.apache.tamaya.Configuration; - -import java.util.Collection; - -/** - * Abstract model of an type used to inject configuration. This also includes instances passed programmatically. - */ -public interface ConfiguredType{ - - /** - * Get the type's class. - * @return the base type. - */ - Class getType(); - - /** - * Get the type's name. - * @return the type's name. - */ - String getName(); - - /** - * Get the registered configured fields. - * @return the registered configured fields, never null. - */ - Collection<ConfiguredField> getConfiguredFields(); - - /** - * Get the registered configured methods. - * @return the registered configured methods, never null. - */ - Collection<ConfiguredMethod> getConfiguredMethods(); - - /** - * This method actually configures an instance using the given configuration data. - * - * @param instance The instance to be configured, not null. - * @param config the target config, not null. - */ - void configure(Object instance, Configuration config); - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection/cdi-ee/pom.xml ---------------------------------------------------------------------- diff --git a/modules/injection/cdi-ee/pom.xml b/modules/injection/cdi-ee/pom.xml new file mode 100644 index 0000000..4804738 --- /dev/null +++ b/modules/injection/cdi-ee/pom.xml @@ -0,0 +1,226 @@ +<!-- +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 current 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-injection-all</artifactId> + <version>0.3-incubating-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <artifactId>tamaya-cdi</artifactId> + <groupId>tamaya-integration</groupId> + <name>Apache Tamaya Modules - Injection CDI</name> + <packaging>bundle</packaging> + + <properties> + <owb.version>1.6.2</owb.version> + <weld.version>2.2.7.Final</weld.version> + <geronimo-jcdi-1.1-spec.version>1.0</geronimo-jcdi-1.1-spec.version> + <geronimo-interceptor-1.2-spec.version>1.0</geronimo-interceptor-1.2-spec.version> + <geronimo-atinject-1.0-spec.version>1.0</geronimo-atinject-1.0-spec.version> + <bval.version>0.5</bval.version> + <ds.version>1.1.0</ds.version> + <javaee-api.version>6.0-6</javaee-api.version> + <openejb.version>4.7.1</openejb.version> + <tomee.version>1.7.1</tomee.version> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <executions> + <execution> + <id>prepare-agent</id> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package> + org.apache.tamaya.integration.cdi + </Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-injection-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>java-hamcrest</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-core</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-api</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>javaee-api</artifactId> + <version>${javaee-api.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.tomitribe</groupId> + <artifactId>tomitribe-util</artifactId> + <version>1.1.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>openejb-core</artifactId> + <version>${openejb.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jcdi_1.1_spec</artifactId> + <version>${geronimo-jcdi-1.1-spec.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-test-control-module-api</artifactId> + <version>${ds.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-test-control-module-impl</artifactId> + <version>${ds.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + <profiles> + <!--<profile>--> + <!--<id>OWB</id>--> + <!--<!– there is an issue with this profile:--> + <!--java.lang.NoClassDefFoundError: org/apache/webbeans/event/EventMetadata--> + <!--–>--> + <!--<activation>--> + <!--<activeByDefault>false</activeByDefault>--> + <!--</activation>--> + <!--<dependencies>--> + <!--<!– OWB specific dependencies–>--> + <!--<dependency>--> + <!--<groupId>org.apache.geronimo.specs</groupId>--> + <!--<artifactId>geronimo-atinject_1.0_spec</artifactId>--> + <!--<version>${geronimo-atinject-1.0-spec.version}</version>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>org.apache.geronimo.specs</groupId>--> + <!--<artifactId>geronimo-interceptor_1.2_spec</artifactId>--> + <!--<version>${geronimo-interceptor-1.2-spec.version}</version>--> + <!--<scope>test</scope>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>org.apache.geronimo.specs</groupId>--> + <!--<artifactId>geronimo-annotation_1.2_spec</artifactId>--> + <!--<version>1.0</version>--> + <!--<scope>test</scope>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>org.apache.geronimo.specs</groupId>--> + <!--<artifactId>geronimo-el_2.2_spec</artifactId>--> + <!--<version>1.0.2</version>--> + <!--</dependency>--> + + <!--<dependency>--> + <!--<groupId>org.apache.openwebbeans</groupId>--> + <!--<artifactId>openwebbeans-impl</artifactId>--> + <!--<version>${owb.version}</version>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>org.apache.openwebbeans</groupId>--> + <!--<artifactId>openwebbeans-spi</artifactId>--> + <!--<version>${owb.version}</version>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>org.apache.openwebbeans</groupId>--> + <!--<artifactId>openwebbeans-resource</artifactId>--> + <!--<version>${owb.version}</version>--> + <!--</dependency>--> + + <!--<dependency>--> + <!--<groupId>org.apache.bval</groupId>--> + <!--<artifactId>bval-jsr303</artifactId>--> + <!--<version>${bval.version}</version>--> + <!--<scope>test</scope>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>org.apache.deltaspike.cdictrl</groupId>--> + <!--<artifactId>deltaspike-cdictrl-owb</artifactId>--> + <!--<version>${ds.version}</version>--> + <!--<scope>test</scope>--> + <!--</dependency>--> + <!--</dependencies>--> + <!--</profile>--> + <profile> + <id>Weld</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.jboss.weld.se</groupId> + <artifactId>weld-se</artifactId> + <version>${weld.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.deltaspike.cdictrl</groupId> + <artifactId>deltaspike-cdictrl-weld</artifactId> + <version>${ds.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIAwareServiceContext.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIAwareServiceContext.java b/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIAwareServiceContext.java new file mode 100644 index 0000000..5bfb1c1 --- /dev/null +++ b/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIAwareServiceContext.java @@ -0,0 +1,169 @@ +/* + * 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.tamaya.integration.cdi; + +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.spi.ServiceContext; + +import javax.annotation.Priority; +import javax.enterprise.inject.Instance; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import java.text.MessageFormat; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + + +/** + * <p>This class implements a {@link ServiceContext}, which basically provides a similar loading mechanism as used + * by the {@link java.util.ServiceLoader}. Whereas the {@link java.util.ServiceLoader} only loads configurations + * and instances from one classloader, this loader manages configs found and the related instances for each + * classloader along the classloader hierarchies individually. It ensures instances are loaded on the classloader + * level, where they first are visible. Additionally it ensures the same configuration resource (and its + * declared services) are loaded multiple times, when going up the classloader hierarchy.</p> + * + * <p>Finally classloaders are not stored by reference by this class, to ensure they still can be garbage collected. + * Refer also the inherited parent class for further details.</p> + * + * <p>This class uses an ordinal of {@code 10}, so it overrides any default {@link ServiceContext} implementations + * provided with the Tamaya core modules.</p> + */ +public class CDIAwareServiceContext implements ServiceContext { + + /** + * Singletons. + */ + private final Map<Class<?>, Object> singletons = new ConcurrentHashMap<>(); + + private ServiceContext defaultServiceContext = new ServiceLoaderServiceContext(); + + + @Override + public <T> T getService(Class<T> serviceType) { + Object cached = singletons.get(serviceType); + if (cached == null) { + Collection<T> services = getServices(serviceType); + if (services.isEmpty()) { + cached = null; + } else { + cached = getServiceWithHighestPriority(services, serviceType); + } + if(cached!=null) { + singletons.put(serviceType, cached); + } + } + return serviceType.cast(cached); + } + + /** + * Loads and registers services. + * + * @param <T> the concrete type. + * @param serviceType The service type. + * @return the items found, never {@code null}. + */ + @Override + public <T> List<T> getServices(final Class<T> serviceType) { + List<T> found = defaultServiceContext.getServices(serviceType); + BeanManager beanManager = TamayaCDIIntegration.getBeanManager(); + Instance<T> cdiInstances = null; + if(beanManager!=null){ + Set<Bean<?>> instanceBeans = beanManager.getBeans(Instance.class); + Bean<?> bean = instanceBeans.iterator().next(); + cdiInstances = (Instance<T>)beanManager.getReference(bean, Instance.class, + beanManager.createCreationalContext(bean)); + } + if(cdiInstances!=null){ + for(T t:cdiInstances.select(serviceType)){ + found.add(t); + } + } + return found; + } + + /** + * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such + * annotation is present, a default priority is returned (1); + * @param o the instance, not null. + * @return a priority, by default 1. + */ + public static int getPriority(Object o){ + int prio = 1; //X TODO discuss default priority + Priority priority = o.getClass().getAnnotation(Priority.class); + if (priority != null) { + prio = priority.value(); + } + return prio; + } + + /** + * @param services to scan + * @param <T> type of the service + * + * @return the service with the highest {@link Priority#value()} + * + * @throws ConfigException if there are multiple service implementations with the maximum priority + */ + private <T> T getServiceWithHighestPriority(Collection<T> services, Class<T> serviceType) { + + // we do not need the priority stuff if the list contains only one element + if (services.size() == 1) { + return services.iterator().next(); + } + + Integer highestPriority = null; + int highestPriorityServiceCount = 0; + T highestService = null; + + for (T service : services) { + int prio = getPriority(service); + if (highestPriority == null || highestPriority < prio) { + highestService = service; + highestPriorityServiceCount = 1; + highestPriority = prio; + } else if (highestPriority == prio) { + highestPriorityServiceCount++; + } + } + + if (highestPriorityServiceCount > 1) { + throw new ConfigException(MessageFormat.format("Found {0} implementations for Service {1} with Priority {2}: {3}", + highestPriorityServiceCount, + serviceType.getName(), + highestPriority, + services)); + } + + return highestService; + } + + /** + * Returns ordinal of 20, overriding defaults as well as the inherited (internally used) CLAwareServiceContext + * instance. + * @return ordinal of 20. + */ + @Override + public int ordinal() { + return 20; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredField.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredField.java b/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredField.java new file mode 100644 index 0000000..fa826f5 --- /dev/null +++ b/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredField.java @@ -0,0 +1,77 @@ +/* + * 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.tamaya.integration.cdi; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.inject.spi.ConfiguredField; + +import javax.enterprise.inject.spi.InjectionPoint; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * CDI implementation for event publishing of configured instances. + */ +class CDIConfiguredField implements ConfiguredField{ + + private final Field field; + private List<String> keys = new ArrayList<>(); + + CDIConfiguredField(InjectionPoint injectionPoint, List<String> keys){ + this.field = (Field)injectionPoint.getMember(); + this.keys.addAll(keys); + this.keys = Collections.unmodifiableList(this.keys); + } + + @Override + public Class<?> getType() { + return field.getType(); + } + + @Override + public Collection<String> getConfiguredKeys() { + return keys; + } + + @Override + public Field getAnnotatedField() { + return field; + } + + @Override + public String getName() { + return field.getName(); + } + + @Override + public String getSignature() { + return getName()+':'+field.getType().getName(); + } + + @Override + public void configure(Object instance, Configuration config) { + throw new UnsupportedOperationException("Use CDI annotations for configuration injection."); + } + + @Override + public String toString() { + return "CDIConfiguredField["+getSignature()+']'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredMethod.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredMethod.java b/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredMethod.java new file mode 100644 index 0000000..ed8019a --- /dev/null +++ b/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredMethod.java @@ -0,0 +1,77 @@ +/* + * 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.tamaya.integration.cdi; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.inject.spi.ConfiguredMethod; + +import javax.enterprise.inject.spi.InjectionPoint; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of a configured methods for CDI module. + */ +public class CDIConfiguredMethod implements ConfiguredMethod{ + + private final Method method; + private List<String> keys = new ArrayList<>(); + + CDIConfiguredMethod(InjectionPoint injectionPoint, List<String> keys){ + this.method = (Method)injectionPoint.getMember(); + this.keys.addAll(keys); + this.keys = Collections.unmodifiableList(this.keys); + } + + @Override + public Collection<String> getConfiguredKeys() { + return keys; + } + + @Override + public Class<?>[] getParameterTypes() { + return method.getParameterTypes(); + } + + @Override + public Method getAnnotatedMethod() { + return method; + } + + @Override + public String getName() { + return method.getName(); + } + + @Override + public String getSignature() { + return null; + } + + @Override + public void configure(Object instance, Configuration config) { + throw new UnsupportedOperationException("Use CDI annotations for configuration injection."); + } + + @Override + public String toString() { + return "CDIConfiguredMethod["+getSignature()+']'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/fe7cd8f1/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredType.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredType.java b/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredType.java new file mode 100644 index 0000000..c677065 --- /dev/null +++ b/modules/injection/cdi-ee/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredType.java @@ -0,0 +1,94 @@ +/* + * 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.tamaya.integration.cdi; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.inject.spi.ConfiguredField; +import org.apache.tamaya.inject.spi.ConfiguredMethod; +import org.apache.tamaya.inject.spi.ConfiguredType; + +import javax.enterprise.inject.spi.InjectionPoint; +import java.lang.reflect.Field; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + +/** + * Event published for items configured by CDI extensions. This is for example used by the documentation module + * to automatically track the configuration endpoints for documentation. + */ +class CDIConfiguredType implements ConfiguredType{ + + private final Class<?> type; + private final List<CDIConfiguredMethod> methods = new ArrayList<>(); + private final List<CDIConfiguredField> fields = new ArrayList<>(); + + public CDIConfiguredType(Class<?> type){ + this.type = Objects.requireNonNull(type); + } + + @Override + public Class getType() { + return type; + } + + @Override + public String getName() { + return type.getName(); + } + + @Override + public Collection<ConfiguredField> getConfiguredFields() { + return null; + } + + @Override + public Collection<ConfiguredMethod> getConfiguredMethods() { + return null; + } + + @Override + public void configure(Object instance, Configuration config) { + throw new UnsupportedOperationException("Use CDI annotations for configuration injection."); + } + + /** + * Used to build up during injection point processing. + * @param injectionPoint the CDI injection ppint, not null. + * @param keys the possible config keys, in order of precedence, not null. + */ + void addConfiguredMember(InjectionPoint injectionPoint, List<String> keys) { + Member member = injectionPoint.getMember(); + if(member instanceof Field){ + this.fields.add(new CDIConfiguredField(injectionPoint, keys)); + } else if(member instanceof Method){ + this.methods.add(new CDIConfiguredMethod(injectionPoint, keys)); + } + } + + @Override + public String toString() { + return "CDIConfiguredType{" + + "type=" + type + + ", methods=" + methods + + ", fields=" + fields + + '}'; + } +}
