Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3386 Move the responsibility of passing the BeanReference dat…
…a (name, class, ...) to the BeanReference itself
- Loading branch information
Showing
10 changed files
with
175 additions
and
118 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
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
52 changes: 0 additions & 52 deletions
52
...ne/src/main/java/org/hibernate/search/engine/environment/bean/ImmutableBeanReference.java
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
engine/src/main/java/org/hibernate/search/engine/environment/bean/NameBeanReference.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,37 @@ | ||
/* | ||
* 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; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
import org.hibernate.search.engine.logging.impl.Log; | ||
import org.hibernate.search.util.impl.common.LoggerFactory; | ||
import org.hibernate.search.util.impl.common.StringHelper; | ||
|
||
final class NameBeanReference implements BeanReference { | ||
|
||
private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); | ||
|
||
private final String name; | ||
|
||
NameBeanReference(String name) { | ||
if ( StringHelper.isEmpty( name ) ) { | ||
throw log.invalidBeanReferenceNameNullOrEmpty(); | ||
} | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "[name=" + name + "]"; | ||
} | ||
|
||
@Override | ||
public <T> T getBean(BeanProvider beanProvider, Class<T> expectedType) { | ||
return beanProvider.getBean( expectedType, name ); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
.../src/main/java/org/hibernate/search/engine/environment/bean/TypeAndNameBeanReference.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,55 @@ | ||
/* | ||
* 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; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
import org.hibernate.search.engine.logging.impl.Log; | ||
import org.hibernate.search.util.impl.common.LoggerFactory; | ||
import org.hibernate.search.util.impl.common.StringHelper; | ||
|
||
final class TypeAndNameBeanReference implements BeanReference { | ||
|
||
private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); | ||
|
||
static BeanReference createLenient(Class<?> type, String name) { | ||
boolean nameProvided = StringHelper.isNotEmpty( name ); | ||
boolean typeProvided = type != null; | ||
|
||
if ( nameProvided && typeProvided ) { | ||
return new TypeAndNameBeanReference( type, name ); | ||
} | ||
else if ( nameProvided ) { | ||
return new NameBeanReference( name ); | ||
} | ||
else if ( typeProvided ) { | ||
return new TypeBeanReference( type ); | ||
} | ||
else { | ||
throw log.invalidBeanReferenceTypeIsNullAndNameNullOrEmpty(); | ||
} | ||
} | ||
|
||
private final Class<?> type; | ||
private final String name; | ||
|
||
private TypeAndNameBeanReference(Class<?> type, String name) { | ||
this.type = type; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "[type=" + type + ", name=" + name + "]"; | ||
} | ||
|
||
@Override | ||
public <T> T getBean(BeanProvider beanProvider, Class<T> expectedType) { | ||
return beanProvider.getBean( expectedType, type, name ); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
engine/src/main/java/org/hibernate/search/engine/environment/bean/TypeBeanReference.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,37 @@ | ||
/* | ||
* 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; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
import org.hibernate.search.engine.logging.impl.Log; | ||
import org.hibernate.search.util.impl.common.LoggerFactory; | ||
|
||
final class TypeBeanReference implements BeanReference { | ||
|
||
private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); | ||
|
||
private final Class<?> type; | ||
|
||
TypeBeanReference(Class<?> type) { | ||
if ( type == null ) { | ||
throw log.invalidBeanReferenceNameNullOrEmpty(); | ||
} | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "[type=" + type + "]"; | ||
} | ||
|
||
@Override | ||
public <T> T getBean(BeanProvider beanProvider, Class<T> expectedType) { | ||
return beanProvider.getBean( expectedType, type ); | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.