jochen 2005/05/07 12:42:27
Modified: src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg
BeanGeneratingVisitor.java GroupUtil.java
SimpleContentHandlerSG.java
src/jaxme/org/apache/ws/jaxme/generator/types
SimpleTypeSGImpl.java
src/jaxme/org/apache/ws/jaxme/generator/sg/impl
JAXBTypeSG.java JAXBPropertySG.java
src/test/jaxb/jira jaxme-21.xsd
. status.xml
src/jaxme/org/apache/ws/jaxme/generator/sg TypeSG.java
PropertySG.java SimpleTypeSG.java
Log:
The PropertySG didn't distinguish clearly between the property name ("foo")
and the generated fields name ("_foo"). As a consequence, invalid code has been
generated in some cases.
PR: JAXME-50
Revision Changes Path
1.2 +3 -0
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/BeanGeneratingVisitor.java
Index: BeanGeneratingVisitor.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/BeanGeneratingVisitor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanGeneratingVisitor.java 24 Apr 2005 20:16:48 -0000 1.1
+++ BeanGeneratingVisitor.java 7 May 2005 19:42:26 -0000 1.2
@@ -104,6 +104,9 @@
PropertySGChain chain = ((PropertySGImpl)
elementSG).getHeadOfChain();
PropertySGChain head = new PropertySGChainImpl(chain){
public String getXMLFieldName(PropertySG
pController) throws SAXException {
+ return "_value";
+ }
+ public String getPropertyName(PropertySG
pController) throws SAXException {
return "value";
}
};
1.4 +2 -3
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupUtil.java
Index: GroupUtil.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GroupUtil.java 24 Apr 2005 20:16:48 -0000 1.3
+++ GroupUtil.java 7 May 2005 19:42:26 -0000 1.4
@@ -5,7 +5,6 @@
import org.apache.ws.jaxme.generator.util.JavaNamer;
import org.apache.ws.jaxme.js.JavaQName;
import org.apache.ws.jaxme.js.JavaQNameImpl;
-import org.apache.ws.jaxme.js.JavaSource;
import org.xml.sax.SAXException;
@@ -33,7 +32,7 @@
if (num++ > 0) {
sb.append(sep);
}
- String f =
particle.getPropertySG().getXMLFieldName();
+ String f =
particle.getPropertySG().getPropertyName();
sb.append(Character.toUpperCase(f.charAt(0)) + f.substring(1));
if (num == 3) {
break;
@@ -50,7 +49,7 @@
static JavaQName getContentClass(GroupSG pGroup, ParticleSG pParticle,
JavaQName pQName) throws SAXException {
- String name = pParticle.getPropertySG().getXMLFieldName();
+ String name = pParticle.getPropertySG().getPropertyName();
name = Character.toUpperCase(name.charAt(0)) +
name.substring(1);
if (pGroup.isGlobal()) {
return
JavaQNameImpl.getInstance(pQName.getPackageName(),
1.6 +1 -1
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SimpleContentHandlerSG.java
Index: SimpleContentHandlerSG.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SimpleContentHandlerSG.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SimpleContentHandlerSG.java 28 Apr 2005 23:57:53 -0000 1.5
+++ SimpleContentHandlerSG.java 7 May 2005 19:42:26 -0000 1.6
@@ -44,7 +44,7 @@
element.addLine("(", elementInterface, ") result");
SimpleContentSG scSG = ctSG.getSimpleContentSG();
TypedValue tv = createSimpleTypeConversion(result,
scSG.getContentTypeSG(),
-
getParamResult(), scSG.getPropertySG().getXMLFieldName());
+
getParamResult(), scSG.getPropertySG().getPropertyName());
scSG.getPropertySG().addValue(result, element, tv, null);
return result;
}
1.4 +2 -3
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/types/SimpleTypeSGImpl.java
Index: SimpleTypeSGImpl.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/types/SimpleTypeSGImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SimpleTypeSGImpl.java 30 Sep 2004 00:09:30 -0000 1.3
+++ SimpleTypeSGImpl.java 7 May 2005 19:42:26 -0000 1.4
@@ -110,11 +110,10 @@
}
public JavaMethod getXMLSetMethod(SimpleTypeSG pController, JavaSource
pSource,
- String pFieldName, String pMethodName)
throws SAXException {
+ String pFieldName, String pParamName,
String pMethodName) throws SAXException {
if (pController.hasSetMethod()) {
- String pName = "p" + Character.toUpperCase(pFieldName.charAt(0)) +
pFieldName.substring(1);
JavaMethod jm = pSource.newJavaMethod(pMethodName, JavaQNameImpl.VOID,
JavaSource.PUBLIC);
- DirectAccessible param = jm.addParam(pController.getRuntimeType(),
pName);
+ DirectAccessible param = jm.addParam(pController.getRuntimeType(),
pParamName);
if (!pSource.isInterface()) {
pController.addValidation(jm, param);
jm.addLine(pFieldName, " = ", param, ";");
1.16 +5 -5
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- JAXBTypeSG.java 27 Apr 2005 06:23:26 -0000 1.15
+++ JAXBTypeSG.java 7 May 2005 19:42:26 -0000 1.16
@@ -303,7 +303,7 @@
}
public JavaMethod getXMLGetMethod(TypeSG pController, JavaSource pSource,
- String pFieldName, String pMethodName)
throws SAXException {
+ String
pFieldName, String pMethodName) throws SAXException {
JavaQName runtimeType;
if (pController.isComplex() && pFieldName.equals("value") &&
pController.getComplexTypeSG().hasSimpleContent()) {
SimpleContentSG obj =
pController.getComplexTypeSG().getSimpleContentSG();
@@ -325,10 +325,10 @@
}
public JavaMethod getXMLSetMethod(TypeSG pController, JavaSource pSource,
- String pFieldName, String
pMethodName,
+ String pFieldName, String
pParamName,
+ 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()) {
@@ -343,13 +343,13 @@
else {
runtimeType = pController.getRuntimeType();
}
- DirectAccessible param = jm.addParam(runtimeType, pName);
+ DirectAccessible param = jm.addParam(runtimeType, pParamName);
if (!pSource.isInterface()) {
jm.addLine(pFieldName, " = ", param, ";");
}
return jm;
} else {
- JavaMethod jm =
pController.getSimpleTypeSG().getXMLSetMethod(pSource, pFieldName, pMethodName);
+ JavaMethod jm =
pController.getSimpleTypeSG().getXMLSetMethod(pSource, pFieldName, pParamName,
pMethodName);
if (pSetIsSet && pController.getRuntimeType().isPrimitive()) {
jm.addLine(getIsSetCheckFieldName(pFieldName), " =
true;");
}
1.13 +18 -23
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- JAXBPropertySG.java 24 Apr 2005 20:16:48 -0000 1.12
+++ JAXBPropertySG.java 7 May 2005 19:42:26 -0000 1.13
@@ -39,7 +39,6 @@
import org.apache.ws.jaxme.xs.XSElement;
import org.apache.ws.jaxme.xs.XSObject;
import org.apache.ws.jaxme.xs.XSType;
-import org.apache.ws.jaxme.xs.jaxb.JAXBElement;
import org.apache.ws.jaxme.xs.jaxb.JAXBProperty;
import org.apache.ws.jaxme.xs.jaxb.JAXBPropertyOwner;
import org.xml.sax.SAXException;
@@ -55,12 +54,9 @@
private final boolean generateIsSetMethod;
private final String defaultValue;
private final TypeSG typeSG;
- private final boolean globalType;
protected JAXBPropertySG(String pDefaultPropertyName, SchemaSG pSchema,
XSObject pXSObject,
String pDefaultValue,
TypeSG pTypeSG) {
- globalType = (pTypeSG != null && pTypeSG.isGlobalType()
- || (pXSObject instanceof XSElement && ((XSElement)
pXSObject).isGlobal()));
typeSG = pTypeSG;
defaultValue = pDefaultValue;
String myPropertyName = null;
@@ -110,6 +106,10 @@
public String getCollectionType(PropertySG pController) { return
collectionType; }
public String getXMLFieldName(PropertySG pController) throws
SAXException {
+ return fieldName;
+ }
+
+ public String getPropertyName(PropertySG pController) throws
SAXException {
return propertyName;
}
@@ -121,8 +121,8 @@
} else {
prefix = "get";
}
- String fieldName = pController.getXMLFieldName();
- String methodName = prefix +
Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
+ String propName = pController.getPropertyName();
+ String methodName = prefix +
Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
if (methodName.equals("getClass")) {
throw new SAXException("Method name getClass() conflicts with
java.lang.Object.getClass(), use jaxb:property to customize the property
name.");
}
@@ -130,33 +130,35 @@
}
public String getXMLSetMethodName(PropertySG pController) throws
SAXException {
- String fieldName = pController.getXMLFieldName();
- return "set" + Character.toUpperCase(fieldName.charAt(0)) +
fieldName.substring(1);
+ String propName = pController.getPropertyName();
+ return "set" + Character.toUpperCase(propName.charAt(0)) +
propName.substring(1);
}
public String getXMLIsSetMethodName(PropertySG pController) throws
SAXException {
- String fieldName = pController.getXMLFieldName();
+ String propName = pController.getPropertyName();
return hasIsSetMethod(pController) ?
-
"isSet" + Character.toUpperCase(fieldName.charAt(0)) +
fieldName.substring(1) : null;
+
"isSet" + Character.toUpperCase(propName.charAt(0)) + propName.substring(1)
: null;
}
public JavaField getXMLField(PropertySG pController, JavaSource
pSource) throws SAXException {
- return typeSG.getXMLField(pSource, fieldName, defaultValue);
+ return typeSG.getXMLField(pSource,
pController.getXMLFieldName(), defaultValue);
}
public JavaMethod getXMLGetMethod(PropertySG pController, JavaSource
pSource) throws SAXException {
- return typeSG.getXMLGetMethod(pSource, fieldName,
- pController.getXMLGetMethodName());
+ return typeSG.getXMLGetMethod(pSource,
pController.getXMLFieldName(),
+
pController.getXMLGetMethodName());
}
public JavaMethod getXMLSetMethod(PropertySG pController, JavaSource
pSource) throws SAXException {
- return typeSG.getXMLSetMethod(pSource, fieldName,
-
pController.getXMLSetMethodName(),
+ String propName = pController.getPropertyName();
+ String pName = "p" + Character.toUpperCase(propName.charAt(0))
+ propName.substring(1);
+ return typeSG.getXMLSetMethod(pSource,
pController.getXMLFieldName(),
+
pName, pController.getXMLSetMethodName(),
pController.hasIsSetMethod());
}
public JavaMethod getXMLIsSetMethod(PropertySG pController, JavaSource
pSource) throws SAXException {
- return typeSG.getXMLIsSetMethod(pSource, fieldName,
+ return typeSG.getXMLIsSetMethod(pSource,
pController.getXMLFieldName(),
pController.getXMLIsSetMethodName());
}
@@ -236,11 +238,4 @@
public void addValue(PropertySG pController, JavaMethod pMethod,
DirectAccessible pElement, TypedValue pValue, JavaQName pType) throws
SAXException {
pController.setValue(pMethod, pElement, pValue, pType);
}
-
- public String getDefaultValue(PropertySG pController) throws
IllegalStateException {
- if (typeSG.isComplex()) {
- throw new IllegalStateException("Complex type " +
typeSG.getName() + " doesn't support default value.");
- }
- return defaultValue;
- }
}
1.3 +15 -0 ws-jaxme/src/test/jaxb/jira/jaxme-21.xsd
Index: jaxme-21.xsd
===================================================================
RCS file: /home/cvs/ws-jaxme/src/test/jaxb/jira/jaxme-21.xsd,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- jaxme-21.xsd 12 Aug 2004 00:04:28 -0000 1.2
+++ jaxme-21.xsd 7 May 2005 19:42:26 -0000 1.3
@@ -168,4 +168,19 @@
<attribute name="lastLoginDate" type="dateTime"/>
</complexType>
+ <complexType name="VisualType">
+ <all>
+ <element name="periodlist">
+ <complexType>
+ <sequence>
+ <element name="period" type="string" maxOccurs="unbounded">
+ <annotation><appinfo>
+ <jaxb:property generateIsSetMethod="true"/>
+ </appinfo></annotation>
+ </element>
+ </sequence>
+ </complexType>
+ </element>
+ </all>
+ </complexType>
</schema>
1.53 +8 -0 ws-jaxme/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/ws-jaxme/status.xml,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- status.xml 28 Apr 2005 23:57:52 -0000 1.52
+++ status.xml 7 May 2005 19:42:27 -0000 1.53
@@ -37,6 +37,14 @@
</release>
<release version="0.4" date="Not yet published">
<action dev="JW" type="fix" context="generator">
+ The PropertySG didn't distinguish clearly between
+ the property name ("foo") and the generated Java
+ fields name ("_foo"). As a consequence, invalid
+ code has been generated in some cases. See
+ JAXME-50 in Jira. (Geert Barentsen,
+ geert.barentsen at telenet.be)
+ </action>
+ <action dev="JW" type="fix" context="generator">
A proper ParseConversionEvent is now generated, if the
conversion of a simple type fails.
</action>
1.8 +1 -0
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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TypeSG.java 13 Oct 2004 22:51:53 -0000 1.7
+++ TypeSG.java 7 May 2005 19:42:27 -0000 1.8
@@ -116,6 +116,7 @@
/** <p>Generates a set method returning an instance of this type.</p>
*/
public JavaMethod getXMLSetMethod(JavaSource pSource, String pFieldName,
+ String
pParamName,
String pMethodName, boolean
pSetIsSet) throws SAXException;
/** <p>Generates an "isSet" method returning whether the field is set.</p>
1.5 +6 -1
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/PropertySG.java
Index: PropertySG.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/PropertySG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PropertySG.java 8 Apr 2005 23:10:45 -0000 1.4
+++ PropertySG.java 7 May 2005 19:42:27 -0000 1.5
@@ -41,10 +41,15 @@
*/
public String getCollectionType();
- /** <p>Returns the objects property name.</p>
+ /** <p>Returns the objects field name. By default, this is the
+ * property name with the prefix '_'.</p>
*/
public String getXMLFieldName() throws SAXException;
+ /** <p>Returns the objects property name.</p>
+ */
+ public String getPropertyName() throws SAXException;
+
/** <p>Returns the objects getter name.</p>
*/
public String getXMLGetMethodName() throws SAXException;
1.7 +2 -2
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/SimpleTypeSG.java
Index: SimpleTypeSG.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/SimpleTypeSG.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SimpleTypeSG.java 28 Apr 2005 23:57:53 -0000 1.6
+++ SimpleTypeSG.java 7 May 2005 19:42:27 -0000 1.7
@@ -148,8 +148,8 @@
/** <p>Generates a set method for the simple type.</p>
*/
- public JavaMethod getXMLSetMethod(JavaSource pSource,
- String pFieldName, String pMethodName)
throws SAXException;
+ public JavaMethod getXMLSetMethod(JavaSource pSource, String pFieldName,
+ String
pParamName, String pMethodName) throws SAXException;
/** <p>Adds code for validating the value <code>pValue</code> to the "add"
or
* "set" method <code>pMethod</code>.</p>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]