1 package org.ozoneDB.tools.OPP.srcgen.resolve; 9 10 import org.exolab.castor.xml.MarshalException; 11 import org.exolab.castor.xml.ValidationException; 12 import org.ozoneDB.tools.OPP.srcgen.MethodResolver; 13 import org.ozoneDB.tools.OPP.srcgen.ResolverException; 14 import org.ozoneDB.tools.OPP.srcgen.streamfactory.InputStreamFactory; 15 import org.ozoneDB.tools.OPP.castor.Methods; 16 import org.ozoneDB.tools.OPP.castor.OzoneClassDescriptor; 17 import org.ozoneDB.tools.OPP.castor.PublicMethod; 18 import org.ozoneDB.tools.OPP.message.MessageWriter; 19 import org.ozoneDB.tools.OPP.CDHelper; 20 import org.ozoneDB.core.Lock; 21 import org.xml.sax.InputSource ; 22 23 import java.io.InputStream ; 24 import java.io.IOException ; 25 import java.util.Map ; 26 import java.util.HashMap ; 27 28 33 public class ClassDescriptorUpdateMethodResolver implements MethodResolver { 34 private final String WRITELOCK = "WRITE"; 35 private final String UPGRADELOCK = "UPGRADE"; 36 private final String READLOCK = "READ"; 37 private final String NONELOCK = "NONE"; 39 private InputStreamFactory factory; 40 private MessageWriter msgListener; 41 42 43 public ClassDescriptorUpdateMethodResolver(InputStreamFactory factory, MessageWriter msgListener) { 44 this.factory = factory; 45 this.msgListener = msgListener; 46 } 47 48 public void resolveMethods(String className, MethodResolver.UpdateMethodBag result) throws ResolverException { 49 try { 50 searchUpdateMethods(className, result); 51 } catch (ValidationException e) { 52 throw new ResolverException(e); 53 } catch (MarshalException e) { 54 throw new ResolverException(e); 55 } catch (IOException e) { 56 msgListener.info("No ocd was found!"); 58 msgListener.debug("message: " + e.getMessage()); 59 } 60 61 62 } 63 64 67 private void searchUpdateMethods(String className, MethodResolver.UpdateMethodBag updateMethods) throws ValidationException, MarshalException, IOException { 68 OzoneClassDescriptor descriptor = null; 69 InputStream input = factory.newInstance(className); 70 descriptor = CDHelper.xml2Descriptor(new InputSource (input)); 71 72 Methods mths = descriptor.getMethods(); 73 PublicMethod[] m = mths.getPublicMethod(); 74 for (int i = 0; i < m.length; i++) { 75 String methodName = m[i].getName(); 76 String locklevel = m[i].getLocklevel(); 77 78 int level = stringToLockLevel(locklevel); 79 80 81 boolean isUpdate = level > Lock.LEVEL_READ; 82 91 if (isUpdate) { 92 updateMethods.addMethod(methodName, level); 93 } 94 } 95 } 96 97 private int stringToLockLevel(String level) { 98 if (WRITELOCK.equals(level)) { 99 return Lock.LEVEL_WRITE; 100 } else if (UPGRADELOCK.equals(level)) { 101 return Lock.LEVEL_UPGRADE; 102 } else if (READLOCK.equals(level)) { 103 return Lock.LEVEL_READ; 104 } else if (NONELOCK.equals(level)) { 105 return Lock.LEVEL_NONE; 106 } 107 return Lock.LEVEL_READ; 108 } 109 } 110 | Popular Tags |