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:19:07 UTC
[sling-org-apache-sling-caconfig-api] 21/24: SLING-6057
Context-Aware Config: Separate Maven Project for SPI
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 bf5306b71f9f1bd55edabec05701f76fbf4e0ae8
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Sep 19 16:18:18 2016 +0000
SLING-6057 Context-Aware Config: Separate Maven Project for SPI
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/contextaware-config/api@1761475 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 40 -------
.../ConfigurationResourceResolvingStrategy.java | 84 -------------
.../config/resource/spi/ContextPathStrategy.java | 46 --------
.../config/resource/spi/package-info.java | 23 ----
.../config/spi/ConfigurationMetadataProvider.java | 47 --------
.../spi/ConfigurationPersistenceException.java | 38 ------
.../spi/ConfigurationPersistenceStrategy.java | 67 -----------
.../config/spi/metadata/AbstractMetadata.java | 96 ---------------
.../config/spi/metadata/ConfigurationMetadata.java | 78 ------------
.../config/spi/metadata/PropertyMetadata.java | 131 ---------------------
.../config/spi/metadata/package-info.java | 23 ----
.../contextaware/config/spi/package-info.java | 23 ----
.../spi/metadata/ConfigurationMetadataTest.java | 53 ---------
.../config/spi/metadata/PropertyMetadataTest.java | 90 --------------
14 files changed, 839 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8f0f1a7..1cba2c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,45 +66,5 @@
<version>2.9.0</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.3.2</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
- <version>2.1.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.sling-mock</artifactId>
- <version>1.8.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.4.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>2.0.87-beta</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/apache/sling/contextaware/config/resource/spi/ConfigurationResourceResolvingStrategy.java b/src/main/java/org/apache/sling/contextaware/config/resource/spi/ConfigurationResourceResolvingStrategy.java
deleted file mode 100644
index 89ad4b8..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/resource/spi/ConfigurationResourceResolvingStrategy.java
+++ /dev/null
@@ -1,84 +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.sling.contextaware.config.resource.spi;
-
-import java.util.Collection;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-
-import org.apache.sling.api.resource.Resource;
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * Defines how and where the configuration resources are looked up.
- * This SPI allows application to define their own configuration storage and inheritance strategies.
- */
-@ConsumerType
-public interface ConfigurationResourceResolvingStrategy {
-
- /**
- * Get a context-aware singleton configuration resource defined by the given configuration name.
- * @param resource Context resource to fetch configuration for
- * @param bucketName Configuration "bucket" name. Each high-level configuration resolver should store
- * it's configuration data grouped in a child resource of the configuration resource. This is what
- * we call a "bucket", and the resource name is specified with this parameter.
- * @param configName Configuration name or relative path.
- * @return Configuration resource or {@code null}.
- */
- @CheckForNull Resource getResource(@Nonnull Resource resource, @Nonnull String bucketName, @Nonnull String configName);
-
- /**
- * Get a collection of context-aware configuration resources defined by the given configuration name.
- * @param resource Context resource to fetch configuration for
- * @param bucketName Configuration "bucket" name. Each high-level configuration resolver should store
- * it's configuration data grouped in a child resource of the configuration resource. This is what
- * we call a "bucket", and the resource name is specified with this parameter.
- * @param configName Configuration name or relative path.
- * @return Collection of configuration resources, the collection might be empty.
- */
- @Nonnull Collection<Resource> getResourceCollection(@Nonnull Resource resource, @Nonnull String bucketName, @Nonnull String configName);
-
- /**
- * Get the configuration resource path for storing configuration data for the given context resource and configuration name.
- * This path is used when no configuration resource exists yet, but new configuration data should be stored.
- * So usually the returned path does not yet exist (and perhaps not even it's parents).
- * @param resource Context resource to fetch configuration for
- * @param bucketName Configuration "bucket" name. Each high-level configuration resolver should store
- * it's configuration data grouped in a child resource of the configuration resource. This is what
- * we call a "bucket", and the resource name is specified with this parameter.
- * @param configName Configuration name or relative path.
- * @return Resource path, or null if no matching configuration resource path can be determined
- */
- @CheckForNull String getResourcePath(@Nonnull Resource resource, @Nonnull String bucketName, @Nonnull String configName);
-
- /**
- * Get the configuration resource collection parent path for storing configuration data for the given context resource and configuration name.
- * This path is used when no configuration resource collection exists yet, but new configuration data should be stored.
- * So usually the returned path does not yet exist (and perhaps not even it's parents).
- * @param resource Context resource to fetch configuration for
- * @param bucketName Configuration "bucket" name. Each high-level configuration resolver should store
- * it's configuration data grouped in a child resource of the configuration resource. This is what
- * we call a "bucket", and the resource name is specified with this parameter.
- * @param configName Configuration name or relative path.
- * @return Resource path, or null if no matching configuration resource path can be determined
- */
- @CheckForNull String getResourceCollectionParentPath(@Nonnull Resource resource, @Nonnull String bucketName, @Nonnull String configName);
-
-}
diff --git a/src/main/java/org/apache/sling/contextaware/config/resource/spi/ContextPathStrategy.java b/src/main/java/org/apache/sling/contextaware/config/resource/spi/ContextPathStrategy.java
deleted file mode 100644
index 4b93957..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/resource/spi/ContextPathStrategy.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.contextaware.config.resource.spi;
-
-import java.util.Iterator;
-
-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.
- * A context paths is the root path of a "configuration context", which is a subtree in the resource hierarchy.
- * Each context may have it's own context-aware configuration attached to.0
- * If multiple context path strategy implementations are defined the results of them are merged.
- */
-@ConsumerType
-public interface ContextPathStrategy {
-
- /**
- * Finds context paths for the given resource.
- * @param resource Context resource
- * @return Root resource for each context found (in order of closest matching first).
- * Only one of the parent resources or the resource itself may be included in the result.
- * If none are found an empty list is returned.
- */
- @Nonnull Iterator<Resource> findContextResources(@Nonnull Resource resource);
-
-}
diff --git a/src/main/java/org/apache/sling/contextaware/config/resource/spi/package-info.java b/src/main/java/org/apache/sling/contextaware/config/resource/spi/package-info.java
deleted file mode 100644
index a7722f2..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/resource/spi/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-/**
- * SPI for applications hooking into the configuration resource infrastructure for parameterizing and customizing.
- */
-@org.osgi.annotation.versioning.Version("1.0.0")
-package org.apache.sling.contextaware.config.resource.spi;
diff --git a/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationMetadataProvider.java b/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationMetadataProvider.java
deleted file mode 100644
index 92ac552..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationMetadataProvider.java
+++ /dev/null
@@ -1,47 +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.sling.contextaware.config.spi;
-
-import java.util.SortedSet;
-
-import javax.annotation.Nonnull;
-
-import org.apache.sling.contextaware.config.spi.metadata.ConfigurationMetadata;
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * Allows application to provide the necessary metadata for configurations.
- */
-@ConsumerType
-public interface ConfigurationMetadataProvider {
-
- /**
- * Get all configuration names.
- * @return Configuration names
- */
- @Nonnull SortedSet<String> getConfigurationNames();
-
- /**
- * Get configuration metadata.
- * @param configName Configuration name
- * @return Configuration metadata or null if none exists for the given name.
- */
- ConfigurationMetadata getConfigurationMetadata(String configName);
-
-}
diff --git a/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationPersistenceException.java b/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationPersistenceException.java
deleted file mode 100644
index 618357d..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationPersistenceException.java
+++ /dev/null
@@ -1,38 +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.sling.contextaware.config.spi;
-
-import org.osgi.annotation.versioning.ProviderType;
-
-/**
- * Is thrown when configuration cannot be persisted.
- */
-@ProviderType
-public final class ConfigurationPersistenceException extends RuntimeException {
- private static final long serialVersionUID = 1L;
-
- public ConfigurationPersistenceException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ConfigurationPersistenceException(String message) {
- super(message);
- }
-
-}
diff --git a/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationPersistenceStrategy.java b/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationPersistenceStrategy.java
deleted file mode 100644
index 9dfe945..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/spi/ConfigurationPersistenceStrategy.java
+++ /dev/null
@@ -1,67 +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.sling.contextaware.config.spi;
-
-import java.util.Collection;
-import java.util.Map;
-
-import javax.annotation.Nonnull;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * Defines how configuration data is stored in the configuration resource.
- * This SPI allows application to define their own content structure and node types to be used for configuration data storage.
- */
-@ConsumerType
-public interface ConfigurationPersistenceStrategy {
-
- /**
- * Allows the strategy to transform the given configuration resource according to it's persistent strategies,
- * e.g. fetching the data from a child resource instead of the given resource.
- * @param resource Configuration resource
- * @return Transformed configuration resource. If null is returned this strategy does not support the given configuration resource.
- */
- Resource getResource(@Nonnull Resource resource);
-
- /**
- * Stores configuration data for a singleton configuration resource.
- * The changes are written using the given resource resolver. They are not committed, this is left to the caller.
- * @param resourceResolver Resource resolver
- * @param configResourcePath Path to store configuration data to. The resource (and it's parents) may not exist and may have to be created.
- * @param properties Configuration properties
- * @return true if the data was persisted. false if persisting the data was not accepted by this persistence strategy (but in case of error throw an exception).
- */
- boolean persist(@Nonnull ResourceResolver resourceResolver,
- @Nonnull String configResourcePath, @Nonnull Map<String,Object> properties);
-
- /**
- * Stores configuration data for a configuration resource collection.
- * The changes are written using the given resource resolver. They are not committed, this is left to the caller.
- * @param resourceResolver Resource resolver
- * @param configResourceCollectionParentPath Parent path to store configuration collection data to. The resource (and it's parents) may not exist and may have to be created.
- * @param propertiesCollection Configuration properties
- * @return true if the data was persisted. false if persisting the data was not accepted by this persistence strategy (but in case of error throw an exception).
- */
- boolean persistCollection(@Nonnull ResourceResolver resourceResolver,
- @Nonnull String configResourceCollectionParentPath, @Nonnull Collection<Map<String,Object>> propertiesCollection);
-
-}
diff --git a/src/main/java/org/apache/sling/contextaware/config/spi/metadata/AbstractMetadata.java b/src/main/java/org/apache/sling/contextaware/config/spi/metadata/AbstractMetadata.java
deleted file mode 100644
index 2cd0d17..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/spi/metadata/AbstractMetadata.java
+++ /dev/null
@@ -1,96 +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.sling.contextaware.config.spi.metadata;
-
-import java.util.Map;
-
-import javax.annotation.Nonnull;
-
-/**
- * Common properties for configuration and properties.
- */
-abstract class AbstractMetadata {
-
- private final String name;
- private String label;
- private String description;
- private Map<String,String> properties;
-
- public AbstractMetadata(@Nonnull String name) {
- if (name == null) {
- throw new IllegalArgumentException("Invalid name: " + name);
- }
- this.name = name;
- }
-
- /**
- * @return Parameter name
- */
- public @Nonnull String getName() {
- return this.name;
- }
-
- /**
- * @return Label
- */
- public String getLabel() {
- return label;
- }
-
- /**
- * @param label Label
- */
- public void setLabel(String label) {
- this.label = label;
- }
-
- /**
- * @return Description
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * @param description Description
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
- /**
- * @return Further properties for documentation and configuration of behavior in configuration editor.
- */
- public Map<String,String> getProperties() {
- return this.properties;
- }
-
- /**
- * @param properties Further properties for documentation and configuration of behavior in configuration editor.
- */
- public void setProperties(Map<String,String> properties) {
- this.properties = properties;
- }
-
- @Override
- public String toString() {
- return this.name;
- }
-
-}
diff --git a/src/main/java/org/apache/sling/contextaware/config/spi/metadata/ConfigurationMetadata.java b/src/main/java/org/apache/sling/contextaware/config/spi/metadata/ConfigurationMetadata.java
deleted file mode 100644
index 7730157..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/spi/metadata/ConfigurationMetadata.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.contextaware.config.spi.metadata;
-
-import java.util.Map;
-
-import javax.annotation.Nonnull;
-
-import org.osgi.annotation.versioning.ProviderType;
-
-/**
- * Defines a configuration.
- */
-@ProviderType
-public final class ConfigurationMetadata extends AbstractMetadata {
-
- private boolean isList;
- private Map<String,PropertyMetadata<?>> propertyMetadata;
-
- /**
- * @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 properties
- */
- public Map<String,PropertyMetadata<?>> getPropertyMetadata() {
- return this.propertyMetadata;
- }
-
- /**
- * @param propertyMetadata Configuration properties
- */
- public void setPropertyMetadata(Map<String,PropertyMetadata<?>> propertyMetadata) {
- this.propertyMetadata = propertyMetadata;
- }
-
-}
diff --git a/src/main/java/org/apache/sling/contextaware/config/spi/metadata/PropertyMetadata.java b/src/main/java/org/apache/sling/contextaware/config/spi/metadata/PropertyMetadata.java
deleted file mode 100644
index 5e0da26..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/spi/metadata/PropertyMetadata.java
+++ /dev/null
@@ -1,131 +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.sling.contextaware.config.spi.metadata;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.annotation.Nonnull;
-
-import org.apache.commons.lang3.ClassUtils;
-import org.osgi.annotation.versioning.ProviderType;
-
-/**
- * Defines a configuration property.
- * @param <T> Property value type
- */
-@ProviderType
-public final class PropertyMetadata<T> extends AbstractMetadata {
-
- // these are all types supported for fields of annotation classes (plus class which indicates nested configurations)
- private static final Class<?>[] SUPPORTED_TYPES_ARRAY = {
- String.class,
- int.class,
- long.class,
- double.class,
- boolean.class
- };
-
- /**
- * Set with all types support for property metadata (not including nested configurations).
- */
- public static final Set<Class<?>> SUPPORTED_TYPES = Collections.unmodifiableSet(
- new HashSet<>(Arrays.asList(SUPPORTED_TYPES_ARRAY)));
-
- private final Class<T> type;
- private T defaultValue;
-
- /**
- * @param name Property name
- * @param type Property type
- */
- @SuppressWarnings("unchecked")
- public PropertyMetadata(@Nonnull String name, @Nonnull Class<T> type) {
- super(name);
- Class<T> convertedType = (Class<T>)typeToPrimitive(type);
- if (!isSupportedType(convertedType)) {
- throw new IllegalArgumentException("Invalid type for property '" + name + "': " + type);
- }
- this.type = convertedType;
- }
-
- /**
- * @param name Property name
- * @param defaultValue Default value (also defines property type)
- */
- @SuppressWarnings("unchecked")
- public PropertyMetadata(@Nonnull String name, @Nonnull T defaultValue) {
- this(name, (Class<T>)defaultValue.getClass());
- this.defaultValue = defaultValue;
- }
-
- private static Class<?> typeToPrimitive(Class<?> clazz) {
- if (clazz != String.class && !clazz.isPrimitive()) {
- Class<?> type = ClassUtils.wrapperToPrimitive(clazz);
- if (type != null) {
- return type;
- }
- }
- return clazz;
- }
-
- private static boolean isSupportedType(Class<?> paramType) {
- if (paramType.isArray()) {
- return isSupportedType(paramType.getComponentType());
- }
- for (Class<?> type : SUPPORTED_TYPES) {
- if (type.equals(paramType)) {
- return true;
- }
- }
- if (paramType == ConfigurationMetadata.class) {
- 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/contextaware/config/spi/metadata/package-info.java b/src/main/java/org/apache/sling/contextaware/config/spi/metadata/package-info.java
deleted file mode 100644
index 0372745..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/spi/metadata/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-/**
- * Defining configuration and parameter metadata for the SPI.
- */
-@org.osgi.annotation.versioning.Version("1.0.0")
-package org.apache.sling.contextaware.config.spi.metadata;
diff --git a/src/main/java/org/apache/sling/contextaware/config/spi/package-info.java b/src/main/java/org/apache/sling/contextaware/config/spi/package-info.java
deleted file mode 100644
index 76033c3..0000000
--- a/src/main/java/org/apache/sling/contextaware/config/spi/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-/**
- * SPI for applications hooking into the configuration infrastructure for parameterizing and customizing.
- */
-@org.osgi.annotation.versioning.Version("1.0.0")
-package org.apache.sling.contextaware.config.spi;
diff --git a/src/test/java/org/apache/sling/contextaware/config/spi/metadata/ConfigurationMetadataTest.java b/src/test/java/org/apache/sling/contextaware/config/spi/metadata/ConfigurationMetadataTest.java
deleted file mode 100644
index b5cf061..0000000
--- a/src/test/java/org/apache/sling/contextaware/config/spi/metadata/ConfigurationMetadataTest.java
+++ /dev/null
@@ -1,53 +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.sling.contextaware.config.spi.metadata;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-
-public class ConfigurationMetadataTest {
-
- @Test
- public void testProps() {
- ConfigurationMetadata underTest = new ConfigurationMetadata("name1");
- assertEquals("name1", underTest.getName());
- assertTrue(underTest.isSingleton());
- assertFalse(underTest.isList());
-
- underTest.setLabel("label1");
- underTest.setDescription("desc1");
- underTest.setList(true);
- Map<String,String> props = ImmutableMap.of("p1", "v1");
- underTest.setProperties(props);
-
- assertEquals("label1", underTest.getLabel());
- assertEquals("desc1", underTest.getDescription());
- assertFalse(underTest.isSingleton());
- assertTrue(underTest.isList());
- assertEquals(props, underTest.getProperties());
- }
-
-}
diff --git a/src/test/java/org/apache/sling/contextaware/config/spi/metadata/PropertyMetadataTest.java b/src/test/java/org/apache/sling/contextaware/config/spi/metadata/PropertyMetadataTest.java
deleted file mode 100644
index 1427192..0000000
--- a/src/test/java/org/apache/sling/contextaware/config/spi/metadata/PropertyMetadataTest.java
+++ /dev/null
@@ -1,90 +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.sling.contextaware.config.spi.metadata;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Map;
-
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-
-public class PropertyMetadataTest {
-
- @Test
- public void testProps() {
- PropertyMetadata<String> underTest = new PropertyMetadata<>("name1", String.class);
- assertEquals("name1", underTest.getName());
- assertEquals(String.class, underTest.getType());
-
- underTest.setLabel("label1");
- underTest.setDescription("desc1");
- underTest.setDefaultValue("value1");
- Map<String,String> props = ImmutableMap.of("p1", "v1");
- underTest.setProperties(props);
-
- assertEquals("label1", underTest.getLabel());
- assertEquals("desc1", underTest.getDescription());
- assertEquals("value1", underTest.getDefaultValue());
- assertEquals(props, underTest.getProperties());
- }
-
- @Test
- public void testAllowedTypes() {
- new PropertyMetadata<>("name1", String.class);
- new PropertyMetadata<>("name1", String[].class);
- new PropertyMetadata<>("name1", int.class);
- new PropertyMetadata<>("name1", int[].class);
- new PropertyMetadata<>("name1", long.class);
- new PropertyMetadata<>("name1", long[].class);
- new PropertyMetadata<>("name1", double.class);
- new PropertyMetadata<>("name1", double[].class);
- new PropertyMetadata<>("name1", boolean.class);
- new PropertyMetadata<>("name1", boolean[].class);
- }
-
- @Test
- public void testNestedConfiguration() {
- new PropertyMetadata<>("name1", ConfigurationMetadata.class);
- new PropertyMetadata<>("name1", ConfigurationMetadata[].class);
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void testDisallowedType() {
- new PropertyMetadata<>("name1", Object.class);
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void testNullNale() {
- new PropertyMetadata<>(null, Object.class);
- }
-
- @Test
- public void testDefaultValueConstructor() {
- PropertyMetadata<String> stringProp = new PropertyMetadata<>("name1", "defValue");
- assertEquals("defValue", stringProp.getDefaultValue());
- assertEquals(String.class, stringProp.getType());
-
- PropertyMetadata<Integer> intProp = new PropertyMetadata<>("name1", 5);
- assertEquals((Integer)5, intProp.getDefaultValue());
- assertEquals(int.class, intProp.getType());
- }
-
-}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.