You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ch...@apache.org on 2005/10/18 05:50:28 UTC
svn commit: r326019 - in /webservices/axis2/trunk/java/modules:
codegen/src/org/apache/axis2/databinding/schema/template/
codegen/src/org/apache/axis2/databinding/utils/
codegen/src/org/apache/axis2/util/
codegen/test/org/apache/axis2/databinding/utils...
Author: chinthaka
Date: Mon Oct 17 20:50:03 2005
New Revision: 326019
URL: http://svn.apache.org/viewcvs?rev=326019&view=rev
Log:
- fixing a small bug in UUID
- adding OMAttr[] as a param to the ADBPullParser to generate pull events for attributes
Modified:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java
webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl?rev=326019&r1=326018&r2=326019&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/template/BeanTemplate.xsl Mon Oct 17 20:50:03 2005
@@ -75,7 +75,7 @@
</xsl:for-each>};
- return org.apache.axis2.databinding.utils.ADBPullParser.createPullParser(qName, objectList);
+ return org.apache.axis2.databinding.utils.ADBPullParser.createPullParser(qName, objectList, null);
}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java?rev=326019&r1=326018&r2=326019&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java Mon Oct 17 20:50:03 2005
@@ -1,6 +1,7 @@
package org.apache.axis2.databinding.utils;
import org.apache.axis2.databinding.ADBBean;
+import org.apache.axis2.om.OMAttribute;
import org.apache.axis2.om.OMElement;
import org.apache.axis2.util.BeanSerializerUtil;
@@ -31,8 +32,13 @@
public class ADBPullParser implements XMLStreamReader {
private Object[] properties;
+ private OMAttribute[] attributes;
private QName elementQName;
+ private boolean isHandlingDocumentElement;
+
+
+
// Every parser can contain a reference to a pull parser of one of its children
private ADBPullParser childPullParser;
@@ -56,9 +62,18 @@
private int currentIndex = 0;
- private ADBPullParser(Object[] properties, QName elementQName) {
+ private ADBPullParser(QName adbBeansQName, Object[] properties, OMAttribute[] attributes) {
+ this.properties = properties;
+ this.elementQName = adbBeansQName;
+ this.attributes = attributes;
+ isHandlingDocumentElement = false;
+ }
+
+ private ADBPullParser(QName adbBeansQName, Object[] properties, OMAttribute[] attributes, boolean isHandlingDocumentElement) {
this.properties = properties;
- this.elementQName = elementQName;
+ this.elementQName = adbBeansQName;
+ this.attributes = attributes;
+ this.isHandlingDocumentElement = isHandlingDocumentElement;
}
/**
@@ -66,41 +81,46 @@
* @param properties - this should contain all the stuff that stax events should be generated.
* Lets take an example of a bean.
* <pre> <Person>
- * <Name>FooOne</Name>
- * <DependentOne>
- * <Name>FooTwo</Name>
- * <Age>25</Age>
- * <Sex>Male</Sex>
- * </DependentOne>
- * </Person>
+ * <Name>FooOne</Name>
+ * <DependentOne>
+ * <Name>FooTwo</Name>
+ * <Age>25</Age>
+ * <Sex>Male</Sex>
+ * </DependentOne>
+ * </Person>
* <p/>
- * so the mapping bean for this is
- * class Person {
- * String Name;
- * Dependent dependentOne;
- * }
+ * so the mapping bean for this is
+ * class Person {
+ * String Name;
+ * Dependent dependentOne;
+ * }
* <p/>
- * class Dependent {
- * String name;
- * int age;
- * String sex;
- * }
+ * class Dependent {
+ * String name;
+ * int age;
+ * String sex;
+ * }
* <p/>
- * So if one needs to generate pull events out of a Person bean, the array he needs
- * to pass is like this.
- * ---------------------------------------------------------------
- * | "Name" | "FooOne" | QName("DependentOne") | Dependent object|
- * ---------------------------------------------------------------
- * Remember "Name" and "FooOne" MUST be strings and DependentOne SHOULD be
- * QName.
- * This DependentObject can either be an ADBBean or a POJO. If its an ADBBean
- * We directly get the pull parser from that. If not we create a reflection based
- * pull parser for that java bean.
- * </pre>
+ * So if one needs to generate pull events out of a Person bean, the array he needs
+ * to pass is like this.
+ * ---------------------------------------------------------------
+ * | "Name" | "FooOne" | QName("DependentOne") | Dependent object|
+ * ---------------------------------------------------------------
+ * Remember "Name" and "FooOne" MUST be strings and DependentOne SHOULD be
+ * QName.
+ * This DependentObject can either be an ADBBean or a POJO. If its an ADBBean
+ * We directly get the pull parser from that. If not we create a reflection based
+ * pull parser for that java bean.
+ * </pre>
+ * @param attributes - this will contain an array of OMAttributes
* @return XMLStreamReader
*/
- public static XMLStreamReader createPullParser(QName adbBeansQName, Object[] properties) {
- return new ADBPullParser(properties, adbBeansQName);
+ public static XMLStreamReader createPullParser(QName adbBeansQName, Object[] properties, OMAttribute[] attributes) {
+ return new ADBPullParser(adbBeansQName, properties, attributes);
+ }
+
+ public static XMLStreamReader createPullParser(QName adbBeansQName, Object[] properties, OMAttribute[] attributes, boolean isDocumentElement) {
+ return new ADBPullParser(adbBeansQName, properties, attributes, isDocumentElement);
}
public boolean isCompleted() {
@@ -192,7 +212,9 @@
public int getAttributeCount() {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ if (accessingChildPullParser) return childPullParser.getAttributeCount();
+ if (attributes != null) return attributes.length;
+ return 0;
}
public int getNamespaceCount() {
@@ -234,72 +256,123 @@
return parserInfo != null ? parserInfo.getName().getPrefix() : null;
}
-
- // -------- un-implemented methods ----------
- public void require(int i, String string, String string1) throws XMLStreamException {
- throw new UnsupportedOperationException("Yet to be implemented !!");
+ public String getAttributeValue(String namespaceURI, String localName) {
+ boolean testNSUri = false;
+ boolean testLocalName = false;
+ if (accessingChildPullParser) return childPullParser.getAttributeValue(namespaceURI, localName);
+
+ // Do I need to handle the no attributes case. It will automatically gets passed from here, returning null.
+ if (namespaceURI == null || "".equals(namespaceURI)) testNSUri = true;
+ if (localName == null || "".equals(localName)) testLocalName = true;
+
+ for (int i = 0; i < attributes.length; i++) {
+ QName attrQName = attributes[i].getQName();
+ boolean isNSUriMatch = !testNSUri;
+ boolean isLocalNameMatch = !testLocalName;
+ if (testNSUri && namespaceURI.equals(attrQName.getNamespaceURI())) {
+ isNSUriMatch = true;
+ }
+ if (testLocalName && localName.equals(attrQName.getLocalPart())) {
+ isLocalNameMatch = true;
+ }
+ if (isLocalNameMatch && isNSUriMatch) return attributes[i].getValue();
+ }
+ return null;
}
- public int nextTag() throws XMLStreamException {
- throw new UnsupportedOperationException("Yet to be implemented !!");
+ public QName getAttributeName(int i) {
+ if (accessingChildPullParser) {
+ return childPullParser.getAttributeName(i);
+ } else if (attributes != null && attributes.length >= i) {
+ return attributes[i].getQName();
+ }
+ return null;
}
- public void close() throws XMLStreamException {
- throw new UnsupportedOperationException("Yet to be implemented !!");
+ public String getAttributeNamespace(int i) {
+ if (accessingChildPullParser) {
+ return childPullParser.getAttributeNamespace(i);
+ } else if (attributes != null && attributes.length >= i) {
+ return attributes[i].getNamespace().getName();
+ }
+ return null;
}
- public String getNamespaceURI(String string) {
- throw new UnsupportedOperationException("Yet to be implemented !!");
+ public String getAttributeLocalName(int i) {
+ if (accessingChildPullParser) {
+ return childPullParser.getAttributeLocalName(i);
+ } else if (attributes != null && attributes.length >= i) {
+ return attributes[i].getLocalName();
+ }
+ return null;
}
- public boolean isStartElement() {
- throw new UnsupportedOperationException("Yet to be implemented !!");
+ public String getAttributePrefix(int i) {
+ if (accessingChildPullParser) {
+ return childPullParser.getAttributePrefix(i);
+ } else if (attributes != null && attributes.length >= i) {
+ return attributes[i].getQName().getPrefix();
+ }
+ return null;
}
- public boolean isEndElement() {
- throw new UnsupportedOperationException("Yet to be implemented !!");
+ public String getAttributeType(int i) {
+ // see http://www.w3.org/TR/REC-xml/#NT-StringType.
+ // since all our attrinutes are Strings, I'm returning CDATA here. But not 100% sure what to do
+ return "CDATA";
}
- public boolean isCharacters() {
- throw new UnsupportedOperationException("Yet to be implemented !!");
+ public String getAttributeValue(int i) {
+ if (accessingChildPullParser) {
+ return childPullParser.getAttributeValue(i);
+ } else if (attributes != null && attributes.length >= i) {
+ return attributes[i].getValue();
+ }
+ return null;
}
- public boolean isWhiteSpace() {
- throw new UnsupportedOperationException("Yet to be implemented !!");
+ public boolean isAttributeSpecified(int i) {
+ if (accessingChildPullParser) {
+ return childPullParser.isAttributeSpecified(i);
+ }
+ return (attributes != null && attributes.length >= i);
}
- public String getAttributeValue(String string, String string1) {
+// -------- un-implemented methods ----------
+
+ public void require(int i, String string, String string1) throws XMLStreamException {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
- public QName getAttributeName(int i) {
+ public int nextTag() throws XMLStreamException {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
- public String getAttributeNamespace(int i) {
+ public void close() throws XMLStreamException {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
- public String getAttributeLocalName(int i) {
+ public String getNamespaceURI(String string) {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
- public String getAttributePrefix(int i) {
+ public boolean isStartElement() {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
- public String getAttributeType(int i) {
+ public boolean isEndElement() {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
- public String getAttributeValue(int i) {
+ public boolean isCharacters() {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
- public boolean isAttributeSpecified(int i) {
+ public boolean isWhiteSpace() {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
+
public String getNamespacePrefix(int i) {
throw new UnsupportedOperationException("Yet to be implemented !!");
}
@@ -365,9 +438,10 @@
throw new UnsupportedOperationException("Yet to be implemented !!");
}
- // =============================================================================
- // Utill methods inside this class
- // =============================================================================
+// =============================================================================
+// Utill methods inside this class
+// =============================================================================
+
private int processADBNameValuePair(String simplePropertyName, String simplePropertyValue) {
int event = 0;
if (!nameValuePairStartElementProcessed) {
@@ -399,7 +473,7 @@
return accessingChildPullParser ? childPullParser.getParserInformation() : this.parserInformation;
}
- // --------------------------------------------------------------------------------------------------//
+// --------------------------------------------------------------------------------------------------//
/**
* Inner class which holds stuff for the parser to pick data
@@ -411,6 +485,7 @@
public class ParserInformation {
String text;
QName name;
+
public ParserInformation(QName name, String text) {
this.text = text;
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java?rev=326019&r1=326018&r2=326019&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java Mon Oct 17 20:50:03 2005
@@ -25,11 +25,6 @@
*
*/
-/**
- * Author: Deepal Jayasinghe
- * Date: Oct 12, 2005
- * Time: 12:52:36 PM
- */
public class BeanSerializerUtil {
@@ -58,7 +53,10 @@
filed.setAccessible(false);
}
}
- return ADBPullParser.createPullParser(beanName, objetc.toArray());
+ return ADBPullParser.createPullParser(beanName, objetc.toArray(), null);
+ // TODO : Deepal fix this. I added another parameter to the above method in the ADBPullPrser
+ // to get the attributes array. For the time being I passed null. Pass attributes array here.
+
} catch (IllegalAccessException e) {
//todo has to throw this exeception
return null;
Modified: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java?rev=326019&r1=326018&r2=326019&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java Mon Oct 17 20:50:03 2005
@@ -2,6 +2,8 @@
import junit.framework.TestCase;
import org.apache.axis2.databinding.ADBBean;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -74,7 +76,7 @@
propertyList.add("Apache");
QName projectQName = new QName("Person");
- XMLStreamReader pullParser = ADBPullParser.createPullParser(projectQName, propertyList.toArray());
+ XMLStreamReader pullParser = ADBPullParser.createPullParser(projectQName, propertyList.toArray(), null);
// while (pullParser.hasNext()) {
// int eventCode = pullParser.next();
// System.out.println(eventCode + ":" + getEventString(eventCode));
@@ -174,7 +176,7 @@
propertyList.add(dummyBean);
QName projectQName = new QName("Person");
- XMLStreamReader pullParser = ADBPullParser.createPullParser(projectQName, propertyList.toArray());
+ XMLStreamReader pullParser = ADBPullParser.createPullParser(projectQName, propertyList.toArray(), null);
StringBuffer buff = new StringBuffer();
while (pullParser.hasNext()) {
@@ -280,7 +282,27 @@
}
public XMLStreamReader getPullParser(QName adbBeanQName) {
- return ADBPullParser.createPullParser(adbBeanQName, propertyList.toArray());
+ return ADBPullParser.createPullParser(adbBeanQName, propertyList.toArray(), null);
}
+ }
+
+// public void testAttributes() throws XMLStreamException {
+// OMFactory factory = OMAbstractFactory.getOMFactory();
+// QName elementQName = new QName("http://ec.org/software", "Employee", "emp");
+// OMNamespace attrNS = factory.createOMNamespace("mailto:whoever@whatever.com", "attr");
+// OMAttribute[] attribute = new OMAttribute[5];
+//
+// for (int i = 0; i < 5; i++) {
+// attribute[i] = factory.createOMAttribute("Attr" + i + 1, attrNS, "Value " + i + 1);
+// }
+//
+// String stringXML = getStringXML(ADBPullParser.createPullParser(elementQName, null, attribute));
+// System.out.println(stringXML);
+//
+// }
+
+ private String getStringXML(XMLStreamReader reader) throws XMLStreamException {
+ OMElement omelement = new StAXOMBuilder(reader).getDocumentElement();
+ return omelement.toStringWithConsume();
}
}
Modified: webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java?rev=326019&r1=326018&r2=326019&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java (original)
+++ webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java Mon Oct 17 20:50:03 2005
@@ -20,8 +20,8 @@
import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.Random;
import java.util.Date;
+import java.util.Random;
public class UUIDGenerator {
/**
@@ -47,7 +47,7 @@
if(++incrementingValue >= Long.MAX_VALUE){
incrementingValue = 0;
}
- return baseUUID + incrementingValue;
+ return baseUUID + new Date().getTime() + incrementingValue;
}
protected static String getInitialUUID() {