Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * 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.
 */
 package org.hibernate.validator.resourceloading;
 
 import java.util.List;
 import java.util.Map;
 
A org.hibernate.validator.spi.resourceloading.ResourceBundleLocator implementation that provides access to multiple source java.util.ResourceBundles by merging them into one aggregated bundle.

Author(s):
Gunnar Morling
 
 	private final List<StringbundleNames;

Creates a locator that delivers a resource bundle merged from the given list of source bundles.

Deprecated:
Will be removed in a future release. Use AggregateResourceBundleLocator(java.util.List,org.hibernate.validator.spi.resourceloading.ResourceBundleLocator) instead.
Parameters:
bundleNames A list with source bundle names. The returned bundle will contain all keys from all source bundles. In case a key occurs in multiple source bundles, the value will be taken from the first bundle containing the key.
delegate A delegate resource bundle locator. The bundle returned by this locator will be added to the aggregate bundle after all source bundles.
 
 		thisbundleNamesnew Adapterdelegate ) );
 	}

Creates a locator that delivers a resource bundle merged from the given list of source bundles.

Parameters:
bundleNames A list with source bundle names. The returned bundle will contain all entries from all source bundles. In case a key occurs in multiple source bundles, the value will be taken from the first bundle containing the key.
 
 	public AggregateResourceBundleLocator(List<StringbundleNames) {
 		thisbundleNames, (ResourceBundleLocatornull );
 	}

Creates a locator that delivers a resource bundle merged from the given list of source bundles.

Parameters:
bundleNames A list with source bundle names. The returned bundle will contain all keys from all source bundles. In case a key occurs in multiple source bundles, the value will be taken from the first bundle containing the key.
delegate A delegate resource bundle locator. The bundle returned by this locator will be added to the aggregate bundle after all source bundles.
 
 	public AggregateResourceBundleLocator(List<StringbundleNamesResourceBundleLocator delegate) {
 		superdelegate );
 
 		Contracts.assertValueNotNullbundleNames"bundleNames" );
 
 		List<StringtmpBundleNames = new ArrayList<String>();
 		tmpBundleNames.addAllbundleNames );
 
 		this. = Collections.unmodifiableListtmpBundleNames );
 	}
 
 	public ResourceBundle getResourceBundle(Locale locale) {
		List<ResourceBundlesourceBundles = new ArrayList<ResourceBundle>();
		for ( String oneBundleName :  ) {
			ResourceBundleLocator oneLocator =
					new PlatformResourceBundleLocatoroneBundleName );
			ResourceBundle oneBundle = oneLocator.getResourceBundlelocale );
			if ( oneBundle != null ) {
				sourceBundles.addoneBundle );
			}
		}
		ResourceBundle bundleFromDelegate = super.getResourceBundlelocale );
		if ( bundleFromDelegate != null ) {
			sourceBundles.addbundleFromDelegate );
		}
		return sourceBundles.isEmpty() ? null : new AggregateBundlesourceBundles );
	}

A java.util.ResourceBundle whose content is aggregated from multiple source bundles.

This class is package-private for the sake of testability.

Author(s):
Gunnar Morling
	public static class AggregateBundle extends ResourceBundle {
		private Map<StringObjectcontents = new HashMap<StringObject>();

Creates a new AggregateBundle.

Parameters:
bundles A list of source bundles, which shall be merged into one aggregated bundle. The newly created bundle will contain all keys from all source bundles. In case a key occurs in multiple source bundles, the value will be taken from the first bundle containing the key.
		public AggregateBundle(List<ResourceBundlebundles) {
			if ( bundles != null ) {
				for ( ResourceBundle bundle : bundles ) {
					Enumeration<Stringkeys = bundle.getKeys();
					while ( keys.hasMoreElements() ) {
						String oneKey = keys.nextElement();
						if ( !.containsKeyoneKey ) ) {
							.putoneKeybundle.getObjectoneKey ) );
						}
					}
				}
			}
		}
		public Enumeration<StringgetKeys() {
		}
		protected Object handleGetObject(String key) {
			return .getkey );
		}
	}

An java.util.Enumeration implementation, that wraps an java.util.Iterator. Can be used to integrate older APIs working with enumerations with iterators.

Parameters:
<T> The enumerated type.
Author(s):
Gunnar Morling
	private static class IteratorEnumeration<T> implements Enumeration<T> {
		private Iterator<T> source;

Creates a new IterationEnumeration.

Parameters:
source The source iterator. Must not be null.
		public IteratorEnumeration(Iterator<T> source) {
			if ( source == null ) {
				throw new IllegalArgumentException"Source must not be null" );
			}
			this. = source;
		}
		public boolean hasMoreElements() {
			return .hasNext();
		}
		public T nextElement() {
			return .next();
		}
	}
	@SuppressWarnings("deprecation")
	private static class Adapter implements org.hibernate.validator.spi.resourceloading.ResourceBundleLocator {
			this. = adaptee;
		}
			return .getResourceBundlelocale );
		}
	}
New to GrepCode? Check out our FAQ X