Question (JDev-Extension): Retreive class name with package info

To JDev Development team:
I'm developing an JDev 10.1.3 EA1 Addin. I have access to an oracle.ide.model.Node (the currently selected java code file from the Application Navigator / System Navigator).
Is there a way (inside the Extension API to convert this node to String representation of a qualified java class pointer (package.classname)? Or do I have to use extensive String manipulation on the filename with path?
Example:
If the file in the tree is:
casthouse
  + panel
    + casting
      + CastingPanel.java
    I want to translate this to casthouse.panel.casting.CastingPanel without having to use the Node objects URL.getFile() and manipulate the String object retreived from this, by removing path down to top-level package name and replacing all '/' with '.'.
I'm sure your API has functions to do this. Either in the JoT packages or in the navigator itself... I've looked, but I cannot find any answers to this in the Extension API javadoc. (ref. post no.4 in Question: Adding extension preferences panels as subnodes in the tree
Message was edited by:
Øystein Amundsen

If you have the Project in which the Node resides, then you can use Jot to get the information that you are looking for. If you don't already have it, you can probably get the project from the Context of the View.
For example;
Project prj = ... // Maybe use Context.getProject() to get this value.
Node node = ...
JavaManager jMgr = JavaManager.getJavaManager(prj);
SourceFile srcFile = jMgr.getSourceFile(node.getURL());
SourceClass srcClass = srcFile.getSourcePrimaryClass();
String clsName = srcClass.getQualifiedName();

Similar Messages

  • Class name and package name clashing

    When i have a class and a package with the same name, I cannot access classes in the package. For example I have 3 classes and 1 package as below
    - Test.java
    - PackageName.java
    + PackageName // this is a directory
    - MyClass.java
    Below are the codes of .java files
    Test.java
    =======
    public class Test { PackageName.MyClass a = new PackageName.MyClass ();}
    PackageName.java
    ===============
    public class PackageName{ }
    MyClass.java
    ==========
    package PackageName; public class MyClass { }
    I can compile PackageName.java and MyClass.java but not Test.java. It says
    cannot resolve symbol
    symbol : class MyClass
    location: class PackageName
    PackageName.MyClass a = new PackageName.MyClass ();
    But if I remove the PackageName.java, I can compile Test.java perfectly. I think when I use PackageName.MyClass, java thinks that I try to access an inner class MyClass of PackageName class, and that does not exists. Is there any way to solve this ambiguation, other than making the package name and class name different? Thank you very much.

    This works fine: just add an import to Test.java.
    import PackageName.MyClass;
    public class Test
        public static void main(String [] args)
            MyClass a = new MyClass();
    public class PackageName {}
    package PackageName;
    public class MyClass {}It's a pretty wacky, useless example, but it works.
    Plus I thought inner classes would have a dollar sign in their .class file names. When I compile this:
    public class OuterClass
        public static void main(String [] args)
            OuterClass outer = new OuterClass();
            System.out.println(outer);
        public String toString() { return "I'm an OuterClass"; }
        class InnerClass
            public String toString() { return "I'm an InnerClass"; }
    }I see two .class files: OuterClass.class and OuterClass$InnerClass.class
    Why make up examples like this? It's hard enough writing code, and it's easy to disambiguate for the compiler.

  • Conflit in class name and package name

    I have a small doubt. If the class name and the package name are the same in a folder, is there will be any conflict between these while using it. That means suppose a folder named 'animator' contain a package 'a' and a class name 'a'. I got any error in the 'Eclipse' tool that "a collides with a package". Is this can be solved my any change of setting in Eclipse? If then where can i change.? Can anybody help me to solve this issue??

    This works fine: just add an import to Test.java.
    import PackageName.MyClass;
    public class Test
        public static void main(String [] args)
            MyClass a = new MyClass();
    public class PackageName {}
    package PackageName;
    public class MyClass {}It's a pretty wacky, useless example, but it works.
    Plus I thought inner classes would have a dollar sign in their .class file names. When I compile this:
    public class OuterClass
        public static void main(String [] args)
            OuterClass outer = new OuterClass();
            System.out.println(outer);
        public String toString() { return "I'm an OuterClass"; }
        class InnerClass
            public String toString() { return "I'm an InnerClass"; }
    }I see two .class files: OuterClass.class and OuterClass$InnerClass.class
    Why make up examples like this? It's hard enough writing code, and it's easy to disambiguate for the compiler.

  • AS3 - dynamic class names with *new* operator

    I'm using AcrtionScript 3 and Adobe Flash 9 Public Alpha.
    I have 50 movie clips in the Library that use Linkage to set
    the Class name to: Img1, Img2, Img3, ..., Img50.
    I have a parent class named RandImg. I want the constructor
    for RandImg to randomly select one of the 50 movie clips from the
    Library and display it. I could get this working by generating a
    random number, and then writing a really huge switch statement to
    associate each possible random number with its respective Library
    Movie Clip Class name, but I would much rather do this with a
    dynamic/variable class name based on the random number, such as:
    var nImgChoice:Number = Math.floor( Math.random( ) * 50 ) +
    1;
    var mcImg:MovieClip = new [ "Img"+String(nImgChoice) ] ( );
    addChild( mcImg );
    Note that this used to be possible in AS 2 by doing the
    following:
    this.attachMovie( "Img"+String(nImgChoice) , "mcImg",
    this.getNextHighestDepth());
    Suggestions?
    Thanks,
    ~JC

    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.utils.getDefinitionByName;
    var nImgChoice:Number = Math.floor( Math.random( ) * 50 ) +
    1;
    var ClassReference:Class =
    getDefinitionByName("Img"+String(nImgChoice) ) as
    Class;
    var instance:Object = new ClassReference();
    addChild(DisplayObject(instance));

  • Deploy java stored proc. publishes java class names without package name

    Hi to All,
    Using JDevStudio 10132 I've created a 'Loadjava and Java Stored Procedure' deployment profile for my project. I've added my static method to the deplyment profile, but it generates script without java packege name, only pure class name.
    For example it executes: ...
    CREATE OR REPLACE PROCEDURE Procedure1(p1 IN VARCHAR2) AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'CryptoHelper.Procedure1(java.lang.String)';
    instead of
    CREATE OR REPLACE PROCEDURE Procedure1(p1 IN VARCHAR2) AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'mypackege.xxx.yyy.CryptoHelper.Procedure1(java.lang.String)';
    The CryproHelper class is definitely in mypackage.xxx.yyy package and JDeveloper Application Navigator shows correctly it.
    Any ideas?
    thx fo answers

    Hi,
    I've just been doing this on 10133 and found exactly the same thing. It's an easy fix to edit the package body - but it's rather annoying to have to manually do something that should just work.
    Steve
    *Hand editing the .deploy file to add in the package name works.
    Message was edited by:
    spilgrim

  • JAXB compiler for class names with special characters

    Hi,
    I trying to run the xjc against an XSD where element names (class names) have an "_" in them. For eg ACCOUNT_AKG.
    JAXB creates a class ACCOUNTAKG and omits the "_". I need "_" to be preserved in the class name of the class is generated.
    Can someone show me the right direction , so I can create classes with "_" preserved in the class name.
    This would be a big help
    thanks
    Jax

    Hi,
    I trying to run the xjc against an XSD where element names (class names) have an "_" in them. For eg ACCOUNT_AKG.
    JAXB creates a class ACCOUNTAKG and omits the "_". I need "_" to be preserved in the class name of the class is generated.
    Can someone show me the right direction , so I can create classes with "_" preserved in the class name.
    This would be a big help
    thanks
    Jax

  • Problem with "package-info.java" using EJB 3.0 and OC4J

    Hi all.
    I already posted this question on JDeveloper forum, but didn't get any answer,
    so I'll try posting here.
    Anyway, I'm new both to JDeveloper and J2EE,
    so I'm trying out examples for EJB 3.0, and I got stuck at "Use Security Annotations with EJB 3.0"
    (http://www.oracle.com/technology/tech/java/oc4j/ejb3/howtos-ejb3/howtoejb30security/doc/how-to-ejb30-security-ejb.html).
    Example code is working perfectly, if one builds it using Ant, but I'm importing all examples into JDeveloper (or at least I'm trying to :))
    JDeveloper can't build file "package-info.java" containing following code:
    @javax.annotation.security.SecurityRoles(roleNames={"superuser", "user"})
    package oracle.ejb30;I'm getting following output in "Compiler - Log" window:
    Error(2,1): 'class', 'interface', or 'enum' expected.
    Help much appreciated...
    platform used:
    Windows XP SP2
    JDeveloper Studio (Version 10.1.3, Build 3412)
    JDK 1.5_06
    OC4J 10.1.3 developer preview 4 (standalone version)

    Since you're using EJBs, you can use JTA and can skip the getTransaction() calls. If you want to use getTransaction().begin() and commit(), then make sure that your EntityManager is resource-local. The configuration for this is in persistence.xml. Set a transaction-type of RESOURCE_LOCAL rather than JTA.

  • Photoshop CS5 question - trying to save a name with extension .jpg or .png

    Hi,
    If I open a new file and go to save it the extension names show up (.jpg or .png). However, if I open an illustrator file in Photoshop and try to save it the extension names are not there (it's just saving them as the proper format, but I want the files to have the .jpg or .png in the name without me typing them in myself.
    Anyone know why this is or how I can fix it?

    rob3rockstar wrote:
    Hi,
    If I open a new file and go to save it the extension names show up (.jpg or .png).
    That is not true.  A net document save may default to .jpg.  I do not ever remember a save defaulting to .png unless a the document was opened from a .png file.  If the new document has layers save should open display the save as dialog and default to file type .psd.
    rob3rockstar wrote:
    Hi,
    However, if I open an illustrator file in Photoshop and try to save it the extension names are not there (it's just saving them as the proper format, but I want the files to have the .jpg or .png in the name without me typing them in myself.
    I do not have or use Illustrator however I do not believe that  Photoshop can open all illustrator file types like .ai.  Photoshop may be able to import and export .ai file.  If you have a document open in Photoshop you should be able to use "Save As"  and  chose the file type you want to save from the file type pull down menu. However .ai will not ne in the list.

  • Class name and package names

    I read a passage from some Java Book (sorry don't have the reference handy) that
    "It is illegal for a package and a class to have the same name, so there can be no ambiguity."
    Yet I have created a class named pkgclass within a package with the very same name.
    i.e.
    package pkgclass;
    public class pkgclass {
    This compiles just fine. Have I misinterpreted the statement from the book? What is it trying to say?
    Thanks in advance.

    Here's a quote from the Java language spec:
    "The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level type (�7.6) declared in that package."
    So your book was not quite correct, or maybe you just misremembered it (clearly you are typing from memory there). It isn't illegal for a package to have the same name as a class, as in your example. But it is illegal for a package to contain a subpackage and a class with the same name.

  • Same class name, different packages

    Let's say I have two classes called Team, and each are in their own package. I go to import a.Team and b.Team, what do I have to do to make this work?

    Import them both if you need them both. When you go to use them, refer to them by their fully qualified name.a.Team aTeam = new a.Team();
    bTeam bTeam = new b.Team();You don't really need the import statements from a programatic point of view, but it helps make your code more legible to other developers.

  • Extract class names from package

    I would like to be able to have te names of some classes. So I will be able to add new classes without changing other classes. I'm writing an application where I explain different kinds of sorting algorithms. I would like to be able to make a list of algorithms that are implemented. And also it should be no problem to add new algoritms. Each algorithm is in another class with a name that's related to their original name. It would be easy that when someone adds a new algorithm, he/she only have to implement a new class without looking at the other classes.
    If it is not clear what I mean, just ask.
    Greetz

    I would like to be able to have te names of some
    classes. So I will be able to add new classes
    without changing other classes.Huh? What keeps you from simply doing it?
    I'm writing an
    application where I explain different kinds of
    sorting algorithms. I would like to be able to make
    a list of algorithms that are implemented. And also
    it should be no problem to add new algoritms. Each
    algorithm is in another class with a name that's
    related to their original name. It would be easy
    that when someone adds a new algorithm, he/she only
    have to implement a new class without looking at the
    other classes.That's what abstract classes are for.

  • Return proper class name with typeof?

    When I perform a typeof on any of my custom AS classes, it
    returns "object." What property or method do you have to add to
    your classes in order to return a valid type name (for instance,
    "com.my.classes.ClassName" or just "ClassName")?

    jonwillis,
    > When I perform a typeof on any of my custom AS classes,
    it
    > returns "object." What property or method do you have to
    add
    > to your classes in order to return a valid type name
    (for instance,
    "com.my.classes.ClassName" or just "ClassName")?
    Nothing. Just use instanceof.
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • Java class names which contain unicode characters

    I need to create, compile and load java classes which have class names that contain unicode characters.
    I am using Win2k but will neet to support unix* in future.
    When I try to create a fooXbar.jar where X is a unicode character which is not ascii I get an error when creating the file.
    My question is: how do I map java class names and package names which contain non ascii characters into
    names that the files systems will like AND that the java VM will use when trying to load .class file from the class path.
    for example what would the .java and .class file be for the following class?
    class \u6587\u66f8 {

    You could make names for .java and .class that is understandable by the filesystem. E.g. you could prepend with % and then digits for the unicode character. The problem is then how to compile the class, and how to load the class.
    You can load the class with a custom classloader, which will translate the unicode class name to the escaped file name (using %).
    The problem is then reduced to how you can compile your code (you have to map the file name to the class name somehow). I think it can be done, but I don't know the solution to that.
    Alternatively you can use meaningful names for the classes, and then make an obfuscator that can change the bytecodes so the classnames are changed to some obscure unicode names. Perhaps there is already obfuscators out there you can use that will use unicode characters.

  • Class name separated by "." eg: Line2D.Double

    Hello,
    Just starting to explore the Java2D tutorial I encounter probably a very basic problem: assigning class names. In the java.awt.geom. package I find several class names with a dot in it like "Line2D.Double". I tried just as an experiment to run an application with name "Dot.Test" . The compiler immediately points out an "{" is expected at the position of the dot. So actually I can not have a dot in a name. I am totally in the dark of this dot in class names now. Can anybody help me here.
    Thanks
    Pierre
    email: [email protected]

    The dot is probably a refrence to an inner class.
    Class test {
    class inner {
    Would be referenced by test.inner

  • Why File Name is Same Name as The Public Class Name

    Hi Friends,
    What is the reason for Naming the File Name is puvlic class name??
    thanks in advance.

    konstkaras wrote:
    What could be reason to give it other name?
    It's as much better as we have less distinct names.
    When I was a schoolboy, I programmed Turbo Pascal. Each program there had a name (declared in file's beginning). The name was never used, but: it has no such restriction of length (as MS-DOS file names had) and it could clash with other identifiers described in code.
    So why those names should be distinct?Java was invented after MSDOS was obsolete, so 8.3 limits were not a consideration.
    Java is designed for larger programs than were attempted in the MSDOS era, so supports compilation of programs which are created from many source files. Turbo Pascal 4 also supported separate compilation units, and did use the name you mention for exactly that purpose, but I can't remember how it dealt with dependencies between compilation units.
    Having the public class' name and package as component in the source file path and the class file path simplifies the dependency problem between the compilation units - all the compiler has to do to determine whether the foo.bar.Baz class needs updating is to look whether foo/bar/Baz.class exists, and if it is less recently modified than foo/bar/Baz.java.

Maybe you are looking for

  • Picard doesn't create files with a user's non-primary groupid

    Scenario: I have a folder in /home/john/music  that contains files that are readable by users in users group. I have set permissions this way (setgid): drwxr-sr-x 284 john users 12K sep 4 00:03 music This way, new files inside that folder belong to "

  • External Authentication Half Working

    I'm having a strange issue with external authentication and PHP. I've got the PHP code set up correctly (I believe) and I pass the authentication token to the Flex application via flashvars and when the application loads the roster pod shows everyone

  • Accidentally uninstall BAM10.1.3.1, how to recover

    Dear all; We have accidentally uninstall BAM10.1.3.1 and Enteprise Link via Windows Add and Remove Program. All we have prior the uninstall is export dump (orabam & orasagent schemas) and the D:\OracleBam folder that we had backup to D:\OracleBam.old

  • Strategy&word documents files

    i have 3 questions 1. the strategy as i understand is a common interface being implemented by more than one class .. and there is a class (which is the strategy) that will instanciate one object of one of those classes (that implement the interface)

  • Address Book lookup

    I have a feature request for at least the nseries phones(but not only). In case of an incoming call the phone match only the last 7 digits of the phone number from the Address Book. As a result it can show a wrong name association to the incoming CLI