本文介绍了需要帮助bean - 在运行时添加属性???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我是Java bean的新手。昨晚拿了一本书,

开始读它们。我正在构建一个允许

用户定义具有动态属性的对象的应用程序。类似于

java哈希表的东西。可以在运行时添加新属性并删除它们




我有一个非常喜欢的第三方房产检查员可供我使用

我非常想重复使用。这个检查器使用bean API。

我希望我可以为我的

动态对象构建一组Java bean包装器,以便在这个检查器中可以检查它们。 br />

好​​吧,从我到目前为止所读到的内容来看,我必须在我的包装类中为我想要的每个属性定义一个getXXX和

setXXX方法

检查。我无法定义这些方法,因为我不知道用户可能添加到原始对象的属性是什么。有什么方法可以解决这个难题吗?


任何帮助都表示赞赏。


Nik

-

================================== =====

Nikita A. Visnevski

自适应系统实验室

CRL,麦克马斯特大学

电话: (905)525-9140 x 27282

网址:

=============================== ========

Hi everyone,

I am rather new to Java beans. Just picked up a book last night and
started reading about them. I am building an application that allows a
user to define objects with dynamic properties. Something similar to a
java hash table. One can add new properties at runtime and remove them
as well.

I have a really fancy third party property inspector available to me
that I would very much like to reuse. This inspector uses beans API.
My hope was that I could build a set of Java bean wrappers for my
dynamic objects such that they could be inspectable in this inspector.

Well, from what I read so far it seams that I have to have a getXXX and
setXXX method defined in my wrapper class for every property I want to
inspect. I can not define these methods since I have no idea what
properties the user might add to my original object. Is there any way
to work around this difficulty?

Any help is appreciated.

Nik
--
=======================================
Nikita A. Visnevski
Adaptive Systems Laboratory
CRL, McMaster University
Phone : (905) 525-9140 x 27282
Web : http://soma.crl.mcmaster.ca
=======================================

推荐答案




我唯一能想到的就是使用java反射和代理

方法......虽然这有点复杂。


我个人认为,我们可以使用散列表或某物来映射物业到

a值。


-

现在有更多的牛铃



The only thing I can think of is using java reflection and proxy
methods... That would be a bit complicated though.

I, personally, would us a hashtable or something to map a property to
a value.

--
now with more cowbell





最后,你必须提供一对accessor / mutator方法

每个属性。你不必把它们叫做setXXX和getXXX就是你不想要b / b
如果它们有另外一种指定这些

方法的方法不同的名字),但你确实需要他们来支付



如果你非常坚定,可能会为你

围绕原始表格生成一个JavaBeans包装类,类似于
对象。你需要做一些Java代码生成,而BCEL将是非常有帮助的。基本上,你想要生成一个类,其对象包含对原始对象的引用,并且
公开一组看起来像JavaBeans方法的方法。这些方法

会将操作传递给原始对象。你需要

来随时生成bean类和对象

检查数据就像它是一个JavaBean一样。


-


培训任何人的最简单方法......无处不在。


Chris Smith - 首席软件开发人员/技术培训师

MindIQ Corporation



In the end, you''ll have to provide a pair of accessor/mutator methods
for each property. You don''t have to call them setXXX and getXXX is you
don''t want to (see BeanInfo for an alternate way to specify these
methods if they have different names), but you do need for them to
exist.

One way around this, if you''re very determined, may be for you to
generate a JavaBeans wrapper class around your original table-like
object. You''d need to do some Java code generation, and BCEL would be
very helpful in accomplishing this. Essentially, you''d want to generate
a class whose objects hold a reference to your original object and
expose a set of methods that look like JavaBeans methods. These methods
would pass their operations through to your original object. You''d need
to generate the bean class and object on the fly whenever you want to
inspect the data as if it were a JavaBean.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation





-

===================================== ==

Nikita A. Visnevski

自适应系统实验室

CRL,麦克马斯特大学

电话:(905) 525-9140 x 27282

网址:

================================== =====



--
=======================================
Nikita A. Visnevski
Adaptive Systems Laboratory
CRL, McMaster University
Phone : (905) 525-9140 x 27282
Web : http://soma.crl.mcmaster.ca
=======================================


这篇关于需要帮助bean - 在运行时添加属性???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:20