1 17 package org.apache.ws.jaxme.pm.impl; 18 19 import java.lang.reflect.InvocationTargetException ; 20 import java.lang.reflect.Method ; 21 22 import javax.xml.bind.Element; 23 import javax.xml.bind.JAXBException; 24 25 import org.apache.ws.jaxme.JMManager; 26 import org.apache.ws.jaxme.PMException; 27 28 29 32 public abstract class PMIdImpl extends PMImpl { 33 private static final Class [] ZERO_CLASSES = new Class [0]; 34 private static final Object [] ZERO_OBJECTS = new Object [0]; 35 private String getIdMethodName; 36 37 public void init(JMManager pManager) throws JAXBException { 38 String methodName = pManager.getProperty("xmldb.getIdMethodName"); 39 if (methodName == null || methodName.length() == 0) { 40 throw new JAXBException("Missing property: 'xmldb.getIdMethodName' (method name for reading the object ID)"); 41 } 42 setGetIdMethodName(methodName); 43 } 44 45 47 public void setGetIdMethodName(String pProperty) { 48 getIdMethodName = pProperty; 49 } 50 51 53 public String getGetIdMethodName() { 54 return getIdMethodName; 55 } 56 57 protected String getId(Element pElement) 58 throws NoSuchMethodException , IllegalAccessException , InvocationTargetException , 59 PMException { 60 String getMethodName = getGetIdMethodName(); 61 Method m = pElement.getClass().getMethod(getMethodName, ZERO_CLASSES); 62 Object o = m.invoke(pElement, ZERO_OBJECTS); 63 if (o == null) { 64 throw new PMException("The method " + getMethodName + " returned null, which is no valid ID."); 65 } 66 return o.toString(); 67 } 68 } 69 | Popular Tags |