Wrapper classes
Hola, tengo una duda con las Wrapper classes, �por qu� estas clases a partir de la versi�n 5 (jvm 1.5) aceptan asignaciones directamente?
Por ejemplo:
(jvm 1.5):
Double d = 5.0; (<-- compila)
(jvm 1.4):
Double d = 5.0; (<-- no compila)
Agradecer�a mucho una respuesta (en ingl�s o espa�ol)
Ok ok so I'm the slowest old sod again and everybody
seems to speak Spanish fluently ;-)Un bocadillo de queso y una cervesa por favor.
Trabajo mucho pero gano poco.Y una cerveza grande, Grolsch, por favor. You must've been studying
Spanish at the same school I did ;-)
kind regards,
Jos (y un poco de aceitunas para dos personas ;-)
Similar Messages
-
What is the proper way to code a "wrapper" class?
Basically I want to replace an existing Action with a custom Action, but I want the custom Action to be able to invoke the existing Action.
The following code works fine. I can create a custom Action using the existing action and the text on the button "paste-from-clipboard" is taken from the existing Action. So everything works great as long as the existing Action extends from AbstractAction.
However the Action interface does not support the getKeys() method which I used to copy the key/value information from the existing action to the wrapped action. So if you try to create a button from some class that strictly implements the Action interface the key/value data in the wrapped Action will be empy and no text will appear on the button.
So as the solution I thought I would need to override all the methods in the wrapped Action class to invoke the methods from the originalAction object. That is why all the commented code in the class is there. But then the protected methods cause a problem as the class won't compile.
Do I just not worry about overriding those two methods? Is this a general rule when creating wrapper classes, you ignore the protected methods?
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.text.*;
public class WrappedAction extends AbstractAction
private Action originalAction;
public WrappedAction(JComponent component, KeyStroke keyStroke)
Object key = getKeyForActionMap(component, keyStroke);
if (key == null)
String message = "no input mapping for KeyStroke: " + keyStroke;
throw new IllegalArgumentException(message);
originalAction = component.getActionMap().get(key);
if (originalAction == null)
String message = "no Action for action key: " + key;
throw new IllegalArgumentException(message);
// Replace the existing Action with this class
component.getActionMap().put(key, this);
// Copy key/value pairs to
if (originalAction instanceof AbstractAction)
AbstractAction action = (AbstractAction)originalAction;
Object[] actionKeys = action.getKeys();
for (int i = 0; i < actionKeys.length; i++)
String actionKey = actionKeys.toString();
putValue(actionKey, action.getValue(actionKey));
private Object getKeyForActionMap(JComponent component, KeyStroke keyStroke)
for (int i = 0; i < 3; i++)
InputMap inputMap = component.getInputMap(i);
if (inputMap != null)
Object key = inputMap.get(keyStroke);
if (key != null)
return key;
return null;
public void invokeOriginalAction(ActionEvent e)
originalAction.actionPerformed(e);
public void actionPerformed(ActionEvent e)
System.out.println("custom code here");
invokeOriginalAction(e);
public void addPropertyChangeListener(PropertyChangeListener listener)
originalAction.addPropertyChangeListener(listener);
protected Object clone()
originalAction.clone();
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
originalAction.firePropertyChange(propertyName, oldValue, newValue);
public Object[] getKeys()
return originalAction.getKeys();
public PropertyChangeListener[] getPropertyChangeListeners()
return originalAction.getPropertyChangeListeners();
public Object getValue(String key)
return originalAction.getValue(key);
public boolean isEnabled()
return originalAction.isEnabled();
public void putValue(String key, Object newValue)
originalAction.putValue(key, newValue);
public void removePropertyChangeListener(PropertyChangeListener listener)
originalAction.removePropertyChangeListener(listener);
public void setEnabled(boolean newValue)
originalAction.setEnabled(newValue);
public static void main(String[] args)
JTextArea textArea = new JTextArea(5, 30);
JFrame frame = new JFrame("Wrapped Action");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JScrollPane(textArea), BorderLayout.NORTH);
frame.add(new JButton(new WrappedAction(textArea, KeyStroke.getKeyStroke("control V"))));
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );I can't get the PropertyChangeListener to fire with any source. Here is my test code. Note I am able to add the PropertyChangeListener to the "Paste Action", but I get no output when I add it to the WrappedAction. I must be missing something basic.
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class WrappedAction3 implements Action, PropertyChangeListener
private Action originalAction;
private SwingPropertyChangeSupport changeSupport;
* Replace the default Action for the given KeyStroke with a custom Action
public WrappedAction3(JComponent component, KeyStroke keyStroke)
Object actionKey = getKeyForActionMap(component, keyStroke);
if (actionKey == null)
String message = "no input mapping for KeyStroke: " + keyStroke;
throw new IllegalArgumentException(message);
originalAction = component.getActionMap().get(actionKey);
if (originalAction == null)
String message = "no Action for action key: " + actionKey;
throw new IllegalArgumentException(message);
// Replace the existing Action with this class
component.getActionMap().put(actionKey, this);
changeSupport = new SwingPropertyChangeSupport(this);
originalAction.addPropertyChangeListener(this);
addPropertyChangeListener(this);
* Search the 3 InputMaps to find the KeyStroke binding
private Object getKeyForActionMap(JComponent component, KeyStroke keyStroke)
for (int i = 0; i < 3; i++)
InputMap inputMap = component.getInputMap(i);
if (inputMap != null)
Object key = inputMap.get(keyStroke);
if (key != null)
return key;
return null;
public void invokeOriginalAction(ActionEvent e)
originalAction.actionPerformed(e);
public void actionPerformed(ActionEvent e)
System.out.println("actionPerformed");
// Delegate the Action interface methods to the original Action
public Object getValue(String key)
return originalAction.getValue(key);
public boolean isEnabled()
return originalAction.isEnabled();
public void putValue(String key, Object newValue)
originalAction.putValue(key, newValue);
public void setEnabled(boolean newValue)
originalAction.setEnabled(newValue);
public void xxxaddPropertyChangeListener(PropertyChangeListener listener)
originalAction.addPropertyChangeListener(listener);
public void xxxremovePropertyChangeListener(PropertyChangeListener listener)
originalAction.removePropertyChangeListener(listener);
public void addPropertyChangeListener(PropertyChangeListener listener)
changeSupport.addPropertyChangeListener(listener);
public void removePropertyChangeListener(PropertyChangeListener listener)
changeSupport.removePropertyChangeListener(listener);
public void propertyChange(PropertyChangeEvent evt)
changeSupport.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
public static void main(String[] args)
JTable table = new JTable(15, 5);
WrappedAction3 action = new WrappedAction3(table, KeyStroke.getKeyStroke("TAB"));
action.addPropertyChangeListener( new PropertyChangeListener()
public void propertyChange(PropertyChangeEvent e)
System.out.println(e.getSource().getClass());
action.putValue(Action.NAME, "name changed");
Action paste = new DefaultEditorKit.PasteAction();
paste.addPropertyChangeListener( new PropertyChangeListener()
public void propertyChange(PropertyChangeEvent e)
System.out.println(e.getSource().getClass());
paste.putValue(Action.NAME, "name changed");
} -
What are the uses of Void wrapper class?
Hi,
Similar to other Wrappers, Void is a wrapper class for the primitive ' void ' . We all know that Void is a final class , we can't instantiate it.
My Question is what are the uses of Void?
thanks,kajbj wrote:
I have at times used it in reflection and jmx.I have used them with SwingWorker if I didn't have anything interesting to return. There is also an example in the tutorial: [http://java.sun.com/docs/books/tutorial/uiswing/concurrency/simple.html] -
Developing the Wrapper class to log the message in XI server
Hi All,
We are trying to develop wrapper class on the SAP Logging API, in that I am unable to log the message in the log file(whose path is mentioned in the properties file).
We use this for storing when exception raised during message transformation due to certain error conditions...
Procedure:
My Wrapper class will take the parameters from Property file and store/log the message in the specified location,
This is working outside of XI environment
Please suggest how to make to work in XI environment
Also suggest do I need to do any configurations in SAP web As
Thanks,
venu.HI,
With the above blog ref by Michal , see the below links also,
/people/alessandro.guarneri/blog/2006/03/27/sap-xi-lookup-api-the-killer
/people/amjad-ali.khoja/blog/2005/12/16/slaw-a-new-logging-tracing-framework-for-xi
/people/amjad-ali.khoja/blog/2006/02/07/using-dom4j-in-xi--a-more-sophisticated-option-for-xml-processing-than-sap-xml-toolkit
Also my be useful..
/people/community.user/blog/2007/01/09/enterprise-soa-explorations-reflections-on-database-integration
/people/anne.tarnoruder/blog/2006/10/26/reusing-code-with-pdk-for-net
/people/piers.harding/blog/2006/05/18/ruby-on-rails-with-ajax
Regards
Chilla -
How to get SDKODBC Wrapper class for indesign cs3
Hi,
I have to implement the mysql database with my indesign plugin. I didn't have a SDKODBC Wrapper class. Can any one say how to get SDKODBC Wrapper class from adobe.
Regards,
saravanan.I doubt if change documents are generated for SE78 transaction.
For list of change documents defined, please check table: TCDOB.
Hope this helps.
Kind Regards
Eswar -
Failed to Generate Wrapper Class Error With Postgresql
Hello,
Sorry if this comes across twice, I posted it first through the Google Groups interface, but I haven't seen it show up on the dev2dev forum interface. So here it is again.
I've read the following threads that seem to be related to this
question:
http://groups-beta.google.com/group/weblogic.developer.interest.jdbc/browse_thread/thread/dc8f0a9ee03e9b9f/f0a70a673db3bb52
http://groups-beta.google.com/group/weblogic.developer.interest.jdbc/browse_thread/thread/4f3b71c77dca30c4/4ed2e1c7b76a0c7b
I also followed the links in the second post ( I also found them via
Google as well ). I've been very sure the Postgresql JDBC driver is
definitely in the class path. I'm able to load it with Class.forName()
from a JSP page and then use DriverManager to get a connection that
works. So that definitely means the driver is found.
What else can cause this?
The only really odd thing I am doing is running Weblogic on OS X,
10.3.7 with all the updates. I know that this Weblogic setup works
since I work on Oracle all day (using the provided Weblogic driver in
8.1SP3). Just when I try to create a Postgresql connection for testing
our app against Postgresql.
I've tried it on Windows with Weblogic 8.1SP3 and it works, so I know
Weblogic is capable of using this driver.
My exact stacktrace is:
java.lang.RuntimeException: Failed to Generate Wrapper Class
at
weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:183)
at
weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:171)
at weblogic.jdbc.pool.Driver.allocateConnection(Driver.java:248)
at weblogic.jdbc.pool.Driver.connect(Driver.java:164)
at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:507)
at weblogic.jdbc.jts.Driver.connect(Driver.java:139)
at
weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:305)
at jsp_servlet.__direct._jspService(direct.jsp:13)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:463)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
at weblogic.jdbc.jts.Driver.wrapAndThrowSQLException(Driver.java:458)
at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:511)
at weblogic.jdbc.jts.Driver.connect(Driver.java:139)
at
weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:305)
at jsp_servlet.__direct._jspService(direct.jsp:13)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:463)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
What is going on at the place where this crashes? Is there a way find
out what class it really can't find?
Thanks,
PatrickPatrick,
1. Could you try to test the postgress connection pool using
"Test Connection" on the pool set up page?
2. Could you compare config.xml for broken and working installations
in part of the connection pool settings?
Regards,
Slava Imeshev
"Patrick Burleson" <[email protected]> wrote in message
Sorry if this comes across twice, I posted it first through the Google Groups interface, but I haven't seen it show up on thedev2dev forum interface. So here it is again.
>
I've read the following threads that seem to be related to this
question:
http://groups-beta.google.com/group/weblogic.developer.interest.jdbc/browse_thread/thread/dc8f0a9ee03e9b9f/f0a70a673db3bb52
http://groups-beta.google.com/group/weblogic.developer.interest.jdbc/browse_thread/thread/4f3b71c77dca30c4/4ed2e1c7b76a0c7b
I also followed the links in the second post ( I also found them via
Google as well ). I've been very sure the Postgresql JDBC driver is
definitely in the class path. I'm able to load it with Class.forName()
from a JSP page and then use DriverManager to get a connection that
works. So that definitely means the driver is found.
What else can cause this?
The only really odd thing I am doing is running Weblogic on OS X,
10.3.7 with all the updates. I know that this Weblogic setup works
since I work on Oracle all day (using the provided Weblogic driver in
8.1SP3). Just when I try to create a Postgresql connection for testing
our app against Postgresql.
I've tried it on Windows with Weblogic 8.1SP3 and it works, so I know
Weblogic is capable of using this driver.
My exact stacktrace is:
java.lang.RuntimeException: Failed to Generate Wrapper Class
at
weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:183)
at
weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:171)
at weblogic.jdbc.pool.Driver.allocateConnection(Driver.java:248)
at weblogic.jdbc.pool.Driver.connect(Driver.java:164)
at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:507)
at weblogic.jdbc.jts.Driver.connect(Driver.java:139)
at
weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:305)
at jsp_servlet.__direct._jspService(direct.jsp:13)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:463)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
at weblogic.jdbc.jts.Driver.wrapAndThrowSQLException(Driver.java:458)
at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:511)
at weblogic.jdbc.jts.Driver.connect(Driver.java:139)
at
weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:305)
at jsp_servlet.__direct._jspService(direct.jsp:13)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:463)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
What is going on at the place where this crashes? Is there a way find
out what class it really can't find?
Thanks,
Patrick -
What is the advantage of using Wrapper Classes ?
Hi friends,
I am happy to join Java/J2EE tech. My project is scaled over the network. MVC-II struts, EJB based architecture, we are using.
We are asked to use Wrapper Classes in in Java programs and not the primitive data types. I could not understand the reason.
Pls tell me what is the advantage of using Wrapper Classes over the primitive data types ?
means Integer instead of int, etc....Hi friends,
I am happy to join Java/J2EE tech. My project is
scaled over the network. MVC-II struts, EJB based
architecture, we are using.
We are asked to use Wrapper Classes in in Java
programs and not the primitive data types. I could
not understand the reason.
Pls tell me what is the advantage of using Wrapper
Classes over the primitive data types ?
means Integer instead of int, etc....I am not sure why use Integer over int; but Wrapper classes are used to remove coupling between classes and create one hand doesn't know what the other hand does effect.
for example:
when you have a SFTP java package but doesn't do everything that your application needs to do in one step and you need to do sftp stuff at many places in your application, it would be wise not to use SFTP java package directly from all the classes that need to do sftp stuff. Because if you were to change the SFTP package later due to say some bug fix or newer version or ... you would have to go and modify all the classes that had sftp stuff to update.
Instead you could write a custom sftp wrapper that handles all the sftp stuff for your application needs and that wrapper deals with the SFTP java package. So all the classes don't need to know which SFTP java package is being used only the custom-wrapper needs to know. -
I am new to the concept of wrapper classes. I have a small spell checker program that I need to access via a servlet by passing a string in and getting a string out with spelling suggestions. I could really use some advice on how to write a servlet that would do such a thing. TIA
grin1dan wrote:
I am new to the concept of wrapper classes. I have a small spell checker program that I need to access via a servlet by passing a string in and getting a string out with spelling suggestions. I could really use some advice on how to write a servlet that would do such a thing. TIABasically, a wrapper class is a class that "wraps" another - otherwise referred to as a "HAS-A" relationship (as opposed to a sub-class, which involves an "IS-A" relationship). It does this by including an instance of the wrapped class as one of its fields.
In many cases, wrapping is actually superior to inheritance.
I don't know how this fits with your servlet, but - assuming that your SpellChecker is implemented as a class - all you need to do is have your servlet define a "spellchecker" field; perhaps something like:
private final SpellChecker spellCheck = new SpellChecker();Probably worth reading up on though. Google "wrapper classes" and "forwarders".
Winston -
Apache comons logging implemented it with a wrapper classes around
hi friends,
i have an interesting (unsually )problem regaurding apache commons logging, i am using three classes .
one is the logger class where i instantiate the logging instance ie Log log = LogFactory .getLog("some name");
then there is a class called LFactory where i use i hashMap to store the various different logger created or to access the different logger for the hashmap
then the last i have i LoggerAccessor class which links the LFactory.
as u all now that the logger will give the line number of the class where we use the log instance ( Log log)..... but as i am using a wrapper classes around the actually log instance.
in any class where i require the logging to be done.. i used my LoggerAccessor. so instead of giving me the Actuall Classname,methodname,and line number of the class where i give logging statements. I get the name of my class where i have created the instance and specially the line number of the class where the instance is created....( means my first class).
i want to get the name,method,linenumber of the class where i have added logging statements
please find me the solution for it.....
thanksGood Question Nutan !! But i don't have answer !! Hope someone else will answer this !
-
Wrapper classes/ instance variables&methods
can anyone provide me additional information on the wrapper classes.
In addition, could someone please provide an explination of the- instance and class (variables+methods)Every primitive class has a wrapper class e.g.
int - Integer
float - Float
long - Long
char - Character
etc. When a primitive is wrapped it becomes an object and immutable. Primitives are generally wrapped (either to make them immutable) or to be able to add them to the collections framework(sets, maps, lists which can only take objects, not primitives).
An instance variable is a variable that each copy of the object you create contains, as is an instance method. Each instance you create (each copy of the object) contains its own copy of the variable and method.
A class variable and method means that no matter how many objects you create, there will be one and only one copy of the variable and method.
Hope this helps. Also see the java tutorial. -
Could not load mediaLib accelerator wrapper classes. Continuing in pure Jav
Can anyone provide an explanation/solution to the following error message:
"Could not load mediaLib accelerator wrapper classes. Continuing in pure Java mode."This problem seems to occur if only the JAI JAR files are installed without the native DLL's. Is there some property that can be passed in to JAI so that it doesn't look for the DLL's? The lookup is causing quite a delay in initial server response time. We don't want to include the DLL's since they are a big pain for our customers to install and the performance issue is not a concern.
Thanks for any help!
-Matt -
Is there an efficient wrapper class for reading binary data in cocoa/iPhone
Hi,
I need to read a data from a binary file in my iPhone application. What is the best way to do it? Is there an efficient cocoa wrapper class for this purpose?
Thanks,
NavaA char is a 16-bit unsigned value - depending on what you want, it may help.
I don't understand your reluctance to mask off the upper 16 bits of an integer; all it requires is a single bitwise 'and' statement. I challenge you to measure the impact of such a statement on your program. -
What exactly is a wrapper class?
In so far as Integer, Byte, Double et al. are concerned I understand that those wrapper classes are a way to handle primitive types as objects. But I've come across references to wrapper classes in documentation and other technical articles and I don't think I really understand what they are really used for. Why do you need a wrapper class for an object?
Could someone shed me some light on this issue?
Thanks,
JohnAn instance of a wrapper class holds a pointer to and instance of some other class or interface and provides access to it, typically supplying methods equivalent to all the methods of the underlying type.
The basic wrapper class a functional replacement for the underlying object.
When you're passed an object from some code outside your control you often don't know what exact class it is, or have access to it's class definition.
A wrapper object allows you to modify the functionality of such an object. You can extend the wrapper class, for example, adding extra methods. Or you can modify the methods, for example to provide logging of calls made.
As a concrete example, I have a wrapper class LoggedConnection which wraps a java.sql.Connection object. It also implements java.sql.Connection. If you ask a LoggedConnection for a Statement or PreparedStatement it fetches the appropriate object and returns a wrapped version which logs the SQL and the execution times etc..
My "get me a connection" routine can return either a raw Connection or a LoggedConnection according to whether a SQL log file is provided.
The main program doesn't need to know if it's using a genuine Connection object or the wrapped version.
Part of the definition would look like:
public class LoggedConnection implements Connection {
private Connection wrappee;
public LoggedConnection(Connection con) {
wrapee = con;
public createStatement() throws SQLExeception {
return new LoggedStatement(wrappee.createStatement())
}(Of course this was tedious to write by hand because Connection has so many methods, all of which the wrapper must implement. Later I wrote a java program to generate Wrapper classes). -
Advantages and disadvantages of wrapper classes
Hi ,
will you please let me know what are the advantages and disadvantages of wrapper classes.
please do needful ASAP.
thanks in advanceHi Anil,
Wrapper classes are classes that allow primitive types to be accessed as objects.
Refer the foll Link:
http://www.cs.wustl.edu/~schmidt/PDF/Reactor1-93.pdf
http://whitepapers.silicon.com/0,39024759,60104914p,00.htm
Regards,
Sunil -
Advantages and disadvantages of wrapper class
Hi ,
will you please let me know what are the advantages and disadvantages of wrapper classes.
please do needful ASAP.
thanks in advanceHi Anil,
Wrapper classes are classes that allow primitive types to be accessed as objects.
Refer the foll Link:
http://www.cs.wustl.edu/~schmidt/PDF/Reactor1-93.pdf
http://whitepapers.silicon.com/0,39024759,60104914p,00.htm
Regards,
Sunil -
Failed to Generate Wrapper Class
Hello,
I am trying to deploy a cmp ejb (attached here) and I always get the following
exception. Can anyone please help?
Julien Martin.
weblogic.management.DeploymentException:
Exception:weblogic.management.ApplicationException: activate failed for account-ejb
Module: account-ejb Error: Exception activating module: EJBModule(account-ejb,status=PREPARED)
Unable to deploy EJB: AccountEJB from account-ejb.jar:
Failed to Generate Wrapper Class.
Nested Exception: java.lang.RuntimeException: Failed to Generate Wrapper Class
at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:141)
at weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:73)
at weblogic.jdbc.jts.Driver.newConnection(Driver.java:674)
at weblogic.jdbc.jts.Driver.createLocalConnection(Driver.java:196)
at weblogic.jdbc.jts.Driver.connect(Driver.java:154)
at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:298)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.getConnection(RDBMSPersistenceManager.java:1841)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.verifyDatabaseType(RDBMSPersistenceManager.java:2025)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.setup(RDBMSPersistenceManager.java:195)
at weblogic.ejb20.manager.BaseEntityManager.setupPM(BaseEntityManager.java:217)
at weblogic.ejb20.manager.BaseEntityManager.setup(BaseEntityManager.java:184)
at weblogic.ejb20.manager.DBManager.setup(DBManager.java:164)
at weblogic.ejb20.deployer.ClientDrivenBeanInfoImpl.activate(ClientDrivenBeanInfoImpl.java:1004)
at weblogic.ejb20.deployer.EJBDeployer.activate(EJBDeployer.java:1322)
at weblogic.ejb20.deployer.EJBModule.activate(EJBModule.java:610)
at weblogic.j2ee.J2EEApplicationContainer.activateModule(J2EEApplicationContainer.java:3012)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2076)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2057)
at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.activateContainer(SlaveDeployer.java:2624)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2547)
at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2349)
at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2431)
at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2343)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2511)
at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:833)
at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:542)
at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:500)
at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2549)
at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2349)
at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2431)
at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2343)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2511)
at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:833)
at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:542)
at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:500)
at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
No Exception Messages
[account-ejb.jar]I would suggest posting in the JDBC newsgroup.
-- Rob
Julien Martin wrote:
Hello,
I am trying to deploy a cmp ejb (attached here) and I always get the following
exception. Can anyone please help?
Julien Martin.
weblogic.management.DeploymentException:
Exception:weblogic.management.ApplicationException: activate failed for account-ejb
Module: account-ejb Error: Exception activating module: EJBModule(account-ejb,status=PREPARED)
Unable to deploy EJB: AccountEJB from account-ejb.jar:
Failed to Generate Wrapper Class.
Nested Exception: java.lang.RuntimeException: Failed to Generate Wrapper Class
at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:141)
at weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:73)
at weblogic.jdbc.jts.Driver.newConnection(Driver.java:674)
at weblogic.jdbc.jts.Driver.createLocalConnection(Driver.java:196)
at weblogic.jdbc.jts.Driver.connect(Driver.java:154)
at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:298)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.getConnection(RDBMSPersistenceManager.java:1841)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.verifyDatabaseType(RDBMSPersistenceManager.java:2025)
at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.setup(RDBMSPersistenceManager.java:195)
at weblogic.ejb20.manager.BaseEntityManager.setupPM(BaseEntityManager.java:217)
at weblogic.ejb20.manager.BaseEntityManager.setup(BaseEntityManager.java:184)
at weblogic.ejb20.manager.DBManager.setup(DBManager.java:164)
at weblogic.ejb20.deployer.ClientDrivenBeanInfoImpl.activate(ClientDrivenBeanInfoImpl.java:1004)
at weblogic.ejb20.deployer.EJBDeployer.activate(EJBDeployer.java:1322)
at weblogic.ejb20.deployer.EJBModule.activate(EJBModule.java:610)
at weblogic.j2ee.J2EEApplicationContainer.activateModule(J2EEApplicationContainer.java:3012)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2076)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2057)
at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.activateContainer(SlaveDeployer.java:2624)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2547)
at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2349)
at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2431)
at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2343)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2511)
at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:833)
at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:542)
at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:500)
at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2549)
at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2349)
at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2431)
at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2343)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2511)
at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:833)
at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:542)
at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:500)
at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
No Exception Messages
Maybe you are looking for
-
Data loading issue from BW Production to BW Sandbox
Hello Guys, I am trying to load data from one info cube (Production) to another info cube (Sendbox) applying update rules for prototype model. I am not getting any error in monitoring window for Info Package. But what I see is '0 from 0 record
-
Keypressed() only working with 'cancel' key
Hi! Good Day! I am trying to make a game using the gameCanvas class, everything is fine except when I try to use the keyPressed() event so that I could evaluate what keys where pressed, unfortunately only the 'Cancel' key works on my program. I am us
-
Can I use SCC-DI01 modules with a PCI-6533 device?
I am looking into performing buffered acquisition of various digital signals using a PCI-6533 device. Can I use SCC-DI01 modules with this device? If so, would this be via the SC-2345 Carrier? The manual seemed to suggest is was only compatible with
-
Lenovo Ideacentre Q150 Multi-Monitor ?
hello, does anybody know if the Lenovo Ideacentre Q150 is able to manage 2 Monitors (first via VGA and second via HDMI)? Grafikchip ION (GeForce 9400M) Speicher (vorhanden) 512 MB Anschlüsse HDMI, VGA thanks
-
Calling two diferent R3 systems for same RFC
Hello Everybody, My scenario is: I have one RFC in two different systems. this is the same RFC available on two systems. I want to call this RFC from the Web dynpro application. System will be determined at runtime to call this RFC. If user selects S