You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/11/30 09:01:58 UTC
[1/6] incubator-tamaya git commit: Added feature to send
ConfiguredType event using BeanManager for configured beans.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 812871712 -> faf09e97c
Added feature to send ConfiguredType event using BeanManager for configured beans.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/bca5ee42
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/bca5ee42
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/bca5ee42
Branch: refs/heads/master
Commit: bca5ee4255015ad047575eff595bc12a4db24de2
Parents: 8128717
Author: anatole <an...@apache.org>
Authored: Mon Nov 30 08:28:54 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Nov 30 08:28:54 2015 +0100
----------------------------------------------------------------------
.../integration/cdi/CDIConfiguredField.java | 79 +++++++++
.../integration/cdi/CDIConfiguredMethod.java | 77 +++++++++
.../integration/cdi/CDIConfiguredType.java | 95 +++++++++++
.../integration/cdi/ConfigurationExtension.java | 164 ++++++++++---------
4 files changed, 338 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bca5ee42/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredField.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredField.java
new file mode 100644
index 0000000..eb99676
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredField.java
@@ -0,0 +1,79 @@
+/*
+ * 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 javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created by atsticks on 29.11.15.
+ */
+class CDIConfiguredField implements ConfiguredField{
+
+ private 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/blob/bca5ee42/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredMethod.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredMethod.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredMethod.java
new file mode 100644
index 0000000..220fe9c
--- /dev/null
+++ b/modules/integration/cdi/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;
+
+/**
+ * Created by atsticks on 29.11.15.
+ */
+public class CDIConfiguredMethod implements ConfiguredMethod{
+
+ private 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/blob/bca5ee42/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredType.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredType.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredType.java
new file mode 100644
index 0000000..4792c41
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/CDIConfiguredType.java
@@ -0,0 +1,95 @@
+/*
+ * 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 Class<?> type;
+ private List<CDIConfiguredMethod> methods = new ArrayList<>();
+ private 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
+ */
+ 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 +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bca5ee42/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
index 4cf5c53..3ad276a 100644
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
@@ -36,6 +36,7 @@ import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.ProcessBean;
import javax.enterprise.inject.spi.ProcessProducerMethod;
+import javax.inject.Inject;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -61,75 +62,6 @@ public class ConfigurationExtension implements Extension {
static final Map<Class, ConfigOperator> CUSTOM_OPERATORS = new ConcurrentHashMap<>();
static final Map<Class, PropertyConverter> CUSTOM_CONVERTERS = new ConcurrentHashMap<>();
- /**
- * Internally used conversion bean.
- */
- private static class ConverterBean implements Bean<Object> {
-
- private final Bean<Object> delegate;
- private final Set<Type> types;
-
- public ConverterBean(final Bean convBean, final Set<Type> types) {
- this.types = types;
- this.delegate = convBean;
- }
-
- @Override
- public Set<Type> getTypes() {
- return types;
- }
-
- @Override
- public Class<?> getBeanClass() {
- return delegate.getBeanClass();
- }
-
- @Override
- public Set<InjectionPoint> getInjectionPoints() {
- return delegate.getInjectionPoints();
- }
-
- @Override
- public String getName() {
- return delegate.getName();
- }
-
- @Override
- public Set<Annotation> getQualifiers() {
- return delegate.getQualifiers();
- }
-
- @Override
- public Class<? extends Annotation> getScope() {
- return delegate.getScope();
- }
-
- @Override
- public Set<Class<? extends Annotation>> getStereotypes() {
- return delegate.getStereotypes();
- }
-
- @Override
- public boolean isAlternative() {
- return delegate.isAlternative();
- }
-
- @Override
- public boolean isNullable() {
- return delegate.isNullable();
- }
-
- @Override
- public Object create(CreationalContext<Object> creationalContext) {
- return delegate.create(creationalContext);
- }
-
- @Override
- public void destroy(Object instance, CreationalContext<Object> creationalContext) {
- delegate.destroy(instance, creationalContext);
- }
- }
-
private Set<Type> types = new HashSet<>();
private Bean<?> convBean;
@@ -137,10 +69,12 @@ public class ConfigurationExtension implements Extension {
* Method that checks the configuration injection points during deployment for available configuration.
* @param pb the bean to process.
*/
- public void retrieveTypes(@Observes final ProcessBean<?> pb) {
+ public void retrieveTypes(@Observes final ProcessBean<?> pb, BeanManager beanManager) {
final Set<InjectionPoint> ips = pb.getBean().getInjectionPoints();
+ CDIConfiguredType configuredType = new CDIConfiguredType(pb.getBean().getBeanClass());
+ boolean configured = false;
for (InjectionPoint injectionPoint : ips) {
if (injectionPoint.getAnnotated().isAnnotationPresent(Config.class)) {
final Config annotation = injectionPoint.getAnnotated().getAnnotation(Config.class);
@@ -181,8 +115,27 @@ public class ConfigurationExtension implements Extension {
keys.toString()));
}
types.add(injectionPoint.getType());
+ if(annotation!=null){
+ configured = true;
+ configuredType.addConfiguredMember(injectionPoint, keys);
+ }
}
}
+ if(configured) {
+ beanManager.fireEvent(configuredType);
+ }
+ }
+
+
+ public void captureConvertBean(@Observes final ProcessProducerMethod<?, ?> ppm) {
+ if (ppm.getAnnotated().isAnnotationPresent(Config.class)) {
+ convBean = ppm.getBean();
+ }
+
+ }
+
+ public void addConverter(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
+ abd.addBean(new ConverterBean(convBean, types));
}
private void tryLoadOpererator(Class<? extends ConfigOperator> operatorClass) {
@@ -253,16 +206,73 @@ public class ConfigurationExtension implements Extension {
}
- public void captureConvertBean(@Observes final ProcessProducerMethod<?, ?> ppm) {
- if (ppm.getAnnotated().isAnnotationPresent(Config.class)) {
- convBean = ppm.getBean();
+ /**
+ * Internally used conversion bean.
+ */
+ private static class ConverterBean implements Bean<Object> {
+
+ private final Bean<Object> delegate;
+ private final Set<Type> types;
+
+ public ConverterBean(final Bean convBean, final Set<Type> types) {
+ this.types = types;
+ this.delegate = convBean;
}
- }
+ @Override
+ public Set<Type> getTypes() {
+ return types;
+ }
- public void addConverter(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
- abd.addBean(new ConverterBean(convBean, types));
- }
+ @Override
+ public Class<?> getBeanClass() {
+ return delegate.getBeanClass();
+ }
+ @Override
+ public Set<InjectionPoint> getInjectionPoints() {
+ return delegate.getInjectionPoints();
+ }
+
+ @Override
+ public String getName() {
+ return delegate.getName();
+ }
+
+ @Override
+ public Set<Annotation> getQualifiers() {
+ return delegate.getQualifiers();
+ }
+
+ @Override
+ public Class<? extends Annotation> getScope() {
+ return delegate.getScope();
+ }
+
+ @Override
+ public Set<Class<? extends Annotation>> getStereotypes() {
+ return delegate.getStereotypes();
+ }
+
+ @Override
+ public boolean isAlternative() {
+ return delegate.isAlternative();
+ }
+
+ @Override
+ public boolean isNullable() {
+ return delegate.isNullable();
+ }
+
+ @Override
+ public Object create(CreationalContext<Object> creationalContext) {
+ return delegate.create(creationalContext);
+ }
+
+ @Override
+ public void destroy(Object instance, CreationalContext<Object> creationalContext) {
+ delegate.destroy(instance, creationalContext);
+ }
+ }
}
[2/6] incubator-tamaya git commit: Added SPI for sending events for
beans configured (used e.g. for documentation and logging).
Posted by an...@apache.org.
Added SPI for sending events for beans configured (used e.g. for documentation and logging).
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/cf6b4118
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/cf6b4118
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/cf6b4118
Branch: refs/heads/master
Commit: cf6b4118fc624e54c4d118080c2916e5445825a3
Parents: bca5ee4
Author: anatole <an...@apache.org>
Authored: Mon Nov 30 08:29:58 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Nov 30 08:29:58 2015 +0100
----------------------------------------------------------------------
.../tamaya/inject/spi/ConfiguredField.java | 68 +++++++++++++++++++
.../tamaya/inject/spi/ConfiguredMethod.java | 71 ++++++++++++++++++++
.../tamaya/inject/spi/ConfiguredType.java | 63 +++++++++++++++++
3 files changed, 202 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/cf6b4118/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
new file mode 100644
index 0000000..94c0091
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java
@@ -0,0 +1,68 @@
+/*
+ * 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/blob/cf6b4118/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
new file mode 100644
index 0000000..0881026
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java
@@ -0,0 +1,71 @@
+/*
+ * 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.ConfigException;
+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
+ */
+ 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 ConfigException if evaluation or conversion failed.
+ */
+ void configure(Object instance, Configuration config);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/cf6b4118/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
new file mode 100644
index 0000000..c223004
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.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.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
+ */
+ 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.
+ */
+ public 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);
+
+
+}
[6/6] incubator-tamaya git commit: Decoupled logic (and moved it into
model module).
Posted by an...@apache.org.
Decoupled logic (and moved it into model module).
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/faf09e97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/faf09e97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/faf09e97
Branch: refs/heads/master
Commit: faf09e97ca982cacfb64fba50fae62225c2a25f7
Parents: 8f2a689
Author: anatole <an...@apache.org>
Authored: Mon Nov 30 09:01:49 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Nov 30 09:01:49 2015 +0100
----------------------------------------------------------------------
.../tamaya/inject/internal/ModelPopulator.java | 144 -------------------
1 file changed, 144 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/faf09e97/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java
deleted file mode 100644
index 3fbc243..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java
+++ /dev/null
@@ -1,144 +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.internal;
-
-import org.apache.tamaya.inject.api.InjectionUtils;
-import org.apache.tamaya.model.ConfigValidator;
-import org.apache.tamaya.model.spi.ParameterValidation;
-
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.logging.Logger;
-
-/**
- * Internal facade that registers all kind of injected fields as {@link org.apache.tamaya.model.Validation} entries,
- * so all configured injection points are visible as documented configuration hooks.
- */
-final class ModelPopulator {
-
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(ModelPopulator.class.getName());
-
- /**
- * The singleton class of the model module to be tested for availability on the classpath.
- */
- private static final String MODEL_SINGLETON_CLASS = "org.apache.tamaya.model.ConfigValidator";
- /**
- * Flag initialized to true, if the model module is visible on the same classloader, also this module was loaded.
- */
- private static boolean modelModuleLoaded = checkModelModuleLoaded();
-
- /**
- * Initializes the flag, controlling the availability of this component.
- *
- * @return true, if the tamaya-model module is visible.
- */
- private static boolean checkModelModuleLoaded() {
- try {
- Class.forName(MODEL_SINGLETON_CLASS, false, ModelPopulator.class.getClassLoader());
- LOG.info("Tamaya Model extension is available. Validation models will be updated" +
- " based on injected config.");
- return true;
- } catch (Exception e) {
- LOG.info("Tamaya Model extension not available. Validation models will not be updated" +
- " based on injected config.");
- return false;
- }
- }
-
- /**
- * Utility classes should not be instantiated.
- */
- private ModelPopulator(){}
-
- /**
- * Registers the given {@link ConfiguredType} into the tamaya-model validation/documentation module.
- *
- * @param confType the type, not null.
- */
- public static void register(ConfiguredType confType) {
- if (!modelModuleLoaded) {
- return;
- }
- for (ConfiguredField field : confType.getConfiguredFields()) {
- Collection<String> keys = field.getConfiguredKeys();
- for (String key : keys) {
- ParameterValidation val = ConfigValidator.getValidation(key, ParameterValidation.class);
- if (val == null) {
- InjectableValidationProvider.addValidation(new ParameterValidation.Builder(key)
- .setType(field.getType().getName())
- .setDescription("Injected field: " +
- field.annotatedField.getDeclaringClass().getName() + '.' + field.toString() +
- ", \nconfigured with keys: " + keys)
- .build());
- }
- }
- }
- for (ConfiguredSetterMethod method : confType.getConfiguredSetterMethods()) {
- Collection<String> keys = method.getConfiguredKeys();
- for (String key : keys) {
- ParameterValidation val = ConfigValidator.getValidation(key, ParameterValidation.class);
- if (val == null) {
- InjectableValidationProvider.addValidation(new ParameterValidation.Builder(key)
- .setType(method.getParameterType().getName())
- .setDescription("Injected field: " +
- method.getAnnotatedMethod().getDeclaringClass().getName() + '.' + method.toString() +
- ", \nconfigured with keys: " + keys)
- .build());
- }
- }
- }
-// for (ConfigChangeCallbackMethod callback : confType.getObserverMethods() {
-// Collection<String> keys = callback.getConfiguredKeys();
-// for (String key : keys) {
-// CallbackValidation val = ConfigValidator.getValidation(key, CallbackValidation.class);
-// if (val == null) {
-// InjectableValidationProvider.addValidation(new CallbackValidation(key, callback));
-// }
-// }
-// }
-
- }
-
- public static void registerTemplate(Class<?> type) {
- if (!modelModuleLoaded) {
- return;
- }
- for (Method method : type.getMethods()) {
- if (method.getDeclaringClass() == Object.class) {
- // skip methods decalred on object.
- continue;
- }
- Collection<String> keys = InjectionUtils.getKeys(method);
- for (String key : keys) {
- ParameterValidation val = ConfigValidator.getValidation(key, ParameterValidation.class);
- if (val == null) {
- InjectableValidationProvider.addValidation(new ParameterValidation.Builder(key)
- .setType(method.getReturnType().getName())
- .setDescription("Template method: " +
- type.getName() + '.' + method.toString() + ", \n" +
- "configured with keys: " + keys)
- .build());
- }
- }
- }
- }
-}
[4/6] incubator-tamaya git commit: Refactored model module a bit so
it was possible to move some logic from the injection modules into this
module. Effectively decoupling was modelled by adding a ConfiguredTypeEvent,
which is used to implicitly populate
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/AreaConfigModel.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/AreaConfigModel.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/AreaConfigModel.java
new file mode 100644
index 0000000..6d14028
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/AreaConfigModel.java
@@ -0,0 +1,204 @@
+/*
+ * 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.model.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.ModelType;
+import org.apache.tamaya.model.ValidationResult;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default configuration Model for a configuration section.
+ */
+public class AreaConfigModel extends ConfigModelGroup {
+
+ /**
+ * Creates a new builder.
+ * @param name the section name.
+ * @return a new builder instance.
+ */
+ public static Builder builder(String name){
+ return new Builder(name);
+ }
+
+ /**
+ * Creates a section validation for the given section.
+ * @param name the fully qualified section name
+ * @param required flag, if the section is required to be present.
+ * @return the ConfigModel instance
+ */
+ public static ConfigModel of(String name, boolean required){
+ return new Builder(name).setRequired(required).build();
+ }
+
+ /**
+ * Creates a section validation for the given section.
+ * @param name the fully qualified section name
+ * @param required flag, if the section is required to be present.
+ * @param configModels additional configModels
+ * @return
+ */
+ public static ConfigModel of(String name, boolean required, ConfigModel... configModels){
+ return new Builder(name).setRequired(required).addValidations(configModels).build();
+ }
+
+ /**
+ * Internal constructor.
+ * @param builder the builder, not null.
+ */
+ protected AreaConfigModel(Builder builder) {
+ super(builder.name, builder.provider, builder.childConfigModels);
+ }
+
+ @Override
+ public ModelType getType(){
+ return ModelType.Section;
+ }
+
+ @Override
+ public Collection<ValidationResult> validate(Configuration config) {
+ Map<String,String> map = config.getProperties();
+ String lookupKey = getName() + '.';
+ boolean present = false;
+ for(String key:map.keySet()){
+ if(key.startsWith(lookupKey)){
+ present = true;
+ break;
+ }
+ }
+ List<ValidationResult> result = new ArrayList<>(1);
+ if(isRequired() && !present) {
+ result.add(ValidationResult.ofMissing(this));
+ }
+ result.addAll(super.validate(config));
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append(getType()).append(": " + getName());
+ if(isRequired()) {
+ b.append(", required: " + isRequired());
+ }
+ for(ConfigModel val:getValidations()){
+ b.append(", ").append(val.toString());
+ }
+ return b.toString();
+ }
+
+ /**
+ * Builder for setting up a AreaConfigModel instance.
+ */
+ public static class Builder{
+ /** The section name. */
+ private String name;
+ /** The optional provider. */
+ private String provider;
+ /** The optional description. */
+ private String description;
+ /** The required flag. */
+ private boolean required;
+ /** The (optional) custom validations.*/
+ private List<ConfigModel> childConfigModels = new ArrayList<>();
+
+ /**
+ * Creates a new Builder.
+ * @param sectionName the section name, not null.
+ */
+ public Builder(String sectionName){
+ this.name = Objects.requireNonNull(sectionName);
+ }
+
+ /**
+ * Add configModels.
+ * @param configModels the configModels, not null.
+ * @return the Builder for chaining.
+ */
+ public Builder addValidations(ConfigModel... configModels){
+ this.childConfigModels.addAll(Arrays.asList(configModels));
+ return this;
+ }
+
+ /**
+ * Add configModels.
+ * @param configModels the configModels, not null.
+ * @return the Builder for chaining.
+ */
+ public Builder addValidations(Collection<ConfigModel> configModels){
+ this.childConfigModels.addAll(configModels);
+ return this;
+ }
+
+ /**
+ * Sets the required flag.
+ * @param required zhe flag.
+ * @return the Builder for chaining.
+ */
+ public Builder setRequired(boolean required){
+ this.required = required;
+ return this;
+ }
+
+ /**
+ * Set the )optional) description.
+ * @param description the description.
+ * @return the Builder for chaining.
+ */
+ public Builder setDescription(String description){
+ this.description = description;
+ return this;
+ }
+
+ /**
+ * Set the )optional) provider.
+ * @param provider the provider.
+ * @return the Builder for chaining.
+ */
+ public Builder setProvider(String provider){
+ this.provider = provider;
+ return this;
+ }
+
+ /**
+ * Set the section name
+ * @param name the section name, not null.
+ * @return the Builder for chaining.
+ */
+ public Builder setName(String name){
+ this.name = Objects.requireNonNull(name);
+ return this;
+ }
+
+ /**
+ * Build a new ConfigModel instance.
+ * @return the new ConfigModel instance, not null.
+ */
+ public ConfigModel build(){
+ return new AreaConfigModel(this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/AreaValidation.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/AreaValidation.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/AreaValidation.java
deleted file mode 100644
index efef5a3..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/AreaValidation.java
+++ /dev/null
@@ -1,204 +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.model.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.model.ValidationResult;
-import org.apache.tamaya.model.Validation;
-import org.apache.tamaya.model.ValidationType;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Default configuration Model for a configuration section.
- */
-public class AreaValidation extends ValidationGroup {
-
- /**
- * Creates a new builder.
- * @param name the section name.
- * @return a new builder instance.
- */
- public static Builder builder(String name){
- return new Builder(name);
- }
-
- /**
- * Creates a section validation for the given section.
- * @param name the fully qualified section name
- * @param required flag, if the section is required to be present.
- * @return the Validation instance
- */
- public static Validation of(String name, boolean required){
- return new Builder(name).setRequired(required).build();
- }
-
- /**
- * Creates a section validation for the given section.
- * @param name the fully qualified section name
- * @param required flag, if the section is required to be present.
- * @param validations additional validations
- * @return
- */
- public static Validation of(String name, boolean required, Validation... validations){
- return new Builder(name).setRequired(required).addValidations(validations).build();
- }
-
- /**
- * Internal constructor.
- * @param builder the builder, not null.
- */
- protected AreaValidation(Builder builder) {
- super(builder.name, builder.provider, builder.childValidations);
- }
-
- @Override
- public ValidationType getType(){
- return ValidationType.Section;
- }
-
- @Override
- public Collection<ValidationResult> validate(Configuration config) {
- Map<String,String> map = config.getProperties();
- String lookupKey = getName() + '.';
- boolean present = false;
- for(String key:map.keySet()){
- if(key.startsWith(lookupKey)){
- present = true;
- break;
- }
- }
- List<ValidationResult> result = new ArrayList<>(1);
- if(isRequired() && !present) {
- result.add(ValidationResult.ofMissing(this));
- }
- result.addAll(super.validate(config));
- return result;
- }
-
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder();
- b.append(getType()).append(": " + getName());
- if(isRequired()) {
- b.append(", required: " + isRequired());
- }
- for(Validation val:getValidations()){
- b.append(", ").append(val.toString());
- }
- return b.toString();
- }
-
- /**
- * Builder for setting up a AreaValidation instance.
- */
- public static class Builder{
- /** The section name. */
- private String name;
- /** The optional provider. */
- private String provider;
- /** The optional description. */
- private String description;
- /** The required flag. */
- private boolean required;
- /** The (optional) custom validations.*/
- private List<Validation> childValidations = new ArrayList<>();
-
- /**
- * Creates a new Builder.
- * @param sectionName the section name, not null.
- */
- public Builder(String sectionName){
- this.name = Objects.requireNonNull(sectionName);
- }
-
- /**
- * Add validations.
- * @param validations the validations, not null.
- * @return the Builder for chaining.
- */
- public Builder addValidations(Validation... validations){
- this.childValidations.addAll(Arrays.asList(validations));
- return this;
- }
-
- /**
- * Add validations.
- * @param validations the validations, not null.
- * @return the Builder for chaining.
- */
- public Builder addValidations(Collection<Validation> validations){
- this.childValidations.addAll(validations);
- return this;
- }
-
- /**
- * Sets the required flag.
- * @param required zhe flag.
- * @return the Builder for chaining.
- */
- public Builder setRequired(boolean required){
- this.required = required;
- return this;
- }
-
- /**
- * Set the )optional) description.
- * @param description the description.
- * @return the Builder for chaining.
- */
- public Builder setDescription(String description){
- this.description = description;
- return this;
- }
-
- /**
- * Set the )optional) provider.
- * @param provider the provider.
- * @return the Builder for chaining.
- */
- public Builder setProvider(String provider){
- this.provider = provider;
- return this;
- }
-
- /**
- * Set the section name
- * @param name the section name, not null.
- * @return the Builder for chaining.
- */
- public Builder setName(String name){
- this.name = Objects.requireNonNull(name);
- return this;
- }
-
- /**
- * Build a new Validation instance.
- * @return the new Validation instance, not null.
- */
- public Validation build(){
- return new AreaValidation(this);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java
index 842d0e9..bad5b10 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.model.spi;
-import org.apache.tamaya.model.ValidationType;
+import org.apache.tamaya.model.ModelType;
/**
* JMX Management bean for accessing current configuration information
@@ -33,7 +33,7 @@ public interface ConfigDocumentationMBean {
public String getConfigurationModel();
- public String getConfigurationModel(ValidationType type);
+ public String getConfigurationModel(ModelType type);
/**
* Find the validations by checking the validation's name using the given regular expression.
@@ -44,9 +44,9 @@ public interface ConfigDocumentationMBean {
/**
* Find the validations by checking the validation's name using the given regular expression.
- * @param type the target ValidationType, not null.
+ * @param type the target ModelType, not null.
* @param namePattern the regular expression to use, not null.
* @return the sections defined, never null.
*/
- public String findValidationModels(ValidationType type, String namePattern);
+ public String findValidationModels(ModelType type, String namePattern);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelGroup.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelGroup.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelGroup.java
new file mode 100644
index 0000000..2c8fb1b
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelGroup.java
@@ -0,0 +1,112 @@
+/*
+ * 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.model.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.ModelType;
+import org.apache.tamaya.model.ValidationResult;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Default configuration Model for a configuration area.
+ */
+public class ConfigModelGroup implements ConfigModel {
+
+ private String name;
+ private boolean required;
+ private String provider;
+ private List<ConfigModel> childConfigModels = new ArrayList<>();
+
+ public ConfigModelGroup(String name, String provider, ConfigModel... configModels){
+ this(name, provider, Arrays.asList(configModels));
+ }
+
+ public ConfigModelGroup(String name, String provider, Collection<ConfigModel> configModels){
+ this.name = Objects.requireNonNull(name);
+ this.provider = provider;
+ this.childConfigModels.addAll(configModels);
+ this.childConfigModels = Collections.unmodifiableList(childConfigModels);
+ for(ConfigModel val: configModels) {
+ if(val.isRequired()){
+ this.required = true;
+ break;
+ }
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getProvider() {
+ return provider;
+ }
+
+ @Override
+ public boolean isRequired() {
+ return required;
+ }
+
+ @Override
+ public ModelType getType() {
+ return ModelType.Group;
+ }
+
+ @Override
+ public String getDescription() {
+ if(childConfigModels.isEmpty()){
+ return null;
+ }
+ StringBuilder b = new StringBuilder();
+ for(ConfigModel val: childConfigModels){
+ b.append(" >> " + val);
+ }
+ return b.toString();
+ }
+
+ public Collection<ConfigModel> getValidations(){
+ return childConfigModels;
+ }
+
+ @Override
+ public Collection<ValidationResult> validate(Configuration config) {
+ List<ValidationResult> result = new ArrayList<>(1);
+ for(ConfigModel child: childConfigModels){
+ result.addAll(child.validate(config));
+ }
+ return result;
+ }
+
+ @Override
+ public String toString(){
+ StringBuilder b = new StringBuilder();
+ b.append(getType()).append(", size: ").append(childConfigModels.size()).append(": ").append(getDescription());
+ return b.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
new file mode 100644
index 0000000..717926a
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
@@ -0,0 +1,179 @@
+/*
+ * 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.model.spi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.tamaya.model.ConfigModel;
+
+/**
+ * Utility class to read metamodel information from properties. Hereby these properties can be part of a
+ * configuration (containing other entriees as well) or be dedicated model definition properties read
+ * from any kind of source.
+ */
+public final class ConfigModelReader {
+
+ /** The default model entries selector. */
+ private static final String DEFAULT_META_INFO_SELECTOR = "{model}";
+ /** parameter to change the selector to be used for filtering out the target values to be used. */
+ private static final String META_INFO_SELECTOR_PARAM = "org.apache.tamaya.model.integrated.selector";
+
+ /**
+ * Utility class only.
+ */
+ private ConfigModelReader(){}
+
+ /**
+ * Loads validations as configured in the given properties.
+ * @param props the properties to be read
+ * @param defaultProviderName the default provider name used if no explicit provider name is configured.
+ * @return a collection of config validations.
+ */
+ public static Collection<ConfigModel> loadValidations(Properties props,
+ String defaultProviderName) {
+ Map<String,String> map = new HashMap<>();
+ for(Map.Entry<Object,Object> en: props.entrySet()){
+ map.put(en.getKey().toString(), props.getProperty(en.getKey().toString()));
+ }
+ return loadValidations(map, defaultProviderName);
+ }
+
+ /**
+ * Loads validations as configured in the given properties.
+ * @param props the properties to be read
+ * @param defaultProviderName the default provider name used if no explicit provider name is configured.
+ * @return a collection of config validations.
+ */
+ public static Collection<ConfigModel> loadValidations(Map<String,String> props,
+ String defaultProviderName) {
+ String selector = props.get(META_INFO_SELECTOR_PARAM);
+ if(selector==null){
+ selector = DEFAULT_META_INFO_SELECTOR;
+ }
+ return loadValidations(props, selector, defaultProviderName);
+ }
+
+ /**
+ * Loads validations as configured in the given properties.
+ * @param props the properties to be read
+ * @param selector the selector (default is {model}), that identifies the model entries.
+ * @param defaultProviderName the default provider name used if no explicit provider name is configured.
+ * @return a collection of config validations.
+ */
+ public static Collection<ConfigModel> loadValidations(Map<String,String> props, String selector,
+ String defaultProviderName) {
+ List<ConfigModel> result = new ArrayList<>();
+ String provider = props.get(selector + ".__provider");
+ if (provider == null) {
+ provider = defaultProviderName;
+ }
+ Set<String> itemKeys = new HashSet<>();
+ for (Object key : props.keySet()) {
+ if (key.toString().endsWith(".class")) {
+ itemKeys.add(key.toString().substring(0, key.toString().length() - ".class".length()));
+ }
+ }
+ for (String baseKey : itemKeys) {
+ String clazz = props.get(baseKey + ".class");
+ String type = props.get(baseKey + ".type");
+ if (type == null) {
+ type = String.class.getName();
+ }
+ String value = props.get(baseKey + ".transitive");
+ boolean transitive = false;
+ if(value!=null) {
+ transitive = Boolean.parseBoolean(value);
+ }
+ String description = props.get(baseKey + ".description");
+ String regEx = props.get(baseKey + ".expression");
+ String validations = props.get(baseKey + ".validations");
+ String requiredVal = props.get(baseKey + ".required");
+ if ("Parameter".equalsIgnoreCase(clazz)) {
+ result.add(createParameterValidation(baseKey.substring(selector.length() + 1), description, type,
+ requiredVal, regEx, validations, provider));
+ } else if ("Section".equalsIgnoreCase(clazz)) {
+ if(transitive){
+ result.add(createSectionValidation(baseKey.substring(selector.length() + 1)+".*", description, requiredVal,
+ validations, provider));
+ } else {
+ result.add(createSectionValidation(baseKey.substring(selector.length() + 1), description, requiredVal,
+ validations, provider));
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Creates a parameter validation.
+ * @param paramName the param name, not null.
+ * @param description the optional description
+ * @param type the param type, default is String.
+ * @param reqVal the required value, default is 'false'.
+ * @param regEx an optional regular expression to be checked for this param
+ * @param validations the optional custom validations to be performed.
+ * @return the new validation for this parameter.
+ */
+ private static ConfigModel createParameterValidation(String paramName, String description, String type, String reqVal,
+ String regEx, String validations, String provider) {
+ boolean required = "true".equalsIgnoreCase(reqVal);
+ ParameterModel.Builder builder = ParameterModel.builder(paramName).setRequired(required)
+ .setDescription(description).setExpression(regEx).setType(type).setProvider(provider);
+// if (validations != null) {
+// try {
+// // TODO defined validator API
+//// builder.addValidations(loadValidations(validations));
+// } catch (Exception e) {
+// LOGGER.log(Level.WARNING, "Failed to load validations for " + paramName, e);
+// }
+// }
+ return builder.build();
+ }
+
+ /**
+ * Creates a section validation.
+ * @param sectionName the section's name, not null.
+ * @param description the optional description
+ * @param reqVal the required value, default is 'false'.
+ * @param validations the optional custom validations to be performed.
+ * @return the new validation for this section.
+ */
+ private static ConfigModel createSectionValidation(String sectionName, String description, String reqVal,
+ String validations, String provider) {
+ boolean required = "true".equalsIgnoreCase(reqVal);
+ AreaConfigModel.Builder builder = AreaConfigModel.builder(sectionName).setRequired(required)
+ .setDescription(description).setProvider(provider);
+// if (validations != null) {
+// try {
+// // TODO defined validator API
+//// builder.addValidations(loadValidations(valiadtions));
+// } catch (Exception e) {
+// LOGGER.log(Level.WARNING, "Failed to load validations for " + sectionName, e);
+// }
+// }
+ return builder.build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigValidationsReader.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigValidationsReader.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigValidationsReader.java
deleted file mode 100644
index e735286..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigValidationsReader.java
+++ /dev/null
@@ -1,179 +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.model.spi;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.tamaya.model.Validation;
-
-/**
- * Utility class to read metamodel information from properties. Hereby these properties can be part of a
- * configuration (containing other entriees as well) or be dedicated model definition properties read
- * from any kind of source.
- */
-public final class ConfigValidationsReader {
-
- /** The default model entries selector. */
- private static final String DEFAULT_META_INFO_SELECTOR = "{model}";
- /** parameter to change the selector to be used for filtering out the target values to be used. */
- private static final String META_INFO_SELECTOR_PARAM = "org.apache.tamaya.model.integrated.selector";
-
- /**
- * Utility class only.
- */
- private ConfigValidationsReader(){}
-
- /**
- * Loads validations as configured in the given properties.
- * @param props the properties to be read
- * @param defaultProviderName the default provider name used if no explicit provider name is configured.
- * @return a collection of config validations.
- */
- public static Collection<Validation> loadValidations(Properties props,
- String defaultProviderName) {
- Map<String,String> map = new HashMap<>();
- for(Map.Entry<Object,Object> en: props.entrySet()){
- map.put(en.getKey().toString(), props.getProperty(en.getKey().toString()));
- }
- return loadValidations(map, defaultProviderName);
- }
-
- /**
- * Loads validations as configured in the given properties.
- * @param props the properties to be read
- * @param defaultProviderName the default provider name used if no explicit provider name is configured.
- * @return a collection of config validations.
- */
- public static Collection<Validation> loadValidations(Map<String,String> props,
- String defaultProviderName) {
- String selector = props.get(META_INFO_SELECTOR_PARAM);
- if(selector==null){
- selector = DEFAULT_META_INFO_SELECTOR;
- }
- return loadValidations(props, selector, defaultProviderName);
- }
-
- /**
- * Loads validations as configured in the given properties.
- * @param props the properties to be read
- * @param selector the selector (default is {model}), that identifies the model entries.
- * @param defaultProviderName the default provider name used if no explicit provider name is configured.
- * @return a collection of config validations.
- */
- public static Collection<Validation> loadValidations(Map<String,String> props, String selector,
- String defaultProviderName) {
- List<Validation> result = new ArrayList<>();
- String provider = props.get(selector + ".__provider");
- if (provider == null) {
- provider = defaultProviderName;
- }
- Set<String> itemKeys = new HashSet<>();
- for (Object key : props.keySet()) {
- if (key.toString().endsWith(".class")) {
- itemKeys.add(key.toString().substring(0, key.toString().length() - ".class".length()));
- }
- }
- for (String baseKey : itemKeys) {
- String clazz = props.get(baseKey + ".class");
- String type = props.get(baseKey + ".type");
- if (type == null) {
- type = String.class.getName();
- }
- String value = props.get(baseKey + ".transitive");
- boolean transitive = false;
- if(value!=null) {
- transitive = Boolean.parseBoolean(value);
- }
- String description = props.get(baseKey + ".description");
- String regEx = props.get(baseKey + ".expression");
- String validations = props.get(baseKey + ".validations");
- String requiredVal = props.get(baseKey + ".required");
- if ("Parameter".equalsIgnoreCase(clazz)) {
- result.add(createParameterValidation(baseKey.substring(selector.length() + 1), description, type,
- requiredVal, regEx, validations, provider));
- } else if ("Section".equalsIgnoreCase(clazz)) {
- if(transitive){
- result.add(createSectionValidation(baseKey.substring(selector.length() + 1)+".*", description, requiredVal,
- validations, provider));
- } else {
- result.add(createSectionValidation(baseKey.substring(selector.length() + 1), description, requiredVal,
- validations, provider));
- }
- }
- }
- return result;
- }
-
- /**
- * Creates a parameter validation.
- * @param paramName the param name, not null.
- * @param description the optional description
- * @param type the param type, default is String.
- * @param reqVal the required value, default is 'false'.
- * @param regEx an optional regular expression to be checked for this param
- * @param validations the optional custom validations to be performed.
- * @return the new validation for this parameter.
- */
- private static Validation createParameterValidation(String paramName, String description, String type, String reqVal,
- String regEx, String validations, String provider) {
- boolean required = "true".equalsIgnoreCase(reqVal);
- ParameterValidation.Builder builder = ParameterValidation.builder(paramName).setRequired(required)
- .setDescription(description).setExpression(regEx).setType(type).setProvider(provider);
-// if (validations != null) {
-// try {
-// // TODO defined validator API
-//// builder.addValidations(loadValidations(validations));
-// } catch (Exception e) {
-// LOGGER.log(Level.WARNING, "Failed to load validations for " + paramName, e);
-// }
-// }
- return builder.build();
- }
-
- /**
- * Creates a section validation.
- * @param sectionName the section's name, not null.
- * @param description the optional description
- * @param reqVal the required value, default is 'false'.
- * @param validations the optional custom validations to be performed.
- * @return the new validation for this section.
- */
- private static Validation createSectionValidation(String sectionName, String description, String reqVal,
- String validations, String provider) {
- boolean required = "true".equalsIgnoreCase(reqVal);
- AreaValidation.Builder builder = AreaValidation.builder(sectionName).setRequired(required)
- .setDescription(description).setProvider(provider);
-// if (validations != null) {
-// try {
-// // TODO defined validator API
-//// builder.addValidations(loadValidations(valiadtions));
-// } catch (Exception e) {
-// LOGGER.log(Level.WARNING, "Failed to load validations for " + sectionName, e);
-// }
-// }
- return builder.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ModelProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ModelProviderSpi.java
new file mode 100644
index 0000000..01c0979
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/ModelProviderSpi.java
@@ -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 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.model.spi;
+
+import org.apache.tamaya.model.ConfigModel;
+
+import java.util.Collection;
+
+/**
+ * Model of a configuration state. A model can be a full model, or a partial model, validating only
+ * a configuration subset. This allows better user feedback because big configurations can be grouped
+ * and validated by multiple (partial) models.
+ */
+public interface ModelProviderSpi {
+
+ /**
+ * Get the validation defined.
+ *
+ * @return the sections defined, never null.
+ */
+ Collection<ConfigModel> getConfigModels();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ParameterModel.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ParameterModel.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ParameterModel.java
new file mode 100644
index 0000000..504723f
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/ParameterModel.java
@@ -0,0 +1,236 @@
+/*
+ * 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.model.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.ModelType;
+import org.apache.tamaya.model.ValidationResult;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default configuration Model for a configuration parameter.
+ */
+public class ParameterModel extends AbstractModel {
+ /** Optional regular expression for validating the value. */
+ private String regEx;
+ /** The target type into which the value must be convertible. */
+ private Class<?> type;
+
+ /**
+ * Internal constructor.
+ * @param builder the builder, not null.
+ */
+ protected ParameterModel(Builder builder) {
+ super(builder.name, builder.required, builder.description, builder.provider);
+ this.regEx = builder.regEx;
+ this.type = builder.type;
+ }
+
+ @Override
+ public ModelType getType() {
+ return ModelType.Parameter;
+ }
+
+ /**
+ * Get the required parameter type.
+ *
+ * @return the type.
+ */
+ public Class<?> getParameterType() {
+ return type;
+ }
+
+ @Override
+ public Collection<ValidationResult> validate(Configuration config) {
+ List<ValidationResult> result = new ArrayList<>(1);
+ String configValue = config.get(getName());
+ if (configValue == null && isRequired()) {
+ result.add(ValidationResult.ofMissing(this));
+ }
+ if (configValue != null && regEx != null) {
+ if (!configValue.matches(regEx)) {
+ result.add(ValidationResult.ofError(this, "Config value not matching expression: " + regEx + ", was " +
+ configValue));
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append(getType()).append(": ").append(getName());
+ if (isRequired()) {
+ b.append(", required: " + isRequired());
+ }
+ if (regEx != null) {
+ b.append(", expression: " + regEx);
+ }
+ return b.toString();
+ }
+
+ /**
+ * Creates a new Builder instance.
+ * @param name the fully qualified parameter name.
+ * @return
+ */
+ public static Builder builder(String name) {
+ return new Builder(name);
+ }
+
+ /**
+ * Creates a new ConfigModel
+ * @param name the fully qualified parameter name.
+ * @param required the required flag.
+ * @param expression an optional regular expression to validate a value.
+ * @return the new ConfigModel instance.
+ */
+ public static ConfigModel of(String name, boolean required, String expression) {
+ return new Builder(name).setRequired(required).setExpression(expression).build();
+ }
+
+ /**
+ * Creates a new ConfigModel
+ * @param name the fully qualified parameter name.
+ * @param required the required flag.
+ * @return the new ConfigModel instance.
+ */
+ public static ConfigModel of(String name, boolean required) {
+ return new Builder(name).setRequired(required).build();
+ }
+
+ /**
+ * Creates a new ConfigModel. The parameter will be defined as optional.
+ * @param name the fully qualified parameter name.
+ * @return the new ConfigModel instance.
+ */
+ public static ConfigModel of(String name) {
+ return new Builder(name).setRequired(false).build();
+ }
+
+
+ /**
+ * A new Builder for creating ParameterModel instances.
+ */
+ public static class Builder {
+ /** The parameter's target type. */
+ private Class<?> type;
+ /** The fully qualified parameter name. */
+ private String name;
+ /** The optional provider. */
+ private String provider;
+ /** The optional validation expression. */
+ private String regEx;
+ /** The optional description. */
+ private String description;
+ /** The required flag. */
+ private boolean required;
+
+ /**
+ * Creates a new Builder.
+ * @param name the fully qualified parameter name, not null.
+ */
+ public Builder(String name) {
+ this.name = Objects.requireNonNull(name);
+ }
+
+ /**
+ * Sets the target type.
+ * @param type the type, not null.
+ * @return the Builder for chaining
+ */
+ public Builder setType(String type) {
+ try {
+ this.type = Class.forName(type);
+ } catch (ClassNotFoundException e) {
+ try {
+ this.type = Class.forName("java.lang."+type);
+ } catch (ClassNotFoundException e2) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to load parameter type: " + type, e2);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Sets the required flag.
+ * @param required the required flag.
+ * @return the Builder for chaining
+ */
+ public Builder setRequired(boolean required) {
+ this.required = required;
+ return this;
+ }
+
+ /**
+ * Sets the optional description
+ * @param description the description
+ * @return the Builder for chaining
+ */
+ public Builder setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ /**
+ * Sets the optional validation expression
+ * @param expression the validation expression
+ * @return the Builder for chaining
+ */
+ public Builder setExpression(String expression) {
+ this.regEx = expression;
+ return this;
+ }
+
+ /**
+ * Sets the fully qualified parameter name.
+ * @param name the fully qualified parameter name, not null.
+ * @return the Builder for chaining
+ */
+ public Builder setName(String name) {
+ this.name = Objects.requireNonNull(name);
+ return this;
+ }
+
+ /**
+ * Set the provider.
+ * @param provider the provider.
+ * @return the Builder for chaining
+ */
+ public Builder setProvider(String provider) {
+ this.provider = provider;
+ return this;
+ }
+
+ /**
+ * Creates a new ConfigModel with the given parameters.
+ * @return a new ConfigModel , never null.
+ */
+ public ConfigModel build() {
+ return new ParameterModel(this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ParameterValidation.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ParameterValidation.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ParameterValidation.java
deleted file mode 100644
index a8ac17d..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/ParameterValidation.java
+++ /dev/null
@@ -1,236 +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.model.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.model.Validation;
-import org.apache.tamaya.model.ValidationResult;
-import org.apache.tamaya.model.ValidationType;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Default configuration Model for a configuration parameter.
- */
-public class ParameterValidation extends AbstractValidation {
- /** Optional regular expression for validating the value. */
- private String regEx;
- /** The target type into which the value must be convertible. */
- private Class<?> type;
-
- /**
- * Internal constructor.
- * @param builder the builder, not null.
- */
- protected ParameterValidation(Builder builder) {
- super(builder.name, builder.required, builder.description, builder.provider);
- this.regEx = builder.regEx;
- this.type = builder.type;
- }
-
- @Override
- public ValidationType getType() {
- return ValidationType.Parameter;
- }
-
- /**
- * Get the required parameter type.
- *
- * @return the type.
- */
- public Class<?> getParameterType() {
- return type;
- }
-
- @Override
- public Collection<ValidationResult> validate(Configuration config) {
- List<ValidationResult> result = new ArrayList<>(1);
- String configValue = config.get(getName());
- if (configValue == null && isRequired()) {
- result.add(ValidationResult.ofMissing(this));
- }
- if (configValue != null && regEx != null) {
- if (!configValue.matches(regEx)) {
- result.add(ValidationResult.ofError(this, "Config value not matching expression: " + regEx + ", was " +
- configValue));
- }
- }
- return result;
- }
-
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder();
- b.append(getType()).append(": ").append(getName());
- if (isRequired()) {
- b.append(", required: " + isRequired());
- }
- if (regEx != null) {
- b.append(", expression: " + regEx);
- }
- return b.toString();
- }
-
- /**
- * Creates a new Builder instance.
- * @param name the fully qualified parameter name.
- * @return
- */
- public static Builder builder(String name) {
- return new Builder(name);
- }
-
- /**
- * Creates a new Validation
- * @param name the fully qualified parameter name.
- * @param required the required flag.
- * @param expression an optional regular expression to validate a value.
- * @return the new Validation instance.
- */
- public static Validation of(String name, boolean required, String expression) {
- return new Builder(name).setRequired(required).setExpression(expression).build();
- }
-
- /**
- * Creates a new Validation
- * @param name the fully qualified parameter name.
- * @param required the required flag.
- * @return the new Validation instance.
- */
- public static Validation of(String name, boolean required) {
- return new Builder(name).setRequired(required).build();
- }
-
- /**
- * Creates a new Validation. The parameter will be defined as optional.
- * @param name the fully qualified parameter name.
- * @return the new Validation instance.
- */
- public static Validation of(String name) {
- return new Builder(name).setRequired(false).build();
- }
-
-
- /**
- * A new Builder for creating ParameterValidation instances.
- */
- public static class Builder {
- /** The parameter's target type. */
- private Class<?> type;
- /** The fully qualified parameter name. */
- private String name;
- /** The optional provider. */
- private String provider;
- /** The optional validation expression. */
- private String regEx;
- /** The optional description. */
- private String description;
- /** The required flag. */
- private boolean required;
-
- /**
- * Creates a new Builder.
- * @param name the fully qualified parameter name, not null.
- */
- public Builder(String name) {
- this.name = Objects.requireNonNull(name);
- }
-
- /**
- * Sets the target type.
- * @param type the type, not null.
- * @return the Builder for chaining
- */
- public Builder setType(String type) {
- try {
- this.type = Class.forName(type);
- } catch (ClassNotFoundException e) {
- try {
- this.type = Class.forName("java.lang."+type);
- } catch (ClassNotFoundException e2) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to load parameter type: " + type, e2);
- }
- }
- return this;
- }
-
- /**
- * Sets the required flag.
- * @param required the required flag.
- * @return the Builder for chaining
- */
- public Builder setRequired(boolean required) {
- this.required = required;
- return this;
- }
-
- /**
- * Sets the optional description
- * @param description the description
- * @return the Builder for chaining
- */
- public Builder setDescription(String description) {
- this.description = description;
- return this;
- }
-
- /**
- * Sets the optional validation expression
- * @param expression the validation expression
- * @return the Builder for chaining
- */
- public Builder setExpression(String expression) {
- this.regEx = expression;
- return this;
- }
-
- /**
- * Sets the fully qualified parameter name.
- * @param name the fully qualified parameter name, not null.
- * @return the Builder for chaining
- */
- public Builder setName(String name) {
- this.name = Objects.requireNonNull(name);
- return this;
- }
-
- /**
- * Set the provider.
- * @param provider the provider.
- * @return the Builder for chaining
- */
- public Builder setProvider(String provider) {
- this.provider = provider;
- return this;
- }
-
- /**
- * Creates a new Validation with the given parameters.
- * @return a new Validation , never null.
- */
- public Validation build() {
- return new ParameterValidation(this);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ValidationGroup.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ValidationGroup.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ValidationGroup.java
deleted file mode 100644
index baa39bd..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/ValidationGroup.java
+++ /dev/null
@@ -1,112 +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.model.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.model.Validation;
-import org.apache.tamaya.model.ValidationResult;
-import org.apache.tamaya.model.ValidationType;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Default configuration Model for a configuration area.
- */
-public class ValidationGroup implements Validation {
-
- private String name;
- private boolean required;
- private String provider;
- private List<Validation> childValidations = new ArrayList<>();
-
- public ValidationGroup(String name, String provider, Validation... validations){
- this(name, provider, Arrays.asList(validations));
- }
-
- public ValidationGroup(String name, String provider, Collection<Validation> validations){
- this.name = Objects.requireNonNull(name);
- this.provider = provider;
- this.childValidations.addAll(validations);
- this.childValidations = Collections.unmodifiableList(childValidations);
- for(Validation val:validations) {
- if(val.isRequired()){
- this.required = true;
- break;
- }
- }
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getProvider() {
- return provider;
- }
-
- @Override
- public boolean isRequired() {
- return required;
- }
-
- @Override
- public ValidationType getType() {
- return ValidationType.Group;
- }
-
- @Override
- public String getDescription() {
- if(childValidations.isEmpty()){
- return null;
- }
- StringBuilder b = new StringBuilder();
- for(Validation val:childValidations){
- b.append(" >> " + val);
- }
- return b.toString();
- }
-
- public Collection<Validation> getValidations(){
- return childValidations;
- }
-
- @Override
- public Collection<ValidationResult> validate(Configuration config) {
- List<ValidationResult> result = new ArrayList<>(1);
- for(Validation child: childValidations){
- result.addAll(child.validate(config));
- }
- return result;
- }
-
- @Override
- public String toString(){
- StringBuilder b = new StringBuilder();
- b.append(getType()).append(", size: ").append(childValidations.size()).append(": ").append(getDescription());
- return b.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/ValidationProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ValidationProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ValidationProviderSpi.java
deleted file mode 100644
index edb795c..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/ValidationProviderSpi.java
+++ /dev/null
@@ -1,39 +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.model.spi;
-
-import org.apache.tamaya.model.Validation;
-
-import java.util.Collection;
-
-/**
- * Model of a configuration state. A model can be a full model, or a partial model, validating only
- * a configuration subset. This allows better user feedback because big configurations can be grouped
- * and validated by multiple (partial) models.
- */
-public interface ValidationProviderSpi {
-
- /**
- * Get the validation defined.
- *
- * @return the sections defined, never null.
- */
- Collection<Validation> getValidations();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener
----------------------------------------------------------------------
diff --git a/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener b/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener
new file mode 100644
index 0000000..e8b12e9
--- /dev/null
+++ b/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.tamaya.model.internal.ConfiguredTypeEventsModelPopulator
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
----------------------------------------------------------------------
diff --git a/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi b/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
new file mode 100644
index 0000000..b394c17
--- /dev/null
+++ b/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+org.apache.tamaya.model.internal.ConfiguredPropertiesModelProviderSpi
+org.apache.tamaya.model.internal.ConfiguredInlineModelProviderSpi
+org.apache.tamaya.model.internal.ConfiguredResourcesModelProviderSpi
+org.apache.tamaya.model.internal.ConfiguredTypeEventsModelProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
----------------------------------------------------------------------
diff --git a/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi b/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
deleted file mode 100644
index 47c18de..0000000
--- a/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
+++ /dev/null
@@ -1,21 +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.
-#
-org.apache.tamaya.model.internal.ConfiguredPropertiesValidationProviderSpi
-org.apache.tamaya.model.internal.ConfiguredInlineModelProviderSpi
-org.apache.tamaya.model.internal.ConfiguredResourcesModelProviderSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
----------------------------------------------------------------------
diff --git a/modules/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java b/modules/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
new file mode 100644
index 0000000..f1f09a1
--- /dev/null
+++ b/modules/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
@@ -0,0 +1,65 @@
+/*
+ * 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.model;
+
+import org.apache.tamaya.model.spi.AreaConfigModel;
+import org.apache.tamaya.model.spi.ParameterModel;
+import org.apache.tamaya.model.spi.ConfigModelGroup;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created by Anatole on 09.08.2015.
+ */
+public class TestConfigModelProvider implements ModelProviderSpi {
+
+ private List<ConfigModel> configModels = new ArrayList<>(1);
+
+ public TestConfigModelProvider(){
+ configModels.add(new TestConfigConfigModel());
+ configModels = Collections.unmodifiableList(configModels);
+ }
+
+ public Collection<ConfigModel> getConfigModels() {
+ return configModels;
+ }
+
+ private static final class TestConfigConfigModel extends ConfigModelGroup {
+
+ public TestConfigConfigModel(){
+ super("TestConfig", "test", new AreaConfigModel.Builder("a.test.existing").setRequired(true).build(),
+ ParameterModel.of("a.test.existing.aParam", true),
+ ParameterModel.of("a.test.existing.optionalParam"),
+ ParameterModel.of("a.test.existing.aABCParam", false, "[ABC].*"),
+ new AreaConfigModel.Builder("a.test.notexisting").setRequired(true).build(),
+ ParameterModel.of("a.test.notexisting.aParam", true),
+ ParameterModel.of("a.test.notexisting.optionalParam"),
+ ParameterModel.of("a.test.existing.aABCParam2", false, "[ABC].*"));
+ }
+ @Override
+ public String getName() {
+ return "TestConfigConfigModel";
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/java/org/apache/tamaya/model/TestConfigValidationProvider.java
----------------------------------------------------------------------
diff --git a/modules/model/src/test/java/org/apache/tamaya/model/TestConfigValidationProvider.java b/modules/model/src/test/java/org/apache/tamaya/model/TestConfigValidationProvider.java
deleted file mode 100644
index b923ed3..0000000
--- a/modules/model/src/test/java/org/apache/tamaya/model/TestConfigValidationProvider.java
+++ /dev/null
@@ -1,66 +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.model;
-
-import org.apache.tamaya.model.spi.AreaValidation;
-import org.apache.tamaya.model.spi.ParameterValidation;
-import org.apache.tamaya.model.spi.ValidationGroup;
-import org.apache.tamaya.model.spi.ValidationProviderSpi;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Created by Anatole on 09.08.2015.
- */
-public class TestConfigValidationProvider implements ValidationProviderSpi{
-
- private List<Validation> validations = new ArrayList<>(1);
-
- public TestConfigValidationProvider(){
- validations.add(new TestConfigValidation());
- validations = Collections.unmodifiableList(validations);
- }
-
- @Override
- public Collection<Validation> getValidations() {
- return validations;
- }
-
- private static final class TestConfigValidation extends ValidationGroup{
-
- public TestConfigValidation(){
- super("TestConfig", "test", new AreaValidation.Builder("a.test.existing").setRequired(true).build(),
- ParameterValidation.of("a.test.existing.aParam", true),
- ParameterValidation.of("a.test.existing.optionalParam"),
- ParameterValidation.of("a.test.existing.aABCParam", false, "[ABC].*"),
- new AreaValidation.Builder("a.test.notexisting").setRequired(true).build(),
- ParameterValidation.of("a.test.notexisting.aParam", true),
- ParameterValidation.of("a.test.notexisting.optionalParam"),
- ParameterValidation.of("a.test.existing.aABCParam2", false, "[ABC].*"));
- }
- @Override
- public String getName() {
- return "TestConfigValidation";
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/java/org/apache/tamaya/model/ValidationTests.java
----------------------------------------------------------------------
diff --git a/modules/model/src/test/java/org/apache/tamaya/model/ValidationTests.java b/modules/model/src/test/java/org/apache/tamaya/model/ValidationTests.java
index 53496ea..2b25b21 100644
--- a/modules/model/src/test/java/org/apache/tamaya/model/ValidationTests.java
+++ b/modules/model/src/test/java/org/apache/tamaya/model/ValidationTests.java
@@ -27,16 +27,16 @@ public class ValidationTests {
@Test
public void testDefaults(){
- System.err.println(ConfigValidator.validate());
+ System.err.println(ConfigModelManager.validate());
}
@Test
public void testAllValidations(){
- System.err.println(ConfigValidator.getValidations());
+ System.err.println(ConfigModelManager.getModels());
}
@Test
public void testAllValidationsInclUndefined(){
- System.err.println("Including UNDEFINED: \n" + ConfigValidator.validate(true));
+ System.err.println("Including UNDEFINED: \n" + ConfigModelManager.validate(true));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
----------------------------------------------------------------------
diff --git a/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java b/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
index 4763a01..61557b8 100644
--- a/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
+++ b/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.model.internal;
-import org.apache.tamaya.model.ValidationType;
+import org.apache.tamaya.model.ModelType;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
@@ -73,7 +73,7 @@ public class ConfigDocumentationBeanTest {
@Test
public void testGetConfigurationModel_WithSection() throws Exception {
- String results = mbean.getConfigurationModel(ValidationType.Parameter);
+ String results = mbean.getConfigurationModel(ModelType.Parameter);
assertNotNull(results);
assertFalse(results.trim().isEmpty());
assertTrue(results.contains("\"type\":\"Parameter\""));
@@ -92,12 +92,12 @@ public class ConfigDocumentationBeanTest {
@Test
public void testFindValidationModels() throws Exception {
- String results = mbean.findValidationModels(ValidationType.Section, "a");
+ String results = mbean.findValidationModels(ModelType.Section, "a");
assertNotNull(results);
assertFalse(results.trim().isEmpty());
assertFalse(results.contains("\"type\":\"Parameter\""));
assertTrue(results.contains("\"type\":\"Section\""));
- results = mbean.findValidationModels(ValidationType.CombinationPolicy, "a");
+ results = mbean.findValidationModels(ModelType.CombinationPolicy, "a");
assertFalse(results.trim().isEmpty());
assertFalse(results.contains("\"type\":\"Parameter\""));
assertFalse(results.contains("\"type\":\"Section\""));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/resources/META-INF/configmodel.properties
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/META-INF/configmodel.properties b/modules/model/src/test/resources/META-INF/configmodel.properties
index af37705..4561f3f 100644
--- a/modules/model/src/test/resources/META-INF/configmodel.properties
+++ b/modules/model/src/test/resources/META-INF/configmodel.properties
@@ -89,7 +89,7 @@
# a.b.c.aValidatedSection (section)
{model}.a.b.c.aValidatedSection.class=Section
{model}.a.b.c.aValidatedSection.description=A validated section.
-{model}.a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator
+{model}.a.b.c.aValidatedSection.configModels=org.apache.tamaya.model.TestValidator
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi b/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
new file mode 100644
index 0000000..e2d3350
--- /dev/null
+++ b/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.tamaya.model.TestConfigModelProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi b/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
deleted file mode 100644
index 45c1b86..0000000
--- a/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
+++ /dev/null
@@ -1,19 +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.
-#
-org.apache.tamaya.model.TestConfigValidationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/resources/examples/configmodel.ini
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/examples/configmodel.ini b/modules/model/src/test/resources/examples/configmodel.ini
index ec4070c..0f37807 100644
--- a/modules/model/src/test/resources/examples/configmodel.ini
+++ b/modules/model/src/test/resources/examples/configmodel.ini
@@ -68,8 +68,8 @@ class = Section
[{model}a.b.c.aValidatedSection]
class = Section
-description = "A validation section."
-validations = org.apache.tamaya.model.TestValidator?max=3
+description = "A configModel section."
+configModels = org.apache.tamaya.model.TestValidator?max=3
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/resources/examples/configmodel.properties
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/examples/configmodel.properties b/modules/model/src/test/resources/examples/configmodel.properties
index 4e69549..da0a275 100644
--- a/modules/model/src/test/resources/examples/configmodel.properties
+++ b/modules/model/src/test/resources/examples/configmodel.properties
@@ -89,7 +89,7 @@
# a.b.c.aValidatedSection (section)
{model}.a.b.c.aValidatedSection.class=Section
{model}.a.b.c.aValidatedSection.description=A validated section.
-{model}.a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator
+{model}.a.b.c.aValidatedSection.configModels=org.apache.tamaya.model.TestValidator
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/resources/examples/configmodel.xml
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/examples/configmodel.xml b/modules/model/src/test/resources/examples/configmodel.xml
index dd78c05..f23f783 100644
--- a/modules/model/src/test/resources/examples/configmodel.xml
+++ b/modules/model/src/test/resources/examples/configmodel.xml
@@ -90,8 +90,8 @@ under the License.
</section>
<section name="a.b.c.aRequiredSection.optional-subsection"/>
<section name="a.b.c.aRequiredSection.aValidatedSection">
- <validations>org.apache.tamaya.model.validation.MaxItemValidator?max=3"</validations>
- <description>A validation section.</description>
+ <configModels>org.apache.tamaya.model.configModel.MaxItemValidator?max=3"</configModels>
+ <description>A configModel section.</description>
</section>
</section>
</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/test/resources/examples/configmodel.yaml
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/examples/configmodel.yaml b/modules/model/src/test/resources/examples/configmodel.yaml
index a59246a..041c801 100644
--- a/modules/model/src/test/resources/examples/configmodel.yaml
+++ b/modules/model/src/test/resources/examples/configmodel.yaml
@@ -99,8 +99,8 @@
---
{model}.a.b.c.aRequiredSection.aValidatedSection: {
- description: 'A validation section.',
- validations: 'org.apache.tamaya.model.validation.MaxItemValidator?max=3'
+ description: 'A configModel section.',
+ configModels: 'org.apache.tamaya.model.configModel.MaxItemValidator?max=3'
}
[5/6] incubator-tamaya git commit: Refactored model module a bit so
it was possible to move some logic from the injection modules into this
module. Effectively decoupling was modelled by adding a ConfiguredTypeEvent,
which is used to implicitly populate
Posted by an...@apache.org.
Refactored model module a bit so it was possible to move some logic from the injection modules into this module. Effectively decoupling was modelled by adding a ConfiguredTypeEvent, which is used to implicitly populate the configuration models on system load.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/8f2a689d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/8f2a689d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/8f2a689d
Branch: refs/heads/master
Commit: 8f2a689da926a67bb92a6d74a48577277f51a893
Parents: 4f3d4be
Author: anatole <an...@apache.org>
Authored: Mon Nov 30 08:45:27 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Nov 30 08:45:27 2015 +0100
----------------------------------------------------------------------
.../internal/InjectableValidationProvider.java | 46 ----
modules/model/pom.xml | 20 +-
.../org/apache/tamaya/model/ConfigModel.java | 78 ++++++
.../apache/tamaya/model/ConfigModelManager.java | 239 +++++++++++++++++++
.../apache/tamaya/model/ConfigValidator.java | 239 -------------------
.../java/org/apache/tamaya/model/ModelType.java | 49 ++++
.../org/apache/tamaya/model/Validation.java | 78 ------
.../apache/tamaya/model/ValidationResult.java | 88 +++----
.../org/apache/tamaya/model/ValidationType.java | 49 ----
.../model/internal/ConfigDocumentationBean.java | 48 ++--
.../ConfiguredInlineModelProviderSpi.java | 23 +-
.../ConfiguredPropertiesModelProviderSpi.java | 152 ++++++++++++
...nfiguredPropertiesValidationProviderSpi.java | 153 ------------
.../ConfiguredResourcesModelProviderSpi.java | 23 +-
.../ConfiguredTypeEventsModelPopulator.java | 76 ++++++
.../ConfiguredTypeEventsModelProvider.java | 51 ++++
.../apache/tamaya/model/spi/AbstractModel.java | 89 +++++++
.../tamaya/model/spi/AbstractValidation.java | 89 -------
.../tamaya/model/spi/AreaConfigModel.java | 204 ++++++++++++++++
.../apache/tamaya/model/spi/AreaValidation.java | 204 ----------------
.../model/spi/ConfigDocumentationMBean.java | 8 +-
.../tamaya/model/spi/ConfigModelGroup.java | 112 +++++++++
.../tamaya/model/spi/ConfigModelReader.java | 179 ++++++++++++++
.../model/spi/ConfigValidationsReader.java | 179 --------------
.../tamaya/model/spi/ModelProviderSpi.java | 39 +++
.../apache/tamaya/model/spi/ParameterModel.java | 236 ++++++++++++++++++
.../tamaya/model/spi/ParameterValidation.java | 236 ------------------
.../tamaya/model/spi/ValidationGroup.java | 112 ---------
.../tamaya/model/spi/ValidationProviderSpi.java | 39 ---
...org.apache.tamaya.events.ConfigEventListener | 19 ++
...org.apache.tamaya.model.spi.ModelProviderSpi | 22 ++
...pache.tamaya.model.spi.ValidationProviderSpi | 21 --
.../tamaya/model/TestConfigModelProvider.java | 65 +++++
.../model/TestConfigValidationProvider.java | 66 -----
.../apache/tamaya/model/ValidationTests.java | 6 +-
.../internal/ConfigDocumentationBeanTest.java | 8 +-
.../resources/META-INF/configmodel.properties | 2 +-
...org.apache.tamaya.model.spi.ModelProviderSpi | 19 ++
...pache.tamaya.model.spi.ValidationProviderSpi | 19 --
.../src/test/resources/examples/configmodel.ini | 4 +-
.../resources/examples/configmodel.properties | 2 +-
.../src/test/resources/examples/configmodel.xml | 4 +-
.../test/resources/examples/configmodel.yaml | 4 +-
43 files changed, 1754 insertions(+), 1645 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectableValidationProvider.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectableValidationProvider.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectableValidationProvider.java
deleted file mode 100644
index 0761492..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectableValidationProvider.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.internal;
-
-import org.apache.tamaya.model.Validation;
-import org.apache.tamaya.model.spi.ValidationProviderSpi;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Created by Anatole on 19.08.2015.
- */
-public class InjectableValidationProvider implements ValidationProviderSpi{
-
- private static Collection<Validation> validations = new ArrayList<>();
-
- static void addValidation(Validation validation){
- List<Validation> newList = new ArrayList<>(validations);
- newList.add(validation);
- InjectableValidationProvider.validations = newList;
- }
-
- @Override
- public Collection<Validation> getValidations() {
- return Collections.unmodifiableCollection(validations);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/pom.xml
----------------------------------------------------------------------
diff --git a/modules/model/pom.xml b/modules/model/pom.xml
index b92aa6b..7bab7ac 100644
--- a/modules/model/pom.xml
+++ b/modules/model/pom.xml
@@ -43,25 +43,37 @@ under the License.
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-api</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-injection-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-formats</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-events</artifactId>
+ <version>${project.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-json</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>${project.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
new file mode 100644
index 0000000..0c24e1c
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
@@ -0,0 +1,78 @@
+/*
+ * 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.model;
+
+import org.apache.tamaya.Configuration;
+
+import java.util.Collection;
+
+/**
+ * Basis structure describing a validated item, by default a parameter or a section.
+ */
+public interface ConfigModel {
+
+
+ /**
+ * Get the type of item that is modelled..
+ * @return the modelled type, never null.
+ */
+ ModelType getType();
+
+ /**
+ * Get the item's name, it should minimally describe the validation. Examples are:
+ * <pre>
+ * Sections: a.b.c
+ * Params: a.b.c.paramName
+ * Filter: a.b.c.FilterImplClass
+ * Dependency: mydepClassname
+ * CombinationPolicy: a.b.c.MyCombinationPolicyClass
+ * </pre>
+ */
+ String getName();
+
+ /**
+ * CHeck if this validation is a required one.
+ * @return true, if this validation is required.
+ */
+ boolean isRequired();
+
+ /**
+ * Get the provider of this validation.
+ * @return the provider.
+ */
+ String getProvider();
+
+ /**
+ * Get an description of the item, using the default locale. The description is basically optional
+ * though it is higly recommended to provide a description, so the validation issues is well
+ * resolvable.
+ *
+ * @return the description required, or null.
+ */
+ String getDescription();
+
+ /**
+ * Validates the item and all its children against the given configuration.
+ *
+ * @param config the configuration to be validated against, not null.
+ * @return the validation results, never null.
+ */
+ Collection<ValidationResult> validate(Configuration config);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
new file mode 100644
index 0000000..18b6b98
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
@@ -0,0 +1,239 @@
+/*
+ * 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.model;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.model.spi.ConfigDocumentationMBean;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Validator accessor to validate the current configuration.
+ */
+public final class ConfigModelManager {
+
+ /** The logger used. */
+ private final static Logger LOG = Logger.getLogger(ConfigModelManager.class.getName());
+
+ /**
+ * Singleton constructor.
+ */
+ private ConfigModelManager() {
+ }
+
+ /**
+ * Get the validations defined.
+ *
+ * @return the sections defined, never null.
+ */
+ public static Collection<ConfigModel> getModels() {
+ List<ConfigModel> result = new ArrayList<>();
+ for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class)) {
+ result.addAll(model.getConfigModels());
+ }
+ return result;
+ }
+
+ /**
+ * Find the validations by checking the validation's name using the given regular expression.
+ * @param type the target ModelType, not null.
+ * @param namePattern the regular expression to use, not null.
+ * @return the sections defined, never null.
+ */
+ public static Collection<ConfigModel> findModels(ModelType type, String namePattern) {
+ List<ConfigModel> result = new ArrayList<>();
+ for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class)) {
+ for(ConfigModel configModel : model.getConfigModels()) {
+ if(configModel.getName().matches(namePattern) && configModel.getType()==type) {
+ result.add(configModel);
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Find the validations by checking the validation's name using the given regular expression.
+ * @param name the name to use, not null.
+ * @return the sections defined, never null.
+ */
+ public static <T extends ConfigModel> T getModel(String name, Class<T> validationType) {
+ for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class)) {
+ for(ConfigModel configModel : model.getConfigModels()) {
+ if(configModel.getName().equals(name) && configModel.getClass().equals(validationType)) {
+ return validationType.cast(configModel);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find the validations by checking the validation's name using the given regular expression.
+ * @param namePattern the regular expression to use, not null.
+ * @return the sections defined, never null.
+ */
+ public static Collection<ConfigModel> findModels(String namePattern) {
+ List<ConfigModel> result = new ArrayList<>();
+ for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class)) {
+ for(ConfigModel configModel : model.getConfigModels()) {
+ if(configModel.getName().matches(namePattern)) {
+ result.add(configModel);
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Validates the current configuration.
+ *
+ * @return the validation results, never null.
+ */
+ public static Collection<ValidationResult> validate() {
+ return validate(false);
+ }
+
+ /**
+ * Validates the current configuration.
+ * @param showUndefined show any unknown parameters.
+ * @return the validation results, never null.
+ */
+ public static Collection<ValidationResult> validate(boolean showUndefined) {
+ return validate(ConfigurationProvider.getConfiguration(), showUndefined);
+ }
+
+ /**
+ * Validates the given configuration.
+ *
+ * @param config the configuration to be validated against, not null.
+ * @return the validation results, never null.
+ */
+ public static Collection<ValidationResult> validate(Configuration config) {
+ return validate(config, false);
+ }
+
+ /**
+ * Validates the given configuration.
+ *
+ * @param config the configuration to be validated against, not null.
+ * @return the validation results, never null.
+ */
+ public static Collection<ValidationResult> validate(Configuration config, boolean showUndefined) {
+ List<ValidationResult> result = new ArrayList<>();
+ for (ConfigModel defConf : getModels()) {
+ result.addAll(defConf.validate(config));
+ }
+ if(showUndefined){
+ Map<String,String> map = new HashMap<>(config.getProperties());
+ Set<String> areas = extractTransitiveAreas(map.keySet());
+ for (ConfigModel defConf : getModels()) {
+ if(ModelType.Section.equals(defConf.getType())){
+ for (Iterator<String> iter = areas.iterator();iter.hasNext();){
+ String area = iter.next();
+ if(area.matches(defConf.getName())){
+ iter.remove();
+ }
+ }
+ }
+ if(ModelType.Parameter.equals(defConf.getType())){
+ map.remove(defConf.getName());
+ }
+ }
+ outer:for(Map.Entry<String,String> entry:map.entrySet()){
+ for (ConfigModel defConf : getModels()) {
+ if(ModelType.Section.equals(defConf.getType())){
+ if(defConf.getName().endsWith(".*") && entry.getKey().matches(defConf.getName())){
+ // Ignore parameters that are part of transitive section.
+ continue outer;
+ }
+ }
+ }
+ result.add(ValidationResult.ofUndefined(entry.getKey(), ModelType.Parameter, null));
+ }
+ for(String area:areas){
+ result.add(ValidationResult.ofUndefined(area, ModelType.Section, null));
+ }
+ }
+ return result;
+ }
+
+ private static java.util.Set<java.lang.String> extractTransitiveAreas(Set<String> keys) {
+ Set<String> transitiveClosure = new HashSet<>();
+ for(String key:keys){
+ int index = key.lastIndexOf('.');
+ while(index>0){
+ String areaKey = key.substring(0,index);
+ transitiveClosure.add(areaKey);
+ index = areaKey.lastIndexOf('.');
+ }
+ }
+ return transitiveClosure;
+ }
+
+
+ /**
+ * Registers the {@link ConfigDocumentationMBean} mbean for accessing config documentation into the local platform
+ * mbean server.
+ */
+ public static void registerMBean() {
+ registerMBean(null);
+ }
+
+ /**
+ * Registers the {@link ConfigDocumentationMBean} mbean for accessing config documentation into the local platform
+ * mbean server.
+ */
+ public static void registerMBean(String context) {
+ try{
+ ConfigDocumentationMBean configMbean = ServiceContextManager.getServiceContext()
+ .getService(ConfigDocumentationMBean.class);
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ ObjectName on = context==null?new ObjectName("org.apache.tamaya.model:type=ConfigDocumentationMBean"):
+ new ObjectName("org.apache.tamaya.model:type=ConfigDocumentationMBean,context="+context);
+ try{
+ mbs.getMBeanInfo(on);
+ LOG.warning("Cannot register mbean " + on + ": already existing.");
+ } catch(InstanceNotFoundException e) {
+ LOG.info("Registering mbean " + on + "...");
+ mbs.registerMBean(configMbean, on);
+ }
+ } catch(Exception e){
+ LOG.log(Level.WARNING,
+ "Failed to register ConfigDocumentationMBean.", e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java
deleted file mode 100644
index 827adca..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java
+++ /dev/null
@@ -1,239 +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.model;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.model.spi.ConfigDocumentationMBean;
-import org.apache.tamaya.model.spi.ValidationProviderSpi;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import java.lang.management.ManagementFactory;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Validator accessor to validate the current configuration.
- */
-public final class ConfigValidator {
-
- /** The logger used. */
- private final static Logger LOG = Logger.getLogger(ConfigValidator.class.getName());
-
- /**
- * Singleton constructor.
- */
- private ConfigValidator() {
- }
-
- /**
- * Get the validations defined.
- *
- * @return the sections defined, never null.
- */
- public static Collection<Validation> getValidations() {
- List<Validation> result = new ArrayList<>();
- for (ValidationProviderSpi model : ServiceContextManager.getServiceContext().getServices(ValidationProviderSpi.class)) {
- result.addAll(model.getValidations());
- }
- return result;
- }
-
- /**
- * Find the validations by checking the validation's name using the given regular expression.
- * @param type the target ValidationType, not null.
- * @param namePattern the regular expression to use, not null.
- * @return the sections defined, never null.
- */
- public static Collection<Validation> findValidations(ValidationType type, String namePattern) {
- List<Validation> result = new ArrayList<>();
- for (ValidationProviderSpi model : ServiceContextManager.getServiceContext().getServices(ValidationProviderSpi.class)) {
- for(Validation validation: model.getValidations()) {
- if(validation.getName().matches(namePattern) && validation.getType()==type) {
- result.add(validation);
- }
- }
- }
- return result;
- }
-
- /**
- * Find the validations by checking the validation's name using the given regular expression.
- * @param name the name to use, not null.
- * @return the sections defined, never null.
- */
- public static <T extends Validation> T getValidation(String name, Class<T> validationType) {
- for (ValidationProviderSpi model : ServiceContextManager.getServiceContext().getServices(ValidationProviderSpi.class)) {
- for(Validation validation: model.getValidations()) {
- if(validation.getName().equals(name) && validation.getClass().equals(validationType)) {
- return validationType.cast(validation);
- }
- }
- }
- return null;
- }
-
- /**
- * Find the validations by checking the validation's name using the given regular expression.
- * @param namePattern the regular expression to use, not null.
- * @return the sections defined, never null.
- */
- public static Collection<Validation> findValidations(String namePattern) {
- List<Validation> result = new ArrayList<>();
- for (ValidationProviderSpi model : ServiceContextManager.getServiceContext().getServices(ValidationProviderSpi.class)) {
- for(Validation validation: model.getValidations()) {
- if(validation.getName().matches(namePattern)) {
- result.add(validation);
- }
- }
- }
- return result;
- }
-
- /**
- * Validates the current configuration.
- *
- * @return the validation results, never null.
- */
- public static Collection<ValidationResult> validate() {
- return validate(false);
- }
-
- /**
- * Validates the current configuration.
- * @param showUndefined show any unknown parameters.
- * @return the validation results, never null.
- */
- public static Collection<ValidationResult> validate(boolean showUndefined) {
- return validate(ConfigurationProvider.getConfiguration(), showUndefined);
- }
-
- /**
- * Validates the given configuration.
- *
- * @param config the configuration to be validated against, not null.
- * @return the validation results, never null.
- */
- public static Collection<ValidationResult> validate(Configuration config) {
- return validate(config, false);
- }
-
- /**
- * Validates the given configuration.
- *
- * @param config the configuration to be validated against, not null.
- * @return the validation results, never null.
- */
- public static Collection<ValidationResult> validate(Configuration config, boolean showUndefined) {
- List<ValidationResult> result = new ArrayList<>();
- for (Validation defConf : getValidations()) {
- result.addAll(defConf.validate(config));
- }
- if(showUndefined){
- Map<String,String> map = new HashMap<>(config.getProperties());
- Set<String> areas = extractTransitiveAreas(map.keySet());
- for (Validation defConf : getValidations()) {
- if(ValidationType.Section.equals(defConf.getType())){
- for (Iterator<String> iter = areas.iterator();iter.hasNext();){
- String area = iter.next();
- if(area.matches(defConf.getName())){
- iter.remove();
- }
- }
- }
- if(ValidationType.Parameter.equals(defConf.getType())){
- map.remove(defConf.getName());
- }
- }
- outer:for(Map.Entry<String,String> entry:map.entrySet()){
- for (Validation defConf : getValidations()) {
- if(ValidationType.Section.equals(defConf.getType())){
- if(defConf.getName().endsWith(".*") && entry.getKey().matches(defConf.getName())){
- // Ignore parameters that are part of transitive section.
- continue outer;
- }
- }
- }
- result.add(ValidationResult.ofUndefined(entry.getKey(), ValidationType.Parameter, null));
- }
- for(String area:areas){
- result.add(ValidationResult.ofUndefined(area, ValidationType.Section, null));
- }
- }
- return result;
- }
-
- private static java.util.Set<java.lang.String> extractTransitiveAreas(Set<String> keys) {
- Set<String> transitiveClosure = new HashSet<>();
- for(String key:keys){
- int index = key.lastIndexOf('.');
- while(index>0){
- String areaKey = key.substring(0,index);
- transitiveClosure.add(areaKey);
- index = areaKey.lastIndexOf('.');
- }
- }
- return transitiveClosure;
- }
-
-
- /**
- * Registers the {@link ConfigDocumentationMBean} mbean for accessing config documentation into the local platform
- * mbean server.
- */
- public static void registerMBean() {
- registerMBean(null);
- }
-
- /**
- * Registers the {@link ConfigDocumentationMBean} mbean for accessing config documentation into the local platform
- * mbean server.
- */
- public static void registerMBean(String context) {
- try{
- ConfigDocumentationMBean configMbean = ServiceContextManager.getServiceContext()
- .getService(ConfigDocumentationMBean.class);
- MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- ObjectName on = context==null?new ObjectName("org.apache.tamaya.model:type=ConfigDocumentationMBean"):
- new ObjectName("org.apache.tamaya.model:type=ConfigDocumentationMBean,context="+context);
- try{
- mbs.getMBeanInfo(on);
- LOG.warning("Cannot register mbean " + on + ": already existing.");
- } catch(InstanceNotFoundException e) {
- LOG.info("Registering mbean " + on + "...");
- mbs.registerMBean(configMbean, on);
- }
- } catch(Exception e){
- LOG.log(Level.WARNING,
- "Failed to register ConfigDocumentationMBean.", e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/ModelType.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ModelType.java b/modules/model/src/main/java/org/apache/tamaya/model/ModelType.java
new file mode 100644
index 0000000..aaf22f7
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ModelType.java
@@ -0,0 +1,49 @@
+/*
+ * 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.model;
+
+/**
+ * This enumeration defines the types of supported validations.
+ */
+public enum ModelType {
+ /**
+ * A configuration section.
+ */
+ Section,
+ /**
+ * A configuration paramter.
+ */
+ Parameter,
+ /**
+ * ConfigModel to ensure a certain configuration filter is installed.
+ */
+ Filter,
+ /**
+ * ConfigModel to ensure a certain combination policy is active.
+ */
+ CombinationPolicy,
+ /**
+ * ConfigModel that is a container of other validations.
+ */
+ Group,
+ /**
+ * ConfigModel to simply check availability for a class on the current classpath.
+ */
+ LoadableClass
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/Validation.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/Validation.java b/modules/model/src/main/java/org/apache/tamaya/model/Validation.java
deleted file mode 100644
index ec5113a..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/Validation.java
+++ /dev/null
@@ -1,78 +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.model;
-
-import org.apache.tamaya.Configuration;
-
-import java.util.Collection;
-
-/**
- * Basis structure describing a validated item, by default a parameter or a section.
- */
-public interface Validation {
-
-
- /**
- * Get the type of item that is validated by a validation.
- * @return the validted type, never null.
- */
- ValidationType getType();
-
- /**
- * Get the item's name, it should minimally describe the validation. Examples are:
- * <pre>
- * Sections: a.b.c
- * Params: a.b.c.paramName
- * Filter: a.b.c.FilterImplClass
- * Dependency: mydepClassname
- * CombinationPolicy: a.b.c.MyCombinationPolicyClass
- * </pre>
- */
- String getName();
-
- /**
- * CHeck if this validation is a required one.
- * @return true, if this validation is required.
- */
- boolean isRequired();
-
- /**
- * Get the provider of this validation.
- * @return the provider.
- */
- String getProvider();
-
- /**
- * Get an description of the item, using the default locale. The description is basically optional
- * though it is higly recommended to provide a description, so the validation issues is well
- * resolvable.
- *
- * @return the description required, or null.
- */
- String getDescription();
-
- /**
- * Validates the item and all its children against the given configuration.
- *
- * @param config the configuration to be validated against, not null.
- * @return the validation results, never null.
- */
- Collection<ValidationResult> validate(Configuration config);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java b/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
index 3c86edf..a7a55a6 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
@@ -19,105 +19,105 @@
package org.apache.tamaya.model;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.model.spi.AbstractValidation;
+import org.apache.tamaya.model.spi.AbstractModel;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
/**
- * Models a partial configuration validation result.
+ * Models a partial configuration configModel result.
*/
public final class ValidationResult {
/**
* the config section.
*/
- private Validation validation;
+ private ConfigModel configModel;
/**
- * The validation result.
+ * The configModel result.
*/
private ValidationState result;
/**
- * The validation message.
+ * The configModel message.
*/
private String message;
/**
* Creates a new ValidationResult.
*
- * @param validation the validation item, not null.
+ * @param configModel the configModel item, not null.
*/
- public static ValidationResult ofValid(Validation validation) {
- return new ValidationResult(validation, ValidationState.VALID, null);
+ public static ValidationResult ofValid(ConfigModel configModel) {
+ return new ValidationResult(configModel, ValidationState.VALID, null);
}
/**
* Creates a new ValidationResult.
*
- * @param validation the validation item, not null.
+ * @param configModel the configModel item, not null.
*/
- public static ValidationResult ofMissing(Validation validation) {
- return new ValidationResult(validation, ValidationState.MISSING, null);
+ public static ValidationResult ofMissing(ConfigModel configModel) {
+ return new ValidationResult(configModel, ValidationState.MISSING, null);
}
/**
* Creates a new ValidationResult.
*
- * @param validation the validation item, not null.
+ * @param configModel the configModel item, not null.
* @param message Additional message to be shown (optional).
*/
- public static ValidationResult ofMissing(Validation validation, String message) {
- return new ValidationResult(validation, ValidationState.MISSING, message);
+ public static ValidationResult ofMissing(ConfigModel configModel, String message) {
+ return new ValidationResult(configModel, ValidationState.MISSING, message);
}
/**
* Creates a new ValidationResult.
*
- * @param validation the validation item, not null.
+ * @param configModel the configModel item, not null.
*/
- public static ValidationResult ofError(Validation validation, String error) {
- return new ValidationResult(validation, ValidationState.ERROR, error);
+ public static ValidationResult ofError(ConfigModel configModel, String error) {
+ return new ValidationResult(configModel, ValidationState.ERROR, error);
}
/**
* Creates a new ValidationResult.
*
- * @param validation the validation item, not null.
+ * @param configModel the configModel item, not null.
*/
- public static ValidationResult ofWarning(Validation validation, String warning) {
- return new ValidationResult(validation, ValidationState.WARNING, warning);
+ public static ValidationResult ofWarning(ConfigModel configModel, String warning) {
+ return new ValidationResult(configModel, ValidationState.WARNING, warning);
}
/**
* Creates a new ValidationResult.
*
- * @param validation the validation item, not null.
+ * @param configModel the configModel item, not null.
*/
- public static ValidationResult ofDeprecated(Validation validation, String alternateUsage) {
- return new ValidationResult(validation, ValidationState.DEPRECATED, alternateUsage != null ? "Use instead: " + alternateUsage : null);
+ public static ValidationResult ofDeprecated(ConfigModel configModel, String alternateUsage) {
+ return new ValidationResult(configModel, ValidationState.DEPRECATED, alternateUsage != null ? "Use instead: " + alternateUsage : null);
}
/**
* Creates a new ValidationResult.
*
- * @param validation the validation item, not null.
+ * @param configModel the configModel item, not null.
*/
- public static ValidationResult ofDeprecated(Validation validation) {
- return new ValidationResult(validation, ValidationState.DEPRECATED, null);
+ public static ValidationResult ofDeprecated(ConfigModel configModel) {
+ return new ValidationResult(configModel, ValidationState.DEPRECATED, null);
}
/**
* Creates a new ValidationResult.
*
* @param key the name/key
- * @return a corresponding validation item
+ * @return a corresponding configModel item
*/
- public static ValidationResult ofUndefined(final String key, final ValidationType type, String provider) {
- return new ValidationResult(new AbstractValidation(key, false, "Undefined key: " + key, provider) {
+ public static ValidationResult ofUndefined(final String key, final ModelType type, String provider) {
+ return new ValidationResult(new AbstractModel(key, false, "Undefined key: " + key, provider) {
@Override
- public ValidationType getType() {
+ public ModelType getType() {
return type;
}
@@ -132,39 +132,39 @@ public final class ValidationResult {
/**
* Constructor.
*
- * @param validation the validation item, not null.
- * @param result the validation result, not null.
+ * @param configModel the configModel item, not null.
+ * @param result the configModel result, not null.
* @param message the detail message.
*/
- public static ValidationResult of(Validation validation, ValidationState result, String message) {
- return new ValidationResult(validation, result, message);
+ public static ValidationResult of(ConfigModel configModel, ValidationState result, String message) {
+ return new ValidationResult(configModel, result, message);
}
/**
* Constructor.
*
- * @param validation the validation item, not null.
- * @param result the validation result, not null.
+ * @param configModel the configModel item, not null.
+ * @param result the configModel result, not null.
* @param message the detail message.
*/
- private ValidationResult(Validation validation, ValidationState result, String message) {
+ private ValidationResult(ConfigModel configModel, ValidationState result, String message) {
this.message = message;
- this.validation = Objects.requireNonNull(validation);
+ this.configModel = Objects.requireNonNull(configModel);
this.result = Objects.requireNonNull(result);
}
/**
- * Get the validation section.
+ * Get the configModel section.
*
* @return the section, never null.
*/
- public Validation getValidation() {
- return validation;
+ public ConfigModel getConfigModel() {
+ return configModel;
}
/**
- * Get the validation result.
+ * Get the configModel result.
*
* @return the result, never null.
*/
@@ -184,8 +184,8 @@ public final class ValidationResult {
@Override
public String toString() {
if (message != null) {
- return result + ": " + validation.getName() + " (" + validation.getType() + ") -> " + message + '\n';
+ return result + ": " + configModel.getName() + " (" + configModel.getType() + ") -> " + message + '\n';
}
- return result + ": " + validation.getName() + " (" + validation.getType() + ")";
+ return result + ": " + configModel.getName() + " (" + configModel.getType() + ")";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/ValidationType.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ValidationType.java b/modules/model/src/main/java/org/apache/tamaya/model/ValidationType.java
deleted file mode 100644
index f916032..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/ValidationType.java
+++ /dev/null
@@ -1,49 +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.model;
-
-/**
- * This enumeration defines the types of supported validations.
- */
-public enum ValidationType {
- /**
- * A configuration section.
- */
- Section,
- /**
- * A configuration paramter.
- */
- Parameter,
- /**
- * Validation to ensure a certain configuration filter is installed.
- */
- Filter,
- /**
- * Validation to ensure a certain combination policy is active.
- */
- CombinationPolicy,
- /**
- * Validation that is a container of other validations.
- */
- Group,
- /**
- * Validation to simply check availability for a class on the current classpath.
- */
- LoadableClass
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
index 1c20bea..b86fcec 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
@@ -20,10 +20,10 @@ package org.apache.tamaya.model.internal;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.model.ConfigValidator;
-import org.apache.tamaya.model.Validation;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.ConfigModelManager;
+import org.apache.tamaya.model.ModelType;
import org.apache.tamaya.model.ValidationResult;
-import org.apache.tamaya.model.ValidationType;
import org.apache.tamaya.model.spi.ConfigDocumentationMBean;
import javax.json.Json;
@@ -52,7 +52,7 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
private static final Comparator<ValidationResult> COMPARATOR = new Comparator<ValidationResult>() {
@Override
public int compare(ValidationResult v1, ValidationResult v2) {
- int compare = VAL_COMPARATOR.compare(v1.getValidation(), v2.getValidation());
+ int compare = VAL_COMPARATOR.compare(v1.getConfigModel(), v2.getConfigModel());
if(compare==0){
compare = v1.getResult().compareTo(v2.getResult());
}
@@ -62,9 +62,9 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
return compare;
}
};
- private static final Comparator<Validation> VAL_COMPARATOR = new Comparator<Validation>() {
+ private static final Comparator<ConfigModel> VAL_COMPARATOR = new Comparator<ConfigModel>() {
@Override
- public int compare(Validation v1, Validation v2) {
+ public int compare(ConfigModel v1, ConfigModel v2) {
int compare = v1.getType().compareTo(v2.getType());
if(compare==0){
compare = v1.getName().compareTo(v2.getName());
@@ -105,7 +105,7 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
@Override
public String validate(boolean showUndefined) {
- List<ValidationResult> validations = new ArrayList<>(ConfigValidator.validate(getConfig(), showUndefined));
+ List<ValidationResult> validations = new ArrayList<>(ConfigModelManager.validate(getConfig(), showUndefined));
Collections.sort(validations, COMPARATOR);
JsonArrayBuilder builder = Json.createArrayBuilder();
for(ValidationResult val:validations){
@@ -118,37 +118,37 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
@Override
public String getConfigurationModel() {
- List<Validation> validations = new ArrayList<>(ConfigValidator.getValidations());
- Collections.sort(validations, VAL_COMPARATOR);
+ List<ConfigModel> configModels = new ArrayList<>(ConfigModelManager.getModels());
+ Collections.sort(configModels, VAL_COMPARATOR);
JsonArrayBuilder result = Json.createArrayBuilder();
- for(Validation val:validations){
+ for(ConfigModel val: configModels){
result.add(toJsonObject(val));
}
return formatJson(result.build());
}
@Override
- public String getConfigurationModel(ValidationType type) {
+ public String getConfigurationModel(ModelType type) {
return findValidationModels(type, ".*");
}
@Override
public String findConfigurationModels(String namePattern) {
- List<Validation> validations = new ArrayList<>(ConfigValidator.findValidations(namePattern));
- Collections.sort(validations, VAL_COMPARATOR);
+ List<ConfigModel> configModels = new ArrayList<>(ConfigModelManager.findModels(namePattern));
+ Collections.sort(configModels, VAL_COMPARATOR);
JsonArrayBuilder result = Json.createArrayBuilder();
- for(Validation val:validations){
+ for(ConfigModel val: configModels){
result.add(toJsonObject(val));
}
return formatJson(result.build());
}
@Override
- public String findValidationModels(ValidationType type, String namePattern) {
- List<Validation> validations = new ArrayList<>(ConfigValidator.findValidations(type, namePattern));
- Collections.sort(validations, VAL_COMPARATOR);
+ public String findValidationModels(ModelType type, String namePattern) {
+ List<ConfigModel> configModels = new ArrayList<>(ConfigModelManager.findModels(type, namePattern));
+ Collections.sort(configModels, VAL_COMPARATOR);
JsonArrayBuilder result = Json.createArrayBuilder();
- for(Validation val:validations){
+ for(ConfigModel val: configModels){
result.add(toJsonObject(val));
}
return formatJson(result.build());
@@ -160,7 +160,7 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
}
- private JsonObject toJsonObject(Validation val) {
+ private JsonObject toJsonObject(ConfigModel val) {
JsonObjectBuilder valJson = Json.createObjectBuilder().add("type", val.getType().toString())
.add("name", val.getName());
if(val.getDescription()!=null) {
@@ -173,13 +173,13 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
}
private JsonObject toJsonObject(ValidationResult val) {
- JsonObjectBuilder valJson = Json.createObjectBuilder().add("type", val.getValidation().getType().toString())
- .add("name", val.getValidation().getName());
- if(val.getValidation().isRequired()){
+ JsonObjectBuilder valJson = Json.createObjectBuilder().add("type", val.getConfigModel().getType().toString())
+ .add("name", val.getConfigModel().getName());
+ if(val.getConfigModel().isRequired()){
valJson.add("required",true);
}
- if(val.getValidation().getDescription() != null){
- valJson.add("description", val.getValidation().getDescription());
+ if(val.getConfigModel().getDescription() != null){
+ valJson.add("description", val.getConfigModel().getDescription());
}
valJson.add("result", val.getResult().toString());
if( val.getMessage() != null) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
index 1eb7e8c..6d1f9e1 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
@@ -19,9 +19,9 @@
package org.apache.tamaya.model.internal;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.model.Validation;
-import org.apache.tamaya.model.spi.ConfigValidationsReader;
-import org.apache.tamaya.model.spi.ValidationProviderSpi;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.spi.ConfigModelReader;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
import java.util.ArrayList;
import java.util.Collection;
@@ -31,17 +31,17 @@ import java.util.Map;
import java.util.logging.Logger;
/**
- * Validation provider that reads model metadata from the current {@link org.apache.tamaya.Configuration}.
+ * ConfigModel provider that reads model metadata from the current {@link org.apache.tamaya.Configuration}.
*/
-public class ConfiguredInlineModelProviderSpi implements ValidationProviderSpi {
+public class ConfiguredInlineModelProviderSpi implements ModelProviderSpi {
/** The logger. */
private static final Logger LOG = Logger.getLogger(ConfiguredInlineModelProviderSpi.class.getName());
/** parameter to disable this provider. By default the provider is active. */
private static final String MODEL_EANABLED_PARAM = "org.apache.tamaya.model.integrated.enabled";
- /** The validations read. */
- private List<Validation> validations = new ArrayList<>();
+ /** The configModels read. */
+ private List<ConfigModel> configModels = new ArrayList<>();
/**
@@ -53,15 +53,14 @@ public class ConfiguredInlineModelProviderSpi implements ValidationProviderSpi {
if (enabled) {
LOG.info("Reading model configuration from config...");
Map<String,String> config = ConfigurationProvider.getConfiguration().getProperties();
- validations.addAll(ConfigValidationsReader.loadValidations(config,
+ configModels.addAll(ConfigModelReader.loadValidations(config,
"<Inline Configuration Model>"));
}
- validations = Collections.unmodifiableList(validations);
+ configModels = Collections.unmodifiableList(configModels);
}
- @Override
- public Collection<Validation> getValidations() {
- return validations;
+ public Collection<ConfigModel> getConfigModels() {
+ return configModels;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesModelProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesModelProviderSpi.java
new file mode 100644
index 0000000..1757361
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesModelProviderSpi.java
@@ -0,0 +1,152 @@
+/*
+ * 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.model.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.spi.ConfigModelReader;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * ConfigModel provider that reads model metadata from property files from
+ * {@code classpath*:META-INF/configmodel.properties} in the following format:
+ * <pre>
+ * ###################################################################################
+ * # Example of a configuration metamodel expressed via properties.
+ * ####################################################################################
+ *
+ * # Metamodel information
+ * [model].provider=ConfigModel Extension
+ *
+ * ####################################################################################
+ * # Description of Configuration Sections (minimal, can be extended by other modules).
+ * # By default its interpreted as a section !
+ * ####################################################################################
+ *
+ * # a (section)
+ * {model}a.class=Section
+ * {model}a.params2.class=Parameter
+ * {model}a.params2.type=String
+ * {model}a.params2.required=true
+ * {model}a.params2.description=a required parameter
+ *
+ * {model}a.paramInt.class=Parameter
+ * {model}a.paramInt.ref=MyNumber
+ * {model}a.paramInt.description=an optional parameter (default)
+ *
+ * {model}a._number.class=Parameter
+ * {model}a._number.type=Integer
+ * {model}a._number.deprecated=true
+ * {model}a._number.mappedTo=a.paramInt
+ *
+ * # a.b.c (section)
+ * {model}a.b.c.class=Section
+ * {model}a.b.c.description=Just a test section
+ *
+ * # a.b.c.aRequiredSection (section)
+ * {model}a.b.c.aRequiredSection.class=Section
+ * {model}a.b.c.aRequiredSection.required=true
+ * {model}a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
+ * Sections can also explicitly be defined to be required, but without\
+ * specifying the paramteres to be contained.,
+ *
+ * # a.b.c.aRequiredSection.subsection (section)
+ * {model}a.b.c.aRequiredSection.subsection.class=Section
+ *
+ * {model}a.b.c.aRequiredSection.subsection.param0.class=Parameter
+ * {model}a.b.c.aRequiredSection.subsection.param0.type=String
+ * {model}a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
+ * # A minmal String parameter
+ * {model}a.b.c.aRequiredSection.subsection.param00.class=Parameter
+ * {model}a.b.c.aRequiredSection.subsection.param00.type=String
+ *
+ * # a.b.c.aRequiredSection.subsection (section)
+ * {model}a.b.c.aRequiredSection.subsection.param1.class=Parameter
+ * {model}a.b.c.aRequiredSection.subsection.param1.type = String
+ * {model}a.b.c.aRequiredSection.subsection.param1.required = true
+ * {model}a.b.c.aRequiredSection.subsection.intParam.class=Parameter
+ * {model}a.b.c.aRequiredSection.subsection.intParam.type = Integer
+ * {model}a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
+ *
+ * # a.b.c.aRequiredSection.nonempty-subsection (section)
+ * {model}a.b.c.aRequiredSection.nonempty-subsection.class=Section
+ * {model}a.b.c.aRequiredSection.nonempty-subsection.required=true
+ *
+ * # a.b.c.aRequiredSection.optional-subsection (section)
+ * {model}a.b.c.aRequiredSection.optional-subsection.class=Section
+ *
+ * # a.b.c.aValidatedSection (section)
+ * {model}a.b.c.aValidatedSection.class=Section
+ * {model}a.b.c.aValidatedSection.description=A validated section.
+ * {model}a.b.c.aValidatedSection.configModels=org.apache.tamaya.model.TestValidator
+ * </pre>
+ */
+public class ConfiguredPropertiesModelProviderSpi implements ModelProviderSpi {
+
+ /** The logger. */
+ private static final Logger LOG = Logger.getLogger(ConfiguredPropertiesModelProviderSpi.class.getName());
+ /** parameter to disable this provider. By default the provider is active. */
+ private static final String MODEL_EANABLED_PARAM = "org.apache.tamaya.model.default.enabled";
+ /** The configModels read. */
+ private List<ConfigModel> configModels = new ArrayList<>();
+
+ public ConfiguredPropertiesModelProviderSpi() {
+ String enabledVal = ConfigurationProvider.getConfiguration().get(MODEL_EANABLED_PARAM);
+ boolean enabled = enabledVal==null? true: "true".equalsIgnoreCase(enabledVal);
+ if(!enabled){
+ LOG.info("Reading model data from META-INF/configmodel.properties has been disabled.");
+ return;
+ }
+ try {
+ LOG.info("Reading model data from META-INF/configmodel.properties...");
+ Enumeration<URL> configs = getClass().getClassLoader().getResources("META-INF/configmodel.properties");
+ while (configs.hasMoreElements()) {
+ URL config = configs.nextElement();
+ try (InputStream is = config.openStream()) {
+ Properties props = new Properties();
+ props.load(is);
+ configModels.addAll(ConfigModelReader.loadValidations(props, config.toString()));
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Error loading config metadata from " + config, e);
+ }
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE,
+ "Error loading config metadata from META-INF/configmodel.properties", e);
+ }
+ configModels = Collections.unmodifiableList(configModels);
+ }
+
+
+ public Collection<ConfigModel> getConfigModels() {
+ return configModels;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesValidationProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesValidationProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesValidationProviderSpi.java
deleted file mode 100644
index 41157ac..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesValidationProviderSpi.java
+++ /dev/null
@@ -1,153 +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.model.internal;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.model.Validation;
-import org.apache.tamaya.model.spi.ConfigValidationsReader;
-import org.apache.tamaya.model.spi.ValidationProviderSpi;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Validation provider that reads model metadata from property files from
- * {@code classpath*:META-INF/configmodel.properties} in the following format:
- * <pre>
- * ###################################################################################
- * # Example of a configuration metamodel expressed via properties.
- * ####################################################################################
- *
- * # Metamodel information
- * [model].provider=ConfigModel Extension
- *
- * ####################################################################################
- * # Description of Configuration Sections (minimal, can be extended by other modules).
- * # By default its interpreted as a section !
- * ####################################################################################
- *
- * # a (section)
- * {model}a.class=Section
- * {model}a.params2.class=Parameter
- * {model}a.params2.type=String
- * {model}a.params2.required=true
- * {model}a.params2.description=a required parameter
- *
- * {model}a.paramInt.class=Parameter
- * {model}a.paramInt.ref=MyNumber
- * {model}a.paramInt.description=an optional parameter (default)
- *
- * {model}a._number.class=Parameter
- * {model}a._number.type=Integer
- * {model}a._number.deprecated=true
- * {model}a._number.mappedTo=a.paramInt
- *
- * # a.b.c (section)
- * {model}a.b.c.class=Section
- * {model}a.b.c.description=Just a test section
- *
- * # a.b.c.aRequiredSection (section)
- * {model}a.b.c.aRequiredSection.class=Section
- * {model}a.b.c.aRequiredSection.required=true
- * {model}a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
- * Sections can also explicitly be defined to be required, but without\
- * specifying the paramteres to be contained.,
- *
- * # a.b.c.aRequiredSection.subsection (section)
- * {model}a.b.c.aRequiredSection.subsection.class=Section
- *
- * {model}a.b.c.aRequiredSection.subsection.param0.class=Parameter
- * {model}a.b.c.aRequiredSection.subsection.param0.type=String
- * {model}a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
- * # A minmal String parameter
- * {model}a.b.c.aRequiredSection.subsection.param00.class=Parameter
- * {model}a.b.c.aRequiredSection.subsection.param00.type=String
- *
- * # a.b.c.aRequiredSection.subsection (section)
- * {model}a.b.c.aRequiredSection.subsection.param1.class=Parameter
- * {model}a.b.c.aRequiredSection.subsection.param1.type = String
- * {model}a.b.c.aRequiredSection.subsection.param1.required = true
- * {model}a.b.c.aRequiredSection.subsection.intParam.class=Parameter
- * {model}a.b.c.aRequiredSection.subsection.intParam.type = Integer
- * {model}a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
- *
- * # a.b.c.aRequiredSection.nonempty-subsection (section)
- * {model}a.b.c.aRequiredSection.nonempty-subsection.class=Section
- * {model}a.b.c.aRequiredSection.nonempty-subsection.required=true
- *
- * # a.b.c.aRequiredSection.optional-subsection (section)
- * {model}a.b.c.aRequiredSection.optional-subsection.class=Section
- *
- * # a.b.c.aValidatedSection (section)
- * {model}a.b.c.aValidatedSection.class=Section
- * {model}a.b.c.aValidatedSection.description=A validated section.
- * {model}a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator
- * </pre>
- */
-public class ConfiguredPropertiesValidationProviderSpi implements ValidationProviderSpi {
-
- /** The logger. */
- private static final Logger LOG = Logger.getLogger(ConfiguredPropertiesValidationProviderSpi.class.getName());
- /** parameter to disable this provider. By default the provider is active. */
- private static final String MODEL_EANABLED_PARAM = "org.apache.tamaya.model.default.enabled";
- /** The validations read. */
- private List<Validation> validations = new ArrayList<>();
-
- public ConfiguredPropertiesValidationProviderSpi() {
- String enabledVal = ConfigurationProvider.getConfiguration().get(MODEL_EANABLED_PARAM);
- boolean enabled = enabledVal==null? true: "true".equalsIgnoreCase(enabledVal);
- if(!enabled){
- LOG.info("Reading model data from META-INF/configmodel.properties has been disabled.");
- return;
- }
- try {
- LOG.info("Reading model data from META-INF/configmodel.properties...");
- Enumeration<URL> configs = getClass().getClassLoader().getResources("META-INF/configmodel.properties");
- while (configs.hasMoreElements()) {
- URL config = configs.nextElement();
- try (InputStream is = config.openStream()) {
- Properties props = new Properties();
- props.load(is);
- validations.addAll(ConfigValidationsReader.loadValidations(props, config.toString()));
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.SEVERE,
- "Error loading config metadata from " + config, e);
- }
- }
- } catch (Exception e) {
- LOG.log(Level.SEVERE,
- "Error loading config metadata from META-INF/configmodel.properties", e);
- }
- validations = Collections.unmodifiableList(validations);
- }
-
-
- @Override
- public Collection<Validation> getValidations() {
- return validations;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
index 577ce44..b3e29a4 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
@@ -21,9 +21,9 @@ package org.apache.tamaya.model.internal;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.format.ConfigurationFormats;
-import org.apache.tamaya.model.Validation;
-import org.apache.tamaya.model.spi.ConfigValidationsReader;
-import org.apache.tamaya.model.spi.ValidationProviderSpi;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.spi.ConfigModelReader;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
import org.apache.tamaya.resource.ConfigResources;
import java.io.IOException;
@@ -38,12 +38,12 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Validation provider that reads model metadata from property files from
+ * ConfigModel provider that reads model metadata from property files from
* {@code classpath*:META-INF/configmodel.json} in the following format:
* <pre>
* </pre>
*/
-public class ConfiguredResourcesModelProviderSpi implements ValidationProviderSpi {
+public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi {
/** The logger. */
private static final Logger LOG = Logger.getLogger(ConfiguredResourcesModelProviderSpi.class.getName());
@@ -58,8 +58,8 @@ public class ConfiguredResourcesModelProviderSpi implements ValidationProviderSp
/** Initializes the flag showing if the resources module is present (optional). */
private static boolean resourcesExtensionAvailable = checkAvailabilityResources();
- /** The validations read. */
- private List<Validation> validations = new ArrayList<>();
+ /** The configModels read. */
+ private List<ConfigModel> configModels = new ArrayList<>();
/** Initializes the flag showing if the formats module is present (required). */
private static boolean checkAvailabilityFormats() {
@@ -119,19 +119,18 @@ public class ConfiguredResourcesModelProviderSpi implements ValidationProviderSp
for(URL config:urls){
try (InputStream is = config.openStream()) {
ConfigurationData data = ConfigurationFormats.readConfigurationData(config);
- validations.addAll(ConfigValidationsReader.loadValidations(data.getCombinedProperties(), config.toString()));
+ configModels.addAll(ConfigModelReader.loadValidations(data.getCombinedProperties(), config.toString()));
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE,
"Error loading config model data from " + config, e);
}
}
}
- validations = Collections.unmodifiableList(validations);
+ configModels = Collections.unmodifiableList(configModels);
}
- @Override
- public Collection<Validation> getValidations() {
- return validations;
+ public Collection<ConfigModel> getConfigModels() {
+ return configModels;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
new file mode 100644
index 0000000..04004cb
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
@@ -0,0 +1,76 @@
+/*
+ * 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.model.internal;
+
+import org.apache.tamaya.events.ConfigEventListener;
+import org.apache.tamaya.inject.spi.ConfiguredField;
+import org.apache.tamaya.inject.spi.ConfiguredMethod;
+import org.apache.tamaya.inject.spi.ConfiguredType;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.ConfigModelManager;
+import org.apache.tamaya.model.spi.ParameterModel;
+
+import java.util.Collection;
+import java.util.logging.Logger;
+
+/**
+ * Internal facade that registers all kind of injected fields as {@link ConfigModel} entries,
+ * so all configured injection points are visible as documented configuration hooks.
+ */
+public final class ConfiguredTypeEventsModelPopulator implements ConfigEventListener<ConfiguredType> {
+
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(ConfiguredTypeEventsModelPopulator.class.getName());
+
+ @Override
+ public void onConfigEvent(ConfiguredType confType) {
+ for (ConfiguredField field : confType.getConfiguredFields()) {
+ Collection<String> keys = field.getConfiguredKeys();
+ for (String key : keys) {
+ ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
+ if (val == null) {
+ ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
+ .setType(field.getType().getName())
+ .setDescription("Injected field: " +
+ field.getAnnotatedField().getDeclaringClass().getName() + '.' + field.toString() +
+ ", \nconfigured with keys: " + keys)
+ .build());
+ }
+ }
+ }
+ for (ConfiguredMethod method : confType.getConfiguredMethods()) {
+ Collection<String> keys = method.getConfiguredKeys();
+ for (String key : keys) {
+ ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
+ if (val == null) {
+ ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
+ .setType(method.getParameterTypes()[0].getName())
+ .setDescription("Injected field: " +
+ method.getAnnotatedMethod().getDeclaringClass().getName() + '.' + method.toString() +
+ ", \nconfigured with keys: " + keys)
+ .build());
+ }
+ }
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
new file mode 100644
index 0000000..946d99b
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
@@ -0,0 +1,51 @@
+/*
+ * 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.model.internal;
+
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Model provider that adds model definitions for the items published as
+ * {@link org.apache.tamaya.inject.spi.ConfiguredType} events.
+ */
+public class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
+ /** The collected models. */
+ private static Collection<ConfigModel> configModels = new ArrayList<>();
+
+ /**
+ * Adds a model, called from the registered listener class.
+ * @param configModel adds the config model.
+ */
+ static void addValidation(ConfigModel configModel){
+ List<ConfigModel> newList = new ArrayList<>(configModels);
+ newList.add(configModel);
+ ConfiguredTypeEventsModelProvider.configModels = newList;
+ }
+
+ @Override
+ public Collection<ConfigModel> getConfigModels() {
+ return Collections.unmodifiableCollection(configModels);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/AbstractModel.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/AbstractModel.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/AbstractModel.java
new file mode 100644
index 0000000..726f365
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/AbstractModel.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.tamaya.model.spi;
+
+import org.apache.tamaya.model.ConfigModel;
+
+import java.util.Objects;
+
+/**
+ * Default configuration Model for a configuration area.
+ */
+public abstract class AbstractModel implements ConfigModel, Comparable<ConfigModel> {
+
+ private String name;
+ private String provider;
+ private String description;
+ private boolean required = false;
+
+
+ protected AbstractModel(String name, boolean required, String description, String provider) {
+ this.name = Objects.requireNonNull(name);
+ this.description = description;
+ this.required = required;
+ this.provider = provider;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getProvider() {
+ return provider;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public boolean isRequired() {
+ return required;
+ }
+
+ @Override
+ public int compareTo(ConfigModel configModel) {
+ int compare = getType().compareTo(configModel.getType());
+ if (compare != 0) {
+ return compare;
+ }
+ return getName().compareTo(configModel.getName());
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ AbstractModel that = (AbstractModel) o;
+ return getType().equals(that.getType()) && name.equals(that.name);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return getType().hashCode() + name.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8f2a689d/modules/model/src/main/java/org/apache/tamaya/model/spi/AbstractValidation.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/AbstractValidation.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/AbstractValidation.java
deleted file mode 100644
index d411198..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/AbstractValidation.java
+++ /dev/null
@@ -1,89 +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.model.spi;
-
-import org.apache.tamaya.model.Validation;
-
-import java.util.Objects;
-
-/**
- * Default configuration Model for a configuration area.
- */
-public abstract class AbstractValidation implements Validation, Comparable<Validation> {
-
- private String name;
- private String provider;
- private String description;
- private boolean required = false;
-
-
- protected AbstractValidation(String name, boolean required, String description, String provider) {
- this.name = Objects.requireNonNull(name);
- this.description = description;
- this.required = required;
- this.provider = provider;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getProvider() {
- return provider;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public boolean isRequired() {
- return required;
- }
-
- @Override
- public int compareTo(Validation validation) {
- int compare = getType().compareTo(validation.getType());
- if (compare != 0) {
- return compare;
- }
- return getName().compareTo(validation.getName());
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- AbstractValidation that = (AbstractValidation) o;
- return getType().equals(that.getType()) && name.equals(that.name);
-
- }
-
- @Override
- public int hashCode() {
- return getType().hashCode() + name.hashCode();
- }
-}
[3/6] incubator-tamaya git commit: Added feature to send
ConfiguredType event using BeanManager for configured beans,
if tamaya-events is loaded.
Posted by an...@apache.org.
Added feature to send ConfiguredType event using BeanManager for configured beans, if tamaya-events is loaded.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/4f3d4be8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/4f3d4be8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/4f3d4be8
Branch: refs/heads/master
Commit: 4f3d4be87d41be8aff215b35b674b735c63cf8c7
Parents: cf6b411
Author: anatole <an...@apache.org>
Authored: Mon Nov 30 08:32:56 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Nov 30 08:32:56 2015 +0100
----------------------------------------------------------------------
modules/injection/pom.xml | 11 +-
.../ConfigTemplateInvocationHandler.java | 24 +-
.../tamaya/inject/internal/ConfiguredField.java | 152 ------------
.../inject/internal/ConfiguredFieldImpl.java | 167 +++++++++++++
.../inject/internal/ConfiguredSetterMethod.java | 44 +++-
.../tamaya/inject/internal/ConfiguredType.java | 228 ------------------
.../inject/internal/ConfiguredTypeImpl.java | 234 +++++++++++++++++++
.../internal/DefaultConfigurationInjector.java | 7 +-
.../tamaya/inject/internal/InjectionHelper.java | 26 +++
...pache.tamaya.model.spi.ValidationProviderSpi | 20 --
10 files changed, 479 insertions(+), 434 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection/pom.xml b/modules/injection/pom.xml
index b5c87b3..ee532e1 100644
--- a/modules/injection/pom.xml
+++ b/modules/injection/pom.xml
@@ -43,7 +43,7 @@ under the License.
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-injection-api</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
@@ -54,7 +54,7 @@ under the License.
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-events</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
@@ -69,9 +69,10 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext.model</groupId>
- <artifactId>tamaya-model</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-events</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
index 4e41656..9b69da9 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
@@ -19,8 +19,10 @@
package org.apache.tamaya.inject.internal;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.spi.ConfiguredType;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -37,29 +39,21 @@ public final class ConfigTemplateInvocationHandler implements InvocationHandler
private ConfiguredType type;
/**
- * The configuration instance of this proxy.
- */
- private Configuration configuration;
-
- /**
* Creates a new handler instance.
*
* @param type the target type, not null.
- * @param configuration the configuration to be used for evaluating the values for injection into {@code instance},
- * not null.
*/
- public ConfigTemplateInvocationHandler(Class<?> type, Configuration configuration) {
- Objects.requireNonNull(configuration);
- this.type = new ConfiguredType(Objects.requireNonNull(type));
+ public ConfigTemplateInvocationHandler(Class<?> type) {
+ this.type = new ConfiguredTypeImpl(Objects.requireNonNull(type));
if (!type.isInterface()) {
throw new IllegalArgumentException("Can only proxy interfaces as configuration templates.");
}
- this.configuration = Objects.requireNonNull(configuration);
- ModelPopulator.registerTemplate(type);
+ InjectionHelper.sendConfigurationEvent(this.type);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ Configuration config = ConfigurationProvider.getConfiguration();
if ("toString".equals(method.getName())) {
return "Configured Proxy -> " + this.type.getType().getName();
} else if ("hashCode".equals(method.getName())) {
@@ -67,13 +61,13 @@ public final class ConfigTemplateInvocationHandler implements InvocationHandler
} else if ("equals".equals(method.getName())) {
return Objects.equals(proxy, args[0]);
} else if ("get".equals(method.getName())) {
- return this.configuration;
+ return config;
}
if (method.getReturnType() == DynamicValue.class) {
- return DefaultDynamicValue.of(method, configuration);
+ return DefaultDynamicValue.of(method, config);
}
String[] retKey = new String[1];
- String configValue = InjectionHelper.getConfigValue(method, retKey, configuration);
+ String configValue = InjectionHelper.getConfigValue(method, retKey, config);
return InjectionHelper.adaptValue(method, TypeLiteral.of(method.getReturnType()), retKey[0], configValue);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
deleted file mode 100644
index e734171..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
+++ /dev/null
@@ -1,152 +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.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.inject.api.DynamicValue;
-import org.apache.tamaya.inject.api.InjectionUtils;
-
-import java.lang.reflect.Field;
-import java.security.AccessController;
-import java.security.PrivilegedExceptionAction;
-import java.util.Collection;
-import java.util.Objects;
-
-/**
- * Small class that contains and manages all information anc access to a configured field and a concrete instance current
- * it (referenced by a weak reference). It also implements all aspects current keys filtering, converting any applying the
- * final keys by reflection.
- */
-public class ConfiguredField {
- /**
- * The configured field instance.
- */
- protected Field annotatedField;
-
- /**
- * Models a configured field and provides mechanisms for injection.
- *
- * @param field the field instance.
- */
- public ConfiguredField(Field field) {
- Objects.requireNonNull(field);
- this.annotatedField = field;
- }
-
-
- /**
- * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
- *
- * @param target the target instance.
- * @throws ConfigException if evaluation or conversion failed.
- */
- public void applyValue(Object target,Configuration config) throws ConfigException {
- if (this.annotatedField.getType() == DynamicValue.class) {
- applyDynamicValue(target);
- } else {
- applyValue(target, config, false);
- }
- }
-
-
- /**
- * This method instantiates and assigns a dynamic value.
- *
- * @param target the target instance, not null.
- * @throws ConfigException if the configuration required could not be resolved or converted.
- */
- private void applyDynamicValue(Object target) throws ConfigException {
- Objects.requireNonNull(target);
- try {
- AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
- @Override
- public Object run() throws Exception {
- annotatedField.setAccessible(true);
- return annotatedField;
- }
- });
- annotatedField.set(target,
- DefaultDynamicValue.of(annotatedField, ConfigurationProvider.getConfiguration()));
- } catch (Exception e) {
- throw new ConfigException("Failed to annotation configured field: " + this.annotatedField.getDeclaringClass()
- .getName() + '.' + annotatedField.getName(), e);
- }
- }
-
- /**
- * This method applies a configuration to the field.
- *
- * @param target the target instance, not null.
- * @param resolve set to true, if expression resolution should be applied on the keys passed.
- * @throws ConfigException if the configuration required could not be resolved or converted.
- */
- private void applyValue(Object target, Configuration config, boolean resolve) throws ConfigException {
- Objects.requireNonNull(target);
- try {
- String[] retKey = new String[1];
- String configValue = InjectionHelper.getConfigValue(this.annotatedField, retKey, config);
- // Next step perform expression resolution, if any
- String evaluatedValue = resolve && configValue != null
- ? InjectionHelper.evaluateValue(configValue)
- : configValue;
-
- // Check for adapter/filter
- Object value = InjectionHelper.adaptValue(this.annotatedField,
- TypeLiteral.of(this.annotatedField.getType()), retKey[0], evaluatedValue);
- AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
- @Override
- public Object run() throws Exception {
- annotatedField.setAccessible(true);
- return annotatedField;
- }
- });
- annotatedField.set(target, value);
- } catch (Exception e) {
- throw new ConfigException("Failed to evaluate annotated field: " + this.annotatedField.getDeclaringClass()
- .getName() + '.' + annotatedField.getName(), e);
- }
- }
-
- /**
- * Get the field's type.
- * @return the field's type, not null.
- */
- public Class<?> getType(){
- return this.annotatedField.getType();
- }
-
- /**
- * Access the applyable configuration keys for this field.
- * @return the configuration keys, never null.
- */
- public Collection<String> getConfiguredKeys(){
- return InjectionUtils.getKeys(this.annotatedField);
- }
-
- @Override
- public String toString() {
- return "ConfiguredField{" +
- annotatedField.getName() + ": " +
- " " + annotatedField.getDeclaringClass().getName() + '}';
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
new file mode 100644
index 0000000..086265b
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
@@ -0,0 +1,167 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.api.InjectionUtils;
+import org.apache.tamaya.inject.spi.ConfiguredField;
+
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+import java.util.Collection;
+import java.util.Objects;
+
+/**
+ * Small class that contains and manages all information anc access to a configured field and a concrete instance current
+ * it (referenced by a weak reference). It also implements all aspects current keys filtering, converting any applying the
+ * final keys by reflection.
+ */
+public class ConfiguredFieldImpl implements ConfiguredField{
+ /**
+ * The configured field instance.
+ */
+ protected Field annotatedField;
+
+ /**
+ * Models a configured field and provides mechanisms for injection.
+ *
+ * @param field the field instance.
+ */
+ public ConfiguredFieldImpl(Field field) {
+ Objects.requireNonNull(field);
+ this.annotatedField = field;
+ }
+
+
+ /**
+ * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
+ *
+ * @param target the target instance.
+ * @throws ConfigException if evaluation or conversion failed.
+ */
+ public void configure(Object target, Configuration config) throws ConfigException {
+ if (this.annotatedField.getType() == DynamicValue.class) {
+ applyDynamicValue(target);
+ } else {
+ applyValue(target, config, false);
+ }
+ }
+
+
+ /**
+ * This method instantiates and assigns a dynamic value.
+ *
+ * @param target the target instance, not null.
+ * @throws ConfigException if the configuration required could not be resolved or converted.
+ */
+ private void applyDynamicValue(Object target) throws ConfigException {
+ Objects.requireNonNull(target);
+ try {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ @Override
+ public Object run() throws Exception {
+ annotatedField.setAccessible(true);
+ return annotatedField;
+ }
+ });
+ annotatedField.set(target,
+ DefaultDynamicValue.of(annotatedField, ConfigurationProvider.getConfiguration()));
+ } catch (Exception e) {
+ throw new ConfigException("Failed to annotation configured field: " + this.annotatedField.getDeclaringClass()
+ .getName() + '.' + annotatedField.getName(), e);
+ }
+ }
+
+ /**
+ * This method applies a configuration to the field.
+ *
+ * @param target the target instance, not null.
+ * @param resolve set to true, if expression resolution should be applied on the keys passed.
+ * @throws ConfigException if the configuration required could not be resolved or converted.
+ */
+ private void applyValue(Object target, Configuration config, boolean resolve) throws ConfigException {
+ Objects.requireNonNull(target);
+ try {
+ String[] retKey = new String[1];
+ String configValue = InjectionHelper.getConfigValue(this.annotatedField, retKey, config);
+ // Next step perform expression resolution, if any
+ String evaluatedValue = resolve && configValue != null
+ ? InjectionHelper.evaluateValue(configValue)
+ : configValue;
+
+ // Check for adapter/filter
+ Object value = InjectionHelper.adaptValue(this.annotatedField,
+ TypeLiteral.of(this.annotatedField.getType()), retKey[0], evaluatedValue);
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ @Override
+ public Object run() throws Exception {
+ annotatedField.setAccessible(true);
+ return annotatedField;
+ }
+ });
+ annotatedField.set(target, value);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to evaluate annotated field: " + this.annotatedField.getDeclaringClass()
+ .getName() + '.' + annotatedField.getName(), e);
+ }
+ }
+
+ /**
+ * Get the field's type.
+ * @return the field's type, not null.
+ */
+ @Override
+ public Class<?> getType(){
+ return this.annotatedField.getType();
+ }
+
+ /**
+ * Access the applyable configuration keys for this field.
+ * @return the configuration keys, never null.
+ */
+ @Override
+ public Collection<String> getConfiguredKeys(){
+ return InjectionUtils.getKeys(this.annotatedField);
+ }
+
+ @Override
+ public String toString() {
+ return "ConfiguredField[" + getSignature() + ']';
+ }
+
+ @Override
+ public String getName() {
+ return annotatedField.getName();
+ }
+
+ @Override
+ public String getSignature() {
+ return getName()+':'+getType().getName();
+ }
+
+ @Override
+ public Field getAnnotatedField() {
+ return annotatedField;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
index 3095553..a731dec 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
@@ -22,6 +22,7 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.inject.api.InjectionUtils;
+import org.apache.tamaya.inject.spi.ConfiguredMethod;
import java.lang.reflect.Method;
import java.security.AccessController;
@@ -34,7 +35,7 @@ import java.util.Objects;
* it (referenced by a weak reference). It also implements all aspects current keys filtering, conversions any applying the
* final keys by reflection.
*/
-public class ConfiguredSetterMethod {
+public class ConfiguredSetterMethod implements ConfiguredMethod {
/**
* The configured field instance.
@@ -54,18 +55,13 @@ public class ConfiguredSetterMethod {
}
}
- /**
- * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
- *
- * @param target the target instance.
- * @throws ConfigException if evaluation or conversion failed.
- */
- public void applyValue(Object target, Configuration config, boolean resolve) throws ConfigException {
+ @Override
+ public void configure(Object target, Configuration config) throws ConfigException {
String[] retKey = new String[1];
String configValue = InjectionHelper.getConfigValue(this.setterMethod, retKey, config);
Objects.requireNonNull(target);
try {
- String evaluatedString = resolve && configValue != null
+ String evaluatedString = configValue != null
? InjectionHelper.evaluateValue(configValue)
: configValue;
@@ -95,6 +91,7 @@ public class ConfiguredSetterMethod {
*
* @return the configuration keys, never null.
*/
+ @Override
public Collection<String> getConfiguredKeys() {
return InjectionUtils.getKeys(this.setterMethod);
}
@@ -103,15 +100,40 @@ public class ConfiguredSetterMethod {
* Get the type to be set on the setter method.
* @return
*/
- public Class<?> getParameterType() {
- return this.setterMethod.getParameterTypes()[0];
+ @Override
+ public Class<?>[] getParameterTypes() {
+ return this.setterMethod.getParameterTypes();
}
/**
* Access the annotated method.
* @return the annotated method, not null.
*/
+ @Override
public Method getAnnotatedMethod() {
return this.setterMethod;
}
+
+ @Override
+ public String getName() {
+ return this.setterMethod.getName();
+ }
+
+ @Override
+ public String getSignature() {
+ return "void " + this.setterMethod.getName()+'('+ printTypes(getParameterTypes())+')';
+ }
+
+ private String printTypes(Class<?>[] parameterTypes) {
+ StringBuilder b = new StringBuilder();
+ for(Class cl:parameterTypes){
+ b.append(cl.getName());
+ b.append(',');
+ }
+ if(b.length()>0){
+ b.setLength(b.length()-1);
+ }
+ return b.toString();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
deleted file mode 100644
index 4bceeea..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
+++ /dev/null
@@ -1,228 +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.internal;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.*;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.inject.ConfigAutoInject;
-import org.apache.tamaya.inject.NoConfig;
-import org.apache.tamaya.inject.api.Config;
-import org.apache.tamaya.inject.api.ConfigDefaultSections;
-
-/**
- * Structure that contains and manages configuration related things for a configured type registered.
- * Created by Anatole on 03.10.2014.
- */
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class ConfiguredType {
- /** The log used. */
- private static final Logger LOG = Logger.getLogger(ConfiguredType.class.getName());
- /**
- * A list with all annotated instance variables.
- */
- private List<ConfiguredField> configuredFields = new ArrayList<>();
- /**
- * A list with all annotated methods (templates).
- */
- private List<ConfiguredSetterMethod> configuredSetterMethods = new ArrayList<>();
- /**
- * The basic type.
- */
- private Class type;
-
- /**
- * Creates an instance of this class hereby evaluating the config annotations given for later effective
- * injection (configuration) of instances.
- *
- * @param type the instance type.
- */
-
- public ConfiguredType(Class type) {
- this.type = Objects.requireNonNull(type);
- ConfigDefaultSections confType = (ConfigDefaultSections)
- type.getAnnotation(ConfigDefaultSections.class);
- ConfigAutoInject autoInject = (ConfigAutoInject)type.getAnnotation(ConfigAutoInject.class);
- if(confType!=null){
- initFields(type, autoInject!=null);
- initMethods(type, autoInject!=null);
- }else{
- initFields(type, false);
- initMethods(type, false);
- }
- }
-
- private void initFields(Class type, boolean autoConfigure) {
- for (Field f : type.getDeclaredFields()) {
- if (f.isAnnotationPresent(NoConfig.class)) {
- LOG.finest("Ignored @NoConfig annotated field " + f.getClass().getName() + "#" +
- f.toGenericString());
- continue;
- }
- if (Modifier.isFinal(f.getModifiers())) {
- LOG.finest("Ignored final field " + f.getClass().getName() + "#" +
- f.toGenericString());
- continue;
- }
- if (f.isSynthetic()) {
- LOG.finest("Ignored synthetic field " + f.getClass().getName() + "#" +
- f.toGenericString());
- continue;
- }
- try {
- if(isConfiguredField(f) || autoConfigure) {
- ConfiguredField configuredField = new ConfiguredField(f);
- configuredFields.add(configuredField);
- LOG.finer("Registered field " + f.getClass().getName() + "#" +
- f.toGenericString());
- }
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured field: " +
- f.getDeclaringClass().getName() + '.' + f.getName(), e);
- }
- }
- }
-
- private void initMethods(Class type, boolean autoConfigure) {
- // TODO revisit this logic here...
- for (Method m : type.getDeclaredMethods()) {
- if (m.isAnnotationPresent(NoConfig.class)) {
- LOG.finest("Ignored @NoConfig annotated method " + m.getClass().getName() + "#" +
- m.toGenericString());
- continue;
- }
- if (m.isSynthetic()) {
- LOG.finest("Ignored synthetic method " + m.getClass().getName() + "#" +
- m.toGenericString());
- continue;
- }
- if(isConfiguredMethod(m) || autoConfigure) {
- Config propAnnot = m.getAnnotation(Config.class);
- if (addPropertySetter(m, propAnnot)) {
- LOG.finer("Added configured setter: " + m.getClass().getName() + "#" +
- m.toGenericString());
- }
- }
- }
- }
-
- private boolean addPropertySetter(Method m, Config prop) {
- if (prop!=null) {
- if (m.getParameterTypes().length == 1) {
- // getter method
- Class<?> returnType = m.getReturnType();
- if (void.class.equals(returnType)) {
- try {
- configuredSetterMethods.add(new ConfiguredSetterMethod(m));
- return true;
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured setter method: " +
- m.getDeclaringClass().getName() + '.' + m.getName(), e);
- }
- }
- }
- }
- return false;
- }
-
-
- /**
- * Method called to configure an instance.
- *
- * @param instance The instance to be configured.
- */
- public void configure(Object instance) {
- configure(instance, ConfigurationProvider.getConfiguration());
- }
-
- /**
- * Method called to configure an instance.
- *
- * @param instance The instance to be configured.
- * @param config the target config.
- */
- public void configure(Object instance, Configuration config) {
- for (ConfiguredField field : configuredFields) {
- field.applyValue(instance, config);
- }
- for (ConfiguredSetterMethod method : configuredSetterMethods) {
- method.applyValue(instance, config, true);
-// // TODO, if method should be recalled on changes, corresponding callbacks could be registered here
- }
- }
-
-
- public static boolean isConfigured(Class type) {
- if (type.getAnnotation(ConfigDefaultSections.class) != null) {
- return true;
- }
- // if no class level annotation is there we might have field level annotations only
- for (Field field : type.getDeclaredFields()) {
- if (isConfiguredField(field)) {
- return true;
- }
- }
- // if no class level annotation is there we might have method level annotations only
- for (Method method : type.getDeclaredMethods()) {
- if(isConfiguredMethod(method)) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean isConfiguredField(Field field) {
- return field.isAnnotationPresent(Config.class);
- }
-
- public static boolean isConfiguredMethod(Method method) {
- return method.isAnnotationPresent(Config.class);
- }
-
- public Class getType() {
- return this.type;
- }
-
- /**
- * Get the registered configured fields.
- * @return the registered configured fields, never null.
- */
- public Collection<ConfiguredField> getConfiguredFields(){
- return configuredFields;
- }
-
- /**
- * Get the registered annotated setter methods.
- * @return the registered annotated setter methods, never null.
- */
- public Collection<ConfiguredSetterMethod> getConfiguredSetterMethods(){
- return configuredSetterMethods;
- }
-
- @Override
- public String toString() {
- return "ConfigDefaultSections{"+ this.getType().getName() + '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
new file mode 100644
index 0000000..0c22e1c
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
@@ -0,0 +1,234 @@
+/*
+ * 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.internal;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.*;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.inject.ConfigAutoInject;
+import org.apache.tamaya.inject.NoConfig;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
+import org.apache.tamaya.inject.spi.ConfiguredField;
+import org.apache.tamaya.inject.spi.ConfiguredMethod;
+import org.apache.tamaya.inject.spi.ConfiguredType;
+
+/**
+ * Structure that contains and manages configuration related things for a configured type registered.
+ * Created by Anatole on 03.10.2014.
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class ConfiguredTypeImpl implements ConfiguredType{
+ /** The log used. */
+ private static final Logger LOG = Logger.getLogger(ConfiguredTypeImpl.class.getName());
+ /**
+ * A list with all annotated instance variables.
+ */
+ private List<ConfiguredField> configuredFields = new ArrayList<>();
+ /**
+ * A list with all annotated methods (templates).
+ */
+ private List<ConfiguredMethod> configuredSetterMethods = new ArrayList<>();
+ /**
+ * The basic type.
+ */
+ private Class type;
+
+ /**
+ * Creates an instance of this class hereby evaluating the config annotations given for later effective
+ * injection (configuration) of instances.
+ *
+ * @param type the instance type.
+ */
+
+ public ConfiguredTypeImpl(Class type) {
+ this.type = Objects.requireNonNull(type);
+ ConfigDefaultSections confType = (ConfigDefaultSections)
+ type.getAnnotation(ConfigDefaultSections.class);
+ ConfigAutoInject autoInject = (ConfigAutoInject)type.getAnnotation(ConfigAutoInject.class);
+ if(confType!=null){
+ initFields(type, autoInject!=null);
+ initMethods(type, autoInject!=null);
+ }else{
+ initFields(type, false);
+ initMethods(type, false);
+ }
+ }
+
+ private void initFields(Class type, boolean autoConfigure) {
+ for (Field f : type.getDeclaredFields()) {
+ if (f.isAnnotationPresent(NoConfig.class)) {
+ LOG.finest("Ignored @NoConfig annotated field " + f.getClass().getName() + "#" +
+ f.toGenericString());
+ continue;
+ }
+ if (Modifier.isFinal(f.getModifiers())) {
+ LOG.finest("Ignored final field " + f.getClass().getName() + "#" +
+ f.toGenericString());
+ continue;
+ }
+ if (f.isSynthetic()) {
+ LOG.finest("Ignored synthetic field " + f.getClass().getName() + "#" +
+ f.toGenericString());
+ continue;
+ }
+ try {
+ if(isConfiguredField(f) || autoConfigure) {
+ ConfiguredField configuredField = new ConfiguredFieldImpl(f);
+ configuredFields.add(configuredField);
+ LOG.finer("Registered field " + f.getClass().getName() + "#" +
+ f.toGenericString());
+ }
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured field: " +
+ f.getDeclaringClass().getName() + '.' + f.getName(), e);
+ }
+ }
+ }
+
+ private void initMethods(Class type, boolean autoConfigure) {
+ // TODO revisit this logic here...
+ for (Method m : type.getDeclaredMethods()) {
+ if (m.isAnnotationPresent(NoConfig.class)) {
+ LOG.finest("Ignored @NoConfig annotated method " + m.getClass().getName() + "#" +
+ m.toGenericString());
+ continue;
+ }
+ if (m.isSynthetic()) {
+ LOG.finest("Ignored synthetic method " + m.getClass().getName() + "#" +
+ m.toGenericString());
+ continue;
+ }
+ if(isConfiguredMethod(m) || autoConfigure) {
+ Config propAnnot = m.getAnnotation(Config.class);
+ if (addPropertySetter(m, propAnnot)) {
+ LOG.finer("Added configured setter: " + m.getClass().getName() + "#" +
+ m.toGenericString());
+ }
+ }
+ }
+ }
+
+ private boolean addPropertySetter(Method m, Config prop) {
+ if (prop!=null) {
+ if (m.getParameterTypes().length == 1) {
+ // getter method
+ Class<?> returnType = m.getReturnType();
+ if (void.class.equals(returnType)) {
+ try {
+ configuredSetterMethods.add(new ConfiguredSetterMethod(m));
+ return true;
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured setter method: " +
+ m.getDeclaringClass().getName() + '.' + m.getName(), e);
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * Method called to configure an instance.
+ *
+ * @param instance The instance to be configured.
+ */
+ public void configure(Object instance) {
+ configure(instance, ConfigurationProvider.getConfiguration());
+ }
+
+ @Override
+ public void configure(Object instance, Configuration config) {
+ for (ConfiguredField field : configuredFields) {
+ field.configure(instance, config);
+ }
+ for (ConfiguredMethod method : configuredSetterMethods) {
+ method.configure(instance, config);
+// // TODO, if method should be recalled on changes, corresponding callbacks could be registered here
+ }
+ }
+
+
+ public static boolean isConfigured(Class type) {
+ if (type.getAnnotation(ConfigDefaultSections.class) != null) {
+ return true;
+ }
+ // if no class level annotation is there we might have field level annotations only
+ for (Field field : type.getDeclaredFields()) {
+ if (isConfiguredField(field)) {
+ return true;
+ }
+ }
+ // if no class level annotation is there we might have method level annotations only
+ for (Method method : type.getDeclaredMethods()) {
+ if(isConfiguredMethod(method)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean isConfiguredField(Field field) {
+ return field.isAnnotationPresent(Config.class);
+ }
+
+ public static boolean isConfiguredMethod(Method method) {
+ return method.isAnnotationPresent(Config.class);
+ }
+
+ @Override
+ public Class getType() {
+ return this.type;
+ }
+
+ @Override
+ public String getName() {
+ return this.type.getName();
+ }
+
+ /**
+ * Get the registered configured fields.
+ * @return the registered configured fields, never null.
+ */
+ @Override
+ public Collection<ConfiguredField> getConfiguredFields(){
+ return configuredFields;
+ }
+
+ /**
+ * Get the registered annotated setter methods.
+ * @return the registered annotated setter methods, never null.
+ */
+ @Override
+ public Collection<ConfiguredMethod> getConfiguredMethods(){
+ return configuredSetterMethods;
+ }
+
+ @Override
+ public String toString() {
+ return "ConfigDefaultSections{"+ this.getType().getName() + '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
index 17b9657..db0baa7 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
@@ -35,6 +35,7 @@ import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
import org.apache.tamaya.inject.NoConfig;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefaultSections;
+import org.apache.tamaya.inject.spi.ConfiguredType;
/**
* Simple injector singleton that also registers instances configured using weak references.
@@ -55,9 +56,9 @@ public final class DefaultConfigurationInjector implements ConfigurationInjector
public ConfiguredType registerType(Class<?> type) {
ConfiguredType confType = configuredTypes.get(type);
if (confType == null && isConfigured(type)) {
- confType = new ConfiguredType(type);
- ModelPopulator.register(confType);
+ confType = new ConfiguredTypeImpl(type);
configuredTypes.put(type, confType);
+ InjectionHelper.sendConfigurationEvent(confType);
}
return confType;
// return configuredTypes.computeIfAbsent(type, ConfigDefaultSections::new);
@@ -138,7 +139,7 @@ public final class DefaultConfigurationInjector implements ConfigurationInjector
cl = this.getClass().getClassLoader();
}
return templateType.cast(Proxy.newProxyInstance(cl, new Class[]{ConfiguredItemSupplier.class, Objects.requireNonNull(templateType)},
- new ConfigTemplateInvocationHandler(templateType, ConfigurationProvider.getConfiguration())));
+ new ConfigTemplateInvocationHandler(templateType)));
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
index 5c0d9f8..fa4ba03 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
@@ -30,11 +30,13 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.events.ConfigEventManager;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefault;
import org.apache.tamaya.inject.api.ConfigDefaultSections;
import org.apache.tamaya.inject.api.InjectionUtils;
import org.apache.tamaya.inject.api.WithPropertyConverter;
+import org.apache.tamaya.inject.spi.ConfiguredType;
import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
@@ -51,6 +53,20 @@ final class InjectionHelper {
private static final boolean RESOLUTION_MODULE_LOADED = checkResolutionModuleLoaded();
+ private static boolean EVENTS_AVAILABLE = checkForEvents();
+
+ private static boolean checkForEvents() {
+ try{
+ Class.forName("org.apache.tamaya.events.FrozenConfiguration");
+ LOG.info("Detected tamaya-events is loaded, will trigger ConfigEvents...");
+ return true;
+ }
+ catch(Exception e){
+ LOG.info("Detected tamaya-events not found, will not trigger any ConfigEvents...");
+ return false;
+ }
+ }
+
private static boolean checkResolutionModuleLoaded() {
try {
Class.forName("org.apache.tamaya.resolver.internal.DefaultExpressionEvaluator");
@@ -209,4 +225,14 @@ final class InjectionHelper {
return expression;
}
+ /**
+ * This method distributes the configuration event, if the Tamaya event module is accessible.
+ * When Tamaya events are not available, the call simply returns.
+ * @param event the event to be distributed, not null.
+ */
+ static void sendConfigurationEvent(ConfiguredType event) {
+ if(EVENTS_AVAILABLE){
+ ConfigEventManager.fireEvent(event);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4f3d4be8/modules/injection/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi b/modules/injection/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
deleted file mode 100644
index ef93b75..0000000
--- a/modules/injection/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
+++ /dev/null
@@ -1,20 +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.
-#
-# Note: this provider is loaded by the model extension module
-org.apache.tamaya.inject.internal.InjectableValidationProvider
\ No newline at end of file