Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.apache.cayenne.swing;
 
 import  ognl.Ognl;
 import  ognl.OgnlException;
 

Author(s):
Andrei Adamchik
 
 // TODO: extend BindingExpression, unless we decide to make it a composition...
 public abstract class BindingBase implements ObjectBinding {
 
     private Object compiled;
 
     protected Object context;
     protected String expression;
 
     protected BindingDelegate delegate;
     protected boolean modelUpdateDisabled;
 
     protected boolean usingNullForEmptyStrings;
     protected boolean checkingForValueChange;
 
     static Throwable unwind(Throwable th) {
         if (th instanceof OgnlException) {
             Throwable reason = ((OgnlException) th).getReason();
             return (reason != null) ? unwind(reason) : th;
         }
         else {
             return Util.unwindException(th);
         }
     }
 
     public BindingBase(String propertyExpression) {
 
         try {
             this. = Ognl.parseExpression(propertyExpression);
         }
         catch (OgnlException ex) {
             throw new CayenneRuntimeException("Invalid expression - "
                     + propertyExpression, BindingBase.unwind(ex));
         }
 
         this. = propertyExpression;
     }
 
     public Object getContext() {
         return ;
     }
 
     public void setContext(Object object) {
         this. = object;
     }
 
     public boolean isCheckingForValueChange() {
         return ;
     }
 
     public void setCheckingForValueChange(boolean checkingForValueChange) {
         this. = checkingForValueChange;
     }
 
     public boolean isUsingNullForEmptyStrings() {
         return ;
     }
 
     public void setUsingNullForEmptyStrings(boolean b) {
         this. = b;
     }
 
     public String getExpression() {
         return ;
     }
 
     public BindingDelegate getDelegate() {
         return ;
     }
    public void setDelegate(BindingDelegate delegate) {
        this. = delegate;
    }

    
Pushes a new value to the bound context. If binding delegate is set, notifies it delegate about the update.
    public void setValue(Object value) {
        if ( == null) {
            throw new BindingException("No context");
        }
        try {
            // prevent the same thread from calling setValue recursively - something that
            // may happen due to event loops.
            if () {
                return;
            }
            Object oldValue = null;
             = true;
            try {
                if ( != null) {
                    // find old value
                    oldValue = getValue();
                }
                if (isUsingNullForEmptyStrings() && "".equals(value)) {
                    value = null;
                }
                if (isCheckingForValueChange()) {
                    // avoid calling getValue() twice...
                    Object existingValue = ( != null) ? oldValue : getValue();
                    if (Util.nullSafeEquals(valueexistingValue)) {
                        return;
                    }
                }
                Ognl.setValue(value);
            }
            finally {
                 = false;
            }
            if ( != null) {
                .modelUpdated(thisoldValuevalue);
            }
        }
        catch (OgnlException ex) {
            processException(ex);
        }
    }

    
Pulls bound value from the context.
    public Object getValue() {
        if ( == null) {
            throw new BindingException("No context");
        }
        try {
            return Ognl.getValue();
        }
        catch (OgnlException ex) {
            processException(ex);
            return null;
        }
    }
    protected void processException(Throwable ththrows ValidationException,
            BindingException {
        Throwable root = BindingBase.unwind(th);
        if (root instanceof ValidationException) {
            throw (ValidationExceptionroot;
        }
        else if (root instanceof NumberFormatException) {
            throw new ValidationException("Invalid numeric string");
        }
        throw new BindingException("Evaluation failed in context: " + root);
    }
New to GrepCode? Check out our FAQ X