Value Object pattern implementation problem

Hi All!
I try to implement value object pattern in my bean as follows:
/* Simplified code */
public class Value implements Serializable {
private String s;
public setS(String value){
s = value
public getS(){return s}
bean class:
public class Bean extends Value implemets EntityBean {
public Value getValue(){return this}
Now question.
When I try run this code I get next message
org.omg.CORBA.MARSHAL: minor code: 0 completed: No
org.omg.CORBA.portable.InputStream com.visigenic.vbroker.orb.GiopStubDelegate.invoke(org.omg.CORBA.Object, org.omg.CORBA.portable.OutputStream, org.omg.CORBA.StringHolder, org.omg.CORBA.Context, org.omg.CORBA.ContextList)
org.omg.CORBA.portable.InputStream com.visigenic.vbroker.orb.GiopStubDelegate.invoke(org.omg.CORBA.Object, org.omg.CORBA.portable.OutputStream, org.omg.CORBA.StringHolder)
org.omg.CORBA.portable.InputStream com.inprise.vbroker.CORBA.portable.ObjectImpl._invoke(org.omg.CORBA.portable.OutputStream, org.omg.CORBA.StringHolder)
com.retailpro.cms.common.InventoryValue com.retailpro.cms.ejb._st_Inventory.getValue()
void com.retailpro.cms.inventory.SetInventory._jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
void oracle.jsp.runtime.HttpJsp.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void oracle.jsp.app.JspApplication.dispatchRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
void oracle.jsp.JspServlet.doDispatch(oracle.jsp.app.JspRequestContext)
void oracle.jsp.JspServlet.internalService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
void oracle.jsp.JspServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
void javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void oracle.lite.web.JupServlet.service(oracle.lite.web.JupRequest, oracle.lite.web.JupResponse)
void oracle.lite.web.MimeServletHandler.handle(oracle.lite.web.JupApplication, java.lang.String, int, oracle.lite.web.JupRequest, oracle.lite.web.JupResponse)
void oracle.lite.web.JupApplication.service(oracle.lite.web.JupRequest, oracle.lite.web.JupResponse)
void oracle.lite.web.JupHandler.handle(oracle.lite.web.JupRequest, oracle.lite.web.JupResponse)
void oracle.lite.web.HTTPServer.process(oracle.lite.web.JupRequest, oracle.lite.web.JupResponse)
boolean oracle.lite.web.HTTPServer.handleRequest(oracle.lite.web.JupInputStream, oracle.lite.web.JupOutputStream)
boolean oracle.lite.web.JupServer.handle(oracle.lite.web.JupInputStream, oracle.lite.web.JupOutputStream)
void oracle.lite.web.SocketListener.process(java.net.Socket)
void oracle.lite.web.SocketListener$ReqHandler.run()
Seems like object can't be serialized.
But when I change my getValue() to next
public Value getValue(){
Value result = new Value();
result.setS(s);
return result;
Everything goes fine!
Can anybody comments this situation?
Any information will be appreciated!
Mike
null

Have you tried using our Business Components for Java framework to assist in developing your EJB components. BC4J is a design pattern framework that implements the J2EE Blueprints design patterns out of the box:
[list][*]Session-Entity Fagade
[*]Paged-List
[*]Unified Data Access & Logic
[*]Value Object
[*]Model View Controller
[list]
and more...
So many things you don't have to code yourself when you use BC4J to turbocharge your development... Also, using BC4J insulates you from having to choose once and for all at the beginning of your project that you ARE USING EJB AT ALL COSTS on your project.
Many projects discover that they don't require a distributed objects configuration, but end up paying for it in architectural complexity and EJB's assumption that all beans might be located on remote VM's.
With BC4J, you can build an app, deploy to EJB if you need EJB for a given project, or deploy to CORBA, or just to simple Java classes for improved performance without the remoting overheads. All without touching your application code.
Pretty cool, I think. But of course, I'm biased :-)
Steve Muench
Lead Product Manager for BC4J and Lead XML Evangelist, Oracle Corp
Author, Building Oracle XML Applications

Similar Messages

  • Value Object Pattern - Does EJB 2.0 Deprecate?

    In the EJB 1.1 specification, there were no such things as Local Interfaces and Local Home Interfaces. In the Core J2EE Patterns book, they cite the main reason for using the Value Object Pattern as being a way to avoid much of the network overhead associated with using EJB; any call to an EJB potentially involves a remote call to the object even if it lives in the same JVM. But with EJB 2.0 you can have a Local Interface which seems to eliminate all this network overhead already.
    Anyone care to register an opinion on whether or not there are still valid reasons for implementing the Value Object Pattern when using EJB 2.0?
    Any input would be greatly appreciated!

    Yes - the fact that it's generally a bad idea to "tie" stateful information (e.g. EntityBeans) to a stateless front-end.
    In other words, it's better functionality to transfer "static" sets of data (Value Objects) in chunks from a business-layer (SLSBs, fronting the EntityBeans) than to have the front-end directly query the persistence tier. Also, using the Facade (and related) patterns as the go-between the view (front-end) layer and the persistence layer, you gain the flexibility of the persistence (and the business) layer changing without having to re-engineer the view at all.

  • BusinessDelegate and Value Object Patterns

    I have just embarked on the facinating world of J2EE. My questions are very simple:
    Why would I use a BusinessDelegate pattern? What is it and why have this extra tier?
    Finally, why would I use a Value Object? What are they? How would I use them in practice?
    As you can see I am a total novice and would appreciate expert advice. Thanks in advance.

    Why would I use a BusinessDelegate pattern? What is it
    and why have this extra tier?Well, there are always some extra "plumbing" work involved when calling business services, especially if they are located in remotely hosted EJBs. You need to create your JNDI-context, perform a lookup, do narrow()-operations etc. etc.
    Now this is implementation-specific stuff, that your presentation tier doesn't really need. No, it's only concerned about sending some values to the business-logic tier, and retrieving the results and acting upon them (usually formatting and displaying them to the end-user at some way).
    If you wouldn't have BusinessDelegate as an extra insulation layer between your presentation and business tiers, you'd end up cluttering your presentation code with unnecesessary implementation-specific stuff. When you have a BusinessDelegate, you can isolate all the dirty work into it, make it configurable somehow, and just call it from your Servlets/JSPs/Applets whatever.
    So instead of this:
    InitialContext ctx = new InitialContext();
    Object home = ctx.lookup( "com.company.myproject.ejb.FirstBusinessBean" );
    FirstBusinessBeanHome narrowedHome = (FirstBusinessBeanHome)PortableRemoteObject.narrow( home, FirstBusinessBeanHome.class );
    FirstBusinessBean remote = home.create();
    // Only now you get down to the real business.
    String[] initialValues = remote.readInitialValues();
    // And so on.
    // Some stuff like try..catch suppressed for readability.You can do something simple as this:
    EJBDelegate myDelegate = EJBDelegate.getInstance( MyBeans.FIRST_BUSINESS_BEAN );
    String[] initialValues = myDelegate.readInitialValues();
    Finally, why would I use a Value Object? What are
    they? How would I use them in practice?A value object is an object whose sole purpose is to represent a value (or a bunch of values). In the previous example, if you needed to get a list of persons from you database, and one person is represented as one entity bean, at first you'd probably end up getting a collection of PersonEntityBean's remote interfaces as a result of some ejbFindBy()-query method.
    Now if you are running on a true distributed enviroment, when you iterate through this collection, displaying the persons ie. on a JSP page, every getFirstName(), getLastName(), getTitle() etc. call could potentially be a remote method call, adding a tremendous amount of extra overhead. This of course depends entirely upon your app servers implementation.
    But if you replace your Remote interfaces with a simple Value object, for example PersonVO, it could be as simple as this:
    public class PersonVO
        String firstName, lastName, title;
        public PersonVO( String firstName, String lastName, String title )
            this.firstName = firstName;
            this.lastName = lastName;
            this.title = title;
       public void getFirstName() { return this.firstName; }
       public void getLastName() { return this.lastName; }
       public void getTitle() { return this.title; }
    }Instead of a collection of remote interfaces, you return these from your business method, and use them for displaying in your presentation logic. Simple, clean and fast.
    Oh, and notice that the VO is immutable. This is a done on purpose.
    Another point where a VO is really helpful that if you have ie. two different tables in your DB, represented by two different Entity Beans (Person and PhoneNumber for example), which have a relation at the database. With a VO, you can package data from multiple entities into a single object, instead of having to deal with a multitude of different entities and their remote interfaces.
    I could go on for hours about this, but I guess I'll have to do some productive work as well. Anyway, these patterns are tried and tested, any believe me, they make the job a lot easier when properly implemented.
    .P.

  • Serialize a value object that implements Comparator T

    Hi.
    I'm implementing a VO like this:
    public class RegionVO implements Serializable, Comparable<RegionVO>My problem is that i need that the class could be serialized completely.
    The VO will be transfered throught EJB's and by past experiences with EJB 2 projects (the actual project is developed with EJB 3) and running the project in clusters, the application crashes to use VO defined like that.
    I think that the problem is caused by implement Comparable too, this inteface isn't serializable and even if implement of Serializable interface, at least 1 method (compareTo(RegionVO o))not would serializable.
    My question is if that is true, how to solve to serialize the entire VO.
    Thanks.
    Edited by: terinlagos on Jul 24, 2008 2:48 PM

    terinlagos wrote:
    Well, the question was because if eventually could have the same problem when in the future the application run in a clusterized server. Actually in my pc has no problem.Well at least you are thinking that clustering will introduce problems you don't have currently.
    I suggest you start trying to cluster you application as early as possible, you undoubtedly will have allot of lessons to learn (I have never seen a cluster solution from an it-works-on-my-pc solution not run into unexpected problems)
    Note: you can run a "clustered" solution on a single PC just in multiple JVMs (which would be deployed to different machines in your final solution)
    You should make looking at this your top priority. IMHO.

  • Inserting a tree of value objects

    Let's say I have these entities in my database:
    Person
    personId (PK)
    firstName
    lastName
    PhoneNumber
    phoneNumberId (PK)
    number
    description
    personId (FK referencing Person entity)
    I have a PersonValueObject class with the following attributes:
    Integer personId
    String firstName
    String lastName
    Collection phoneNumbers (a collection of PhoneNumberValueObject's - can be populated or set to null, depending on use case)
    I have a PhoneNumberValueObject class with the following attributes:
    Integer phoneNumberId
    String number
    Strong description
    Integer personId
    PersonValueObject person (can be populated or set to null, depending on the use case)
    I have session facade with the following methods
    createPerson(PersonValueObject personVO)
    createPhoneNumber(PhoneNumberValueObject phoneNumberVO)
    My question is, how should I insert a tree containing a Person and his related PhoneNumbers? I see three options:
    1) The session facade's client calls createPerson(), which inserts the personVO and then the session facade traverses the personVO.phoneNumbers collection and calls createPhoneNumber() internally for every element in the collection. This means that the createPerson() method must have extra code to traverse the collection.
    2) The session facade's client calls createPerson(), which inserts the personVO. Next, the session facade's client traverses the personVO.phoneNumbers collection and calls createPhoneNumber() for every element in the collection. This means that the client must have extra code to traverse the collection.
    3) Add a third method called createPersonTree(PersonValueObject personVO), which internally calls createPerson() and then internally calls createPhoneNumber(). In this case, the createPersonTree() method must have the extra code to traverse the collection. The way I see it, the advantage of this approach is that the session facade's client has a choice of calling createPersonTree(), if it needs to insert a whole tree, whereas it can just call createPhoneNumber() directly if it just needs to add a new phone number to an existing person.
    Comments?

    1) Are you using session Bean for inserting the data?
    2) Are you using the Entity Beans, I mean BMP?
    3) Have you looked in the features provided by the
    CMP2.0.Let me explain all the patterns I am using. The client is a regular java class that implements the "business delegate" pattern. The business delegate communicates with a session bean that is implementing the "session facade" pattern. It is this session facade that has those methods I referred to above, namely createPerson(), createPhoneNumber() and potentially createPersonTree(). The session facade communicates with a Person entity bean and a PhoneNumber entity bean, which implement the persistence layer. Both of these entity beans use EJB 2.0 CMR and CMP. The actual inserts are performed by these entity beans. For example, inside the session facade's createPerson() method, the session facade delegates the actual insert to the Person entity bean.
    Data is passed between objects by using the "value object" pattern. For example, the business delegate passes person data to the session facade inside a Person value object. The session facade also passes this value object to the entity bean (alternatively, the session facade could pass the person's attributes individually, but I thought this was not as convenient).
    I hope that explains the situation.

  • Shall I use Value Objects???

    Hi,
    I am creating a web app with approx 25 web pages with not much business logic.
    I plan to use struts framework.
    What I wanted to know was, shall I use value object pattern for my web page?
    Is there some kind of questionaire which I can take to decide whether I should use VO or not?
    Thanks,
    KS

    What's the difference between DTO and VO? Both are
    little more than C structs for ferrying data between
    layers. No functionality whatsoever.Value Object was the name used in the first editions of the Applied Java Patterns & Core J2ee Pattern books from Sun. These are called Data Transfer Objects in the later issues of these books.
    The Value Object name also caused some confusion because the term has previously been used to refer to language specific ideoms of wrapping primative types in Object.

  • Problem in setting vector or string[] as the "value object" in hashmap

    Hey I am new to this forum.
    I am doing a project in which i need to store a array of strings as "value object" for a unique key in hashmap.
    as I populate the hashmap from external file according to key and setting the string[]. The hashmap is taking the value field same for each entry i.e the last field as i keep updating the same variable and then putting it into hashmap.
    Please give solution to my problem???
    if question not clear,please tell me- i will add more information
    Edited by: AnkitNahar on Apr 4, 2009 8:06 AM

    I tried using the method suggested by you...but it is of same case as using the string[].
    I need to loop the statements in which the hashmap is populating so cant change the variable names in the dd.put() statements. When the below code executes it shows the same set of string for both the keys, that was the problem i was facing with string[].
    here is the example with two entries....same thing in looping.
    HashMap<String,Set<String>> dd=new HashMap<String,Set<String>>();
    String word = "Hello";
    Set<String> alternativeWords = new HashSet<String>();
    alternativeWords.add("Hi");
    alternativeWords.add("Yo");
    dd.put(word, alternativeWords);
    alternativeWords.clear();
    alternativeWords.add("hey");
    word="yep";
    dd.put(word,alternativeWords);
    System.out.println(dd.get("Hello").toString());
    System.out.println(dd.get("yep").toString());

  • Design patterns,about value object ,how?why?could you give me a soluttion

    design patterns,about value object ,how?why?could you give me a soluttion
    use value object in ejb,thanks
    i want not set/get the value in ejb,find the method to solve it ,use value
    object ?
    how? thanks.

    Hai
    Enter your telephone number here, at the top it will say your Exchange, Phone and cabient number. If it doesn't mention cabinet that means you are directly connected to the exchange and not via PCP.
    If you are connected to a cabinet and it doesn't say FTTC is available, ask your neighbor to-do the same test (they have 2 be infinity connected). If they are, then proceed to contact the moderators here. Though it could not be showing because all the ports have been used up in the FTTC Cabinet.
    If this helped you please click the Star beside my name.
    If this answered your question please click "Mark as Accepted Solution" below.

  • Stale Value Objects

    We are using Session Beans, Data Access Objects, and Value Objects in our application (no EBs). A majority of our database tables do not have timestamp columns and we are wondering how others handle stale value objects when timestamps aren't available. Is adding the timestamp column the best way to fix this? Has anyone implemented a different solution?
    Thanks,

    I assume that if use processing flags for the state of these objects u will be still have problem of data integrity,If you use session beans its good to use a time stamp column in the database and that time stamp can be used as a check value,.. if u had used BMP that u could u have used processing flags in BMP
    There is a good pattern defined on this issue on www.theserverside.com have a look at it
    thanks
    Jay

  • Transfer Object Pattern and Concurrency Transaction Mgmt

    I am developing an application that implements a remote rich client. For
    performance reasons I have chosen to use the Transfer Object pattern. I
    have been very successful with this from a performance standpoint, it
    really paid off. I am using it in combination with an assembler pattern
    to construct Transfer Objects for the view and to also reassemble domain
    objects based on changes made to transfer objects on my client side.
    Anyways the only problem I am having with it is I can't seem to figure
    out how I should implement optimistic locking with it. Is there a best
    practices to handle transaction control here?
    I generally try to keep visibility of stale data down, but there are still
    situations where concurrent clients could have requested to edit the same
    the Transfer Object at the same time. I would ideally like to handle this
    using a flavor of optimistic locking. I in fact have implemented
    optimistic locking on the domain side, but now I am not sure how or if I
    should integrate this into the Transfer Object or View side. The version
    field used in optimistic locking is generally a hidden field. The only
    way I can see to handle this with the view side is to expose this field on
    the Domain Objects and actually store it into assembeled transfer objects.
    This seems like it may be a bad idea from a design standpoint.
    The problem is the client requests data and it assembled and delivered to the client. Then at some later time the client may send a request to the server to update this data. At this time a new transaction must be started where the server reloads the domain data and copies over the requested changes. Since the domain data was just loaded you wouldn't ever trigger a versioning problem unless the version was maintained on the transfer object and copied over as well. I am developing this project with hibernate on the back end and unfortunately hibernate doesn't acknowledge manual changes to the version field.
    I just feel like there must be a better way to do this. I believe that using the Transfer Object or DTO pattern for remote client/server architectures is pretty common. So there must be a best practice to deal with concurrency? Suggestions, insight, lay it on me please.
    thx

    I personal respect both concepts and am using both in an application I am currently work.
    Firstly, I have my Transfer Object which I call xxxData.
    Next, the entities are called xxx
    I have my DAO classes that handles all CRUD operation. but within the DAO class I have two methods
    private <EntityClass> retrieveEntityFromObject(<EntityClassData> data) {}
    private <EntityClassData> retrieveEntityFromObject(<EntityClass> entity) {}so with these methods, I separate my business logic from my data layer. My codes will alway use data objects instead of entities. For example, a create method will be
    public ProductData createProduct(ProductData data)
         entity.persist(retrieveEntityFromObject(data));
    }I hope someone understands
    Regards

  • Authorization Issue with Custom Pending Value Object and Anonymous Users

    Hi,
    I am just converting my demo from version 7.1 to 7.2. I am not doing upgrade. The demo uses a custom pending value object USER_REQUEST. The idea is that new employee goes to Java AS as anonymous user and enters her details and store where she will work. After submitting request there is an approval process using custom entry type USER_REQUEST. If the request is approved then IdM converts USER_REQUEST into MX_PERSON entry. This works nice in 7.1 but I am having problems with replicating this in 7.2. I created new UI task accessible by anonymous that creates new USER_REQUEST entry. I also assigned role idm.anonymous with UME action idm_anonymous to UME built in group Anonymous users.
    My problem is with the field STORE. This field is a reference field to another custom entry type STORE (this entry type will be used in context based assignment). Every new employee must selects a store where she will work. The problem is when user clicks on button "Select". Web dynpro terminates and returns authorization error. I also tested this with entry type MX_ROLE. I added attribute MXREF_MX_ROLE and same issue. So it seems that just assigning UME action idm_anonymous is not enough to list objects from identity store. I found a workaround for this issue. When I assign also UME action idm_authenticated to Anonymous users then it does not dump and I get a pop up window where I can search for store. It does not seem right to assign idm_authenticated to anonymous users.
    Another issue is with display task for entry type USER_REQUEST. I assigned a display task to entry STORE and I set that Anonymous have access to this task in Access control tab. I assigned default value to the field store. So when a user opens page she can see a hyper link to display already assigned store. When user clicks on this hyper link it opens a new pop up window and user must authenticate against Java AS. After successful authentication the display task for entry STORE is displayed. I would assume that anonymous user can display it without authentication.
    So to me it seems like authorization checks have been changed in 7.2 versions and are more strict for anonymous tasks. Hence my question is how can I implement my scenario. Am I missing some configuration or what's the proper solution to my two issues? I don't count assigning idm_authenticated to Anonymous users as a solution. This workaround does not solve my second issue.
    Thanks

    Some of the folks from Trondheim labs check, but rather infrequently.  There's another person who I guess is in consulting that also checks from time to time.
    Sorry I can't help you with your main question...
    Matt

  • Value Objects still  relevant in EJB 2.0?

    I came across the concept of using Value Objects to get better performance from EJBs as they reduce the number of remote calls to invoke to retrieve object property values.
    However, with the introduction of LocalHome and Local interfaces for EJB 2.0, is it still useful to have value objects to pass data around, typically between EJBs and the Controller (typically servlets/JSPs or session beans that implement business logic)?

    Not so fast.
    I wouldn't be so quick to get rid of VOs simply because local interfaces exist now. Keep in mind that using local interfaces is not always the right answer to your problem (since there are still situations where the client and server are not co-located within a given VM).
    Also, there are times when the brittleness of your API should be considered. If a method takes many parameters, it is often benificial to pass a single VO as a paramater rather than multiple individual parameters. This really comes into play when methods are modified to take different arguments (e.g. adding a new argument).
    Consider a method on a bean used to update a student's records for example.public StudentVO update(String firstName, String middleInitial, String lastName, int age, String ssn, String status) throws UpdateException; is much more brittle than public StudentVO update(StudentVO student) throws UpdateException;Consider what would happen if a design change makes GPA and gradeLevel part of a student's profile.
    The second method's signature would remain the same. The signature of the first method however would now read public StudentVO update(String firstName, String middleInitial, String lastName, int age, String ssn, String status, float gpa, int gradeLevel) throws UpdateException; This change would "break" the calls made by any callers of this method. While there are pros and cons to this (as well as other ways to solve this issue, such as method overloading, etc.), it is something to consider when deciding whether a value object should be used in certain situations.
    Hope this adds another point of view to the discussion.
    Note: I'm using Value Object (VO), Data Transfer Object (DTO) and Transfer Object (TO) to me the same thing here.

  • Modification to Pending Value Object

    Hi,
    we have defined an Add Member Task for all Privileges, so that a Pending Value Object (PVO) is created and an approval step can be performed.
    Within the approval step we would like the user to add additional information (a reference to an MX_PERSON object). However, when the user adds such an attribute value in the approval window, the attribute value is not written to the database.
    Is it possible that a PVO cannot be modified within an approval step? Is there any workaround to this behaviour?
    Thanks in advance for your help.
    Best regards
    Holger

    Hi Dominik,
    thanks for the hint - I was already considering to use a custom PVO, but so far I haven't found an easy way to implement this when only requesting new privileges or roles.
    I can see two alternatives in using a custom PVO:
    1. We still have the Add Member Task defined on the privilege. When a privilege is requested, I get a standard PVO. I would then have to start/create my custom PVO and perform the approval. The problem with that solution is that I need to make sure that the standard PVO Ordered Task Group is waiting for the  completion of my custom PVO. So we would need to perform a tricky synchronization between the tasks.
    2. We do not have an Add Member Task. In this case we need to make sure that the provisioning is not immediately started once the user has pressed the Submit button. So I would need to make sure that we do not use the MX_PRIVILEGE attribute on the interface, but rather another temporary attribute that shows all the available privileges. In that case I would lose some of the functionality when searching for privileges and showing the user's current privileges is not that easy.
    Did you also implement requesting additional privileges with custom PVOs?
    Best regards
    Holger

  • Transfer Object pattern question

    Hi, developers!
    I created a Transfer Object pattern class, that has an array field. See below:
    class TOClass {
      private int[] values;
      //notice that I am using clone() method
      public int[] getValues() {
        return (int[])values.clone();
      public void setValues(int[] values) {
        this.values = (int[])values.clone();
    }Would you do like I did?
    Thanks in advance!

    Thank you, you all!
    I am testing the solution you presented, Saish, and I am verifying yet. But I see that the problem of manipulation of data continues, like dubway said. But, this discussion gave me a lot of ideas! (I didn�t know Collections.unmodifiableList() method yet, very interesting method). I will continue my researchs for the best solution.
    But I have to worry only when the getter method is used, because I don�t know what other developers will do with the value returned. I don�t need to worry about setter, because the only person that sets is me, and nobody else.
    And one more thing. My TO class does not contain only one field. There are other fields: Strings, BigDecimals, etc, but these other fields are easy, I just have to create getters and setters for them. There is only one field that has the "behaviour of an array". But because of the fact that there are other fields, to not make this class complicated and "dirty" visually, I really want to use simple getters and setters methods, only. Your solution is not providing getters and setters exactly, Saish. I want to follow the Transfer Object pattern, whose feature is the existence of getters and setters, only.

  • Exposing Methods of Value Object

    I have the need for a value (transfer) object that contains only getters and setters, as well as a full "business object" that has the same getters and setters as well as business logic (like insert()).
    I hate the idea of maintaining two separate objects, and making sure that when I add a new attribute to the BO I remember to add it to the VO.
    I would love to have the BO hold a private instance of the VO inside it, and automatically "expose" all the VO's methods to the outside world as if they were its own. I could do this with inheritence, but then I have the problem of creating a VO from a BO (lots of error-prone repetitive code).
    Any ideas on how I could expose these methods, together with the BO's logic?
    Thanks, Gary

    If I've understood your question, you may use a Proxy
    object to achieve the desired behaviour.
    What you'll need to do is create a "super" interface
    that contains the methods from your business object
    and value object. You will then create a Proxy that
    implements the "super" interface. When you invoke a
    method on the proxy, the invocation handler will try
    to first invoke the method on the business object. If
    the business object does not implement the requested
    method (i.e. one of the value methods), the handler
    tries to invoke the method on the value object member
    of the business object.
    The only maintainence overhead implied by this
    solution is that methods must be added to the "super"
    interface to correspond to each method added to the
    business or value objects.
    Have a look at this example to see what I mean
    public class Test {
    public static void main(String[] args) {
    try {
    ProxyHandler d = new ProxyHandler(new
    Handler(new BusinessObject());
    Object o =
    Object o =
    Proxy.newProxyInstance(Thread.currentThread().getConte
    tClassLoader(),
    new Class[]
    new Class[] {BusinessValueInterface.class},
    class}, d);
    BusinessValueInterface bvi =
    rface bvi = (BusinessValueInterface)o;
    bvi.businessMethod();
    System.out.println(bvi.getVal());
    catch (Exception ex) {
    ex.printStackTrace();
    static class ProxyHandler implements
    nts InvocationHandler {
    BusinessObject b;
    public ProxyHandler(BusinessObject bo) {
    b = bo;
    public Object invoke(Object proxy, Method m,
    thod m, Object[] params)
    throws Throwable
    Class[] paramClasses = null;
    if (params != null) {
    paramClasses = new
    amClasses = new Class[params.length];
    for (int x = 0; x < params.length;
    params.length; x++)
    paramClasses[x] =
    paramClasses[x] = params[x].getClass();
    Method m1 = null;
    try {
    m1 =
    m1 = b.getClass().getMethod(m.getName(),
    getName(), paramClasses);
    catch (Exception ex) {
    if (m1 != null) {
    return m1.invoke(b, params);
    else {
    Method m2 =
    Method m2 =
    2 = b.val.getClass().getMethod(m.getName(),
    paramClasses);
    if (m2 != null) {
    return m2.invoke(b.val, params);
    else {
    return null;
    interface BusinessValueInterface {
    public String getVal();
    public void businessMethod();
    static class BusinessObject {
    ValueObject val = new ValueObject();
    public void businessMethod() {
    System.out.println("businessMethod
    inessMethod invoked");
    static class ValueObject {
    public String getVal() {
    return "value";
    Good luck,
    MikeI would definetly like to know more about what performance characteristics is needed in the system before recommending a dynamic proxy. Value objects accessors and mutators tend to be the most called methods in a system, and there is a fairly large overhead for dynamic proxies (about 5*(normal method call) on a windows 2000 box running IBM jre 1.3.1). Dynamix proxies are great and I use them for a lot of things, but NOT for value object setter and getters...
    I�d recommend either wrapping the VO in the BO and exposing it as:
    MyBO myBo = getBO();
    myBo.getValue().setName( ... ); or make the BO stateless and pass the value in the method calls:
    myBO.performSomeNiceBusinessLogic( valueObject, someOtherArgument );The latter is probably the way I would go for most cases, but the former has its advantages to.
    Br - johan

Maybe you are looking for

  • IPod cannot be synced. The disk could not be read or written to.

    I have... G5 ipod video 30Gb formated to PC iBook G3 600MHz iTunes 7.1 (59) iPhoto 4.03 I use my ipod to contain all my videos, photos and music manually and nothing stored on the iBook itself, as it only has a small hard drive. I have a large amount

  • FI: Open Items and Disputes

    Hi Experts, I would like to know how to retrieve the FI Open items. Basically the SAP tables and criteria to fetch all Open Items. Also, how to identify the disputes in the items. Best Regards, Kurtt

  • Need help buying a PC for a graphics designer.

    Hi, I have a user that uses a desktop maskin basically only for Photoshop. I have my eyes on the following PC but im not sure if it is good enough for working with photoshop. I would  appreciate all the help i can get. for exemple, should there be mo

  • Mail server working sending emails between user accounts but not to other (outside) email accounts?

    Hi! I am new to Mac OS X Server Mail and I am trying to set up.  I have successfully started the mail services and created 2 user accounts.  Those accounts can email each other back and forth, no problem; however, they cannot send/receive to other em

  • Difficulty with iPod restore on older G4 iMac

    My mother bought a 60GB video iPod in July. Right now we have an older 17" flat panel G4 iMac that has been updated to OS X 10.4.7, the kind that only has USB 1.1 (by this http://docs.info.apple.com/article.html?artnum=60971). I know that the iPod sh