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 2017/04/18 09:39:19 UTC
[1/7] incubator-tamaya-sandbox git commit: TAMAYA-150: Renabled UI
after refactoring out several functionality into separate modules.
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master 5ee4802c7 -> d344e7323
TAMAYA-150: Renabled UI after refactoring out several functionality into separate modules.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/fd26d6c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/fd26d6c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/fd26d6c0
Branch: refs/heads/master
Commit: fd26d6c0b0e4cd44d6408b4449a01e946886f59b
Parents: 5ee4802
Author: anatole <an...@apache.org>
Authored: Sat Apr 15 22:10:03 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Sat Apr 15 22:10:03 2017 +0200
----------------------------------------------------------------------
ui/base/pom.xml | 9 +
.../org/apache/tamaya/ui/ApplicationLayout.java | 39 ++-
.../main/java/org/apache/tamaya/ui/NavBar.java | 8 +-
.../java/org/apache/tamaya/ui/TamayaUI.java | 75 +++++-
.../java/org/apache/tamaya/ui/UIConstants.java | 2 +
.../java/org/apache/tamaya/ui/VadiinApp.java | 97 -------
.../java/org/apache/tamaya/ui/ViewProvider.java | 73 -----
.../ConfigurationBasedMessageProvider.java | 6 +-
.../ui/internal/ConfiguredUserService.java | 2 +-
.../tamaya/ui/internal/PageTitleUpdater.java | 4 +-
.../internal/ResourceBundleMessageProvider.java | 182 ++++++-------
.../tamaya/ui/internal/URLPropertySource.java | 78 ------
.../ui/internal/VerticalSpacedLayout.java | 4 +-
.../org/apache/tamaya/ui/spi/LazyProvider.java | 81 ------
.../apache/tamaya/ui/spi/MessageProvider.java | 2 +-
.../tamaya/ui/spi/SystemInfoProvider.java | 15 ++
.../org/apache/tamaya/ui/spi/UserService.java | 2 +-
.../ui/views/AbstractTextInfoProvider.java | 67 +++++
.../org/apache/tamaya/ui/views/ConfigView.java | 263 ++++++++-----------
.../org/apache/tamaya/ui/views/HomeView.java | 48 +---
.../org/apache/tamaya/ui/views/SystemView.java | 77 ++----
.../views/TamayaGeneralSystemInfoProvider.java | 112 ++++++--
.../apache/tamaya/ui/views/login/LoginBox.java | 4 +-
.../services/org.apache.tamaya.ui.ViewProvider | 3 -
...rg.apache.tamaya.ui.services.MessageProvider | 19 --
.../org.apache.tamaya.ui.services.UserService | 19 --
.../org.apache.tamaya.ui.spi.MessageProvider | 19 ++
.../org.apache.tamaya.ui.spi.SystemInfoProvider | 19 ++
.../org.apache.tamaya.ui.spi.UserService | 19 ++
.../main/resources/ui/lang/tamaya.properties | 6 +-
ui/pom.xml | 88 ++++++-
31 files changed, 665 insertions(+), 777 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/pom.xml
----------------------------------------------------------------------
diff --git a/ui/base/pom.xml b/ui/base/pom.xml
index 40914d8..c300feb 100644
--- a/ui/base/pom.xml
+++ b/ui/base/pom.xml
@@ -33,6 +33,10 @@ under the License.
<artifactId>tamaya-ui-base_alpha</artifactId>
<name>Apache Tamaya Modules - UI (Base)</name>
+ <properties>
+ <mainClass>org.apache.tamaya.ui.VadiinApp</mainClass>
+ </properties>
+
<build>
<plugins>
<plugin>
@@ -151,6 +155,11 @@ under the License.
<enabled>true</enabled>
</snapshots>
</repository>
+ <repository>
+ <id>vaadin-prereleases</id>
+ <name>Vaadin Pre-releases</name>
+ <url>https://maven.vaadin.com/vaadin-prereleases</url>
+ </repository>
</repositories>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java b/ui/base/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java
index 20190be..f1dd7e7 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java
@@ -18,11 +18,18 @@
*/
package org.apache.tamaya.ui;
+import com.vaadin.navigator.Navigator;
+import com.vaadin.navigator.View;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
-import org.apache.tamaya.ui.components.PageTitleUpdater;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.ui.spi.MessageProvider;
+import org.apache.tamaya.ui.views.ConfigView;
import org.apache.tamaya.ui.views.ErrorView;
+import org.apache.tamaya.ui.views.HomeView;
+import org.apache.tamaya.ui.views.SystemView;
/**
@@ -32,7 +39,7 @@ public class ApplicationLayout extends HorizontalLayout {
private NavBar navBar;
private Panel content;
- private NavigationBar navigator;
+ private Navigator navigator;
public ApplicationLayout(UI ui) {
addStyleName(UIConstants.MAIN_LAYOUT);
@@ -41,7 +48,7 @@ public class ApplicationLayout extends HorizontalLayout {
setupNavigator(ui);
}
- public NavigationBar getNavigationBar(){
+ public Navigator getNavigator(){
return navigator;
}
@@ -56,16 +63,32 @@ public class ApplicationLayout extends HorizontalLayout {
setExpandRatio(content, 1);
}
+ public void addView(String uri, Class<? extends View> viewClass, String viewName){
+ navigator.addView(uri, viewClass);
+ navBar.addViewButton(uri, viewName);
+ }
- private void setupNavigator(UI ui) {
- navigator = new NavigationBar(ui, content, navBar);
+ private void setupNavigator(UI ui) {
+ navigator = new Navigator(ui, content);
+ navigator.setErrorView(ErrorView.class);
// Add view change listeners so we can do things like select the correct menu item and update the page title
navigator.addViewChangeListener(navBar);
- navigator.addViewChangeListener(new PageTitleUpdater());
-
+// navigator.addViewChangeListener(new PageTitleUpdater());
+ addView("/home", HomeView.class, getViewName(HomeView.class));
+ addView("/system", SystemView.class, getViewName(SystemView.class));
+ addView("/config", ConfigView.class, getViewName(ConfigView.class));
navigator.navigateTo("/home");
- navigator.setErrorView(ErrorView.class);
+ }
+
+ private String getViewName(Class<? extends View> viewClass) {
+ MessageProvider prov = ServiceContextManager.getServiceContext()
+ .getService(MessageProvider.class);
+ String msg = null;
+ if(prov!=null){
+ msg = prov.getMessage("views."+viewClass.getSimpleName()+".name");
+ }
+ return msg;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/NavBar.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/NavBar.java b/ui/base/src/main/java/org/apache/tamaya/ui/NavBar.java
index 9020cd8..bdbfd49 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/NavBar.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/NavBar.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.ui;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.server.FontAwesome;
-import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
@@ -29,7 +29,7 @@ import org.apache.tamaya.spi.ServiceContextManager;
import org.apache.tamaya.ui.event.EventBus;
import org.apache.tamaya.ui.event.LogoutEvent;
import org.apache.tamaya.ui.event.NavigationEvent;
-import org.apache.tamaya.ui.services.MessageProvider;
+import org.apache.tamaya.ui.spi.MessageProvider;
import java.util.HashMap;
import java.util.Map;
@@ -74,8 +74,8 @@ public class NavBar extends VerticalLayout implements ViewChangeListener {
Button settings = new Button("...", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent clickEvent) {
- UISettingsDialog dlog = new UISettingsDialog(appLayout.getNavigationBar());
- dlog.show();
+// UISettingsDialog dlog = new UISettingsDialog(appLayout.getNavigationBar());
+// dlog.show();
}
});
settings.addStyleName(UIConstants.BUTTON_SETTINGS);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java b/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java
index f446d6f..515dcd7 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java
@@ -18,27 +18,82 @@
*/
package org.apache.tamaya.ui;
+import com.google.common.eventbus.Subscribe;
+import com.vaadin.annotations.Theme;
+import com.vaadin.annotations.Title;
+import com.vaadin.server.Page;
+import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.UI;
import org.apache.catalina.Context;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.ui.event.LogoutEvent;
+import org.apache.tamaya.ui.event.NavigationEvent;
+import org.apache.tamaya.ui.views.login.LoginEvent;
+import org.apache.tamaya.ui.views.login.LoginView;
import java.io.File;
import java.util.logging.Logger;
/**
- * Tamaya UI Main class.
+ * This UI is the application entry point. A UI may either represent a browser window
+ * (or tab) or some part of a html page where a Vaadin application is embedded.
+ * <p>
+ * The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be
+ * overridden to add component to the user interface and initialize non-component functionality.
*/
-public class TamayaUI {
+@Theme("valo")
+@Title("Tamaya")
+public class TamayaUI extends UI {
private static final Logger LOG = Logger.getLogger(TamayaUI.class.getName());
/**
* Not an instantiable class.
*/
- private TamayaUI(){}
+ public TamayaUI(){
+ super(new Panel());
+ super.setPollInterval(2000);
+ }
+
+ @Override
+ protected void init(VaadinRequest vaadinRequest) {
+ setupEventBus();
+ if (CurrentUser.isLoggedIn()) {
+ setContent(new ApplicationLayout(this));
+ } else {
+ setContent(new LoginView());
+ }
+ }
+
+ @Subscribe
+ public void userLoggedIn(
+ LoginEvent event) {
+ CurrentUser.set(event.getUser());
+ setContent(new ApplicationLayout(this));
+ }
+
+ @Subscribe
+ public void navigateTo(NavigationEvent evt) {
+ if(getNavigator()==null){
+ return;
+ }
+ if(evt.getViewName().isEmpty()){
+ getNavigator().navigateTo("/home");
+
+ }else {
+ getNavigator().navigateTo(evt.getViewName());
+ }
+ }
+
+ public static TamayaUI getCurrent() {
+ return (TamayaUI) UI.getCurrent();
+ }
/**
* The main entry point, use configuration as follows:
@@ -64,7 +119,7 @@ public class TamayaUI {
Wrapper wrapper = tomcat.addServlet(context, "vadiin-servlet",
VaadinServlet.class.getName());
wrapper.addInitParameter("ui",
- VadiinApp.class.getName());
+ TamayaUI.class.getName());
wrapper.addInitParameter("productionMode",config.getOrDefault("tamaya.server.productionMode", String.class,
"false"));
wrapper.addInitParameter("asyncSupported", "true");
@@ -74,4 +129,16 @@ public class TamayaUI {
tomcat.getServer().await();
}
+ @Subscribe
+ public void logout(LogoutEvent logoutEvent) {
+ // Don't invalidate the underlying HTTP session if you are using it for something else
+ VaadinSession.getCurrent().getSession().invalidate();
+ VaadinSession.getCurrent().close();
+ Page.getCurrent().reload();
+
+ }
+
+ private void setupEventBus() {
+ org.apache.tamaya.ui.event.EventBus.register(this);
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/UIConstants.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/UIConstants.java b/ui/base/src/main/java/org/apache/tamaya/ui/UIConstants.java
index ecf90ff..78d5855 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/UIConstants.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/UIConstants.java
@@ -33,4 +33,6 @@ public class UIConstants extends ValoTheme {
public static final String BUTTON_LOGOUT = "logout";
public static final String BUTTON_SETTINGS = BUTTON_TINY;
+
+ public static final String FIXED_FONT = "font-face: fixed;";
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/VadiinApp.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/VadiinApp.java b/ui/base/src/main/java/org/apache/tamaya/ui/VadiinApp.java
deleted file mode 100644
index 9e2510d..0000000
--- a/ui/base/src/main/java/org/apache/tamaya/ui/VadiinApp.java
+++ /dev/null
@@ -1,97 +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.ui;
-
-import com.google.common.eventbus.Subscribe;
-import com.vaadin.annotations.Theme;
-import com.vaadin.annotations.Title;
-import com.vaadin.server.Page;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinSession;
-import com.vaadin.ui.Panel;
-import com.vaadin.ui.UI;
-import org.apache.tamaya.ui.event.LogoutEvent;
-import org.apache.tamaya.ui.event.NavigationEvent;
-import org.apache.tamaya.ui.views.login.LoginEvent;
-import org.apache.tamaya.ui.views.login.LoginView;
-
-/**
- * This UI is the application entry point. A UI may either represent a browser window
- * (or tab) or some part of a html page where a Vaadin application is embedded.
- * <p>
- * The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be
- * overridden to add component to the user interface and initialize non-component functionality.
- */
-@Theme("valo")
-@Title("Tamaya")
-public class VadiinApp extends UI {
-
- public VadiinApp(){
- super(new Panel());
- super.setPollInterval(2000);
- }
-
- @Override
- protected void init(VaadinRequest vaadinRequest) {
- setupEventBus();
- if (CurrentUser.isLoggedIn()) {
- setContent(new ApplicationLayout(this));
- } else {
- setContent(new LoginView());
- }
- }
-
- @Subscribe
- public void userLoggedIn(
- LoginEvent event) {
- CurrentUser.set(event.getUser());
- setContent(new ApplicationLayout(this));
- }
-
- @Subscribe
- public void navigateTo(NavigationEvent evt) {
- if(getNavigator()==null){
- return;
- }
- if(evt.getViewName().isEmpty()){
- getNavigator().navigateTo("/home");
-
- }else {
- getNavigator().navigateTo(evt.getViewName());
- }
- }
-
- public static VadiinApp getCurrent() {
- return (VadiinApp) UI.getCurrent();
- }
-
- @Subscribe
- public void logout(LogoutEvent logoutEvent) {
- // Don't invalidate the underlying HTTP session if you are using it for something else
- VaadinSession.getCurrent().getSession().invalidate();
- VaadinSession.getCurrent().close();
- Page.getCurrent().reload();
-
- }
-
- private void setupEventBus() {
- org.apache.tamaya.ui.event.EventBus.register(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/ViewProvider.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/ViewProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/ViewProvider.java
deleted file mode 100644
index 578689f..0000000
--- a/ui/base/src/main/java/org/apache/tamaya/ui/ViewProvider.java
+++ /dev/null
@@ -1,73 +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.ui;
-
-import com.vaadin.navigator.View;
-
-/**
- * Interface to register Tamaya UI parts. For priorization also use the @Priority annotations.
- */
-public interface ViewProvider {
-
- /**
- * View lifecycle options that determine when a view is created and how long an instance is used.
- */
- enum ViewLifecycle {
- /** Creates a new view instance whenever the view is showed. */
- CREATE,
- /** Loads the view on first access. */
- LAZY,
- /** Eagerly preloads the view. */
- EAGER
- }
-
- /**
- * Get the view lifecycle model.
- * @return the lifecycle model, not null.
- */
- ViewLifecycle getLifecycle();
-
- /**
- * Get the view's name, used for resolving the view display name.
- * @return the view's name.
- */
- String getName();
-
- /**
- * Get the url pattern where this view should be accessible.
- * @return the url pattern, not null.
- */
- String getUrlPattern();
-
- /**
- * Get the name to be displayed for this view. This value will also be used to lookup a name from the {@code /ui/lang/tamaya}
- * bundle. If not found the value returned will be used for display.
- *
- * @return the name to be displayed, or its resource bundle key, not null.
- */
- String getDisplayName();
-
- /**
- * Method that is called to create a new view instance.
- * @see #getLifecycle()
- * @param params any parameters that may be needed to create the view.
- * @return a new view instance, not null.
- */
- View createView(Object... params);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java
index e242418..811debf 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java
@@ -19,9 +19,11 @@
package org.apache.tamaya.ui.internal;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.core.propertysource.SimplePropertySource;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spisupport.BasePropertySource;
import org.apache.tamaya.spisupport.DefaultConfiguration;
-import org.apache.tamaya.ui.services.MessageProvider;
+import org.apache.tamaya.ui.spi.MessageProvider;
import java.io.IOException;
import java.net.URL;
@@ -95,7 +97,7 @@ public final class ConfigurationBasedMessageProvider implements MessageProvider{
Enumeration<URL> urls = getClass().getClassLoader().getResources(bundleID+"."+format);
while(urls.hasMoreElements()){
URL url = urls.nextElement();
- ctxBuilder.addPropertySources(new URLPropertySource(url));
+ ctxBuilder.addPropertySources(new SimplePropertySource(url));
}
} catch (IOException e) {
e.printStackTrace();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java
index 14af644..ee687e9 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java
@@ -21,7 +21,7 @@ package org.apache.tamaya.ui.internal;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.functions.ConfigurationFunctions;
import org.apache.tamaya.ui.User;
-import org.apache.tamaya.ui.services.UserService;
+import org.apache.tamaya.ui.spi.UserService;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/internal/PageTitleUpdater.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/PageTitleUpdater.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/PageTitleUpdater.java
index 83a0105..d10b66f 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/PageTitleUpdater.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/internal/PageTitleUpdater.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.ui.components;
+package org.apache.tamaya.ui.internal;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.server.Page;
import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.ui.services.MessageProvider;
+import org.apache.tamaya.ui.spi.MessageProvider;
/**
* Listener that updates the page title when a new view is shown.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java
index 193144e..6772085 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java
@@ -1,91 +1,91 @@
-///*
-// * 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.ui.internal;
-//
-//import org.apache.tamaya.ConfigurationProvider;
-//import org.apache.tamaya.ui.services.MessageProvider;
-//
-//import java.util.Locale;
-//import java.util.ResourceBundle;
-//
-///**
-// * Component resolving messages for being shown in the UI, based on the ResourceBundle mechanisms.
-// * The baseName used can optionally be configured by setting {@code tamaya.ui.baseName} either as system property,
-// * environment property or Tamaya configuration. Be aware that the JDK resource bundle mechanism only reads
-// * the first property file on the classpath (or a corresponding class file implementing ResourceBundle).
-// */
-//public class ResourceBundleMessageProvider implements MessageProvider{
-//
-// private static final String BASENAME = evaluateBaseName();
-//
-// /**
-// * The property name for configuring the resource bundle's base name either as
-// * system property, environment property or configuration entry.
-// */
-// private static final String TAMAYA_UI_BASE_NAME = "tamaya.ui.baseName";
-//
-// /**
-// * Evaluates the base name to be used for creating the resource bundle used.
-// * @return
-// */
-// private static String evaluateBaseName() {
-// String baseName = System.getProperty(TAMAYA_UI_BASE_NAME);
-// if(baseName==null || baseName.isEmpty()){
-// baseName = System.getenv("tamaya.ui.baseName");
-// }
-// if(baseName==null || baseName.isEmpty()){
-// baseName = ConfigurationProvider.getConfiguration().get("tamaya.ui.baseName");
-// }
-// if(baseName==null || baseName.isEmpty()){
-// baseName = "ui/ui.lang/tamaya";
-// }
-// return baseName;
-// }
-//
-// /**
-// * Private singleton constructor.
-// */
-// public ResourceBundleMessageProvider(){}
-//
-// /**
-// * Get a message using the defaul locale.
-// * @param bundleID the message bundle key, not null.
-// * @return the resolved message, or the bundle ID, never null.
-// */
-// public String getMessage(String bundleID){
-// return getMessage(bundleID, Locale.getDefault());
-// }
-//
-// /**
-// * Get a message.
-// * @param bundleID the message bundle key, not null.
-// * @param locale the target locale, or null, for the default locale.
-// * @return the resolved message, or the bundle ID, never null.
-// */
-// public String getMessage(String bundleID, Locale locale){
-// try{
-// ResourceBundle bundle = ResourceBundle.getBundle(BASENAME, locale);
-// return bundle.getString(bundleID);
-// }
-// catch(Exception e){
-// return bundleID;
-// }
-// }
-//
-//}
+/*
+ * 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.ui.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.ui.spi.MessageProvider;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * Component resolving messages for being shown in the UI, based on the ResourceBundle mechanisms.
+ * The baseName used can optionally be configured by setting {@code tamaya.ui.baseName} either as system property,
+ * environment property or Tamaya configuration. Be aware that the JDK resource bundle mechanism only reads
+ * the first property file on the classpath (or a corresponding class file implementing ResourceBundle).
+ */
+public class ResourceBundleMessageProvider implements MessageProvider{
+
+ private static final String BASENAME = evaluateBaseName();
+
+ /**
+ * The property name for configuring the resource bundle's base name either as
+ * system property, environment property or configuration entry.
+ */
+ private static final String TAMAYA_UI_BASE_NAME = "tamaya.ui.baseName";
+
+ /**
+ * Evaluates the base name to be used for creating the resource bundle used.
+ * @return
+ */
+ private static String evaluateBaseName() {
+ String baseName = System.getProperty(TAMAYA_UI_BASE_NAME);
+ if(baseName==null || baseName.isEmpty()){
+ baseName = System.getenv("tamaya.ui.baseName");
+ }
+ if(baseName==null || baseName.isEmpty()){
+ baseName = ConfigurationProvider.getConfiguration().get("tamaya.ui.baseName");
+ }
+ if(baseName==null || baseName.isEmpty()){
+ baseName = "ui/ui.lang/tamaya";
+ }
+ return baseName;
+ }
+
+ /**
+ * Private singleton constructor.
+ */
+ public ResourceBundleMessageProvider(){}
+
+ /**
+ * Get a message using the defaul locale.
+ * @param bundleID the message bundle key, not null.
+ * @return the resolved message, or the bundle ID, never null.
+ */
+ public String getMessage(String bundleID){
+ return getMessage(bundleID, Locale.getDefault());
+ }
+
+ /**
+ * Get a message.
+ * @param bundleID the message bundle key, not null.
+ * @param locale the target locale, or null, for the default locale.
+ * @return the resolved message, or the bundle ID, never null.
+ */
+ public String getMessage(String bundleID, Locale locale){
+ try{
+ ResourceBundle bundle = ResourceBundle.getBundle(BASENAME, locale);
+ return bundle.getString(bundleID);
+ }
+ catch(Exception e){
+ return bundleID;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/internal/URLPropertySource.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/URLPropertySource.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/URLPropertySource.java
deleted file mode 100644
index 83b4af4..0000000
--- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/URLPropertySource.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.ui.internal;
-
-import org.apache.tamaya.spisupport.BasePropertySource;
-import org.apache.tamaya.spisupport.MapPropertySource;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Simple property source, used for internationalization.
- */
-final class URLPropertySource extends BasePropertySource{
-
- private static final Logger LOG = Logger.getLogger(URLPropertySource.class.getName());
- private URL url;
- private Map<String, String> properties;
-
- public URLPropertySource(URL url){
- this.url = Objects.requireNonNull(url);
- load();
- }
-
- /**
- * Loads/reloads the properties from the URL. If loading of the properties failed the previus state is preserved,
- * unless there is no such state. In this case an empty map is assigned.
- */
- public void load(){
- try(InputStream is = url.openStream()) {
- Properties props = new Properties();
- if (url.getFile().endsWith(".xml")) {
- props.loadFromXML(is);
- } else {
- props.load(is);
- }
- properties = Collections.unmodifiableMap(MapPropertySource.getMap(props));
- }
- catch(Exception e){
- LOG.log(Level.WARNING, "Failed to read config from "+url,e);
- if(properties==null) {
- properties = Collections.emptyMap();
- }
- }
- }
-
- @Override
- public String getName() {
- return url.toString();
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/internal/VerticalSpacedLayout.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/VerticalSpacedLayout.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/VerticalSpacedLayout.java
index 94fc980..405d0dc 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/VerticalSpacedLayout.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/internal/VerticalSpacedLayout.java
@@ -16,8 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.ui.components;
+package org.apache.tamaya.ui.internal;
+import com.vaadin.ui.Alignment;
import com.vaadin.ui.VerticalLayout;
/**
@@ -28,5 +29,6 @@ public class VerticalSpacedLayout extends VerticalLayout {
public VerticalSpacedLayout() {
setMargin(true);
setSpacing(true);
+ setDefaultComponentAlignment(Alignment.TOP_LEFT);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/spi/LazyProvider.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/spi/LazyProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/spi/LazyProvider.java
deleted file mode 100644
index 2d1547f..0000000
--- a/ui/base/src/main/java/org/apache/tamaya/ui/spi/LazyProvider.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy 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.ui.components;
-
-import com.vaadin.navigator.View;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.ui.ViewProvider;
-import org.apache.tamaya.ui.services.MessageProvider;
-
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Lazily initializes a view when it's first accessed, then always returns the
- * same instance on subsequent calls.
- */
-public class LazyProvider implements ViewProvider {
- private static final Logger LOG = Logger.getLogger(
- LazyProvider.class.getName());
- private Class<? extends View> viewClass;
- private View view;
- private String urlPattern;
- private String name;
-
- public LazyProvider(String name, String urlPattern, Class<? extends View> viewClass) {
- this.viewClass = Objects.requireNonNull(viewClass);
- this.urlPattern = Objects.requireNonNull(urlPattern);
- this.name = Objects.requireNonNull(name);
- }
-
- @Override
- public String getUrlPattern() {
- return urlPattern;
- }
-
-
- @Override
- public ViewLifecycle getLifecycle() {
- return ViewLifecycle.LAZY;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getDisplayName() {
- return ServiceContextManager.getServiceContext().getService(MessageProvider.class)
- .getMessage(name);
- }
-
- @Override
- public View createView(Object... params) {
- if(view==null){
- try {
- view = viewClass.newInstance();
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to create view: "+urlPattern, e);
- }
- }
- return view;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/spi/MessageProvider.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/spi/MessageProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/spi/MessageProvider.java
index a15ae46..2ea205d 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/spi/MessageProvider.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/spi/MessageProvider.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.ui.services;
+package org.apache.tamaya.ui.spi;
import java.util.Locale;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/spi/SystemInfoProvider.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/spi/SystemInfoProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/spi/SystemInfoProvider.java
new file mode 100644
index 0000000..eb8ab7d
--- /dev/null
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/spi/SystemInfoProvider.java
@@ -0,0 +1,15 @@
+package org.apache.tamaya.ui.spi;/*
+ * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+ */
+
+import com.vaadin.ui.Accordion;
+
+/**
+ * Created by atsticks on 28.03.17.
+ */
+public interface SystemInfoProvider {
+
+ void addSystemInfo(Accordion systemInfoPanel);
+
+ void updateSystemInfo(Accordion systemInfoPanel);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/spi/UserService.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/spi/UserService.java b/ui/base/src/main/java/org/apache/tamaya/ui/spi/UserService.java
index 71a8a43..091ea60 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/spi/UserService.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/spi/UserService.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.ui.services;
+package org.apache.tamaya.ui.spi;
import org.apache.tamaya.ui.User;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/views/AbstractTextInfoProvider.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/views/AbstractTextInfoProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/views/AbstractTextInfoProvider.java
new file mode 100644
index 0000000..1185056
--- /dev/null
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/views/AbstractTextInfoProvider.java
@@ -0,0 +1,67 @@
+/*
+ * 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.ui.views;
+
+import com.vaadin.ui.Accordion;
+import com.vaadin.ui.TextArea;
+import com.vaadin.ui.VerticalLayout;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.ui.UIConstants;
+import org.apache.tamaya.ui.spi.SystemInfoProvider;
+
+import javax.annotation.Priority;
+
+/**
+ * Created by atsticks on 29.06.16.
+ */
+public abstract class AbstractTextInfoProvider implements SystemInfoProvider {
+
+ private TextArea textArea;
+
+ protected abstract String getCaption();
+
+ protected abstract String getInfo();
+
+ @Override
+ public void addSystemInfo(Accordion systemInfoPanel) {
+ VerticalLayout layout = new VerticalLayout();
+ textArea = new TextArea("System Info");
+ textArea.addStyleName(UIConstants.FIXED_FONT);
+ textArea.setValue(getInfo());
+ textArea.setRows(20);
+ textArea.setHeight("400px");
+ textArea.setWidth("100%");
+ layout.addComponents(textArea);
+ systemInfoPanel.addTab(layout, getCaption());
+ }
+
+ @Override
+ public void updateSystemInfo(Accordion systemInfoPanel) {
+ if(textArea!=null){
+ textArea.setValue(getInfo());
+ }else{
+ textArea = new TextArea("System Info");
+ textArea.setValue(getInfo());
+ textArea.setSizeFull();
+ systemInfoPanel.addTab(textArea, textArea.getCaption());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java b/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java
index fb0d41b..e4c6de1 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java
@@ -18,26 +18,16 @@
*/
package org.apache.tamaya.ui.views;
-import com.vaadin.data.Property;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
-import com.vaadin.shared.ui.label.ContentMode;
-import com.vaadin.ui.Alignment;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.CheckBox;
-import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.TabSheet;
-import com.vaadin.ui.TextArea;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.Tree;
-import com.vaadin.ui.VerticalLayout;
+import com.vaadin.shared.ui.ContentMode;
+import com.vaadin.ui.*;
+import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.apache.tamaya.functions.PropertyMatcher;
import org.apache.tamaya.ui.UIConstants;
-import org.apache.tamaya.ui.ViewProvider;
-import org.apache.tamaya.ui.components.VerticalSpacedLayout;
-import org.apache.tamaya.ui.services.MessageProvider;
+import org.apache.tamaya.ui.internal.VerticalSpacedLayout;
import javax.annotation.Priority;
import java.util.Locale;
@@ -45,98 +35,38 @@ import java.util.Map;
import java.util.TreeMap;
/**
- * View for evaluating the current convifugration tree.
+ * View for evaluating the current convifugration configArea.
*/
@Priority(10)
public class ConfigView extends VerticalSpacedLayout implements View {
- /**
- * Provider to register this view.
- */
- @Priority(10)
- public static final class Provider implements ViewProvider{
-
- @Override
- public ViewLifecycle getLifecycle() {
- return ViewLifecycle.CREATE;
- }
-
- @Override
- public String getName() {
- return "view.config.name";
- }
-
- @Override
- public String getUrlPattern() {
- return "/config";
- }
-
- @Override
- public String getDisplayName() {
- return ServiceContextManager.getServiceContext().getService(MessageProvider.class)
- .getMessage("view.config.name");
- }
-
- @Override
- public View createView(Object... params){
- return new ConfigView();
- }
- }
-
private TextField keyFilter = new TextField("Key filter");
private TextField valueFilter = new TextField("Value filter");
- private CheckBox showMetaEntries = new CheckBox("Show Metadata", false);
- private Tree tree = new Tree("Current Configuration");
+ private TextArea configArea = new TextArea("Current Configuration");
public ConfigView() {
Label caption = new Label("Raw Configuration");
Label description = new Label(
- "This view shows the overall <b>raw</b> configuration tree. Dependening on your access rights you" +
+ "This view shows the overall <b>raw</b> configuration configArea. Dependening on your access rights you" +
"may see partial or masked data. Similarly configuration can be <i>read-only</i> or <i>mutable</i>.",
ContentMode.HTML);
-
TabSheet tabPane = new TabSheet();
- VerticalLayout configLayout = new VerticalLayout();
-
- HorizontalLayout filters = new HorizontalLayout();
-
- Button filterButton = new Button("Filter", new Button.ClickListener() {
- @Override
- public void buttonClick(Button.ClickEvent clickEvent) {
- fillTree();
- }
- });
- filters.setDefaultComponentAlignment(Alignment.BOTTOM_LEFT);
- filters.addComponents(keyFilter, valueFilter, filterButton, showMetaEntries);
- filters.setSpacing(true);
+ tabPane.setHeight("100%");
+ tabPane.setWidth("100%");
+ tabPane.addTab(createConfigTab(), "Configuration");
+ tabPane.addTab(createEnvTab(), "Environment Properties");
+ tabPane.addTab(createSysPropsTab(), "System Properties");
+ tabPane.addTab(createRuntimeTab(), "Runtime Properties");
+ addComponents(caption, description, tabPane);
+ caption.addStyleName(UIConstants.LABEL_HUGE);
+ description.addStyleName(UIConstants.LABEL_LARGE);
+ }
- fillTree();
- configLayout.addComponents(filters, tree);
- tabPane.addTab(configLayout, "Configuration");
- TextArea envProps = new TextArea();
- StringBuilder b = new StringBuilder();
- envProps.setHeight("100%");
- envProps.setWidth("100%");
- envProps.setSizeFull();
- envProps.setRows(System.getenv().size());
- for(Map.Entry<String,String> en:new TreeMap<>(System.getenv()).entrySet()){
- b.append(en.getKey()).append("=").append(en.getValue()).append('\n');
- }
- envProps.setValue(b.toString());
- envProps.setReadOnly(true);
- tabPane.addTab(envProps, "Environment Properties");
- TextArea sysProps = new TextArea();
- sysProps.setSizeFull();
- sysProps.setRows(System.getProperties().size());
- b.setLength(0);
- for(Map.Entry<Object,Object> en:new TreeMap<>(System.getProperties()).entrySet()){
- b.append(en.getKey()).append("=").append(en.getValue()).append('\n');
- }
- sysProps.setValue(b.toString());
- sysProps.setReadOnly(true);
- tabPane.addTab(sysProps, "System Properties");
+ private Component createRuntimeTab() {
+ VerticalLayout tabLayout = new VerticalLayout();
TextArea runtimeProps = new TextArea();
- runtimeProps.setRows(5);
+ runtimeProps.setRows(25);
+ StringBuilder b = new StringBuilder();
b.setLength(0);
b.append("Available Processors : ").append(Runtime.getRuntime().availableProcessors()).append('\n');
b.append("Free Memory : ").append(Runtime.getRuntime().freeMemory()).append('\n');
@@ -145,85 +75,100 @@ public class ConfigView extends VerticalSpacedLayout implements View {
b.append("Default Locale : ").append(Locale.getDefault()).append('\n');
runtimeProps.setValue(b.toString());
runtimeProps.setReadOnly(true);
- tabPane.addTab(runtimeProps, "Runtime Properties");
- runtimeProps.setSizeFull();
- addComponents(caption, description, tabPane);
- caption.addStyleName(UIConstants.LABEL_HUGE);
- description.addStyleName(UIConstants.LABEL_LARGE);
- showMetaEntries.addValueChangeListener(new Property.ValueChangeListener() {
+ runtimeProps.setHeight("100%");
+ runtimeProps.setWidth("100%");
+ tabLayout.addComponents(runtimeProps);
+ tabLayout.setHeight("100%");
+ tabLayout.setWidth("100%");
+ return tabLayout;
+ }
+
+ private Component createSysPropsTab() {
+ VerticalLayout tabLayout = new VerticalLayout();
+ TextArea sysProps = new TextArea();
+ sysProps.setRows(25);
+ StringBuilder b = new StringBuilder();
+ for(Map.Entry<Object,Object> en:new TreeMap<>(System.getProperties()).entrySet()){
+ b.append(en.getKey()).append("=").append(en.getValue()).append('\n');
+ }
+ sysProps.setValue(b.toString());
+ sysProps.setReadOnly(true);
+ sysProps.setHeight("100%");
+ sysProps.setWidth("100%");
+ tabLayout.addComponents(sysProps);
+ tabLayout.setHeight("100%");
+ tabLayout.setWidth("100%");
+ return tabLayout;
+ }
+
+ private Component createEnvTab() {
+ VerticalLayout tabLayout = new VerticalLayout();
+ TextArea envProps = new TextArea();
+ StringBuilder b = new StringBuilder();
+ envProps.setRows(25);
+ for(Map.Entry<String,String> en:new TreeMap<>(System.getenv()).entrySet()){
+ b.append(en.getKey()).append("=").append(en.getValue()).append('\n');
+ }
+ envProps.setValue(b.toString());
+ envProps.setReadOnly(true);
+ envProps.setHeight("100%");
+ envProps.setWidth("100%");
+ tabLayout.addComponents(envProps);
+ tabLayout.setHeight("100%");
+ tabLayout.setWidth("100%");
+ return tabLayout;
+ }
+
+ private Component createConfigTab() {
+ VerticalLayout tabLayout = new VerticalLayout();
+ Component filters = createFilters();
+ configArea.setWordWrap(false);
+ configArea.setReadOnly(true);
+ configArea.setHeight("100%");
+ configArea.setWidth("100%");
+ configArea.setRows(20);
+ fillTree();
+ tabLayout.addComponents(filters, configArea);
+ tabLayout.setHeight("100%");
+ tabLayout.setWidth("100%");
+ return tabLayout;
+ }
+
+ private Component createFilters() {
+ HorizontalLayout filters = new HorizontalLayout();
+ Button filterButton = new Button("Filter", new Button.ClickListener() {
@Override
- public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
+ public void buttonClick(Button.ClickEvent clickEvent) {
fillTree();
}
});
+ filters.setDefaultComponentAlignment(Alignment.BOTTOM_LEFT);
+ filters.addComponents(keyFilter, valueFilter, filterButton);
+ filters.setSpacing(true);
+ return filters;
}
private void fillTree() {
- String keyFilterExp = this.keyFilter.getValue();
- if(keyFilterExp.isEmpty()){
- keyFilterExp = null;
- }
- String valueFilterExp = this.valueFilter.getValue();
- if(valueFilterExp.isEmpty()){
- valueFilterExp = null;
- }
- tree.removeAllItems();
- boolean showMetadata = showMetaEntries.getValue();
- for(Map.Entry<String,String> entry: ConfigurationProvider.getConfiguration().getProperties().entrySet()){
- String key = entry.getKey();
- if(keyFilterExp!=null && !key.matches(keyFilterExp)){
- continue;
- }
- if(valueFilterExp!=null && !entry.getValue().matches(valueFilterExp)){
- continue;
- }
- if(!showMetadata && entry.getKey().startsWith("_")){
- continue;
- }
- tree.addItem(key);
- tree.setItemCaption(key, getCaption(key, entry.getValue()));
- tree.setChildrenAllowed(key, false);
- String parent = null;
- int start = 0;
- int index = key.indexOf('.', start);
- while(index>0){
- String subItem = key.substring(0,index);
- String caption = key.substring(start, index);
- tree.addItem(subItem);
- tree.setItemCaption(subItem, caption);
- if(parent!=null){
- tree.setParent(subItem, parent);
- }
- parent = subItem;
- start = index+1;
- index = key.indexOf('.', start);
- }
- String lastItem = key.substring(start);
- if(!lastItem.equals(key)){
- if(parent!=null){
- tree.setParent(key, parent);
- }else{
- // should not happen
+ final String keyFilterExp = this.keyFilter.getValue();
+ final String valueFilterExp = this.valueFilter.getValue();
+ Configuration config = ConfigurationProvider.getConfiguration()
+ .with(ConfigurationFunctions.filter(new PropertyMatcher() {
+ @Override
+ public boolean test(String key, String value) {
+ if(!keyFilterExp.isEmpty() && !key.matches(keyFilterExp)){
+ return false;
}
- }else{ // singl root entry
- if(parent!=null) {
- tree.setParent(key, parent);
+ if(!valueFilterExp.isEmpty() && !value.matches(valueFilterExp)){
+ return false;
}
+ return true;
}
- }
- }
-
- private String getCaption(String key, String value) {
- int index = key.lastIndexOf('.');
- if(index<0){
- return key + " = " + value;
- }else{
- return key.substring(index+1) + " = " + value;
- }
+ }));
+ configArea.setValue(config.query(ConfigurationFunctions.textInfo()));
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
-
+ fillTree();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/views/HomeView.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/views/HomeView.java b/ui/base/src/main/java/org/apache/tamaya/ui/views/HomeView.java
index 9d371d0..71944f2 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/views/HomeView.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/views/HomeView.java
@@ -20,16 +20,12 @@ package org.apache.tamaya.ui.views;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
-import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Label;
-import org.apache.tamaya.spi.ServiceContextManager;
import org.apache.tamaya.ui.CurrentUser;
import org.apache.tamaya.ui.UIConstants;
-import org.apache.tamaya.ui.ViewProvider;
-import org.apache.tamaya.ui.components.VerticalSpacedLayout;
-import org.apache.tamaya.ui.services.MessageProvider;
+import org.apache.tamaya.ui.internal.VerticalSpacedLayout;
-import javax.annotation.Priority;
/**
* Home view containing a title and a description, used as default entry point of the UI after login.
@@ -37,40 +33,6 @@ import javax.annotation.Priority;
public class HomeView extends VerticalSpacedLayout implements View {
/**
- * Provider to bew registered providing this view to the UI module.
- */
- @Priority(0)
- public static final class Provider implements ViewProvider{
-
- @Override
- public ViewLifecycle getLifecycle() {
- return ViewLifecycle.LAZY;
- }
-
- @Override
- public String getName() {
- return "view.home.name";
- }
-
- @Override
- public String getUrlPattern() {
- return "/home";
- }
-
- @Override
- public String getDisplayName() {
- return ServiceContextManager.getServiceContext().getService(MessageProvider.class)
- .getMessage(getName());
- }
-
- @Override
- public View createView(Object... params) {
- return new HomeView();
- }
-
- }
-
- /**
* Constructor.
*/
public HomeView() {
@@ -79,12 +41,12 @@ public class HomeView extends VerticalSpacedLayout implements View {
"<b>Apache Tamaya</b> is an API and extendable framework for accessing and managing configuration.<br/> \n" +
"Please check the project's home page <a href='http://tamaya.incubator.apache.org'>http://tamaya.incubator.apache.org</a>.",
ContentMode.HTML);
-
addComponents(caption, description);
-
caption.addStyleName(UIConstants.LABEL_HUGE);
description.addStyleName(UIConstants.LABEL_LARGE);
-
+ setHeight("100%");
+ setWidth("100%");
+ setSizeFull();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/views/SystemView.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/views/SystemView.java b/ui/base/src/main/java/org/apache/tamaya/ui/views/SystemView.java
index ea3421c..9206df0 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/views/SystemView.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/views/SystemView.java
@@ -20,14 +20,15 @@ package org.apache.tamaya.ui.views;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
-import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.shared.ui.ContentMode;
+import com.vaadin.ui.Accordion;
+import com.vaadin.ui.Alignment;
import com.vaadin.ui.Label;
-import com.vaadin.ui.Tree;
import org.apache.tamaya.spi.ServiceContextManager;
import org.apache.tamaya.ui.UIConstants;
-import org.apache.tamaya.ui.ViewProvider;
-import org.apache.tamaya.ui.components.VerticalSpacedLayout;
-import org.apache.tamaya.ui.services.MessageProvider;
+import org.apache.tamaya.ui.internal.VerticalSpacedLayout;
+import org.apache.tamaya.ui.spi.MessageProvider;
+import org.apache.tamaya.ui.spi.SystemInfoProvider;
import javax.annotation.Priority;
@@ -37,43 +38,7 @@ import javax.annotation.Priority;
@Priority(10000)
public class SystemView extends VerticalSpacedLayout implements View {
-
- /**
- * Provider to register this view.
- */
- @Priority(20)
- public static final class Provider implements ViewProvider{
-
- @Override
- public ViewLifecycle getLifecycle() {
- return ViewLifecycle.CREATE;
- }
-
- @Override
- public String getName() {
- return "view.system.name";
- }
-
- @Override
- public String getUrlPattern() {
- return "/system";
- }
-
- @Override
- public String getDisplayName() {
- return ServiceContextManager.getServiceContext().getService(MessageProvider.class)
- .getMessage("view.system.name");
- }
-
- @Override
- public View createView(Object... params){
- return new SystemView();
- }
- }
-
-
- private Tree configTree = new Tree(ServiceContextManager.getServiceContext().getService(MessageProvider.class)
- .getMessage("default.label.system"));
+ private Accordion configTree = new Accordion();
public SystemView() {
@@ -82,36 +47,32 @@ public class SystemView extends VerticalSpacedLayout implements View {
"This view shows the system components currently active. This information may be useful when checking if an" +
"configuration extension is loaded and for inspection of the configuration and property sources" +
"invovlved.",
- ContentMode.HTML);
-
- fillComponentTree();
+ ContentMode.TEXT);
+ configTree.setHeight("100%");
+ configTree.setWidth("100%");
+ fillAccordion();
addComponents(caption, description, configTree);
-
caption.addStyleName(UIConstants.LABEL_HUGE);
- description.addStyleName(UIConstants.LABEL_LARGE);
-
}
- private void fillComponentTree() {
- configTree.removeAllItems();
+ private void fillAccordion() {
+ configTree.removeAllComponents();
for(SystemInfoProvider infoProvider:ServiceContextManager.getServiceContext()
.getServices(SystemInfoProvider.class)){
- infoProvider.provideSystemInfo(configTree);
+ infoProvider.addSystemInfo(configTree);
}
}
- private String getCaption(String key, String value) {
- int index = key.lastIndexOf('.');
- if(index<0){
- return key + " = " + value;
- }else{
- return key.substring(index+1) + " = " + value;
+ private void updateAccordion() {
+ for(SystemInfoProvider infoProvider:ServiceContextManager.getServiceContext()
+ .getServices(SystemInfoProvider.class)){
+ infoProvider.updateSystemInfo(configTree);
}
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
-
+ fillAccordion();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java
index fd37136..0896c3c 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java
@@ -18,39 +18,105 @@
*/
package org.apache.tamaya.ui.views;
-import com.vaadin.ui.Tree;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
import javax.annotation.Priority;
+import java.util.List;
+import java.util.Map;
/**
* Created by atsticks on 29.06.16.
*/
@Priority(0)
-public class TamayaGeneralSystemInfoProvider implements SystemInfoProvider{
+public class TamayaGeneralSystemInfoProvider extends AbstractTextInfoProvider {
+
@Override
- public void provideSystemInfo(Tree tree) {
+ protected String getCaption(){
+ return "System Info";
+ }
+
+ @Override
+ protected String getInfo() {
Configuration config = ConfigurationProvider.getConfiguration();
- String currentParent = "General";
- tree.addItem(currentParent);
- tree.addItem("Configuration.class");
- tree.setItemCaption("Configuration.class", "Configuration class = " + config.getClass().getName());
- tree.setParent("Configuration.class", currentParent);
- tree.setChildrenAllowed("Configuration.class", false);
-
- tree.addItem("ConfigurationContext.class");
- tree.setItemCaption("ConfigurationContext.class", "ConfigurationContext class = " +
- config.getContext().getClass().getName());
- tree.setParent("ConfigurationContext.class", currentParent);
- tree.setChildrenAllowed("ConfigurationContext.class", false);
-
- tree.addItem("PropertyValueCombinationPolicy.class");
- tree.setItemCaption("PropertyValueCombinationPolicy.class",
- PropertyValueCombinationPolicy.class.getSimpleName() + " class = " +
- config.getContext().getPropertyValueCombinationPolicy().getClass().getName());
- tree.setParent("PropertyValueCombinationPolicy.class", currentParent);
- tree.setChildrenAllowed("PropertyValueCombinationPolicy.class", false);
+ return new StringBuilder()
+ .append("Configuration: ").append(config.getClass().getName()).append('\n')
+ .append("ConfigurationContext: ").append(config.getContext().getClass().getName()).append('\n')
+ .append("PropertyValueCombinationPolicy: ")
+ .append(config.getContext().getPropertyValueCombinationPolicy().getClass().getName()).append('\n')
+ .append("Property sources: ").append(config.getContext().getPropertySources().size()).append('\n')
+ .append(getPropertySourceList(config.getContext())).append('\n')
+ .append("Property filters: ").append(config.getContext().getPropertyFilters().size()).append('\n')
+ .append(getPropertyFilterList(config.getContext())).append('\n')
+ .append("Property converters: ").append(config.getContext().getPropertyConverters().size()).append('\n')
+ .append(getPropertyConverterList(config.getContext())).append('\n')
+ .toString();
+
+ }
+
+ private String getPropertySourceList(ConfigurationContext context) {
+ StringBuilder b = new StringBuilder();
+ b.append(" ").append(format("NAME", 40)).append(format("ORDINAL", 8))
+ .append(format("CLASS", 30)).append('\n');
+ b.append(" ---------------------------------------------------------------------------------" +
+ "-------------------------------------------------------------").append('\n');
+ for(PropertySource ps:context.getPropertySources()){
+ b.append(" ").append(format(ps.getName(),40)).append(format(String.valueOf(ps.getOrdinal()), 8))
+ .append(format(ps.getClass().getSimpleName(), 30)).append('\n');
+ }
+ return b.toString();
+ }
+
+ private String getPropertyFilterList(ConfigurationContext context) {
+ StringBuilder b = new StringBuilder();
+ b.append(" ").append(format("CLASS", 80)).append('\n');
+ b.append(" ---------------------------------------------------------------------------------" +
+ "-------------------------------------------------------------").append('\n');
+ for(PropertyFilter ps:context.getPropertyFilters()){
+ b.append(" ").append(format(ps.getClass().getName(), 80)).append('\n');
+ }
+ return b.toString();
}
+
+ private String getPropertyConverterList(ConfigurationContext context) {
+ StringBuilder b = new StringBuilder();
+ b.append(" ").append(format("TYPE", 30))
+ .append(format("CONVERTERS", 90)).append('\n');
+ b.append(" ---------------------------------------------------------------------------------" +
+ "-------------------------------------------------------------").append('\n');
+ for(Map.Entry<TypeLiteral<?>,List<PropertyConverter<?>>> ps:context.getPropertyConverters().entrySet()){
+ b.append(" ").append(format(ps.getKey().getRawType().getSimpleName(),30))
+ .append(format(getClassList(ps.getValue()), 90)).append('\n');
+ }
+ return b.toString();
+ }
+
+ private String getClassList(List<PropertyConverter<?>> items) {
+ StringBuilder b = new StringBuilder();
+ for (Object o : items) {
+ b.append(o.getClass().getName()).append(", ");
+ }
+ if (b.length() > 0) {
+ b.setLength(b.length() - 2);
+ }
+ return b.toString();
+ }
+
+ private String format(String val, int len){
+ if(val.length()>len){
+ return val.substring(0, len-3)+".. ";
+ }
+ StringBuilder b = new StringBuilder(val);
+ for(int i=0;i<len-val.length();i++){
+ b.append(' ');
+ }
+ return b.toString();
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/java/org/apache/tamaya/ui/views/login/LoginBox.java
----------------------------------------------------------------------
diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/views/login/LoginBox.java b/ui/base/src/main/java/org/apache/tamaya/ui/views/login/LoginBox.java
index 73cf018..e40e23d 100644
--- a/ui/base/src/main/java/org/apache/tamaya/ui/views/login/LoginBox.java
+++ b/ui/base/src/main/java/org/apache/tamaya/ui/views/login/LoginBox.java
@@ -33,8 +33,8 @@ import org.apache.tamaya.spi.ServiceContextManager;
import org.apache.tamaya.ui.UIConstants;
import org.apache.tamaya.ui.User;
import org.apache.tamaya.ui.event.EventBus;
-import org.apache.tamaya.ui.services.MessageProvider;
-import org.apache.tamaya.ui.services.UserService;
+import org.apache.tamaya.ui.spi.MessageProvider;
+import org.apache.tamaya.ui.spi.UserService;
/**
* Login dialog centerd on the screen.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
----------------------------------------------------------------------
diff --git a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
index 0ff3225..326528e 100644
--- a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
+++ b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
@@ -19,6 +19,3 @@
org.apache.tamaya.ui.views.HomeView$Provider
org.apache.tamaya.ui.views.ConfigView$Provider
org.apache.tamaya.ui.views.SystemView$Provider
-
-# Events Module
-org.apache.tamaya.ui.events.EventView$Provider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.services.MessageProvider
----------------------------------------------------------------------
diff --git a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.services.MessageProvider b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.services.MessageProvider
deleted file mode 100644
index 6ce4a9f..0000000
--- a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.services.MessageProvider
+++ /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.ui.internal.ConfigurationBasedMessageProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.services.UserService
----------------------------------------------------------------------
diff --git a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.services.UserService b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.services.UserService
deleted file mode 100644
index 109865f..0000000
--- a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.services.UserService
+++ /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.ui.internal.ConfiguredUserService
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.MessageProvider
----------------------------------------------------------------------
diff --git a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.MessageProvider b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.MessageProvider
new file mode 100644
index 0000000..6ce4a9f
--- /dev/null
+++ b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.MessageProvider
@@ -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.ui.internal.ConfigurationBasedMessageProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.SystemInfoProvider
----------------------------------------------------------------------
diff --git a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.SystemInfoProvider b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.SystemInfoProvider
new file mode 100644
index 0000000..a0a3ecd
--- /dev/null
+++ b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.SystemInfoProvider
@@ -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.ui.views.TamayaGeneralSystemInfoProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.UserService
----------------------------------------------------------------------
diff --git a/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.UserService b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.UserService
new file mode 100644
index 0000000..109865f
--- /dev/null
+++ b/ui/base/src/main/resources/META-INF/services/org.apache.tamaya.ui.spi.UserService
@@ -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.ui.internal.ConfiguredUserService
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/base/src/main/resources/ui/lang/tamaya.properties
----------------------------------------------------------------------
diff --git a/ui/base/src/main/resources/ui/lang/tamaya.properties b/ui/base/src/main/resources/ui/lang/tamaya.properties
index ba458de..a2f1423 100644
--- a/ui/base/src/main/resources/ui/lang/tamaya.properties
+++ b/ui/base/src/main/resources/ui/lang/tamaya.properties
@@ -23,6 +23,6 @@ default.label.username=Username
default.label.password=Password
default.label.system=Runtime
-view.config.name=Configuration
-view.home.name=Home
-view.system.name=System Runtime
+views.ConfigView.name=Configuration
+views.HomeView.name=Home
+views.SystemView.name=System Runtime
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fd26d6c0/ui/pom.xml
----------------------------------------------------------------------
diff --git a/ui/pom.xml b/ui/pom.xml
index 9e5f340..9214a84 100644
--- a/ui/pom.xml
+++ b/ui/pom.xml
@@ -23,18 +23,23 @@
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-sandbox</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
- <relativePath>..</relativePath>
</parent>
<artifactId>tamaya-ui-parent</artifactId>
- <name>Apache Tamaya Modules - UI (parent)</name>
- <description>Parent of the UI modules, which implement a servlet application
+ <name>Apache Tamaya Modules - Web UI (parent)</name>
+ <description>Parent of the UI modules, which implement a web application
for accessing and changing of configuration.
</description>
<packaging>pom</packaging>
<properties>
- <jdkVersion>1.7</jdkVersion>
+ <jdkVersion>1.8</jdkVersion>
+ <maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
+ <maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
+ <vaadin.plugin.version>2.1.0</vaadin.plugin.version>
+ <vaadin.version>8.0.4</vaadin.version>
+ <guava.version>21.0</guava.version>
+ <tomcat.version>7.0.57</tomcat.version>
</properties>
<modules>
@@ -43,4 +48,79 @@
<module>mutableconfig</module>
</modules>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-functions</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.vaadin</groupId>
+ <artifactId>vaadin-server</artifactId>
+ <version>${vaadin.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.vaadin</groupId>
+ <artifactId>vaadin-client-compiled</artifactId>
+ <version>${vaadin.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.vaadin</groupId>
+ <artifactId>vaadin-themes</artifactId>
+ <version>${vaadin.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guava.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-core</artifactId>
+ <version>${tomcat.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-jasper</artifactId>
+ <version>${tomcat.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-logging-juli</artifactId>
+ <version>${tomcat.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jaxrs_2.0_spec</artifactId>
+ <version>1.0-alpha-1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>3.1.6</version>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>vaadin-prereleases</id>
+ <name>Vaadin Pre-releases</name>
+ <url>https://maven.vaadin.com/vaadin-prereleases</url>
+ </repository>
+ </repositories>
</project>
[4/7] incubator-tamaya-sandbox git commit: TAMAYA-145: Simplified
syntax and MetaContext. Added tests.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java
new file mode 100644
index 0000000..e9ca5a5
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.metamodel.ext;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+/**
+ * Created by atsticks on 17.04.17.
+ */
+public class MyConverter implements PropertyConverter<String> {
+
+ @Override
+ public String convert(String value, ConversionContext context) {
+ return value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java
new file mode 100644
index 0000000..e819e2f
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.metamodel.ext;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+
+/**
+ * Created by atsticks on 17.04.17.
+ */
+public class MyFilter implements PropertyFilter{
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ return value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java
new file mode 100644
index 0000000..cdb4ae8
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.metamodel.ext;
+
+
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Created by atsticks on 17.04.17.
+ */
+public class MyPropertySource extends org.apache.tamaya.spisupport.BasePropertySource{
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/IntegrationTests/context-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/context-test.xml b/metamodel/src/test/resources/IntegrationTests/context-test.xml
new file mode 100644
index 0000000..e1073f7
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/context-test.xml
@@ -0,0 +1,29 @@
+<!--
+// 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.
+// -->
+<configuration>
+ <!-- Context is evaluated first. -->
+ <context>
+ <stage>${properties:system:STAGE?default=DEV}</stage>
+ <configdir>${properties:system:configdir?default=.}</configdir>
+ <app>${properties:system:APP?default=NONE}</app>
+ <context>${java:org.apache.tamaya.metamodel.MetaContext#id()}</context>
+ </context>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.xml b/metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.xml
new file mode 100644
index 0000000..91252cf
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.xml
@@ -0,0 +1,31 @@
+<!--
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy 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.
+// -->
+<configuration>
+
+ <!-- combinationPolicy class="" / -->
+
+ <!-- Configuration definition. -->
+
+ <property-converters>
+ <!--<converter type="AllInOneConverter"/>-->
+ <defaults/>
+ </property-converters>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml b/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
new file mode 100644
index 0000000..199f04f
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
@@ -0,0 +1,26 @@
+<!--
+// 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.
+// -->
+<configuration>
+
+ <property-filters>
+ <defaults/>
+ </property-filters>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/IntegrationTests/default-propertysources-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/default-propertysources-test.xml b/metamodel/src/test/resources/IntegrationTests/default-propertysources-test.xml
new file mode 100644
index 0000000..a7270ec
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/default-propertysources-test.xml
@@ -0,0 +1,29 @@
+<!--
+// 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.
+// -->
+<configuration>
+ <!-- combinationPolicy class="" / -->
+
+ <!-- Configuration definition. -->
+
+ <property-sources>
+ <defaults />
+ </property-sources>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.xml
new file mode 100644
index 0000000..fe47b84
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.xml
@@ -0,0 +1,30 @@
+<!--
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy 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.
+// -->
+<configuration>
+
+ <!-- combinationPolicy class="" / -->
+
+ <!-- Configuration definition. -->
+
+ <property-converters>
+ <org.apache.tamaya.metamodel.ext.MyConverter targetType="java.lang.String"/>
+ </property-converters>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/IntegrationTests/propertyfilters-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/propertyfilters-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyfilters-test.xml
new file mode 100644
index 0000000..c1f4ee4
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/propertyfilters-test.xml
@@ -0,0 +1,26 @@
+<!--
+// 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.
+// -->
+<configuration>
+
+ <property-filters>
+ <Cached timeout="30000" maxSize="300" matches="cached.*"/>
+ </property-filters>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/IntegrationTests/propertysources-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/propertysources-test.xml b/metamodel/src/test/resources/IntegrationTests/propertysources-test.xml
new file mode 100644
index 0000000..831da19
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/propertysources-test.xml
@@ -0,0 +1,25 @@
+<!--
+// 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.
+// -->
+<configuration>
+ <property-sources>
+ <org.apache.tamaya.metamodel.ext.MyPropertySource/>
+ <sys-properties />
+ </property-sources>
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
new file mode 100644
index 0000000..80fa6c6
--- /dev/null
+++ b/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
@@ -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 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.
+#
+org.apache.tamaya.metamodel.ImmutableFilter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/resources/tamaya-config.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/tamaya-config.xml b/metamodel/src/test/resources/tamaya-config.xml
index eb44f83..388d84c 100644
--- a/metamodel/src/test/resources/tamaya-config.xml
+++ b/metamodel/src/test/resources/tamaya-config.xml
@@ -19,77 +19,53 @@
<configuration>
<!-- Context is evaluated first. -->
<context>
- <context-entry name="stage">${properties:system:STAGE?default=DEV}</context-entry>
- <context-entry name="configdir">${properties:system:configdir?default=.}</context-entry>
- <context-entry name="app">${properties:system.APP?default=NONE}</context-entry>
- <context-entry name="context">${java:org.apache.tamaya.context.Context#id()}</context-entry>
- <context-entry name="company">Trivadis</context-entry>
- <context-entry name="default-formats">yaml,json</context-entry>
- <context-entry name="default-refresh-period">5 SECOND</context-entry>
+ <stage>${properties:system:STAGE?default=DEV}</stage>
+ <configdir>${properties:system:configdir?default=.}</configdir>
+ <app>${properties:system.APP?default=NONE}</app>
+ <context>${java:org.apache.tamaya.context.Context#id()}</context>
+ <company>Trivadis</company>
+ <default-formats>yaml,json</default-formats>
+ <default-refresh-period>5 SECOND</default-refresh-period>
</context>
<context name="APP">
- <context-entry name="application">someAppName</context-entry>
+ <application>someAppName</application>
</context>
- <!-- combinationPolicy type="" / -->
+ <!-- combinationPolicy class="" / -->
<!-- Configuration definition. -->
<property-sources>
- <source enabled="${stage=TEST || stage=PTA || stage=PROD}"
- type="env-properties">
- <filter type="PropertyMapping">
- <param name="mapTarget">ENV.</param>
- </filter>
- <filter type="AccessMask">
- <param name="roles">admin,power-user</param>
- <param name="policy">mask</param>
- <param name="mask">*****</param>
- <param name="matchExpression">SEC_</param>
- </filter>
- </source>
- <source type="sys-properties" >
- <filter type="ImmutablePropertySource" />
- </source>
- <source type="file" refreshable="true">
- <name>config.json</name>
- <param name="location">config.json</param>
- </source>
- <source type="file" refreshable="true">
- <name>config.xml</name>
- <param name="location">config.xml</param>
- <param name="formats">xml-properties</param>
- </source>
- <source-provider type="resource">
- <name>classpath:application-config.yml</name>
- <param name="location">/META-INF/application-config.yml</param>
- </source-provider>
- <source type="ch.mypack.MyClassSource" />
+ <env-properties enabled="${stage=TEST || stage=PTA || stage=PROD}">
+ <filters>
+ <Map target="ENV."/>
+ <Mask policy="MULTIVALUE"
+ mask="*****"
+ matches="SEC_"/>
+ </filters>
+ </env-properties>
+ <sys-properties >
+ <filters>
+ <Immutable />
+ </filters>
+ </sys-properties>
+ <file location="config.json" refreshable="true" />
+ <file location="config.xml" formats="xml-properties" refreshable="true" />
+ <resource location="/META-INF/application-config.yml"/>
+ <ch.mypack.MyClassSource />
<!--<include enabled="${stage==TEST}">TEST-config.xml</include>-->
- <source-provider type="resource" enabled="${configdir != null}">
- <name>config-dir</name>
- <param name="location">/${configdir}/**/*.json</param>
- </source-provider>
- <source type="url" refreshable="true">
- <name>remote</name>
- <param name="location">https://www.confdrive.com/cfg/customerId=1234</param>
- <param name="formats">json</param>
- <filter type="CachedPropertySource">
- <param name="ttl">30 SECOND</param>
- </filter>
- </source>
+ <resources location="${configdir}/**/*.json" enabled="${configdir != null}" />
+ <url location="https://www.confdrive.com/cfg/customerId=1234"
+ formats="json"
+ refreshable="true">
+ <filters>
+ <Cached ttl="30 SECOND"/>
+ </filters>
+ </url>
</property-sources>
<property-filters>
- <filter type="UsageTrackerFilter"/>
- <filter type="AccessControl">
- <param name="roles">admin,power-user</param>
- <param name="policy">hide</param>
- <param name="expression">*.secret</param>
- </filter>
- <filter type="Cache">
- <param name="ttl">30000</param>
- <param name="expression">cached.*</param>
- </filter>
+ <Secured roles="admin,power-user" matches="*.secret" policy="hide"/>
+ <Cached timeout="30000" maxSize="300" matches="cached.*"/>
</property-filters>
<property-converters>
<!--<converter type="AllInOneConverter"/>-->
[5/7] incubator-tamaya-sandbox git commit: TAMAYA-145: Simplified
syntax and MetaContext. Added tests.
Posted by an...@apache.org.
TAMAYA-145: Simplified syntax and MetaContext. Added tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/10d711e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/10d711e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/10d711e6
Branch: refs/heads/master
Commit: 10d711e6a7e15996c54baad0edf0b38102d3afa7
Parents: 098c75f
Author: anatole <an...@apache.org>
Authored: Tue Apr 18 00:14:42 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Apr 18 00:14:42 2017 +0200
----------------------------------------------------------------------
.../apache/tamaya/metamodel/CachedFilter.java | 108 +++++++++++
.../org/apache/tamaya/metamodel/HideFilter.java | 67 +++++++
.../tamaya/metamodel/ImmutableFilter.java | 55 ++++++
.../org/apache/tamaya/metamodel/MapFilter.java | 101 ++++++++++
.../org/apache/tamaya/metamodel/MaskFilter.java | 121 ++++++++++++
.../apache/tamaya/metamodel/MetaContext.java | 112 +++--------
.../apache/tamaya/metamodel/SecuredFilter.java | 119 ++++++++++++
.../metamodel/ext/FilteredPropertySource.java | 25 ++-
.../internal/CombinationPolicyReader.java | 2 +-
.../internal/ComponentConfigurator.java | 19 +-
.../metamodel/internal/ContextReader.java | 181 ------------------
.../metamodel/internal/MetaContextReader.java | 185 +++++++++++++++++++
.../internal/PropertyConverterReader.java | 55 +++---
.../internal/PropertyFilterReader.java | 47 +++--
.../internal/PropertySourceReader.java | 132 +++++++------
.../factories/FilePropertySourceFactory.java | 10 +-
.../ResourcePropertySourceFactory.java | 8 +-
.../ResourcePropertySourceProviderFactory.java | 8 +-
.../factories/URLPropertySourceFactory.java | 6 +-
.../internal/resolver/PropertiesResolver.java | 13 +-
.../org.apache.tamaya.metamodel.spi.ItemFactory | 7 +
...tamaya.metamodel.spi.MetaConfigurationReader | 2 +-
.../tamaya/metamodel/ext/IntegrationTest.java | 107 ++++++++++-
.../tamaya/metamodel/ext/MyConverter.java | 33 ++++
.../apache/tamaya/metamodel/ext/MyFilter.java | 33 ++++
.../tamaya/metamodel/ext/MyPropertySource.java | 35 ++++
.../resources/IntegrationTests/context-test.xml | 29 +++
.../default-propertyconverters-test.xml | 31 ++++
.../default-propertyfilters-test.xml | 26 +++
.../default-propertysources-test.xml | 29 +++
.../propertyconverters-test.xml | 30 +++
.../IntegrationTests/propertyfilters-test.xml | 26 +++
.../IntegrationTests/propertysources-test.xml | 25 +++
.../org.apache.tamaya.spi.PropertyFilter | 19 ++
metamodel/src/test/resources/tamaya-config.xml | 96 ++++------
35 files changed, 1419 insertions(+), 483 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
new file mode 100644
index 0000000..c07e11d
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
@@ -0,0 +1,108 @@
+package org.apache.tamaya.metamodel;/*
+ * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+ */
+
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Simple filter that never changes a key/value pair returned, regardless if a value
+ * is changing underneath, hereby different values for single and multi-property access
+ * are considered.
+ */
+public class CachedFilter implements PropertyFilter{
+
+ private String matches;
+ private Map<String, CachedEntry> cachedEntries = new ConcurrentHashMap<>();
+ private int maxSize = -1;
+ private long timeout = TimeUnit.MINUTES.toMillis(5);
+
+ /**
+ * Factory for configuring immutable property filter.
+ */
+ public static final class CachedFilterFactory implements ItemFactory<PropertyFilter> {
+ @Override
+ public String getName() {
+ return "Cached";
+ }
+
+ @Override
+ public PropertyFilter create(Map<String,String> parameters) {
+ return new CachedFilter();
+ }
+
+ @Override
+ public Class<? extends PropertyFilter> getType() {
+ return PropertyFilter.class;
+ }
+ }
+
+ public String getMatches() {
+ return matches;
+ }
+
+ public CachedFilter setMatches(String matches) {
+ this.matches = matches;
+ return this;
+ }
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ if(matches !=null){
+ if(value.getKey().matches(matches)){
+ return resolveCachedEntry(value);
+ }
+ }
+ return value;
+ }
+
+ /**
+ * Method checks for a cached value. if present and valid the cached value is returned.
+ * If not valid the cached entry is removed/updated.
+ * @param value
+ * @return
+ */
+ private PropertyValue resolveCachedEntry(PropertyValue value) {
+ if(maxSize>0 && maxSize<=this.cachedEntries.size()){
+ return value;
+ }
+ CachedEntry ce = cachedEntries.get(value.getKey());
+ if(ce==null || !ce.isValid()){
+ if(value!=null) {
+ ce = new CachedEntry(value, System.currentTimeMillis() + timeout);
+ this.cachedEntries.put(value.getKey(), ce);
+ }
+ }
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "CachedFilter{" +
+ "matches='" + matches + '\'' +
+ ", cache-size=" + cachedEntries.size() +
+ ", max-size=" + maxSize +
+ ", timeout=" + timeout +
+ '}';
+ }
+
+ private static final class CachedEntry{
+ long ttl;
+ PropertyValue value;
+
+ public CachedEntry (PropertyValue value, long ttl){
+ this.ttl = ttl;
+ this.value = value;
+ }
+
+ public boolean isValid(){
+ return System.currentTimeMillis() > ttl;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
new file mode 100644
index 0000000..2bd701c
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
@@ -0,0 +1,67 @@
+package org.apache.tamaya.metamodel;/*
+ * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+ */
+
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.PropertyValueBuilder;
+
+import java.util.Map;
+
+/**
+ * Simple filter that never changes a key/value pair returned, regardless if a value
+ * is changing underneath, hereby different values for single and multi-property access
+ * are considered.
+ */
+public class HideFilter implements PropertyFilter{
+
+ private String matches;
+
+ /**
+ * Factory for configuring immutable property filter.
+ */
+ public static final class HideFilterFactory implements ItemFactory<PropertyFilter> {
+ @Override
+ public String getName() {
+ return "Hide";
+ }
+
+ @Override
+ public PropertyFilter create(Map<String,String> parameters) {
+ return new HideFilter();
+ }
+
+ @Override
+ public Class<? extends PropertyFilter> getType() {
+ return PropertyFilter.class;
+ }
+ }
+
+ public String getMatches() {
+ return matches;
+ }
+
+ public HideFilter setMatches(String matches) {
+ this.matches = matches;
+ return this;
+ }
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ if(matches !=null){
+ if(value.getKey().matches(matches)){
+ return null;
+ }
+ }
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "HideFilter{" +
+ "matches='" + matches + '\'' +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
new file mode 100644
index 0000000..90c65f5
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
@@ -0,0 +1,55 @@
+package org.apache.tamaya.metamodel;/*
+ * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+ */
+
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Simple filter that never changes a key/value pair returned, regardless if a value
+ * is changing underneath, hereby different values for single and multi-property access
+ * are considered.
+ */
+public class ImmutableFilter implements PropertyFilter{
+
+ /**
+ * Factory for configuring immutable property filter.
+ */
+ public static final class ImmutableFilterFactory implements ItemFactory<PropertyFilter> {
+ @Override
+ public String getName() {
+ return "Immutable";
+ }
+
+ @Override
+ public PropertyFilter create(Map<String,String> parameters) {
+ return new ImmutableFilter();
+ }
+
+ @Override
+ public Class<? extends PropertyFilter> getType() {
+ return PropertyFilter.class;
+ }
+ }
+
+ private Map<String,PropertyValue> map = new ConcurrentHashMap<>();
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ String key = value.getKey();
+ if(!context.isSinglePropertyScoped()) {
+ key = value.getKey() + "_all";
+ }
+ PropertyValue val = map.get(key);
+ if(val==null){
+ map.put(key, value);
+ val = value;
+ }
+ return val;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
new file mode 100644
index 0000000..ab521dd
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
@@ -0,0 +1,101 @@
+package org.apache.tamaya.metamodel;/*
+ * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+ */
+
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.PropertyValueBuilder;
+
+import java.util.Map;
+
+/**
+ * Simple filter that never changes a key/value pair returned, regardless if a value
+ * is changing underneath, hereby different values for single and multi-property access
+ * are considered.
+ */
+public class MapFilter implements PropertyFilter{
+
+ private String target;
+ private String cutoff;
+ private String matches;
+
+ /**
+ * Factory for configuring immutable property filter.
+ */
+ public static final class MapFilterFactory implements ItemFactory<PropertyFilter> {
+ @Override
+ public String getName() {
+ return "Map";
+ }
+
+ @Override
+ public PropertyFilter create(Map<String,String> parameters) {
+ return new MapFilter();
+ }
+
+ @Override
+ public Class<? extends PropertyFilter> getType() {
+ return PropertyFilter.class;
+ }
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ public MapFilter setTarget(String target) {
+ this.target = target;
+ return this;
+ }
+
+ public String getCutoff() {
+ return cutoff;
+ }
+
+ public MapFilter setCutoff(String cutoff) {
+ this.cutoff = cutoff;
+ return this;
+ }
+
+ public String getMatches() {
+ return matches;
+ }
+
+ public MapFilter setMatches(String matches) {
+ this.matches = matches;
+ return this;
+ }
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ PropertyValueBuilder b = value.toBuilder();
+ String key = value.getKey();
+ if(matches !=null){
+ if(!value.getKey().matches(matches)){
+ return value;
+ }
+ }
+ if(cutoff !=null){
+ if(value.getKey().startsWith(cutoff)){
+ key = key.substring(cutoff.length());
+ b.setKey(key);
+ }
+ }
+ if(target!=null){
+ key = target+key;
+ b.setKey(key);
+ }
+ return b.build();
+ }
+
+ @Override
+ public String toString() {
+ return "MapFilter{" +
+ "target='" + target + '\'' +
+ ", cutoff='" + cutoff + '\'' +
+ ", matches='" + matches + '\'' +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
new file mode 100644
index 0000000..d374dc4
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
@@ -0,0 +1,121 @@
+package org.apache.tamaya.metamodel;/*
+ * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+ */
+
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Simple filter that never changes a key/value pair returned, regardless if a value
+ * is changing underneath, hereby different values for single and multi-property access
+ * are considered.
+ */
+public class MaskFilter implements PropertyFilter{
+
+ private String matches;
+ private List<String> roles = new ArrayList<>();
+ private String mask = "*****";
+ private TargetPolicy policy = TargetPolicy.ALL;
+
+ /**
+ * Factory for configuring immutable property filter.
+ */
+ public static final class MaskFilterFactory implements ItemFactory<PropertyFilter> {
+ @Override
+ public String getName() {
+ return "Mask";
+ }
+
+ @Override
+ public PropertyFilter create(Map<String,String> parameters) {
+ return new MaskFilter();
+ }
+
+ @Override
+ public Class<? extends PropertyFilter> getType() {
+ return PropertyFilter.class;
+ }
+ }
+
+ public String getMatches() {
+ return matches;
+ }
+
+ public MaskFilter setMatches(String matches) {
+ this.matches = matches;
+ return this;
+ }
+
+ public List<String> getRoles() {
+ return roles;
+ }
+
+ public MaskFilter setRoles(List<String> roles) {
+ this.roles.clear();
+ for(String role:roles) {
+ this.roles.add(role.trim());
+ }
+ return this;
+ }
+
+ public MaskFilter setRoles(String... roles) {
+ return setRoles(Arrays.asList(roles));
+ }
+
+ public MaskFilter setRoles(String roles){
+ setRoles(roles.split(","));
+ return this;
+ }
+
+ public String getMask() {
+ return mask;
+ }
+
+ public MaskFilter setMask(String mask) {
+ this.mask = mask;
+ return this;
+ }
+
+ public TargetPolicy getPolicy() {
+ return policy;
+ }
+
+ public MaskFilter setPolicy(TargetPolicy policy) {
+ this.policy = policy;
+ return this;
+ }
+
+ public MaskFilter setPolicy(String policy) {
+ return setPolicy(TargetPolicy.valueOf(policy));
+ }
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ if(matches !=null){
+ if(value.getKey().matches(matches)){
+ return null;
+ }
+ }
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "HideFilter{" +
+ "matches='" + matches + '\'' +
+ '}';
+ }
+
+ private enum TargetPolicy {
+ ALL,
+ SINGLEVALUE,
+ MULTIVALUE
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
index 1952d8e..9082fc3 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
@@ -18,31 +18,22 @@
*/
package org.apache.tamaya.metamodel;
-import org.apache.tamaya.functions.Supplier;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.WeakHashMap;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
/**
- * Class managing the configuration system's shared context. This
+ * Class managing a configuration system's meta-context. This
* context is used by the configuration system to evaluate the
* right properties, e.g. by defining the current stage or labels
- * that apply to the current configuration. Hereby context are
+ * that apply to the current configuration. Hereby contexts are
* <ul>
- * <li>identified by unique names</li>
- * <li>stackable into a context hierarchy, see {@link #combineWith(MetaContext...)}</li>
- * <li>optionally be valid only in some contexts or for a limited time, see {@link #isValid()},
- * {@link #getInstance(String, Supplier)}</li>
+ * <li>stackable into a context hierarchy, see {@link #combineWith(MetaContext, MetaContext...)}</li>
* <li>providing key/values only valid for a certain time (assigned a TTL), see {@link #setProperty(String, String, int, TimeUnit)},
* {@link #setProperties(Map, long, TimeUnit)}</li>
* </ul>
- * Additionally there is special support for thread related contexts, see {@link #getThreadInstance(boolean)}.
- * Finally there is also one special globally shared context instance, see {@link #getCurrentInstance(boolean)}.
+ * Additionally there is special support for thread related contexts, see {@link #getThreadInstance()}.
+ * Finally there is also one special globally shared context instance, see {@link #getInstance()}.
*/
public final class MetaContext {
@@ -52,54 +43,32 @@ public final class MetaContext {
return new MetaContext();
}
};
- public static final String DEFAULT_CONTEXT_NAME = "<DEFAULT>";
-
- private String id;
-
- private Supplier<Boolean> validSupplier;
private final Map<String,Value> properties = new ConcurrentHashMap<>();
- private static final Map<String,MetaContext> CONTEXTS = new WeakHashMap<>();
+ private static final MetaContext globalContext = new MetaContext();
- /**
- * Access a context by name. Contexts are managed as weak references in this class. If no
- * such context exists, a new instance is created.
- * @param contextName the context name, not null.
- * @return the context instance, never null.
- */
- public static MetaContext getInstance(String contextName) {
- return getInstance(contextName, null);
+ /** The unique id of this context. */
+ private MetaContext(){
+ setProperty("_id", UUID.randomUUID().toString());
}
/**
- * Access the default context. Contexts are managed as weak references in this class. If no
- * such context exists, a new instance is created.
- * @return the context instance, never null.
+ * Get the context's id.
+ * @return
*/
- public static MetaContext getDefaultInstance(){
- return getInstance(DEFAULT_CONTEXT_NAME);
+ public String getId() {
+ return getProperty("_id", "N/A");
}
+
/**
- * Access a context by name. Contexts are managed as weak references in this class. If no
- * such valid context exists, a new instance is created, using the given {@code validSupplier}.
- * @param contextName the context name, not null.
+ * Access the global context. There might be other contexts used in the system, which also
+ * may delegate to the global context.
* @return the context instance, never null.
*/
- public static MetaContext getInstance(String contextName, Supplier<Boolean> validSupplier){
- synchronized(CONTEXTS){
- MetaContext ctx = CONTEXTS.get(contextName);
- if(ctx!=null && ctx.isValid()){
- return ctx;
- }
- ctx = new MetaContext();
- ctx.id = Objects.requireNonNull(contextName);
- ctx.validSupplier = validSupplier;
- CONTEXTS.put(contextName, ctx);
- return ctx;
- }
-
+ public static MetaContext getInstance(){
+ return globalContext;
}
/**
@@ -109,7 +78,7 @@ public final class MetaContext {
* @return the corresponding context, never null.
*/
public static MetaContext getThreadInstance(boolean reinit){
- MetaContext threadContext =THREAD_CONTEXT.get();
+ MetaContext threadContext = THREAD_CONTEXT.get();
if(reinit){
threadContext.properties.clear();
}
@@ -121,44 +90,21 @@ public final class MetaContext {
* context (overriding).
* @return the corresponding context, never null.
*/
- public MetaContext getCurrentInstance(){
- return getCurrentInstance(false);
+ public MetaContext getThreadInstance(){
+ return getThreadInstance(false);
}
- /**
- * Access the current context, which actually is the current context, combined with the thread based
- * context (overriding).
- * @param reinit if true, clear's the thread's meta context.
- * @return the corresponding context, never null.
- */
- public MetaContext getCurrentInstance(boolean reinit){
- return this.combineWith(getThreadInstance(reinit));
- }
/**
- * Method to evaluate if a context is valid. This basically depends on the
- * {@code validSupplier}, if any is set. If no supplier is present the context is valid.
- *
- * @return true, if this context is valid.
- */
- public boolean isValid(){
- return this.validSupplier == null || validSupplier.get();
- }
-
-
- /**
- * Combine this context with the other contexts given, hereby only contexts are included
- * which are {@code valid}, see {@link #isValid()}.
+ * Combine this context with the other contexts given.
* @param contexts the context to merge with this context.
* @return the newly created Context.
*/
- public MetaContext combineWith(MetaContext... contexts) {
+ public static MetaContext combineWith(MetaContext baseContext, MetaContext... contexts) {
MetaContext newContext = new MetaContext();
- newContext.properties.putAll(this.properties);
+ newContext.properties.putAll(baseContext.properties);
for(MetaContext ctx:contexts) {
- if(ctx.isValid()) {
- newContext.properties.putAll(ctx.properties);
- }
+ newContext.properties.putAll(ctx.properties);
}
return newContext;
}
@@ -311,8 +257,10 @@ public final class MetaContext {
@Override
public String toString() {
- return "Context{" +
- properties +
+ return "MetaContext{" +
+ "id=" + getId() +
+ ", properties=" + properties +
+ ", global=" + (this == MetaContext.globalContext) +
'}';
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
new file mode 100644
index 0000000..5878106
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
@@ -0,0 +1,119 @@
+package org.apache.tamaya.metamodel;/*
+ * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+ */
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+
+import javax.security.auth.Subject;
+import java.security.*;
+import java.util.Map;
+import java.util.logging.Logger;
+
+/**
+ * Simple filter that never changes a key/value pair returned, regardless if a value
+ * is changing underneath, hereby different values for single and multi-property access
+ * are considered.
+ */
+public class SecuredFilter implements PropertyFilter{
+
+ private static final Logger LOG = Logger.getLogger(SecuredFilter.class.getName());
+
+ private String matches;
+ private String roles;
+ private String[]rolesArray;
+ private SecurePolicy policy = SecurePolicy.HIDE;
+
+ /**
+ * Factory for configuring immutable property filter.
+ */
+ public static final class SecuredFilterFactory implements ItemFactory<PropertyFilter> {
+ @Override
+ public String getName() {
+ return "Secured";
+ }
+
+ @Override
+ public PropertyFilter create(Map<String,String> parameters) {
+ return new SecuredFilter();
+ }
+
+ @Override
+ public Class<? extends PropertyFilter> getType() {
+ return PropertyFilter.class;
+ }
+ }
+
+ public String getMatches() {
+ return matches;
+ }
+
+ public SecuredFilter setMatches(String matches) {
+ this.matches = matches;
+ return this;
+ }
+
+ public String getRoles() {
+ return roles;
+ }
+
+ public SecuredFilter setRoles(String roles) {
+ this.roles = roles;
+ this.rolesArray = roles.split(",");
+ return this;
+ }
+
+ public SecurePolicy getPolicy() {
+ return policy;
+ }
+
+ public SecuredFilter setPolicy(SecurePolicy policy) {
+ this.policy = policy;
+ return this;
+ }
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ if(matches !=null){
+ if(!value.getKey().matches(matches)) {
+ return value;
+ }
+ }
+ Subject s = javax.security.auth.Subject.getSubject(AccessController.getContext());
+ for(Principal principal:s.getPrincipals()){
+ for(String role:rolesArray) {
+ if(principal.getName().equals(role)){
+ return value;
+ }
+ }
+ }
+ switch(policy){
+ case THROW_EXCPETION:
+ throw new ConfigException("Unauthorized access to '"+value.getKey()+"', not in " + roles);
+ case WARN_ONLY:
+ LOG.warning("Unauthorized access to '"+value.getKey()+"', not in " + roles);
+ return value;
+ case HIDE:
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "SecuredFilter{" +
+ "matches='" + matches + '\'' +
+ ", roles='" + roles + '\'' +
+ ", policy='" + policy + '\'' +
+ '}';
+ }
+
+ public enum SecurePolicy{
+ HIDE,
+ WARN_ONLY,
+ THROW_EXCPETION
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/FilteredPropertySource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/FilteredPropertySource.java
index 43d1836..fec8777 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/FilteredPropertySource.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/FilteredPropertySource.java
@@ -142,6 +142,21 @@ public final class FilteredPropertySource extends BasePropertySource {
}
/**
+ * Removes the (first) given filter, if present.
+ * @param filterClass the class of the filter to remove, not null.
+ */
+ public void removePropertyFilter(Class<? extends PropertyFilter> filterClass){
+ synchronized(filters){
+ for(PropertyFilter f:filters){
+ if(f.getClass().equals(filterClass)){
+ filters.remove(f);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
* Access the current filters present.
* @return a copy of the current filter list.
*/
@@ -152,13 +167,11 @@ public final class FilteredPropertySource extends BasePropertySource {
}
@Override
- public String toString() {
+ protected String toStringValues() {
synchronized (filters) {
- return "FilteredPropertySource{" +
- "\n wrapped=" + wrapped +
- "\n filters=" + this.filters +
- "\n base=" + super.toString() +
- "\n}";
+ return super.toStringValues() +
+ " wrapped=" + wrapped + '\n' +
+ " filters=" + this.filters + '\n';
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java
index 4c9217d..9e31add 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java
@@ -49,7 +49,7 @@ public class CombinationPolicyReader implements MetaConfigurationReader{
throw new ConfigException("Only one combination policy can be applied.");
}
Node node = nodeList.item(0);
- String type = node.getAttributes().getNamedItem("type").getNodeValue();
+ String type = node.getAttributes().getNamedItem("class").getNodeValue();
LOG.finest("Loading combination policy configured: " + type);
ItemFactory<PropertyValueCombinationPolicy> policyFactory = ItemFactoryManager.getInstance().getFactory(PropertyValueCombinationPolicy.class, type);
PropertyValueCombinationPolicy policy = policyFactory.create(ComponentConfigurator.extractParameters(node));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
index 93c50da..8832d98 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.metamodel.internal;
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -41,8 +42,17 @@ public final class ComponentConfigurator<T> {
public static void configure(Object instance, Node node) {
NodeList entryNodes = node.getChildNodes();
Map<String,String> params = new HashMap<>();
+ for(int c=0;c<node.getAttributes().getLength();c++){
+ Node attr = node.getAttributes().item(c);
+ String key = attr.getNodeName();
+ String value = attr.getNodeValue();
+ params.put(key, value);
+ }
for(int c=0;c<entryNodes.getLength();c++) {
Node filterNode = entryNodes.item(c);
+ if(filterNode.getNodeType()!=Node.ELEMENT_NODE){
+ continue;
+ }
if ("param".equals(filterNode.getNodeName())) {
String key = filterNode.getAttributes().getNamedItem("name").getNodeValue();
String value = filterNode.getTextContent();
@@ -71,8 +81,15 @@ public final class ComponentConfigurator<T> {
}
public static Map<String, String> extractParameters(Node node) {
- NodeList entryNodes = node.getChildNodes();
Map<String,String> params = new HashMap<>();
+ NamedNodeMap attributes = node.getAttributes();
+ for(int c=0;c<attributes.getLength();c++) {
+ Node pn = attributes.item(c);
+ String key = pn.getNodeName();
+ String value = pn.getNodeValue();
+ params.put(key, value);
+ }
+ NodeList entryNodes = node.getChildNodes();
for(int c=0;c<entryNodes.getLength();c++) {
Node filterNode = entryNodes.item(c);
if ("param".equals(filterNode.getNodeName())) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
deleted file mode 100644
index 5e74f75..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
+++ /dev/null
@@ -1,181 +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.metamodel.internal;
-
-import org.apache.tamaya.metamodel.MetaContext;
-import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
-import org.apache.tamaya.metamodel.spi.SimpleResolver;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import javax.annotation.Priority;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
-
-
-/**
- * Meta-configuration reader that reads the shared context data.
- */
-@Priority(-1)
-public class ContextReader implements MetaConfigurationReader {
-
- private static final Logger LOG = Logger.getLogger(ContextReader.class.getName());
-
- private Map<String,SimpleResolver> resolvers = new ConcurrentHashMap<>();
-
- public ContextReader(){
- for(SimpleResolver resolver: ServiceContextManager.getServiceContext()
- .getServices(SimpleResolver.class)){
- this.resolvers.put(resolver.getResolverId(), resolver);
- }
- }
-
- public void addResolver(SimpleResolver resolver){
- if(!this.resolvers.containsKey(resolver.getResolverId())) {
- this.resolvers.put(resolver.getResolverId(), resolver);
- }
- }
-
- public void removeResolver(SimpleResolver resolver){
- this.resolvers.remove(resolver.getResolverId());
- }
-
- public Set<String> getResolverIds(){
- return this.resolvers.keySet();
- }
-
- public SimpleResolver getResolver(String resolverKey){
- return this.resolvers.get(resolverKey);
- }
-
- @Override
- public void read(Document document, ConfigurationContextBuilder contextBuilder) {
- NodeList nodeList = document.getDocumentElement().getElementsByTagName("context");
- String contextName = null;
- LOG.finer("Reading " + nodeList.getLength() + " meta context entries...");
- for(int i=0;i<nodeList.getLength();i++){
- Node node = nodeList.item(i);
- if(node.getNodeName().equals("context")){
- Node nameNode = node.getAttributes().getNamedItem("name");
- if(nameNode!=null){
- contextName = nameNode.getTextContent();
- }
- MetaContext context = contextName!=null?MetaContext.getInstance(contextName):MetaContext.getDefaultInstance();
- NodeList entryNodes = node.getChildNodes();
- for(int c=0;c<entryNodes.getLength();c++){
- Node entryNode = entryNodes.item(c);
- if("context-entry".equals(entryNode.getNodeName())){
- String key = entryNode.getAttributes().getNamedItem("name").getNodeValue();
- String value = entryNode.getTextContent();
- resolvePlaceholders(value);
- LOG.finest("Applying context entry: " + key + '=' + value + " on " + contextName);
- context.setProperty(key, value);
- }
- }
- }
- }
- }
-
- private String resolvePlaceholders(String value) {
- StringBuilder result = new StringBuilder();
- StringBuilder exp = new StringBuilder();
- final int INVALUE = 0;
- final int BEFORE_EXP = 1;
- final int INEXP = 2;
- int state = INVALUE;
- StringTokenizer tokenizer = new StringTokenizer(value, "${}", true);
- while(tokenizer.hasMoreTokens()){
- String token = tokenizer.nextToken();
- switch(token){
- case "$":
- switch(state){
- case INVALUE:
- default:
- state = BEFORE_EXP;
- break;
- case BEFORE_EXP: // escaped
- result.append(token);
- state = INVALUE;
- break;
- case INEXP:
- exp.append(token);
- break;
- }
- break;
- case "{":
- switch(state){
- case BEFORE_EXP:
- state = INEXP;
- break;
- case INVALUE:
- case INEXP:
- default:
- result.append(token);
- break;
- }
- case "}":
- switch(state){
- case INVALUE:
- result.append(token);
- break;
- case INEXP:
- result.append(evaluateExpression(exp.toString()));
- exp.setLength(0);
- state = INVALUE;
- break;
- case BEFORE_EXP:
- result.append("$").append(token);
- state = INVALUE;
- break;
- }
- break;
- default:
- result.append(token);
- }
- }
- return result.toString();
- }
-
- private String evaluateExpression(String exp) {
- String[] parts = exp.split(":", 2);
- if(parts.length<2){
- return "--{MISSING RESOLVER ID in "+exp+"}";
- }
- SimpleResolver resolver = this.resolvers.get(parts[0]);
- if(resolver==null){
- return "--{NO RESOLVER FOUND for "+exp+"}";
- }
- try{
- String resolved = resolver.evaluate(parts[1]);
- if(resolved==null) {
- return "--{NOT RESOLVABLE:" + exp + "}";
- }else{
- return resolved;
- }
- }catch(Exception e){
- return "--{ERROR:"+exp+":"+e+"}";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java
new file mode 100644
index 0000000..8ec1c76
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java
@@ -0,0 +1,185 @@
+/*
+ * 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.metamodel.internal;
+
+import org.apache.tamaya.metamodel.MetaContext;
+import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
+import org.apache.tamaya.metamodel.spi.SimpleResolver;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.annotation.Priority;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+
+
+/**
+ * Meta-configuration reader that reads the shared context data.
+ */
+@Priority(-1)
+public class MetaContextReader implements MetaConfigurationReader {
+
+ private static final Logger LOG = Logger.getLogger(MetaContextReader.class.getName());
+
+ private Map<String,SimpleResolver> resolvers = new ConcurrentHashMap<>();
+
+ public MetaContextReader(){
+ for(SimpleResolver resolver: ServiceContextManager.getServiceContext()
+ .getServices(SimpleResolver.class)){
+ this.resolvers.put(resolver.getResolverId(), resolver);
+ }
+ }
+
+ public void addResolver(SimpleResolver resolver){
+ if(!this.resolvers.containsKey(resolver.getResolverId())) {
+ this.resolvers.put(resolver.getResolverId(), resolver);
+ }
+ }
+
+ public void removeResolver(SimpleResolver resolver){
+ this.resolvers.remove(resolver.getResolverId());
+ }
+
+ public Set<String> getResolverIds(){
+ return this.resolvers.keySet();
+ }
+
+ public SimpleResolver getResolver(String resolverKey){
+ return this.resolvers.get(resolverKey);
+ }
+
+ @Override
+ public void read(Document document, ConfigurationContextBuilder contextBuilder) {
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("context");
+ LOG.finer("Reading " + nodeList.getLength() + " meta context entries...");
+ for(int i=0;i<nodeList.getLength();i++){
+ Node node = nodeList.item(i);
+ if(node.getNodeName().equals("context")){
+ MetaContext context = MetaContext.getInstance();
+ NodeList entryNodes = node.getChildNodes();
+ for(int c=0;c<entryNodes.getLength();c++){
+ Node entryNode = entryNodes.item(c);
+ if(entryNode.getNodeType()==Node.ELEMENT_NODE) {
+ String key = entryNode.getNodeName();
+ String value = entryNode.getTextContent();
+ value = resolvePlaceholders(value);
+ LOG.finest("MetaContext: " + key + '=' + value);
+ context.setProperty(key, value);
+ }
+ }
+ }
+ }
+ }
+
+ private String resolvePlaceholders(String value) {
+ StringBuilder result = new StringBuilder();
+ StringBuilder exp = new StringBuilder();
+ final int INVALUE = 0;
+ final int BEFORE_EXP = 1;
+ final int INEXP = 2;
+ int state = INVALUE;
+ StringTokenizer tokenizer = new StringTokenizer(value, "${}", true);
+ while(tokenizer.hasMoreTokens()){
+ String token = tokenizer.nextToken();
+ switch(token){
+ case "$":
+ switch(state){
+ case INVALUE:
+ default:
+ state = BEFORE_EXP;
+ break;
+ case BEFORE_EXP: // escaped
+ result.append(token);
+ state = INVALUE;
+ break;
+ case INEXP:
+ exp.append(token);
+ break;
+ }
+ break;
+ case "{":
+ switch(state){
+ case BEFORE_EXP:
+ state = INEXP;
+ break;
+ case INVALUE:
+ case INEXP:
+ default:
+ result.append(token);
+ break;
+ }
+ break;
+ case "}":
+ switch(state){
+ case INVALUE:
+ result.append(token);
+ break;
+ case INEXP:
+ result.append(evaluateExpression(exp.toString()));
+ exp.setLength(0);
+ state = INVALUE;
+ break;
+ case BEFORE_EXP:
+ result.append("$").append(token);
+ state = INVALUE;
+ break;
+ }
+ break;
+ default:
+ switch(state){
+ case INEXP:
+ exp.append(token);
+ break;
+ default:
+ result.append(token);
+ break;
+ }
+
+ }
+ }
+ return result.toString();
+ }
+
+ private String evaluateExpression(String exp) {
+ String[] parts = exp.split(":", 2);
+ if(parts.length<2){
+ return "--{MISSING RESOLVER ID in "+exp+"}";
+ }
+ SimpleResolver resolver = this.resolvers.get(parts[0]);
+ if(resolver==null){
+ return "--{NO RESOLVER FOUND for "+exp+"}";
+ }
+ try{
+ String resolved = resolver.evaluate(parts[1]);
+ if(resolved==null) {
+ return "--{NOT RESOLVABLE:" + exp + "}";
+ }else{
+ return resolved;
+ }
+ }catch(Exception e){
+ return "--{ERROR:"+exp+":"+e+"}";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
index f82e92d..9490a78 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
@@ -18,14 +18,13 @@
*/
package org.apache.tamaya.metamodel.internal;
+import org.apache.tamaya.ConfigException;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -49,38 +48,36 @@ public class PropertyConverterReader implements MetaConfigurationReader{
return;
}
if(nodeList.getLength()>1){
- LOG.warning("Multiple property-converters sections configured, onyl reading first...");
- return;
+ throw new ConfigException("Only one single property-converters section allowed.");
}
nodeList = nodeList.item(0).getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
Node node = nodeList.item(i);
- try{
- if(node.getNodeName().equals("converter")){
- String type = node.getAttributes().getNamedItem("type").getNodeValue();
- try {
- ItemFactory<PropertyConverter> converterFactory = ItemFactoryManager.getInstance().getFactory(PropertyConverter.class, type);
- if(converterFactory==null){
- LOG.severe("No such property converter: " + type);
- continue;
- }
- Map<String,String> params = ComponentConfigurator.extractParameters(node);
- PropertyConverter converter = converterFactory.create(params);
- if(converter!=null) {
- ComponentConfigurator.configure(converter, node);
- Class targetType = Class.forName(params.get("targetType"));
- LOG.finer("Adding converter for type " + targetType.getName() + ": " + converter.getClass());
- contextBuilder.addPropertyConverters(TypeLiteral.of(targetType), converter);
- }
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to configure PropertyConverter: " + type, e);
- }
- }else if(node.getNodeName().equals("default-converters")){
- LOG.finer("Adding default property converters...");
- contextBuilder.addDefaultPropertyConverters();
+ if(node.getNodeType()!=Node.ELEMENT_NODE) {
+ continue;
+ }
+ String type = node.getNodeName();
+ if("defaults".equals(type)){
+ LOG.finer("Adding default property converters...");
+ contextBuilder.addDefaultPropertyConverters();
+ continue;
+ }
+ try {
+ ItemFactory<PropertyConverter> converterFactory = ItemFactoryManager.getInstance().getFactory(PropertyConverter.class, type);
+ if(converterFactory==null){
+ LOG.severe("No such property converter: " + type);
+ continue;
+ }
+ Map<String,String> params = ComponentConfigurator.extractParameters(node);
+ PropertyConverter converter = converterFactory.create(params);
+ if(converter!=null) {
+ ComponentConfigurator.configure(converter, node);
+ Class targetType = Class.forName(params.get("targetType"));
+ LOG.finer("Adding converter for type " + targetType.getName() + ": " + converter.getClass());
+ contextBuilder.addPropertyConverters(TypeLiteral.of(targetType), converter);
}
- }catch(Exception e){
- LOG.log(Level.SEVERE, "Failed to read property converter configuration: " + node, e);
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertyConverter: " + type, e);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
index 94bb6ec..be6fa2b 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
@@ -18,18 +18,17 @@
*/
package org.apache.tamaya.metamodel.internal;
+import org.apache.tamaya.ConfigException;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySourceProvider;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Map;
-import java.util.logging.Level;
import java.util.logging.Logger;
@@ -48,33 +47,31 @@ public class PropertyFilterReader implements MetaConfigurationReader{
return;
}
if(nodeList.getLength()>1){
- LOG.warning("Multiple property-filters sections configured, onyl reading first...");
- return;
+ throw new ConfigException("Only one single property-filters section allowed.");
}
nodeList = nodeList.item(0).getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
Node node = nodeList.item(i);
- try {
- if ("filter".equals(node.getNodeName())) {
- String type = node.getAttributes().getNamedItem("type").getNodeValue();
- ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type);
- if(filterFactory==null){
- LOG.severe("No such property filter: " + type);
- continue;
- }
- Map<String,String> params = ComponentConfigurator.extractParameters(node);
- PropertyFilter filter = filterFactory.create(params);
- if(filter!=null) {
- ComponentConfigurator.configure(filter, params);
- LOG.finer("Adding configured property filter: " + filter.getClass().getName());
- contextBuilder.addPropertyFilters(filter);
- }
- } else if ("default-filters".equals(node.getNodeName())) {
- LOG.finer("Adding default property filters...");
- contextBuilder.addDefaultPropertyFilters();
- }
- }catch(Exception e){
- LOG.log(Level.SEVERE, "Failed to read property filter configuration: " + node, e);
+ if(node.getNodeType()!=Node.ELEMENT_NODE) {
+ continue;
+ }
+ String type = node.getNodeName();
+ if ("defaults".equals(type)) {
+ LOG.finer("Adding default property filters...");
+ contextBuilder.addDefaultPropertyFilters();
+ continue;
+ }
+ ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type);
+ if(filterFactory==null){
+ LOG.severe("No such property filter: " + type);
+ continue;
+ }
+ Map<String,String> params = ComponentConfigurator.extractParameters(node);
+ PropertyFilter filter = filterFactory.create(params);
+ if(filter!=null) {
+ ComponentConfigurator.configure(filter, params);
+ LOG.finer("Adding configured property filter: " + filter.getClass().getName());
+ contextBuilder.addPropertyFilters(filter);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
index ebcd8e0..a465146 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
@@ -18,7 +18,9 @@
*/
package org.apache.tamaya.metamodel.internal;
-import org.apache.tamaya.metamodel.*;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.metamodel.EnabledPropertySource;
+import org.apache.tamaya.metamodel.MetaContext;
import org.apache.tamaya.metamodel.ext.EnabledPropertySourceProvider;
import org.apache.tamaya.metamodel.ext.FilteredPropertySource;
import org.apache.tamaya.metamodel.ext.RefreshablePropertySource;
@@ -53,57 +55,53 @@ public class PropertySourceReader implements MetaConfigurationReader{
return;
}
if(nodeList.getLength()>1){
- LOG.warning("Multiple property-sources sections configured, onyl reading first...");
- return;
+ throw new ConfigException("Only one single property-source section allowed.");
}
nodeList = nodeList.item(0).getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
Node node = nodeList.item(i);
- try{
- if(node.getNodeName().equals("source")){
- String type = node.getAttributes().getNamedItem("type").getNodeValue();
- try {
- ItemFactory<PropertySource> sourceFactory = ItemFactoryManager.getInstance().getFactory(PropertySource.class, type);
- if(sourceFactory==null){
- LOG.severe("No such property source: " + type);
- continue;
- }
- Map<String,String> params = ComponentConfigurator.extractParameters(node);
- PropertySource ps = sourceFactory.create(params);
- if(ps!=null) {
- ComponentConfigurator.configure(ps, params);
- ps = decoratePropertySource(ps, contextBuilder, node, params);
- LOG.finer("Adding configured property source: " + ps.getName());
- contextBuilder.addPropertySources(ps);
- }
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to configure PropertySource: " + type, e);
- }
- }else if(node.getNodeName().equals("source-provider")){
- String type = node.getAttributes().getNamedItem("type").getNodeValue();
- try {
- ItemFactory<PropertySourceProvider> providerFactory = ItemFactoryManager.getInstance().getFactory(PropertySourceProvider.class, type);
- if(providerFactory==null){
- LOG.severe("No such property source provider: " + type);
- continue;
- }
- Map<String,String> params = ComponentConfigurator.extractParameters(node);
- PropertySourceProvider prov = providerFactory.create(params);
- if(prov!=null) {
- ComponentConfigurator.configure(prov, node);
- prov = decoratePropertySourceProvider(prov, contextBuilder, node, params);
- LOG.finer("Adding configured property source provider: " + prov.getClass().getName());
- contextBuilder.addPropertySources(prov.getPropertySources());
- }
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to configure PropertySourceProvider: " + type, e);
+ if(node.getNodeType()!=Node.ELEMENT_NODE) {
+ continue;
+ }
+ String type = node.getNodeName();
+ if("defaults".equals(type)){
+ LOG.fine("Adding default property sources.");
+ contextBuilder.addDefaultPropertySources();
+ continue;
+ }
+ try {
+ ItemFactory<PropertySource> sourceFactory = ItemFactoryManager.getInstance().getFactory(PropertySource.class, type);
+ if (sourceFactory != null) {
+ LOG.fine("Property source found: " + type);
+ Map<String, String> params = ComponentConfigurator.extractParameters(node);
+ PropertySource ps = sourceFactory.create(params);
+ if (ps != null) {
+ ComponentConfigurator.configure(ps, params);
+ ps = decoratePropertySource(ps, node, params);
+ LOG.finer("Adding configured property source: " + ps.getName());
+ contextBuilder.addPropertySources(ps);
}
- }else if(node.getNodeName().equals("default-sources")){
- LOG.finer("Adding default property sources.");
- contextBuilder.addDefaultPropertySources();
}
- }catch(Exception e){
- LOG.log(Level.SEVERE, "Failed to read property source configuration: " + node, e);
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertySource: " + type, e);
+ continue;
+ }
+ try {
+ ItemFactory<PropertySourceProvider> providerFactory = ItemFactoryManager.getInstance().getFactory(PropertySourceProvider.class, type);
+ if(providerFactory==null){
+ LOG.fine("No such property source provider: " + type);
+ continue;
+ }
+ Map<String,String> params = ComponentConfigurator.extractParameters(node);
+ PropertySourceProvider prov = providerFactory.create(params);
+ if(prov!=null) {
+ ComponentConfigurator.configure(prov, node);
+ prov = decoratePropertySourceProvider(prov, node, params);
+ LOG.finer("Adding configured property source provider: " + prov.getClass().getName());
+ contextBuilder.addPropertySources(prov.getPropertySources());
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertySourceProvider: " + type, e);
}
}
}
@@ -111,37 +109,38 @@ public class PropertySourceReader implements MetaConfigurationReader{
/**
* Decorates a property source to be refreshable or filtered.
* @param ps the wrapped property source
- * @param contextBuilder
*@param configNode the XML config node
* @param params the extracted parameter list @return the property source to be added to the context.
*/
- private PropertySource decoratePropertySource(PropertySource ps, ConfigurationContextBuilder contextBuilder, Node configNode, Map<String, String> params){
+ private PropertySource decoratePropertySource(PropertySource ps, Node configNode, Map<String, String> params){
Node refreshableVal = configNode.getAttributes().getNamedItem("refreshable");
if(refreshableVal!=null && Boolean.parseBoolean(refreshableVal.getNodeValue())){
- if(!(ps instanceof Refreshable)){
- ps = RefreshablePropertySource.of(params, ps);
- }
+ ps = RefreshablePropertySource.of(params, ps);
+ }
+ Node enabledVal = configNode.getAttributes().getNamedItem("enabled");
+ if(enabledVal!=null){
+ ps = new EnabledPropertySource(ps,
+ MetaContext.getInstance().getProperties(),
+ enabledVal.getNodeValue());
}
NodeList childNodes = configNode.getChildNodes();
for(int i=0;i<childNodes.getLength();i++){
Node node = childNodes.item(i);
- if("filter".equals(node.getNodeName())) {
+ if("filters".equals(node.getNodeName())){
ps = FilteredPropertySource.of(ps);
- configureFilter((FilteredPropertySource) ps, node);
+ NodeList filterNodes = node.getChildNodes();
+ for(int f=0;f<filterNodes.getLength();f++) {
+ Node filterNode = filterNodes.item(f);
+ configureFilter((FilteredPropertySource) ps, filterNode);
+ }
}
}
- Node enabledVal = configNode.getAttributes().getNamedItem("enabled");
- if(enabledVal!=null){
- ps = new EnabledPropertySource(ps,
- MetaContext.getDefaultInstance().getProperties(),
- enabledVal.getNodeValue());
- }
return ps;
}
private void configureFilter(FilteredPropertySource ps, Node filterNode) {
try {
- String type = filterNode.getAttributes().getNamedItem("type").getNodeValue();
+ String type = filterNode.getNodeName();
ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type);
if(filterFactory==null){
LOG.severe("No such property filter: " + type);
@@ -162,21 +161,20 @@ public class PropertySourceReader implements MetaConfigurationReader{
/**
* Decorates a property source provider to be refreshable or filtered.
* @param prov the property source provider to be wrapped.
- * @param contextBuilder
- *@param configNode the XML config node
+ * @param configNode the XML config node
* @param params the extracted parameter list @return the property source provider to be added to the context.
*/
- private PropertySourceProvider decoratePropertySourceProvider(PropertySourceProvider prov, ConfigurationContextBuilder contextBuilder, Node configNode, Map<String, String> params){
+ private PropertySourceProvider decoratePropertySourceProvider(PropertySourceProvider prov, Node configNode, Map<String, String> params){
Node refreshableVal = configNode.getAttributes().getNamedItem("refreshable");
+ // Refreshable
if(refreshableVal!=null && Boolean.parseBoolean(refreshableVal.getNodeValue())){
- if(!(prov instanceof Refreshable)){
- prov = RefreshablePropertySourceProvider.of(params, prov);
- }
+ prov = RefreshablePropertySourceProvider.of(params, prov);
}
+ // Enabled
Node enabledVal = configNode.getAttributes().getNamedItem("enabled");
if(enabledVal!=null){
prov = new EnabledPropertySourceProvider(prov,
- MetaContext.getDefaultInstance().getProperties(),
+ MetaContext.getInstance().getProperties(),
enabledVal.getNodeValue());
}
return prov;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
index d3961d4..5acfefd 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
@@ -52,10 +52,8 @@ public final class FilePropertySourceFactory extends ResourcePropertySourceFacto
@Override
protected String example() {
- return "<source type=\""+getName()+"\">\n" +
- " <param name=\"location\">c:/temp/config.xml</param>\n" +
- " <param name=\"formats\">xml-properties</param>\n" +
- "</source>\n";
+ return "<file location=\"c:/temp/config.xml\"\n" +
+ " formats=\"xml-properties\")>\n";
}
@Override
@@ -63,9 +61,9 @@ public final class FilePropertySourceFactory extends ResourcePropertySourceFacto
try {
Path path = Paths.get(location);
if(!path.toFile().exists()){
- LOG.info("Cannot read resource '" + location + "': no such file.");
+ LOG.info("Cannot read file '" + location + "': no such file.");
}else if(!path.toFile().canRead()){
- LOG.info("Cannot read resource '" + location + "': not readable.");
+ LOG.info("Cannot read file '" + location + "': not readable.");
}
return path.toUri().toURL();
} catch (MalformedURLException e) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
index a36fd7f..0248100 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
@@ -41,15 +41,13 @@ public class ResourcePropertySourceFactory extends URLPropertySourceFactory{
@Override
public String getName() {
- return "classpath";
+ return "resource";
}
protected String example() {
- return "<source type=\""+getName()+"\">\n" +
- " <param name=\"location\">/META-INF/config.xml</param>\n" +
- " <param name=\"formats\">xml-properties</param>\n" +
- "</source>\n";
+ return "<resource location=\"META-INF/config.xml\"\n" +
+ " formats=\"xml-properties\")>\n";
}
protected URL createResource(String location) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
index 77f22d4..db5c9b9 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
@@ -41,7 +41,7 @@ public class ResourcePropertySourceProviderFactory implements ItemFactory<Proper
@Override
public String getName() {
- return "resource";
+ return "resources";
}
@Override
@@ -97,10 +97,8 @@ public class ResourcePropertySourceProviderFactory implements ItemFactory<Proper
}
protected String example() {
- return "<source-provider type=\""+getName()+"\">\n" +
- " <param name=\"location\">/META-INF/**/config.xml</param>\n" +
- " <param name=\"formats\">xml-properties</param>\n" +
- "</source-provider>\n";
+ return "<resources location\"/META-INF/**/config.xml\"\n" +
+ " formats=\"xml-properties\"\n/>";
}
protected Collection<URL> createResources(String location) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
index 342eebb..7cf6ab6 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
@@ -68,10 +68,8 @@ public class URLPropertySourceFactory implements ItemFactory<PropertySource>{
}
protected String example() {
- return "<source type=\""+getName()+"\">\n" +
- " <param name=\"location\">http://127.0.0.1:1110/config.xml</param>\n" +
- " <param name=\"formats\">xml-properties</param>\n" +
- "</source>\n";
+ return "<url location=\"http://127.0.0.1:1110/config.xml\"\n" +
+ " formats=\"xml-properties\"\n/>";
}
protected URL createResource(String location) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java
index 4edbe3e..4e70e03 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java
@@ -48,7 +48,7 @@ public final class PropertiesResolver implements SimpleResolver{
if(mainParts.length==1){
return evaluate(expression, null);
}else{
- return evaluate(expression, mainParts[1].trim().substring("default=".length()));
+ return evaluate(mainParts[0], mainParts[1].trim().substring("default=".length()));
}
}
@@ -59,7 +59,7 @@ public final class PropertiesResolver implements SimpleResolver{
return null;
}
switch(parts[0]){
- case "sys":
+ case "system":
return System.getProperty(parts[1],defaultValue);
case "env":
String val = System.getenv(parts[1]);
@@ -68,13 +68,8 @@ public final class PropertiesResolver implements SimpleResolver{
}
return val;
case "ctx":
- if(parts.length==3){
- return MetaContext.getInstance(parts[1])
- .getProperty(parts[2], defaultValue);
- }else{
- return MetaContext.getDefaultInstance()
- .getProperty(parts[1], defaultValue);
- }
+ return MetaContext.getInstance()
+ .getProperty(parts[1], defaultValue);
default:
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
----------------------------------------------------------------------
diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
index 7b73763..951f4b8 100644
--- a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
+++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
@@ -24,3 +24,10 @@ org.apache.tamaya.metamodel.internal.factories.SysPropertiesFactory
org.apache.tamaya.metamodel.internal.factories.URLPropertySourceFactory
org.apache.tamaya.metamodel.internal.factories.ResourcePropertySourceProviderFactory
+
+org.apache.tamaya.metamodel.ImmutableFilter$ImmutableFilterFactory
+org.apache.tamaya.metamodel.MapFilter$MapFilterFactory
+org.apache.tamaya.metamodel.HideFilter$HideFilterFactory
+org.apache.tamaya.metamodel.CachedFilter$CachedFilterFactory
+org.apache.tamaya.metamodel.MaskFilter$MaskFilterFactory
+org.apache.tamaya.metamodel.SecuredFilter$SecuredFilterFactory
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
----------------------------------------------------------------------
diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
index cd2af30..79b9249 100644
--- a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
+++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
@@ -20,7 +20,7 @@
org.apache.tamaya.metamodel.internal.PropertyFilterReader
org.apache.tamaya.metamodel.internal.PropertyConverterReader
org.apache.tamaya.metamodel.internal.PropertySourceReader
-org.apache.tamaya.metamodel.internal.ContextReader
+org.apache.tamaya.metamodel.internal.MetaContextReader
org.apache.tamaya.metamodel.internal.CombinationPolicyReader
org.apache.tamaya.metamodel.internal.PropertyFilterOrderingReader
org.apache.tamaya.metamodel.internal.PropertySourceOrderingReader
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/10d711e6/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
index 4462520..b461603 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
@@ -16,16 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.tamaya.metamodel.ext;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.metamodel.CachedFilter;
+import org.apache.tamaya.metamodel.MapFilter;
import org.apache.tamaya.metamodel.MetaConfiguration;
+import org.apache.tamaya.metamodel.MetaContext;
+import org.apache.tamaya.spi.PropertyConverter;
import org.junit.Test;
import java.net.URL;
+import java.util.List;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
@@ -50,6 +57,104 @@ public class IntegrationTest {
assertTrue(config.getContext().getPropertyFilters().isEmpty());
}
+ @Test
+ public void testMetaContextConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/context-test.xml"));
+ assertNotNull(config);
+ assertTrue(config.getProperties().isEmpty());
+ assertTrue(config.getContext().getPropertyConverters().isEmpty());
+ assertTrue(config.getContext().getPropertyFilters().isEmpty());
+ MetaContext ctx = MetaContext.getInstance();
+ assertFalse(ctx.getProperties().isEmpty());
+ assertEquals(ctx.getId(), ctx.getProperty("_id"));
+ assertEquals("NONE", ctx.getProperty("app"));
+ assertEquals("DEV", ctx.getProperty("stage"));
+ assertEquals(".", ctx.getProperty("configdir"));
+
+ }
+
+ @Test
+ public void testDefaultConvertersConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertyconverters-test.xml"));
+ assertNotNull(config);
+ assertTrue(config.getContext().getPropertySources().isEmpty());
+ assertTrue(config.getProperties().isEmpty());
+ assertFalse(config.getContext().getPropertyConverters().isEmpty());
+ assertTrue(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(config.getContext(),
+ ConfigurationProvider.getConfigurationContextBuilder()
+ .addDefaultPropertyConverters()
+ .build());
+
+ }
+
+ @Test
+ public void testDefaultPropertySourcesConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertysources-test.xml"));
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertFalse(config.getContext().getPropertySources().isEmpty());
+ assertTrue(config.getContext().getPropertyConverters().isEmpty());
+ assertTrue(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(config.getContext(),
+ ConfigurationProvider.getConfigurationContextBuilder()
+ .addDefaultPropertySources()
+ .build());
+
+ }
+
+ @Test
+ public void testDefaultPropertyFiltersConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertyfilters-test.xml"));
+ assertNotNull(config);
+ assertTrue(config.getProperties().isEmpty());
+ assertTrue(config.getContext().getPropertySources().isEmpty());
+ assertTrue(config.getContext().getPropertyConverters().isEmpty());
+ assertFalse(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(config.getContext(),
+ ConfigurationProvider.getConfigurationContextBuilder()
+ .addDefaultPropertyFilters()
+ .build());
+
+ }
+
+ @Test
+ public void testPropertyFiltersConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyfilters-test.xml"));
+ assertNotNull(config);
+ assertTrue(config.getProperties().isEmpty());
+ assertTrue(config.getContext().getPropertySources().isEmpty());
+ assertTrue(config.getContext().getPropertyConverters().isEmpty());
+ assertFalse(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(1, config.getContext().getPropertyFilters().size());
+ assertTrue(config.getContext().getPropertyFilters().get(0) instanceof CachedFilter);
+ }
+
+ @Test
+ public void testPropertyConvertersConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyconverters-test.xml"));
+ assertNotNull(config);
+ assertTrue(config.getProperties().isEmpty());
+ assertTrue(config.getContext().getPropertySources().isEmpty());
+ assertFalse(config.getContext().getPropertyConverters().isEmpty());
+ assertTrue(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(1, config.getContext().getPropertyConverters().size());
+ List<PropertyConverter<Object>> converters = config.getContext().getPropertyConverters(TypeLiteral.of(String.class));
+ assertTrue(converters.get(0).getClass().equals(MyConverter.class));
+ }
+
+ @Test
+ public void testPropertySourcesConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertysources-test.xml"));
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertFalse(config.getContext().getPropertySources().isEmpty());
+ assertTrue(config.getContext().getPropertyConverters().isEmpty());
+ assertTrue(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(2, config.getContext().getPropertySources().size());
+ assertTrue(config.getContext().getPropertySources().get(0) instanceof MyPropertySource);
+ }
+
private URL getConfig(String resource) {
return getClass().getClassLoader().getResource(resource);
}
[7/7] incubator-tamaya-sandbox git commit: TAMAYA-145: Added tests,
some bugfixes.
Posted by an...@apache.org.
TAMAYA-145: Added tests, some bugfixes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/d344e732
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/d344e732
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/d344e732
Branch: refs/heads/master
Commit: d344e7323db6ec97f3566fd7b893b47093dae771
Parents: bf8c110
Author: anatole <an...@apache.org>
Authored: Tue Apr 18 11:38:52 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Apr 18 11:38:52 2017 +0200
----------------------------------------------------------------------
.../apache/tamaya/metamodel/CachedFilter.java | 20 ++-
.../org/apache/tamaya/metamodel/HideFilter.java | 20 ++-
.../tamaya/metamodel/ImmutableFilter.java | 20 ++-
.../org/apache/tamaya/metamodel/MapFilter.java | 20 ++-
.../org/apache/tamaya/metamodel/MaskFilter.java | 20 ++-
.../apache/tamaya/metamodel/SecuredFilter.java | 20 ++-
.../internal/ComponentConfigurator.java | 160 ++++++++++++++++---
.../internal/PropertySourceReader.java | 1 +
.../internal/factories/CLIArgumentsFactory.java | 1 -
.../internal/resolver/JavaResolver.java | 30 +++-
.../tamaya/metamodel/ext/IntegrationTest.java | 60 +++++++
.../tamaya/metamodel/ext/MyConverter.java | 36 +++++
.../apache/tamaya/metamodel/ext/MyFilter.java | 37 +++++
.../tamaya/metamodel/ext/MyPropertySource.java | 37 +++++
.../factories/CLIArgumentsFactoryTest.java | 54 +++++++
.../factories/EnvPropertiesFactoryTest.java | 54 +++++++
.../FilePropertySourceFactoryTest.java | 63 ++++++++
.../ResourcePropertySourceFactoryTest.java | 63 ++++++++
...sourcePropertySourceProviderFactoryTest.java | 64 ++++++++
.../factories/SysPropertiesFactoryTest.java | 54 +++++++
.../factories/URLPropertySourceFactoryTest.java | 63 ++++++++
.../internal/resolver/JavaResolverTest.java | 71 ++++++++
.../resolver/PropertiesResolverTest.java | 52 ++++++
.../propertyconverter-config-test.xml | 32 ++++
.../propertyfilter-config-test.xml | 30 ++++
.../propertysource-config-test.xml | 31 ++++
server/src/main/resources/META-INF/web.xml | 0
27 files changed, 1068 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
index c07e11d..d2a343c 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
@@ -1,6 +1,22 @@
-package org.apache.tamaya.metamodel;/*
- * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+/*
+ * 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.metamodel;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.spi.FilterContext;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
index 2bd701c..6a1e116 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
@@ -1,6 +1,22 @@
-package org.apache.tamaya.metamodel;/*
- * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+/*
+ * 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.metamodel;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.spi.FilterContext;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
index 90c65f5..13f3d0c 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
@@ -1,6 +1,22 @@
-package org.apache.tamaya.metamodel;/*
- * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+/*
+ * 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.metamodel;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.spi.FilterContext;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
index ab521dd..b721780 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
@@ -1,6 +1,22 @@
-package org.apache.tamaya.metamodel;/*
- * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+/*
+ * 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.metamodel;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.spi.FilterContext;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
index d374dc4..a252f96 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
@@ -1,6 +1,22 @@
-package org.apache.tamaya.metamodel;/*
- * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+/*
+ * 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.metamodel;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.spi.FilterContext;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
index 5878106..57171c3 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
@@ -1,6 +1,22 @@
-package org.apache.tamaya.metamodel;/*
- * (C) Copyright 2015-2017 Trivadis AG. All rights reserved.
+/*
+ * 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.metamodel;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.metamodel.spi.ItemFactory;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
index 8832d98..6e7ea75 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
@@ -22,7 +22,9 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import java.lang.reflect.*;
import java.util.*;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -40,25 +42,7 @@ public final class ComponentConfigurator<T> {
* @param node the node containing any configuration child nodes, not null.
*/
public static void configure(Object instance, Node node) {
- NodeList entryNodes = node.getChildNodes();
- Map<String,String> params = new HashMap<>();
- for(int c=0;c<node.getAttributes().getLength();c++){
- Node attr = node.getAttributes().item(c);
- String key = attr.getNodeName();
- String value = attr.getNodeValue();
- params.put(key, value);
- }
- for(int c=0;c<entryNodes.getLength();c++) {
- Node filterNode = entryNodes.item(c);
- if(filterNode.getNodeType()!=Node.ELEMENT_NODE){
- continue;
- }
- if ("param".equals(filterNode.getNodeName())) {
- String key = filterNode.getAttributes().getNamedItem("name").getNodeValue();
- String value = filterNode.getTextContent();
- params.put(key, value);
- }
- }
+ Map<String,String> params = extractParameters(node);
configure(instance, params);
}
@@ -70,14 +54,140 @@ public final class ComponentConfigurator<T> {
public static void configure(Object instance, Map<String,String> params) {
LOG.finest("Configuring instance: " + instance + " with " + params);
for(Map.Entry<String,String> en:params.entrySet()){
- if(!params.isEmpty()){
- applyParam(instance, en.getKey(), en.getValue());
+ applyParam(instance, en.getKey(), en.getValue());
+ }
+ }
+
+ /**
+ * Apply parameters to instance using reflection ,only if found, as of now only
+ * String and basic lang types are supported.
+ * @param instance the instance to configure.
+ * @param key the parameter name, not null.
+ * @param value the value to be set, normally not null.
+ */
+ private static void applyParam(Object instance, String key, String value) {
+ // apply parameters to instance using reflection ,only if found.
+ Class type = instance.getClass();
+ try {
+ Method[] methods = type.getMethods();
+ String methodName = "set" + toUpperCase(key);
+ for(Method m:methods){
+ if(methodName.equals(m.getName()) && m.getParameterTypes().length==1) {
+ if (applyParam(instance, key, value, m)) {
+ return;
+ }
+ }
}
+ }catch(Exception e){
+ LOG.log(Level.FINE, "Reflection issue configuring instance: " + instance, e);
+ }
+ try{
+ Field field = type.getDeclaredField(key);
+ applyParam(instance, key, value, field);
+ }catch(Exception e){
+ LOG.log(Level.FINE, "Reflection issue configuring instance: " + instance, e);
}
}
- private static void applyParam(Object instance, String param, String value) {
- // TODO apply parameters to instance using reflection ,only if found.
+ private static String toUpperCase(String value) {
+ return value.substring(0,1).toUpperCase() + value.substring(1);
+ }
+
+ /**
+ * Apply parameters to instance using reflection ,only if found, as of now only
+ * String and basic lang types are supported.
+ * @param instance the instance to configure.
+ * @param key the parameter name, not null.
+ * @param value the value to be set, normally not null.
+ * @param setter the setter method, not null.
+ */
+ private static boolean applyParam(Object instance, String key, String value, Method setter) {
+ if(!Modifier.isPublic(setter.getModifiers())){
+ LOG.fine("Setting method as accessible: " + instance.getClass().getSimpleName() + '#' + setter.getName());
+ setter.setAccessible(true);
+ }
+ try {
+ Class<?> targetType = setter.getParameterTypes()[0];
+ setter.invoke(instance, convert(value, targetType));
+ return true;
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Could not apply parameter (SETTER) '" + key + "' to " + instance, e);
+ return false;
+ }
+ }
+
+ /**
+ * Apply parameters to instance using reflection ,only if found, as of now only
+ * String and basic lang types are supported.
+ * @param instance the instance to configure.
+ * @param key the parameter name, not null.
+ * @param value the value to be set, normally not null.
+ * @param field the field method, not null.
+ */
+ private static void applyParam(Object instance, String key, String value, Field field) {
+ if(Modifier.isFinal(field.getModifiers())){
+ LOG.finest("Ignoring final field: " + instance.getClass().getSimpleName() + '#' + field.getName());
+ return;
+ }
+ if(!Modifier.isPublic(field.getModifiers())){
+ LOG.finest("Setting field as accessible: " + instance.getClass().getSimpleName() + '#' + field.getName());
+ field.setAccessible(true);
+ }
+ try {
+ Class<?> targetType = field.getType();
+ field.set(instance, convert(value, targetType));
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Could not apply parameter (FIELD) '" + key + "' to " + instance, e);
+ }
+ }
+
+ private static Object convert(String value, Class<?> targetType) {
+ try {
+ switch (targetType.getSimpleName()) {
+ case "String":
+ case "Object":
+ return value;
+ case "boolean":
+ case "Boolean":
+ return Boolean.valueOf(value);
+ case "byte":
+ case "Byte":
+ return Byte.valueOf(value);
+ case "char":
+ case "Character":
+ if (value.isEmpty()) {
+ return null;
+ }
+ return Character.valueOf(value.charAt(0));
+ case "short":
+ case "Short":
+ return Short.valueOf(value);
+ case "int":
+ case "Integer":
+ return Integer.valueOf(value);
+ case "long":
+ case "Long":
+ return Long.valueOf(value);
+ case "float":
+ case "Float":
+ return Float.valueOf(value);
+ case "double":
+ case "Double":
+ case "Number":
+ return Float.valueOf(value);
+ default:
+ Constructor c = targetType.getConstructor(String.class);
+ if (!Modifier.isPublic(c.getModifiers())) {
+ LOG.fine("Setting constructor as accessible: " + targetType.getSimpleName() + "#<constructor>(String)");
+ c.setAccessible(true);
+ }
+ return c.newInstance(value);
+ }
+ }catch(Exception e){
+ LOG.log(Level.WARNING,
+ "Failed to convert value '"+value+"' to required target type: " + targetType.getName(), e);
+ return null;
+ }
}
public static Map<String, String> extractParameters(Node node) {
@@ -92,8 +202,8 @@ public final class ComponentConfigurator<T> {
NodeList entryNodes = node.getChildNodes();
for(int c=0;c<entryNodes.getLength();c++) {
Node filterNode = entryNodes.item(c);
- if ("param".equals(filterNode.getNodeName())) {
- String key = filterNode.getAttributes().getNamedItem("name").getNodeValue();
+ if(filterNode.getNodeType()==Node.ELEMENT_NODE) {
+ String key = filterNode.getNodeName();
String value = filterNode.getTextContent();
params.put(key, value);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
index a465146..0fdac29 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
@@ -80,6 +80,7 @@ public class PropertySourceReader implements MetaConfigurationReader{
ps = decoratePropertySource(ps, node, params);
LOG.finer("Adding configured property source: " + ps.getName());
contextBuilder.addPropertySources(ps);
+ continue;
}
}
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
index ae4bf24..c5af56c 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.tamaya.metamodel.internal.factories;
import org.apache.tamaya.metamodel.spi.ItemFactory;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java
index 6ad83e1..22d8618 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.metamodel.internal.resolver;
import org.apache.tamaya.metamodel.MetaContext;
import org.apache.tamaya.metamodel.spi.SimpleResolver;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Objects;
@@ -59,16 +60,31 @@ public final class JavaResolver implements SimpleResolver{
return null;
}
- private String evaluate(String className, String methodName) throws Exception{
+ private String evaluate(String className, String memberName) throws Exception{
Objects.requireNonNull(className);
- Objects.requireNonNull(methodName);
+ Objects.requireNonNull(memberName);
Class clazz = Class.forName(className);
- Method method = clazz.getMethod(methodName);
- if(Modifier.isStatic(method.getModifiers())){
- if(!method.isAccessible()){
- method.setAccessible(true);
+ try {
+ Method method = clazz.getDeclaredMethod(memberName);
+ if (Modifier.isStatic(method.getModifiers())) {
+ if (!method.isAccessible()) {
+ method.setAccessible(true);
+ }
+ return (String) method.invoke(null);
}
- return (String)method.invoke(null);
+ }catch(Exception e){
+ // ignore
+ }
+ try {
+ Field field = clazz.getDeclaredField(memberName);
+ if (Modifier.isStatic(field.getModifiers())) {
+ if (!field.isAccessible()) {
+ field.setAccessible(true);
+ }
+ return (String) field.get(null);
+ }
+ }catch(Exception e){
+ // ignore
}
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
index b461603..fe46d81 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
@@ -26,6 +26,8 @@ import org.apache.tamaya.metamodel.MapFilter;
import org.apache.tamaya.metamodel.MetaConfiguration;
import org.apache.tamaya.metamodel.MetaContext;
import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
import java.net.URL;
@@ -155,6 +157,64 @@ public class IntegrationTest {
assertTrue(config.getContext().getPropertySources().get(0) instanceof MyPropertySource);
}
+ @Test
+ public void testPropertyFilterConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyfilter-config-test.xml"));
+ assertNotNull(config);
+ assertTrue(config.getProperties().isEmpty());
+ assertTrue(config.getContext().getPropertySources().isEmpty());
+ assertTrue(config.getContext().getPropertyConverters().isEmpty());
+ assertFalse(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(1, config.getContext().getPropertyFilters().size());
+ PropertyFilter filter = config.getContext().getPropertyFilters().get(0);
+ assertNotNull(filter);
+ assertTrue(filter instanceof MyFilter);
+ MyFilter myFilter = (MyFilter)filter;
+ assertEquals("my-filter-name", myFilter.getName());
+ assertEquals("attrValue1", myFilter.getAttrValue());
+ assertEquals("elemValue1", myFilter.getElemValue());
+ assertEquals("overrideValue2", myFilter.getOverrideValue());
+ }
+
+ @Test
+ public void testPropertySourceConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertysource-config-test.xml"));
+ assertNotNull(config);
+ assertTrue(config.getProperties().isEmpty());
+ assertFalse(config.getContext().getPropertySources().isEmpty());
+ assertTrue(config.getContext().getPropertyConverters().isEmpty());
+ assertTrue(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(1, config.getContext().getPropertySources().size());
+ PropertySource ps = config.getContext().getPropertySources().get(0);
+ assertNotNull(ps);
+ assertTrue(ps instanceof MyPropertySource);
+ MyPropertySource mySource = (MyPropertySource)ps;
+ assertEquals("my-source-name", mySource.getName2());
+ assertEquals("attrValue1", mySource.getAttrValue());
+ assertEquals("elemValue1", mySource.getElemValue());
+ assertEquals("overrideValue2", mySource.getOverrideValue());
+ }
+
+ @Test
+ public void testPropertyConverterConfig(){
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyconverter-config-test.xml"));
+ assertNotNull(config);
+ assertTrue(config.getProperties().isEmpty());
+ assertTrue(config.getContext().getPropertySources().isEmpty());
+ assertFalse(config.getContext().getPropertyConverters().isEmpty());
+ assertTrue(config.getContext().getPropertyFilters().isEmpty());
+ assertEquals(1, config.getContext().getPropertyConverters().size());
+ PropertyConverter converter = config.getContext().getPropertyConverters().values().iterator()
+ .next().get(0);
+ assertNotNull(converter);
+ assertTrue(converter instanceof MyConverter);
+ MyConverter myConverter = (MyConverter)converter;
+ assertEquals("my-converter-name", myConverter.getName());
+ assertEquals("attrValue1", myConverter.getAttrValue());
+ assertEquals("elemValue1", myConverter.getElemValue());
+ assertEquals("overrideValue2", myConverter.getOverrideValue());
+ }
+
private URL getConfig(String resource) {
return getClass().getClassLoader().getResource(resource);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java
index e9ca5a5..22f642c 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java
@@ -26,8 +26,44 @@ import org.apache.tamaya.spi.PropertyConverter;
*/
public class MyConverter implements PropertyConverter<String> {
+ private String name;
+ private String attrValue;
+ private String elemValue;
+ private String overrideValue;
+
@Override
public String convert(String value, ConversionContext context) {
return value;
}
+
+ public String getAttrValue() {
+ return attrValue;
+ }
+
+ public MyConverter setAttrValue(String attrValue) {
+ this.attrValue = attrValue;
+ return this;
+ }
+
+ public String getElemValue() {
+ return elemValue;
+ }
+
+ public MyConverter setElemValue(String elemValue) {
+ this.elemValue = elemValue;
+ return this;
+ }
+
+ public String getOverrideValue() {
+ return overrideValue;
+ }
+
+ public MyConverter setOverrideValue(String overrideValue) {
+ this.overrideValue = overrideValue;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java
index e819e2f..e6ab7e6 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java
@@ -26,8 +26,45 @@ import org.apache.tamaya.spi.PropertyValue;
* Created by atsticks on 17.04.17.
*/
public class MyFilter implements PropertyFilter{
+
+ private String name;
+ private String attrValue;
+ private String elemValue;
+ private String overrideValue;
+
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
return value;
}
+
+ public String getAttrValue() {
+ return attrValue;
+ }
+
+ public MyFilter setAttrValue(String attrValue) {
+ this.attrValue = attrValue;
+ return this;
+ }
+
+ public String getElemValue() {
+ return elemValue;
+ }
+
+ public MyFilter setElemValue(String elemValue) {
+ this.elemValue = elemValue;
+ return this;
+ }
+
+ public String getOverrideValue() {
+ return overrideValue;
+ }
+
+ public MyFilter setOverrideValue(String overrideValue) {
+ this.overrideValue = overrideValue;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java
index cdb4ae8..55455f9 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java
@@ -28,8 +28,45 @@ import java.util.Map;
* Created by atsticks on 17.04.17.
*/
public class MyPropertySource extends org.apache.tamaya.spisupport.BasePropertySource{
+
+ private String name2;
+ private String attrValue;
+ private String elemValue;
+ private String overrideValue;
+
@Override
public Map<String, PropertyValue> getProperties() {
return Collections.emptyMap();
}
+
+ public String getAttrValue() {
+ return attrValue;
+ }
+
+ public MyPropertySource setAttrValue(String attrValue) {
+ this.attrValue = attrValue;
+ return this;
+ }
+
+ public String getElemValue() {
+ return elemValue;
+ }
+
+ public MyPropertySource setElemValue(String elemValue) {
+ this.elemValue = elemValue;
+ return this;
+ }
+
+ public String getOverrideValue() {
+ return overrideValue;
+ }
+
+ public MyPropertySource setOverrideValue(String overrideValue) {
+ this.overrideValue = overrideValue;
+ return this;
+ }
+
+ public String getName2() {
+ return name2;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java
new file mode 100644
index 0000000..bf78f0e
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.metamodel.internal.factories;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.CLIPropertySource;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class CLIArgumentsFactoryTest {
+
+ private static CLIArgumentsFactory f = new CLIArgumentsFactory();
+
+ @Test
+ public void getName() throws Exception {
+ assertEquals("CLI", f.getName());
+ }
+
+ @Test
+ public void create() throws Exception {
+ PropertySource ps = f.create(Collections.EMPTY_MAP);
+ assertNotNull(ps);
+ assertTrue(ps instanceof CLIPropertySource);
+ }
+
+ @Test
+ public void getType() throws Exception {
+ assertEquals(PropertySource.class, f.getType());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactoryTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactoryTest.java
new file mode 100644
index 0000000..bfbcf82
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactoryTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.metamodel.internal.factories;
+
+import org.apache.tamaya.spisupport.EnvironmentPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class EnvPropertiesFactoryTest {
+
+ private static EnvPropertiesFactory f = new EnvPropertiesFactory();
+
+ @Test
+ public void getName() throws Exception {
+ assertEquals("env-properties", f.getName());
+ }
+
+ @Test
+ public void create() throws Exception {
+ PropertySource ps = f.create(Collections.EMPTY_MAP);
+ assertNotNull(ps);
+ assertTrue(ps instanceof EnvironmentPropertySource);
+ }
+
+ @Test
+ public void getType() throws Exception {
+ assertEquals(PropertySource.class, f.getType());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactoryTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactoryTest.java
new file mode 100644
index 0000000..d91d279
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactoryTest.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.metamodel.internal.factories;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class FilePropertySourceFactoryTest {
+
+ private static FilePropertySourceFactory f = new FilePropertySourceFactory();
+
+ @Test
+ public void getName() throws Exception {
+ assertEquals("file", f.getName());
+ }
+
+ @Test
+ public void create() throws Exception {
+ Map<String,String> params = new HashMap<>();
+ params.put("location", "src/test/resources/GLOBAL.properties");
+ PropertySource ps = f.create(params);
+ assertNotNull(ps);
+ }
+
+ @Test
+ public void create_Error() throws Exception {
+ Map<String,String> params = new HashMap<>();
+ PropertySource ps = f.create(Collections.<String, String>emptyMap());
+ assertNull("Should throw error for missing location.", ps);
+ }
+
+ @Test
+ public void getType() throws Exception {
+ assertEquals(PropertySource.class, f.getType());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactoryTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactoryTest.java
new file mode 100644
index 0000000..bd6ee93
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactoryTest.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.metamodel.internal.factories;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class ResourcePropertySourceFactoryTest {
+
+ private static ResourcePropertySourceFactory f = new ResourcePropertySourceFactory();
+
+ @Test
+ public void getName() throws Exception {
+ assertEquals("resource", f.getName());
+ }
+
+ @Test
+ public void create() throws Exception {
+ Map<String,String> params = new HashMap<>();
+ params.put("location", "GLOBAL.properties");
+ PropertySource ps = f.create(params);
+ assertNotNull(ps);
+ }
+
+ @Test
+ public void create_Error() throws Exception {
+ Map<String,String> params = new HashMap<>();
+ PropertySource ps = f.create(Collections.<String, String>emptyMap());
+ assertNull("Should return null for missing location.", ps);
+ }
+
+ @Test
+ public void getType() throws Exception {
+ assertEquals(PropertySource.class, f.getType());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactoryTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactoryTest.java
new file mode 100644
index 0000000..edc0d95
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactoryTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.metamodel.internal.factories;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class ResourcePropertySourceProviderFactoryTest {
+
+ private static ResourcePropertySourceProviderFactory f = new ResourcePropertySourceProviderFactory();
+
+ @Test
+ public void getName() throws Exception {
+ assertEquals("resources", f.getName());
+ }
+
+ @Test
+ public void create() throws Exception {
+ Map<String,String> params = new HashMap<>();
+ params.put("location", "GLOBAL.properties");
+ PropertySourceProvider prov = f.create(params);
+ assertNotNull(prov);
+ }
+
+ @Test
+ public void create_Error() throws Exception {
+ Map<String,String> params = new HashMap<>();
+ PropertySourceProvider prov = f.create(Collections.<String, String>emptyMap());
+ assertNull("Should return null for missing location.", prov);
+ }
+
+ @Test
+ public void getType() throws Exception {
+ assertEquals(PropertySourceProvider.class, f.getType());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactoryTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactoryTest.java
new file mode 100644
index 0000000..3fa1d22
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactoryTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.metamodel.internal.factories;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.SystemPropertySource;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class SysPropertiesFactoryTest {
+
+ private static SysPropertiesFactory f = new SysPropertiesFactory();
+
+ @Test
+ public void getName() throws Exception {
+ assertEquals("sys-properties", f.getName());
+ }
+
+ @Test
+ public void create() throws Exception {
+ PropertySource ps = f.create(Collections.EMPTY_MAP);
+ assertNotNull(ps);
+ assertTrue(ps instanceof SystemPropertySource);
+ }
+
+ @Test
+ public void getType() throws Exception {
+ assertEquals(PropertySource.class, f.getType());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactoryTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactoryTest.java
new file mode 100644
index 0000000..f316417
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactoryTest.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.metamodel.internal.factories;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class URLPropertySourceFactoryTest {
+
+ private static URLPropertySourceFactory f = new URLPropertySourceFactory();
+
+ @Test
+ public void getName() throws Exception {
+ assertEquals("url", f.getName());
+ }
+
+ @Test
+ public void create() throws Exception {
+ Map<String,String> params = new HashMap<>();
+ params.put("location", "http://apache.org");
+ PropertySource ps = f.create(params);
+ assertNotNull(ps);
+ }
+
+ @Test
+ public void create_Error() throws Exception {
+ Map<String,String> params = new HashMap<>();
+ PropertySource ps = f.create(Collections.<String, String>emptyMap());
+ assertNull("Should return null for missing location.", ps);
+ }
+
+ @Test
+ public void getType() throws Exception {
+ assertEquals(PropertySource.class, f.getType());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java
new file mode 100644
index 0000000..55ca290
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.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.metamodel.internal.resolver;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class JavaResolverTest {
+
+ private static final String TEST = "ResTest";
+ private JavaResolver r = new JavaResolver();
+
+ @Test
+ public void getResolverId() throws Exception {
+ assertEquals(r.getResolverId(), "java");
+ }
+
+ @Test
+ public void evaluate() throws Exception {
+ assertEquals(TEST, r.evaluate("org.apache.tamaya.metamodel.internal.resolver.JavaResolverTest#TEST"));
+ assertEquals(TEST, r.evaluate("org.apache.tamaya.metamodel.internal.resolver.JavaResolverTest#getTest4"));
+ assertEquals(TEST, r.evaluate("org.apache.tamaya.metamodel.internal.resolver.JavaResolverTest#getTest6"));
+ assertEquals(TEST, r.evaluate("org.apache.tamaya.metamodel.internal.resolver.JavaResolverTest#getTest7"));
+ }
+
+ private String getTest5(){
+ return TEST;
+ }
+
+ String getTest2(){
+ return TEST;
+ }
+
+ public String getTest3(){
+ return TEST;
+ }
+
+ static String getTest4(){
+ return TEST;
+ }
+
+ private static String getTest6(){
+ return TEST;
+ }
+
+ public static String getTest7(){
+ return TEST;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolverTest.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolverTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolverTest.java
new file mode 100644
index 0000000..988c224
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolverTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.metamodel.internal.resolver;
+
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Created by atsticks on 18.04.17.
+ */
+public class PropertiesResolverTest {
+
+ private PropertiesResolver r = new PropertiesResolver();
+
+ @Test
+ public void getResolverId() throws Exception {
+ assertEquals(r.getResolverId(), "properties");
+ }
+
+ @Test
+ public void evaluate() throws Exception {
+ for(Map.Entry<String,String> en: System.getenv().entrySet()){
+ assertEquals(en.getValue(), r.evaluate("env:"+en.getKey()));
+ }
+ assertEquals("foo", r.evaluate("env:fsdifoisfo?default=foo"));
+ for(Map.Entry en: System.getProperties().entrySet()){
+ assertEquals(en.getValue(), r.evaluate("system:"+en.getKey()));
+ }
+ assertEquals("foo", r.evaluate("system:fsdifoisfo?default=foo"));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml
new file mode 100644
index 0000000..485ac8b
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml
@@ -0,0 +1,32 @@
+<!--
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy 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.
+// -->
+<configuration>
+
+ <property-converters>
+ <org.apache.tamaya.metamodel.ext.MyConverter targetType="java.lang.String"
+ attrValue="attrValue1"
+ overrideValue="overrideValue1">
+ <name>my-converter-name</name>
+ <elemValue>elemValue1</elemValue>
+ <overrideValue>overrideValue2</overrideValue>
+ </org.apache.tamaya.metamodel.ext.MyConverter>
+ </property-converters>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml
new file mode 100644
index 0000000..71c1b3a
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml
@@ -0,0 +1,30 @@
+<!--
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy 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.
+// -->
+<configuration>
+
+ <property-filters>
+ <org.apache.tamaya.metamodel.ext.MyFilter attrValue="attrValue1" overrideValue="overrideValue1">
+ <name>my-filter-name</name>
+ <elemValue>elemValue1</elemValue>
+ <overrideValue>overrideValue2</overrideValue>
+ </org.apache.tamaya.metamodel.ext.MyFilter>
+ </property-filters>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml
new file mode 100644
index 0000000..28710d4
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml
@@ -0,0 +1,31 @@
+<!--
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy 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.
+// -->
+<configuration>
+
+ <property-sources>
+ <org.apache.tamaya.metamodel.ext.MyPropertySource
+ attrValue="attrValue1" overrideValue="overrideValue1">
+ <name2>my-source-name</name2>
+ <elemValue>elemValue1</elemValue>
+ <overrideValue>overrideValue2</overrideValue>
+ </org.apache.tamaya.metamodel.ext.MyPropertySource>
+ </property-sources>
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/server/src/main/resources/META-INF/web.xml
----------------------------------------------------------------------
diff --git a/server/src/main/resources/META-INF/web.xml b/server/src/main/resources/META-INF/web.xml
new file mode 100644
index 0000000..e69de29
[6/7] incubator-tamaya-sandbox git commit: Enabled more fine grained
reusage of toString fields.
Posted by an...@apache.org.
Enabled more fine grained reusage of toString fields.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/bf8c110e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/bf8c110e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/bf8c110e
Branch: refs/heads/master
Commit: bf8c110e583f8487a88f9e4889c46305b4655453
Parents: 10d711e
Author: anatole <an...@apache.org>
Authored: Tue Apr 18 11:38:13 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Apr 18 11:38:13 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/consul/ConsulPropertySource.java | 8 ++++++++
.../main/java/org/apache/tamaya/etcd/EtcdPropertySource.java | 7 +++++++
.../org/apache/tamaya/hazelcast/HazelcastPropertySource.java | 7 +++----
3 files changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/bf8c110e/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
----------------------------------------------------------------------
diff --git a/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java b/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
index 026a926..c99eca4 100644
--- a/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
+++ b/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
@@ -237,4 +237,12 @@ implements MutablePropertySource{
}
return consulBackends;
}
+
+ @Override
+ protected String toStringValues() {
+ return super.toStringValues() +
+ " prefix=" + prefix + '\n' +
+ " backends=" + this.consulBackends + '\n';
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/bf8c110e/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
----------------------------------------------------------------------
diff --git a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
index e6175b7..9e55643 100644
--- a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
+++ b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
@@ -271,4 +271,11 @@ public class EtcdPropertySource extends BasePropertySource
}
return etcdBackends;
}
+
+ @Override
+ protected String toStringValues() {
+ return super.toStringValues() +
+ " prefix=" + prefix + '\n' +
+ " backends=" + this.etcdBackends + '\n';
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/bf8c110e/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java
----------------------------------------------------------------------
diff --git a/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java b/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java
index f883cc5..566e70b 100644
--- a/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java
+++ b/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java
@@ -227,13 +227,12 @@ implements MutablePropertySource{
}
@Override
- public String toString() {
- return "HazelcastPropertySource{" +
+ protected String toStringValues() {
+ return super.toStringValues() +
"\n hazelcastInstance=" + hazelcastInstance +
"\n name='" + getName() + '\'' +
"\n mapReference='" + mapReference + '\'' +
- "\n readOnly=" + readOnly +
- "\n}";
+ "\n readOnly=" + readOnly + '\'';
}
}
[3/7] incubator-tamaya-sandbox git commit: Preparing Java 8.
Posted by an...@apache.org.
Preparing Java 8.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/098c75f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/098c75f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/098c75f6
Branch: refs/heads/master
Commit: 098c75f66e75b5679c2e2bc59aa75aaa10b4e11d
Parents: 46e3ed0
Author: anatole <an...@apache.org>
Authored: Sat Apr 15 22:13:28 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Sat Apr 15 22:13:28 2017 +0200
----------------------------------------------------------------------
pom.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/098c75f6/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 836b89a..a788354 100644
--- a/pom.xml
+++ b/pom.xml
@@ -754,8 +754,9 @@ under the License.
<module>osgi</module>
<module>management</module>
<module>metamodel</module>
+ <!-- Requires JAVA 8: <module>microprofile</module>-->
<module>uom</module>
- <!--<module>vertx</module>-->
+ <!-- Requires JAVA 8: <module>vertx</module>-->
</modules>
<profiles>
[2/7] incubator-tamaya-sandbox git commit: TAMAYA-218: Renamed some
methods.
Posted by an...@apache.org.
TAMAYA-218: Renamed some methods.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/46e3ed0c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/46e3ed0c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/46e3ed0c
Branch: refs/heads/master
Commit: 46e3ed0caccc8cafd466740d1a1c7b0ebd3c71f0
Parents: fd26d6c
Author: anatole <an...@apache.org>
Authored: Sat Apr 15 22:12:09 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Sat Apr 15 22:12:09 2017 +0200
----------------------------------------------------------------------
.../apache/tamaya/usagetracker/ConfigUsage.java | 31 +++++----
.../apache/tamaya/usagetracker/UsageStat.java | 72 ++++++++++----------
.../internal/DefaultConfigUsage.java | 42 ++++++------
.../internal/UsageTrackerFilter.java | 4 +-
.../tamaya/usagetracker/spi/ConfigUsageSpi.java | 18 ++---
.../tamaya/model/ConfigUsageStatsTest.java | 10 +--
6 files changed, 90 insertions(+), 87 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/46e3ed0c/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java
----------------------------------------------------------------------
diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java
index 963dcb0..5cae8d2 100644
--- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java
+++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java
@@ -33,6 +33,7 @@ public final class ConfigUsage {
/** The logger used. */
private static final Logger LOG = Logger.getLogger(ConfigUsage.class.getName());
+
private static final String NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE = "No UsageTrackerSpi component available.";
/** The loaded usage tracking SPI. */
@@ -55,7 +56,7 @@ public final class ConfigUsage {
* Returns a set of package names that are to be ignored when collecting usage data.
* @return the ignored package names, not null.
*/
- public static Set<String> getIgnoredUsagePackages(){
+ public static Set<String> getIgnoredPackages(){
return spi().getIgnoredPackages();
}
@@ -63,8 +64,8 @@ public final class ConfigUsage {
* Adds the given packageNames to the list of packages to be ignored when collecting usage data.
* @param packageName the package names to be added, not null.
*/
- public static void addIgnoredUsagePackages(String... packageName){
- spi().addIgnoredUsagePackages(packageName);
+ public static void addIgnoredPackages(String... packageName){
+ spi().addIgnoredPackages(packageName);
}
/**
@@ -81,23 +82,23 @@ public final class ConfigUsage {
* @param key the fully qualified configuration key, not null.
* @return the stats collected, or null.
*/
- public static UsageStat getUsage(String key){
- return spi().getUsage(key);
+ public static UsageStat getSinglePropertyStats(String key){
+ return spi().getSinglePropertyStats(key);
}
/**
* Get the recorded usage references of configuration.
* @return the recorded usge references, never null.
*/
- public static Collection<UsageStat> getUsages() {
- return spi().getUsages();
+ public static Collection<UsageStat> getUsageStats() {
+ return spi().getUsageStats();
}
/**
* Clears all collected usage statistics.
*/
- public static void clearUsageStats() {
- spi().clearUsageStats();
+ public static void clearStats() {
+ spi().clearStats();
}
/**
@@ -105,24 +106,24 @@ public final class ConfigUsage {
* If usage stats collection is not activated (default), this method returns null.
* @return the stats collected, or null.
*/
- public static UsageStat getUsageAllProperties(){
- return spi().getUsageAllProperties();
+ public static UsageStat getAllPropertiesStats(){
+ return spi().getAllPropertiesStats();
}
/**
* Allows to check if usage tracking is enabled (should be disbled by default).
* @return true, if usage tracking is enabled.
*/
- public static boolean isUsageTrackingEnabled(){
- return spi().isUsageTrackingEnabled();
+ public static boolean isTrackingEnabled(){
+ return spi().isTrackingEnabled();
}
/**
* Access the usage statistics for the recorded uses of configuration.
* @return usage info or default message.
*/
- public static String getUsageInfo(){
- return spi().getUsageInfo();
+ public static String getInfo(){
+ return spi().getInfo();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/46e3ed0c/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java
----------------------------------------------------------------------
diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java
index d04f787..8cd0236 100644
--- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java
+++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java
@@ -36,24 +36,24 @@ import java.util.logging.Logger;
* Metrics container containing access statistics for a given configuration key.
*/
public final class UsageStat {
- private static final Logger LOG = Logger.getLogger(UsageStat.class.getName());
+
private static final String[] EMPTY_TRACE = new String[0];
/**
- * the config section.
+ * the config entry's key.
*/
private final String key;
/**
- * Maps with usage references, key is the fully qualified package name.
+ * Maps with access references, key is the fully qualified package name.
*/
- private final Map<String,AccessDetail> accessDetails = new ConcurrentHashMap<>();
+ private final Map<String,AccessStats> accessDetails = new ConcurrentHashMap<>();
/**
* The maximal length of the stacktrace stored.
*/
private static int maxTrace = 10;
/**
- * Creates a usage metric container for a given key.
+ * Creates a usage statistics container for a given key.
* @param key the parameter (fully qualified).
*/
public UsageStat(String key) {
@@ -64,7 +64,7 @@ public final class UsageStat {
* Get the maximal length of the stack traces recorded, default is 10.
* @return the maximal length of the stack traces recorded
*/
- public static int getMaxTraceLength(){
+ public static int getMaxTrace(){
return UsageStat.maxTrace;
}
@@ -73,12 +73,12 @@ public final class UsageStat {
* usage. Setting it to a negative value, disabled stacktrace logging.
* @param maxTrace the maximal recorded stack length.
*/
- public static void setMaxTraceLength(int maxTrace){
+ public static void setMaxTrace(int maxTrace){
UsageStat.maxTrace =maxTrace;
}
/**
- * Get the configModel section.
+ * Get the target key of this instance.
*
* @return the section, never null.
*/
@@ -94,42 +94,42 @@ public final class UsageStat {
}
/**
- * Get the detail message.
+ * Get the detail number of access points recorded.
*
- * @return the detail message, or null.
+ * @return the detail numer of access points, or null.
*/
public int getReferenceCount() {
return accessDetails.size();
}
/**
- * Get the detail message.
+ * Get the overall number of accesses, hereby summing up the access details tracked.
*
- * @return the detail message, or null.
+ * @return the overall number of accesses.
*/
public int getUsageCount() {
int count = 0;
- for(AccessDetail ref: accessDetails.values()){
+ for(AccessStats ref: accessDetails.values()){
count += ref.getAccessCount();
}
return count;
}
/**
- * Access a usage reference for a given class.
- * @param type class to get usage references for, not null.
+ * Access access details for a given class.
+ * @param type class to get usage access stats for, not null.
* @return the usage ref, if present, or null.
*/
- public Collection<AccessDetail> getAccessDetails(Class type){
+ public Collection<AccessStats> getAccessDetails(Class type){
return getAccessDetails(type.getName() +"\\..*");
}
/**
- * Access a usage reference for a given package.
- * @param pack package to get usage references for, not null.
+ * Access access details for a given package.
+ * @param pack package to get usage access stats for, not null.
* @return the usage ref, if present, or null.
*/
- public Collection<AccessDetail> getAccessDetails(Package pack){
+ public Collection<AccessStats> getAccessDetails(Package pack){
return getAccessDetails(pack.getName() +"\\..*");
}
@@ -138,11 +138,11 @@ public final class UsageStat {
* matched with the tracked reference identifier, which has the form
* {@code f.q.n.ClassName#methodName(line: 123)}.
* @param lookupExpression the target lookup expression, not null.
- * @return the matching references, not null.
+ * @return the matching access statistics, not null.
*/
- public Collection<AccessDetail> getAccessDetails(String lookupExpression){
- List<AccessDetail> result = new ArrayList<>();
- for(AccessDetail ref:this.accessDetails.values()){
+ public Collection<AccessStats> getAccessDetails(String lookupExpression){
+ List<AccessStats> result = new ArrayList<>();
+ for(AccessStats ref:this.accessDetails.values()){
if(ref.getAccessPoint().matches(lookupExpression)){
result.add(ref);
}
@@ -152,14 +152,16 @@ public final class UsageStat {
@Override
public String toString() {
- return "Usage Count: " + key + " -> " + getUsageCount() + '\n';
+ return "Usage Stats{\n key=" + key + '\n'+
+ " usageCount " + getUsageCount() + '\n' +
+ "}";
}
/**
* Get the access details (stacktrace etc) for this reference.
* @return return the access details, not null.
*/
- public Collection<AccessDetail> getAccessDetails(){
+ public Collection<AccessStats> getAccessDetails(){
return Collections.unmodifiableCollection(accessDetails.values());
}
@@ -186,7 +188,7 @@ public final class UsageStat {
List<String> trace = new ArrayList<>();
stack:
for (StackTraceElement ste : e.getStackTrace()) {
- for (String ignored : ConfigUsage.getIgnoredUsagePackages()) {
+ for (String ignored : ConfigUsage.getIgnoredPackages()) {
if (ste.getClassName().startsWith(ignored)) {
continue stack;
}
@@ -204,19 +206,19 @@ public final class UsageStat {
// all ignored, take first one, with different package
accessPoint = "<unknown/filtered/internal>";
}
- AccessDetail details = getAccessDetails(accessPoint, trace.toArray(new String[trace.size()]));
+ AccessStats details = getAccessDetails(accessPoint, trace.toArray(new String[trace.size()]));
details.trackAccess(value);
}else{
accessPoint = "<disabled>";
- AccessDetail details = getAccessDetails(accessPoint, EMPTY_TRACE);
+ AccessStats details = getAccessDetails(accessPoint, EMPTY_TRACE);
details.trackAccess(value);
}
}
- private AccessDetail getAccessDetails(String accessPoint, String[] trace) {
- AccessDetail details = accessDetails.get(accessPoint);
+ private AccessStats getAccessDetails(String accessPoint, String[] trace) {
+ AccessStats details = accessDetails.get(accessPoint);
if(details==null){
- details = new AccessDetail(key, accessPoint, trace);
+ details = new AccessStats(key, accessPoint, trace);
accessDetails.put(accessPoint, details);
}
return details;
@@ -225,7 +227,7 @@ public final class UsageStat {
/**
* Class modelling the access details tracked per detailed item, e.g. per class in the owning package.
*/
- public static final class AccessDetail {
+ public static final class AccessStats {
private String key;
private AtomicLong accessCount = new AtomicLong();
private long lastAccessTS;
@@ -234,7 +236,7 @@ public final class UsageStat {
private String accessPoint;
private Map<Long, PropertyValue> trackedValues;
- public AccessDetail(String key, String accessPoint, String[] stackTrace){
+ public AccessStats(String key, String accessPoint, String[] stackTrace){
this.key = Objects.requireNonNull(key);
this.accessPoint = Objects.requireNonNull(accessPoint);
this.stackTrace = stackTrace.clone();
@@ -299,14 +301,14 @@ public final class UsageStat {
@Override
public String toString() {
- return "AccessDetails{" +
+ return "AccessStats{" +
"key=" + key +
", accessCount=" + accessCount +
", lastAccessTS=" + lastAccessTS +
", firstAccessTS=" + firstAccessTS +
- ", stackTrace=" + Arrays.toString(stackTrace) +
", accessPoint='" + accessPoint + '\'' +
", trackedValues=" + trackedValues +
+ ", stackTrace=" + Arrays.toString(stackTrace) +
'}';
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/46e3ed0c/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java
----------------------------------------------------------------------
diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java
index dc6f8ed..34e1fa4 100644
--- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java
+++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java
@@ -35,13 +35,13 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Created by atsticks on 29.04.16.
+ * Default implementation of the module's SPI.
*/
public class DefaultConfigUsage implements ConfigUsageSpi {
private Set<String> ignoredPackages = new HashSet<>();
- private Map<String, UsageStat> usages = new ConcurrentHashMap<>();
+ private Map<String, UsageStat> stats = new ConcurrentHashMap<>();
/** By default usage tracking is not enabled. */
private boolean usageTrackingEnabled = initEnabled();
@@ -78,7 +78,7 @@ public class DefaultConfigUsage implements ConfigUsageSpi {
}
@Override
- public boolean isUsageTrackingEnabled(){
+ public boolean isTrackingEnabled(){
return usageTrackingEnabled;
}
@@ -88,18 +88,18 @@ public class DefaultConfigUsage implements ConfigUsageSpi {
}
@Override
- public void addIgnoredUsagePackages(String... packageName) {
+ public void addIgnoredPackages(String... packageName) {
}
@Override
- public UsageStat getUsage(String key) {
- return this.usages.get(key);
+ public UsageStat getSinglePropertyStats(String key) {
+ return this.stats.get(key);
}
@Override
- public UsageStat getUsageAllProperties() {
- return this.usages.get("<<all>>");
+ public UsageStat getAllPropertiesStats() {
+ return this.stats.get("<<all>>");
}
/**
@@ -107,25 +107,25 @@ public class DefaultConfigUsage implements ConfigUsageSpi {
* @return the recorded usge references, never null.
*/
@Override
- public Collection<UsageStat> getUsages() {
- return usages.values();
+ public Collection<UsageStat> getUsageStats() {
+ return stats.values();
}
@Override
- public void trackAllPropertiesAccess(ConfigurationContext context){
- trackSingleKeyAccess(PropertyValue.of("<<all>>","<not stored>","-"), context);
+ public void recordAllPropertiesAccess(ConfigurationContext context){
+ recordSingleKeyAccess(PropertyValue.of("<<all>>","<not stored>","-"), context);
}
@Override
- public void trackSingleKeyAccess(PropertyValue value, ConfigurationContext context){
+ public void recordSingleKeyAccess(PropertyValue value, ConfigurationContext context){
// Ignore meta-entries
- if(!isUsageTrackingEnabled()){
+ if(!isTrackingEnabled()){
return;
}
- UsageStat usage = this.usages.get(value.getKey());
+ UsageStat usage = this.stats.get(value.getKey());
if(usage==null){
usage = new UsageStat(value.getKey());
- this.usages.put(value.getKey(), usage);
+ this.stats.put(value.getKey(), usage);
}
usage.trackUsage(value);
}
@@ -135,12 +135,12 @@ public class DefaultConfigUsage implements ConfigUsageSpi {
* Access the usage statistics for the recorded uses of configuration.
*/
@Override
- public String getUsageInfo(){
+ public String getInfo(){
StringBuilder b = new StringBuilder();
b.append("Apache Tamaya Configuration Usage Metrics\n");
b.append("=========================================\n");
b.append("DATE: ").append(new Date()).append("\n\n");
- List<UsageStat> usages = new ArrayList<>(getUsages());
+ List<UsageStat> usages = new ArrayList<>(getUsageStats());
Collections.sort(usages, new Comparator<UsageStat>() {
@Override
public int compare(UsageStat k1, UsageStat k2) {
@@ -152,7 +152,7 @@ public class DefaultConfigUsage implements ConfigUsageSpi {
b.append(usageCount);
b.append(" ".substring(0, 7-usageCount.length()));
b.append(usage.getKey()).append(":\n");
- for(UsageStat.AccessDetail details: usage.getAccessDetails()) {
+ for(UsageStat.AccessStats details: usage.getAccessDetails()) {
String accessCount = String.valueOf(details.getAccessCount());
b.append(" - ").append(accessCount);
b.append(" ".substring(0, 6-usageCount.length()));
@@ -171,8 +171,8 @@ public class DefaultConfigUsage implements ConfigUsageSpi {
}
@Override
- public void clearUsageStats() {
- this.usages.clear();
+ public void clearStats() {
+ this.stats.clear();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/46e3ed0c/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java
----------------------------------------------------------------------
diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java
index 9859ff2..c9839ac 100644
--- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java
+++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java
@@ -38,9 +38,9 @@ public class UsageTrackerFilter implements PropertyFilter{
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
ConfigUsageSpi tracker = ServiceContextManager.getServiceContext().getService(ConfigUsageSpi.class);
if (context.isSinglePropertyScoped()) {
- tracker.trackSingleKeyAccess(value, context.getContext());
+ tracker.recordSingleKeyAccess(value, context.getContext());
} else {
- tracker.trackAllPropertiesAccess(context.getContext());
+ tracker.recordAllPropertiesAccess(context.getContext());
}
return value;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/46e3ed0c/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java
----------------------------------------------------------------------
diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java
index 95b34b6..46fd767 100644
--- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java
+++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java
@@ -41,7 +41,7 @@ public interface ConfigUsageSpi {
* Allows to check if usage tracking is enabled (should be disbled by default).
* @return true, if usage tracking is enabled.
*/
- boolean isUsageTrackingEnabled();
+ boolean isTrackingEnabled();
/**
* Get the list of packages, which are not evaluated for tracking configuration access and usage statistics.
@@ -53,7 +53,7 @@ public interface ConfigUsageSpi {
* Adds the given packageNames to the list of packages to be ignored when collecting usage data.
* @param packageName the package names to be added, not null.
*/
- void addIgnoredUsagePackages(String... packageName);
+ void addIgnoredPackages(String... packageName);
/**
* Access the usage statistics for a given key. If usage stats collection is not
@@ -61,27 +61,27 @@ public interface ConfigUsageSpi {
* @param key the fully qualified configuration key, not null.
* @return the stats collected, or null.
*/
- UsageStat getUsage(String key);
+ UsageStat getSinglePropertyStats(String key);
/**
* Access the usage statistics for accessing {@link org.apache.tamaya.Configuration#getProperties()}.
* If usage stats collection is not activated (default), this method returns null.
* @return the stats collected, or null.
*/
- UsageStat getUsageAllProperties();
+ UsageStat getAllPropertiesStats();
/**
* Get the recorded usage references of configuration.
* @return the recorded usge references, never null.
*/
- Collection<UsageStat> getUsages();
+ Collection<UsageStat> getUsageStats();
/**
* Track the access of {@code Configuration#getProperties()} for
* usage statistics.
* @param context the corresponding context.
*/
- void trackAllPropertiesAccess(ConfigurationContext context);
+ void recordAllPropertiesAccess(ConfigurationContext context);
/**
* Track the access of {@code Configuration#get(String)} for
@@ -89,16 +89,16 @@ public interface ConfigUsageSpi {
* @param context the corresponding context.
* @param value value to track for
*/
- void trackSingleKeyAccess(PropertyValue value, ConfigurationContext context);
+ void recordSingleKeyAccess(PropertyValue value, ConfigurationContext context);
/**
* Access the usage statistics for the recorded uses of configuration.
* @return usage statistics info
*/
- String getUsageInfo();
+ String getInfo();
/**
* Clears all collected usage statistics.
*/
- void clearUsageStats();
+ void clearStats();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/46e3ed0c/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java
----------------------------------------------------------------------
diff --git a/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java b/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java
index a16a62e..1fcdee9 100644
--- a/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java
+++ b/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java
@@ -36,7 +36,7 @@ public class ConfigUsageStatsTest {
ConfigUsage.enableUsageTracking(true);
TestConfigAccessor.readConfiguration();
Configuration config = ConfigurationProvider.getConfiguration();
- String info = ConfigUsage.getUsageInfo();
+ String info = ConfigUsage.getInfo();
assertFalse(info.contains("java.version"));
assertNotNull(info);
config = TestConfigAccessor.readConfiguration();
@@ -45,7 +45,7 @@ public class ConfigUsageStatsTest {
TestConfigAccessor.readProperty(config, "java.version");
TestConfigAccessor.readProperty(config, "java.version");
config.get("java.version");
- info = ConfigUsage.getUsageInfo();
+ info = ConfigUsage.getInfo();
System.out.println(info);
assertTrue(info.contains("java.version"));
assertNotNull(info);
@@ -55,10 +55,10 @@ public class ConfigUsageStatsTest {
@Test
public void testUsageWhenDisabled(){
ConfigUsage.enableUsageTracking(false);
- ConfigUsage.clearUsageStats();
+ ConfigUsage.clearStats();
TestConfigAccessor.readConfiguration();
Configuration config = ConfigurationProvider.getConfiguration();
- String info = ConfigUsage.getUsageInfo();
+ String info = ConfigUsage.getInfo();
assertNotNull(info);
assertFalse(info.contains("java.version"));
config = TestConfigAccessor.readConfiguration();
@@ -67,7 +67,7 @@ public class ConfigUsageStatsTest {
TestConfigAccessor.readProperty(config, "java.version");
TestConfigAccessor.readProperty(config, "java.version");
config.get("java.version");
- info = ConfigUsage.getUsageInfo();
+ info = ConfigUsage.getInfo();
assertFalse(info.contains("java.version"));
assertNotNull(info);
ConfigUsage.enableUsageTracking(false);