Go Back   ZeroC Forums > Comments

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 08-18-2006
rc_hz 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
Send a message via MSN to rc_hz
-->
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)
Reply With Quote
  #2 (permalink)  
Old 08-19-2006
rc_hz 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
Send a message via MSN to rc_hz
-->
Is there any comment ?
__________________
Eric RC
www.genband.com (telecommunication)
I like ICE (Ice for C++/Java/Python)
Reply With Quote
  #3 (permalink)  
Old 08-23-2006
mes's Avatar
mes mes is online now
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
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
Reply With Quote
  #4 (permalink)  
Old 08-23-2006
rc_hz 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
Send a message via MSN to rc_hz
-->
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.
__________________
Eric RC
www.genband.com (telecommunication)
I like ICE (Ice for C++/Java/Python)

Last edited by rc_hz : 08-23-2006 at 10:09 PM.
Reply With Quote
  #5 (permalink)  
Old 08-23-2006
rc_hz 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
Send a message via MSN to rc_hz
-->
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.
__________________
Eric RC
www.genband.com (telecommunication)
I like ICE (Ice for C++/Java/Python)

Last edited by rc_hz : 08-23-2006 at 10:37 PM.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
OSX package on Intel MAC ctennis Bug Reports 2 11-23-2006 09:32 PM
solution to install ICE-3.1.1 on freebsd.6.1 canyoudink Bug Reports 0 10-19-2006 12:36 PM
Which solution is better when programming with ICE? nyingchi Help Center 3 09-29-2006 07:24 AM
a misstake for IceCS-2.0.0 vs.net2003 solution? lkw Bug Reports 3 01-04-2005 07:45 PM
package metadata directive - ClassCast Exception vsonnathi Bug Reports 1 09-28-2004 11:46 AM


All times are GMT -4. The time now is 02:04 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.