http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/FilterReader.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/FilterReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/FilterReader.java new file mode 100644 index 0000000..3537ac0 --- /dev/null +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/FilterReader.java @@ -0,0 +1,85 @@ +/* + * 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.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.Filter; +import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.TamayaConfigBuilder; +import org.osgi.service.component.annotations.Component; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.config.spi.ConfigBuilder; +import java.util.Map; +import java.util.logging.Logger; + + +/** + * Metaconfiguration reader that reads the configuration filters to be used. + */ +@Component +public class FilterReader implements MetaConfigurationReader{ + + private static final Logger LOG = Logger.getLogger(FilterReader.class.getName()); + + @Override + public void read(Document document, ConfigBuilder configBuilder) { + NodeList nodeList = document.getDocumentElement().getElementsByTagName("filters"); + if(nodeList.getLength()==0){ + LOG.finer("No filters configured."); + return; + } + if(nodeList.getLength()>1){ + throw new ConfigException("Only one single filters section allowed."); + } + nodeList = nodeList.item(0).getChildNodes(); + for(int i=0;i<nodeList.getLength();i++){ + Node node = nodeList.item(i); + if(node.getNodeType()!=Node.ELEMENT_NODE) { + continue; + } + String type = node.getNodeName(); + if ("defaults".equals(type)) { + LOG.finer("Adding default filters..."); + TamayaConfigBuilder.from(configBuilder).addDiscoveredFilters(); + continue; + } + ItemFactory<Filter> filterFactory = ItemFactoryManager.getInstance().getFactory(Filter.class, type); + if(filterFactory==null){ + LOG.severe("No such filter: " + type); + continue; + } + Map<String,String> params = ComponentConfigurator.extractParameters(node); + Filter filter = filterFactory.create(params); + if(filter!=null) { + ComponentConfigurator.configure(filter, params); + LOG.finer("Adding configured filter: " + filter.getClass().getName()); + TamayaConfigBuilder.from(configBuilder).withFilters(filter); + } + } + } + + +}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 index 59878c5..5e7cff9 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java @@ -21,7 +21,6 @@ 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.osgi.service.component.annotations.Component; import org.w3c.dom.Document; @@ -29,6 +28,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import javax.annotation.Priority; +import javax.config.spi.ConfigBuilder; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; @@ -73,7 +73,7 @@ public class MetaContextReader implements MetaConfigurationReader { } @Override - public void read(Document document, ConfigurationContextBuilder contextBuilder) { + public void read(Document document, ConfigBuilder configBuilder) { NodeList nodeList = document.getDocumentElement().getElementsByTagName("context"); LOG.finer("Reading " + nodeList.getLength() + " meta context entries..."); for(int i=0;i<nodeList.getLength();i++){ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 deleted file mode 100644 index a6223a3..0000000 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java +++ /dev/null @@ -1,87 +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.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.osgi.service.component.annotations.Component; -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; - -/** - * Metaconfiguration reader to read property sources and property source providers. - */ -@Component -public class PropertyConverterReader implements MetaConfigurationReader{ - - private static final Logger LOG = Logger.getLogger(PropertyConverterReader.class.getName()); - - @Override - public void read(Document document, ConfigurationContextBuilder contextBuilder) { - NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-converters"); - if(nodeList.getLength()==0){ - LOG.finer("No property converters configured"); - return; - } - if(nodeList.getLength()>1){ - 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); - 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 configure PropertyConverter: " + type, e); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java deleted file mode 100644 index 2b2bcb8..0000000 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java +++ /dev/null @@ -1,65 +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.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.osgi.service.component.annotations.Component; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import javax.annotation.Priority; -import java.util.Comparator; -import java.util.logging.Logger; - - -/** - * Metaconfiguration reader that reads the configuration combination policy to be used. - */ -@Component -@Priority(Integer.MAX_VALUE) -public class PropertyFilterOrderingReader implements MetaConfigurationReader{ - - private static final Logger LOG = Logger.getLogger(PropertyFilterOrderingReader.class.getName()); - - @Override - public void read(Document document, ConfigurationContextBuilder contextBuilder) { - NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-filter-order"); - if(nodeList.getLength()==0){ - LOG.finer("No property filter ordering configured."); - return; - } - if(nodeList.getLength()>1){ - throw new ConfigException("Only one property filter order can be applied."); - } - Node node = nodeList.item(0); - String type = node.getAttributes().getNamedItem("type").getNodeValue(); - ItemFactory<Comparator> comparatorFactory = ItemFactoryManager.getInstance().getFactory(Comparator.class, type); - Comparator comparator = comparatorFactory.create(ComponentConfigurator.extractParameters(node)); - ComponentConfigurator.configure(comparator, node); - LOG.finer("Sorting property filters using comparator: " + comparator.getClass().getName()); - contextBuilder.sortPropertyFilter(comparator); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 deleted file mode 100644 index 5b4f80c..0000000 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java +++ /dev/null @@ -1,82 +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.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.osgi.service.component.annotations.Component; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import java.util.Map; -import java.util.logging.Logger; - - -/** - * Metaconfiguration reader that reads the configuration filters to be used. - */ -@Component -public class PropertyFilterReader implements MetaConfigurationReader{ - - private static final Logger LOG = Logger.getLogger(PropertyFilterReader.class.getName()); - - @Override - public void read(Document document, ConfigurationContextBuilder contextBuilder) { - NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-filters"); - if(nodeList.getLength()==0){ - LOG.finer("No property filters configured."); - return; - } - if(nodeList.getLength()>1){ - 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); - 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/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java deleted file mode 100644 index e7cd29c..0000000 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.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.PropertyValueCombinationPolicy; -import org.osgi.service.component.annotations.Component; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import javax.annotation.Priority; -import java.util.Comparator; -import java.util.logging.Logger; - - -/** - * Metaconfiguration reader that reads the configuration combination policy to be used. - */ -@Component -@Priority(Integer.MAX_VALUE) -public class PropertySourceOrderingReader implements MetaConfigurationReader{ - - private static final Logger LOG = Logger.getLogger(PropertySourceOrderingReader.class.getName()); - - @Override - public void read(Document document, ConfigurationContextBuilder contextBuilder) { - NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-source-order"); - if(nodeList.getLength()==0){ - LOG.finer("No property source ordering defined."); - return; - } - if(nodeList.getLength()>1){ - throw new ConfigException("Only one property source order can be applied."); - } - Node node = nodeList.item(0); - String type = node.getAttributes().getNamedItem("type").getNodeValue(); - ItemFactory<Comparator> comparatorFactory = ItemFactoryManager.getInstance().getFactory(Comparator.class, type); - Comparator comparator = comparatorFactory.create(ComponentConfigurator.extractParameters(node)); - ComponentConfigurator.configure(comparator, node); - LOG.finer("Sorting property sources using comparator: " + comparator.getClass().getName()); - contextBuilder.sortPropertySources(comparator); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 deleted file mode 100644 index 1957bf6..0000000 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java +++ /dev/null @@ -1,186 +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.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; -import org.apache.tamaya.metamodel.ext.RefreshablePropertySourceProvider; -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.PropertySource; -import org.apache.tamaya.spi.PropertySourceProvider; -import org.osgi.service.component.annotations.Component; -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; - -/** - * Metaconfiguration reader to read property sources and property source providers. - */ -@Component -public class PropertySourceReader implements MetaConfigurationReader{ - - private static final Logger LOG = Logger.getLogger(PropertySourceReader.class.getName()); - - @Override - public void read(Document document, ConfigurationContextBuilder contextBuilder) { - NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-sources"); - if(nodeList.getLength()==0){ - LOG.finer("No property sources configured."); - return; - } - if(nodeList.getLength()>1){ - 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); - 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); - continue; - } - } - } 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); - } - } - } - - /** - * Decorates a property source to be refreshable or filtered. - * @param ps the wrapped property source - *@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, Node configNode, Map<String, String> params){ - Node refreshableVal = configNode.getAttributes().getNamedItem("refreshable"); - if(refreshableVal!=null && Boolean.parseBoolean(refreshableVal.getNodeValue())){ - 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("filters".equals(node.getNodeName())){ - ps = FilteredPropertySource.of(ps); - NodeList filterNodes = node.getChildNodes(); - for(int f=0;f<filterNodes.getLength();f++) { - Node filterNode = filterNodes.item(f); - configureFilter((FilteredPropertySource) ps, filterNode); - } - } - } - return ps; - } - - private void configureFilter(FilteredPropertySource ps, Node filterNode) { - try { - String type = filterNode.getNodeName(); - ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type); - if(filterFactory==null){ - LOG.severe("No such property filter: " + type); - return; - } - Map<String,String> params = ComponentConfigurator.extractParameters(filterNode); - PropertyFilter filter = filterFactory.create(params); - if(filter!=null) { - ComponentConfigurator.configure(filter, params); - LOG.finer("Adding configured property filter: " + filter.getClass().getName()); - ps.addPropertyFilter(filter); - } - }catch(Exception e){ - LOG.log(Level.SEVERE, "Failed to read property filter configuration: " + filterNode, e); - } - } - - /** - * Decorates a property source provider to be refreshable or filtered. - * @param prov the property source provider to be wrapped. - * @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, Node configNode, Map<String, String> params){ - Node refreshableVal = configNode.getAttributes().getNamedItem("refreshable"); - // Refreshable - if(refreshableVal!=null && Boolean.parseBoolean(refreshableVal.getNodeValue())){ - prov = RefreshablePropertySourceProvider.of(params, prov); - } - // Enabled - Node enabledVal = configNode.getAttributes().getNamedItem("enabled"); - if(enabledVal!=null){ - prov = new EnabledPropertySourceProvider(prov, - MetaContext.getInstance().getProperties(), - enabledVal.getNodeValue()); - } - return prov; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java index 00d823e..c073245 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java @@ -1,233 +1,233 @@ -///* -// * 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 java.util.HashMap; -//import java.util.Map; -//import java.util.Objects; -// -///** -// * Resolver to resolve/map DSL related source expressions into PropertySources -// * loadable by a ConfigurationContext. Hereby the ordering of loaded property sources must be -// * honored if possible by implicitly adapting/Overriding the default ordinal for the sources -// * added. -// */ -//public class SourceConfig { -// -// private boolean enabled; -// private String type; -// private String name; -// private Integer ordinal; -// private long refreshInterval; -// private Map<String,String> sourceConfiguration = new HashMap<>(); -// -// private SourceConfig(Builder builder) { -// enabled = builder.enabled; -// type = builder.type; -// name = builder.name; -// refreshInterval = builder.refreshInterval; -// ordinal = builder.ordinal; -// sourceConfiguration = builder.sourceConfiguration; -// } -// -// /** -// * New builder builder. -// * -// * @param type the type -// * @return the builder -// */ -// public static Builder newBuilder(String type) { -// return new Builder(type); -// } -// -// /** -// * New builder builder using this instance's settings. -// * -// * @return the builder -// */ -// public Builder toBuilder() { -// Builder builder = new Builder(this.type); -// builder.enabled = this.enabled; -// builder.type = this.type; -// builder.ordinal = this.ordinal; -// builder.name = this.name; -// builder.sourceConfiguration = this.sourceConfiguration; -// return builder; -// } -// -// /** -// * Is enabled boolean. -// * -// * @return the boolean -// */ -// public boolean isEnabled() { -// return enabled; -// } -// -// /** -// * Gets source configuration. -// * -// * @return the source configuration -// */ -// public Map<String, String> getSourceConfiguration() { -// return sourceConfiguration; -// } -// -// /** -// * Gets type. -// * -// * @return the type -// */ -// public String getType() { -// return type; -// } -// -// /** -// * Gets the current refresh interval, default is 0 meaning the property -// * source is never refreshed. -// * -// * @return the refresh interval -// */ -// public long getRefreshInterval() { -// return refreshInterval; -// } -// -// /** -// * Gets name. -// * -// * @return the name -// */ -// public String getName() { -// return name; -// } -// -// @Override -// public String toString() { -// return "PropertySourceConfig{" + -// "enabled=" + enabled + -// ", type='" + type + '\'' + -// ", name='" + name + '\'' + -// ", ordinal=" + ordinal + -// ", sourceConfiguration=" + sourceConfiguration + -// '}'; -// } -// -// -// public <T> T create(Class<T> type) -// throws ClassNotFoundException, IllegalAccessException, -// InstantiationException { -// return (T)Class.forName(this.getType()).newInstance(); -// } -// -// -// /** -// * {@code PropertySourceConfig} builder static inner class. -// */ -// public static final class Builder { -// private boolean enabled; -// private String type; -// private String name; -// private Integer ordinal; -// private long refreshInterval; -// private Map<String, String> sourceConfiguration; -// -// private Builder(String type) { -// this.type = Objects.requireNonNull(type); -// if(type.trim().isEmpty()){ -// throw new IllegalArgumentException("Type is empty."); -// } -// } -// -// /** -// * Sets the {@code refreshInterval} and returns a reference to this Builder so that the methods can be chained together. -// * -// * @param val the {@code refreshInterval} to set -// * @return a reference to this Builder -// */ -// public Builder withRefreshInterval(long val) { -// refreshInterval = val; -// return this; -// } -// -// /** -// * Sets the {@code ordinal} and returns a reference to this Builder so that the methods can be chained together. -// * -// * @param val the {@code ordinal} to set -// * @return a reference to this Builder -// */ -// public Builder withOrdinal(Integer val) { -// ordinal = val; -// return this; -// } -// -// /** -// * Sets the {@code enabled} and returns a reference to this Builder so that the methods can be chained together. -// * -// * @param val the {@code enabled} to set -// * @return a reference to this Builder -// */ -// public Builder withEnabled(boolean val) { -// enabled = val; -// return this; -// } -// -// /** -// * Sets the {@code type} and returns a reference to this Builder so that the methods can be chained together. -// * -// * @param val the {@code type} to set -// * @return a reference to this Builder -// */ -// public Builder withType(String val) { -// type = val; -// return this; -// } -// -// /** -// * Sets the {@code name} and returns a reference to this Builder so that the methods can be chained together. -// * -// * @param val the {@code name} to set -// * @return a reference to this Builder -// */ -// public Builder withName(String val) { -// name = val; -// return this; -// } -// -// /** -// * Sets the {@code sourceConfiguration} and returns a reference to this Builder so that the methods can be chained together. -// * -// * @param val the {@code sourceConfiguration} to set -// * @return a reference to this Builder -// */ -// public Builder withSourceConfiguration(Map<String, String> val) { -// sourceConfiguration = val; -// return this; -// } -// -// /** -// * Returns a {@code PropertySourceConfig} built from the parameters previously set. -// * -// * @return a {@code PropertySourceConfig} built with parameters of this {@code PropertySourceConfig.Builder} -// */ -// public SourceConfig build() { -// return new SourceConfig(this); -// } -// } -//} +/* + * 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 java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Resolver to resolve/map DSL related source expressions into PropertySources + * loadable by a ConfigurationBuilder. Hereby the ordering of loaded property sources must be + * honored if possible by implicitly adapting/Overriding the default ordinal for the sources + * added. + */ +public class SourceConfig { + + private boolean enabled; + private String type; + private String name; + private Integer ordinal; + private long refreshInterval; + private Map<String,String> sourceConfiguration = new HashMap<>(); + + private SourceConfig(Builder builder) { + enabled = builder.enabled; + type = builder.type; + name = builder.name; + refreshInterval = builder.refreshInterval; + ordinal = builder.ordinal; + sourceConfiguration = builder.sourceConfiguration; + } + + /** + * New builder builder. + * + * @param type the type + * @return the builder + */ + public static Builder newBuilder(String type) { + return new Builder(type); + } + + /** + * New builder builder using this instance's settings. + * + * @return the builder + */ + public Builder toBuilder() { + Builder builder = new Builder(this.type); + builder.enabled = this.enabled; + builder.type = this.type; + builder.ordinal = this.ordinal; + builder.name = this.name; + builder.sourceConfiguration = this.sourceConfiguration; + return builder; + } + + /** + * Is enabled boolean. + * + * @return the boolean + */ + public boolean isEnabled() { + return enabled; + } + + /** + * Gets source configuration. + * + * @return the source configuration + */ + public Map<String, String> getSourceConfiguration() { + return sourceConfiguration; + } + + /** + * Gets type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Gets the current refresh interval, default is 0 meaning the property + * source is never refreshed. + * + * @return the refresh interval + */ + public long getRefreshInterval() { + return refreshInterval; + } + + /** + * Gets name. + * + * @return the name + */ + public String getName() { + return name; + } + + @Override + public String toString() { + return "SourceConfig{" + + "enabled=" + enabled + + ", type='" + type + '\'' + + ", name='" + name + '\'' + + ", ordinal=" + ordinal + + ", sourceConfiguration=" + sourceConfiguration + + '}'; + } + + + public <T> T create(Class<T> type) + throws ClassNotFoundException, IllegalAccessException, + InstantiationException { + return (T)Class.forName(this.getType()).newInstance(); + } + + + /** + * {@code PropertySourceConfig} builder static inner class. + */ + public static final class Builder { + private boolean enabled; + private String type; + private String name; + private Integer ordinal; + private long refreshInterval; + private Map<String, String> sourceConfiguration; + + private Builder(String type) { + this.type = Objects.requireNonNull(type); + if(type.trim().isEmpty()){ + throw new IllegalArgumentException("Type is empty."); + } + } + + /** + * Sets the {@code refreshInterval} and returns a reference to this Builder so that the methods can be chained together. + * + * @param val the {@code refreshInterval} to set + * @return a reference to this Builder + */ + public Builder withRefreshInterval(long val) { + refreshInterval = val; + return this; + } + + /** + * Sets the {@code ordinal} and returns a reference to this Builder so that the methods can be chained together. + * + * @param val the {@code ordinal} to set + * @return a reference to this Builder + */ + public Builder withOrdinal(Integer val) { + ordinal = val; + return this; + } + + /** + * Sets the {@code enabled} and returns a reference to this Builder so that the methods can be chained together. + * + * @param val the {@code enabled} to set + * @return a reference to this Builder + */ + public Builder withEnabled(boolean val) { + enabled = val; + return this; + } + + /** + * Sets the {@code type} and returns a reference to this Builder so that the methods can be chained together. + * + * @param val the {@code type} to set + * @return a reference to this Builder + */ + public Builder withType(String val) { + type = val; + return this; + } + + /** + * Sets the {@code name} and returns a reference to this Builder so that the methods can be chained together. + * + * @param val the {@code name} to set + * @return a reference to this Builder + */ + public Builder withName(String val) { + name = val; + return this; + } + + /** + * Sets the {@code sourceConfiguration} and returns a reference to this Builder so that the methods can be chained together. + * + * @param val the {@code sourceConfiguration} to set + * @return a reference to this Builder + */ + public Builder withSourceConfiguration(Map<String, String> val) { + sourceConfiguration = val; + return this; + } + + /** + * Returns a {@code PropertySourceConfig} built from the parameters previously set. + * + * @return a {@code PropertySourceConfig} built with parameters of this {@code PropertySourceConfig.Builder} + */ + public SourceConfig build() { + return new SourceConfig(this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 04dfc4c..5d5ece2 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 @@ -18,30 +18,30 @@ */ package org.apache.tamaya.metamodel.internal.factories; +import org.apache.tamaya.base.configsource.CLIConfigSource; import org.apache.tamaya.metamodel.spi.ItemFactory; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spisupport.propertysource.CLIPropertySource; import org.osgi.service.component.annotations.Component; +import javax.config.spi.ConfigSource; import java.util.Map; /** * Factory for configuring CLI argument based property sources. */ @Component -public final class CLIArgumentsFactory implements ItemFactory<PropertySource>{ +public final class CLIArgumentsFactory implements ItemFactory<ConfigSource>{ @Override public String getName() { return "CLI"; } @Override - public PropertySource create(Map<String,String> parameters) { - return new CLIPropertySource(); + public ConfigSource create(Map<String,String> parameters) { + return new CLIConfigSource(); } @Override - public Class<? extends PropertySource> getType() { - return PropertySource.class; + public Class<? extends ConfigSource> getType() { + return ConfigSource.class; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java index a22cc98..a69255c 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java @@ -19,30 +19,30 @@ package org.apache.tamaya.metamodel.internal.factories; +import org.apache.tamaya.base.configsource.EnvironmentConfigSource; import org.apache.tamaya.metamodel.spi.ItemFactory; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource; import org.osgi.service.component.annotations.Component; +import javax.config.spi.ConfigSource; import java.util.Map; /** * Factory for configuring environment properties based property sources. */ @Component -public final class EnvPropertiesFactory implements ItemFactory<PropertySource>{ +public final class EnvPropertiesFactory implements ItemFactory<ConfigSource>{ @Override public String getName() { return "env-properties"; } @Override - public PropertySource create(Map<String,String> parameters) { - return new EnvironmentPropertySource(); + public ConfigSource create(Map<String,String> parameters) { + return new EnvironmentConfigSource(); } @Override - public Class<? extends PropertySource> getType() { - return PropertySource.class; + public Class<? extends ConfigSource> getType() { + return ConfigSource.class; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 c2ebe15..5abe359 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 @@ -31,7 +31,7 @@ import java.util.logging.Logger; * Factory for configuring file based property sources. */ @Component -public final class FilePropertySourceFactory extends ResourcePropertySourceFactory{ +public final class FilePropertySourceFactory extends ResourceConfigSourceFactory { private static final Logger LOG = Logger.getLogger(FilePropertySourceFactory.class.getName()); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourceConfigSourceFactory.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourceConfigSourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourceConfigSourceFactory.java new file mode 100644 index 0000000..7f837ed --- /dev/null +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourceConfigSourceFactory.java @@ -0,0 +1,55 @@ +/* + * 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.osgi.service.component.annotations.Component; + +import java.net.URL; +import java.util.logging.Logger; + +/** + * Factory for configuring resource based property sources. + */ +@Component +public class ResourceConfigSourceFactory extends URLConfigSourceFactory { + + private static final Logger LOG = Logger.getLogger(ResourceConfigSourceFactory.class.getName()); + + @Override + public String getName() { + return "resource"; + } + + + protected String example() { + return "<resource location=\"META-INF/config.xml\"\n" + + " formats=\"xml-properties\")>\n"; + } + + protected URL createResource(String location) { + try { + return getClass().getClassLoader().getResource(location); + } catch (Exception e) { + LOG.warning("Invalid resource '" + location + "'."); + return null; + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 deleted file mode 100644 index 76472a5..0000000 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java +++ /dev/null @@ -1,55 +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.factories; - -import org.osgi.service.component.annotations.Component; - -import java.net.URL; -import java.util.logging.Logger; - -/** - * Factory for configuring resource based property sources. - */ -@Component -public class ResourcePropertySourceFactory extends URLPropertySourceFactory{ - - private static final Logger LOG = Logger.getLogger(ResourcePropertySourceFactory.class.getName()); - - @Override - public String getName() { - return "resource"; - } - - - protected String example() { - return "<resource location=\"META-INF/config.xml\"\n" + - " formats=\"xml-properties\")>\n"; - } - - protected URL createResource(String location) { - try { - return getClass().getClassLoader().getResource(location); - } catch (Exception e) { - LOG.warning("Invalid resource '" + location + "'."); - return null; - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 6dc97ac..37781b5 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 @@ -24,10 +24,10 @@ import org.apache.tamaya.format.ConfigurationFormats; import org.apache.tamaya.format.MappedConfigurationDataConfigSource; import org.apache.tamaya.metamodel.spi.ItemFactory; import org.apache.tamaya.resource.ConfigResources; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertySourceProvider; import org.osgi.service.component.annotations.Component; +import javax.config.spi.ConfigSource; +import javax.config.spi.ConfigSourceProvider; import java.net.URL; import java.util.*; import java.util.logging.Level; @@ -37,7 +37,7 @@ import java.util.logging.Logger; * Factory for configuring resource based property sources. */ @Component -public class ResourcePropertySourceProviderFactory implements ItemFactory<PropertySourceProvider>{ +public class ResourcePropertySourceProviderFactory implements ItemFactory<ConfigSourceProvider>{ private static final Logger LOG = Logger.getLogger(ResourcePropertySourceProviderFactory.class.getName()); @@ -47,14 +47,14 @@ public class ResourcePropertySourceProviderFactory implements ItemFactory<Proper } @Override - public PropertySourceProvider create(Map<String,String> parameters) { + public ConfigSourceProvider create(Map<String,String> parameters) { String location = parameters.get("location"); if(location==null){ LOG.warning("Cannot read 'location' from " + parameters + ", example: " + example()); return null; } Collection<URL> resources = createResources(location); - List<PropertySource> propertySources = new ArrayList<>(); + List<ConfigSource> propertySources = new ArrayList<>(); if(resources!=null) { String[] formats = getFormats(parameters); for(URL resource:resources) { @@ -72,18 +72,13 @@ public class ResourcePropertySourceProviderFactory implements ItemFactory<Proper } } } - final List<PropertySource> finalPropertySources = Collections.unmodifiableList(propertySources); - return new PropertySourceProvider() { - @Override - public Collection<PropertySource> getPropertySources() { - return finalPropertySources; - } - }; + final List<ConfigSource> finalPropertySources = Collections.unmodifiableList(propertySources); + return (url)-> finalPropertySources; } @Override - public Class<? extends PropertySourceProvider> getType() { - return PropertySourceProvider.class; + public Class<? extends ConfigSourceProvider> getType() { + return ConfigSourceProvider.class; } protected String[] getFormats(Map<String, String> parameters) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java index 4fbae29..31c015f 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java @@ -19,30 +19,30 @@ package org.apache.tamaya.metamodel.internal.factories; +import org.apache.tamaya.base.configsource.SystemConfigSource; import org.apache.tamaya.metamodel.spi.ItemFactory; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spisupport.propertysource.SystemPropertySource; import org.osgi.service.component.annotations.Component; +import javax.config.spi.ConfigSource; import java.util.Map; /** * Factory for configuring system properties based property sources. */ @Component -public final class SysPropertiesFactory implements ItemFactory<PropertySource>{ +public final class SysPropertiesFactory implements ItemFactory<ConfigSource>{ @Override public String getName() { return "sys-properties"; } @Override - public PropertySource create(Map<String,String> parameters) { - return new SystemPropertySource(); + public ConfigSource create(Map<String,String> parameters) { + return new SystemConfigSource(); } @Override - public Class<? extends PropertySource> getType() { - return PropertySource.class; + public Class<? extends ConfigSource> getType() { + return ConfigSource.class; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLConfigSourceFactory.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLConfigSourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLConfigSourceFactory.java new file mode 100644 index 0000000..a5439a9 --- /dev/null +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLConfigSourceFactory.java @@ -0,0 +1,151 @@ +/* + * 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.format.ConfigurationData; +import org.apache.tamaya.format.ConfigurationFormats; +import org.apache.tamaya.format.MappedConfigurationDataConfigSource; +import org.apache.tamaya.functions.Supplier; +import org.apache.tamaya.metamodel.internal.ComponentConfigurator; +import org.apache.tamaya.metamodel.spi.ItemFactory; +import org.osgi.service.component.annotations.Component; + +import javax.config.spi.ConfigSource; +import javax.security.auth.RefreshFailedException; +import javax.security.auth.Refreshable; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Factory for configuring resource based property sources. + */ +@Component +public class URLConfigSourceFactory implements ItemFactory<ConfigSource>{ + + private static final Logger LOG = Logger.getLogger(FilePropertySourceFactory.class.getName()); + + @Override + public String getName() { + return "url"; + } + + @Override + public ConfigSource create(Map<String,String> parameters) { + String location = parameters.get("location"); + if(location==null){ + LOG.warning("Cannot read 'location' from " + parameters + ", example: " + example()); + return null; + } + URL resource = createResource(location); + if(resource!=null) { + String[] formats = getFormats(parameters); + String name = resource.toString(); + RefreshablePropertySource ps = new RefreshablePropertySource(name, new LazyDataSupplier(resource, formats)); + ComponentConfigurator.configure(ps, parameters); + return ps; + } + return null; + } + + protected String example() { + return "<url location=\"http://127.0.0.1:1110/config.xml\"\n" + + " formats=\"xml-properties\"\n/>"; + } + + protected URL createResource(String location) { + try { + return new URL(location); + } catch (MalformedURLException e) { + LOG.warning("Invalid url '" + location + "'."); + return null; + } + } + + protected String[] getFormats(Map<String, String> parameters) { + String val = parameters.get("formats"); + if(val==null){ + return new String[0]; + } + String[] formats = val.split(","); + for(int i=0;i<formats.length;i++){ + formats[i] = formats[i].trim(); + } + return formats; + } + + @Override + public Class<? extends ConfigSource> getType() { + return ConfigSource.class; + } + + private static final class LazyDataSupplier implements Supplier<ConfigurationData> { + + private String[] formats; + private URL resource; + + public LazyDataSupplier(URL resource, String[] formats) { + this.formats = Objects.requireNonNull(formats); + this.resource = Objects.requireNonNull(resource); + } + + @Override + public ConfigurationData get() { + ConfigurationData data; + try { + if (formats.length == 0) { + data = ConfigurationFormats.readConfigurationData(resource); + } else { + data = ConfigurationFormats.readConfigurationData(resource, + ConfigurationFormats.getFormats(formats)); + } + return data; + } catch (Exception e) { + LOG.log(Level.INFO, "Failed to read property source from resource: " + resource, e); + return null; + } + } + } + + private static final class RefreshablePropertySource extends MappedConfigurationDataConfigSource + implements Refreshable{ + + public RefreshablePropertySource(String name, Supplier<ConfigurationData> dataSupplier) { + super(name, dataSupplier); + } + + public RefreshablePropertySource(String name, int defaultOrdinal, Supplier<ConfigurationData> dataSupplier) { + super(name, dataSupplier); + } + + @Override + public boolean isCurrent() { + return false; + } + + @Override + public void refresh() throws RefreshFailedException { + super.load(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 deleted file mode 100644 index d09ae88..0000000 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java +++ /dev/null @@ -1,151 +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.factories; - -import org.apache.tamaya.format.ConfigurationData; -import org.apache.tamaya.format.ConfigurationFormats; -import org.apache.tamaya.format.MappedConfigurationDataConfigSource; -import org.apache.tamaya.functions.Supplier; -import org.apache.tamaya.metamodel.internal.ComponentConfigurator; -import org.apache.tamaya.metamodel.spi.ItemFactory; -import org.apache.tamaya.spi.PropertySource; -import org.osgi.service.component.annotations.Component; - -import javax.security.auth.RefreshFailedException; -import javax.security.auth.Refreshable; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Map; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Factory for configuring resource based property sources. - */ -@Component -public class URLPropertySourceFactory implements ItemFactory<PropertySource>{ - - private static final Logger LOG = Logger.getLogger(FilePropertySourceFactory.class.getName()); - - @Override - public String getName() { - return "url"; - } - - @Override - public PropertySource create(Map<String,String> parameters) { - String location = parameters.get("location"); - if(location==null){ - LOG.warning("Cannot read 'location' from " + parameters + ", example: " + example()); - return null; - } - URL resource = createResource(location); - if(resource!=null) { - String[] formats = getFormats(parameters); - String name = resource.toString(); - RefreshablePropertySource ps = new RefreshablePropertySource(name, new LazyDataSupplier(resource, formats)); - ComponentConfigurator.configure(ps, parameters); - return ps; - } - return null; - } - - protected String example() { - return "<url location=\"http://127.0.0.1:1110/config.xml\"\n" + - " formats=\"xml-properties\"\n/>"; - } - - protected URL createResource(String location) { - try { - return new URL(location); - } catch (MalformedURLException e) { - LOG.warning("Invalid url '" + location + "'."); - return null; - } - } - - protected String[] getFormats(Map<String, String> parameters) { - String val = parameters.get("formats"); - if(val==null){ - return new String[0]; - } - String[] formats = val.split(","); - for(int i=0;i<formats.length;i++){ - formats[i] = formats[i].trim(); - } - return formats; - } - - @Override - public Class<? extends PropertySource> getType() { - return PropertySource.class; - } - - private static final class LazyDataSupplier implements Supplier<ConfigurationData> { - - private String[] formats; - private URL resource; - - public LazyDataSupplier(URL resource, String[] formats) { - this.formats = Objects.requireNonNull(formats); - this.resource = Objects.requireNonNull(resource); - } - - @Override - public ConfigurationData get() { - ConfigurationData data; - try { - if (formats.length == 0) { - data = ConfigurationFormats.readConfigurationData(resource); - } else { - data = ConfigurationFormats.readConfigurationData(resource, - ConfigurationFormats.getFormats(formats)); - } - return data; - } catch (Exception e) { - LOG.log(Level.INFO, "Failed to read property source from resource: " + resource, e); - return null; - } - } - } - - private static final class RefreshablePropertySource extends MappedConfigurationDataConfigSource - implements Refreshable{ - - public RefreshablePropertySource(String name, Supplier<ConfigurationData> dataSupplier) { - super(name, dataSupplier); - } - - public RefreshablePropertySource(String name, int defaultOrdinal, Supplier<ConfigurationData> dataSupplier) { - super(name, dataSupplier); - } - - @Override - public boolean isCurrent() { - return false; - } - - @Override - public void refresh() throws RefreshFailedException { - super.load(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java index 005aa24..9339b71 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java @@ -18,9 +18,10 @@ */ package org.apache.tamaya.metamodel.spi; -import org.apache.tamaya.spi.ConfigurationContextBuilder; import org.w3c.dom.Document; +import javax.config.spi.ConfigBuilder; + /** * Reader that reads meta configuration from the meta configuration XML source. * This SPI allows to allow different aspects to be configured by different modules. @@ -32,8 +33,8 @@ public interface MetaConfigurationReader { * context builder. The priority of readers is determined by the priorization policy * implemented by the {@link org.apache.tamaya.spi.ServiceContext}, * @param document the meta-configuration document - * @param contextBuilder the context builder to use. + * @param configBuilder the config builder to use. */ - void read(Document document, ConfigurationContextBuilder contextBuilder); + void read(Document document, ConfigBuilder configBuilder); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.core.TamayaConfigProviderResolver$ConfigFactory ---------------------------------------------------------------------- diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.core.TamayaConfigProviderResolver$ConfigFactory b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.core.TamayaConfigProviderResolver$ConfigFactory new file mode 100644 index 0000000..c7c460b --- /dev/null +++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.core.TamayaConfigProviderResolver$ConfigFactory @@ -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.metamodel.internal.DSLBasedConfigFactory \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 951f4b8..846c63f 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 @@ -19,9 +19,9 @@ org.apache.tamaya.metamodel.internal.factories.CLIArgumentsFactory org.apache.tamaya.metamodel.internal.factories.EnvPropertiesFactory org.apache.tamaya.metamodel.internal.factories.FilePropertySourceFactory -org.apache.tamaya.metamodel.internal.factories.ResourcePropertySourceFactory +org.apache.tamaya.metamodel.internal.factories.ResourceConfigSourceFactory org.apache.tamaya.metamodel.internal.factories.SysPropertiesFactory -org.apache.tamaya.metamodel.internal.factories.URLPropertySourceFactory +org.apache.tamaya.metamodel.internal.factories.URLConfigSourceFactory org.apache.tamaya.metamodel.internal.factories.ResourcePropertySourceProviderFactory http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/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 79b9249..e3bb4f8 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 @@ -16,11 +16,10 @@ # specific language governing permissions and limitations # under the License. # - -org.apache.tamaya.metamodel.internal.PropertyFilterReader -org.apache.tamaya.metamodel.internal.PropertyConverterReader -org.apache.tamaya.metamodel.internal.PropertySourceReader +org.apache.tamaya.metamodel.internal.FilterReader +org.apache.tamaya.metamodel.internal.ConverterReader +org.apache.tamaya.metamodel.internal.ConfigSourceReader 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 +org.apache.tamaya.metamodel.internal.FilterOrderingReader +org.apache.tamaya.metamodel.internal.ConfigSourceOrderingReader \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi ---------------------------------------------------------------------- diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi deleted file mode 100644 index f9a7797..0000000 --- a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi +++ /dev/null @@ -1,20 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -org.apache.tamaya.metamodel.internal.DSLLoadingConfigurationProviderSpi \ No newline at end of file
