gnu.CORBA

Class ObjectCreator


public class ObjectCreator
extends Object

Creates java objects from the agreed IDL names for the simple case when the CORBA object is directly mapped into the locally defined java class.

Field Summary

static String
CLASSPATH_PREFIX
The prefix for classes that are placed instide the gnu.CORBA namespace.
static String
JAVA_PREFIX
The standard java prefix.
static String
OMG_PREFIX
The standard OMG prefix.
static Map<K,V>
m_classes
Maps IDL strings into known classes.
static Map<K,V>
m_helpers
Maps IDL types to they helpers.
static Map<K,V>
m_names
Maps classes to they IDL or RMI names.

Method Summary

static Object
Idl2Object(String IDL)
Converts the given IDL name to class name, tries to load the matching class and create an object instance with parameterless constructor.
static Class<T>
Idl2class(String IDL)
Converts the given IDL name to class name and tries to load the matching class.
static Object
createObject(String idl, String suffix)
Try to instantiate an object with the given IDL name.
static Class<T>
findHelper(String idl)
Find helper for the class with the given name.
static Class<T>
forName(String className)
Load the class with the given name.
static String
getDefaultName(String idl)
Get the type name from the IDL string.
static String
getRepositoryId(Class<T> cx)
Convert the class name to IDL or RMI name (repository id).
static void
insertException(Any into, Throwable exception)
Insert this exception into the given Any.
static boolean
insertSysException(Any into, SystemException exception)
Insert the system exception into the given Any.
static boolean
insertWithHelper(Any into, Object object)
Insert the passed parameter into the given Any, assuming that the helper class is available.
static SystemException
readSystemException(InputStream input, ServiceContext[] contexts)
Read the system exception from the given stream.
static UserException
readUserException(String idl, InputStream input)
Reads the user exception, having the given Id, from the input stream.
protected static String
toClassName(String prefix, String IDL)
Converts the given IDL name to class name.
static String
toHelperName(String IDL)
Gets the helper class name from the string like 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0'
static void
writeSystemException(OutputStream output, SystemException ex)
Writes the system exception data to CDR output stream.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

CLASSPATH_PREFIX

public static final String CLASSPATH_PREFIX
The prefix for classes that are placed instide the gnu.CORBA namespace.
Field Value:
"gnu.CORBA."

JAVA_PREFIX

public static final String JAVA_PREFIX
The standard java prefix.
Field Value:
"org.omg."

OMG_PREFIX

public static final String OMG_PREFIX
The standard OMG prefix.
Field Value:
"omg.org/"

m_classes

public static Map<K,V> m_classes
Maps IDL strings into known classes. The map must be weak to ensure that the class can be unloaded, when applicable.

m_helpers

public static Map<K,V> m_helpers
Maps IDL types to they helpers.

m_names

public static Map<K,V> m_names
Maps classes to they IDL or RMI names. Computing RMI name is an expensive operations, so frequently used RMI keys are reused. The map must be weak to ensure that the class can be unloaded, when applicable.

Method Details

Idl2Object

public static Object Idl2Object(String IDL)
Converts the given IDL name to class name, tries to load the matching class and create an object instance with parameterless constructor. The OMG prefix (omg.org) is replaced by the java prefix org.omg. No other prefixes are added.
Parameters:
IDL - the idl name.
Returns:
instantiated object instance or null if such attempt was not successful.

Idl2class

public static Class<T> Idl2class(String IDL)
Converts the given IDL name to class name and tries to load the matching class. The OMG prefix (omg.org) is replaced by the java prefix org.omg. No other prefixes are added.
Parameters:
IDL - the idl name.
Returns:
the matching class or null if no such is available.

createObject

public static Object createObject(String idl,
                                  String suffix)
Try to instantiate an object with the given IDL name. The object must be mapped to the local java class. The omg.org domain must be mapped into the object in either org/omg or gnu/CORBA namespace.
Parameters:
idl - name
Returns:
instantiated object instance or null if no such available.

findHelper

public static Class<T> findHelper(String idl)
Find helper for the class with the given name.

forName

public static Class<T> forName(String className)
            throws ClassNotFoundException
Load the class with the given name. This method tries to use the context class loader first. If this fails, it searches for the suitable class loader in the caller stack trace. This method is a central point where all requests to find a class by name are delegated.

getDefaultName

public static String getDefaultName(String idl)
Get the type name from the IDL string.

getRepositoryId

public static String getRepositoryId(Class<T> cx)
Convert the class name to IDL or RMI name (repository id). If the class inherits from IDLEntity, ValueBase or SystemException, returns repository Id in the IDL:(..) form. If it does not, returns repository Id in the RMI:(..) form.
Parameters:
cx - the class for that the name must be computed.
Returns:
the idl or rmi name.

insertException

public static void insertException(Any into,
                                   Throwable exception)
Insert this exception into the given Any. On failure, insert the UNKNOWN exception.

insertSysException

public static boolean insertSysException(Any into,
                                         SystemException exception)
Insert the system exception into the given Any.

insertWithHelper

public static boolean insertWithHelper(Any into,
                                       Object object)
Insert the passed parameter into the given Any, assuming that the helper class is available. The helper class must have the "Helper" suffix and be in the same package as the class of the object being inserted.
Parameters:
into - the target to insert.
object - the object to insert. It can be any object as far as the corresponding helper is provided.
Returns:
true on success, false otherwise.

readSystemException

public static SystemException readSystemException(InputStream input,
                                                  ServiceContext[] contexts)
Read the system exception from the given stream.
Parameters:
input - the CDR stream to read from.
contexts - the service contexts in request/reply header/
Returns:
the exception that has been stored in the stream (IDL name, minor code and completion status).

readUserException

public static UserException readUserException(String idl,
                                              InputStream input)
Reads the user exception, having the given Id, from the input stream. The id is expected to be in the form like 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0'
Parameters:
idl - the exception idl name.
input - the stream to read from.
Returns:
the loaded exception.

toClassName

protected static String toClassName(String prefix,
                                    String IDL)
Converts the given IDL name to class name.
Parameters:
IDL - the idl name.

toHelperName

public static String toHelperName(String IDL)
Gets the helper class name from the string like 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0'
Parameters:
IDL - the idl name.

writeSystemException

public static void writeSystemException(OutputStream output,
                                        SystemException ex)
Writes the system exception data to CDR output stream.
Parameters:
output - a stream to write data to.
ex - an exception to write.

ObjectCreator.java -- Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.