You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:18:47 UTC
[sling-org-apache-sling-caconfig-api] 01/24: SLING-5886 : Add draft
api
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.caconfig.api-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-caconfig-api.git
commit fd452cbd4744dda2da0d7ea68ed6a2646278bcb5
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Jul 29 12:19:18 2016 +0000
SLING-5886 : Add draft api
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/context-aware-config/api@1754502 13f79535-47bb-0310-9956-ffa450edef68
---
README.txt | 25 +++++++
pom.xml | 69 +++++++++++++++++
.../apache/sling/config/ConfigurationBuilder.java | 54 ++++++++++++++
.../apache/sling/config/ConfigurationResolver.java | 41 +++++++++++
.../java/org/apache/sling/config/package-info.java | 23 ++++++
.../resource/ConfigurationResourceResolver.java | 68 +++++++++++++++++
.../apache/sling/config/resource/package-info.java | 24 ++++++
.../config/spi/ConfigurationMetadataProvider.java | 39 ++++++++++
.../config/spi/ConfigurationOverrideProvider.java | 68 +++++++++++++++++
.../spi/ConfigurationPersistenceProvider.java | 60 +++++++++++++++
.../sling/config/spi/ContextPathStrategy.java | 44 +++++++++++
.../spi/metadata/AbstractConfigurationPart.java | 65 ++++++++++++++++
.../config/spi/metadata/ConfigurationMetadata.java | 73 ++++++++++++++++++
.../config/spi/metadata/ConfigurationPart.java | 44 +++++++++++
.../config/spi/metadata/PropertyMetadata.java | 86 ++++++++++++++++++++++
.../sling/config/spi/metadata/package-info.java | 23 ++++++
.../org/apache/sling/config/spi/package-info.java | 23 ++++++
.../spi/metadata/ConfigurationMetadataTest.java | 60 +++++++++++++++
.../config/spi/metadata/PropertyMetadataTest.java | 52 +++++++++++++
19 files changed, 941 insertions(+)
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..5d77ea0
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,25 @@
+Apache Sling Context Aware Configuration API
+
+
+Getting Started
+===============
+
+This component uses a Maven 3 (http://maven.apache.org/) build
+environment. It requires a Java 7 JDK (or higher) and Maven (http://maven.apache.org/)
+3.3.9 or later. We recommend to use the latest Maven version.
+
+If you have Maven 3 installed, you can compile and
+package the jar using the following command:
+
+ mvn package
+
+See the Maven 3 documentation for other build features.
+
+The latest source code for this component is available in the
+Subversion (http://subversion.tigris.org/) source repository of
+the Apache Software Foundation. If you have Subversion installed,
+you can checkout the latest source using the following command:
+
+ svn checkout https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/context-aware-config/api
+
+See the Subversion documentation for other source control features.
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..e00d9e4
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>27</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>org.apache.sling.config.api</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Apache Sling Context-Aware-Config API</name>
+ <description>Apache Sling Context-Aware-Config API</description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/context-aware-config/api</connection>
+ <developerConnection> scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/context-aware-config/api</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/api</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.4.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/config/ConfigurationBuilder.java b/src/main/java/org/apache/sling/config/ConfigurationBuilder.java
new file mode 100644
index 0000000..acf44c6
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/ConfigurationBuilder.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.sling.config;
+
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Defines how the configuration should be mapped and returned.
+ */
+@ProviderType
+public interface ConfigurationBuilder {
+
+ /**
+ * Define configuration name. Optional when using annotation class, mandatory when getting configuration as value map.
+ * @param configName Relative path
+ * @return Configuration builder
+ */
+ @Nonnull ConfigurationBuilder name(@Nonnull String configName);
+
+ /**
+ * Get configuration as singleton and its properties mapped to the given annotation class.
+ * @param clazz Annotation class or {@link org.apache.sling.api.resource.ValueMap}
+ * @return Configuration object
+ */
+ @Nonnull <T> T as(@Nonnull Class<T> clazz);
+
+ /**
+ * Get list of configuration instances with its properties mapped to the given annotation class.
+ * @param clazz Annotation class or {@link org.apache.sling.api.resource.ValueMap}
+ * @return List of configuration objects
+ */
+ @Nonnull <T> Collection<T> asCollection(@Nonnull Class<T> clazz);
+
+}
diff --git a/src/main/java/org/apache/sling/config/ConfigurationResolver.java b/src/main/java/org/apache/sling/config/ConfigurationResolver.java
new file mode 100644
index 0000000..b3a4285
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/ConfigurationResolver.java
@@ -0,0 +1,41 @@
+/*
+ * 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.sling.config;
+
+import javax.annotation.Nonnull;
+
+import org.apache.sling.api.resource.Resource;
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Getting context-specific configurations for a given resource context.
+ * Context-specific configuration may be different for different parts of the resource
+ * hierarchy, and configuration parameter inheritance may take place.
+ */
+@ProviderType
+public interface ConfigurationResolver {
+
+ /**
+ * Get configuration for given resource.
+ * @param resource Context resource
+ * @return Configuration builder
+ */
+ @Nonnull ConfigurationBuilder get(@Nonnull Resource resource);
+
+}
diff --git a/src/main/java/org/apache/sling/config/package-info.java b/src/main/java/org/apache/sling/config/package-info.java
new file mode 100644
index 0000000..e4bc375
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+/**
+ * API for accessing context-specific configuration.
+ */
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.config;
diff --git a/src/main/java/org/apache/sling/config/resource/ConfigurationResourceResolver.java b/src/main/java/org/apache/sling/config/resource/ConfigurationResourceResolver.java
new file mode 100644
index 0000000..4fa6baf
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/resource/ConfigurationResourceResolver.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.resource;
+
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+
+import org.apache.sling.api.resource.Resource;
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Getting context-specific configuration resources for a given resource context.
+ * This is a low-level interface for supporting advanced usecases. If you just want to fetch
+ * some configuration parameters {@link ConfigurationResolver} is the right place.
+ */
+@ProviderType
+public interface ConfigurationResourceResolver {
+
+ /**
+ * Get a context-specific singleton configuration resource defined by the given configuration name.
+ * @param resource Context resource to fetch configuration for
+ * @param configName Configuration name or relative path.
+ * @return Configuration resource
+ */
+ @Nonnull Resource getResource(@Nonnull Resource resource, @Nonnull String configName);
+
+ /**
+ * Get a list of context-specific configuration resources defined by the given configuration name.
+ * @param resource Context resource to fetch configuration for
+ * @param configName Configuration name or relative path.
+ * @return List of configuration resources
+ */
+ @Nonnull Collection<Resource> getResourceList(@Nonnull Resource resource, @Nonnull String configName);
+
+ /**
+ * Get the inner-most context path (deepest path) returned by {@link #getAllContextPaths(Resource)}.
+ * @param resource Context resource to fetch configuration for
+ * @return Context path or null
+ */
+ String getContextPath(@Nonnull Resource resource);
+
+ /**
+ * Get all context paths for which context-specific configurations could be defined.
+ * The context paths are always ancestors of the resource path, or the resource path itself.
+ * Which ancestors are allowed for context-specific configuration depends on configuration.
+ * @param resource Context resource to fetch configuration for
+ * @return List of context paths
+ */
+ @Nonnull Collection<String> getAllContextPaths(@Nonnull Resource resource);
+
+}
diff --git a/src/main/java/org/apache/sling/config/resource/package-info.java b/src/main/java/org/apache/sling/config/resource/package-info.java
new file mode 100644
index 0000000..f602d02
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/resource/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+/**
+ * API for accessing context-specific configuration resources.
+ * This is a low-level API.
+ */
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.config.resource;
diff --git a/src/main/java/org/apache/sling/config/spi/ConfigurationMetadataProvider.java b/src/main/java/org/apache/sling/config/spi/ConfigurationMetadataProvider.java
new file mode 100644
index 0000000..c7e83f9
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/ConfigurationMetadataProvider.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.spi;
+
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+
+import org.apache.sling.config.spi.metadata.ConfigurationMetadata;
+import org.osgi.annotation.versioning.ConsumerType;
+
+/**
+ * Allows application to provide the necessary metadata for configurations.
+ */
+@ConsumerType
+public interface ConfigurationMetadataProvider {
+
+ /**
+ * @return Configuration metadata that the application defines
+ */
+ @Nonnull Collection<ConfigurationMetadata> getConfigSets();
+
+}
diff --git a/src/main/java/org/apache/sling/config/spi/ConfigurationOverrideProvider.java b/src/main/java/org/apache/sling/config/spi/ConfigurationOverrideProvider.java
new file mode 100644
index 0000000..56b2d50
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/ConfigurationOverrideProvider.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.spi;
+
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+
+import org.osgi.annotation.versioning.ConsumerType;
+
+/**
+ * Provides configuration override values (default or forced).
+ */
+@ConsumerType
+public interface ConfigurationOverrideProvider {
+
+ /**
+ * Returns a map with key value pairs for configuration parameter override.
+ * <p>
+ * Key:
+ * </p>
+ * <ul>
+ * <li>Syntax: <code>[{scope}[:locked]]{configName}/{propertyName}</code></li>
+ * <li><code>{scope}</code>: if "default", the system default parameter is overridden. Otherwise <code>{scope}</code>
+ * may define a context path, in this case the configuration set's property value is overwritten by force for this
+ * context path. If the [{scope}] part is missing or [locked], the parameter is overridden for all context paths.</li>
+ * <li><code>locked</code>: If the scope value is suffixed with the string ":locked" this configuration
+ * parameter cannot be overridden in nested configuration scopes.</li>
+ * <li><code>{configName}</code>: Configuration name</li>
+ * <li><code>{propertyName}</code>: Configuration property name</li>
+ * </ul>
+ * <p>
+ * Examples:
+ * </p>
+ * <ul>
+ * <li><code>[default]set1/param1</code> - Override default value for property "param1" from set "set1"</li>
+ * <li><code>set1/param1</code> - Override value for property "param1" from set "set1" for all context paths</li>
+ * <li><code>[/content/region1/site1]set1/param1</code> - Override value for property "param1" from set "set1" for the context path
+ * <code>/content/region1/site1</code>. This has higher precedence than the other variants.</li>
+ * </ul>
+ * <p>
+ * Value:
+ * </p>
+ * <ul>
+ * <li>Override value</li>
+ * <li>Has to be convertible to the property's type</li>
+ * </ul>
+ * @return Map
+ */
+ @Nonnull Map<String, String> getOverrideMap();
+
+}
diff --git a/src/main/java/org/apache/sling/config/spi/ConfigurationPersistenceProvider.java b/src/main/java/org/apache/sling/config/spi/ConfigurationPersistenceProvider.java
new file mode 100644
index 0000000..eee2245
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/ConfigurationPersistenceProvider.java
@@ -0,0 +1,60 @@
+/*
+ * 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.sling.config.spi;
+
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.osgi.annotation.versioning.ConsumerType;
+
+/**
+ * Provides configuration persistence implementations.
+ */
+@ConsumerType
+public interface ConfigurationPersistenceProvider {
+
+ /**
+ * Get all configuration values stored for a context path.
+ * @param resolver Resource resolver
+ * @param contextPath Context path
+ * @param configNames If a set of config names is given only configuration for these names is returned.
+ * Otherwise all are returned.
+ * @return Configuration names with value map containing the configuration set properties.
+ * Returns null if no parameters stored for this context paths, allowing other
+ * persistence providers to step in.
+ */
+ Map<String, Map<String, Object>> get(@Nonnull ResourceResolver resolver, @Nonnull String contextPath, String... configNames);
+
+ /**
+ * Writes configuration values for a context paths. For each configuration name contained in the values map all existing
+ * parameter values are erased before writing the new ones.
+ * @param resolver Resource resolver
+ * @param contextPath Context path
+ * @param values Configuration names with value map containing the configuration set properties.
+ * @return true if configurations are accepted. false if this provider does not accept storing
+ * the configurations and the next provider should be asked to store them.
+ * @throws PersistenceException Persistence exception is thrown when storing configurations failed.
+ */
+ boolean store(@Nonnull ResourceResolver resolver, @Nonnull String contextPath, @Nonnull String configName,
+ @Nonnull Map<String, Map<String, Object>> values) throws PersistenceException;
+
+}
diff --git a/src/main/java/org/apache/sling/config/spi/ContextPathStrategy.java b/src/main/java/org/apache/sling/config/spi/ContextPathStrategy.java
new file mode 100644
index 0000000..7d6b629
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/ContextPathStrategy.java
@@ -0,0 +1,44 @@
+/*
+ * 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.sling.config.spi;
+
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+
+import org.apache.sling.api.resource.Resource;
+import org.osgi.annotation.versioning.ConsumerType;
+
+/**
+ * Allows application to define a strategy to find context paths for content paths.
+ * Each context path may have it's own context-specific configuration.
+ */
+@ConsumerType
+public interface ContextPathStrategy {
+
+ /**
+ * Finds context paths for the given context resource.
+ * @param resource Context resource
+ * @return Context paths that where detected in the given path
+ * (in order of closest matching first).
+ * If none are found an empty list is returned.
+ */
+ @Nonnull Collection<String> findContextPaths(@Nonnull Resource resource);
+
+}
diff --git a/src/main/java/org/apache/sling/config/spi/metadata/AbstractConfigurationPart.java b/src/main/java/org/apache/sling/config/spi/metadata/AbstractConfigurationPart.java
new file mode 100644
index 0000000..b79d8b5
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/metadata/AbstractConfigurationPart.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.spi.metadata;
+
+import java.util.HashMap;
+
+import javax.annotation.Nonnull;
+
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Defines a configuration set.
+ */
+@ProviderType
+abstract class AbstractConfigurationPart implements ConfigurationPart {
+
+ private final String name;
+ private final ValueMap properties = new ValueMapDecorator(new HashMap<String, Object>());
+
+ public AbstractConfigurationPart(@Nonnull String name) {
+ if (name == null || !ConfigurationPart.NAME_PATTERN.matcher(name).matches()) {
+ throw new IllegalArgumentException("Invalid name: " + name);
+ }
+ this.name = name;
+ }
+
+ /**
+ * @return Parameter name
+ */
+ public @Nonnull String getName() {
+ return this.name;
+ }
+
+ /**
+ * @return Further properties for documentation and configuration of
+ * behavior in configuration editor.
+ */
+ public @Nonnull ValueMap getProperties() {
+ return this.properties;
+ }
+
+ @Override
+ public String toString() {
+ return this.name;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/config/spi/metadata/ConfigurationMetadata.java b/src/main/java/org/apache/sling/config/spi/metadata/ConfigurationMetadata.java
new file mode 100644
index 0000000..e43cecc
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/metadata/ConfigurationMetadata.java
@@ -0,0 +1,73 @@
+/*
+ * 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.sling.config.spi.metadata;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Defines a configuration set.
+ */
+@ProviderType
+public final class ConfigurationMetadata extends AbstractConfigurationPart {
+
+ private boolean isList;
+ private final List<ConfigurationPart> parts = new ArrayList<>();
+
+ /**
+ * @param name Configuration name
+ */
+ public ConfigurationMetadata(@Nonnull String name) {
+ super(name);
+ }
+
+ /**
+ * @return true if configuration is singleton
+ */
+ public boolean isSingleton() {
+ return !isList;
+ }
+
+ /**
+ * @return true if configuration is list
+ */
+ public boolean isList() {
+ return isList;
+ }
+
+ /**
+ * @param isList true if configuration is list
+ */
+ public void setList(boolean isList) {
+ this.isList = isList;
+ }
+
+ /**
+ * @return Configuration set parts
+ */
+ public @Nonnull Collection<ConfigurationPart> getParts() {
+ return this.parts;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/config/spi/metadata/ConfigurationPart.java b/src/main/java/org/apache/sling/config/spi/metadata/ConfigurationPart.java
new file mode 100644
index 0000000..1a1590c
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/metadata/ConfigurationPart.java
@@ -0,0 +1,44 @@
+/*
+ * 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.sling.config.spi.metadata;
+
+import java.util.regex.Pattern;
+
+import javax.annotation.Nonnull;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Part of configuration set.
+ */
+@ProviderType
+public interface ConfigurationPart {
+
+ /**
+ * Pattern for allowed configuration part names.
+ */
+ Pattern NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9\\-\\_\\.]+(/[a-zA-Z0-9\\-\\_\\.]+)*$");
+
+ /**
+ * Configuration part name
+ * @return
+ */
+ @Nonnull String getName();
+
+}
diff --git a/src/main/java/org/apache/sling/config/spi/metadata/PropertyMetadata.java b/src/main/java/org/apache/sling/config/spi/metadata/PropertyMetadata.java
new file mode 100644
index 0000000..2b4e1a6
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/metadata/PropertyMetadata.java
@@ -0,0 +1,86 @@
+/*
+ * 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.sling.config.spi.metadata;
+
+import javax.annotation.Nonnull;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Defines a configuration property.
+ * @param <T> Property value type
+ */
+@ProviderType
+public final class PropertyMetadata<T> extends AbstractConfigurationPart {
+
+ private static final Class<?>[] SUPPORTED_TYPES = {
+ String.class, String[].class,
+ Integer.class, Integer[].class,
+ Long.class, Long[].class,
+ Double.class, Double[].class,
+ Boolean.class, Boolean[].class
+ };
+
+ private final Class<T> type;
+ private T defaultValue;
+
+ public PropertyMetadata(@Nonnull String name, @Nonnull Class<T> type) {
+ super(name);
+ if (type == null || !isSupportedType(type)) {
+ throw new IllegalArgumentException("Invalid parameter type: " + type);
+ }
+ this.type = type;
+ }
+
+ private boolean isSupportedType(Class<T> paramType) {
+ for (Class<?> type : SUPPORTED_TYPES) {
+ if (type.equals(paramType)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @return Parameter type
+ */
+ public @Nonnull Class<T> getType() {
+ return this.type;
+ }
+
+ /**
+ * @return Default value if parameter is not set for configuration
+ */
+ public T getDefaultValue() {
+ return this.defaultValue;
+ }
+
+ /**
+ * @param value Default value if parameter is not set for configuration
+ */
+ public void setDefaultValue(T value) {
+ this.defaultValue = value;
+ }
+
+ @Override
+ public String toString() {
+ return getName() + "[" + this.type.getSimpleName() + "]";
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/config/spi/metadata/package-info.java b/src/main/java/org/apache/sling/config/spi/metadata/package-info.java
new file mode 100644
index 0000000..f8b578b
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/metadata/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+/**
+ * Defining configuration and parameter metadata for the SPI.
+ */
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.config.spi.metadata;
diff --git a/src/main/java/org/apache/sling/config/spi/package-info.java b/src/main/java/org/apache/sling/config/spi/package-info.java
new file mode 100644
index 0000000..3b35911
--- /dev/null
+++ b/src/main/java/org/apache/sling/config/spi/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+/**
+ * SPI for applications hooking into the configuration infrastructure for parameterizing and customizing.
+ */
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.config.spi;
diff --git a/src/test/java/org/apache/sling/config/spi/metadata/ConfigurationMetadataTest.java b/src/test/java/org/apache/sling/config/spi/metadata/ConfigurationMetadataTest.java
new file mode 100644
index 0000000..50c6dd5
--- /dev/null
+++ b/src/test/java/org/apache/sling/config/spi/metadata/ConfigurationMetadataTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.sling.config.spi.metadata;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class ConfigurationMetadataTest {
+
+ @Test
+ public void testSimple() {
+ ConfigurationMetadata underTest = new ConfigurationMetadata("hier1/set1");
+ assertEquals("hier1/set1", underTest.getName());
+ assertTrue(underTest.isSingleton());
+ assertFalse(underTest.isList());
+
+ underTest.getProperties().put("p1", "v1");
+ assertEquals("v1", underTest.getProperties().get("p1", String.class));
+
+ underTest.getParts().add(new PropertyMetadata<String>("param1", String.class));
+ underTest.getParts().add(new PropertyMetadata<Integer>("param2", Integer.class));
+ underTest.getParts().add(new ConfigurationMetadata("set1"));
+
+ assertEquals(3, underTest.getParts().size());
+ }
+
+ @Test
+ public void testList() {
+ ConfigurationMetadata underTest = new ConfigurationMetadata("hier1/set1");
+ underTest.setList(true);
+ assertEquals("hier1/set1", underTest.getName());
+ assertFalse(underTest.isSingleton());
+ assertTrue(underTest.isList());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidName() {
+ new ConfigurationMetadata("$illegal name");
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/config/spi/metadata/PropertyMetadataTest.java b/src/test/java/org/apache/sling/config/spi/metadata/PropertyMetadataTest.java
new file mode 100644
index 0000000..60fab1b
--- /dev/null
+++ b/src/test/java/org/apache/sling/config/spi/metadata/PropertyMetadataTest.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.sling.config.spi.metadata;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class PropertyMetadataTest {
+
+ @Test
+ public void testValid() {
+ PropertyMetadata<String> underTest = new PropertyMetadata<String>("testParam", String.class);
+ assertEquals("testParam", underTest.getName());
+ assertEquals(String.class, underTest.getType());
+ assertNull(underTest.getDefaultValue());
+
+ underTest.getProperties().put("p1", "v1");
+ assertEquals("v1", underTest.getProperties().get("p1", String.class));
+
+ underTest.setDefaultValue("defValue");
+ assertEquals("defValue", underTest.getDefaultValue());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidName() {
+ new PropertyMetadata<String>("$illegal name", String.class);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidType() {
+ new PropertyMetadata<Object>("testParam", Object.class);
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.