Get and set the value of a property in a bean using Expression and Statement : Java Beans « Development Class « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Development Class » Java BeansScreenshots 
Get and set the value of a property in a bean using Expression and Statement
   

import java.beans.Expression;
import java.beans.Statement;

public class Main {
  public static void main(String[] argvthrows Exception {
    Object o = new MyBean();
    // Get the value of prop1
    Expression expr = new Expression(o, "getProp1"new Object[0]);
    expr.execute();
    String s = (Stringexpr.getValue();

    // Set the value of prop1
    Statement stmt = new Statement(o, "setProp1"new Object[] { "new string" });
    stmt.execute();
  }
}

class MyBean {
  String prop1;

  public String getProp1() {
    return prop1;
  }

  public void setProp1(String s) {
    prop1 = s;
  }

  int prop2;

  public int getProp2() {
    return prop2;
  }

  public void setProp2(int i) {
    prop2 = i;
  }

  byte[] prop3;

  public byte[] getProp3() {
    return prop3;
  }

  public void setProp3(byte[] bytes) {
    prop3 = bytes;
  }
}

   
    
    
  
Related examples in the same category
1. JavaBean: BeanContextSupportJavaBean: BeanContextSupport
2. JavaBean: Test program that adds 100 beans to a contextJavaBean: Test program that adds 100 beans to a context
3. JavaBean: how to use the instantiateChild() convenience method to create a beanJavaBean: how to use the instantiateChild() convenience method to create a bean
4. JavaBean: illustrate delivery of the BeanContextMembershipEventJavaBean: illustrate delivery of the BeanContextMembershipEvent
5. JavaBean: creates all of the objects, a tests the service capabilitiesJavaBean: creates all of the objects, a tests the service capabilities
6. Bean ContainerBean Container
7. PropertyTablePropertyTable
8. Property Test
9. Introspecting a BeanIntrospecting a Bean
10. Listening for Changes to the Selected File in a JFileChooser Dialog
11. Get a list of selected files
12. Listening for Changes to the Current Directory in a JFileChooser Dialog
13. Displaying the Current Directory in the Title of a JFileChooser Dialog
14. Setting an Accessory Component in a JFileChooser Dialog
15. Convert a bean to XML persistence
16. Listen for bean's property change event
17. List property names of a Bean
18. Prevent bean's property being serialized to XML
19. Create an instance a Bean
20. Convert an XML persistence to bean
21. Determine bean's property type
22. Listen for a constrained property change
23. Bean has a single property called property.
24. Implementing a Bound Property
25. Implementing a Constrained Property: fires a PropertyChangeEvent whenever its value is about to be changed.
26. Instantiating a Bean
27. Listing the Property Names of a Bean
28. Getting and Setting a Property of a Bean
29. Get and set an Object type property
30. gets and sets a primitive type property
31. gets and sets an array type property
32. Serializing a Bean to XML: XMLEncoder only persists the value of public properties.
33. Deserializing a Bean from XML
34. Preventing a Bean Property from Being Serialized to XML
35. Serializing an Immutable Bean Property to XML
36. Listening for a Property Change Event: A property change event is fired when a bound property is changed.
37. Listening for a Vetoable Property Change Event
38. Read bean's property value
39. Saving and restoring the state of a pretend CAD systemSaving and restoring the state of a pretend CAD system
40. An extension of ArrayList that provides some handy utilities for working with JavaBeans
41. An extension of Vector that provides some handy utilities for working with JavaBeans
42. extends SimpleBeanInfo
43. Get and set properties on a bean
44. Bean Utility
45. Is JavaBean Compliant Setter
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.