KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > MethodItemConverter


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

18 package org.objectweb.jac.ide;
19
20 import org.apache.log4j.Logger;
21 import org.objectweb.jac.aspects.persistence.StringConverter;
22 import org.objectweb.jac.core.rtti.ClassItem;
23 import org.objectweb.jac.core.rtti.ClassRepository;
24 import org.objectweb.jac.core.rtti.MethodItem;
25
26 /**
27  * Persistance for a MethodItem Class
28  */

29 public class MethodItemConverter implements StringConverter {
30     static Logger logger = Logger.getLogger("ide");
31
32     /**
33      * Persistance storage : translate the object into String
34      * @param obj the object to translate
35      * @return a string representing the object ClassItem:MethodItem
36      */

37     public String JavaDoc objectToString(Object JavaDoc obj){
38         String JavaDoc result=null;
39         try{
40             MethodItem method=(MethodItem)obj;
41             ClassItem cl=method.getClassItem();
42             result=cl.getName()+":"+method.getFullName();
43         }catch(Exception JavaDoc e){
44             result=null;
45         }
46         return result;
47     }
48
49     /**
50      * Trying to convert a String into a MethodItem: the string must
51      * be like ClassItem:MethodItem (fully qualified)
52      *
53      * @param str the input string ClassItem:MethodItem
54      * @return a MethodItem
55      */

56     public Object JavaDoc stringToObject(String JavaDoc str){
57         //The position of ':' in the string
58
int pos = str.indexOf(":");
59         //If not found error
60
if (pos==-1) {
61             logger.warn("Malformed method string (must be <classname>:<methodname>)"+str);
62         }
63         ClassItem classItem = ClassRepository.get().getClass(str.substring(0,pos));
64         //if classItem doesn't exist
65
if (classItem==null) {
66             logger.warn("The class "+str.substring(0,pos)+" couldn't be found in the Repository");
67             return null;
68         }
69         return classItem.getMethod(str.substring(pos+1));
70     }
71 }
72
Popular Tags