Results 1 to 5 of 5

Thread: Another solution about package mapping in Java

  1. #1
    rc_hz is offline Registered User
    Name: Eric RC
    Organization: www.genband.com
    Project: No project yet
    Join Date
    Jul 2004
    Location
    Hangzhou, China
    Posts
    189

    Another solution about package mapping in Java

    According to page 331 in Ice 3.1.0 manul, when we want to use a common package prefix, we have to do like this:
    Code:
    1.Add a global meta in slice definition:
    [["java:package:com.acme"]]
    module Workflow {
        class Document {
        // ...
        };
    };
    
    
    2.Add one confication in config files:
    Ice.Package.Workflow=com.acme
    or
    Ice.Default.Package=com.acme
    This solution has one big shortcoming: the application assembler should has some knowedge about the code, that is, he or she should know that "com.acme" or "com.xxx" package names; Furthermore, in practical applications, that having to configure these packages is very boring.

    The following is another solution to this problem. The heart of it is the annotation feature in Java 5.
    Code:
    1.Add a global meta in slice definition(This is the same as above):
    [["java:package:com.acme"]]
    module Workflow {
        class Document {
            // ...
        };
    };
    
    2.change the behavior of slice2java a litte. Add an annotation to the java file:
    package com.acme.Workflow;
    
    @SomeAnnotation("com.acme")
    public abstract class Document {
        //...
    };    
    
    3.When Ice begins to run, the class loader scans the class file. If it finds an @SomeAnnotation, it gets a map. That is:
    ::Workflow::Document  ==> com.acme.Workflow.Document
    
    4.When Ice run time unmarshals an exception or concrete class , it can contact the map first.
    If we do like this, the application assembler don't need to any configration about packages.
    Eric RC
    www.genband.com (telecommunication)
    I like ICE (Ice for C++/Java/Python)

  2. #2
    rc_hz is offline Registered User
    Name: Eric RC
    Organization: www.genband.com
    Project: No project yet
    Join Date
    Jul 2004
    Location
    Hangzhou, China
    Posts
    189
    Is there any comment ?
    Eric RC
    www.genband.com (telecommunication)
    I like ICE (Ice for C++/Java/Python)

  3. #3
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    Hi,

    Unless I'm mistaken, this approach would require the Ice run time to scan every class in the program's classpath to find those that have the package annotation, which is not something I would be eager to do.

    Take care,
    - Mark

  4. #4
    rc_hz is offline Registered User
    Name: Eric RC
    Organization: www.genband.com
    Project: No project yet
    Join Date
    Jul 2004
    Location
    Hangzhou, China
    Posts
    189
    Quote Originally Posted by mes
    Hi,

    Unless I'm mistaken, this approach would require the Ice run time to scan every class in the program's classpath to find those that have the package annotation, which is not something I would be eager to do.

    - Mark
    Yes, you are right, this approach require the Ice to scan all classes in the program's classpath to find those that have the package annotation. However, annotation and this corresponding finding are just common things in modern java5 software, such as JBoss/Hibernate/Spring/WebLogic/Websphere. This finding can be done at the very beginning of program, so it has almost no impact on the program's performance. Further, this finding can be done in just a helper function , so it would not pollute the Ice's core code.

    In my point of view, these two config items(Ice.Package.Workflow/Ice.Default.Package) are very ugly and they pollute the Ice's simplicity and consistency because they require the assembler/tester to know some code detail of Ice program.
    Last edited by rc_hz; 08-23-2006 at 09:09 PM.
    Eric RC
    www.genband.com (telecommunication)
    I like ICE (Ice for C++/Java/Python)

  5. #5
    rc_hz is offline Registered User
    Name: Eric RC
    Organization: www.genband.com
    Project: No project yet
    Join Date
    Jul 2004
    Location
    Hangzhou, China
    Posts
    189

    Another solution

    1.Add a global meta in slice definition(This is the same as above) :
    Code:
    [["java:package:com.acme"]]                                                                                             
    module Workflow {                                                                                                       
        class Document {                                                                                                    
            // ...                                                                                                          
        };                                                                                                                  
    };
    2.change the behavior of slice2java a litte, which generates the following two files:
    1)The first one is just as usual:
    Code:
    package com.acme.Workflow;                                                                                              
                                                                                                                            
    public abstract class Document {                                                                                        
        //...                                                                                                               
    };
    2)The second one's package always begins with "com.zeroc":
    Code:
    package com.zeroc.Workflow;
    public class Document {
        public static final string CLASSNAME = "com.acme.Workflow.Document";
    }
    3.When Ice run time gets a type id such as "::Workflow:: Document", it follow these two steps to resolve it:
    1) Try to load Workflow.Document class.
    2) If 1) fails, try to load com.zeroc.Workflow.Document class. If this succeeds, it further tries to load the class with the name of com.zeroc.Workflow.Document.CLASSNAME, that is, com.acme.Workflow.Document.
    3) Otherwise, this type id can not be resolved.
    Last edited by rc_hz; 08-23-2006 at 09:37 PM.
    Eric RC
    www.genband.com (telecommunication)
    I like ICE (Ice for C++/Java/Python)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Controling Java Slice package names.
    By vincei in forum Comments
    Replies: 2
    Last Post: 09-11-2008, 10:57 PM
  2. Slice mapping for java.lang.Object
    By sattursa in forum Help Center
    Replies: 5
    Last Post: 06-02-2008, 04:15 PM
  3. Java global package metadata and builtin datatypes
    By mefoster in forum Bug Reports
    Replies: 1
    Last Post: 05-11-2007, 11:27 AM
  4. Why is the Java mapping for consts the way it is?
    By mefoster in forum Help Center
    Replies: 1
    Last Post: 04-17-2007, 12:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •