KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > helper > ImplHelper


1 /**
2  * copyright 2002 2003 Laboratoire d'Informatique Paris 6 (LIP6)
3  *
4  * This file is part of ModFact.
5  *
6  * ModFact is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * at your option) any later version.
10  *
11  * ModFact is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with ModFact; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package org.objectweb.modfact.jmi.helper;
21
22 import javax.jmi.model.*;
23
24 public class ImplHelper {
25     
26     
27   public static final String JavaDoc implPrefix = "org.objectweb.modfact.jmi.repository.";
28     
29   public static String JavaDoc wrap(TypedElement t, String JavaDoc code) {
30     if(MofHelper.isSinglePrimitive(t)) {
31       String JavaDoc name = t.getType().getName();
32       if(name.equalsIgnoreCase("boolean")) {
33         return "new Boolean(" +code +")";
34       } else if(name.equalsIgnoreCase("integer")
35         || name.equalsIgnoreCase("long")
36       ) {
37         return "new Integer(" +code +")";
38
39       } else if(name.equalsIgnoreCase("float")) {
40         return "new Float(" +code +")";
41       } else if(name.equalsIgnoreCase("double")) {
42         return "new Double(" +code +")";
43       }
44     }
45     return code;
46   }
47   
48   public static String JavaDoc unwrap(TypedElement elem, String JavaDoc code) {
49     if(MofHelper.isSinglePrimitive(elem)) {
50       String JavaDoc name = elem.getType().getName();
51       if(name.equalsIgnoreCase("boolean")) {
52         return "((Boolean)" +code +").booleanValue()";
53       } else if(name.equalsIgnoreCase("integer")
54         || name.equalsIgnoreCase("long")
55       ) {
56         return "((Integer)" +code +").intValue()";
57
58       } else if(name.equalsIgnoreCase("float")) {
59         return "((Float)" +code +").floatValue()";
60       } else if(name.equalsIgnoreCase("double")) {
61         return "((Double)" +code +").doubleValue()";
62       }
63     }
64     return code;
65   }
66     
67
68 }
69
Popular Tags