Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3101 Add a way to define named beans from integrations (backe…
…nds, ...)
- Loading branch information
Showing
9 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../java/org/hibernate/search/engine/environment/bean/impl/BeanConfigurationContextImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.environment.bean.impl; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.hibernate.search.engine.environment.bean.spi.BeanConfigurationContext; | ||
import org.hibernate.search.engine.environment.bean.spi.BeanFactory; | ||
import org.hibernate.search.util.impl.common.Contracts; | ||
|
||
final class BeanConfigurationContextImpl implements BeanConfigurationContext { | ||
|
||
private Map<ConfiguredBeanKey<?>, BeanFactory<?>> explicitlyConfiguredBeans = new HashMap<>(); | ||
|
||
@Override | ||
public <T> void define(Class<T> exposedType, String name, BeanFactory<T> factory) { | ||
Contracts.assertNotNull( exposedType, "exposedType" ); | ||
Contracts.assertNotNull( name, "name" ); | ||
Contracts.assertNotNull( factory, "factory" ); | ||
explicitlyConfiguredBeans.put( new ConfiguredBeanKey<>( exposedType, name ), factory ); | ||
} | ||
|
||
Map<ConfiguredBeanKey<?>, BeanFactory<?>> getConfiguredBeans() { | ||
return Collections.unmodifiableMap( explicitlyConfiguredBeans ); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/org/hibernate/search/engine/environment/bean/impl/BeanCreationContextImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.environment.bean.impl; | ||
|
||
import org.hibernate.search.engine.environment.bean.BeanProvider; | ||
import org.hibernate.search.engine.environment.bean.spi.BeanCreationContext; | ||
|
||
final class BeanCreationContextImpl implements BeanCreationContext { | ||
private final BeanProvider beanProvider; | ||
|
||
BeanCreationContextImpl(BeanProvider beanProvider) { | ||
this.beanProvider = beanProvider; | ||
} | ||
|
||
@Override | ||
public BeanProvider getBeanProvider() { | ||
return beanProvider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ne/src/main/java/org/hibernate/search/engine/environment/bean/impl/ConfiguredBeanKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.environment.bean.impl; | ||
|
||
import java.util.Objects; | ||
|
||
final class ConfiguredBeanKey<T> { | ||
private final Class<T> exposedType; | ||
private final String name; | ||
|
||
ConfiguredBeanKey(Class<T> exposedType, String name) { | ||
this.exposedType = exposedType; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if ( obj == null || getClass() != obj.getClass() ) { | ||
return false; | ||
} | ||
ConfiguredBeanKey<?> other = (ConfiguredBeanKey<?>) obj; | ||
return Objects.equals( exposedType, other.exposedType ) | ||
&& Objects.equals( name, other.name ); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash( exposedType, name ); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../main/java/org/hibernate/search/engine/environment/bean/spi/BeanConfigurationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.environment.bean.spi; | ||
|
||
public interface BeanConfigurationContext { | ||
|
||
<T> void define(Class<T> exposedType, String name, BeanFactory<T> factory); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
engine/src/main/java/org/hibernate/search/engine/environment/bean/spi/BeanConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.environment.bean.spi; | ||
|
||
public interface BeanConfigurer { | ||
|
||
/** | ||
* Configure beans as necessary using the given {@code context}. | ||
* @param context A context exposing methods to configure beans. | ||
*/ | ||
void configure(BeanConfigurationContext context); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...e/src/main/java/org/hibernate/search/engine/environment/bean/spi/BeanCreationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.environment.bean.spi; | ||
|
||
import org.hibernate.search.engine.environment.bean.BeanProvider; | ||
|
||
public interface BeanCreationContext { | ||
|
||
BeanProvider getBeanProvider(); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
engine/src/main/java/org/hibernate/search/engine/environment/bean/spi/BeanFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.environment.bean.spi; | ||
|
||
public interface BeanFactory<T> { | ||
|
||
T create(BeanCreationContext context); | ||
|
||
} |