KickJava   Java API By Example, From Geeks To Geeks.

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


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.generator.sg.impl;
18
19 import org.apache.ws.jaxme.generator.sg.AttributeSG;
20 import org.apache.ws.jaxme.generator.sg.AttributeSGChain;
21 import org.apache.ws.jaxme.generator.sg.Context;
22 import org.apache.ws.jaxme.generator.sg.PropertySG;
23 import org.apache.ws.jaxme.generator.sg.PropertySGChain;
24 import org.apache.ws.jaxme.generator.sg.SGFactory;
25 import org.apache.ws.jaxme.generator.sg.SGlet;
26 import org.apache.ws.jaxme.generator.sg.SchemaSG;
27 import org.apache.ws.jaxme.generator.sg.TypeSG;
28 import org.apache.ws.jaxme.js.DirectAccessible;
29 import org.apache.ws.jaxme.js.JavaMethod;
30 import org.apache.ws.jaxme.xs.XSAttribute;
31 import org.apache.ws.jaxme.xs.XSType;
32 import org.apache.ws.jaxme.xs.XSWildcard;
33 import org.apache.ws.jaxme.xs.xml.XsNamespaceList;
34 import org.apache.ws.jaxme.xs.xml.XsQName;
35 import org.apache.ws.jaxme.xs.xml.XsTWildcard;
36 import org.apache.ws.jaxme.xs.xml.XsTWildcard.ProcessContents;
37 import org.xml.sax.Locator JavaDoc;
38 import org.xml.sax.SAXException JavaDoc;
39
40
41 /**
42  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
43  */

44 class JAXBAttributeSG extends JAXBSGItem implements AttributeSGChain {
45     private final boolean isRequired, isWildcard;
46     private final XsQName name;
47     private final XsNamespaceList namespaceList;
48     private final XsTWildcard.ProcessContents processContents;
49     private XSAttribute xsAttribute;
50     private XSWildcard xsWildcard;
51     private final TypeSG typeSG;
52     private PropertySG propertySG;
53     
54     
55     protected JAXBAttributeSG(SchemaSG pSchema, XSAttribute pAttribute, Context pClassContext) throws SAXException JavaDoc {
56         super(pSchema.getFactory(), pSchema, pAttribute);
57         xsAttribute = pAttribute;
58         xsWildcard = null;
59         isRequired = !pAttribute.isOptional();
60         name = pAttribute.getName();
61         XSType type = pAttribute.getType();
62         if (type == null) {
63             throw new IllegalStateException JavaDoc("The attribute type must not be null.");
64         }
65         if (type.isGlobal()) {
66             typeSG = getFactory().getTypeSG(type);
67             if (typeSG == null) {
68                 throw new IllegalStateException JavaDoc("Unknown global type: " + type.getName());
69             }
70         } else {
71             typeSG = getFactory().getTypeSG(pAttribute.getType(), pClassContext, name);
72         }
73         isWildcard = false;
74         namespaceList = null;
75         processContents = null;
76     }
77     
78     protected JAXBAttributeSG(SchemaSG pSchema, XSWildcard pWildcard, Context pClassContext) throws SAXException JavaDoc {
79         super(pSchema.getFactory(), pSchema, pWildcard);
80         xsWildcard = pWildcard;
81         xsAttribute = null;
82         isRequired = false;
83         name = null;
84         typeSG = null;
85         isWildcard = true;
86         namespaceList = pWildcard.getNamespaceList();
87         processContents = pWildcard.getProcessContents();
88     }
89     
90     public Object JavaDoc newPropertySGChain(AttributeSG pController) {
91         PropertySGChain result;
92         if (xsWildcard != null) {
93             result = new AnyAttributePropertySG(pController, xsWildcard);
94             xsWildcard = null;
95         } else if (xsAttribute != null) {
96             result = new JAXBPropertySG(pController, xsAttribute);
97             xsAttribute = null; // Make this available for garbage collection
98
} else {
99             throw new IllegalStateException JavaDoc("PropertySG is already created.");
100         }
101         return result;
102     }
103     
104     public void init(AttributeSG pController) throws SAXException JavaDoc {
105         PropertySGChain chain = (PropertySGChain) pController.newPropertySGChain();
106         propertySG = new PropertySGImpl(chain);
107         propertySG.init();
108     }
109     
110     public PropertySG getPropertySG(AttributeSG pController) { return propertySG; }
111     public TypeSG getTypeSG(AttributeSG pController) { return typeSG; }
112     public SGFactory getFactory(AttributeSG pController) { return getFactory(); }
113     public SchemaSG getSchema(AttributeSG pController) { return getSchema(); }
114     public Locator JavaDoc getLocator(AttributeSG pController) { return getLocator(); }
115     public XsQName getName(AttributeSG pController) { return name; }
116     
117     public boolean isRequired(AttributeSG pAttrController) { return isRequired; }
118     
119     public void forAllValues(AttributeSG pController, JavaMethod pMethod,
120                              DirectAccessible pElement, SGlet pSGlet) throws SAXException JavaDoc {
121         pController.getPropertySG().forAllValues(pMethod, pElement, pSGlet);
122     }
123     
124     public void forAllNonNullValues(AttributeSG pController, JavaMethod pMethod,
125                                     DirectAccessible pElement, SGlet pSGlet) throws SAXException JavaDoc {
126         pController.getPropertySG().forAllNonNullValues(pMethod, pElement, pSGlet);
127     }
128
129     public boolean isWildcard(AttributeSG pController) {
130         return isWildcard;
131     }
132
133     public XsNamespaceList getNamespaceList(AttributeSG pController) {
134         return namespaceList;
135     }
136
137     public ProcessContents getProcessContents(AttributeSG pController) {
138         return processContents;
139     }
140 }
141
Popular Tags