Package Name from Calls

My problem is this. I have the following 3 packages.
layer1.layer2a
layer1.layer2a.layer3
layer1.layer2b
I have a interface in layer2a that is either public to everyone or private just to that package. I need for layer2b NOT to have access to it but for all packages that start with layer1.layer2a to have access to it. So package layer1.layer2a.layer3 would have access to it and package layer1.layer2b would not.
I thought that if I could get the calling classes package name I could return a null value if the package name does not start with layer1.layer2a, however the below code always returns null.
this.getClass().getPackage(); //returns null
this.getClass().getDeclaringClass() //returns null
All of my classes definetly have package names so I'm not sure why the first line returns null. And yes I know that the first line will not return the calling classes package. I was just testing it.
Can anyone help me with this? If you have a better solution to my problem please post.
Below is my code example.
package layer1.layer2a;
public class DataFile {
     private String userId="test";
     public String getUserId(){
//System.out.println("package name = "+this.getClass().getPackage());
//System.out.println("calling class is = "+this.getClass().getDeclaringClass());
          return userId;
-----------------------calling class---------------------------
package layer1.layer2a;
public class MyTest{
     public void callDataFile(){
          DataFile df = new DataFile();
          String s = df.getUserId();          
System.out.println("s = "+s);          
}

So package layer1.layer2a.layer3 would have access to it and package layer1.layer2b would not.Not possible.
There is no hierarchial relationship between packages. Given the following packages:
A.B
A.B.C
A.Z
The package A.B.C has the same relationship to A.B as it does to A.Z. There is no way to give expose something to one package without exposing it to all other packages.
Solutions:
-Look at the design again. Maybe it can be refactored to provide a different solution.
-Just expose it, and document that the interface should only be used in a certain way.

Similar Messages

  • 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());
    }

  • Package name from classname .class

    Is there any way to know the package name of the class from its .class without using the Reflection API's since there we need to instantiate the class with its fully qualified name. Can anybody suggest a method to do it.

    javap requires the name of fully qualified class, so
    if you are not aware of it, this utility will not
    work.
    We cannot create an instance of the class, if we donot
    know the full name of the class <including the package
    name>
    Both the above ways I think will not satisfy the
    purpose.I'm having a hard time understanding why anyone would want to instantiate a class they don't know anything about, or how anyone could expect to do so.

  • Issue with renaming the package name from "Oracle" to "oracle" in windows

    Hi all,
    I created a project in which initially I created all the jsffs in a package Oracle/communications. In one of the jsff pages(a.jsff) I have include tag <jsp:directive.include file="/*Oracle*/communications/b.jsff"/>
    But later I refactored the code and renamed the package to oracle/communications and I modified the include tag to <jsp:directive.include file="/*oracle*/communications/b.jsff"/>
    But after that change also when I deploy the ear and try to access the a.jsff, I am getting the file not found exception.
    Root cause of ServletException.
    oracle.jsp.parse.JspParseException:
    /adflib/oracle/communications/a.jsff: Line # 19, <jsp:directive.include file="/Oracle/communications/b.jsff" xmlns:jsp="http://java.sun.com/JSP/Page"/>
    Error: Include file not found: /Oracle/communications/b.jsff
    Do I need to change any other configuration file?
    The same ear when deployed in linux is working absolutely fine.
    Thanks in advance,
    Vamsi

    Windows doesn't know the difference between upper case and lowercase file names. So renaming Oracle to oracle will not change the file name.
    To change the file name you have to rename it from Oracle to xxoracle and then to oracle.
    Timo

  • Full package name?

    All,
    I am very new to Javadoc. I would like to know how (if possible) to eliminate the full package name from any descriptions. For example, if I have a method that returns a Hashtable, the Javadoc that gets generated looks like this:
    public static java.util.Hashtable newMethod()
    I would like it to look like this:
    public static Hashtable newMethod()
    I'm using the Eclipse tool, and that is actually calling Javadoc and passing the appropriate parms (v1.4).
    I'm new to Javadoc, so I don't know if the generated method (with the package name) is preferred. I've also read some of the forum's comments on how to get started with this. I'm attempting to consolidate the lengthy Javadoc documentation, and some of the comments I've read have been helpful.
    Thanks,
    Van Williams

    The default should display the package name only
    for classes not in the "current" package.
    For 1.4, use "-noqualifier all" to prevent the package
    name from appearing ahead of the class name
    for all packages. This is further described at:
    http://java.sun.com/j2se/1.4/docs/tooldocs/windows/javadoc.html#noqualifier
    You can reduce the confusion this may cause
    by using -linkoffline to create links to
    classes not being documented, such as to
    java.util.HashTable in your example. This
    is further described at:
    http://java.sun.com/j2se/1.4/docs/tooldocs/windows/javadoc.html#linkoffline
    -Doug Kramer
    Javadoc team

  • Package name when the doman name contains "-"

    Recently I'm working for a project for a company whose domain name like www.my-donkey.com. By convention, the Java package name should start with com.my-donkey.xxx, unfortunately the hypen is not allowed in the package name.
    What is the standard Java convention to address this?

    Remember that the package naming convention is exactly that: a convention. It isn't a rule, nothing checks them and you don't have to follow it. It was just an idea that someone came up with to make it less likely that package names from different organisations would collide. Go with Kaj's idea, package names don't have any legal ramifications or anything

  • Any Function Module/Class to get Program's Package Name??

    Hi Guys,
    Are there any Function Modules/Classes that return the Package name of any given Program?
    I have had a look but have been unable to find any...
    thanks,
    C
    PS POINTS WILL BE REWARDED

    Hi,
    1)u can get Package name from SE93
    go to SE93>give transaction code>display
    2)you can also get from
    go to t-code>system>status>d.click on program name>goto-->attributes
    Thanks
    Ankur Sharma

  • JDeveloper Addin - Get Package Name

    I'm creating a new Wizard addin for JDeveloper that basically does the same thing as creating a new java file, however it will create the JavaSourceNode with content from a template using my companies coding standards.
    My question / problem is that I can't figure out how to get the package name from JDeveloper to display in my JDialog similar to how creating a new java file works.
    When creaing a new java file, you can select a package and click new and the package name that displays in the dialog is that package name.
    Can any one suggest how to get the package name in the same manner that creating a new java file works?

    Here is the code that I came up with that I think fits with creating a new java file;
    public String getPackageName(Context context) {
    JProject jProject = (JProject)context.getProject();
    String packageName = null;
    // Get a selected element
    Element element = context.getElement();
    // If element is not NULL and is of instance of PackageFolder then
    // set the packageName to the selected package.
    if ((element != null) && (element instanceof PackageFolder)) {
    // Set the packageName to the package that was selected
    packageName = element.getShortLabel();
    } else {
    // If no package was selected then try to get the first package
    // entry of the <defaultPackages> element of the jpr. If there
    // are no packages then just use the default jpr package
    // name.
    if (!(jProject.getDefaultPackages().isEmpty())) {
    packageName = (String)jProject.getDefaultPackages().get(0);
    } else {
    packageName = jProject.getDefaultPackage();
    } // end if not empty
    } // end if
    return packageName;
    } // getPackageName
    The plugin that you suggested is very cool, but a little different that what I'm trying to do.

  • How can i get all java class names from a package using reflection?

    hi,
    can i get all classes name from a package using reflection or any other way?
    If possible plz give the code with example.

    You can't, because the package doesn't have to be on the local machine. It could be ANYWHERE.
    For example, via a URLClassLoader (ie from the internet) I could load a class called:
    com.paperstack.NobodyExpectsTheSpanishInquisitionI haven't written it yet. But I might tomorrow. How are you going to determine if that class is in the package?
    This subject comes up a lot. If you want to do something a bit like what you're asking for (but not quite) there are plenty of threads on the subject. Use google and/or the forum search facility to find them.
    But the answer to your question, as you asked it, is "you can't do that".

  • I need to remove "air." from package name. I'm get a Layout xml error when repackaging android app..

    So, i'm doing this on my own app. I made an update for an older app that was build using Native Android. But this time, i used Adobe AIR... The catch is Adobe likes to append a "air." to the front of your package name without asking you. So basically I can't upload my update because it has a new package name is now "air.com.mycompany.myapp" rather than the original "com.mycompany.myapp"
    Basically I'm going through this guide..
    http://helpx.adobe.com/air/kb/opt-out-air-application-analytics.html
    I followed all the steps, made all the adjustments to the androidmanifest.xml like it asks.
    But after going along with the above guide, with no issues when i get to the step that says
    "Run the following command to create the resource file for the updated AndroidManifest.xml:"
    I run this..
        "/Users/brybam/Documents/eclipse/android-sdk-mac_x86/platform-tools/aapt" package -f -M AndroidManifest.xml -F resources.arsc -I "/Users/brybam/Documents/eclipse/android-sdk-mac_x86/platforms/android-8/android.jar" -S ./res
    But I keep getting the same error regarding the xml files in res/layout
        ./res/layout/expandable_chooser_row.xml:1: error: Error parsing XML: not well-formed (invalid token)
        ./res/layout/expandable_multiple_chooser_row.xml:1: error: Error parsing XML: not well-formed (invalid token)
        ./res/layout/main.xml:1: error: Error parsing XML: not well-formed (invalid token)
        ./res/layout/multiple_file_selection_panel.xml:1: error: Error parsing XML: not well-formed (invalid token)
        ./res/layout/ssl_certificate_warning.xml:1: error: Error parsing XML: not well-formed (invalid token)
    The guide doesn't say anything about these xml files, and im not sure what to do with these or how to handle them.
    If i go into the res/layout folder, and just delete these (i know they're necessary. But i just deleted them as a test, to get through the rest of the guide...)
    I was able to get through the rest of the steps in the guide fine, make an apk, and put it on my phone...only to find out the app will crash the moment you try to run it. Probably because i deleted the layout xml files...But i cant get the command i need to run above to accept them!
    So, earlier in the guide they have me use thing thing called the "AXMLPrinter2.jar" to make the AndroidManifest.xml readable so i can edit it.
    I run something like this:
        java -jar "/Users/brybam/Desktop/repackage/AXMLPrinter2.jar" AndroidManifest.xml > AndroidManifest.xml.bk
    This makes a new file "AndroidManifest.xml.bk" and i can edit that.
    So, I was thinking with all of these layout xml files, maybe I could run this "AXMLPrinter2.jar" on them and then edit them. Because right now if you open them they're not human readable, and its hard for me to work on them if they're not...
    I tried this thinking i could do the same thing...
        java -jar "/Users/brybam/Desktop/repackage/AXMLPrinter2.jar" main.xml > main.xml.bk
    Just get a blank file and a console erorr when trying to use the AXMLPrinter2.jar on the layout xml files...
        java.lang.ArrayIndexOutOfBoundsException: 67
                  at android.content.res.StringBlock.getShort(StringBlock.java:231)
                  at android.content.res.StringBlock.getString(StringBlock.java:91)
                  at android.content.res.AXmlResourceParser.getName(AXmlResourceParser.java:140)
                  at test.AXMLPrinter.main(AXMLPrinter.java:56)
    So, I think my whole issue is based around these XML files not being converted to human readable before i try and re-package....
    EDIT:::
    Ok, so I found a site that talks about the error I'm getting but it's in chinese, and even after translating the page...I'm still not well versed with terminal and this stuff to get it.
    It reads:
    "Error.
    Final conclusion:
    In minSdkVersion <= 7, AXMLPrinter2.jar can normally decompile xml file
    Greater than 7 can not be normal decompile xml file (AndroidManifest.xml except)
    Give way to share a batch decompile xml file:
    First, create a *. Txt file
    Stresses inside the content authoring
    for / r layout%% a in (*. xml) do @ java-jar AXMLPrinter2.jar "%% a" >> "%% a". txt
    Then this txt file extension into bat form, and this BAT the file and AXMLPrinter2.jar on the same directory will be decompiled xml into the layout directory
    Decompilation results can be generated by executing the bat file multiple xml files."
    - http://hi.baidu.com/ghcghc/item/ecbaa1ce997cb225a0b50ac2
    Maybe someone with more know-how could explain what they're explaining? I get that he's saying the issue im seeing appears when you're using minSdK <=7 but I need to use minSdk 8. Does anyone understand this work around? And how I might go about it on a Mac with terminal?
    I wish adobe would make it easy to remove the "air." from the package name. If they want to convert old Native devs to AIR devs...the transition needs to be seamless. But now I'm about to have to go back to Native because I can't update an app I already have out on the market with an air app.

    Hello~
         I also tried to remove "air." package name in air application. And i encounter the same problem.
         I do not find any solution to decode the xml inside res folder by AXMLPrinter2.jar. And those xml inside is compressed which is unreadable.
         However, what you can do is copying the structure of res folder. And go to your air sdk file path -  adobeair-sdk-folder/lib/android/lib/resources/
         Replace those file exists in your res folder. And copy "values" folder to your res folder.
         Hope this solve your problem~

  • How to find proc/func name from package name and line number?

    Hi,
    We are using the pl/sql call stack dump (dbms_utility.format_call_stack) for some debugging purposes. But in the case of a package body execution, the dump does not return the name of the procedure/function that is being executed, but only the name of the package and the line number being executed. So, we have a requirement wherein we need to extract the type and name of a package subunit from the package name and line number.
    e.g.
    From the information package 'A', line number 739
    we should be able to deduce that line 739 is a part of *'function A.f'*
    Does the oracle database provide any native mechanism (PL/SQL packages or otherwise) to support such functionality? If it does not, how can we achieve the desired result?
    Thanks in advance,
    Shashank

    The approach we are currently planning to take up is this :
    1. Write PL/SQL code to parse the entire source (user_source) and build a database table with a structure like this :
    PACKAGE_NAME | UNIT_TYPE | UNIT_NAME | START_LINE | END_LINE
    =============================================
    A | PROCEDURE | P1 | 20 | 345
    A | FUNCTION | F1 | 347 | 629
    etc..
    2. Start PL/SQL package execution.
    3. Keep dumping call stack snapshots whenever a custom debug procedure is called.
    4. Dump the package name and line number to a log file.
    5. Using the package name and line number, query the table built in step 1 and build the final report which shows the control flow in a readable form.
    What we want is to get rid of step 5 and by some means get the logic to extract the unit type and name in step 4 itself.
    Keep them coming..
    Thanks and regards,
    Shashank

  • Calling package name error?

    How can I call class.function  from timeline?? with package name
    package game {
    internal class carnode {
            public function carnode() {
                function printtrace():void{
                trace("Tesitng package name");
    Usage
    var car:game.carnode=new game.carnode();
    car;

    You have to import the class first:
    import game.carnode;
    var car:carnode=new carnode();
    You also need to change internal to public.
    And remove the printtrace function from the carnode function. Nesting functions is very poor coding practice.

  • Adding caller with name and number from call list to the contact list only inserts the number and not the name

    I recently bought a BlackBerry Z10 and moved my cell service to Rogers to take advantage of the name display service offered by Rogers (Fido also offers this service).
    Due to the number of calls that I receive from first time clients, I wanted the name display service to help me know who was calling. Evidently it is impossible to add clients to my contact list before they call me so I'm constantly seeing numbers that have no name to help me decide if I want to answer the call.
    When I try to add a caller from my call list to my contact list, only the number gets inserted in the new contact. The name needs to be entered manually.
    I understand and realize that not all call display formats are the same and that it's virtually impossible to parse the first and last names from the name portion of the caller id.
    However, I would like to see BlackBerry add the functionality to insert the name portion of the call entry from the caller list to a "Nickname" entry in the contact list just like it adds the number to a "Home", "Mobile", or "Work" entry in the contact list.
    If a user doesn't have a name display service, there would be no change to how their contacts are added because there is no name variable to copy over.
    Can someone from BlackBerry please let me know if this feature can be added to BB10 and when it can be added? For me it's an obvious feature that should just work.
    I am really enjoying my Z10 but I'm feeling let down that something so logical and helpful is not supported out of the box.
    Regards,
    Marc

    Hey ViciousFerret,
    It appears that you are not aware of the fact that both Rogers and Fido offer name AND number display service (although the name display feature is an add-on service) and have been offering it for many years (since 2006). Here is a link to the name display service description of each provider...
    http://www.fido.ca/web/content/manageyourcalls/calldisplay&lang=en
    http://www.rogers.com/business/on/en/smallbusiness/products/wireless/addons/valuepacks/
    As you can see from the link below, Rogers and Fido have been offering this service since 2006.
    http://www.businesswire.com/news/home/20060914005951/en/Teams-HP-Rogers-Wireless-Fido-Succeed-North
    My BlackBerry Z10 shows both the name and number when someone calls (and the caller is not in my contact list).
    All I would like is for the Z10 (and Q10) to support the addition of the name and number from the caller list to my contact list without me having to type the name. As I mentioned in my original post, to avoid the OS having to parse the first name and last name from the name portion of the caller list entry the name could simply be added to the contact list as a "Nickname". If your provider only has number display, nothing would have to be copied from the name variable in the caller list to the contact list.
    I find it difficult to believe that BlackBerry would not be aware of this name display service since it's been around since 2006 with both Rogers and Fido.
    I hope I have clarified the reasons why I would like to have this feature added to BB10 and how it's surprising that this simple feature is not already a part of the BB10 OS.
    Either way, I don't think this is a difficult feature for the BlackBerry team to add. They're just copying a 2nd variable from the caller list to the contact list.
    I'm surprised that Rogers hasn't asked BlackBerry to add this feature to their phones. I think it would be a popular feature for those who receive a high number of calls from first time callers.
    How can I get this feature request to BlackBerry for their consideration?
    Cheers,
    Marc

  • How to call a stored procedure using its package name in Oracle

    hi
    we're doing a JDBC scenario where we call a stored procedure(a.prc) using its package name(b)The stored procedure has In /Out/IN-OUT parameter.
    i have got 2 queries:
    1- How to call the stored procedure using it's package.
    2- How to capture the In/Out parameter in the response.

    hi Prateek
    thanks for the reply.
    However when i tried mapping it to Package.procedure, communication channel throws the error saying that Package.proceudre needs to be declared.
    As i said , the procedure has IN-OUT parameter too.In oracle we need to write a block if we want to read the IN-OUT parameter.
    How to get the IN-OUT parameter in XI?

  • Call Package Procedure from a Servlet?

    Hi,
    Is it possible to call a package procedure from a servlet?
    Art

    Could you be a bit more specific please? I'm not sure where or what to look for.
    Art
    Wrap it with WebServices interface. There is an example article somewhere on otn.oracle.com

Maybe you are looking for