ContextProperty.java :  » Database-ORM » csvbeans » org » csvbeans » Java Open Source

Java Open Source » Database ORM » csvbeans 
csvbeans » org » csvbeans » ContextProperty.java
/*
 * Copyright 2004-2006 Fouad HAMDI with the idea 
 * of SameLAN, S.L. Soluciones Tecnolgicas.
 *
 * Licensed 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.csvbeans;

import org.csvbeans.context.ContextManager;

/**
 * A property whose value can be retrieved in the contexts.
 * 
 * @author Fouad Hamdi
 * @since 0.7
 */
public class ContextProperty extends Property {
    private String attributeName;
    private String scope;
    private ContextManager manager;
    
    /**
     * Constructor.
     * 
     * @param name the property name
     * @param attribute the name of the value in the context
     * @param manager helper to retrieve the value
     */
    public ContextProperty(String name, String attributeName, ContextManager manager) {
        this(name, attributeName, null, manager);
    }
    
    /**
     * Constructor.
     * 
     * @param name the property name
     * @param attribute the name of the value in the context
     * @param scope the scope where to retrieve the value
     * @param manager helper to retrieve the value
     */
    public ContextProperty(String name, String attributeName, String scope, ContextManager manager) {
        super(name, null);
        // TODO throw an exception when manager is null
        this.scope = scope;
        this.manager = manager;
        this.attributeName = attributeName;
    }

    /**
     * Retrieve the value of the property from the contexts.
     */
    public Object getValue() {
        if (scope != null) {
            return manager.getAttribute(attributeName, scope);
        } else {
            return manager.getAttribute(attributeName);
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.