Getting fully qualified name from class' byte code

Heya,
In one of my previous postings, I was asking if anybody knows a way how to get fully gualified name (e.g. java.lang.Object) of byte[] representing bytecode of the class.
I found a way how to get it. It's a workaround, but it works.
I mention it here, so that if anybody needs, he/she doesn't need to invent it again.
And if anybody knows better way how to do it, I'm always interested.
here comes the code:
public String getFullClassName(byte[] classByteCode) {
    Class newClass = null;
    try {
        // ClassName can NEVER start with number - this will always fail
        newClass = this.defineClass("1",classByteCode,0,classByteCode.length);
    } catch (NoClassDefFoundError noClassDefErr) {
        String message = noClassDefErr.getMessage(); // '1 (wrong name: com/foo/MyClass)'
        String messagePropolg = "wrong name: ";
        String className = message.substring(message.indexOf(messagePropolg)+messagePropolg.length(),message.length()-")".length());
        className = className.replace('/','.');
        return className;
    } catch (ClassFormatError err) {
        err.printStackTrace();
    if (newClass==null) return null;
    return newClass.getName();// should never get here. it's just to make it compile
}Michal

Heya,
In one of my previous postings, I was asking if
anybody knows a way how to get fully gualified name
(e.g. java.lang.Object) of byte[] representing
bytecode of the class.
Why don't you just read the name?
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#80959
From the class structure you get field this_class.
You use that to get the pool entry for the CONSTANT_Class_info structure. From that you get the name_index which gives you an entry into the pool for a CONSTANT_Utf8_info (which contains the name)...
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#7963

Similar Messages

  • How to get fully qualified name for a class with just the class name

    I want to get the fully qualified name of the class at runtime. The only piece of information which I have is the class name.
    I want to create a runtime instance of a class with the class name [Just the class name].
    Is there is any way to achieve this using ClassLoader?
    Could anyone suggest me an idea?
    Cheers,
    Vinn.

    Nope. If you are given "List", will you decide that means "java.util.List" or "java.awt.List"? Of course you could prompt the user to make the decision for you, I suppose. But using a class loader isn't going to make the task any easier.

  • How Oracle Installation cannot get fully qualified name of the server?

    Hi,
    I'm installing Oracle Internet Application Server (10.1.2) on Windows. The Win machine has fully qualified name as myserver.mydomain.com
    However, after the installation, Oracle shows that the URL to Internet Application Server is only
    http://myserver:7777
    I have changed the hosts file of the Win machine and add the line, e.g.,
    10.1.10.10 myserver.mydomain.com myserver
    where 10.1.10.10 is the IP of the Win machine.
    I re-install Oracle Internet Application Server again, but it still cannot picks up the fully qualified name as myserver.mydomain.com for the URL of Internet Application Server page.
    Any ideal?

    I'm installing Oracle Internet Application Server (10.1.2) on Windows. The Win machine has fully qualified name as myserver.mydomain.com
    I have changed the hosts file of the Win machine and add the line, e.g.,
    10.1.10.10 myserver.mydomain.com myserverInstead, use the following in your hosts file, and then try again.
    10.1.10.10 myserver.mydomain.com # myserver

  • Getting Package Name From Class File Without Parsing File

    I am writing an application where I need to get the package name from a class file without parsing the class file itself.
    Basically, what happens is the user chooses a class file from anywhere in the file system. I then want to use reflection to get information about that class. To do that I need the fully qualified class name. I know that the package name is part or all of the path name but I don't know for sure which part it is. I don't want to parse the class file directly for the package name in case the class file spec is changed (that way I won't have to rewrite any code).
    Does Java have any way of getting this information without doing something stupid like gradually stripping off part of the pathname and trying it?

    The ClassLoader way seems to work fine, copy a class file to "A.class" and run this:import java.io.*;
    class ClassLoaderExample {
        public static void main(String[] args) throws Exception {
            class MyClassLoader extends ClassLoader {
                public Class load() throws IOException {
                    File f = new File("A.class");
                    byte[] classData = new byte[(int) f.length()];
                    new RandomAccessFile(f, "r").readFully(classData);
                    Class loaded = defineClass(null, classData, 0, classData.length);
                    resolveClass(loaded);
                    return loaded;
            Class c = new MyClassLoader().load();
            System.out.println(c);
            System.out.println(c.newInstance());
    }

  • Fully-qualified name of a class not in a package

    I have a class PackageNodeCreator and a class that's in a package called com.alex.PackageNodeCreator. I'm want to callthe first one (that's not in a package) like this...
    PackageNodeCreator pnc=new PackageNodeCreator();
    but I get this error:
    symbol 'PackageNodeCreator' is ambiguous, found matching classes com.alex.PackageNodeCreator and PackageNodeCreator. Use fully-qualified name to disambiguate.
    What is the fully qualified name of the PackageNodeCreator that's not in a package??
    Message was edited by:
    eggie5

    Since 1.4 a change in the import structure actually
    makes it impossible for a class in a package to
    reference a class in the default package.Yep.
    The choices are
    1. Put it in a package.
    2. Create a wrapper that does have a package. Use a compiler before 1.4 to compile it. Use the compiled version only in the new code.
    3. Don't use it.

  • Compile error when using a class by fully-qualified name

    Hi... Is it an AS3 "feature" or a FB compiler bug that I cannot use a class without importing it?
    I have a statement such as
    if (de.codebank.util.StringUtilities.startsWith(status.name, phase.name+"_"))
    which does not compile until I import the StringUtilities class, which is pointless, of course.
    The compile error mentions an unknown property "util"

    I believe this is how AS3 works. Fully qualified class types require import statement.
    You use fully qualified name whenever you want to avoid ambiguity.
    However, when the code is like,
    import mx.collections.XMLListCollection;
    var arr:mx.collections.ArrayCollection;
    It works since compiler now understands that "mx.collections" is a package.

  • Class names - why is the fully qualified name required?

    Hello,
    Why is the fully qualified name required? I thought that if the class was imported, it was not necessary to fully qualify it in a method call.
    Since I have these import statement in my java class:
    import javax.swing.*;
    import javax.swing.border.*;
    //I was wondering what the reason is that "javax.swing.border." is required in the following:
    jsectionPanel.setBorder(new javax.swing.border.TitledBorder(
                                      new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED, Color.black, Color.black,
                                                      Color.lightGray,
                                                      Color.lightGray),
                          "Section Data",
                          javax.swing.border.TitledBorder.CENTER,         //int titleJustification,
                          javax.swing.border.TitledBorder.TOP,           //int titlePosition,
                          new Font("Dialog",0,11),          //Font titleFont,
                          new Color(0,51,255)));
    //Thanks,
    -- HSC --

    I guess there must have been something else conflicting at the time I tried because it would not compile, however, it works fine now.
    Chalk it up to the ghost in the machine.
    - I am using Windows ME afterall! :)
    thanks,
    -- HSC --

  • Difference between fully qualified name and Canonical name

    CAn annyone xplain Difference between fully qualified name and Canonical name

    If you dont know then don't replyYou were given a link directly to the answer. The state of my knowledge is therefore (a) irrelevant and (b) not proven by anything in this thread.
    Who asked [you] to reply
    You* did, when you posted here.
    I know how to get from java language specificationClearly not, or you wouldn't still be posting here.
    I need clarification for what is in java lang specification..It seems clear enough to me. What part of "A member class or member interface M declared in another class C has a canonical name if and only if C has a canonical name. In that case, the canonical name of M consists of the canonical name of C, followed by ".", followed by the simple name of M." didn't you understand?

  • How to get Universe Long Name from DataProvider from BO SDK Web XI R3

    In BO 6.5 I was able to query the repository using an Oracle query to get details about the classes, property(s) and property data value(s). I'm using the following query:
    SELECT DISTINCT u.uni_longname, c.cls_name, p.prp_name, p.property_id,
                    d.prp_datavalue
               FROM unv_universe@PRBA u,
                    unv_class@PRBA c,
                    unv_property@PRBA p,
                    unv_prop_data@PRBA d
              WHERE c.universe_id = u.universe_id
                AND c.universe_id = p.universe_id
                AND c.class_id = p.class_id
                AND p.universe_id = d.universe_id
                AND p.property_id = d.property_id
                AND d.prp_datatype = 'W'
           ORDER BY 1, 2
    where PRBA is our BO oracle repository. It would return the following, though I get multiple rows for this query, I am pasting one row only
    UNI_LONGNAME          CLS_NAME            PRP_NAME               PROPERTY_ID      PRP_DATAVALUE
    Accounting Universe   Account Details     Account Option     15                      ACCT.ACCT_ID  IN  @Prompt('ACCOUNT_OPTION','N', ['Account Details\Account ID'],multi,free)
    I'm wondering what is the equivalent methods/objects using BO Java SDK in Webi XI R3 to get the same information. I use the above information to delete the prompts for which user has not provided a value.
    Also I need to know, Is it possible to get Univers Long Name from DataProivder, then from Univers Long Name, will I be able to get the above Records Set? Is this possible in BO SDK Webi XI R3?
    My requirement is, I have BO Prompts and I need to remove certain prompts which are not supplied by the User, for example if I need to remove ACCOUNT_OPTION, I iterate the record set, as long as ACCOUNT_OPTION is there in PRP_DATAVALUE then I would remove the Filter Condition.Can anyone help me out on this? Rightnow This is a show stopper for me.
    Thanks

    Thanks for your reply, NO Java SDK means, what is it not possible? and what is possible through COM SDK?
    my requirement is, I need to remove certain Filter condition for a DataProvider, for example, ACCOUNT_OPTION is the name of the field, but through JAVA SDK, I am getting Account Option ,
    I have been trying the below code, Can anyone help me out what am I doing wrong? I could not go further.
    ACTXTRACTCon is my list of arrays, these prompts have to be removed from BO Prompts. Although I wanted to post my entire code, for some reason I could not embed the code. This code may have some compilation errors.
         // Get Providers from DocumentInstance
                   DataProviders oProviders = oDoc.getDataProviders();
                   int iDataProviderIndex = 0;
                   int iQueryCount = 0;
                   int iQueryIdx = 0;
                   Query oQuery = null;
                   // Declare ConditionContainer
                   ConditionContainer oCC = null;
                   int iCCIndex = 0;
                   FilterConditionNode oFCN = null;
                   ConditionObject oCO = null;
    String ACTXTRACTCon [] ={                    
                   "PRINTER_NAME",
                   "PARTNER_RANK",
                   "PARTNER_DOMICILE",
                   "TO_GL_CYCLE_DT",
                   "ENTITY_OPTION",
                   "LONG_MEMO",
                   "SHORT_MEMO",
                   "ENTITY_TYPE",
                   "POST_END_DT",
                   "TCODE_TYPE",
                   "ACCOUNT_OPTION",
                   "PARTNER_STATUS",
                   "ACCT_TYPE",
                   "POST_BEGIN_DT",
                   "TCODE_OPTION",
                   "FROM_GL_CYCLE_DT",
                   "PARTNER_TYPE"
    while (iDataProviderIndex <= oProviders.getCount()-1){
                        // Get DataProvider from DataProviders
                        DataProvider oProvider = oProviders.getItem(iDataProviderIndex);
                        // Get Query from DataProvider
                        QueryContainer oQuerys = oProvider.getCombinedQueries();
                        System.out.println("oProvider------->"+oProvider);
                        System.out.println("oProvider.getName().."+oProvider.getName());
                        System.out.println("oProvider.getDataSource().getLongName().."+oProvider.getDataSource().getLongName());
                        System.out.println("oProvider.getDataSource().getUniverseID().."+oProvider.getDataSource().getUniverseID());
                        iQueryCount = oQuerys.getChildCount();
                        if (iQueryCount > 0) {                         
                             // Loop through Query to get ConditionObject
                             for (iQueryIdx = 0; iQueryIdx <= iQueryCount - 1; iQueryIdx++) {
                                  oQuery = (Query)oQuerys.getChildAt(iQueryIdx);
                                  oCC = oQuery.getCondition();
                                  if (oCC != null){                              
                                       // Only Leaf object has condition
                                       if (!oCC.isLeaf()){
                                            // Loop through ConditionContainer to get all conditions
                                            int iCCCount = oCC.getChildCount();
                                            int iRevCCIndex = 0;
                                            //Removing universe level conditions
                                            for (iCCIndex = 0; iCCIndex <= iCCCount-1; iCCIndex++){
                                                 iRevCCIndex= iCCCount - iCCIndex -1;
                                                 oFCN=oCC.getFilterConditionNode(iRevCCIndex);
                                                 if (oFCN instanceof ConditionObject) {
                                                      oCO = (ConditionObject)oFCN;
                                                      FilterCondition oOperand=(FilterCondition)oCO.getOperand();
                                                      System.out.println("oOperand.."+oOperand);
                                                      for (int iRow = 0; iRow <= ACTXTRACTCon.length - 1; iRow++){     
                                                           if (oCO.getName().trim().toString().equals(ACTXTRACTCon[iRow])){
                                                                oFCN.remove(oCO);
                                                                break;
                                            // Removing report level conditions
                                            iCCCount = oCC.getChildCount();
                                            for (iCCIndex = 0; iCCIndex <= iCCCount-1; iCCIndex++){
                                                 iRevCCIndex= iCCCount - iCCIndex -1;
                                                 oFCN=oCC.getFilterConditionNode(iRevCCIndex);
                                                 if (oFCN instanceof ConditionObject){
                                                      oCO = (ConditionObject)oFCN;
                                                      FilterCondition oOperand=(FilterCondition)oCO.getOperand();
                                                      if (oOperand != null){
                                                           int iOperandCount = oOperand.getOperandCount();
                                                           int iRevOperandIdx = 0;
                                                           boolean bBreakInd = false;
                                                           for (int iOperandIdx = 0; iOperandIdx <= iOperandCount-1; iOperandIdx++){
                                                                // Removing conditions start with high index
                                                                iRevOperandIdx = iOperandCount - iOperandIdx - 1;
                                                                for (int iRow = 0; iRow <= ACTXTRACTCon.length-1 ; iRow++){                                                                 
                                                                     if (oOperand.getOperand(iRevOperandIdx).toString().equals(ACTXTRACTCon[iRow])){
                                                                          oFCN.remove(oCO);
                                                                          bBreakInd = true;
                                                                          break;
                                                                if (bBreakInd == true){
                                                                     // Exit from loop if condition has been removed
                                                                     break;
                        // fetch the changes
                        oProvider.runQuery();
                        iDataProviderIndex++;
                        System.out.println("Data Provider Index = " + iDataProviderIndex);
    Thanks
    Gokul.
    Edited by: mgggkn on Jul 11, 2011 8:18 PM

  • Fully qualified name of the portal service application

    Hi,
    I want to Access portal Services from Web dynpro, for Which we have to provide Sharing reference,
    this would be
    PORTAL:<Vendor name>/<Fully qualified name of the portal service application>
    my question is how to find out "Fully qualified name of the portal service application"
    regards,
    Venki.

    Venki,
    Please refer this thread.
    Re: Changes are not getting reflected in theme
    We cannot access the portal service in the browser as the service wont produce any http request. Instead you can access & utilize  the service in the the portal component such as JSP Dunpage etc.  which will produce the http request and display the result or o/p  on the broswer.
    Ramganesan Karuppaiyah

  • How to get the Users Name from the SSL certificate?

    Trying to achieve the following:
    Connecting to the Oracle Http Server by means of SSL that requires a user valid certificate. Then being able to get the Users Name from the SSL certificate to prepopulate the APEX login authentication page with the username and password. Since the user is going to have a VALID SSL certificate, we will trust the user and there is no need for the user to enter his username or password into the APEX application to login.
    Does SSO do this or something else?

    Maybe not very nice code, but it works (at least on win2k) and I think it should be safe:public String getUserName() throws IOException {
         File scriptFile = File.createTempFile("script", ".js");
         FileWriter fw = new FileWriter(scriptFile);
         fw.write ("WScript.Echo(WScript.CreateObject('WScript.Network').UserName)");
         fw.flush();
         fw.close();
         BufferedReader br = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("CSCRIPT.EXE \"" + scriptFile + "\" //Nologo").getInputStream()));
         String uName = br.readLine();
         br.close();
         scriptFile.delete();
         if (scriptFile.exists()) scriptFile.deleteOnExit();
         return uName;
    }

  • Register system to SLD with fully qualified name

    Anybody know how to register the host name for an abap system to the SLD so it uses the fully qualified DNS name?   According to the help files in the SLD, it say's:   "By default, host names in SLD are written lower case without any network domain"
    Our SAP servers are in:
    ex.) abc.domain.com
    Our desktops are in:
    ex.) def.domain.com
    So, when developers try to register their local NWDS to the SLD,  they cannot reach it.  The only solution is for them to add the SAP Server domain (dx.domain.com) into their local tcp/ip settings on their desktop.
    Does anybody else have this same issue?  Any suggestions on how we can use a FQ DNS name for SLD registration?
    -Dave

    Sorry for the confusion.  I think I may have mis-worded my own question.  It was a Friday!
    Want I meant to say was, our developers' local JCo connections fail when they try to make a connection to an SAP system listed in the SLD.   This is because the two machines (pc and SAP server) reside in different domains. 
    SAP Servers are in abc.domain.com
    Desktop computers are in def.domain.com
    The only way for the JCo connection to work from their desktop, is if the developer adds "abc.domain.com" into the tcp/ip settings on their desktop.
    If we could register the SAP system in the SLD as a Fully Qualified Name, I think the problem would disappear.

  • How to get the domain name from the System

    I need to get the domain name from the system in JDK 1.1.8
    Any Ideas?

    InetAddress.getLocalHost().getHostName() will get you the name of the computer the code is executed on. If that isn't the "domain name" then perhaps you could give more detail about what "domain" you are trying to find the name of.

  • Server fully qualified Name

    Hi Experts,
    How to findout the EP server fully qualified name?
    I have following URL only
    for eg: http://<servername>:<port>/irj/portal
    i need fully qualified name?
    Regards,
    Manivannan P

    Hi sap_prof, hi colleagues,
    as I had also problems when starting with WDA on my SAP NetWeaver 7.0 SR 3, Development Subscription,
    I like to add some comments how I have solved this situation.
    My SAP AS-ABAP-Java runs in a Microsoft workgroup landscape (without an explicit  DNS-Server) together
    with a NAS server and four client machines.
    Looking here (as usual) in the forum, I found yesterday following threads:
    [FQDN for workgroup]
    [Re: Server fully qualified Name]
    So, having found the solution for my issue, I decided to come back to the community to give my implemented solution.
    But knowing now the correct term FQDN, I found instead following additionally thread which give us the hint in the right
    direction: [Re: CX_FQDN runtime error]
    Reading in the book "Windows Server 2003, R2 and SP1 Edition, Wiley, given by Jeffrey R. Shapiro and Jim Boyce,
    I get conscious about that with Windows hosts file you are able to resolve FQDN names without needing to query
    a DNS server for resolution.
    So, I build up my hosts files on all machines in the following manner:
    127.0.0.1    localhost
    192.168.MMM.NNN    <hostname>    <hostname>.dr-rauch.eu
    192.168.MMM.NNN    <HOSTNAME>    <HOSTNAME>.dr-rauch.eu
    192.168.MMM.NNN    <Hostname>    <Hostname>.dr-rauch.eu
    I repeated the three last items for all of my server and client machines.
    Additionally, I added in the properties of the internet protocol (TCP/IP) of the NICs the following DNS-Server
    address items:
    preferred DNS-Server    127.0.0.1
    alternative DNS-Server    IP-address of my gateway/router, to be able furtheron to access the www.
    Last but not least, I extended my SAP AS-ABAP-Java instance profile as proposed in the online help with the
    following item:
    icm/host_name_full = $(SAPLOCALHOST).dr-rauch.eu, and
    via SU01 I managed a new user - especially for web access - to prevent some upcomming access and
    other issues, and did what is said in the SAP note 1088717 - Active Services for WDA in the SICF.
    Now I am able and ready to work in my "DNS-less" Microsoft workgroup landscape with my SAP system.
    Thank you for this forum.
    Regards, Christian

  • How can I get the host name from Email address?

    hi
    When I using socket to develope an email-sending servlet,I don't know how to get the host name from emial address.can you help me,thanks

    Stripping off the user name will give you the domain of from field in the message. This is not the same as the host. Take a look at:
    http://www.stopspam.org/email/headers/headers.html
    Theres a pretty good discussion about email headers and how to use the information. You probably want to check the information here against the RFC.
    Sean

Maybe you are looking for

  • Itunes wont open after i updated my iphone 4s to ios 6, can anyone help?

    Recently i updated my iphone 4s to the ios6 system. i purchased more music and went about normal operations on my phone. when i connected my phone to my computer to update my purchased music and photos, itunes will not load. i have searched through t

  • Missing effects in cs5. Error message when I add presets.

    So I'm new to AE, and need some help. When I add the "rotate over time" animation preset to a title, it says "this favorite contains 1 reference to a missing effect. Please install the following effect to restore this reference". Does anyone know how

  • How to get information about connections and calls?

    Hi everyone, I would like to know if there's a way to get informations like time spent and bytes transfered from connections* and callings made from the cellphone, not just from a midlet application? * Any type of connections like WAP, SMS, GPRS. tks

  • Please begin to work more for the future dear Canon.

    I love Canon and I am a Canon guy for long time, but dear Canon, you lose so much time brush up models that in short time would be overwhelmed (EOS models), please take a look at the New Pentax 645D Medium Format, Hasselblad and Phase One which is th

  • SIII S3 How do I send a long text message conversation to my email account?

    I have a need to put my text message over the course of the past 4 months into an email to give to my attorney. How do I tell my phone to send me the conversation? I do not want to copy each piece and mail it as it is a discussion over over 4 months