/* (non-Javadoc)
@see nz.co.senanque.rules.RuleSession#bind(nz.co.senanque.validationengine.ValidationObject, nz.co.senanque.validationengine.ProxyField, nz.co.senanque.rules.FieldReference, nz.co.senanque.validationengine.ValidationObject)
543839
public void unbind(final ValidationObject validationObject, final ProxyField proxyField, final FieldReference fieldReference, final ValidationObject owner)
    {
        final RuleProxyField ruleProxyField = getRuleProxyField(proxyField);
        for (Rule rule: fieldReference.getListeners())
        {
            RuleContext ruleContext;
			try {
				ruleContext = getRuleContext(rule,validationObject,(owner==null)?validationObject:owner);
			} catch (FailsToMatchException e) {
				continue;
			}
            ruleProxyField.removeInputRule(ruleContext);
        }
        removeRuleProxyField(proxyField);
    }
796947
@Override
    public /*final*/ void bind(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) {

        // bind only address with matching scheme
        URI location = address.getResource();
        String schemeName = location.getScheme();
        if (!canBind(schemeName)) {
            throw new IllegalArgumentException(format("Unexpected scheme \"%s\" for URI: %s", schemeName, location));
        }
        
        if (!started.get()) {
            synchronized (started) {
                if (!started.get()) {
                    init();
                    started.set(true);
                }
            }
        }

        boolean bindAlternate;
        do {
            bindAlternate = address.getOption(BIND_ALTERNATE);
            //
            // add binding, expecting no clashing (according to BINDINGS_COMPARATOR)
            //
            Binding newBinding = new Binding(address, handler, initializer);
            Binding oldBinding = bindings.addBinding(newBinding);

            //System.out.println(getClass().getSimpleName()+"@"+hashCode()+" binding: "+address.getExternalURI()+" -- "+address.getOption(NEXT_PROTOCOL));

            if (oldBinding != null) {
                throw new RuntimeException("Unable to bind address " + address
                        + " because it collides with an already bound address " + oldBinding.bindAddress());
            }

            bindInternal(address, handler, initializer);
            address = address.getOption(ALTERNATE);
            
        } while (address != null && bindAlternate);
    }
912509
public void bind() throws Throwable
   {
      if (name == null)
         throw new IllegalArgumentException("Name is null");

      if (obj == null)
         throw new IllegalArgumentException("Obj is null");

      if (trace)
         log.trace("Binding " + obj.getClass().getName() + " under " + name);

      Properties properties = new Properties();
      properties.setProperty(Context.PROVIDER_URL, jndiProtocol + "://" + jndiHost + ":" + jndiPort);
      Context context = new InitialContext(properties);

      try
      {
         String className = obj.getClass().getName();
         Reference ref = new Reference(className,
                                       new StringRefAddr("class", className),
                                       JndiBinder.class.getName(),
                                       null);
         ref.add(new StringRefAddr("name", name));

         objs.put(name, obj);

         Util.bind(context, name, ref);

         if (log.isDebugEnabled())
            log.debug("Bound " + obj.getClass().getName() + " under " + name);
      }
      finally
      {
         if (context != null)
         {
            try
            {
               context.close();
            }
            catch (NamingException ne)
            {
               // Ignore
            }
         }
      }
   }
976185
public void unbind(ValidationSession session, ValidationObject validationObject,
			Map<ValidationObject, ProxyObject> boundMap) {
		if (validationObject == null) {
			return;
		}
		// For all the fields: look for attached objects.
		ProxyObject proxyObject = session.getProxyObject(validationObject);
		Map<String,ProxyField> fieldMap = proxyObject.getFieldMap();
		for (String fieldName: fieldMap.keySet()) {
			if (fieldName != null) {
				final ClassMetadata classMetadata = m_validationEngine.getClassMetadata(validationObject.getClass());
				final PropertyMetadata fieldMetadata = classMetadata.getField(fieldName);
				if (fieldMetadata == null) {
					continue;
				}
				ProxyField proxyField = proxyObject.getProxyField(fieldName);
				Method getter = proxyField.getGetter();
				if (getter.getReturnType().isAssignableFrom(List.class)) {
					// if this is a list then walk the list and unbind the objects there.
					try {
						@SuppressWarnings("unchecked")
						final List<ValidationObject> validationObjects = 
								(List<ValidationObject>) getter.invoke(validationObject, new Object[] {});
						for (ValidationObject child : validationObjects) {
							m_validationEngine.unbind(session, proxyField, child, boundMap);
							if (child != null) {
								child.setValidationSession(null);
							}
						}
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
					continue;
				}
				if (m_validationEngine.getClassMetadata(getter.getReturnType()) != null) {
					// if this is a known object then unbind it
					try {
						ValidationObject child = (ValidationObject) getter
								.invoke(validationObject, new Object[] {});
						m_validationEngine.unbind(session, proxyField, child, boundMap);
						if (child != null) {
							child.setValidationSession(null);
						}
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
					continue;
				}
			}
		}
	}
918865
@Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    {
        if (constructed)
        {

            String methodName = method.getName();
            int params = args.length;

            if (params == 0)
            {
                if (isUninitialized() && method.equals(getIdentifierMethod))
                {
                    return getIdentifier();
                }

                else if ("getKunderaLazyInitializer".equals(methodName))
                {
                    return this;
                }
            }

            Object target = getImplementation();

            String[] strArr = entityName.split("#");
            String fieldName = strArr[1];

            if (owner != null)
            {
                EntityMetadata m = KunderaMetadataManager.getEntityMetadata(persistenceDelegator.getKunderaMetadata(),
                        owner.getClass());
                Relation r = m.getRelation(fieldName);
                if (r != null)
                {
                    PropertyAccessorHelper.set(owner, r.getProperty(), target);
                }
                if (r.getBiDirectionalField() != null && method.getReturnType().equals(m.getEntityClazz()))
                {
                    PropertyAccessorHelper.set(target, r.getBiDirectionalField(), owner);
                }

            }

            try
            {
                final Object returnValue;
                if (method.isAccessible())
                {
                    if (!method.getDeclaringClass().isInstance(target))
                    {
                        throw new ClassCastException(target.getClass().getName());
                    }
                    returnValue = method.invoke(target, args);
                }
                else
                {
                    if (!method.isAccessible())
                    {
                        method.setAccessible(true);
                    }
                    returnValue = method.invoke(target, args);
                }
                return ((returnValue == target) ? proxy : returnValue);
            }
            catch (InvocationTargetException ite)
            {
                throw new LazyInitializationException(ite);
            }
        }
        else
        {
            // while constructor is running
            throw new LazyInitializationException("unexpected case hit, method=" + method.getName());
        }

    }
75881
def on_bind_field(self, field_name, field_obj):
        
        if _MARSHMALLOW_VERSION_INFO[0] < 3:
            if not field_obj.load_from:
                field_obj.load_from = self.inflect(field_name)
        else:
            if not field_obj.data_key:
                field_obj.data_key = self.inflect(field_name)
        return None
210660
private void bindFields() {

        m_formBinderAfter = new Binder<>();
        m_formBinderAfter.bind(m_messageAfter, CmsLoginMessage::getMessage, CmsLoginMessage::setMessage);

        m_formBinderAfter.bind(
            m_enabledAfter,
            loginMessage -> Boolean.valueOf(loginMessage.isEnabled()),
            (loginMessage, enabled) -> loginMessage.setEnabled(enabled.booleanValue()));

        m_formBinderAfter.bind(
            m_logoutAfter,
            loginMessage -> Boolean.valueOf(loginMessage.isLoginForbidden()),
            (loginMessage, forbidden) -> loginMessage.setLoginForbidden(forbidden.booleanValue()));

        m_formBinderAfter.forField(m_endTimeAfter).withValidator(
            endTime -> hasValidTimes(),
            CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_LOGINMESSAGE_VAL_DATE_0)).bind(
                loginMessage -> loginMessage.getTimeEnd() != CmsLoginMessage.DEFAULT_TIME_END
                ? CmsDateField.dateToLocalDateTime(new Date(loginMessage.getTimeEnd()))
                : null,
                (loginMessage, endTime) -> loginMessage.setTimeEnd(
                    endTime != null
                    ? CmsDateField.localDateTimeToDate(endTime).getTime()
                    : CmsLoginMessage.DEFAULT_TIME_END));
        m_formBinderAfter.forField(m_startTimeAfter).withValidator(
            startTime -> hasValidTimes(),
            CmsVaadinUtils.getMessageText(Messages.GUI_MESSAGES_LOGINMESSAGE_VAL_DATE_0)).bind(
                loginMessage -> loginMessage.getTimeStart() != CmsLoginMessage.DEFAULT_TIME_START
                ? CmsDateField.dateToLocalDateTime(new Date(loginMessage.getTimeStart()))
                : null,
                (loginMessage, startTime) -> loginMessage.setTimeStart(
                    startTime != null
                    ? CmsDateField.localDateTimeToDate(startTime).getTime()
                    : CmsLoginMessage.DEFAULT_TIME_START));
        m_formBinderBefore = new Binder<>();
        m_formBinderBefore.bind(m_messageBefore, CmsLoginMessage::getMessage, CmsLoginMessage::setMessage);

        m_formBinderBefore.bind(
            m_enabledBefore,
            loginMessage -> Boolean.valueOf(loginMessage.isEnabled()),
            (loginMessage, enabled) -> loginMessage.setEnabled(enabled.booleanValue()));
    }
1176591
public void autoAssign(ProxyField proxyField, RuleContext ruleContext)
    {
        // Count the excludes left and if only 1 then assign this value.
        // TODO: work out what should happen if a later rule excludes this value
        ChoiceBase lastChoice = findLastChoice(proxyField);
        if (lastChoice != null)
        {
            Object value = proxyField.getPropertyMetadata().convertFromString(lastChoice.getKey().toString());
            s_log.debug("{}auto-assign: {} {}",new Object[]{m_indenter,proxyField,value});
            assign(getRuleProxyField(proxyField),value,ruleContext,true);
        }        
    }
324643
public void unbind(ValidationObject validationObject)
    {
        Integer id = System.identityHashCode(validationObject);
    	m_unbinding.add(id);
        List<ProposedValue> proposedValues = new ArrayList<ProposedValue>();
    	ProxyObject proxyObject = getSession().getProxyObject(validationObject);
    	for (ProxyField proxyField: proxyObject.getFieldMap().values())
    	{
    		if (!proxyField.isDerived())
    		{
    			// Figure out if this property contains a list or a known object type
    			// we want to ignore those and only reset primitive objects (long, String etc)
    			Class<?> clazz = proxyField.getPropertyMetadata().getGetMethod().getReturnType();
       			if (clazz.isAssignableFrom(List.class))
    			{
    				continue;
    			}
       			if (getSession().getValidationEngine().getClassMetadata(clazz) != null)
    			{
    				continue;
    			}
    			RuleProxyField ruleProxyField = getRuleProxyField(proxyField);
    			if (ruleProxyField.isDifferent(proxyField.getInitialValue()))
    			{
    				ProposedValue pv = new ProposedValue(ruleProxyField,proxyField.getInitialValue());
    				proposedValues.add(pv);
    			}
    		}    		
    	}
        setValues(proposedValues);
        m_boundObjects.remove(id);
    	m_unbinding.remove(id);
        List<String> kill = new ArrayList<String>();
        for (Map.Entry<String, RuleContext> entry: m_ruleContextsMap.entrySet())
        {
        	if (entry.getValue().getValidationObject() == validationObject)
        	{
        		kill.add(entry.getKey());
        	}
        }

        for (String key: kill)
        {
        	RuleContext rc = m_ruleContextsMap.remove(key);
        	rc.reset();
        }
    }
445024
@Bind(id = "exporterServices", specification = ExporterService.class, aggregate = true, optional = true)
    void bindExporterService(ServiceReference<ExporterService> serviceReference) {
        synchronized (lock) {
            try {
                exportersManager.add(serviceReference);
            } catch (InvalidFilterException invalidFilterException) {
                LOG.error("The ServiceProperty \"" + TARGET_FILTER_PROPERTY + "\" of the ExporterService "
                                + bundleContext.getService(serviceReference) + " doesn't provides a valid Filter."
                                + " To be used, it must provides a correct \"" + TARGET_FILTER_PROPERTY + "\" ServiceProperty.",
                        invalidFilterException
                );
                return;
            }
            if (!exportersManager.matched(serviceReference)) {
                return;
            }
            LOG.debug(linkerName + " : Bind the ExporterService "
                    + exportersManager.getDeclarationBinder(serviceReference)
                    + " with filter " + exportersManager.getTargetFilter(serviceReference));
            exportersManager.createLinks(serviceReference);
        }
    }
765763
public static BindingResult bindObjectToInstance(Object object, Object source) {
        return bindObjectToInstance(object, source, getBindingIncludeList(object), Collections.emptyList(), null);
    }
860343
public void assign(RuleContext ruleContext, Object value, List<ProxyField> list)
    {
        for (ProxyField proxyField: list)
        {
            assign(getRuleProxyField(proxyField),value,ruleContext,true);
        }
    }
707821
private static function Bind()
	{
		ValueProxy::$conv_t = array_fill( 0, ValueProxy::TYPES_MAX, 0 );
		for ( $k = 0; $k < ValueProxy::TYPES_MAX; $k++ )
		{
			ValueProxy::$conv_t[ $k ] = array_fill( 0, ValueProxy::TYPES_MAX, -2 );
		}

		$list = array_values( ValueProxy::$valueFactory );

		foreach ( $list as /** @var ValueProxyFactory $curr */ $curr )
		{
			foreach ( $list as /** @var ValueProxyFactory $curr2 */ $curr2 )
			{
				if ( $curr == $curr2 )
					ValueProxy::$conv_t[ $curr->GetValueCode() ][ $curr2->GetValueCode() ] = 0;
				else
					ValueProxy::$conv_t[ $curr->GetValueCode() ][ $curr2->GetValueCode() ] = $curr->Compare( $curr2 );
			}
		}
	}
779522
private void resolveCurrentclassFieldDependencies(final Object reference) {
        for (final FieldInjectionPoint injectionPoint : fieldInjectionPoints) {
            final Object injection = beanManager.getInjectableReference(injectionPoint);
            final Field field = injectionPoint.getAnnotated().getJavaMember();

            try {
                final Field declaredField = proxyClass.getDeclaredField(field.getName());

                if (declaredField.isAnnotationPresent(Inject.class)) {
                    try {
                        declaredField.set(reference, injection);
                    } catch (final Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            } catch (final NoSuchFieldException ex) {
                try {
                    field.set(reference, injection);
                } catch (final Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
1035227
public DataBinder put(Object object) throws Exception {
        for (Field field: Beans.getKnownInstanceFields(object.getClass())) {
            Object value = field.get(object);
            if (value != null) {
                put(field.getName(), value.toString());
            }
        }
        return this;
    }
541374
public Binding createBinding(String propertyPath, String binderId, Map context)
    {
        Assert.notNull(context, "Context must not be null");
        Binder binder = ((SwingBinderSelectionStrategy)getBinderSelectionStrategy()).getIdBoundBinder(binderId);
        Binding binding = binder.bind(getFormModel(), propertyPath, context);
        interceptBinding(binding);
        return binding;
    }
21084
protected void bindSubClass(HibernatePersistentEntity sub, Subclass subClass, InFlightMetadataCollector mappings,
                                String sessionFactoryBeanName) {
        bindClass(sub, subClass, mappings);

        if (LOG.isDebugEnabled())
            LOG.debug("Mapping subclass: " + subClass.getEntityName() +
                    " -> " + subClass.getTable().getName());

        // properties
        createClassProperties(sub, subClass, mappings, sessionFactoryBeanName);
    }