You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2004/10/14 00:51:53 UTC
cvs commit: ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/util QNameUtil.java
jochen 2004/10/13 15:51:53
Modified: src/jaxme/org/apache/ws/jaxme/generator/sg/impl
JAXBGroupSG.java JAXBComplexContentTypeSG.java
JAXBPropertySG.java JAXBObjectSG.java
JAXBParticleSG.java JAXBTypeSG.java
src/jaxme/org/apache/ws/jaxme/junit JiraTest.java
src/jaxme/org/apache/ws/jaxme/generator/sg GroupSG.java
TypeSG.java ObjectSG.java ComplexContentSG.java
ParticleSG.java
Added: src/jaxme/org/apache/ws/jaxme/generator/util QNameUtil.java
Log:
Added SPG generation.
Revision Changes Path
1.16 +53 -1 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBGroupSG.java
Index: JAXBGroupSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBGroupSG.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- JAXBGroupSG.java 11 Oct 2004 23:03:48 -0000 1.15
+++ JAXBGroupSG.java 13 Oct 2004 22:51:53 -0000 1.16
@@ -12,7 +12,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-
*/
package org.apache.ws.jaxme.generator.sg.impl;
@@ -21,6 +20,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.xml.bind.JAXBException;
@@ -55,6 +55,9 @@
import org.apache.ws.jaxme.js.PlaceHolder;
import org.apache.ws.jaxme.logging.Logger;
import org.apache.ws.jaxme.logging.LoggerAccess;
+import org.apache.ws.jaxme.spg.SPGGroup;
+import org.apache.ws.jaxme.spg.SPGParticle;
+import org.apache.ws.jaxme.spg.impl.SPGGroupImpl;
import org.apache.ws.jaxme.xs.XSGroup;
import org.apache.ws.jaxme.xs.XSParticle;
import org.apache.ws.jaxme.xs.xml.XsQName;
@@ -71,12 +74,14 @@
private ParticleSG[] particles;
private final boolean isGlobal, isAll, isSequence, isChoice;
private final Context classContext;
+ private final XsQName qName;
/** <p>Creates a new, global group.</p>
*/
protected JAXBGroupSG(SGFactory pFactory, SchemaSG pSchema, XSGroup pGroup) throws SAXException {
super(pFactory, pSchema, pGroup);
isGlobal = true;
+ qName = pGroup.getName();
isAll = pGroup.isAll();
isSequence = pGroup.isSequence();
isChoice = pGroup.isChoice();
@@ -89,6 +94,7 @@
throws SAXException {
super(pFactory, pSchema, pGroup);
isGlobal = false;
+ qName = null;
isAll = pGroup.isAll();
isSequence = pGroup.isSequence();
isChoice = pGroup.isChoice();
@@ -774,4 +780,50 @@
log.finest(mName, "->", pController.isGlobal() ? pController.getClassContext().toString() : "Local group");
log.finest(mName, "<-");
}
+
+ public SPGGroup getSPGGroup(GroupSG pController, Map pGlobalElementNames,
+ Map pGlobalGroupNames) throws SAXException {
+ SPGGroupImpl result = new SPGGroupImpl();
+ if (pController.isGlobal()) {
+ XsQName qName = pController.getName();
+ if (pGlobalGroupNames.containsKey(qName)) {
+ throw new IllegalStateException("Recursion detected for group " + qName);
+ }
+ pGlobalGroupNames.put(qName, result);
+ }
+
+ if (pController.isAll()) {
+ result.setSequence(false);
+ result.setChoice(false);
+ result.setAll(true);
+ } else if (pController.isChoice()) {
+ result.setSequence(false);
+ result.setAll(false);
+ result.setChoice(true);
+ } else if (pController.isSequence()) {
+ result.setAll(false);
+ result.setChoice(false);
+ result.setSequence(true);
+ } else {
+ throw new IllegalStateException("Unknown group type: Neither of choice, sequence, or all");
+ }
+ ParticleSG[] particles = pController.getParticles();
+ List partList = new ArrayList();
+ if (particles != null) {
+ for (int i = 0; i < particles.length; i++) {
+ ParticleSG particle = particles[i];
+ partList.add(particle.getSPGParticle(pGlobalElementNames, pGlobalGroupNames));
+ }
+ }
+ SPGParticle[] partArray = (SPGParticle[]) partList.toArray(new SPGParticle[partList.size()]);
+ result.setParticles(partArray);
+ return result;
+ }
+
+ public XsQName getName(GroupSG pController) {
+ if (qName == null) {
+ throw new IllegalStateException("Attempt to obtain a local groups name.");
+ }
+ return qName;
+ }
}
1.4 +39 -27 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexContentTypeSG.java
Index: JAXBComplexContentTypeSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexContentTypeSG.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JAXBComplexContentTypeSG.java 27 Aug 2004 21:02:22 -0000 1.3
+++ JAXBComplexContentTypeSG.java 13 Oct 2004 22:51:53 -0000 1.4
@@ -12,7 +12,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-
*/
package org.apache.ws.jaxme.generator.sg.impl;
@@ -26,32 +25,45 @@
import org.xml.sax.SAXException;
-/**
- * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+/** Default implementation of
+ * {@link org.apache.ws.jaxme.generator.sg.ComplexContentSG}.
*/
public class JAXBComplexContentTypeSG implements ComplexContentSGChain {
- private final GroupSG groupSG;
-
- protected JAXBComplexContentTypeSG(ComplexTypeSG pComplexTypeSG, XSType pType) throws SAXException {
- if (pType.getComplexType().isEmpty()) {
- groupSG = null;
- } else {
- XSParticle particle = pType.getComplexType().getParticle();
- if (particle == null) {
- throw new NullPointerException("Missing group particle for type = " + pType.getName());
- }
- if (particle.isGroup()) {
- XSGroup group = particle.getGroup();
- groupSG = pComplexTypeSG.getTypeSG().getFactory().getGroupSG(group, pComplexTypeSG.getClassContext());
- } else {
- throw new IllegalStateException("Expected internal group");
- }
- }
- }
-
- public void init(ComplexContentSG pController) throws SAXException {}
-
- public GroupSG getGroupSG(ComplexContentSG pController) {
- return groupSG;
- }
+ private final GroupSG groupSG;
+ private final boolean isEmpty, isMixed;
+
+ protected JAXBComplexContentTypeSG(ComplexTypeSG pComplexTypeSG, XSType pType) throws SAXException {
+ if (pType.getComplexType().isEmpty()) {
+ groupSG = null;
+ isEmpty = true;
+ isMixed = false;
+ } else {
+ XSParticle particle = pType.getComplexType().getParticle();
+ if (particle == null) {
+ throw new NullPointerException("Missing group particle for type = " + pType.getName());
+ }
+ if (particle.isGroup()) {
+ XSGroup group = particle.getGroup();
+ groupSG = pComplexTypeSG.getTypeSG().getFactory().getGroupSG(group, pComplexTypeSG.getClassContext());
+ } else {
+ throw new IllegalStateException("Expected internal group");
+ }
+ isEmpty = false;
+ isMixed = pType.getComplexType().isMixed();
+ }
+ }
+
+ public void init(ComplexContentSG pController) throws SAXException {}
+
+ public GroupSG getGroupSG(ComplexContentSG pController) {
+ return groupSG;
+ }
+
+ public boolean isEmpty(ComplexContentSG pController) {
+ return isEmpty;
+ }
+
+ public boolean isMixed(ComplexContentSG pController) {
+ return isMixed;
+ }
}
1.10 +2 -1 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBPropertySG.java
Index: JAXBPropertySG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBPropertySG.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- JAXBPropertySG.java 2 Sep 2004 11:25:31 -0000 1.9
+++ JAXBPropertySG.java 13 Oct 2004 22:51:53 -0000 1.10
@@ -140,7 +140,8 @@
public JavaMethod getXMLSetMethod(PropertySG pController, JavaSource pSource) throws SAXException {
return typeSG.getXMLSetMethod(pSource, pController.getXMLFieldName(),
- pController.getXMLSetMethodName());
+ pController.getXMLSetMethodName(),
+ pController.hasIsSetMethod());
}
public JavaMethod getXMLIsSetMethod(PropertySG pController, JavaSource pSource) throws SAXException {
1.7 +160 -3 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBObjectSG.java
Index: JAXBObjectSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBObjectSG.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JAXBObjectSG.java 27 Aug 2004 13:19:26 -0000 1.6
+++ JAXBObjectSG.java 13 Oct 2004 22:51:53 -0000 1.7
@@ -12,10 +12,14 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-
*/
package org.apache.ws.jaxme.generator.sg.impl;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import javax.xml.bind.Element;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
@@ -23,13 +27,17 @@
import org.apache.ws.jaxme.JMElement;
import org.apache.ws.jaxme.JMHandler;
import org.apache.ws.jaxme.JMXmlSerializer;
+import org.apache.ws.jaxme.generator.sg.AttributeSG;
+import org.apache.ws.jaxme.generator.sg.ComplexContentSG;
import org.apache.ws.jaxme.generator.sg.ComplexTypeSG;
import org.apache.ws.jaxme.generator.sg.Context;
+import org.apache.ws.jaxme.generator.sg.GroupSG;
import org.apache.ws.jaxme.generator.sg.ObjectSG;
import org.apache.ws.jaxme.generator.sg.ObjectSGChain;
import org.apache.ws.jaxme.generator.sg.SGFactory;
import org.apache.ws.jaxme.generator.sg.SchemaSG;
import org.apache.ws.jaxme.generator.sg.TypeSG;
+import org.apache.ws.jaxme.generator.util.QNameUtil;
import org.apache.ws.jaxme.js.DirectAccessible;
import org.apache.ws.jaxme.js.JavaField;
import org.apache.ws.jaxme.js.JavaMethod;
@@ -38,12 +46,24 @@
import org.apache.ws.jaxme.js.JavaSourceFactory;
import org.apache.ws.jaxme.logging.Logger;
import org.apache.ws.jaxme.logging.LoggerAccess;
+import org.apache.ws.jaxme.spg.SPGAttrWildcard;
+import org.apache.ws.jaxme.spg.SPGAttribute;
+import org.apache.ws.jaxme.spg.SPGElement;
+import org.apache.ws.jaxme.spg.SPGGroup;
+import org.apache.ws.jaxme.spg.SPGParticle;
+import org.apache.ws.jaxme.spg.impl.SPGAttrWildcardImpl;
+import org.apache.ws.jaxme.spg.impl.SPGAttributeImpl;
+import org.apache.ws.jaxme.spg.impl.SPGElementImpl;
+import org.apache.ws.jaxme.spg.impl.SPGGroupImpl;
+import org.apache.ws.jaxme.spg.impl.SPGParticleImpl;
import org.apache.ws.jaxme.xs.XSAny;
import org.apache.ws.jaxme.xs.XSAttribute;
import org.apache.ws.jaxme.xs.XSElement;
import org.apache.ws.jaxme.xs.XSObject;
import org.apache.ws.jaxme.xs.XSSimpleContentType;
import org.apache.ws.jaxme.xs.XSType;
+import org.apache.ws.jaxme.xs.xml.XsAnyURI;
+import org.apache.ws.jaxme.xs.xml.XsNamespaceList;
import org.apache.ws.jaxme.xs.xml.XsQName;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
@@ -87,8 +107,8 @@
* is generated within the given {@link Context}.</p>
*/
private JAXBObjectSG(SGFactory pFactory, SchemaSG pSchema, XSObject pObject,
- Context pClassContext) throws SAXException {
- super(pFactory, pSchema, pObject);
+ Context pClassContext) throws SAXException {
+ super(pFactory, pSchema, pObject);
final String mName = "<init>(XSObject,Context)";
boolean isClassGlobal;
if (pObject instanceof XSElement) {
@@ -310,6 +330,7 @@
log.finest(mName, "->", pController.getName());
pController.getXMLInterface();
pController.getXMLImplementation();
+ pController.getSPGElement();
pController.getXMLSerializer();
pController.getXMLHandler();
@@ -323,4 +344,140 @@
public boolean isGlobal(ObjectSG pController) throws SAXException {
return global;
}
+
+ private void setAttributes(SPGElementImpl pElement, ComplexTypeSG pComplexTypeSG) {
+ AttributeSG[] attrs = pComplexTypeSG.getAttributes();
+ List attrList = new ArrayList();
+ List wildcardList = new ArrayList();
+ for (int i = 0; i < attrs.length; i++) {
+ AttributeSG attr = attrs[i];
+ if (attr.isWildcard()) {
+ XsNamespaceList namespaceList = attr.getNamespaceList();
+ SPGAttrWildcardImpl xspWildcard = new SPGAttrWildcardImpl();
+ if (namespaceList.isAny()) {
+ xspWildcard.setOther(false);
+ xspWildcard.setUris(null);
+ xspWildcard.setAny(true);
+ } else if (namespaceList.isOther()) {
+ xspWildcard.setAny(false);
+ xspWildcard.setUris(null);
+ xspWildcard.setOther(true);
+ } else {
+ XsAnyURI[] uris = namespaceList.getUris();
+ String[] sUris = new String[uris.length];
+ for (int j = 0; j < uris.length; j++) {
+ sUris[j] = uris[j].getURI();
+ }
+ xspWildcard.setAny(false);
+ xspWildcard.setOther(false);
+ xspWildcard.setUris(sUris);
+ }
+ wildcardList.add(xspWildcard);
+ } else {
+ SPGAttributeImpl xspAttr = new SPGAttributeImpl();
+ xspAttr.setQName(QNameUtil.newQName(attr.getName()));
+ xspAttr.setRequired(attr.isRequired());
+ attrList.add(xspAttr);
+ }
+ }
+ SPGAttribute[] attrArray = (SPGAttribute[]) attrList.toArray(new SPGAttribute[attrList.size()]);
+ pElement.setAttributes(attrArray);
+ SPGAttrWildcard[] wildcardArray = (SPGAttrWildcard[]) wildcardList.toArray(new SPGAttrWildcard[wildcardList.size()]);
+ pElement.setAttrWildcards(wildcardArray);
+ }
+
+ private SPGGroup getEmptyGroup() {
+ SPGGroupImpl result = new SPGGroupImpl();
+ result.setSequence(true);
+ result.setParticles(new SPGParticle[0]);
+ return result;
+ }
+
+ public SPGElement getSPGElement(ObjectSG pController) throws SAXException {
+ Map elements = new HashMap();
+ Map groups = new HashMap();
+ return pController.getSPGElement(elements, groups);
+ }
+
+ private class Key {
+ private final boolean isGlobal, isTypeGlobal;
+ private final XsQName qName, typeQName;
+ Key(ObjectSG pController) throws SAXException {
+ isGlobal = pController.isGlobal();
+ qName = pController.getName();
+ isTypeGlobal = pController.getTypeSG().isGlobalType();
+ typeQName = isTypeGlobal ? pController.getTypeSG().getName() : null;
+ }
+ public int hashCode() {
+ return (isGlobal ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode()) +
+ (isTypeGlobal ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode()) +
+ qName.hashCode() +
+ (typeQName == null ? 0 : typeQName.hashCode());
+ }
+ public boolean equals(Object pOther) {
+ if (pOther == null || !(pOther instanceof Key)) {
+ return false;
+ }
+ Key other = (Key) pOther;
+ if (isGlobal != other.isGlobal
+ || isTypeGlobal != other.isTypeGlobal
+ || !qName.equals(other.qName)) {
+ return false;
+ }
+ if (typeQName == null) {
+ return other.typeQName == null;
+ } else {
+ return typeQName.equals(other.typeQName);
+ }
+ }
+ }
+
+ public SPGElement getSPGElement(final ObjectSG pController,
+ Map pGlobalElementNames,
+ Map pGlobalGroupNames) throws SAXException {
+ XsQName qName = pController.getName();
+ SPGElementImpl result;
+ if (pController.isGlobal() || pController.getTypeSG().isGlobalType()) {
+ Key key = new Key(pController);
+ SPGElement element = (SPGElement) pGlobalElementNames.get(key);
+ if (element != null) {
+ return element;
+ }
+ result = new SPGElementImpl();
+ pGlobalElementNames.put(key, result);
+ } else {
+ result = new SPGElementImpl();
+ }
+ result.setQName(QNameUtil.newQName(qName));
+ TypeSG type = pController.getTypeSG();
+ if (type.isComplex()) {
+ ComplexTypeSG cType = type.getComplexTypeSG();
+ setAttributes(result, cType);
+ if (cType.hasSimpleContent()) {
+ result.setParticle(null);
+ } else {
+ ComplexContentSG ccType = cType.getComplexContentSG();
+ SPGGroup group;
+ if (ccType.isEmpty()) {
+ group = getEmptyGroup();
+ } else {
+ if (ccType.isMixed()) {
+ result.setMixed(true);
+ }
+ GroupSG groupSG = ccType.getGroupSG();
+ group = groupSG.getSPGGroup(pGlobalElementNames, pGlobalGroupNames);
+ }
+ SPGParticleImpl particle = new SPGParticleImpl();
+ particle.setGroup(group);
+ particle.setMinOccurs(1);
+ particle.setMaxOccurs(1);
+ result.setParticle(particle);
+ }
+ } else {
+ result.setAttrWildcards(new SPGAttrWildcard[0]);
+ result.setAttributes(new SPGAttribute[0]);
+ result.setParticle(null);
+ }
+ return result;
+ }
}
1.5 +36 -2 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBParticleSG.java
Index: JAXBParticleSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBParticleSG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JAXBParticleSG.java 27 Aug 2004 01:02:42 -0000 1.4
+++ JAXBParticleSG.java 13 Oct 2004 22:51:53 -0000 1.5
@@ -12,10 +12,12 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-
*/
package org.apache.ws.jaxme.generator.sg.impl;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.ws.jaxme.generator.sg.Context;
import org.apache.ws.jaxme.generator.sg.GroupSG;
import org.apache.ws.jaxme.generator.sg.ObjectSG;
@@ -28,10 +30,15 @@
import org.apache.ws.jaxme.generator.sg.TypeSG;
import org.apache.ws.jaxme.js.DirectAccessible;
import org.apache.ws.jaxme.js.JavaMethod;
-import org.apache.ws.jaxme.js.JavaQName;
+import org.apache.ws.jaxme.spg.SPGElement;
+import org.apache.ws.jaxme.spg.SPGGroup;
+import org.apache.ws.jaxme.spg.SPGParticle;
+import org.apache.ws.jaxme.spg.impl.SPGParticleImpl;
import org.apache.ws.jaxme.xs.XSAny;
import org.apache.ws.jaxme.xs.XSElement;
+import org.apache.ws.jaxme.xs.XSGroup;
import org.apache.ws.jaxme.xs.XSParticle;
+import org.apache.ws.jaxme.xs.xml.XsQName;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
@@ -154,4 +161,31 @@
throw new IllegalStateException("Wildcards and subgroups are not yet supported.");
}
}
+
+ public SPGParticle getSPGParticle(ParticleSG pController, Map pGlobalElementNames, Map pGlobalGroupNames) throws SAXException {
+ SPGParticleImpl result = new SPGParticleImpl();
+ result.setMinOccurs(pController.getMinOccurs());
+ result.setMaxOccurs(pController.getMaxOccurs());
+ if (pController.isElement()) {
+ ObjectSG element = pController.getObjectSG();
+ SPGElement spgElement = element.getSPGElement(pGlobalElementNames, pGlobalGroupNames);
+ result.setElement(spgElement);
+ } else if (pController.isGroup()) {
+ GroupSG group = pController.getGroupSG();
+ SPGGroup spgGroup = null;
+ if (group.isGlobal()) {
+ spgGroup = (SPGGroup) pGlobalGroupNames.get(group.getName());
+ }
+ if (group == null) {
+ spgGroup = group.getSPGGroup(pGlobalElementNames, pGlobalGroupNames);
+ }
+ result.setGroup(spgGroup);
+ } else if (pController.isWildcard()) {
+ // result.setWildcard(pController.getSPGWildcard());
+ throw new IllegalStateException("Wildcard elements are not yet supported.");
+ } else {
+ throw new IllegalStateException("Invalid particle type: Neither of element, group, or wildcard");
+ }
+ return result;
+ }
}
1.12 +38 -31 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBTypeSG.java
Index: JAXBTypeSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBTypeSG.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- JAXBTypeSG.java 2 Oct 2004 00:39:56 -0000 1.11
+++ JAXBTypeSG.java 13 Oct 2004 22:51:53 -0000 1.12
@@ -330,31 +330,40 @@
}
public JavaMethod getXMLSetMethod(TypeSG pController, JavaSource pSource,
- String pFieldName, String pMethodName) throws SAXException {
- if (pController.isComplex()) {
- String pName = "p" + Character.toUpperCase(pFieldName.charAt(0)) + pFieldName.substring(1);
- JavaMethod jm = pSource.newJavaMethod(pMethodName, JavaQNameImpl.VOID, JavaSource.PUBLIC);
- JavaQName runtimeType;
- if (pFieldName.equals("value") && pController.getComplexTypeSG().hasSimpleContent()) {
- SimpleContentSG obj = pController.getComplexTypeSG().getSimpleContentSG();
- runtimeType = obj.getContentTypeSG().getRuntimeType();
- if (pController.isRestriction()) {
- if (pController.getRestrictedType().isExtension()) {
- runtimeType = pController.getRestrictedType().getExtendedType().getRuntimeType();
- }
- }
+ String pFieldName, String pMethodName,
+ boolean pSetIsSet) throws SAXException {
+ if (pController.isComplex()) {
+ String pName = "p" + Character.toUpperCase(pFieldName.charAt(0)) + pFieldName.substring(1);
+ JavaMethod jm = pSource.newJavaMethod(pMethodName, JavaQNameImpl.VOID, JavaSource.PUBLIC);
+ JavaQName runtimeType;
+ if (pFieldName.equals("value") && pController.getComplexTypeSG().hasSimpleContent()) {
+ SimpleContentSG obj = pController.getComplexTypeSG().getSimpleContentSG();
+ runtimeType = obj.getContentTypeSG().getRuntimeType();
+ if (pController.isRestriction()) {
+ if (pController.getRestrictedType().isExtension()) {
+ runtimeType = pController.getRestrictedType().getExtendedType().getRuntimeType();
+ }
+ }
+ }
+ else {
+ runtimeType = pController.getRuntimeType();
+ }
+ DirectAccessible param = jm.addParam(runtimeType, pName);
+ if (!pSource.isInterface()) {
+ jm.addLine(pFieldName, " = ", param, ";");
+ }
+ return jm;
+ } else {
+ JavaMethod jm = pController.getSimpleTypeSG().getXMLSetMethod(pSource, pFieldName, pMethodName);
+ if (pSetIsSet && pController.getRuntimeType().isPrimitive()) {
+ jm.addLine(getIsSetCheckFieldName(pFieldName), " = true;");
}
- else {
- runtimeType = pController.getRuntimeType();
- }
- DirectAccessible param = jm.addParam(runtimeType, pName);
- if (!pSource.isInterface()) {
- jm.addLine(pFieldName, " = ", param, ";");
- }
- return jm;
- } else {
- return pController.getSimpleTypeSG().getXMLSetMethod(pSource, pFieldName, pMethodName);
- }
+ return jm;
+ }
+ }
+
+ private String getIsSetCheckFieldName(String pFieldName) {
+ return "has" + Character.toUpperCase(pFieldName.charAt(0)) + pFieldName.substring(1);
}
/**
@@ -362,15 +371,13 @@
* isSet and unset methods will be implemented by a flag and corresponding default value if it exist.
*/
public JavaMethod getXMLIsSetMethod(TypeSG pController, JavaSource pSource,
- String pFieldName, String pMethodName) throws SAXException {
+ String pFieldName, String pMethodName)
+ throws SAXException {
JavaMethod jm = pSource.newJavaMethod(pMethodName, BooleanSG.BOOLEAN_TYPE, JavaSource.PUBLIC);
if (!pSource.isInterface()) {
- JavaQName checkQName = pController.getRuntimeType();
- boolean isPrimitive = "".equals(checkQName.getPackageName());
- if (isPrimitive) {
- String checkFieldName = "has" + Character.toUpperCase(pFieldName.charAt(0)) + pFieldName.substring(1);
- pSource.newJavaField(checkFieldName, BooleanSG.BOOLEAN_TYPE);
- jm.addLine("return " + checkFieldName + ";");
+ if (pController.getRuntimeType().isPrimitive()) {
+ JavaField jf = pSource.newJavaField(getIsSetCheckFieldName(pFieldName), BooleanSG.BOOLEAN_TYPE);
+ jm.addLine("return ", jf, ";");
} else {
jm.addLine("return (" + pFieldName + " != null);");
}
1.4 +10 -5 ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java
Index: JiraTest.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JiraTest.java 11 Oct 2004 23:03:48 -0000 1.3
+++ JiraTest.java 13 Oct 2004 22:51:53 -0000 1.4
@@ -1,13 +1,9 @@
package org.apache.ws.jaxme.junit;
-import java.io.StringReader;
-
-import javax.xml.bind.JAXBContext;
-
import org.apache.ws.jaxme.test.misc.types.Row;
import org.apache.ws.jaxme.test.misc.types.impl.RowImpl;
-import org.xml.sax.InputSource;
+import magoffin.matt.ieat.domain.impl.IngredientImpl;
import net.dspc.commons.activitymodel.TransmissionData;
import net.dspc.commons.activitymodel2.Body1;
import net.dspc.commons.activitymodel2.Body2;
@@ -80,5 +76,14 @@
" <ex:cell id=\"1\">a</ex:cell>\n" +
"</ex:row>";
unmarshalMarshalUnmarshal(Row.class, xml);
+ }
+
+ /** Test for <a href="http://nagoya.apache.org/jira/browse/JAXME-39">JAXME-39</a>
+ */
+ public void testJaxMe39() throws Exception {
+ IngredientImpl ingredientImpl = new IngredientImpl();
+ assertTrue(!ingredientImpl.isSetIngredientId());
+ ingredientImpl.setIngredientId(new Integer(0));
+ assertTrue(ingredientImpl.isSetIngredientId());
}
}
1.5 +88 -71 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/GroupSG.java
Index: GroupSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/GroupSG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GroupSG.java 9 Sep 2004 00:41:46 -0000 1.4
+++ GroupSG.java 13 Oct 2004 22:51:53 -0000 1.5
@@ -12,13 +12,16 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-
*/
package org.apache.ws.jaxme.generator.sg;
+import java.util.Map;
+
import org.apache.ws.jaxme.js.DirectAccessible;
import org.apache.ws.jaxme.js.JavaSource;
+import org.apache.ws.jaxme.spg.SPGGroup;
import org.apache.ws.jaxme.xs.XSParticle;
+import org.apache.ws.jaxme.xs.xml.XsQName;
import org.apache.ws.jaxme.generator.sg.Context;
import org.apache.ws.jaxme.generator.sg.ParticleSG;
import org.apache.ws.jaxme.generator.sg.SGItem;
@@ -26,76 +29,90 @@
/** <p>Interface of a source generator for model groups.</p>
- *
- * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
*/
public interface GroupSG extends SGItem {
- /** <p>Returns whether the group is global.</p>
- */
- public boolean isGlobal();
-
- /** <p>Returns whether the groups compositor is "all".</p>
- */
- public boolean isAll();
-
- /** <p>Returns whether the groups compositor is "choice".</p>
- */
- public boolean isChoice();
-
- /** <p>Returns whether the groups compositor is "sequence".</p>
- */
- public boolean isSequence();
-
- /** <p>Returns the groups {@link Context}.</p>
- */
- public Context getClassContext() throws SAXException;
-
- /** <p>Generates the groups interface.</p>
- */
- public JavaSource getXMLInterface() throws SAXException;
-
- /** <p>Generates the groups implementation.</p>
- */
- public JavaSource getXMLImplementation() throws SAXException;
-
- /** <p>Generates the groups set and get methods.</p>
- */
- public void generateProperties(JavaSource pSource) throws SAXException;
-
- /** <p>Generates the XML interfaces subclasses.</p>
- */
- public void generateXMLInterfaceSubclasses(JavaSource pSource) throws SAXException;
-
- /** <p>Generates the XML implementations subclasses.</p>
- */
- public void generateXMLImplementationSubclasses(JavaSource pSource) throws SAXException;
-
- /** <p>Generates the XML handlers methods for reading child elements.</p>
- */
- public void generateXMLHandlersElements(JavaSource pSource, DirectAccessible pLevelVar) throws SAXException;
-
- /** <p>Generates the XML serializers methods that create child elements.</p>
- */
- public void generateXMLSerializersElements(JavaSource pSource) throws SAXException;
-
- /** <p>Generates the groups sources.</p>
- */
- public void generate() throws SAXException;
-
- /** <p>Returns the groups particles.</p>
- */
- public ParticleSG[] getParticles() throws SAXException;
-
- /** <p>Creates a new instance of
- * {@link org.apache.ws.jaxme.generator.sg.ParticleSGChain} generating the
- * given particle.</p>
- * <p><em>Implementation note</em>: The type
- * {@link org.apache.ws.jaxme.generator.sg.ParticleSGChain}
- * must not be exposed in the interface, because the interface
- * class is used to generate this type. In other words, this
- * interface must be compilable without the
- * {@link org.apache.ws.jaxme.generator.sg.ParticleSGChain}
- * interface.</p>
- */
- public Object newParticleSG(XSParticle pParticle) throws SAXException;
+ /** <p>Returns whether the group is global.</p>
+ */
+ public boolean isGlobal();
+
+ /** If the group is global: Returns the groups name.
+ * @throws IllegalStateException The group isn't global.
+ * @see #isGlobal()
+ */
+ public XsQName getName();
+
+ /** <p>Returns whether the groups compositor is "all".</p>
+ */
+ public boolean isAll();
+
+ /** <p>Returns whether the groups compositor is "choice".</p>
+ */
+ public boolean isChoice();
+
+ /** <p>Returns whether the groups compositor is "sequence".</p>
+ */
+ public boolean isSequence();
+
+ /** <p>Returns the groups {@link Context}.</p>
+ */
+ public Context getClassContext() throws SAXException;
+
+ /** <p>Generates the groups interface.</p>
+ */
+ public JavaSource getXMLInterface() throws SAXException;
+
+ /** <p>Generates the groups implementation.</p>
+ */
+ public JavaSource getXMLImplementation() throws SAXException;
+
+ /** <p>Generates the groups set and get methods.</p>
+ */
+ public void generateProperties(JavaSource pSource) throws SAXException;
+
+ /** <p>Generates the XML interfaces subclasses.</p>
+ */
+ public void generateXMLInterfaceSubclasses(JavaSource pSource) throws SAXException;
+
+ /** <p>Generates the XML implementations subclasses.</p>
+ */
+ public void generateXMLImplementationSubclasses(JavaSource pSource) throws SAXException;
+
+ /** <p>Generates the XML handlers methods for reading child elements.</p>
+ */
+ public void generateXMLHandlersElements(JavaSource pSource, DirectAccessible pLevelVar) throws SAXException;
+
+ /** <p>Generates the XML serializers methods that create child elements.</p>
+ */
+ public void generateXMLSerializersElements(JavaSource pSource) throws SAXException;
+
+ /** <p>Generates the groups sources.</p>
+ */
+ public void generate() throws SAXException;
+
+ /** <p>Returns the groups particles.</p>
+ */
+ public ParticleSG[] getParticles() throws SAXException;
+
+ /** <p>Creates a new instance of
+ * {@link org.apache.ws.jaxme.generator.sg.ParticleSGChain} generating the
+ * given particle.</p>
+ * <p><em>Implementation note</em>: The type
+ * {@link org.apache.ws.jaxme.generator.sg.ParticleSGChain}
+ * must not be exposed in the interface, because the interface
+ * class is used to generate this type. In other words, this
+ * interface must be compilable without the
+ * {@link org.apache.ws.jaxme.generator.sg.ParticleSGChain}
+ * interface.</p>
+ */
+ public Object newParticleSG(XSParticle pParticle) throws SAXException;
+
+ /** Converts the group into a matching instance of
+ * {@link SPGGroup}, which may be used to create a SAX handler.
+ * @param pGlobalElements Map of global element names, which are
+ * already processed; used to detect recursion
+ * @param pGlobalGroups Map of global group names, which are
+ * already processed; used to detect recursion
+ */
+ public SPGGroup getSPGGroup(Map pGlobalElements, Map pGlobalGroups)
+ throws SAXException;
}
1.7 +2 -2 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/TypeSG.java
Index: TypeSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/TypeSG.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TypeSG.java 9 Sep 2004 00:41:46 -0000 1.6
+++ TypeSG.java 13 Oct 2004 22:51:53 -0000 1.7
@@ -115,8 +115,8 @@
/** <p>Generates a set method returning an instance of this type.</p>
*/
- public JavaMethod getXMLSetMethod(JavaSource pSource,
- String pFieldName, String pMethodName) throws SAXException;
+ public JavaMethod getXMLSetMethod(JavaSource pSource, String pFieldName,
+ String pMethodName, boolean pSetIsSet) throws SAXException;
/** <p>Generates an "isSet" method returning whether the field is set.</p>
*/
1.5 +19 -0 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ObjectSG.java
Index: ObjectSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ObjectSG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ObjectSG.java 9 Sep 2004 00:41:46 -0000 1.4
+++ ObjectSG.java 13 Oct 2004 22:51:53 -0000 1.5
@@ -16,7 +16,10 @@
*/
package org.apache.ws.jaxme.generator.sg;
+import java.util.Map;
+
import org.apache.ws.jaxme.js.JavaSource;
+import org.apache.ws.jaxme.spg.SPGElement;
import org.apache.ws.jaxme.xs.xml.XsQName;
import org.apache.ws.jaxme.generator.sg.Context;
import org.apache.ws.jaxme.generator.sg.SGItem;
@@ -64,4 +67,20 @@
/** Returns whether the <code>ObjectSG</code> is global.
*/
public boolean isGlobal() throws SAXException;
+
+ /** Creates a {@link SPGElement}, which can be used to
+ * create a SAX handler. This method is invoked for global
+ * elements.
+ */
+ public SPGElement getSPGElement() throws SAXException;
+
+ /** Creates a {@link SPGElement}, which can be used to
+ * create a SAX handler. This method is invoked for
+ * global elements (with empty sets) and for any
+ * inner element, or group.
+ * @param pGlobalElements A map of element names, used to detect recursion.
+ * @param pGlobalGroups A map of group names, used to detect recursion.
+ */
+ public SPGElement getSPGElement(Map pGlobalElements, Map pGlobalGroups)
+ throws SAXException;
}
1.4 +16 -10 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ComplexContentSG.java
Index: ComplexContentSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ComplexContentSG.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ComplexContentSG.java 9 Sep 2004 00:41:46 -0000 1.3
+++ ComplexContentSG.java 13 Oct 2004 22:51:53 -0000 1.4
@@ -12,7 +12,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-
*/
package org.apache.ws.jaxme.generator.sg;
@@ -20,15 +19,22 @@
import org.apache.ws.jaxme.generator.sg.GroupSG;
-/**
- * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+/** Interface of a complex type with a complex content model.
*/
public interface ComplexContentSG {
- /** <p>Initializes the ComplexContentSG.</p>
- */
- public void init() throws SAXException;
-
- /** <p>Returns the child elements.</p>
- */
- public GroupSG getGroupSG();
+ /** Initializes the ComplexContentSG.
+ */
+ public void init() throws SAXException;
+
+ /** Returns, whether the types content model is empty.
+ */
+ public boolean isEmpty();
+
+ /** Returns, whether the types content model is mixed.
+ */
+ public boolean isMixed();
+
+ /** <p>Returns the child elements.</p>
+ */
+ public GroupSG getGroupSG();
}
1.4 +81 -69 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ParticleSG.java
Index: ParticleSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ParticleSG.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ParticleSG.java 9 Sep 2004 00:41:46 -0000 1.3
+++ ParticleSG.java 13 Oct 2004 22:51:53 -0000 1.4
@@ -12,12 +12,14 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-
*/
package org.apache.ws.jaxme.generator.sg;
+import java.util.Map;
+
import org.apache.ws.jaxme.js.DirectAccessible;
import org.apache.ws.jaxme.js.JavaMethod;
+import org.apache.ws.jaxme.spg.SPGParticle;
import org.apache.ws.jaxme.generator.sg.GroupSG;
import org.apache.ws.jaxme.generator.sg.ObjectSG;
import org.apache.ws.jaxme.generator.sg.PropertySG;
@@ -26,74 +28,84 @@
import org.xml.sax.SAXException;
-/**
- * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+/** Interface of a particle.
*/
public interface ParticleSG {
- /** <p>Initializes the ParticleSG.</p>
- */
- public void init() throws SAXException;
-
- /** <p>Returns the particles locator.</p>
- */
- public Locator getLocator();
-
- /** <p>Returns whether the pariticle is a group. If so, you may use the
- * {@link #getGroupSG()} method.</p>
- * @see #getGroupSG()
- */
- public boolean isGroup();
-
- /** <p>Returns whether the particle is an element. If so, you may use the
- * {@link #getObjectSG()} method.</p>
- * @see #getObjectSG()
- */
- public boolean isElement();
-
- /** <p>Returns whether the particle is a wildcard. If so, you may use the
- * {@link #getObjectSG()} method.</p>
- * @see #getObjectSG()
- */
- public boolean isWildcard();
-
- /** <p>If the particle is a group, returns the particles {@link GroupSG}.</p>
- * @throws IllegalStateException The particle is no group.
- * @see #isGroup()
- */
- public GroupSG getGroupSG();
-
- /** <p>If the particle is an element or wildcard, returns the particles {@link ObjectSG}.</p>
- * @throws IllegalStateException The particle is neither an element nor a wildcard
- * @see #isElement()
- * @see #isWildcard()
- */
- public ObjectSG getObjectSG();
-
- /** <p>Returns the particles minOccurs value.</p>
- * @see #getMaxOccurs()
- */
- public int getMinOccurs();
-
- /** <p>Returns the particles maxOccurs value; -1 indicated "unbounded".</p>
- * @see #isMultiple()
- * @see #getMinOccurs()
- */
- public int getMaxOccurs();
-
- /** <p>Returns whether the particles multiplicity is 2 or greater.</p>
- * @see #getMaxOccurs()
- */
- public boolean isMultiple();
-
- /** <p>Creates a new instance of {@link org.apache.ws.jaxme.generator.sg.PropertySGChain}.</p>
- */
- public Object newPropertySGChain();
-
- /** <p>Returns an instance of {@link org.apache.ws.jaxme.generator.sg.PropertySG}.</p>
- */
- public PropertySG getPropertySG();
-
- /** <p>Invokes the given {@link SGlet} for all non null values.</p>
- */
- public void forAllNonNullValues(JavaMethod pMethod, DirectAccessible pElement, SGlet pSGlet) throws SAXException;
+ /** <p>Initializes the ParticleSG.</p>
+ */
+ public void init() throws SAXException;
+
+ /** <p>Returns the particles locator.</p>
+ */
+ public Locator getLocator();
+
+ /** <p>Returns whether the pariticle is a group. If so, you may use the
+ * {@link #getGroupSG()} method.</p>
+ * @see #getGroupSG()
+ */
+ public boolean isGroup();
+
+ /** <p>Returns whether the particle is an element. If so, you may use the
+ * {@link #getObjectSG()} method.</p>
+ * @see #getObjectSG()
+ */
+ public boolean isElement();
+
+ /** <p>Returns whether the particle is a wildcard. If so, you may use the
+ * {@link #getObjectSG()} method.</p>
+ * @see #getObjectSG()
+ */
+ public boolean isWildcard();
+
+ /** <p>If the particle is a group, returns the particles {@link GroupSG}.</p>
+ * @throws IllegalStateException The particle is no group.
+ * @see #isGroup()
+ */
+ public GroupSG getGroupSG();
+
+ /** <p>If the particle is an element or wildcard, returns the particles {@link ObjectSG}.</p>
+ * @throws IllegalStateException The particle is neither an element nor a wildcard
+ * @see #isElement()
+ * @see #isWildcard()
+ */
+ public ObjectSG getObjectSG();
+
+ /** <p>Returns the particles minOccurs value.</p>
+ * @see #getMaxOccurs()
+ */
+ public int getMinOccurs();
+
+ /** <p>Returns the particles maxOccurs value; -1 indicated "unbounded".</p>
+ * @see #isMultiple()
+ * @see #getMinOccurs()
+ */
+ public int getMaxOccurs();
+
+ /** <p>Returns whether the particles multiplicity is 2 or greater.</p>
+ * @see #getMaxOccurs()
+ */
+ public boolean isMultiple();
+
+ /** <p>Creates a new instance of {@link org.apache.ws.jaxme.generator.sg.PropertySGChain}.</p>
+ */
+ public Object newPropertySGChain();
+
+ /** <p>Returns an instance of {@link org.apache.ws.jaxme.generator.sg.PropertySG}.</p>
+ */
+ public PropertySG getPropertySG();
+
+ /** <p>Invokes the given {@link SGlet} for all non null values.</p>
+ */
+ public void forAllNonNullValues(JavaMethod pMethod, DirectAccessible pElement, SGlet pSGlet) throws SAXException;
+
+ /** Converts the particle into a matching instance of
+ * {@link SPGParticle}, which may be used to create a
+ * SAX handler.
+ * @param pGlobalElements Map of global element names, which are
+ * already processed; used to detect recursion
+ * @param pGlobalGroups Map of global group names, which are
+ * already processed; used to detect recursion
+ */
+ public SPGParticle getSPGParticle(Map pGlobalElements, Map pGlobalGroups)
+ throws SAXException;
}
1.1 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/util/QNameUtil.java
Index: QNameUtil.java
===================================================================
/*
* Copyright 2003, 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ws.jaxme.generator.util;
import javax.xml.namespace.QName;
import org.apache.ws.jaxme.xs.xml.XsQName;
/** Utility class for working with instances of
* {@link javax.xml.namespace.QName}.
*/
public class QNameUtil {
/** Creates a new instance of {@link QName}, matching
* the given instance of {@link XsQName}.
*/
public static QName newQName(XsQName pXsQName) {
String prefix = pXsQName.getPrefix();
if (prefix == null) {
return new QName(pXsQName.getNamespaceURI(), pXsQName.getLocalName());
} else {
return new QName(pXsQName.getNamespaceURI(), pXsQName.getLocalName(),
pXsQName.getPrefix());
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org