KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > pm > impl > PMIdImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.pm.impl;
18
19 import java.lang.reflect.InvocationTargetException JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
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 /**
30  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
31  */

32 public abstract class PMIdImpl extends PMImpl {
33   private static final Class JavaDoc[] ZERO_CLASSES = new Class JavaDoc[0];
34   private static final Object JavaDoc[] ZERO_OBJECTS = new Object JavaDoc[0];
35   private String JavaDoc getIdMethodName;
36
37   public void init(JMManager pManager) throws JAXBException {
38     String JavaDoc 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   /** <p>Sets the name of the method fetching the object ID.</p>
46    */

47   public void setGetIdMethodName(String JavaDoc pProperty) {
48     getIdMethodName = pProperty;
49   }
50
51   /** <p>Returns the name of the method fetching the object ID.</p>
52    */

53   public String JavaDoc getGetIdMethodName() {
54     return getIdMethodName;
55   }
56
57   protected String JavaDoc getId(Element pElement)
58       throws NoSuchMethodException JavaDoc, IllegalAccessException JavaDoc, InvocationTargetException JavaDoc,
59               PMException {
60     String JavaDoc getMethodName = getGetIdMethodName();
61     Method JavaDoc m = pElement.getClass().getMethod(getMethodName, ZERO_CLASSES);
62     Object JavaDoc 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