Class<?> appliedOnType) {
assert bridgeAnn != null : "@FieldBridge instance cannot be null";
FieldBridge bridge;
Class impl = bridgeAnn.impl();
if ( impl == void.class ) {
throw new SearchException( "@FieldBridge with no implementation class defined in: " + appliedOnName );
}
try {
Object instance = impl.newInstance();
if ( FieldBridge.class.isAssignableFrom( impl ) ) {
bridge = (FieldBridge) instance;
}
else if ( TwoWayStringBridge.class.isAssignableFrom( impl ) ) {
bridge = new TwoWayString2FieldBridgeAdaptor(
(TwoWayStringBridge) instance
);
}
else if ( org.hibernate.search.bridge.StringBridge.class.isAssignableFrom( impl ) ) {
bridge = new String2FieldBridgeAdaptor( (org.hibernate.search.bridge.StringBridge) instance );
}
else {
throw new SearchException(
"@FieldBridge implementation implements none of the field bridge interfaces: "
+ impl + " in " + appliedOnName
);
}
if ( bridgeAnn.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( impl ) ) {
Map<String, String> params = new HashMap<String, String>( bridgeAnn.params().length );
for ( Parameter param : bridgeAnn.params() ) {
params.put( param.name(), param.value() );
}
( (ParameterizedBridge) instance ).setParameterValues( params );
}
populateReturnType( appliedOnType, impl, instance );
}
catch ( Exception e ) {
//TODO add classname
throw new SearchException( "Unable to instantiate FieldBridge for " + appliedOnName, e );
}
return bridge;
}