How to get class name of a object in run time, from its accessible context.
Hi,
I need to get the class name of a java object in run-time, given the AccessibleContext of that object.
I gone through the AccessibleContext api documentation. but there is not way to get the class name for a java object using its AccessibleContext object.
Do any one have any idea how to get the class name of an java object, given its accessible object Accessible.
Thanks
Timberlake
816311 wrote:
Please try to provide a solution for my requirement and avoid evaluating a requirement.
I am a curious guyit's great to be curious. however, in this situation, the requirement makes no sense in the given context. so, in an effort to be helpful, the people on this forum are asking you the reason behind the requirement. the reason we do this is because we have experience answering questions on this forum and, more often than not, requirements which don't make sense are the result of misunderstandings or confusion on the part of the person making the requirement. if we can figure out why you want to do what you want to do, we may be able to point you in a direction which makes more sense.
Similar Messages
-
How to get CLASS name for the generic item?
Hi,
I wrote following method to create a service instance.
public static <IType> IType GetServiceInstance()
IType type=null;
try
InitialContext ic=new InitialContext();
//ERROR: type= ic.lookup(IType.class.getName());
catch(Exception ex)
//do handle
return type;
}please see the //Error: here its giving error, also i m not getting "class" variable in IDE!!!
i want use like this;
IUserService userService=ServiceFactory.GetServiceInstance<IUserService>();so how can i do this?
Edited by: Manikandan.Java on Oct 31, 2007 3:02 AMI don't know if I understand your question, but you cannot find the class name because it is in run time just an object. You can, however, check if it is an instanceof.
if (genericType instanceof MyType) {
doMyThing();
} -
9I: How can get the names of all objects in a package header? [RESOLVED]
Is there a way to get the names fo all objects (function, procedures) from package header
select * from user_objects only gives the the header name, I need the object in the header.
John
Message was edited by:
johnminkjanHere is an example with dbms_output package!
SQL> select owner, object_name,procedure_name from all_procedures
2 where object_name='DBMS_OUTPUT';
OWNER OBJECT_NAME PROCEDURE_NAME
SYS DBMS_OUTPUT GET_LINES
SYS DBMS_OUTPUT GET_LINE
SYS DBMS_OUTPUT NEW_LINE
SYS DBMS_OUTPUT PUT_LINE
SYS DBMS_OUTPUT PUT_LINE
SYS DBMS_OUTPUT PUT
SYS DBMS_OUTPUT PUT
SYS DBMS_OUTPUT DISABLE
SYS DBMS_OUTPUT ENABLE
9 rows selected.
"or"
SQL> desc dbms_output -
How to build sql query for view object at run time
Hi,
I have a LOV on my form that is created from a view object.
View object is read-only and is created from a SQL query.
SQL query consists of few input parameters and table joins.
My scenario is such that if input parameters are passed, i have to join extra tables, otherwise, only one table can fetch the results I need.
Can anyone please suggest, how I can solve this? I want to build the query for view object at run time based on the values passed to input parameters.
Thanks
Srikanth AddankiAs I understand you want to change the query at run time.
If this is what you want, you can use setQuery Method then use executeQuery.
http://download.oracle.com/docs/cd/B14099_19/web.1012/b14022/oracle/jbo/server/ViewObjectImpl.html#setQuery_java_lang_String_ -
How to get Class Name given along with java.exe
Hi friends,
I am Mukesh, currently facing one problem
On command prompt to execute any java program we give :
C : \.-- > java ClassName
This ClassName I need in my application, I want to do some post processing on that.
Actually see what I want :
public class Base
static Base object;
public static void main(String[] args) throws Exception
object=(Base)Class.forName("Derived Class Name").newInstance();
void main()
public class Derived extends Base
void main()
System.out.println("Hello World");
I am trying to Run Derived Class, since there is no entry point found, default JVM invoke the Base class's entry point, there I want to load
Derived Class, but I am not getting any identity of derived class in Base class.
I found one temporary solution to this problem :
C: \ -- >java Derived Derived
& in Base class, I have loaded class
object=Class.forName(args[0]).newInstance();
But I dont want to write the same thing twise just to know the Class name which is given along with java.exe.
Is there any way to get the ClassName supplied with java.exe
I have tried a lot, still I am trying !!!
If any one knows the answer, help me.
Regards.
Mukesh.Multiple post. Please continue in other thread
http://forum.java.sun.com/thread.jspa?threadID=5196980&tstart=0 -
How to get class name and method name within a class method?
Hi,
In a java class, is it possible to get its class name and the class method?
Please advise.
Thank you.I mean whether there's any built-in command that will
return the class name instead of code it ourself, for
easier maintenance.
Possible?
this.getClass().getName(); -
How to get class names in a package ?
If I know a name of a package , is it possible for me to get all the classes in the package ?
YTes...
u can do so,,in SE80..
Give your package for the Dev Class.
Then check under Class Libraray...
Hope it helps.
Praveen -
How to get Database name/IP address of the database server from forms10g
Hi everybody,
How do I get the database instance name and IP address of the database server?
I am using Foms 10g and the database server is Oracle 10g.
SukantaDear...........
Plz use this code
select SYS_CONTEXT('USERENV', 'IP_ADDRESS', 15) ipaddr from dual;
SELECT utl_inaddr.get_host_address IP ,UTL_INADDR.get_host_name NAME FROM dual;
select SYS_CONTEXT('USERENV', 'HOST') HELLO from dual;
select SYS_CONTEXT('USERENV', 'TERMINAL') HELLO from dual;
select SYS_CONTEXT('USERENV', 'OS_USER') HELLO from dual;
SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER') FROM DUAL;
SELECT SYS_CONTEXT ('USERENV', 'DB_UNIQUE_NAME') FROM DUAL;
thx. -
How to get the name of the clicked menu option dynamically from oracle form
Hi folks,
I need to know inside the forms which one was the menu option clicked by the user to open the module.
Is that possible?
Thanks a lot,
Abdel Miranda
PanamaI don't think that's possible but since you can't create menu items at runtime it's not relevant. Just set a global variable to the menu item's name in the code of each menu item.
-
How to create object by getting class name as input
hi
i need to create object for the existing classes by getting class name as input from the user at run time.
how can i do it.
for exapmle ExpnEvaluation is a class, i will get this class name as input and store it in a string
String classname = "ExpnEvaluation";
now how can i create object for the class ExpnEvaluation by using the string classname in which the class name is storted
Thanks in advancei think we have to cast it, can u help me how to cast
the obj to the classname that i get as inputThat's exactly the point why you shouldn't be doing this. You can't have a dynamic cast at compile time already. It doesn't make sense. Which is also the reason why class.forName().newInstance() is a very nice but also often very useless tool, unless the classes loaded all share a mutual interface. -
How to get the name of the class which is currently in use
Hi all,
I have two classes Mother and Child, and I use this code to print the name of the class in use
DATA m TYPE REF TO zmother.
DATA class_name type string VALUE 'CHILD'.
CREATE OBJECT m TYPE (class_name).
CALL METHOD m->PrintName .
So, what is the source code that I have to put in the PrintName methode?
Thanks.Ok, but how can I get the name of the object class that calls the methode!
REPORT ztest_method.
* CLASS c1 DEFINITION
CLASS c1 DEFINITION.
PUBLIC SECTION.
METHODS: get_data.
ENDCLASS. "c1 DEFINITION
* CLASS c1 IMPLEMENTATION
CLASS c1 IMPLEMENTATION.
METHOD get_data.
****** What is the code to put here to know the name of this Class?*
ENDMETHOD. "get_data
ENDCLASS. "c1 IMPLEMENTATION
DATA oref TYPE REF TO object.
DATA: method TYPE string.
DATA: cla_name(20).
START-OF-SELECTION.
cla_name = 'C1'.
CREATE OBJECT oref TYPE (cla_name).
BREAK-POINT.
CALL METHOD oref->(method). -
How do you get the name of an object?
if i create an object...
Obj1 = new MyObject();
is there some way to get the name of the
object "Obj1" inside the object.
thanks for any help.is your example. Obj1 is the name you have given to a reference of an object. You could have said "fred = new MyObject()" right? The compiler doesn't deal with these high level names you gave your objects for the most part. It throws them away. So there is no way to get back the name from inside the object. You can get the name of the type of object from inside it though. If need be. this.getClass().getName() will be the fully qualified type of the object.
-
How to get the values of the objects inside an object??
Hi,
I am trying to write code to display name and memory usage of all session attributes, in a recursive way.
I suppose reflection is needed here, but I cant figure out how to get the values of the objects inside an object...
private void handleIt(String attributeName, Object attributeValue) {
boolean isPrimitiveOrNull = ((null == attributeValue) ||
(attributeValue.getClass().isPrimitive()));
if (isPrimitiveOrNull) {
sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "}");
} else {
sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "{");
Field[] fields = attributeValue.getClass().getDeclaredFields();
int lim = fields.length;
String name;
Object value = null;
for (int i = 0; i < lim; i++) {
name = fields.getName();
//LOOK AT THIS LINE: !!!!!!!!!!!!!!!!!!!!!!!!!!!
value = fields[i].get(obj); //I don´t know what 'obj' should be??
handleIt(name, value);
sb.append("}");
Any suggestions will be greatly appreciated...I realized that massive int objects called MAX_VALUE, MIN_VALUE and SIZE where causing the StackOverflow, so I removed them from the analysis.
This is the resultant code. But I think it isnt accurate in calculating the real size of objects being got using reflexion.
Do you or somebody have any more suggestions?
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class SessionMeasurer extends HttpServlet {
private static final long serialVersionUID = 1470488362727841992L;
private StringBuilder sb = new StringBuilder();
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
performTask(request, response);
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
performTask(request, response);
public void performTask(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession(false);
String attributeName = "";
Object attributeValue = null;
for (Enumeration<?> attributeNames = session.getAttributeNames(); attributeNames.hasMoreElements();) {
attributeName = (String)attributeNames.nextElement();
attributeValue = session.getAttribute(attributeName);
handleIt(attributeName, attributeValue);
System.out.println(sb.toString());
private void handleIt(String attributeName, Object attributeValue) {
if (attributeValue != null) {
boolean isPrimitive = attributeValue.getClass().isPrimitive();
if (isPrimitive) {
sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "}");
} else {
sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "{");
Field[] fields = attributeValue.getClass().getDeclaredFields();
String name;
Object value = null;
int lim = fields.length;
for (int i = 0; i < lim; i++) {
name = fields.getName();
if (!name.endsWith("_VALUE") && !name.equals("SIZE") && !name.equals("serialVersionUID")) {
try {
value = fields[i].get(attributeValue);
} catch(Exception e) {
//PENDIENTE: Tratamiento excepción
handleIt(name, value);
sb.append("}");
private int sizeOf(Object obj) {
//Valid only for Serializables
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
byte[] bytes = null;
try {
oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
bytes = baos.toByteArray();
} catch(Exception e) {
//PENDIENTE: Tratamiento excepción
} finally {
if (oos != null) {
try {
oos.close();
} catch(Exception e) {
//PENDIENTE: Tratamiento excepción
if (baos != null) {
try {
baos.close();
} catch(Exception e) {
//PENDIENTE: Tratamiento excepción
int size = -1;
if (bytes != null) {
size = bytes.length;
return size; -
Getting class name without it's package.
Hi.
How can I get only class name of an object?
obj.getClass().getName() returns the full package hierarchy.
Any simple ideas?Is there any method that do it automatically?What do you mean automatically? You mean a single method so that you don't have to write any code? That's a very small amount of code to write, and you can put it inside a method you create yourself.
Or you could use regex, though some may find that to be overkill. String classOnly = theClass.getName().replaceAll(".*\\.(.*)", "$1"); -
How to get the name of a Data Element of a generic Table!
Hi guys!
In my function i have the following import paramenter
i_outtab type standard table
now i import a table and i want to get the dataelement of the fields.
is there a way to do this??Hello Thomas
Perhaps the following sample report may be useful for you.
*& Report ZUS_SDN_RTTI_STRUCT_COMPONENTS
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1145711"></a>
*& Thread: How to get the name of a Data Element of a generic Table!
REPORT zus_sdn_rtti_struct_components.
TYPE-POOLS: abap.
TYPES: BEGIN OF ty_s_outtab.
TYPES: bukrs TYPE bukrs.
TYPES: kunnr TYPE kunnr.
TYPES: END OF ty_s_outtab.
DATA: gdo_data TYPE REF TO data.
DATA: gs_outtab TYPE ty_s_outtab.
DATA: go_typedescr TYPE REF TO cl_abap_typedescr,
go_structdescr TYPE REF TO cl_abap_structdescr,
go_datadescr type ref to cl_abap_datadescr.
DATA: gs_comp TYPE abap_compdescr,
gd_dtel type string,
gt_dfies type ddfields.
FIELD-SYMBOLS:
<gs_struct> TYPE ANY.
START-OF-SELECTION.
BREAK-POINT.
GET REFERENCE OF gs_outtab INTO gdo_data.
ASSIGN gdo_data->* TO <gs_struct>.
go_typedescr = cl_abap_typedescr=>describe_by_data( <gs_struct> ).
go_structdescr ?= go_typedescr.
BREAK-POINT.
LOOP AT go_structdescr->components INTO gs_comp.
go_datadescr = GO_STRUCTDESCR->GET_COMPONENT_TYPE( gs_comp-name ).
gd_dtel = go_datadescr->get_relative_name( ).
write: / syst-tabix, 'Data element =', gd_dtel.
ENDLOOP.
END-OF-SELECTION.
Regards
Uwe
Maybe you are looking for
-
Hi guys, I'm facing 1 problem in Pricing Proce need ur guidance We have a scenario where we need to calculate the Freight amount for a sales Order only in the 1st Billing Document of the SO ,which is create in ref to the Delivery doc. For all the ne
-
I installed elements 12 on a Win 8.1 computer and moved all my photos from my old XP machine. I updated to elements 12.1. Now, many/most of my photos will not open because I do not have "permission" to open the files. How do I fix this so I can wo
-
*** [BLANK Subject]
Dear support, I just made a fresh and clean install of Windows 7 32bit RTM German. I have a <span class="mainlink">Sound Blaster X-Fi XtremeMusic and right after installing the latest driver from creative.com, it is not possible to start the Control
-
My 6th generation iPod nano won
I'm unable to use the "shuffle" feature on my 6th generation iPod nano. Any thoughts?
-
Integer parameters not acceptible in WHERE clause with TO_DATE function.
Please tell me why the following query is not acceptible in a BI Publisher (11.1.1.5) data set. SELECT * FROM all_tables WHERE LAST_ANALYZED >= TO_DATE(:yyyy || '-' || :startmo || '-' || :startday, 'YYYY-MM-DD') AND LAST_ANALYZED < TO_DATE(:yyyy || '