1 /* ObjectView.java -- A view for HTML object tags
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax
.swing
.text
.html
;
41 import java
.awt
.Component
;
43 import javax
.swing
.text
.AttributeSet
;
44 import javax
.swing
.text
.ComponentView
;
45 import javax
.swing
.text
.Element
;
48 * A view for HTML <code><object></code> tags.
50 * This is a {@link ComponentView} that creates special components depending
51 * on the object specification. If the object tag has a classid attribute, then
52 * this view will try to load the class specified by this attribute using the
53 * classloader that loaded the associated document. If the class could be
54 * loaded, an instance is created and the type narrowed to {@link Component}.
56 * It is also possible to set bean properties on the created component using
57 * nested <code><param></code> tags. For example:
59 * <object classid="javax.swing.JLabel">
60 * <param name="text" value="sample text">
64 * @author Roman Kennke (kennke@aicas.com)
66 public class ObjectView
extends ComponentView
70 * Creates a new <code>ObjectView</code>.
72 * @param el the element for which to create a view
74 public ObjectView(Element el
)
80 * Creates a component based on the specification in the element of this
81 * view. See the class description for details.
83 protected Component
createComponent()
85 Component comp
= null;
86 Element el
= getElement();
87 AttributeSet atts
= el
.getAttributes();
88 String classId
= (String
) atts
.getAttribute("classid");
91 Class objectClass
= Class
.forName(classId
);
92 Object instance
= objectClass
.newInstance();
93 comp
= (Component
) instance
;
95 catch (ClassNotFoundException ex
)
99 catch (IllegalAccessException ex
)
103 catch (InstantiationException ex
)
107 // FIXME: Handle param tags and set bean properties accordingly.