KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.ws.jaxme.generator.sg.impl;
17
18 import org.apache.ws.jaxme.generator.sg.Context;
19 import org.apache.ws.jaxme.generator.sg.GroupSG;
20 import org.apache.ws.jaxme.generator.sg.GroupSGChain;
21 import org.apache.ws.jaxme.generator.sg.ParticleSG;
22 import org.apache.ws.jaxme.generator.sg.ParticleSGChain;
23 import org.apache.ws.jaxme.generator.sg.SGFactory;
24 import org.apache.ws.jaxme.generator.sg.SchemaSG;
25 import org.apache.ws.jaxme.xs.XSGroup;
26 import org.apache.ws.jaxme.xs.XSParticle;
27 import org.apache.ws.jaxme.xs.xml.XsQName;
28 import org.xml.sax.Locator JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30
31
32 /**
33  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
34  */

35 public class JAXBGroupSG extends JAXBSGItem implements GroupSGChain {
36     private ParticleSG[] particles;
37     private final boolean isGlobal, isAll, isSequence, isChoice;
38     private final Context classContext;
39     private final XsQName qName;
40     
41     /** <p>Creates a new, global group.</p>
42      */

43     protected JAXBGroupSG(SGFactory pFactory, SchemaSG pSchema, XSGroup pGroup) throws SAXException JavaDoc {
44         super(pFactory, pSchema, pGroup);
45         isGlobal = true;
46         qName = pGroup.getName();
47         isAll = pGroup.isAll();
48         isSequence = pGroup.isSequence();
49         isChoice = pGroup.isChoice();
50         classContext = new GlobalContext(pGroup.getName(), pGroup, null, "Group", pSchema);
51     }
52     
53     /** <p>Creates a new, local group.</p>
54      */

55     protected JAXBGroupSG(SGFactory pFactory, SchemaSG pSchema, XSGroup pGroup, Context pContext)
56     throws SAXException JavaDoc {
57         super(pFactory, pSchema, pGroup);
58         isGlobal = pGroup.isGlobal();
59         qName = isGlobal ? pGroup.getName() : null;
60         isAll = pGroup.isAll();
61         isSequence = pGroup.isSequence();
62         isChoice = pGroup.isChoice();
63         classContext = pContext;
64     }
65     
66     public Object JavaDoc newParticleSG(GroupSG pController, XSParticle pParticle) throws SAXException JavaDoc {
67         return new JAXBParticleSG(pController.getFactory(), pParticle, classContext);
68     }
69     
70     public Context getClassContext(GroupSG pController) { return classContext; }
71     
72     public SGFactory getFactory(GroupSG pController) { return getFactory(); }
73     public SchemaSG getSchema(GroupSG pController) { return getSchema(); }
74     public Locator JavaDoc getLocator(GroupSG pController) { return getLocator(); }
75     public ParticleSG[] getParticles(GroupSG pController) throws SAXException JavaDoc {
76         if (particles == null) {
77             XSParticle[] xsParticles = ((XSGroup) getXSObject()).getParticles();
78             particles = new ParticleSG[xsParticles.length];
79             for (int i = 0; i < xsParticles.length; i++) {
80                 ParticleSGChain chain = (ParticleSGChain) pController.newParticleSG(xsParticles[i]);
81                 ParticleSG particle = new ParticleSGImpl(chain);
82                 particle.init();
83                 particles[i] = particle;
84             }
85         }
86         return particles;
87     }
88     
89     public void init(GroupSG pController) throws SAXException JavaDoc {
90     }
91     
92     public boolean isAll(GroupSG pController) { return isAll; }
93     public boolean isGlobal(GroupSG pController) { return isGlobal; }
94     public boolean isChoice(GroupSG pController) { return isChoice; }
95     public boolean isSequence(GroupSG pController) { return isSequence; }
96     
97     public XsQName getName(GroupSG pController) {
98         if (qName == null) {
99             throw new IllegalStateException JavaDoc("Attempt to obtain a local groups name.");
100         }
101         return qName;
102     }
103 }
104
Popular Tags