Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1596 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
9 changed files with 104 additions and 7 deletions
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2004-2009 the original author or authors. |
||||
* |
||||
* 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.springframework.ui.binding; |
||||
|
||||
/** |
||||
* A locator for BindingFactories indexed by their models. |
||||
* Makes it easy for clients to lookup BindingFactories for models the need to bind to. |
||||
* @author Keith Donald |
||||
*/ |
||||
public interface BindingFactoryLocator { |
||||
|
||||
/** |
||||
* Get the BindingFactory for the model object. |
||||
* If no such BindingFactory exists, one is created and cached. |
||||
* Never returns <code>null</code>. |
||||
* @param model the model object |
||||
* @return the binding Factory |
||||
*/ |
||||
public BindingFactory getBindingFactory(Object model); |
||||
} |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* Copyright 2004-2009 the original author or authors. |
||||
* |
||||
* 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.springframework.ui.binding.support; |
||||
|
||||
import java.util.IdentityHashMap; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.ui.binding.BindingFactory; |
||||
import org.springframework.ui.binding.BindingFactoryLocator; |
||||
|
||||
/** |
||||
* BindingFactoryLocator implementation that uses a {@link IdentityHashMap} to map models to BindingFactories. |
||||
* @author Keith Donald |
||||
*/ |
||||
public class GenericBindingFactoryLocator implements BindingFactoryLocator { |
||||
|
||||
private Map<Object, BindingFactory> bindingFactories = new IdentityHashMap<Object, BindingFactory>(); |
||||
|
||||
public void put(BindingFactory bindingFactory) { |
||||
bindingFactories.put(bindingFactory.getModel(), bindingFactory); |
||||
} |
||||
|
||||
public BindingFactory getBindingFactory(Object model) { |
||||
BindingFactory factory = bindingFactories.get(model); |
||||
if (factory == null) { |
||||
factory = new GenericBindingFactory(model); |
||||
bindingFactories.put(model, factory); |
||||
} |
||||
return factory; |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue