Source Code Cross Referenced for Expression.java in  » 6.0-JDK-Core » beans » java » beans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » beans » java.beans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package java.beans;
027
028        /**
029         * An <code>Expression</code> object represents a primitive expression 
030         * in which a single method is applied to a target and a set of 
031         * arguments to return a result - as in <code>"a.getFoo()"</code>. 
032         * <p> 
033         * In addition to the properties of the super class, the 
034         * <code>Expression</code> object provides a <em>value</em> which 
035         * is the object returned when this expression is evaluated. 
036         * The return value is typically not provided by the caller and 
037         * is instead computed by dynamically finding the method and invoking 
038         * it when the first call to <code>getValue</code> is made. 
039         * 
040         * @see #getValue
041         * @see #setValue
042         *
043         * @since 1.4
044         * 
045         * @version 1.3 11/15/00
046         * @author Philip Milne
047         */
048        public class Expression extends Statement {
049
050            private static Object unbound = new Object();
051
052            private Object value = unbound;
053
054            /**
055             * Creates a new <code>Statement</code> object with a <code>target</code>, 
056             * <code>methodName</code> and <code>arguments</code> as per the parameters. 
057             *
058             * @param target The target of this expression. 
059             * @param methodName The methodName of this expression. 
060             * @param arguments The arguments of this expression. If <code>null</code> then an empty array will be used. 
061             *     
062             * @see #getValue
063             */
064            @ConstructorProperties({"target","methodName","arguments"})
065            public Expression(Object target, String methodName,
066                    Object[] arguments) {
067                super (target, methodName, arguments);
068            }
069
070            /**
071             * Creates a new <code>Expression</code> object for a method 
072             * that returns a result. The result will never be calculated 
073             * however, since this constructor uses the <code>value</code>  
074             * parameter to set the value property by calling the 
075             * <code>setValue</code> method.
076             *
077             * @param value The value of this expression. 
078             * @param target The target of this expression. 
079             * @param methodName The methodName of this expression. 
080             * @param arguments The arguments of this expression. If <code>null</code> then an empty array will be used.
081             *
082             * @see #setValue
083             */
084            public Expression(Object value, Object target, String methodName,
085                    Object[] arguments) {
086                this (target, methodName, arguments);
087                setValue(value);
088            }
089
090            /**
091             * If the value property of this instance is not already set, 
092             * this method dynamically finds the method with the specified 
093             * methodName on this target with these arguments and calls it. 
094             * The result of the method invocation is first copied 
095             * into the value property of this expression and then returned 
096             * as the result of <code>getValue</code>. If the value property 
097             * was already set, either by a call to <code>setValue</code> 
098             * or a previous call to <code>getValue</code> then the value 
099             * property is returned without either looking up or calling the method.
100             * <p>
101             * The value property of an <code>Expression</code> is set to 
102             * a unique private (non-<code>null</code>) value by default and 
103             * this value is used as an internal indication that the method 
104             * has not yet been called. A return value of <code>null</code> 
105             * replaces this default value in the same way that any other value 
106             * would, ensuring that expressions are never evaluated more than once. 
107             * <p>
108             * See the <code>excecute</code> method for details on how 
109             * methods are chosen using the dynamic types of the target 
110             * and arguments. 
111             * 
112             * @see Statement#execute
113             * @see #setValue
114             * 
115             * @return The result of applying this method to these arguments.  
116             */
117            public Object getValue() throws Exception {
118                if (value == unbound) {
119                    setValue(invoke());
120                }
121                return value;
122            }
123
124            /**
125             * Sets the value of this expression to <code>value</code>. 
126             * This value will be returned by the getValue method 
127             * without calling the method associated with this 
128             * expression. 
129             * 
130             * @param value The value of this expression. 
131             * 
132             * @see #getValue
133             */
134            public void setValue(Object value) {
135                this .value = value;
136            }
137
138            /*pp*/String instanceName(Object instance) {
139                return instance == unbound ? "<unbound>" : super 
140                        .instanceName(instance);
141            }
142
143            /**
144             * Prints the value of this expression using a Java-style syntax. 
145             */
146            public String toString() {
147                return instanceName(value) + "=" + super.toString();
148            }
149        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.