/** * This extracts and instantiates the implementation class from a {@code ClassBridge} annotation. * * @param cb the class bridge annotation * @param clazz the {@code Class} on which the annotation is defined on * @return Returns the specified {@code FieldBridge} instance */ public FieldBridge extractType(ClassBridge cb, Class<?> clazz) { FieldBridge bridge = null; Class<?> bridgeType = null; if (cb != null) { bridgeType = cb.impl(); if (bridgeType != null) { try { Object instance = bridgeType.newInstance(); if (FieldBridge.class.isAssignableFrom(bridgeType)) { bridge = (FieldBridge) instance; } else if (org.hibernate.search.bridge.TwoWayStringBridge.class.isAssignableFrom( bridgeType)) { bridge = new TwoWayString2FieldBridgeAdaptor( (org.hibernate.search.bridge.TwoWayStringBridge) instance); } else if (org.hibernate.search.bridge.StringBridge.class.isAssignableFrom(bridgeType)) { bridge = new String2FieldBridgeAdaptor((org.hibernate.search.bridge.StringBridge) instance); } else { throw LOG.noFieldBridgeInterfaceImplementedByClassBridge(bridgeType.getName()); } } catch (Exception e) { throw LOG.cannotInstantiateClassBridgeOfType(bridgeType.getName(), clazz.getName(), e); } } } if (bridge == null) { throw LOG.unableToDetermineClassBridge(ClassBridge.class.getName()); } populateReturnType(clazz, bridgeType, bridge); return bridge; }
/** * This extracts and instantiates the implementation class from a ClassBridge annotation. * * @param fieldBridgeAnnotation the FieldBridge annotation * @param appliedOnType the type the bridge is applied on * @param reflectionManager The reflection manager instance * @return FieldBridge */ private FieldBridge extractType( org.hibernate.search.annotations.FieldBridge fieldBridgeAnnotation, XClass appliedOnType, ReflectionManager reflectionManager) { FieldBridge bridge = null; if (fieldBridgeAnnotation != null) { bridge = doExtractType( fieldBridgeAnnotation, appliedOnType.getName(), reflectionManager.toClass(appliedOnType)); } if (bridge == null) { throw LOG.unableToDetermineClassBridge(appliedOnType.getName()); } return bridge; }