KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > generator > sg > impl > ccsg > GroupUtil


1 package org.apache.ws.jaxme.generator.sg.impl.ccsg;
2
3 import org.apache.ws.jaxme.generator.sg.GroupSG;
4 import org.apache.ws.jaxme.generator.sg.ParticleSG;
5 import org.apache.ws.jaxme.generator.util.JavaNamer;
6 import org.apache.ws.jaxme.js.JavaQName;
7 import org.apache.ws.jaxme.js.JavaQNameImpl;
8 import org.xml.sax.SAXException JavaDoc;
9
10
11 /** Utility methods for handling groups.
12  */

13 public class GroupUtil {
14     /** Returns a suggested name for the given group.
15      */

16     public static String JavaDoc getGroupName(GroupSG pGroup) throws SAXException JavaDoc {
17         if (pGroup.isGlobal()) {
18             return JavaNamer.convert(pGroup.getName().getLocalName(), pGroup.getSchema());
19         } else {
20             String JavaDoc sep;
21             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
22             if (pGroup.isSequence() || pGroup.isAll()) {
23                 sep = "And";
24             } else {
25                 sep = "Choice";
26             }
27             int num = 0;
28             ParticleSG[] groupParticles = pGroup.getParticles();
29             for (int i = 0; i < groupParticles.length; i++) {
30                 ParticleSG particle = groupParticles[i];
31                 if (particle.isElement()) {
32                     if (num++ > 0) {
33                         sb.append(sep);
34                     }
35                     String JavaDoc f = particle.getPropertySG().getPropertyName();
36                     sb.append(Character.toUpperCase(f.charAt(0)) + f.substring(1));
37                     if (num == 3) {
38                         break;
39                     }
40                 }
41             }
42             if (sb.length() == 0) {
43                 return "Group";
44             } else {
45                 return sb.toString();
46             }
47         }
48     }
49
50     static JavaQName getContentClass(GroupSG pGroup, ParticleSG pParticle,
51                                      JavaQName pQName) throws SAXException JavaDoc {
52         String JavaDoc name = pParticle.getPropertySG().getPropertyName();
53         name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
54         if (pGroup.isGlobal()) {
55             return JavaQNameImpl.getInstance(pQName.getPackageName(),
56                                              getGroupName(pGroup) + name);
57         } else {
58             return JavaQNameImpl.getInnerInstance(pQName, name);
59         }
60     }
61 }
62
Popular Tags