/*
 * #%L
 * Gravia :: Runtime :: API
 * %%
 * Copyright (C) 2013 - 2014 JBoss by Red Hat
 * %%
 * Licensed 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.
 * #L%
 */
package org.jboss.gravia.runtime.spi;

/**
 * A Composite {@link org.jboss.gravia.runtime.spi.PropertiesProvider}.
 */
public class CompositePropertiesProvider extends AbstractPropertiesProvider {

	private final PropertiesProvider[] delegates;

	public CompositePropertiesProvider(PropertiesProvider... delegates) {
		this.delegates = delegates;
	}

	@Override
	public Object getProperty(String key, Object defaultValue) {
		Object result = null;
		for (PropertiesProvider delegate : delegates) {
			result = delegate.getProperty(key);
			if (result != null) {
				return result;
			}
		}
		return defaultValue;
	}

    PropertiesProvider[] getDelegates() {
        return delegates;
    }
}

@@ -699,63 +699,170 @@
 i;%0A%0A
-/**%0A * A Composite %7B@link org.jboss.gravia.runtime.spi.
+import java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport org.jboss.gravia.utils.IllegalArgumentAssertion;%0A%0A/**%0A * A Composite %7B@link 
 Prop
@@ -976,16 +976,21 @@
 e final 
+List%3C
 Properti
@@ -999,18 +999,17 @@
 Provider
-%5B%5D
+%3E
  delegat
@@ -1084,16 +1084,82 @@
 ates) %7B%0A
+%09%09IllegalArgumentAssertion.assertNotNull(delegates, %22delegates%22);%0A
 %09%09this.d
@@ -1169,16 +1169,30 @@
 gates = 
+Arrays.asList(
 delegate
@@ -1192,16 +1192,17 @@
 elegates
+)
 ;%0A%09%7D%0A%0A%09@
@@ -1469,16 +1469,21 @@
 %09%7D%0A%0A    
+List%3C
 Properti
@@ -1496,10 +1496,9 @@
 ider
-%5B%5D
+%3E
  get
@@ -1526,16 +1526,45 @@
  return 
+Collections.unmodifiableList(
 delegate
@@ -1564,16 +1564,17 @@
 elegates
+)
 ;%0A    %7D%0A

Fix ownership of delegates in CompositePropertiesProvider