KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > impl > XSUtil


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.xs.impl;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.ws.jaxme.xs.XSAnnotation;
23 import org.apache.ws.jaxme.xs.XSAppinfo;
24 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
25 import org.xml.sax.SAXException JavaDoc;
26
27 /**
28  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
29  */

30 public class XSUtil {
31   /** <p>Returns all childs of xs:annotation/xs:appinfo implementing
32    * or extending the given class.</p>
33    */

34   public static List JavaDoc getAppinfos(XSAnnotation[] annotations, Class JavaDoc pClass) {
35     List JavaDoc result = new ArrayList JavaDoc();
36     for (int i = 0; i < annotations.length; i++) {
37       XSAppinfo[] appinfos = annotations[i].getAppinfos();
38       for (int j = 0; j < appinfos.length; j++) {
39         Object JavaDoc[] childs = appinfos[j].getChilds();
40         for (int k = 0; k < childs.length; k++) {
41           if (pClass.isAssignableFrom(childs[k].getClass())) {
42             result.add(childs[k]);
43           }
44         }
45       }
46     }
47     return result;
48   }
49
50   /** <p>Returns the first child of xs:annotation/xs:appinfo implementing
51    * or extending the given class. Ensures that the child is unique.</p>
52    * @return The unique child or null, if no such child exists.
53    */

54   public static Object JavaDoc getSingleAppinfo(XSAnnotation[] annotations, Class JavaDoc pClass) throws SAXException {
55     Object JavaDoc result = null;
56     if (annotations != null) {
57       for (int i = 0; i < annotations.length; i++) {
58         XSAppinfo[] appinfos = annotations[i].getAppinfos();
59         for (int j = 0; j < appinfos.length; j++) {
60           Object JavaDoc[] childs = appinfos[j].getChilds();
61           for (int k = 0; k < childs.length; k++) {
62             if (pClass.isAssignableFrom(childs[k].getClass())) {
63               if (result == null) {
64                 result = childs[k];
65               } else {
66                 throw new LocSAXException("Multiple instances of " + pClass.getName() +
67                                            " in xs:annotation/xs:appinfo are forbidden.",
68                                            appinfos[j].getLocator());
69               }
70             }
71           }
72         }
73       }
74     }
75     return result;
76   }
77 }
78
Popular Tags