blob: 802df68568c3be8ae07dbeba5e5c0cfbf755f446 [file] [log] [blame]
// Copyright 2008 The Apache Software Foundation
//
// 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.apache.tapestry.internal.structure;
import org.apache.tapestry.internal.services.ComponentClassCache;
import org.apache.tapestry.ioc.internal.util.CollectionFactory;
import org.apache.tapestry.ioc.internal.util.Defense;
import org.apache.tapestry.ioc.services.TypeCoercer;
import org.apache.tapestry.services.ContextValueEncoder;
import org.apache.tapestry5.services.ComponentMessagesSource;
import java.util.Locale;
import java.util.Map;
public class PageResourcesSourceImpl implements PageResourcesSource
{
private final Map<Locale, PageResources> cache = CollectionFactory.newConcurrentMap();
private final ComponentMessagesSource componentMessagesSource;
private final TypeCoercer typeCoercer;
private final ComponentClassCache componentClassCache;
private final ContextValueEncoder contextValueEncoder;
public PageResourcesSourceImpl(ComponentMessagesSource componentMessagesSource, TypeCoercer typeCoercer,
ComponentClassCache componentClassCache, ContextValueEncoder contextValueEncoder)
{
this.componentMessagesSource = componentMessagesSource;
this.typeCoercer = typeCoercer;
this.componentClassCache = componentClassCache;
this.contextValueEncoder = contextValueEncoder;
}
public PageResources get(Locale locale)
{
Defense.notNull(locale, "locale");
PageResources result = cache.get(locale);
if (result == null)
{
result = new PageResourcesImpl(locale, componentMessagesSource, typeCoercer, componentClassCache,
contextValueEncoder);
// Small race condition here, where we may create two instances of PRI for the same locale,
// but that's not worth worrying about.
cache.put(locale, result);
}
return result;
}
}